Structural deformable models
Public Types | Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
Model Class Reference

#include <Model.h>

Collaboration diagram for Model:
Collaboration graph
[legend]

Public Types

enum  DistType {
  DIST_XY, DIST_XYS, DIST_PVEC, DIST_POINTS,
  DIST_CPOINTS, DIST_HPOINTS
}
 
enum  ModelState {
  ST_WINNER =1, ST_LOOSER =2, ST_OLDSTATE =4, ST_DEL =8,
  ST_MEMBER =16, ST_NODEL =32
}
 

Public Member Functions

 Model (dataset_cptr _dataset=NULL, SensorCollection *sensors=NULL)
 Default constructor. More...
 
 Model (const Model &rhs)
 Copy constructor. More...
 
 ~Model ()
 Destructor. More...
 
void clear ()
 remove and destroy all geometry information (nodes and edges) More...
 
 operator bool () const
 is initialized? More...
 
void reset ()
 reset all model information (including geometry) More...
 
int addNode (const Node &node)
 
int addEdge (const Edge &edge)
 
int addEdge (const Node &from, const Node &to)
 
int addEdge (int ifrom, int ito)
 
const EdgegetEdge (int index) const
 
EdgegetEdge (int index)
 
const NodegetNode (int index) const
 
NodegetNode (int index)
 
int getNNodes () const
 
int getNEdges () const
 
float getNodeAngle (const Node &n) const
 
void setName (const std::string &name)
 
const std::string & getName () const
 
dword getCRC () const
 
dword getID () const
 
void setID (dword id)
 
void draw (bool drawPoints=false) const
 Draw using OpenGL. More...
 
void drawPS (CAMgraphicsProcess &gp, dword mode=0) const
 Draw to postscrip output. More...
 
bool readEdge (ParseFile &is)
 read edge from stream More...
 
bool readNode (ParseFile &is)
 read node from stream More...
 
bool readSensor (ParseFile &is)
 read sensor from stream More...
 
bool readParameter (ParseFile &is)
 read model parameters More...
 
Modeloperator= (const Model &rhs)
 
bool readFile (const char *filename, bool fullread=true)
 
bool writeFile (const char *filename) const
 
void attachDataset (dataset_cptr dataset)
 
float getQualityOfFit () const
 
float getLiveliness () const
 
void translate (const Point &t)
 
void addNoise (float r)
 
void freeze ()
 
void push (const Point &t)
 
void rotate (float angle, const Point &c)
 
void rotate (float angle)
 
void pushRotate (const Point &c, float angle)
 
void attract (const Point &c, float factor)
 
float getFullLength () const
 Returns overall sum of edge lengths. More...
 
float getStdRadius (const Point &center) const
 Returns mean squared distance from centroid. More...
 
float getStdRadius () const
 
float getMaxRadius (const Point &center) const
 Returns the maximum radius from the centroid. More...
 
float getMaxRadius () const
 
void scale (float factor, bool movepoints=false)
 multiply all rest lengths by factor More...
 
void scaleSel (float factor, const DMatrixf &selm)
 multiply all rest lengths of selected edges by factor More...
 
void adaptRestLength (float ratio)
 adapt restlengths towards current lengths by ratio More...
 
void adaptRestLengthSel (float ratio, const DMatrixf &selm)
 adapt restlengths of selected edges towards current lengths by ratio More...
 
void adaptProportion (float ratio)
 overall rest lengths sum is adapted to overall edge lengths by ratio More...
 
float getLengthRatio () const
 relation of overall edge length by overall rest length sum More...
 
float getLengthVariation () const
 mean squared difference from restlength normalized by restlength sum More...
 
float getDeformation () const
 normalized length variation to compensate for different sizes More...
 
float getSensorFit (dword *npts=NULL) const
 get average sensor value More...
 
float getEdgeSensorFit (dword *npts=NULL) const
 get average fit of sensors along edges More...
 
void updateParticles (float dt, int method=0)
 
void resetForces ()
 
void calculateForces (float dt)
 
void calculateDerivatives (std::vector< NodeDerivative > &deriv)
 
float addImageForces (float dt)
 
void addTorque (float dt)
 
void prepareTorque ()
 
void mergeSensorCollection (SensorCollection *sensors)
 
SensorCollectiongetSensorCollection ()
 
void reattachSensors ()
 get sensors from sensor collection More...
 
dword createEdgeSensors (float dist=0.1)
 auto-create appropriate edge sensors (dist*stdRadius is distance) More...
 
const Point getCenter () const
 
float getDirection () const
 
const NodegetDirNode () const
 
void setDirNode (int id)
 
void setWinner (bool iswin=true, float ts=0.)
 
bool isWinner ()
 
void setLooser (bool isloose=true, float ts=0.)
 
bool isLooser ()
 
void setOldState (bool isoldstate=true, float ts=0.)
 
bool isOldState ()
 
dwordgetFlags ()
 
bool hasFlags (dword flags) const
 
dwordsetFlags (dword flags)
 
dwordunsetFlags (dword flags)
 
dwordswitchFlags (dword flags)
 
void setShapeWeight (float weight)
 
void adaptDataScale (dword ppmm=0)
 
dword getDataScale () const
 
void adaptProperties (const PropVec &prop)
 
const PropVecgetProperties () const
 
PropVec getPropertiesMM () const
 return property vector using millimeter scale More...
 
void adaptPropertiesMM (PropVec prop)
 adapt to a property vector using millimeter scale More...
 
Point2DconvertPointFromMM (Point2D &pt) const
 
Point2DconvertPointToMM (Point2D &pt) const
 
PropVecconvertPropFromMM (PropVec &prop) const
 
PropVecconvertPropToMM (PropVec &prop) const
 
int nearestNode (const Point &pos, float &dist=*(float *)(NULL)) const
 
float distance (const Model &rhs, enum Model::DistType kind=DIST_POINTS) const
 
void invalidatePC (dword pcflags=PC_ALL)
 
dword getInstCount () const
 
void setInstCount (dword ic)
 
dword mergeModel (Model &mergemod)
 
const std::string & getFilename () const
 
void setHLNode (int hlnode)
 
int getHLNode () const
 Returns ID of highlighted node. Value is -1 if none is selected. More...
 
dword getSelectedNodesN (dword state=Node::ST_SELECT) const
 get number of selected nodes More...
 
dword connectNodes ()
 Connect selected nodes. More...
 
dword removeEdges ()
 Remove edges between selected nodes. More...
 
void removeNode (int nid)
 Removes a node and its adjacent edges. More...
 
DMatrixf adjMat () const
 compute undirected adjacency matrix More...
 
DMatrixf selMaskMat () const
 compute mask matrix of selected nodes More...
 

Public Attributes

ParticleParam phys
 physical parameter set More...
 
float m_TimeStamp
 time stamps (see. TTimeStamp) More...
 

Protected Types

enum  PreCompF {
  PC_CENTER =0x01, PC_SCALE =0x02, PC_DIR =0x04, PC_QOF =0x08,
  PC_LIVE =0x10, PC_NOTHING =0x00, PC_ALL =0x1f, PC_PVEC =PC_CENTER|PC_SCALE|PC_DIR,
  PC_STATS =PC_QOF|PC_LIVE
}
 

Protected Member Functions

dword removeByAdjMat (DMatrixf &adjm)
 remove edged not mentioned in (non-directional) adjacency matrix More...
 
dword createByAdjMat (const DMatrixf &adjm)
 create edges mentioned in adjacency matrix More...
 
void rebuildIndexTables ()
 rebuild cross indexing between nodes and edges More...
 
void attachSensorColl (SensorCollection *sc)
 set reference to and from sensor collection for correct updates More...
 

Protected Attributes

NodeArray nodes
 indexed list of nodes More...
 
EdgeArray edges
 indexed list of edges More...
 
dataset_cptr m_Dataset
 
SensorCollectionm_Sensors
 
std::string m_SensorFile
 
float m_ShapeWeight
 
dword m_Flags
 
std::string m_Name
 
dword m_CRC
 
dword m_ppmm
 
int m_DirNodeInd
 
dword m_PCFlags
 
PropVec m_PropVec
 
float m_QOF
 
float m_Liveliness
 
float m_Scale
 
float m_Direction
 
dword m_InstCount
 number of merged instances More...
 
std::string m_Filename
 
int m_HLNode
 
dword m_ID
 

Friends

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

Detailed Description

Definition at line 33 of file Model.h.

Member Enumeration Documentation

Enumerator
DIST_XY 
DIST_XYS 
DIST_PVEC 
DIST_POINTS 
DIST_CPOINTS 
DIST_HPOINTS 

Definition at line 40 of file Model.h.

Enumerator
ST_WINNER 
ST_LOOSER 
ST_OLDSTATE 
ST_DEL 
ST_MEMBER 
ST_NODEL 

Definition at line 43 of file Model.h.

enum Model::PreCompF
protected
Enumerator
PC_CENTER 
PC_SCALE 
PC_DIR 
PC_QOF 
PC_LIVE 
PC_NOTHING 
PC_ALL 
PC_PVEC 
PC_STATS 

Definition at line 35 of file Model.h.

Constructor & Destructor Documentation

Model::Model ( dataset_cptr  _dataset = NULL,
SensorCollection sensors = NULL 
)

Default constructor.

Definition at line 26 of file Model.cpp.

References __SHAPEWEIGHT, DEFAULT_PPMM, ParticleParam::gravitational, m_DirNodeInd, m_ppmm, m_Sensors, m_ShapeWeight, phys, SensorCollection::refModel(), setName(), and ParticleParam::viscousdrag.

27  : m_TimeStamp(0), m_Dataset(_dataset), m_Sensors(sensors),
29 {
33  setName("00");
35  m_DirNodeInd=-1;
36  if(m_Sensors) m_Sensors->refModel(this);
37 }
dataset_cptr m_Dataset
Definition: Model.h:265
int m_DirNodeInd
Definition: Model.h:273
ParticleParam phys
physical parameter set
Definition: Model.h:257
float m_ShapeWeight
Definition: Model.h:268
void refModel(Model *model) const
Definition: SensorColl.cpp:282
int m_HLNode
Definition: Model.h:283
SensorCollection * m_Sensors
Definition: Model.h:266
dword m_PCFlags
Definition: Model.h:274
void setName(const std::string &name)
Definition: Model.cpp:399
float viscousdrag
Definition: PartParam.h:63
dword m_ppmm
Definition: Model.h:272
#define __SHAPEWEIGHT
Definition: Brain.cpp:22
dword m_Flags
Definition: Model.h:269
#define DEFAULT_PPMM
Definition: Data.h:16
dword m_InstCount
number of merged instances
Definition: Model.h:280
dword m_ID
Definition: Model.h:284
float gravitational
Definition: PartParam.h:62
float m_TimeStamp
time stamps (see. TTimeStamp)
Definition: Model.h:259
Model::Model ( const Model rhs)

Copy constructor.

Definition at line 39 of file Model.cpp.

References m_Sensors, NULL, and operator=().

40 {
41  m_Sensors = NULL;
42  operator=(rhs);
43 }
#define NULL
Definition: simpletypes.h:9
SensorCollection * m_Sensors
Definition: Model.h:266
Model & operator=(const Model &rhs)
Definition: Model.cpp:50
Model::~Model ( )

Destructor.

Definition at line 45 of file Model.cpp.

References attachSensorColl(), and NULL.

46 {
48 }
#define NULL
Definition: simpletypes.h:9
void attachSensorColl(SensorCollection *sc)
set reference to and from sensor collection for correct updates
Definition: Model.cpp:588

Member Function Documentation

void Model::adaptDataScale ( dword  ppmm = 0)

Definition at line 1240 of file Model.cpp.

References m_Dataset, m_ppmm, and scale().

Referenced by attachDataset(), operator>>(), and setShapeWeight().

1240  {
1241  if(!ppmm) {
1242  if(!m_Dataset) return;
1243  if(!(ppmm = m_Dataset->getPPMM())) return;
1244  }
1245  if(m_ppmm) scale(float(ppmm)/m_ppmm, true);
1246  m_ppmm = ppmm;
1247 }
dataset_cptr m_Dataset
Definition: Model.h:265
void scale(float factor, bool movepoints=false)
multiply all rest lengths by factor
Definition: Model.cpp:1140
dword m_ppmm
Definition: Model.h:272
void Model::adaptProperties ( const PropVec prop)

Definition at line 1249 of file Model.cpp.

References getCenter(), getDirection(), getPropDir(), getPropPos(), getPropScale(), getStdRadius(), nodes, rotate(), scale(), and translate().

Referenced by adaptPropertiesMM(), ExpectationMap::generateInstance(), getDataScale(), and Searcher::mutate().

