Structural deformable models
Functions
Model.cpp File Reference
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <ctype.h>
#include "Model.h"
#include "SensorSet.h"
#include "SensorColl.h"
#include "Data.h"
#include "PartParam.h"
#include "Searcher.h"
#include "crc.h"
#include "mathutil.h"
Include dependency graph for Model.cpp:

Go to the source code of this file.

Functions

ParseFileoperator>> (ParseFile &is, Model &g)
 
ostream & operator<< (ostream &os, const Model &g)
 

Function Documentation

ostream& operator<< ( std::ostream &  os,
const Model g 
)

Read geometry from stream.

Definition at line 338 of file Model.cpp.

References SensorCollection::clearPrintList(), DEFAULT_PPMM, Model::edges, ParseFile::getPath(), Model::m_DirNodeInd, Model::m_Filename, Model::m_Name, Model::m_ppmm, Model::m_SensorFile, Model::m_Sensors, Model::nodes, and Model::phys.

339 {
340  os << "p name " << g.m_Name << endl;
341  if(g.m_ppmm != DEFAULT_PPMM)
342  os << "p ppmm " << g.m_ppmm << endl;
343  os << "p dirnode " << g.m_DirNodeInd << endl;
344  os << g.phys;
345  os << endl;
346  if(!g.m_SensorFile.empty()) {
347  ofstream sf((ParseFile::getPath(g.m_Filename)+g.m_SensorFile).c_str());
348  sf << *g.m_Sensors;
349  os << "sensors " << g.m_SensorFile << endl;
350  } else {
352  for(NodeArray::const_iterator n = g.nodes.begin(); n != g.nodes.end();
353  n++)
354  n->sensor->hprint(os, (SensorCollection*)g.m_Sensors);
355  }
356  os << endl;
357  for(NodeArray::const_iterator n = g.nodes.begin(); n != g.nodes.end(); n++)
358  os << *n;
359  os << endl;
360  for(EdgeArray::const_iterator e = g.edges.begin(); e != g.edges.end(); e++)
361  os << *e;
362  return os;
363 }
void clearPrintList(bool skipdefaults=true)
Definition: SensorColl.cpp:66
std::string m_SensorFile
Definition: Model.h:267
std::string m_Filename
Definition: Model.h:281
int m_DirNodeInd
Definition: Model.h:273
std::string m_Name
Definition: Model.h:270
ParticleParam phys
physical parameter set
Definition: Model.h:257
SensorCollection * m_Sensors
Definition: Model.h:266
EdgeArray edges
indexed list of edges
Definition: Model.h:263
const std::string & getPath() const
Definition: ParseFile.h:52
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
dword m_ppmm
Definition: Model.h:272
#define DEFAULT_PPMM
Definition: Data.h:16
ParseFile& operator>> ( ParseFile is,
Model g 
)

Read complete geometry from input stream.

is comment character, v introduces a point (vertex), e an edge:

#example v 1 1 v 2 2 e 1 2

Definition at line 299 of file Model.cpp.

References Model::adaptDataScale(), DEFAULT_PPMM, ParseFile::eof(), ParseFile::getFilename(), ParseFile::getLineNumber(), IOException::getMessage(), ParticleParam::global, Model::m_Filename, Model::m_ppmm, Model::phys, Model::prepareTorque(), Model::readEdge(), Model::readNode(), Model::readParameter(), Model::readSensor(), Model::reset(), and Model::setName().

300 {
301  g.reset();
302  g.m_Filename = is.getFilename();
304  g.setName("<noname>");
305  g.m_ppmm = DEFAULT_PPMM;
306  try{
307  int phase=0;
308  while(is) {
309  if(phase == 0) {
310  if(!g.readSensor(is) && !g.readParameter(is))
311  phase++;
312  }
313  if(phase == 1) {
314  if(!g.readNode(is))
315  phase++;
316  }
317  if(phase == 2) {
318  if(!g.readEdge(is))
319  phase++;
320  }
321  if(phase == 3 && !is.eof()) {
322  g.reset();
323  throw new IOException("Error reading model file.");
324  }
325  }
326  } catch(const IOException *e) {
327  const char* omsg = e->getMessage();
328  int l=strlen(omsg);
329  char msg[l+256];
330  sprintf(msg,"%s (interpreted line %i)", omsg, is.getLineNumber());
331  throw new IOException(msg);
332  }
333  g.adaptDataScale();
334  g.prepareTorque();
335  return is;
336 }
static ParticleParam global
Definition: PartParam.h:72
const std::string & getFilename() const
Definition: ParseFile.h:53
void prepareTorque()
Definition: Model.cpp:713
bool readSensor(ParseFile &is)
read sensor from stream
Definition: Model.cpp:244
void adaptDataScale(dword ppmm=0)
Definition: Model.cpp:1240
std::string m_Filename
Definition: Model.h:281
ParticleParam phys
physical parameter set
Definition: Model.h:257
bool eof() const
Definition: ParseFile.h:49
const char * getMessage() const
Definition: Errors.h:41
void setName(const std::string &name)
Definition: Model.cpp:399
void reset()
reset all model information (including geometry)
Definition: Model.cpp:103
bool readNode(ParseFile &is)
read node from stream
Definition: Model.cpp:210
bool readParameter(ParseFile &is)
read model parameters
Definition: Model.cpp:263
dword m_ppmm
Definition: Model.h:272
bool readEdge(ParseFile &is)
read edge from stream
Definition: Model.cpp:167
#define DEFAULT_PPMM
Definition: Data.h:16
const int getLineNumber() const
Definition: ParseFile.h:58