1249  {
1250  if(nodes.empty()) return;
1251  Point2D nc = getPropPos(prop);
1252  float ndir = getPropDir(prop);
1253  float nscale = getPropScale(prop);
1254  Point center = getCenter();
1255  float cscale = getStdRadius();
1256  float cdir = getDirection();
1257  rotate(ndir-cdir);
1258  if(nscale>0.001 && cscale>0.0000001)
1259  scale(nscale/cscale, true);
1260  translate(nc-center);
1261 }
void rotate(float angle, const Point &c)
Definition: Model.cpp:946
Point2D getPropPos(const PropVec &prop)
Definition: PropVec.h:13
float getDirection() const
Definition: Model.cpp:890
float getPropScale(const PropVec &prop)
Definition: PropVec.h:19
void scale(float factor, bool movepoints=false)
multiply all rest lengths by factor
Definition: Model.cpp:1140
const Point getCenter() const
Definition: Model.cpp:852
float getStdRadius() const
Definition: Model.h:132
float getPropDir(const PropVec &prop)
Definition: PropVec.h:25
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
void translate(const Point &t)
Definition: Model.cpp:923
Definition: Point.h:16
void Model::adaptPropertiesMM ( PropVec  prop)

adapt to a property vector using millimeter scale

Definition at line 1281 of file Model.cpp.

References adaptProperties(), and convertPropFromMM().

Referenced by getDataScale().

1282 {
1284 }
PropVec & convertPropFromMM(PropVec &prop) const
Definition: Model.cpp:1297
void adaptProperties(const PropVec &prop)
Definition: Model.cpp:1249
void Model::adaptProportion ( float  ratio)

overall rest lengths sum is adapted to overall edge lengths by ratio

Definition at line 1164 of file Model.cpp.

References edges, and getLengthRatio().

Referenced by getMaxRadius(), Searcher::mutate(), and Brain::triggerTest().

1165 {
1166  float corrat = getLengthRatio();
1167  corrat -= (corrat-1)*(1-ratio);
1168  for(EdgeArray::iterator e = edges.begin(); e != edges.end(); e++) {
1169  e->restlength *= corrat;
1170  }
1171 }
EdgeArray edges
indexed list of edges
Definition: Model.h:263
float getLengthRatio() const
relation of overall edge length by overall rest length sum
Definition: Model.cpp:968
void Model::adaptRestLength ( float  ratio)

adapt restlengths towards current lengths by ratio

Definition at line 1126 of file Model.cpp.

References edges.

Referenced by getMaxRadius(), and Brain::triggerTest().

1127 {
1128  for(EdgeArray::iterator e = edges.begin(); e != edges.end(); e++) {
1129  e->adaptRestLength(ratio);
1130  }
1131 }
EdgeArray edges
indexed list of edges
Definition: Model.h:263
void Model::adaptRestLengthSel ( float  ratio,
const DMatrixf selm 
)

adapt restlengths of selected edges towards current lengths by ratio

Definition at line 1133 of file Model.cpp.

References edges.

Referenced by getMaxRadius(), and Brain::triggerTest().

1134 {
1135  for(EdgeArray::iterator e = edges.begin(); e != edges.end(); e++) {
1136  e->adaptRestLength(ratio);
1137  }
1138 }
EdgeArray edges
indexed list of edges
Definition: Model.h:263
int Model::addEdge ( const Edge edge)

add an Edge to the model

Returns
index in the internal array

Definition at line 138 of file Model.cpp.

References edges, and nodes.

Referenced by addEdge(), createByAdjMat(), operator bool(), readEdge(), and Brain::triggerTest().

139 {
140  int index = edges.size();
141  edges.push_back(edge);
142  edges[index].index = index;
143  edges[index].setNodesList(nodes);
144  edges[index].fromNode().edges.push_back(index+1);
145  edges[index].toNode().edges.push_back(-index-1);
146  return index;
147 }
EdgeArray edges
indexed list of edges
Definition: Model.h:263
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
int Model::addEdge ( const Node from,
const Node to 
)

create an Edge from two given nodes

Returns
index in the internal array

Definition at line 151 of file Model.cpp.

References addEdge(), addNode(), and nodes.

152 {
153  int fi = addNode(from);
154  int ti = addNode(to);
155  return addEdge(Edge(fi,ti,nodes));
156 }
Implements an Edge with spring functionality.
Definition: Edge.h:14
int addNode(const Node &node)
Definition: Model.cpp:120
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
int addEdge(const Edge &edge)
Definition: Model.cpp:138
int Model::addEdge ( int  ifrom,
int  ito 
)

create an Edge using node indices (from nodes - array)

Returns
index in the internal array

Definition at line 160 of file Model.cpp.

References addEdge(), nodes, and phys.

161 {
162  assert((dword)ifrom<nodes.size() &&
163  (dword)ito<nodes.size() && ifrom>=0 && ito>=0);
164  return addEdge( Edge(ifrom, ito, nodes, &phys) );
165 }
Implements an Edge with spring functionality.
Definition: Edge.h:14
ParticleParam phys
physical parameter set
Definition: Model.h:257
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
unsigned long dword
Definition: simpletypes.h:6
int addEdge(const Edge &edge)
Definition: Model.cpp:138
float Model::addImageForces ( float  dt)

Definition at line 701 of file Model.cpp.

References m_Dataset, and nodes.

Referenced by calculateForces(), and getMaxRadius().

701  {
702  if(!m_Dataset || !m_Dataset->initialized()) return 0.0f;
703  if(m_Dataset) const_cast<vuMutex&>(m_Dataset->writeMutex).lock();
704  float allf=0;
705  for (NodeArray::iterator p=nodes.begin(); p!=nodes.end();p++) {
706  p->addSensorForce();
707  allf += p->f.norm();
708  }
709  if(m_Dataset) const_cast<vuMutex&>(m_Dataset->writeMutex).unlock();
710  return allf;
711 }
dataset_cptr m_Dataset
Definition: Model.h:265
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
int Model::addNode ( const Node node)

add a Node to the model

Returns
index in the internal array

Definition at line 120 of file Model.cpp.

References Node::index, nodes, and TRACE.

Referenced by addEdge(), operator bool(), readNode(), and Brain::triggerTest().

121 {
122  if(node.index!=-1 && nodes.size()>(dword)node.index) {
123  TRACE(node.index);
124  nodes[node.index] = node;
125  return node.index;
126  }
127  int index = nodes.size();
128  //nodes[index] = node;
129  nodes.push_back(node);
130  //nodes.end()->index = index;
131  nodes[index].index = index;
132  assert(nodes[index].index == index);
133  return index;
134 }
#define TRACE(msg)
Definition: common.h:14
int index
Index in the list (Model.nodes)
Definition: Node.h:56
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
unsigned long dword
Definition: simpletypes.h:6
void Model::addNoise ( float  r)

Definition at line 901 of file Model.cpp.

References dmutil::abs(), edges, frand, and nodes.

Referenced by Searcher::mutate(), setID(), and Brain::triggerTest().

902 {
903  /*
904  for(NodeArray::iterator n = nodes.begin(); n != nodes.end(); n++) {
905  Point d(r-2*frand(r), r-2*frand(r));
906  n->ef += d;
907  }
908  */
909  for(NodeArray::iterator n = nodes.begin(); n != nodes.end(); n++) {
910  float minlen=-1;
911  for(vector<int>::const_iterator edi=n->edges.begin();
912  edi!=n->edges.end(); edi++) {
913  float elen = edges[abs(*edi)-1].length();
914  if(minlen==-1) minlen = elen;
915  else if(minlen>elen) minlen=elen;
916  }
917  float er = r*minlen;
918  Point d(er-2*frand(er), er-2*frand(er));
919  n->ef += d;
920  }
921 }
#define frand(max)
Definition: mathutil.h:48
EdgeArray edges
indexed list of edges
Definition: Model.h:263
DMatrix< T > & abs(DMatrix< T > &mat)
Definition: DMatrixUtil.h:132
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
Definition: Point.h:16
void Model::addTorque ( float  dt)

Definition at line 719 of file Model.cpp.

References edges, Node::f, Point2D::flipOrtho(), Edge::fromNode(), getNodeAngle(), m_Dataset, mapAnglePI(), nodes, Point2D::normalize(), phys, Edge::toNode(), and ParticleParam::torque.

Referenced by getMaxRadius(), and updateParticles().

719  {
720  //doesn't really work with a node array other than nodes
721  //(because of edges.fromNode()...
722  if(m_Dataset) const_cast<vuMutex&>(m_Dataset->writeMutex).lock();
723  //NodeArray &narr = tp ? *tp : nodes;
724  for(NodeArray::iterator p=nodes.begin(); p!=nodes.end();p++) {
725  if(!p->edges.empty()) {
726  float da = mapAnglePI(getNodeAngle(*p) - p->oangle);
727  //TRACE(da << " " << p->oangle << " " << getNodeAngle(*p));
728  if(da!=0.0) {
729  int eind = p->edges[0];
730  Edge &e1 = eind<0 ? edges[-eind-1]:edges[eind-1];
731  Node &n1 = eind<0 ? e1.fromNode() : e1.toNode();
732  Point d1(n1-*p);
733  d1.normalize();
734  eind = p->edges[1];
735  Edge &e2 = eind<0 ? edges[-eind-1]:edges[eind-1];
736  Node &n2 = eind<0 ? e2.fromNode() : e2.toNode();
737  Point d2(*p-n2);
738  d2.normalize();
739  Point t1 = d1.flipOrtho()*(da*phys.torque*0.5);
740  n1.f -= t1;
741  p->f += t1;
742  Point t2 = d2.flipOrtho()*(da*phys.torque*0.5);
743  n2.f -= t2;
744  p->f += t2;
745  }
746  }
747  }
748  if(m_Dataset) const_cast<vuMutex&>(m_Dataset->writeMutex).unlock();
749 }
dataset_cptr m_Dataset
Definition: Model.h:265
Implements a Node used by Model and Edge.
Definition: Node.h:13
Point f
Definition: Node.h:52
Implements an Edge with spring functionality.
Definition: Edge.h:14
ParticleParam phys
physical parameter set
Definition: Model.h:257
Node & fromNode()
Definition: Edge.h:121
EdgeArray edges
indexed list of edges
Definition: Model.h:263
float getNodeAngle(const Node &n) const
Definition: Model.cpp:605
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
const Point2D flipOrtho() const
Definition: Point.h:202
float torque
Definition: PartParam.h:68
Definition: Point.h:16
float mapAnglePI(float a)
Definition: mathutil.h:107
Node & toNode()
Definition: Edge.h:122
DMatrixf Model::adjMat ( ) const

compute undirected adjacency matrix

compute directed adjacency matrix

Definition at line 415 of file Model.cpp.

References DMatrix< T >::at(), edges, getNNodes(), DMatrix< T >::setLower(), and DMatrix< T >::transpose().

Referenced by connectNodes(), getHLNode(), and removeEdges().

416 {
417  DMatrixf adjm(getNNodes(), getNNodes(), 0.0f);
418  for(EdgeArray::const_iterator e=edges.begin(); e!=edges.end(); e++)
419  {
420  assert(e->from < getNNodes() && e->to < getNNodes());
421  adjm.at(e->from, e->to)++;
422  }
423  DMatrixf tri(getNNodes(), getNNodes());
424  tri.setLower();
425  tri*=adjm; tri.transpose();
426  adjm += tri;
427  adjm.setLower(0);
428  return adjm;
429 }
int getNNodes() const
Definition: Model.h:77
EdgeArray edges
indexed list of edges
Definition: Model.h:263
void Model::attachDataset ( dataset_cptr  dataset)

Definition at line 85 of file Model.cpp.

References adaptDataScale(), SensorCollection::addSensor(), SensorCollection::getSensor(), m_Dataset, and m_Sensors.

Referenced by MStructure::MStructure(), and setID().

85  {
86  if(m_Dataset == dataset) return;
87  m_Dataset = dataset;
88  if(m_Sensors && m_Sensors->getSensor("d0") != dataset)
89  m_Sensors->addSensor("d0",
90  std::dynamic_pointer_cast<Sensor>(
91  std::const_pointer_cast<Dataset>(dataset)));
93 }
dataset_cptr m_Dataset
Definition: Model.h:265
void adaptDataScale(dword ppmm=0)
Definition: Model.cpp:1240
sensor_ptr getSensor(const std::string &id)
Definition: SensorColl.cpp:52
SensorCollection * m_Sensors
Definition: Model.h:266
sensor_ptr addSensor(const std::string &key, sensor_ptr s)
Definition: SensorColl.cpp:24
void Model::attachSensorColl ( SensorCollection sc)
protected

set reference to and from sensor collection for correct updates

Definition at line 588 of file Model.cpp.

References m_Sensors, SensorCollection::refModel(), and SensorCollection::unrefModel().

Referenced by getHLNode(), operator=(), and ~Model().

589 {
590  if(m_Sensors == sc) return;
591  if(m_Sensors) m_Sensors->unrefModel(this);
592  if(sc) sc->refModel(this);
593  m_Sensors = sc;
594 }
void refModel(Model *model) const
Definition: SensorColl.cpp:282
SensorCollection * m_Sensors
Definition: Model.h:266
void unrefModel(Model *model) const
Definition: SensorColl.cpp:287
void Model::attract ( const Point c,
float  factor 
)

Definition at line 961 of file Model.cpp.

References nodes.

Referenced by rotate().

962 {
963  for(NodeArray::iterator n = nodes.begin(); n != nodes.end(); n++) {
964  n->ef -= (*n-c)*factor;
965  }
966 }
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
void Model::calculateDerivatives ( std::vector< NodeDerivative > &  deriv)

Definition at line 839 of file Model.cpp.

References nodes.

Referenced by getMaxRadius(), and updateParticles().

840 {
841  deriv.resize(nodes.size());
842  vector<NodeDerivative>::iterator d = deriv.begin();
843  for (NodeArray::iterator n = nodes.begin();
844  d != deriv.end(), n != nodes.end();
845  d++, n++) {
846  d->dpdt = n->v;
847  d->dvdt = n->f;
848  d->dvdt *= (1/n->mass);
849  }
850 }
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
void Model::calculateForces ( float  dt)

Definition at line 648 of file Model.cpp.

References addImageForces(), Point2D::dot(), edges, ParticleParam::gravitational, ParticleParam::imgforce, nodes, Point2D::norm(), phys, and ParticleParam::viscousdrag.

Referenced by getMaxRadius(), and updateParticles().

649 {
650  Point down(0.0f, -1.0f);
651  Point f;
652  float imgf, ifscale;
653  if(phys.imgforce == 0) {
654  imgf = 0;
655  ifscale = 0;
656  } else {
657  imgf = addImageForces(dt);
658  ifscale=1;
659  }
660  if(imgf>0.0) ifscale = ((float)phys.imgforce/imgf)*(float)nodes.size();
661  //TRACE(imgf<< " scale="<<ifscale);
662  for (NodeArray::iterator p=nodes.begin(); p!=nodes.end();p++) {
663  //if (p->fixed) continue;
664  p->f *= ifscale;
665  p->f += p->ef/dt;
666  p->ef = 0.;
667  /* Gravitation */
668  if(phys.gravitational > 0.0f)
669  p->f = (down * (phys.gravitational * p->mass));
670 
671  /* Viscous drag */
672  if(phys.viscousdrag > 0.0f)
673  p->f -= (p->v * phys.viscousdrag);
674  }
675 
676  /* Handle the spring interaction */
677  for (EdgeArray::iterator s=edges.begin(); s!=edges.end(); s++)
678  {
679  Point d = s->fromNode();
680  d -= s->toNode();
681  float len = d.norm();
682  float len1 = 1/len;
683  //spring force
684  f = (s->springconstant * (len - s->restlength));
685  //calc damping force
686  Point vd(s->fromNode().v);
687  vd -= s->toNode().v;
688  d *= len1; //spring direction normalized
689  //vd.times(d); //project velocity difference to spring
690  vd = vd.dot(d); //project velocity difference to spring
691  vd *= s->dampingconstant;
692  f += vd;
693  f *= (d*-1);
694 
695  //if not fixed - maybe
696  s->fromNode().f += f;
697  s->toNode().f -= f;
698  }
699 }
float imgforce
Definition: PartParam.h:67
ParticleParam phys
physical parameter set
Definition: Model.h:257
float norm() const
returns 2-norm aka length or absolute
Definition: Point.h:170
EdgeArray edges
indexed list of edges
Definition: Model.h:263
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
float addImageForces(float dt)
Definition: Model.cpp:701
float viscousdrag
Definition: PartParam.h:63
Definition: Point.h:16
float gravitational
Definition: PartParam.h:62
float dot(const Point2D &rhs) const
Definition: Point.h:82
void Model::clear ( )

remove and destroy all geometry information (nodes and edges)

Definition at line 95 of file Model.cpp.

References edges, m_DirNodeInd, and nodes.

Referenced by Searcher::clear(), MStructure::clear(), and reset().

96 {
97  nodes.clear();
98  edges.clear();
99  //m_Deriv.clear();
100  m_DirNodeInd=-1;
101 }
int m_DirNodeInd
Definition: Model.h:273
EdgeArray edges
indexed list of edges
Definition: Model.h:263
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
dword Model::connectNodes ( )

Connect selected nodes.

Definition at line 483 of file Model.cpp.

References adjMat(), createByAdjMat(), DMatrix< T >::min(), prepareTorque(), selMaskMat(), and DMatrix< T >::setLower().

Referenced by getHLNode(), and Brain::triggerTest().

484 {
485  DMatrixf selm = selMaskMat();
486  selm.setLower(0);
487  DMatrixf adjm = adjMat();
488  adjm.min(1);
489  DMatrixf crem(selm);
490  adjm *= selm;
491  crem -= adjm;
492  dword nc = createByAdjMat(crem);
493  if(nc) prepareTorque();
494  return nc;
495 }
void prepareTorque()
Definition: Model.cpp:713
dword createByAdjMat(const DMatrixf &adjm)
create edges mentioned in adjacency matrix
Definition: Model.cpp:468
MT & min(const MT &rhs)
Definition: DMatrix.h:129
unsigned long dword
Definition: simpletypes.h:6
DMatrixf adjMat() const
compute undirected adjacency matrix
Definition: Model.cpp:415
MT & setLower(const T &val=1, int offset=0)
Definition: DMatrix.h:250
DMatrixf selMaskMat() const
compute mask matrix of selected nodes
Definition: Model.cpp:431
Point2D & Model::convertPointFromMM ( Point2D pt) const

Definition at line 1285 of file Model.cpp.

References m_Dataset, and m_ppmm.

Referenced by convertPropFromMM(), and getDataScale().

1286 {
1287  if(m_ppmm) pt *= (float)m_ppmm;
1288  if(m_Dataset) pt += m_Dataset->getOrigin();
1289  return pt;
1290 }
dataset_cptr m_Dataset
Definition: Model.h:265
dword m_ppmm
Definition: Model.h:272
Point2D & Model::convertPointToMM ( Point2D pt) const

Definition at line 1291 of file Model.cpp.

References m_Dataset, and m_ppmm.

Referenced by MStructure::buildAllStats(), convertPropToMM(), getDataScale(), and MStructure::showStats().

1292 {
1293  if(m_Dataset) pt -= m_Dataset->getOrigin();
1294  if(m_ppmm) pt /= (float)m_ppmm;
1295  return pt;
1296 }
dataset_cptr m_Dataset
Definition: Model.h:265
dword m_ppmm
Definition: Model.h:272
PropVec & Model::convertPropFromMM ( PropVec prop) const

Definition at line 1297 of file Model.cpp.

References convertPointFromMM(), getPropPos(), getPropScale(), m_ppmm, setPropPos(), and setPropScale().

Referenced by adaptPropertiesMM(), and getDataScale().

1298 {
1299  Point2D pos(getPropPos(prop));
1300  setPropPos(prop, convertPointFromMM(pos));
1301  if(m_ppmm) setPropScale(prop, getPropScale(prop)*m_ppmm);
1302  return prop;
1303 }
Point2D getPropPos(const PropVec &prop)
Definition: PropVec.h:13
float getPropScale(const PropVec &prop)
Definition: PropVec.h:19
PropVec & setPropPos(PropVec &prop, const Point2D &p)
Definition: PropVec.h:16
dword m_ppmm
Definition: Model.h:272
Definition: Point.h:16
PropVec & setPropScale(PropVec &prop, float pscale)
Definition: PropVec.h:22
Point2D & convertPointFromMM(Point2D &pt) const
Definition: Model.cpp:1285
PropVec & Model::convertPropToMM ( PropVec prop) const

Definition at line 1304 of file Model.cpp.

References convertPointToMM(), getPropPos(), getPropScale(), m_ppmm, setPropPos(), and setPropScale().

Referenced by getDataScale(), getPropertiesMM(), and MStructure::setRefModel().

1305 {
1306  Point2D pos(getPropPos(prop));
1307  setPropPos(prop, convertPointToMM(pos));
1308  if(m_ppmm) setPropScale(prop, getPropScale(prop)/m_ppmm);
1309  return prop;
1310 }
Point2D getPropPos(const PropVec &prop)
Definition: PropVec.h:13
float getPropScale(const PropVec &prop)
Definition: PropVec.h:19
PropVec & setPropPos(PropVec &prop, const Point2D &p)
Definition: PropVec.h:16
Point2D & convertPointToMM(Point2D &pt) const
Definition: Model.cpp:1291
dword m_ppmm
Definition: Model.h:272
Definition: Point.h:16
PropVec & setPropScale(PropVec &prop, float pscale)
Definition: PropVec.h:22
dword Model::createByAdjMat ( const DMatrixf adjm)
protected

create edges mentioned in adjacency matrix

Definition at line 468 of file Model.cpp.

References addEdge(), DMatrix< T >::at(), getNNodes(), DMatrix< T >::sizeX(), and DMatrix< T >::sizeY().

Referenced by connectNodes(), and getHLNode().

469 {
470  assert(adjm.sizeX() == adjm.sizeY() && adjm.sizeX() == (dword)getNNodes());
471  dword count=0;
472  for(dword j=0; j<adjm.sizeY(); j++)
473  for(dword i=0; i<adjm.sizeX(); i++) {
474  if(adjm.at(i,j)>0.0001) {
475  addEdge(i,j);
476  count++;
477  }
478  }
479  return count;
480 }
int getNNodes() const
Definition: Model.h:77
dword sizeX() const
Definition: DMatrix.h:42
unsigned long dword
Definition: simpletypes.h:6
int addEdge(const Edge &edge)
Definition: Model.cpp:138
dword sizeY() const
Definition: DMatrix.h:43
T & at(dword x, dword y)
Definition: DMatrix.h:46
dword Model::createEdgeSensors ( float  dist = 0.1)

auto-create appropriate edge sensors (dist*stdRadius is distance)

Definition at line 622 of file Model.cpp.

References edges, and getStdRadius().

Referenced by getSensorCollection(), and Brain::triggerTest().

623 {
624  float smpdist = getStdRadius()*dist;
625  if(smpdist < 0.000001) return 0;
626  dword nsens=0;
627  for(EdgeArray::iterator e=edges.begin(); e!=edges.end(); e++)
628  {
629  if(e->fromNode().sensor == e->toNode().sensor && e->fromNode().sensor)
630  { // positive means from-node
631  nsens += (e->edgesensor = (int)(e->length()/smpdist));
632  }
633  }
634  return nsens;
635 }
float getStdRadius() const
Definition: Model.h:132
EdgeArray edges
indexed list of edges
Definition: Model.h:263
unsigned long dword
Definition: simpletypes.h:6
float Model::distance ( const Model rhs,
enum Model::DistType  kind = DIST_POINTS 
) const

Definition at line 1043 of file Model.cpp.

References DIST_CPOINTS, DIST_HPOINTS, DIST_POINTS, DIST_PVEC, DIST_XY, DIST_XYS, getCenter(), getNNodes(), getProperties(), getPropSDir(), getStdRadius(), nodes, dmutil::sqrt(), Point2D::x, and Point2D::y.

Referenced by getDataScale(), and NMerge::operator()().

1044 {
1045  switch(kind) {
1046  case DIST_XY:
1047  return (getCenter() - rhs.getCenter()).norm();
1048  break;
1049  case DIST_XYS:
1050  {
1051  float scaledist = getStdRadius() - rhs.getStdRadius();
1052  return sqrt((getCenter() - rhs.getCenter()).norm2()
1053  + scaledist*scaledist);
1054  }
1055  break;
1056  case DIST_PVEC:
1057  {
1058  PropVec prop = getProperties();
1059  PropVec rhsprop = rhs.getProperties();
1060  Point2D sd = getPropSDir(prop);
1061  Point2D rhssd = getPropSDir(rhsprop);
1062  prop[2] = sd.x; prop[3] = sd.y;
1063  rhsprop[2] = rhssd.x; rhsprop[3] = rhssd.y;
1064  return (prop - rhsprop).norm();
1065  }
1066  break;
1067  case DIST_POINTS:
1068  if(getNNodes() != rhs.getNNodes())
1069  return std::numeric_limits<float>::max();
1070  else {
1071  float dist=0;
1072  for(NodeArray::const_iterator thisn = nodes.begin(),
1073  rhsn = rhs.nodes.begin();
1074  thisn != nodes.end(); thisn++, rhsn++)
1075  {
1076  dist += (*thisn-*rhsn).norm2();
1077  }
1078  return sqrt(dist);
1079  }
1080  break;
1081  case DIST_HPOINTS: // Chamfer distance
1082  case DIST_CPOINTS: // Hausdorff distance
1083  {
1084  if(getNNodes()==0 || rhs.getNNodes()==0)
1085  return std::numeric_limits<float>::max();
1086  double dist=0;
1087  for(NodeArray::const_iterator thisn = nodes.begin();
1088  thisn != nodes.end(); thisn++)
1089  {
1090  float mindist = std::numeric_limits<float>::max();
1091  for(NodeArray::const_iterator rhsn = rhs.nodes.begin();
1092  rhsn != rhs.nodes.end(); rhsn++)
1093  {
1094  register float d = (*thisn-*rhsn).norm2();
1095  if(d<mindist) mindist = d;
1096  }
1097  if(kind == DIST_HPOINTS && mindist>dist) dist=(double)mindist;
1098  if(kind == DIST_CPOINTS ) dist += sqrt((double)mindist);
1099  }
1100  if(kind == DIST_HPOINTS) dist = sqrt(dist);
1101  if(kind == DIST_CPOINTS) dist /= getNNodes();
1102  return float(dist);
1103  }
1104  }
1105  return 0;
1106 }
const PropVec & getProperties() const
Definition: Model.cpp:1263
float getStdRadius(const Point &center) const
Returns mean squared distance from centroid.
Definition: Model.cpp:1018
float y
Definition: Point.h:224
const Point getCenter() const
Definition: Model.cpp:852
int getNNodes() const
Definition: Model.h:77
float getStdRadius() const
Definition: Model.h:132
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
Point2D getPropSDir(const PropVec &prop)
Definition: PropVec.h:31
Definition: Point.h:16
float x
Definition: Point.h:224
DMatrix< T > & sqrt(DMatrix< T > &mat)
Definition: DMatrixUtil.h:81
void Model::draw ( bool  drawPoints = false) const

Draw using OpenGL.

Definition at line 542 of file Model.cpp.

References edges, and nodes.

Referenced by Searcher::draw(), StructTable::draw(), Brain::drawAllModels(), and setID().

542  {
543  if(!edges.empty()) {
544  glBegin(GL_LINES);
545  for(EdgeArray::const_iterator e=edges.begin(); e!=edges.end(); e++)
546  {
547  e->fromNode().glVertex();
548  e->toNode().glVertex();
549  }
550  glEnd();
551  }
552  if(drawPoints && !nodes.empty()) {
553  glPointSize(3.0f);
554  glEnable(GL_POINT_SMOOTH);
555  glColor3f(0,0,1);
556  glBegin(GL_POINTS);
557  for(NodeArray::const_iterator n=nodes.begin(); n!=nodes.end(); n++)
558  {
559  n->glVertex();
560  }
561  glEnd();
562  glDisable(GL_POINT_SMOOTH);
563  glPointSize(1.0f);
564  for(NodeArray::const_iterator n=nodes.begin(); n!=nodes.end(); n++)
565  {
566  if(n->hasState()) n->draw();
567  }
568  }
569 }
EdgeArray edges
indexed list of edges
Definition: Model.h:263
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
void Model::drawPS ( CAMgraphicsProcess &  gp,
dword  mode = 0 
) const

Draw to postscrip output.

Referenced by setID().

void Model::freeze ( )

Definition at line 938 of file Model.cpp.

References edges, and prepareTorque().

Referenced by setID().

939 {
940  for(EdgeArray::iterator e = edges.begin(); e != edges.end(); e++) {
941  e->adaptRestLength();
942  }
943  prepareTorque();
944 }
void prepareTorque()
Definition: Model.cpp:713
EdgeArray edges
indexed list of edges
Definition: Model.h:263
const Point Model::getCenter ( ) const

Definition at line 852 of file Model.cpp.

References getPropPos(), m_PCFlags, m_PropVec, nodes, PC_CENTER, and setPropPos().

Referenced by adaptProperties(), MStructure::buildAllStats(), distance(), Brain::distributeModel(), Brain::evolve(), Searcher::getBindex(), getDirection(), getDirNode(), getLiveliness(), getMaxRadius(), getProperties(), getSensorCollection(), getStdRadius(), rotate(), scale(), MStructure::showStats(), and Brain::triggerTest().

852  {
853  if(!(m_PCFlags&PC_CENTER)) {
854  Point c(0,0);
855  if(!nodes.empty()) {
856  for (NodeArray::const_iterator n = nodes.begin();
857  n != nodes.end();
858  n++)
859  {
860  c+=*n;
861  }
862  c *= (1.0f/nodes.size());
863  }
864  setPropPos(m_PropVec, c);
866  }
867  return getPropPos(m_PropVec);
868 }
Point2D getPropPos(const PropVec &prop)
Definition: PropVec.h:13
PropVec & setPropPos(PropVec &prop, const Point2D &p)
Definition: PropVec.h:16
PropVec m_PropVec
Definition: Model.h:275
dword m_PCFlags
Definition: Model.h:274
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
Definition: Point.h:16
dword Model::getCRC ( ) const
inline

Definition at line 82 of file Model.h.

References m_CRC.

82 { return m_CRC; }
dword m_CRC
Definition: Model.h:271
dword Model::getDataScale ( ) const
inline
float Model::getDeformation ( ) const

normalized length variation to compensate for different sizes

Definition at line 995 of file Model.cpp.

References edges, getLengthRatio(), scale(), ParticleParam::springconst, and dmutil::sqrt().

Referenced by getMaxRadius(), getQualityOfFit(), and Brain::triggerTest().

995  {
996  if(edges.empty()) return 0.0;
997  float vlengths=0,restlengths=0;
998  float scale = 1/getLengthRatio();
999  float scscale = 1/ParticleParam::global.springconst;
1000  for(EdgeArray::const_iterator e = edges.begin(); e != edges.end(); e++) {
1001  register float dl = e->restlength-e->length()*scale;
1002  //dl *= e->springconstant*scscale; // weight by relative springconst
1003  vlengths+=dl*dl;
1004  restlengths+=e->restlength;
1005  }
1006  register float n = edges.size();
1007  return sqrt(vlengths*n)/(restlengths);
1008 }
static ParticleParam global
Definition: PartParam.h:72
void scale(float factor, bool movepoints=false)
multiply all rest lengths by factor
Definition: Model.cpp:1140
EdgeArray edges
indexed list of edges
Definition: Model.h:263
float getLengthRatio() const
relation of overall edge length by overall rest length sum
Definition: Model.cpp:968
float springconst
Definition: PartParam.h:64
DMatrix< T > & sqrt(DMatrix< T > &mat)
Definition: DMatrixUtil.h:81
float Model::getDirection ( ) const

Definition at line 890 of file Model.cpp.

References getCenter(), getDirNode(), getPropDir(), m_PCFlags, m_PropVec, mapAngle2PI(), nodes, PC_DIR, and setPropDir().

Referenced by adaptProperties(), getProperties(), and getSensorCollection().

890  {
891  if(!(m_PCFlags&PC_DIR)) {
892  setPropDir(m_PropVec, nodes.empty() ? 0 :
893  mapAngle2PI((getDirNode()-getCenter()).angle()) );
894  m_PCFlags|=PC_DIR;
895  }
896  return getPropDir(m_PropVec);
897 }
const Node & getDirNode() const
Definition: Model.cpp:870
float mapAngle2PI(float a)
Definition: mathutil.h:97
const Point getCenter() const
Definition: Model.cpp:852
PropVec & setPropDir(PropVec &prop, float dir)
Definition: PropVec.h:28
PropVec m_PropVec
Definition: Model.h:275
float getPropDir(const PropVec &prop)
Definition: PropVec.h:25
dword m_PCFlags
Definition: Model.h:274
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
const Node & Model::getDirNode ( ) const

Definition at line 870 of file Model.cpp.

References getCenter(), getNNodes(), getNode(), m_DirNodeInd, and nodes.

Referenced by Brain::doCommand(), getDirection(), and getSensorCollection().

870  {
871  static const Node dummy;
872  if(!getNNodes()) return dummy;
873  if(m_DirNodeInd < 0) {
874  Point c = getCenter();
875  float cdist = -1.;
876  dword cind = 0;
877  for(NodeArray::const_iterator n=nodes.begin();
878  n!=nodes.end(); n++, cind++)
879  {
880  float dist = (*n-c).norm2();
881  if(cdist < dist) {
882  cdist = dist;
883  m_DirNodeInd = cind;
884  }
885  }
886  }
887  return getNode(m_DirNodeInd);
888 }
Implements a Node used by Model and Edge.
Definition: Node.h:13
int m_DirNodeInd
Definition: Model.h:273
const Point getCenter() const
Definition: Model.cpp:852
int getNNodes() const
Definition: Model.h:77
const Node & getNode(int index) const
Definition: Model.h:74
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
unsigned long dword
Definition: simpletypes.h:6
Definition: Point.h:16
const Edge& Model::getEdge ( int  index) const
inline

Definition at line 71 of file Model.h.

References edges.

Referenced by MStructure::buildMasterModel(), and Brain::triggerTest().

71 { return edges[index]; }
EdgeArray edges
indexed list of edges
Definition: Model.h:263
Edge& Model::getEdge ( int  index)
inline

Definition at line 72 of file Model.h.

References edges.

72 { return edges[index]; }
EdgeArray edges
indexed list of edges
Definition: Model.h:263
float Model::getEdgeSensorFit ( dword npts = NULL) const

get average fit of sensors along edges

Definition at line 1191 of file Model.cpp.

References edges.

Referenced by getMaxRadius(), getQualityOfFit(), and Brain::triggerTest().

1192 {
1193  if(edges.empty()) { if(npts) *npts = 0; return 0.0; }
1194  float fit = 0;
1195  dword npoints = 0;
1196  for(EdgeArray::const_iterator e = edges.begin(); e != edges.end(); e++) {
1197  float i=e->getSensorValue(fit, npoints);
1198  }
1199  if(npoints) fit /= (float)npoints;
1200  if(npts) *npts = npoints;
1201  return fit;
1202 }
EdgeArray edges
indexed list of edges
Definition: Model.h:263
unsigned long dword
Definition: simpletypes.h:6
const std::string& Model::getFilename ( ) const
inline

Definition at line 225 of file Model.h.

References m_Filename, and setHLNode().

Referenced by Brain::triggerTest(), and MStructure::write().

225 { return m_Filename; }
std::string m_Filename
Definition: Model.h:281
dword& Model::getFlags ( )
inline

Definition at line 196 of file Model.h.

References m_Flags.

Referenced by Searcher::add(), and Brain::triggerTest().

196 { return m_Flags; }
dword m_Flags
Definition: Model.h:269
float Model::getFullLength ( ) const

Returns overall sum of edge lengths.

Definition at line 1010 of file Model.cpp.

References edges.

Referenced by rotate().

1010  {
1011  float length=0;
1012  for(EdgeArray::const_iterator e = edges.begin(); e != edges.end(); e++) {
1013  length += e->length();
1014  }
1015  return length;
1016 }
EdgeArray edges
indexed list of edges
Definition: Model.h:263
int Model::getHLNode ( ) const
inline

Returns ID of highlighted node. Value is -1 if none is selected.

Definition at line 231 of file Model.h.

References adjMat(), attachSensorColl(), connectNodes(), createByAdjMat(), getSelectedNodesN(), m_HLNode, rebuildIndexTables(), removeByAdjMat(), removeEdges(), removeNode(), selMaskMat(), and Node::ST_SELECT.

Referenced by Brain::triggerTest().

231 { return m_HLNode; }
int m_HLNode
Definition: Model.h:283
dword Model::getID ( ) const
inline

Definition at line 83 of file Model.h.

References m_ID.

Referenced by Winner::setModel().

83 { return m_ID; }
dword m_ID
Definition: Model.h:284
dword Model::getInstCount ( ) const
inline

Definition at line 222 of file Model.h.

References m_InstCount.

222 { return m_InstCount; }
dword m_InstCount
number of merged instances
Definition: Model.h:280
float Model::getLengthRatio ( ) const

relation of overall edge length by overall rest length sum

Definition at line 968 of file Model.cpp.

References edges.

Referenced by adaptProportion(), getDeformation(), and getMaxRadius().

968  {
969  float lengths=0,restlengths=0;
970  for(EdgeArray::const_iterator e = edges.begin(); e != edges.end(); e++) {
971  lengths+=e->length();
972  restlengths+=e->restlength;
973  }
974  return lengths/restlengths;
975 #ifdef NOTLENGTHWEIGHTED
976  float lenrat=0;
977  for(EdgeArray::const_iterator e = edges.begin(); e != edges.end(); e++) {
978  lenrat += e->lengthRatio();
979  }
980  return lenrat/(float)edges.size();
981 #endif
982 }
EdgeArray edges
indexed list of edges
Definition: Model.h:263
float Model::getLengthVariation ( ) const

mean squared difference from restlength normalized by restlength sum

Definition at line 984 of file Model.cpp.

References edges, and dmutil::sqrt().

Referenced by getMaxRadius().

984  {
985  float vlengths=0,restlengths=0;
986  for(EdgeArray::const_iterator e = edges.begin(); e != edges.end(); e++) {
987  register float dl = e->restlength-e->length();
988  vlengths+=dl*dl;
989  restlengths+=e->restlength;
990  }
991  register float n = edges.size();
992  return sqrt(vlengths*n)/(restlengths);
993 }
EdgeArray edges
indexed list of edges
Definition: Model.h:263
DMatrix< T > & sqrt(DMatrix< T > &mat)
Definition: DMatrixUtil.h:81
float Model::getLiveliness ( ) const

Definition at line 1222 of file Model.cpp.

References edges, getCenter(), m_Liveliness, m_PCFlags, nodes, PC_LIVE, and dmutil::sqrt().

Referenced by MStructure::buildMasterModel(), and setID().

1223 {
1224  if(m_PCFlags&PC_LIVE) return m_Liveliness;
1225  m_Liveliness = 0;
1226  if(!nodes.empty() && !edges.empty()) {
1227  float dist= 0;
1228  Point c = getCenter();
1229  for(NodeArray::const_iterator n = nodes.begin(); n != nodes.end(); n++)
1230  {
1231  m_Liveliness += n->v.norm();
1232  dist += (c-*n).norm2();
1233  }
1234  if(dist > 0.00001) m_Liveliness /= sqrt(dist);
1235  }
1236  m_PCFlags|=PC_LIVE;
1237  return m_Liveliness;
1238 }
const Point getCenter() const
Definition: Model.cpp:852
EdgeArray edges
indexed list of edges
Definition: Model.h:263
dword m_PCFlags
Definition: Model.h:274
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
float m_Liveliness
Definition: Model.h:277
Definition: Point.h:16
DMatrix< T > & sqrt(DMatrix< T > &mat)
Definition: DMatrixUtil.h:81
float Model::getMaxRadius ( const Point center) const

Returns the maximum radius from the centroid.

Definition at line 1032 of file Model.cpp.

References nodes, and dmutil::sqrt().

1032  {
1033  if(nodes.empty()) return 0;
1034  float dist = 0;
1035  for(NodeArray::const_iterator n = nodes.begin(); n != nodes.end(); n++) {
1036  register float td = (*n-center).norm2();
1037  if(dist<td) dist=td;
1038  }
1039  return sqrt(dist);
1040  //return (center-getDirNode()).norm();
1041 }
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
DMatrix< T > & sqrt(DMatrix< T > &mat)
Definition: DMatrixUtil.h:81
float Model::getMaxRadius ( ) const
inline
const std::string& Model::getName ( ) const
inline

Definition at line 81 of file Model.h.

References m_Name.

Referenced by Brain::Brain(), Searcher::evolve(), Winner::setModel(), Searcher::triggerTest(), and Brain::triggerTest().

81 { return m_Name; }
std::string m_Name
Definition: Model.h:270
int Model::getNEdges ( ) const
inline

Definition at line 78 of file Model.h.

References edges, getNodeAngle(), and setName().

Referenced by MStructure::buildMasterModel(), and Brain::triggerTest().

78 { return edges.size(); }
EdgeArray edges
indexed list of edges
Definition: Model.h:263
int Model::getNNodes ( ) const
inline
const Node& Model::getNode ( int  index) const
inline

Definition at line 74 of file Model.h.

References nodes.

Referenced by MStructure::addExpectation(), MStructure::buildAllStats(), getDirNode(), setHLNode(), MStructure::showStats(), and Brain::triggerTest().

74 { return nodes[index]; }
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
Node& Model::getNode ( int  index)
inline

Definition at line 75 of file Model.h.

References nodes.

75 { return nodes[index]; }
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
float Model::getNodeAngle ( const Node n) const

Definition at line 605 of file Model.cpp.

References Point2D::angle(), Node::edges, and edges.

Referenced by addTorque(), getNEdges(), and prepareTorque().

605  {
606  if(n.edges.size()>=2) {
607  int eind1 = n.edges[0];
608  Point e1 = eind1<0 ? edges[-eind1-1].idir() : edges[eind1-1].dir();
609  int eind2 = n.edges[1];
610  Point e2 = eind2<0 ? edges[-eind2-1].idir() : edges[eind2-1].dir();
611  //TRACE(e1<<" "<<e2<<" "<<e1.angle(e2));
612  return e1.angle(e2);
613  } return 0.0;
614 }
std::vector< int > edges
Definition: Node.h:60
float angle(const Point2D &rhs=Point2D(1, 0)) const
Definition: Point.h:93
EdgeArray edges
indexed list of edges
Definition: Model.h:263
Definition: Point.h:16
const PropVec & Model::getProperties ( ) const

Definition at line 1263 of file Model.cpp.

References getCenter(), getDirection(), getStdRadius(), m_PCFlags, m_PropVec, PC_CENTER, PC_DIR, PC_PVEC, and PC_SCALE.

Referenced by MStructure::addExpectation(), Searcher::buildBins(), Searcher::cleanFlags(), distance(), Searcher::distribute(), Brain::doCommand(), getDataScale(), getPropertiesMM(), main(), Searcher::mutate(), MStructure::setRefModel(), and Brain::triggerTest().

1264 {
1265  if((m_PCFlags&PC_PVEC) != PC_PVEC) {
1266  if((m_PCFlags&PC_CENTER) == 0) getCenter(); //setPropPos(m_PropVec,..
1267  if((m_PCFlags&PC_SCALE) == 0) getStdRadius();
1268  if((m_PCFlags&PC_DIR) == 0) getDirection();
1269  }
1270  return m_PropVec;
1271 }
float getDirection() const
Definition: Model.cpp:890
const Point getCenter() const
Definition: Model.cpp:852
PropVec m_PropVec
Definition: Model.h:275
float getStdRadius() const
Definition: Model.h:132
dword m_PCFlags
Definition: Model.h:274
PropVec Model::getPropertiesMM ( ) const

return property vector using millimeter scale

Definition at line 1274 of file Model.cpp.

References convertPropToMM(), and getProperties().

Referenced by getDataScale(), and MStructure::rebuildExpMap().

1275 {
1276  PropVec prop(getProperties());
1277  convertPropToMM(prop);
1278  return prop;
1279 }
PropVec & convertPropToMM(PropVec &prop) const
Definition: Model.cpp:1304
const PropVec & getProperties() const
Definition: Model.cpp:1263
float Model::getQualityOfFit ( ) const

Definition at line 1204 of file Model.cpp.

References dmutil::abs(), edges, getDeformation(), getEdgeSensorFit(), getSensorFit(), m_Dataset, m_PCFlags, m_QOF, m_ShapeWeight, nodes, and PC_QOF.

Referenced by MStructure::addExpectation(), Searcher::cleanFlags(), Searcher::distribute(), Brain::distributeModel(), Brain::drawAllModels(), Searcher::evolve(), Brain::evolve(), StructTable::findBestConnection(), std::greater< Model * >::operator()(), StructPath::print(), setID(), and Brain::triggerTest().

1205 {
1206  if(m_PCFlags&PC_QOF) return m_QOF;
1207  if(nodes.empty() || edges.empty()
1208  || !m_Dataset || !m_Dataset->initialized()) m_QOF=0;
1209  else {
1210  dword nns=0, nes=0;
1211  float ns = getSensorFit(&nns); // node sensors
1212  float es = getEdgeSensorFit(&nes); // edge sensors
1213  m_QOF = (es*nes+ns*nns)/float(nns+nes);
1214  //DEBUG: use deformation*10?
1215  register float lv = getDeformation(); //getLengthVariation();
1216  m_QOF = (1-m_ShapeWeight)*m_QOF + (m_ShapeWeight)*exp(-5*abs(lv));
1217  }
1218  m_PCFlags|=PC_QOF;
1219  return m_QOF;
1220 }
float m_QOF
Definition: Model.h:276
dataset_cptr m_Dataset
Definition: Model.h:265
float getEdgeSensorFit(dword *npts=NULL) const
get average fit of sensors along edges
Definition: Model.cpp:1191
float m_ShapeWeight
Definition: Model.h:268
float getSensorFit(dword *npts=NULL) const
get average sensor value
Definition: Model.cpp:1173
EdgeArray edges
indexed list of edges
Definition: Model.h:263
DMatrix< T > & abs(DMatrix< T > &mat)
Definition: DMatrixUtil.h:132
dword m_PCFlags
Definition: Model.h:274
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
unsigned long dword
Definition: simpletypes.h:6
float getDeformation() const
normalized length variation to compensate for different sizes
Definition: Model.cpp:995
dword Model::getSelectedNodesN ( dword  state = Node::ST_SELECT) const

get number of selected nodes

Definition at line 1334 of file Model.cpp.

References nodes.

Referenced by getHLNode(), and Brain::triggerTest().

1335 {
1336  dword count=0;
1337  for(NodeArray::const_iterator n = nodes.begin(); n != nodes.end(); n++)
1338  if(n->hasState(state)) count++;
1339  return count;
1340 }
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
unsigned long dword
Definition: simpletypes.h:6
SensorCollection* Model::getSensorCollection ( )
inline

Definition at line 168 of file Model.h.

References createEdgeSensors(), getCenter(), getDirection(), getDirNode(), m_Sensors, and reattachSensors().

Referenced by Brain::triggerTest().

168 { return m_Sensors; }
SensorCollection * m_Sensors
Definition: Model.h:266
float Model::getSensorFit ( dword npts = NULL) const

get average sensor value

Definition at line 1173 of file Model.cpp.

References nodes.

Referenced by getMaxRadius(), getQualityOfFit(), and Brain::triggerTest().

1174 {
1175  if(nodes.empty()) { if(npts) *npts = 0; return 0.0; }
1176  float fit = 0;
1177  dword nsns = 0;
1178  for(NodeArray::const_iterator n = nodes.begin(); n != nodes.end(); n++)
1179  if(n->sensor) {
1180  float i=n->sensor->getWeightedValue((int)n->x,(int)n->y);
1181  //float gm = n->sensor->getGradient(*n).norm();
1182  //float vel = n->v.norm();
1183  fit += i;
1184  nsns++;
1185  }
1186  if(nsns) fit /= (float)nsns;
1187  if(npts) *npts = nsns;
1188  return fit;
1189 }
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
unsigned long dword
Definition: simpletypes.h:6
float Model::getStdRadius ( const Point center) const

Returns mean squared distance from centroid.

Definition at line 1018 of file Model.cpp.

References getPropScale(), m_PCFlags, m_PropVec, nodes, PC_SCALE, setPropScale(), and dmutil::sqrt().

Referenced by distance(), Brain::distributeModel(), Brain::evolve(), Searcher::mutate(), and Brain::setupSearch().

1018  {
1020  float dist = 0;
1021  if(!nodes.empty()) {
1022  for(NodeArray::const_iterator n = nodes.begin(); n != nodes.end(); n++)
1023  dist += (*n-center).norm2();
1024  dist /= (float)nodes.size();
1025  dist = sqrt(dist);
1026  }
1027  setPropScale(m_PropVec, dist);
1029  return dist;
1030 }
float getPropScale(const PropVec &prop)
Definition: PropVec.h:19
PropVec m_PropVec
Definition: Model.h:275
dword m_PCFlags
Definition: Model.h:274
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
PropVec & setPropScale(PropVec &prop, float pscale)
Definition: PropVec.h:22
DMatrix< T > & sqrt(DMatrix< T > &mat)
Definition: DMatrixUtil.h:81
float Model::getStdRadius ( ) const
inline

Definition at line 132 of file Model.h.

References getCenter(), getMaxRadius(), and getStdRadius().

Referenced by adaptProperties(), createEdgeSensors(), distance(), getProperties(), getStdRadius(), and rotate().

132 { return getStdRadius(getCenter());}
const Point getCenter() const
Definition: Model.cpp:852
float getStdRadius() const
Definition: Model.h:132
bool Model::hasFlags ( dword  flags) const
inline

Definition at line 197 of file Model.h.

References m_Flags.

Referenced by mergeModel().

197 { return m_Flags & flags; }
dword m_Flags
Definition: Model.h:269
void Model::invalidatePC ( dword  pcflags = PC_ALL)
inline

Definition at line 220 of file Model.h.

References m_PCFlags.

Referenced by rotate(), scale(), setDirNode(), setShapeWeight(), translate(), and updateParticles().

220 { m_PCFlags &= ~pcflags; }
dword m_PCFlags
Definition: Model.h:274
bool Model::isLooser ( )
inline

Definition at line 190 of file Model.h.

References m_Flags, and ST_LOOSER.

190 { return m_Flags&ST_LOOSER; }
dword m_Flags
Definition: Model.h:269
bool Model::isOldState ( )
inline

Definition at line 195 of file Model.h.

References m_Flags, and ST_OLDSTATE.

195 { return m_Flags&ST_OLDSTATE; }
dword m_Flags
Definition: Model.h:269
bool Model::isWinner ( )
inline

Definition at line 184 of file Model.h.

References m_Flags, and ST_WINNER.

184 { return m_Flags&ST_WINNER; }
dword m_Flags
Definition: Model.h:269
dword Model::mergeModel ( Model mergemod)

Definition at line 1312 of file Model.cpp.

References hasFlags(), m_ID, m_InstCount, m_TimeStamp, setFlags(), ST_DEL, and ST_NODEL.

Referenced by setInstCount().

1313 {
1314  if(&mergemod != this && !mergemod.hasFlags(Model::ST_DEL)) {
1315  m_InstCount += mergemod.m_InstCount;
1316  mergemod.m_InstCount=0;
1317  bool mergeID = false;
1318  if(m_TimeStamp > mergemod.m_TimeStamp) {
1319  m_TimeStamp = mergemod.m_TimeStamp;
1320  mergeID = mergemod.m_ID != 0;
1321  } else mergeID = (m_ID==0 && mergemod.m_ID != 0);
1322  if(mergeID) {
1323  m_ID = mergemod.m_ID;
1324  mergemod.m_ID = 0;
1325  if(mergemod.hasFlags(Model::ST_NODEL)) {
1327  }
1328  }
1329  mergemod.setFlags(Model::ST_DEL);
1330  }
1331  return m_InstCount;
1332 }
bool hasFlags(dword flags) const
Definition: Model.h:197
dword & setFlags(dword flags)
Definition: Model.h:198
dword m_InstCount
number of merged instances
Definition: Model.h:280
dword m_ID
Definition: Model.h:284
float m_TimeStamp
time stamps (see. TTimeStamp)
Definition: Model.h:259
void Model::mergeSensorCollection ( SensorCollection sensors)

Definition at line 596 of file Model.cpp.

References m_Sensors, SensorCollection::merge(), and NULL.

Referenced by getMaxRadius(), and MStructure::MStructure().

597 {
598  if(!sensors) return;
599  if(m_Sensors != NULL) {
600  sensors->merge(*m_Sensors);
601  }
602  m_Sensors = sensors;
603 }
#define NULL
Definition: simpletypes.h:9
SensorCollection * m_Sensors
Definition: Model.h:266
SensorCollection & merge(SensorCollection &rhs)
Definition: SensorColl.cpp:256
int Model::nearestNode ( const Point pos,
float &  dist = *(float*)(NULL) 
) const

Definition at line 1108 of file Model.cpp.

References nodes, and dmutil::sqrt().

Referenced by getDataScale(), and Brain::triggerTest().

1109 {
1110  if(nodes.empty()) return -1;
1111  int rid=0, cid=0;
1112  float tdist;
1113  float& mindist = &dist ? dist : tdist;
1114  rid = 0;
1115  mindist = std::numeric_limits<float>::max();
1116  for(NodeArray::const_iterator ni = nodes.begin();
1117  ni != nodes.end(); ni++, cid++)
1118  {
1119  register float d = (pos-*ni).norm2();
1120  if(d<mindist) { mindist = d; rid = cid; }
1121  }
1122  mindist = sqrt(mindist);
1123  return rid;
1124 }
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
DMatrix< T > & sqrt(DMatrix< T > &mat)
Definition: DMatrixUtil.h:81
Model::operator bool ( ) const
inline

is initialized?

Definition at line 55 of file Model.h.

References addEdge(), addNode(), nodes, and reset().

55 { return !nodes.empty(); }
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
Model & Model::operator= ( const Model rhs)

Definition at line 50 of file Model.cpp.

References attachSensorColl(), edges, m_CRC, m_Dataset, m_DirNodeInd, m_Filename, m_Flags, m_HLNode, m_ID, m_InstCount, m_Liveliness, m_Name, m_PCFlags, m_ppmm, m_PropVec, m_QOF, m_SensorFile, m_Sensors, m_ShapeWeight, m_TimeStamp, nodes, and phys.

Referenced by Model(), and setID().

51 {
52  if(&rhs == this) return *this;
53  m_Dataset = rhs.m_Dataset;
56  nodes = rhs.nodes;
57  edges = rhs.edges;
58  for(EdgeArray::iterator e=edges.begin(); e!=edges.end(); e++)
59  {
60  e->setNodesList(nodes);
61  }
62  m_Flags = rhs.m_Flags;
63 // phys.gravitational = rhs.phys.gravitational;
64 // phys.viscousdrag = rhs.phys.viscousdrag;
65  phys = rhs.phys;
66  m_Name = rhs.m_Name;
67  m_CRC = rhs.m_CRC;
68  m_ppmm = rhs.m_ppmm;
71  m_PCFlags = rhs.m_PCFlags;
72  m_PropVec = rhs.m_PropVec;
75  m_QOF = rhs.m_QOF;
77  m_Filename = rhs.m_Filename;
78  m_HLNode = rhs.m_HLNode;
79  //m_Deriv = rhs.m_Deriv;
80  //m_LastDT = rhs.m_LastDT;
81  m_ID = rhs.m_ID;
82  return *this;
83 }
float m_QOF
Definition: Model.h:276
dataset_cptr m_Dataset
Definition: Model.h:265
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
float m_ShapeWeight
Definition: Model.h:268
int m_HLNode
Definition: Model.h:283
dword m_CRC
Definition: Model.h:271
void attachSensorColl(SensorCollection *sc)
set reference to and from sensor collection for correct updates
Definition: Model.cpp:588
SensorCollection * m_Sensors
Definition: Model.h:266
PropVec m_PropVec
Definition: Model.h:275
EdgeArray edges
indexed list of edges
Definition: Model.h:263
dword m_PCFlags
Definition: Model.h:274
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
dword m_ppmm
Definition: Model.h:272
dword m_Flags
Definition: Model.h:269
float m_Liveliness
Definition: Model.h:277
dword m_InstCount
number of merged instances
Definition: Model.h:280
dword m_ID
Definition: Model.h:284
float m_TimeStamp
time stamps (see. TTimeStamp)
Definition: Model.h:259
void Model::prepareTorque ( )

Definition at line 713 of file Model.cpp.

References getNodeAngle(), and nodes.

Referenced by connectNodes(), freeze(), getMaxRadius(), operator>>(), removeEdges(), removeNode(), and Brain::triggerTest().

713  {
714  for(NodeArray::iterator p=nodes.begin(); p!=nodes.end();p++) {
715  p->oangle = getNodeAngle(*p);
716  }
717 }
float getNodeAngle(const Node &n) const
Definition: Model.cpp:605
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
void Model::push ( const Point t)

Definition at line 931 of file Model.cpp.

References nodes.

Referenced by Searcher::mutate(), and setID().

932 {
933  for(NodeArray::iterator n = nodes.begin(); n != nodes.end(); n++) {
934  n->f += t;
935  }
936 }
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
void Model::pushRotate ( const Point c,
float  angle 
)

Definition at line 954 of file Model.cpp.

References nodes.

Referenced by Searcher::mutate(), and rotate().

955 {
956  for(NodeArray::iterator n = nodes.begin(); n != nodes.end(); n++) {
957  n->ef += (*n-c).flipOrtho().copyNormalized()*angle;
958  }
959 }
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
bool Model::readEdge ( ParseFile is)

read edge from stream

Definition at line 167 of file Model.cpp.

References addEdge(), Edge::dampingconstant, edges, Edge::edgesensor, ParseFile::getKey(), ParseFile::getNextLine(), ParseFile::getValue(), nodes, ParseFile::pushLine(), Edge::restlength, ParseFile::setParseError(), and Edge::springconstant.

Referenced by operator>>(), and setID().

168 {
169  if(!is.getNextLine()) return false;
170  if(is.getKey() != "e") {
171  is.pushLine();
172  return false;
173  }
174  istringstream vs(is.getValue());
175  vs >> ws;
176  int from, to;
177  vs >> from;
178  from--;
179  int size = nodes.size();
180  if(from<0 || from>size-1) throw new IOException("Edge is made of node indices that don't exist.");
181  vs >> to;
182  to--;
183  if(to<0 || to>size-1) throw new IOException("Edge is made of node indices that don't exist.");
184  Edge &ed = edges[addEdge(from, to)];
185  string param;
186  while(vs >> param) {
187  if(param == "sc")
188  vs >> ed.springconstant;
189  else if(param == "dc")
190  vs >> ed.dampingconstant;
191  else if(param == "rl")
192  vs >> ed.restlength;
193  else if(param == "es") {
194  char ft = 0;
195  vs >> ft;
196  if(ft == 'f') vs >> ed.edgesensor;
197  else if(ft == 't') { vs >> ed.edgesensor; ed.edgesensor *= -1; }
198  else {
199  is.setParseError("error reading edge parameter [es]");
200  throw new IOException("error reading edge parameter [es]");
201  }
202  } else {
203  is.setParseError("error reading edge parameters");
204  throw new IOException("error reading edge parameters");
205  }
206  }
207  return true;
208 }
float dampingconstant
damping constant
Definition: Edge.h:136
Implements an Edge with spring functionality.
Definition: Edge.h:14
const std::string & getValue() const
Definition: ParseFile.h:57
int edgesensor
0-none, >0-use from sensor n times, <0 use to sensor
Definition: Edge.h:137
float springconstant
spring constant
Definition: Edge.h:134
EdgeArray edges
indexed list of edges
Definition: Model.h:263
const std::string & getKey() const
Definition: ParseFile.h:56
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
int addEdge(const Edge &edge)
Definition: Model.cpp:138
float restlength
Definition: Edge.h:132
void setParseError(const std::string &msg="")
Definition: ParseFile.h:80
void pushLine(const std::string &line)
Definition: ParseFile.h:74
const bool getNextLine()
Definition: ParseFile.h:59
bool Model::readFile ( const char *  filename,
bool  fullread = true 
)

Read geometry from file. See operator>>() for further details.

Definition at line 365 of file Model.cpp.

References IOException::getMessage(), and reset().

Referenced by Brain::doCommand(), MStructure::getRefModel(), Brain::loadModel(), main(), MStructure::read(), and setID().

366 {
367  ParseFile is(filename);
368  if(is) {
369  try {
370  is >> *this;
371  } catch (const IOException *e) {
372  cerr << "IOException: " << e->getMessage() << endl
373  << "reading file " << filename << endl;
374  reset();
375  return false;
376  }
377  return true;
378  } else return false;
379 }
const char * getMessage() const
Definition: Errors.h:41
void reset()
reset all model information (including geometry)
Definition: Model.cpp:103
bool Model::readNode ( ParseFile is)

read node from stream

Definition at line 210 of file Model.cpp.

References addNode(), Node::attachSensor(), ParseFile::getKey(), ParseFile::getNextLine(), SensorCollection::getSensor(), ParseFile::getValue(), getZeroSensor(), m_Sensors, Node::mass, phys, ParseFile::pushLine(), ParseFile::setParseError(), Point2D::x, and Point2D::y.

Referenced by operator>>(), and setID().

211 {
212  if(!is.getNextLine()) return false;
213  if(is.getKey() != "v") {
214  is.pushLine();
215  return false;
216  }
217  istringstream vs(is.getValue());
218  vs >> ws;
219  Node n(&phys);
220  vs >> n.x;
221  vs >> n.y;
222  n.attachSensor(getZeroSensor());
223  string param;
224  while(vs >> param) {
225  if(param == "s") {
226  vs >> param;
227  if(m_Sensors) n.attachSensor(m_Sensors->getSensor(param));
228  else {
229  is.setParseError("tried to load undefined sensor");
230  throw new IOException("tried to load undefined sensor");
231  }
232  } else if(param == "m")
233  vs >> n.mass;
234  else {
235  is.setParseError("error reading node parameters");
236  throw new IOException("error reading node parameters");
237  }
238  }
239  addNode(n);
240  //debugline: cout << addNode(n) << " - " << n << endl;
241  return true;
242 }
Implements a Node used by Model and Edge.
Definition: Node.h:13
ParticleParam phys
physical parameter set
Definition: Model.h:257
sensor_ptr getSensor(const std::string &id)
Definition: SensorColl.cpp:52
const std::string & getValue() const
Definition: ParseFile.h:57
sensor_ptr getZeroSensor()
Definition: Sensor.cpp:234
SensorCollection * m_Sensors
Definition: Model.h:266
const std::string & getKey() const
Definition: ParseFile.h:56
int addNode(const Node &node)
Definition: Model.cpp:120
void setParseError(const std::string &msg="")
Definition: ParseFile.h:80
void pushLine(const std::string &line)
Definition: ParseFile.h:74
const bool getNextLine()
Definition: ParseFile.h:59
bool Model::readParameter ( ParseFile is)

read model parameters

Definition at line 263 of file Model.cpp.

References ParticleParam::damping, ParseFile::getKey(), ParseFile::getNextLine(), ParseFile::getValue(), ParticleParam::gravitational, ParticleParam::imgforce, m_DirNodeInd, m_ppmm, ParticleParam::mass, phys, ParseFile::pushLine(), setName(), ParticleParam::springconst, ParticleParam::torque, and ParticleParam::viscousdrag.

Referenced by operator>>(), and setID().

264 {
265  if(!is.getNextLine()) return false;
266  if(is.getKey() != "p") {
267  is.pushLine();
268  return false;
269  }
270  istringstream vs(is.getValue());
271  string pname;
272  vs >> pname;
273  if(pname == "mass") {
274  vs >> phys.mass;
275  } else if(pname == "springconst") {
276  vs >> phys.springconst;
277  } else if(pname == "grav") {
278  vs >> phys.gravitational;
279  } else if(pname == "viscousdrag") {
280  vs >> phys.viscousdrag;
281  } else if(pname == "damping") {
282  vs >> phys.damping;
283  } else if(pname == "imageforce") {
284  vs >> phys.imgforce;
285  } else if(pname == "torque") {
286  vs >> phys.torque;
287  } else if(pname == "name") {
288  string name;
289  vs >> name;
290  setName(name);
291  } else if(pname == "ppmm") {
292  vs >> m_ppmm;
293  } else if(pname == "dirnode") {
294  vs >> m_DirNodeInd;
295  }
296  return true;
297 }
float imgforce
Definition: PartParam.h:67
int m_DirNodeInd
Definition: Model.h:273
ParticleParam phys
physical parameter set
Definition: Model.h:257
const std::string & getValue() const
Definition: ParseFile.h:57
float mass
Definition: PartParam.h:66
const std::string & getKey() const
Definition: ParseFile.h:56
void setName(const std::string &name)
Definition: Model.cpp:399
float damping
Definition: PartParam.h:65
float viscousdrag
Definition: PartParam.h:63
float torque
Definition: PartParam.h:68
dword m_ppmm
Definition: Model.h:272
float springconst
Definition: PartParam.h:64
void pushLine(const std::string &line)
Definition: ParseFile.h:74
float gravitational
Definition: PartParam.h:62
const bool getNextLine()
Definition: ParseFile.h:59
bool Model::readSensor ( ParseFile is)

read sensor from stream

Definition at line 244 of file Model.cpp.

References SensorCollection::addSensor(), ParseFile::getKey(), ParseFile::getNextLine(), ParseFile::getPath(), ParseFile::getValue(), m_SensorFile, m_Sensors, ParseFile::pushLine(), and SensorCollection::readSensor().

Referenced by operator>>(), and setID().

245 {
246  if(!is.getNextLine()) return false;
247  if(is.getKey() == "sensors") {
248  ParseFile sf(is.getPath()+is.getValue());
249  if(sf) {
250  m_SensorFile = is.getValue();
251  while(sf) readSensor(sf);
252  } else cerr << "couldn't load sensor file "
253  << is.getPath()+is.getValue() << endl;
254  } else is.pushLine();
255  if(!m_Sensors) m_Sensors = new SensorCollection();
257  if(!s) return false;
258  m_Sensors->addSensor(s);
259  //s->enableUpdate(Sensor::UPD_MINMAX); done in Node::attachSensor
260  return true;
261 }
std::string m_SensorFile
Definition: Model.h:267
bool readSensor(ParseFile &is)
read sensor from stream
Definition: Model.cpp:244
std::shared_ptr< Sensor > sensor_ptr
Definition: types_fwd.h:15
const std::string & getValue() const
Definition: ParseFile.h:57
SensorCollection * m_Sensors
Definition: Model.h:266
const std::string & getPath() const
Definition: ParseFile.h:52
const std::string & getKey() const
Definition: ParseFile.h:56
void pushLine(const std::string &line)
Definition: ParseFile.h:74
sensor_ptr readSensor(ParseFile &is)
Definition: SensorColl.cpp:101
const bool getNextLine()
Definition: ParseFile.h:59
sensor_ptr addSensor(const std::string &key, sensor_ptr s)
Definition: SensorColl.cpp:24
void Model::reattachSensors ( )

get sensors from sensor collection

Definition at line 616 of file Model.cpp.

References SensorCollection::getSensor(), m_Sensors, and nodes.

Referenced by getSensorCollection(), Searcher::reattachSensors(), and Brain::triggerTest().

616  {
617  for (NodeArray::iterator p=nodes.begin(); p!=nodes.end();p++) {
618  p->attachSensor(m_Sensors->getSensor(p->sensorID));
619  }
620 }
sensor_ptr getSensor(const std::string &id)
Definition: SensorColl.cpp:52
SensorCollection * m_Sensors
Definition: Model.h:266
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
void Model::rebuildIndexTables ( )
protected

rebuild cross indexing between nodes and edges

Definition at line 527 of file Model.cpp.

References edges, and nodes.

Referenced by getHLNode(), removeByAdjMat(), and removeNode().

528 {
529  dword idx=0;
530  for(NodeArray::iterator n=nodes.begin(); n!=nodes.end(); n++,idx++) {
531  n->index = idx;
532  n->edges.clear();
533  }
534  idx=0;
535  for(EdgeArray::iterator e=edges.begin(); e!=edges.end(); e++, idx++) {
536  e->index = idx;
537  e->fromNode().edges.push_back(e->index+1);
538  e->toNode().edges.push_back(-e->index-1);
539  }
540 }
EdgeArray edges
indexed list of edges
Definition: Model.h:263
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
unsigned long dword
Definition: simpletypes.h:6
dword Model::removeByAdjMat ( DMatrixf adjm)
protected

remove edged not mentioned in (non-directional) adjacency matrix

remove edged mentioned in (non-directional) adjacency matrix

Definition at line 447 of file Model.cpp.

References DMatrix< T >::at(), edges, getNNodes(), rebuildIndexTables(), DMatrix< T >::sizeX(), and DMatrix< T >::sizeY().

Referenced by getHLNode(), and removeEdges().

448 {
449  assert(adjm.sizeX() == adjm.sizeY() && adjm.sizeX() == (dword)getNNodes());
450  dword count=0;
451  EdgeArray::iterator e=edges.begin();
452  while(e!=edges.end()) {
453  int from,to;
454  if(e->from > e->to) { from = e->from; to = e->to; }
455  else { from = e->to; to = e->from; }
456  assert(e->to < getNNodes());
457  if(adjm.at(from, to)>0.0001) {
458  edges.erase(e);
459  adjm.at(from, to)--;
460  count++;
461  } else e++;
462  }
463  if(count) rebuildIndexTables();
464  return count;
465 }
void rebuildIndexTables()
rebuild cross indexing between nodes and edges
Definition: Model.cpp:527
int getNNodes() const
Definition: Model.h:77
EdgeArray edges
indexed list of edges
Definition: Model.h:263
dword sizeX() const
Definition: DMatrix.h:42
unsigned long dword
Definition: simpletypes.h:6
dword sizeY() const
Definition: DMatrix.h:43
T & at(dword x, dword y)
Definition: DMatrix.h:46
dword Model::removeEdges ( )

Remove edges between selected nodes.

Definition at line 498 of file Model.cpp.

References adjMat(), prepareTorque(), removeByAdjMat(), and selMaskMat().

Referenced by getHLNode(), and Brain::triggerTest().

499 {
500  DMatrixf selm = selMaskMat();
501  selm *= adjMat();
502  dword nc = removeByAdjMat(selm);
503  if(nc) prepareTorque();
504  return nc;
505 }
void prepareTorque()
Definition: Model.cpp:713
unsigned long dword
Definition: simpletypes.h:6
DMatrixf adjMat() const
compute undirected adjacency matrix
Definition: Model.cpp:415
DMatrixf selMaskMat() const
compute mask matrix of selected nodes
Definition: Model.cpp:431
dword removeByAdjMat(DMatrixf &adjm)
remove edged not mentioned in (non-directional) adjacency matrix
Definition: Model.cpp:447
void Model::removeNode ( int  nid)

Removes a node and its adjacent edges.

Definition at line 508 of file Model.cpp.

References edges, getNNodes(), m_DirNodeInd, m_HLNode, nodes, prepareTorque(), and rebuildIndexTables().

Referenced by getHLNode(), and Brain::triggerTest().

509 {
510  if(!(nid>=0 && nid<getNNodes())) return;
511  EdgeArray::iterator e=edges.begin();
512  while(e!=edges.end()) {
513  if(e->to == nid || e->from == nid) edges.erase(e);
514  else {
515  if(e->to > nid) e->to--;
516  if(e->from > nid) e->from--;
517  e++;
518  }
519  }
520  m_DirNodeInd = -1;
521  m_HLNode = -1;
522  nodes.erase(nodes.begin()+nid);
524  prepareTorque();
525 }
void prepareTorque()
Definition: Model.cpp:713
void rebuildIndexTables()
rebuild cross indexing between nodes and edges
Definition: Model.cpp:527
int m_DirNodeInd
Definition: Model.h:273
int m_HLNode
Definition: Model.h:283
int getNNodes() const
Definition: Model.h:77
EdgeArray edges
indexed list of edges
Definition: Model.h:263
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
void Model::reset ( )

reset all model information (including geometry)

Definition at line 103 of file Model.cpp.

References __SHAPEWEIGHT, clear(), ParticleParam::gravitational, m_Filename, m_Flags, m_InstCount, m_PCFlags, m_ShapeWeight, m_TimeStamp, PC_NOTHING, phys, setName(), and ParticleParam::viscousdrag.

Referenced by operator bool(), operator>>(), and readFile().

104 {
105  clear();
106  m_TimeStamp = 0; //vector<float>(TS_LAST, 0);
107  m_Flags=0;
109  m_InstCount=1;
113  setName("00");
114  //m_ppmm = DEFAULT_PPMM;
115  m_Filename.clear();
116 }
std::string m_Filename
Definition: Model.h:281
ParticleParam phys
physical parameter set
Definition: Model.h:257
float m_ShapeWeight
Definition: Model.h:268
dword m_PCFlags
Definition: Model.h:274
void setName(const std::string &name)
Definition: Model.cpp:399
float viscousdrag
Definition: PartParam.h:63
#define __SHAPEWEIGHT
Definition: Brain.cpp:22
void clear()
remove and destroy all geometry information (nodes and edges)
Definition: Model.cpp:95
dword m_Flags
Definition: Model.h:269
dword m_InstCount
number of merged instances
Definition: Model.h:280
float gravitational
Definition: PartParam.h:62
float m_TimeStamp
time stamps (see. TTimeStamp)
Definition: Model.h:259
void Model::resetForces ( )

Definition at line 640 of file Model.cpp.

References nodes.

Referenced by getMaxRadius(), and updateParticles().

641 {
642  Point zero;
643  for (NodeArray::iterator p=nodes.begin(); p!=nodes.end();p++) {
644  p->f = zero;
645  }
646 }
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
Definition: Point.h:16
void Model::rotate ( float  angle,
const Point c 
)

Definition at line 946 of file Model.cpp.

References invalidatePC(), nodes, PC_CENTER, PC_DIR, PC_STATS, and Point2D::rotate().

Referenced by adaptProperties(), Brain::distributeModel(), rotate(), setID(), and Brain::triggerTest().

947 {
948  for(NodeArray::iterator n = nodes.begin(); n != nodes.end(); n++) {
949  (Point2D&)*n = c+(*n-c).rotate(angle);
950  }
952 }
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
const Point2D rotate(float angle) const
Definition: Point.h:211
void invalidatePC(dword pcflags=PC_ALL)
Definition: Model.h:220
Definition: Point.h:16
void Model::rotate ( float  angle)
inline

Definition at line 124 of file Model.h.

References attract(), getCenter(), getFullLength(), getStdRadius(), m_PCFlags, PC_CENTER, pushRotate(), and rotate().

124  {
void rotate(float angle, const Point &c)
Definition: Model.cpp:946
const Point getCenter() const
Definition: Model.cpp:852
dword m_PCFlags
Definition: Model.h:274
unsigned long dword
Definition: simpletypes.h:6
void Model::scale ( float  factor,
bool  movepoints = false 
)

multiply all rest lengths by factor

Definition at line 1140 of file Model.cpp.

References edges, getCenter(), invalidatePC(), nodes, PC_SCALE, and PC_STATS.

Referenced by adaptDataScale(), adaptProperties(), MStructure::buildMasterModel(), Brain::distributeModel(), getDeformation(), getMaxRadius(), and Brain::triggerTest().

1141 {
1142  for(EdgeArray::iterator e = edges.begin(); e != edges.end(); e++) {
1143  e->restlength*=factor;
1144  }
1145  if(movepoints) {
1146  Point center = getCenter();
1147  for(NodeArray::iterator n = nodes.begin();
1148  n != nodes.end(); n++)
1149  {
1150  n->setPos(center + ((*n-center)*factor));
1151  }
1153  }
1154 }
const Point getCenter() const
Definition: Model.cpp:852
EdgeArray edges
indexed list of edges
Definition: Model.h:263
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
void invalidatePC(dword pcflags=PC_ALL)
Definition: Model.h:220
Definition: Point.h:16
void Model::scaleSel ( float  factor,
const DMatrixf selm 
)

multiply all rest lengths of selected edges by factor

Definition at line 1156 of file Model.cpp.

References DMatrix< T >::at(), and edges.

Referenced by getMaxRadius(), and Brain::triggerTest().

1157 {
1158  for(EdgeArray::iterator e = edges.begin(); e != edges.end(); e++) {
1159  if(selm.at(e->from, e->to) > 0.001)
1160  e->restlength*=factor;
1161  }
1162 }
EdgeArray edges
indexed list of edges
Definition: Model.h:263
T & at(dword x, dword y)
Definition: DMatrix.h:46
DMatrixf Model::selMaskMat ( ) const

compute mask matrix of selected nodes

Definition at line 431 of file Model.cpp.

References getNNodes(), DMatrix< T >::min(), nodes, DMatrix< T >::setCol(), DMatrix< T >::setRow(), and Node::ST_SELECT.

Referenced by connectNodes(), getHLNode(), removeEdges(), and Brain::triggerTest().

432 {
433  DMatrixf selmc(getNNodes(), getNNodes());
434  DMatrixf selmr(getNNodes(), getNNodes());
435  for(NodeArray::const_iterator n = nodes.begin(); n != nodes.end(); n++)
436  if(n->hasState(Node::ST_SELECT)) {
437  selmr.setRow(n->getIndex());
438  selmc.setCol(n->getIndex());
439  }
440  selmr+=selmc;
441  selmc=selmr;
442  selmr.min(1);
443  return selmc-=selmr;
444 }
int getNNodes() const
Definition: Model.h:77
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
void Model::setDirNode ( int  id)
inline

Definition at line 177 of file Model.h.

References invalidatePC(), m_DirNodeInd, and PC_DIR.

Referenced by Brain::doCommand().

177 { m_DirNodeInd = id; invalidatePC(PC_DIR); }
int m_DirNodeInd
Definition: Model.h:273
void invalidatePC(dword pcflags=PC_ALL)
Definition: Model.h:220
dword& Model::setFlags ( dword  flags)
inline

Definition at line 198 of file Model.h.

References m_Flags.

Referenced by mergeModel(), and StructPath::protectWinners().

198 { return m_Flags|=flags; }
dword m_Flags
Definition: Model.h:269
void Model::setHLNode ( int  hlnode)

Set ID of highlighted node. Pass invalid node id (e.g. -1) to have none highlighted.

Definition at line 405 of file Model.cpp.

References Node::disableState(), Node::enableState(), getNNodes(), getNode(), m_HLNode, and Node::ST_HIGHLIGHT.

Referenced by getFilename(), and Brain::triggerTest().

405  {
406  if(m_HLNode>=0 && m_HLNode<getNNodes())
408  m_HLNode = hlnode;
409  if(m_HLNode>=0 && m_HLNode<getNNodes())
411  else m_HLNode = -1;
412 }
void disableState(dword nstate=0xffffffff)
Definition: Node.h:39
int m_HLNode
Definition: Model.h:283
int getNNodes() const
Definition: Model.h:77
const Node & getNode(int index) const
Definition: Model.h:74
void enableState(dword nstate)
Definition: Node.h:38
void Model::setID ( dword  id)
inline
void Model::setInstCount ( dword  ic)
inline

Definition at line 223 of file Model.h.

References m_InstCount, and mergeModel().

Referenced by Searcher::add().

223 { m_InstCount=ic; }
dword m_InstCount
number of merged instances
Definition: Model.h:280
void Model::setLooser ( bool  isloose = true,
float  ts = 0. 
)
inline

Definition at line 185 of file Model.h.

References m_Flags, and ST_LOOSER.

185  {
186  if(isloose) m_Flags |= ST_LOOSER;
187  else m_Flags &= ~ST_LOOSER;
188  //if(ts!=0.) m_TimeStamp[TS_LOOSE]=ts;
189  }
dword m_Flags
Definition: Model.h:269
void Model::setName ( const std::string &  name)

Definition at line 399 of file Model.cpp.

References CRC(), m_CRC, and m_Name.

Referenced by getNEdges(), Model(), operator>>(), readParameter(), MStructure::rebuildExpMap(), and reset().

400 {
401  m_Name = name;
402  m_CRC = (dword)CRC((unsigned char*)m_Name.c_str(), m_Name.size());
403 }
std::string m_Name
Definition: Model.h:270
dword m_CRC
Definition: Model.h:271
unsigned short CRC(const unsigned char *Data, unsigned int Length)
Definition: crc.h:56
unsigned long dword
Definition: simpletypes.h:6
void Model::setOldState ( bool  isoldstate = true,
float  ts = 0. 
)
inline

Definition at line 191 of file Model.h.

References m_Flags, and ST_OLDSTATE.

191  {
192  if(isoldstate) m_Flags |= ST_OLDSTATE;
193  else m_Flags &= ~ST_OLDSTATE;
194  }
dword m_Flags
Definition: Model.h:269
void Model::setShapeWeight ( float  weight)
inline

Definition at line 201 of file Model.h.

References adaptDataScale(), invalidatePC(), m_ShapeWeight, and PC_QOF.

Referenced by Brain::distributeModel(), and Brain::triggerTest().

201  {
202  m_ShapeWeight = weight; invalidatePC(PC_QOF); }
float m_ShapeWeight
Definition: Model.h:268
void invalidatePC(dword pcflags=PC_ALL)
Definition: Model.h:220
void Model::setWinner ( bool  iswin = true,
float  ts = 0. 
)
inline

Definition at line 179 of file Model.h.

References m_Flags, and ST_WINNER.

179  {
180  if(iswin) m_Flags |= ST_WINNER;
181  else m_Flags &= ~ST_WINNER;
182  //if(ts!=0.) m_TimeStamp[TS_WIN]=ts;
183  }
dword m_Flags
Definition: Model.h:269
dword& Model::switchFlags ( dword  flags)
inline

Definition at line 200 of file Model.h.

References m_Flags.

200 { return m_Flags^=flags; }
dword m_Flags
Definition: Model.h:269
void Model::translate ( const Point t)

Definition at line 923 of file Model.cpp.

References invalidatePC(), nodes, PC_CENTER, and PC_STATS.

Referenced by adaptProperties(), Brain::distributeModel(), Brain::evolve(), setID(), and Brain::triggerTest().

924 {
925  for(NodeArray::iterator n = nodes.begin(); n != nodes.end(); n++) {
926  *n += t;
927  }
929 }
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
void invalidatePC(dword pcflags=PC_ALL)
Definition: Model.h:220
dword& Model::unsetFlags ( dword  flags)
inline

Definition at line 199 of file Model.h.

References m_Flags.

Referenced by StructPath::unprotectWinners().

199 { return m_Flags&=~flags; }
dword m_Flags
Definition: Model.h:269
void Model::updateParticles ( float  dt,
int  method = 0 
)

Definition at line 752 of file Model.cpp.

References addTorque(), calculateDerivatives(), calculateForces(), getNNodes(), getSearchPara(), invalidatePC(), SearcherParams::m_ParaSolver, nodes, and resetForces().

Referenced by MStructure::buildMasterModel(), and getMaxRadius().

753 {
754  method = getSearchPara().m_ParaSolver;
755  if(nodes.empty()) return;
756  switch (method) {
757  case 0: // Euler
758  {
759  std::vector<NodeDerivative> m_Deriv(getNNodes());
760  resetForces();
761  calculateForces(dt);
762  addTorque(dt);
763  calculateDerivatives(m_Deriv);
764  vector<NodeDerivative>::iterator d=m_Deriv.begin();
765  for (NodeArray::iterator n=nodes.begin();
766  n != nodes.end(), d != m_Deriv.end(); n++, d++) {
767  *n += (d->dpdt*dt);
768  n->v += (d->dvdt*dt);
769  }
770  }
771  break;
772  case 1: // Midpoint
773  {
774  int i;
775  std::vector<NodeDerivative> m_Deriv(getNNodes());
776  resetForces();
777  calculateForces(dt);
778  addTorque(dt);
779  calculateDerivatives(m_Deriv);
780  NodeArray ptmp(nodes);
781  for (i=0;i<(int)nodes.size();i++) {
782  nodes[i] += (m_Deriv[i].dpdt * (dt * 0.5));
783  nodes[i].v += (m_Deriv[i].dvdt * (dt * 0.5));
784  }
785  vector<NodeDerivative> deriv2(getNNodes());
786  resetForces();
787  calculateForces(dt);
788  addTorque(dt);
789  calculateDerivatives(deriv2);
790  for (i=0;i<(int)nodes.size();i++) {
791  nodes[i].setPos(ptmp[i]+
792  ((m_Deriv[i].dpdt+deriv2[i].dpdt)* (0.5*dt)));
793  nodes[i].v = ptmp[i].v+
794  ((m_Deriv[i].dvdt+deriv2[i].dvdt)*(0.5*dt));
795  }
796  }
797  break;
798  case 2: // latent midpoint
799  {
800  // the goal of this approach is to use information about
801  // the last derivative to get more stable results if step
802  // size is increasing. actually, there is no point in using
803  // a derivative of a long past position to correct the
804  // current derivative for further steps. incorporating the
805  // old one makes the method even more instable...
806 
807  // in the original implementation this is preserved from last time
808  std::vector<NodeDerivative> m_Deriv(getNNodes());
809  float m_LastDT = 0;
810  vector<NodeDerivative> deriv(getNNodes());
811  resetForces();
812  calculateForces(dt);
813  addTorque(dt);
814  calculateDerivatives(deriv);
815  if(m_LastDT == 0 || deriv.size() != m_Deriv.size()) {
816  m_Deriv = deriv;
817  m_LastDT = 0;
818  }
819  //float wnow = dt*m_LastDT / (dt+m_LastDT);
820  //float wlast = dt*dt / (dt+m_LastDT);
821  float wnow = 0.9*dt;
822  float wlast = dt - wnow;
823  int i;
824  for (i=0;i<(int)nodes.size();i++) {
825  nodes[i] += (m_Deriv[i].dpdt*wlast+deriv[i].dpdt*wnow);
826  nodes[i].v += (m_Deriv[i].dvdt*wlast+deriv[i].dvdt*wnow);
827  }
828  m_Deriv = deriv;
829  m_LastDT = dt;
830  }
831  break;
832  }
833  invalidatePC();
834 }
void addTorque(float dt)
Definition: Model.cpp:719
void calculateForces(float dt)
Definition: Model.cpp:648
std::vector< Node > NodeArray
Definition: Model.h:19
void calculateDerivatives(std::vector< NodeDerivative > &deriv)
Definition: Model.cpp:839
void resetForces()
Definition: Model.cpp:640
int getNNodes() const
Definition: Model.h:77
int m_ParaSolver
method for solving ODE, 0-gauss, 1-midpnt
Definition: Searcher.h:189
NodeArray nodes
indexed list of nodes
Definition: Model.h:262
SearcherParams & getSearchPara()
Definition: Searcher.h:194
void invalidatePC(dword pcflags=PC_ALL)
Definition: Model.h:220
bool Model::writeFile ( const char *  filename) const

Write geometry to file.

Definition at line 381 of file Model.cpp.

References IOException::getMessage(), and phys.

Referenced by setID(), MStructure::setRefModel(), and Brain::triggerTest().

382 {
383  ofstream os(filename);
384  if(os) {
385  try {
386  os << "# file '" << filename << "' "<<endl;
388  os << *this;
389  } catch (const IOException *e) {
390  cerr << "IOException: " << e->getMessage() << endl
391  << "writing file " << filename << endl;
392  return false;
393  }
394  os.close();
395  return true;
396  } else return false;
397 }
static ParticleParam global
Definition: PartParam.h:72
ParticleParam phys
physical parameter set
Definition: Model.h:257
const char * getMessage() const
Definition: Errors.h:41

Friends And Related Function Documentation

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

Read geometry from stream.

Definition at line 338 of file Model.cpp.

Referenced by setID().

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 
)
friend

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.

Referenced by setID().

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

Member Data Documentation

EdgeArray Model::edges
protected
dword Model::m_CRC
protected

Definition at line 271 of file Model.h.

Referenced by getCRC(), operator=(), and setName().

dataset_cptr Model::m_Dataset
protected
float Model::m_Direction
mutableprotected

Definition at line 279 of file Model.h.

int Model::m_DirNodeInd
mutableprotected
std::string Model::m_Filename
protected

Definition at line 281 of file Model.h.

Referenced by getFilename(), operator<<(), operator=(), operator>>(), and reset().

dword Model::m_Flags
protected
int Model::m_HLNode
mutableprotected

Definition at line 283 of file Model.h.

Referenced by getHLNode(), operator=(), removeNode(), and setHLNode().

dword Model::m_ID
mutableprotected

Definition at line 284 of file Model.h.

Referenced by getID(), mergeModel(), operator=(), and setID().

dword Model::m_InstCount
protected

number of merged instances

Definition at line 280 of file Model.h.

Referenced by getInstCount(), mergeModel(), operator=(), reset(), and setInstCount().

float Model::m_Liveliness
mutableprotected

Definition at line 277 of file Model.h.

Referenced by getLiveliness(), and operator=().

std::string Model::m_Name
protected

Definition at line 270 of file Model.h.

Referenced by getName(), operator<<(), operator=(), and setName().

dword Model::m_PCFlags
mutableprotected
dword Model::m_ppmm
protected
PropVec Model::m_PropVec
mutableprotected

Definition at line 275 of file Model.h.

Referenced by getCenter(), getDirection(), getProperties(), getStdRadius(), and operator=().

float Model::m_QOF
mutableprotected

Definition at line 276 of file Model.h.

Referenced by getQualityOfFit(), and operator=().

float Model::m_Scale
mutableprotected

Definition at line 278 of file Model.h.

std::string Model::m_SensorFile
protected

Definition at line 267 of file Model.h.

Referenced by operator<<(), operator=(), and readSensor().

SensorCollection* Model::m_Sensors
protected
float Model::m_ShapeWeight
protected

Definition at line 268 of file Model.h.

Referenced by getQualityOfFit(), Model(), operator=(), reset(), and setShapeWeight().

float Model::m_TimeStamp

time stamps (see. TTimeStamp)

Definition at line 259 of file Model.h.

Referenced by Searcher::add(), Searcher::cleanFlags(), Searcher::getGeneration(), mergeModel(), operator=(), and reset().

NodeArray Model::nodes
protected
ParticleParam Model::phys

The documentation for this class was generated from the following files: