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

#include <MStruct.h>

Collaboration diagram for MStructure:
Collaboration graph
[legend]

Public Member Functions

 MStructure (const std::string &name="", StructTable *psTable=NULL)
 
 MStructure (const MStructure &rhs)
 
 ~MStructure ()
 
void clear ()
 
MStructureoperator= (const MStructure &rhs)
 
void setName (const std::string &name)
 
const std::string & getName () const
 
void setSize (float size)
 
float getSize () const
 
void setModel (const Model &model)
 
const ModelgetModel () const
 
ModelgetModel ()
 
void setWeight (float weight)
 
float getWeight () const
 
void attachStructTable (StructTable *psTable)
 
StructTablegetStructTable ()
 
const SearchergetSearcher () const
 
const WinnergetWinner (dword wid) const
 
bool isFrame () const
 
 operator bool () const
 
void addSubStruct (const SubStructure &substruct)
 
const SubStructuregetSubStruct (const std::string sname) const
 
bool hasSubStruct (const std::string sname) const
 
const SubStructuregetSupStruct (const std::string sname) const
 
bool hasSupStruct (const std::string sname) const
 
bool read (ParseFile &is)
 
void write (std::ostream &os) const
 
void showStats (const SubStructure &subs, std::ostream &os=std::cout) const
 
std::string getInfoFilename (const std::string &suffix) const
 
bool getRefModel (dword id, Model &model) const
 
void setRefModel (dword id, const Model &model)
 
bool getRefProp (dword id, PropVec &prop) const
 
void setRefProp (dword id, const PropVec &prop)
 
template<class Iter >
dword getRefModelIDs (Iter iter) const
 
dword loadRefProp ()
 
void saveRefProp () const
 
void buildAllStats ()
 
bool buildMasterModel (float scscale=1.f)
 
void rebuildExpMap ()
 
void verifyWinnerRating ()
 
const ExpectationMapgetExpMap () const
 
bool stepSearch (float dt)
 

Protected Member Functions

void refSubSuper (bool doclear=false)
 
bool addExpectation (const SubStructure &subs, ExpectationMap &expmap, bool inverse=false) const
 

Protected Attributes

StructTablem_PStructTable
 
std::string m_Name
 
Model m_Model
 
float m_Size
 stdradius in mm More...
 
std::map< std::string, SubStructurem_SubStructures
 
std::map< std::string, SubStructure * > m_SupStructures
 
std::map< dword, PropVecm_RefProp
 
Searcher m_Searcher
 
float m_Weight
 
Winner m_FrameWinner
 

Friends

class StructTable
 
ParseFileoperator>> (ParseFile &is, MStructure &st)
 
std::ostream & operator<< (std::ostream &os, const MStructure &st)
 

Detailed Description

Definition at line 52 of file MStruct.h.

Constructor & Destructor Documentation

MStructure::MStructure ( const std::string &  name = "",
StructTable psTable = NULL 
)

Definition at line 24 of file MStruct.cpp.

References Model::attachDataset(), StructTable::getDataset(), StructTable::getSensors(), m_Model, m_PStructTable, Model::mergeSensorCollection(), and setName().

25  : m_PStructTable(psTable), m_Size(1.0f), m_Weight(1.0f)
26 {
27  setName(name);
28  if(m_PStructTable) {
31  }
32 }
Model m_Model
Definition: MStruct.h:120
void attachDataset(dataset_cptr dataset)
Definition: Model.cpp:85
void mergeSensorCollection(SensorCollection *sensors)
Definition: Model.cpp:596
StructTable * m_PStructTable
Definition: MStruct.h:118
float m_Size
stdradius in mm
Definition: MStruct.h:121
float m_Weight
Definition: MStruct.h:126
void setName(const std::string &name)
Definition: MStruct.cpp:73
SensorCollection * getSensors()
Definition: StructTable.cpp:48
dataset_ptr getDataset()
Definition: StructTable.cpp:43
MStructure::MStructure ( const MStructure rhs)

Definition at line 34 of file MStruct.cpp.

References operator=().

35 {
36  operator=(rhs);
37 }
MStructure & operator=(const MStructure &rhs)
Definition: MStruct.cpp:45
MStructure::~MStructure ( )

Definition at line 39 of file MStruct.cpp.

References clear(), m_RefProp, and saveRefProp().

40 {
41  if(!m_RefProp.empty()) saveRefProp();
42  clear();
43 }
void clear()
Definition: MStruct.cpp:61
std::map< dword, PropVec > m_RefProp
Definition: MStruct.h:124
void saveRefProp() const
Definition: MStruct.cpp:218

Member Function Documentation

bool MStructure::addExpectation ( const SubStructure subs,
ExpectationMap expmap,
bool  inverse = false 
) const
protected

Definition at line 373 of file MStruct.cpp.

References ExpectationMap::add(), DMatrix< T >::at(), dmutil::avg(), ExpectationMap::correctLBUB(), DUMP, SubStructure::generateEMDist(), Model::getDataScale(), StructTable::getDataset(), ExpectationMap::getEDist(), Searcher::getGeneration(), EMDRect::getLB(), SubStructure::getLBUB(), Model::getNode(), Model::getProperties(), getPropScale(), Model::getQualityOfFit(), getSearchPara(), EMDistribution::getShootCount(), EMDRect::getUB(), Searcher::getWinList(), isFrame(), Winner::m_BestRating, m_FrameWinner, SearcherParams::m_MaxShoot, SubStructure::m_Mode, Winner::m_Model, SubStructure::m_Pivot, m_PStructTable, SubStructure::m_RateWeight, m_Searcher, Winner::m_WinnerID, DMatrix< T >::max(), DMatrix< T >::min(), SubStructure::MODE_NOSPAWN, NULL, EMDistribution::setCreator(), EMDistribution::setIntegral(), EMDRect::setLB(), setPropPos(), setPropScale(), EMDistribution::setShootCount(), EMDRect::setUB(), and dmutil::stdev().

Referenced by rebuildExpMap().

375 {
376 // if inverse look backwards to super structure
377 // MStructure& st = m_PStructTable->getStructs()
378 // [backwards ? subs.m_SupStructName : subs.m_SubStructName];
379  if(isFrame()) {
380  //cout << "is a frame" << endl;
381  float ppmm = (float)m_PStructTable->getDataset()->getPPMM();
382  PropVec frameprop(m_PStructTable->getDataset()->getPropVec());
383  if(!(subs.m_Mode&SubStructure::MODE_NOSPAWN)) {
384  EMDistribution* emdist =
385  subs.generateEMDist(frameprop,ppmm,backwards,
386  getSearchPara().m_PDist);
387  emdist->setCreator(m_FrameWinner);
389  if(olddist) emdist->setShootCount(olddist->getShootCount());
390  float exhaust =
391  float(emdist->getShootCount()) / getSearchPara().m_MaxShoot;
392  if(exhaust>1.f) exhaust = 0.f;
393  else exhaust = 1.f-exhaust;
394  emdist->setIntegral(exhaust); //1.f was default
395  expmap.add(emdist);
396  }
397  PropVec lb, ub;
398  subs.getLBUB(lb, ub, frameprop, ppmm);
400  expmap.setLB(lb);
401  expmap.setUB(ub);
402  return true;
403  }
404 // list<const Model*> winners;
405 // m_Searcher.getWinners( back_inserter(winners) );
406  if(subs.m_Mode&SubStructure::MODE_NOSPAWN) return true;
407  const map<dword,Winner>& winners = m_Searcher.getWinList();
408  dword nwinners = winners.size();
409  if(!nwinners) return false;
410  DMatrixf qof(1, nwinners);
411  map<dword,Winner>::const_iterator wi = winners.begin();
412  for(dword i=0; i<nwinners; i++, wi++)
413  qof.at(0,i) = wi->second.m_Model->getQualityOfFit();
414  float avgqof = dmutil::avg(qof).at(0,0);
415  float stdqof = dmutil::stdev(qof).at(0,0);
416  float maxqof = qof.max(), minqof = qof.min();
417  if(maxqof<0.0000001) return false; //DEBUG
418  const Winner* thebest = NULL;
419  float bestrating = 0;
420  dword maxshoot = 0;
421  for(wi = winners.begin(); wi!= winners.end(); wi++) {
422  const Winner& winner = wi->second;
423  if(m_Searcher.getGeneration(winner.m_Model) > 2) {
424  float wqof = winner.m_Model->getQualityOfFit();
425 #ifdef _SPAWN_FROM_BEST_
426  float rating = wqof/maxqof + subs.m_RateWeight*winner.m_BestRating;
427  if(rating > bestrating) {
428  thebest = &winner;
429  bestrating = rating;
430  }
431  }
432  }
433  if(thebest) {
434  {
435  const Winner& winner = *thebest;
436  float wqof = winner.m_Model->getQualityOfFit();
437 #endif
438  float ppmm = (float)winner.m_Model->getDataScale();
439  PropVec wprop = winner.m_Model->getProperties();
440  if(subs.m_Pivot>=0) setPropPos(wprop, winner.m_Model
441  ->getNode(subs.m_Pivot));
442  EMDistribution* emdist = subs.generateEMDist
443  (wprop,ppmm,backwards,getSearchPara().m_PDist);
444  emdist->setCreator(winner);
445  EMDistribution* olddist=expmap.getEDist(winner.m_WinnerID);
446  if(olddist) emdist->setShootCount(olddist->getShootCount());
447  if(maxshoot < emdist->getShootCount())
448  maxshoot = emdist->getShootCount();
449  float exhaust =
450  float(emdist->getShootCount()) / getSearchPara().m_MaxShoot;
451  if(exhaust>1.f) exhaust = 0.f;
452  else exhaust = 1.f-exhaust;
453  emdist->setIntegral((wqof/maxqof)*exhaust);
454  expmap.add(emdist);
455  PropVec lb, ub;
456  subs.getLBUB(lb, ub, wprop, ppmm);
458  PropVec olb = expmap.getLB(), oub = expmap.getUB();
459  setPropScale(lb, getPropScale(olb));
460  setPropScale(ub, getPropScale(oub));
463  expmap.setLB(lb);
464  expmap.setUB(ub);
465  }
466  }
467  if(thebest && false) {
468  PropVec lb, ub;
469  float ppmm = (float)thebest->m_Model->getDataScale();
470  subs.getLBUB(lb, ub, thebest->m_Model->getProperties(), ppmm);
472  PropVec olb = expmap.getLB(), oub = expmap.getUB();
473  setPropScale(olb, getPropScale(lb));
474  setPropScale(oub, getPropScale(ub));
475  expmap.setLB(olb);
476  expmap.setUB(oub);
477  }
478  DUMP(maxshoot << " --------------------" );
479  return true;
480 }
#define NULL
Definition: simpletypes.h:9
float getGeneration(const Model *model) const
Definition: Searcher.cpp:303
#define DUMP(expr)
Definition: common.h:16
float getQualityOfFit() const
Definition: Model.cpp:1204
std::map< dword, Winner > & getWinList()
Definition: Searcher.h:30
dword m_Mode
Definition: MStruct.h:48
StructTable * m_PStructTable
Definition: MStruct.h:118
const PropVec & getProperties() const
Definition: Model.cpp:1263
EMDistribution * getEDist(dword wid)
Definition: ExpMap.cpp:65
static void correctLBUB(PropVec &lb, PropVec &ub)
Definition: ExpMap.cpp:193
dword getShootCount() const
Definition: ExpMap.h:62
float getPropScale(const PropVec &prop)
Definition: PropVec.h:19
void add(EMDistribution *ed)
Definition: ExpMap.cpp:23
float m_RateWeight
Definition: MStruct.h:47
void setShootCount(dword scount)
Definition: ExpMap.h:61
void setCreator(const Winner &creator)
Definition: ExpMap.h:58
Model * m_Model
Definition: ExpMap.h:36
int m_MaxShoot
maximum number of spawns from an exp map
Definition: Searcher.h:191
bool isFrame() const
Definition: MStruct.h:75
PropVec & setPropPos(PropVec &prop, const Point2D &p)
Definition: PropVec.h:16
void setUB(const PropVec &ub)
Definition: ExpMap.h:87
float m_BestRating
Definition: ExpMap.h:39
const Node & getNode(int index) const
Definition: Model.h:74
Definition: ExpMap.h:10
const PropVec & getLB() const
Definition: ExpMap.h:86
SearcherParams & getSearchPara()
Definition: Searcher.h:194
unsigned long dword
Definition: simpletypes.h:6
Searcher m_Searcher
Definition: MStruct.h:125
virtual void setIntegral(float integral)
Definition: ExpMap.h:51
dword m_WinnerID
Definition: ExpMap.h:37
const PropVec & getUB() const
Definition: ExpMap.h:85
DMatrix< T > avg(const DMatrix< T > &mat)
Definition: DMatrixUtil.h:90
DMatrix< T > stdev(const DMatrix< T > &mat)
Definition: DMatrixUtil.h:106
EMDistribution * generateEMDist(const PropVec &wprop, float ppmm, bool inverse=false, dword dtype=EMD_RECT) const
Definition: MStruct.cpp:711
Winner m_FrameWinner
Definition: MStruct.h:127
PropVec & setPropScale(PropVec &prop, float pscale)
Definition: PropVec.h:22
void getLBUB(PropVec &lb, PropVec &ub, const PropVec &wprop, float ppmm, float radius=3) const
Definition: MStruct.cpp:803
dword getDataScale() const
Definition: Model.h:204
int m_Pivot
Definition: MStruct.h:43
void setLB(const PropVec &lb)
Definition: ExpMap.h:88
dataset_ptr getDataset()
Definition: StructTable.cpp:43
void MStructure::addSubStruct ( const SubStructure substruct)

Definition at line 87 of file MStruct.cpp.

References m_Name, SubStructure::m_SubStructName, and m_SubStructures.

Referenced by read().

88 {
89  m_SubStructures[substruct.m_SubStructName] = substruct;
90  m_SubStructures[substruct.m_SubStructName].m_SupStructName = m_Name;
91  //super structure references are updated in connectSubSuper()
92 }
std::string m_SubStructName
Definition: MStruct.h:41
std::map< std::string, SubStructure > m_SubStructures
Definition: MStruct.h:122
std::string m_Name
Definition: MStruct.h:119
void MStructure::attachStructTable ( StructTable psTable)
inline

Definition at line 71 of file MStruct.h.

71 { m_PStructTable = psTable;}
StructTable * m_PStructTable
Definition: MStruct.h:118
void MStructure::buildAllStats ( )

Definition at line 232 of file MStruct.cpp.

References SubStructure::analyseTF(), VVector< T, D >::begin(), buildMasterModel(), Model::convertPointToMM(), Model::getCenter(), getInfoFilename(), Model::getNNodes(), Model::getNode(), getPropPos(), getPropTF(), getRefModel(), getRefModelIDs(), getRefProp(), StructTable::getStructs(), SubStructure::m_Mode, m_Model, m_Name, SubStructure::m_Pivot, m_PStructTable, SubStructure::m_SubStructName, m_SubStructures, SubStructure::MODE_SHOWSTATS, setPropPos(), DMatrix< T >::setRange(), showStats(), VVector< T, D >::size(), and toString().

Referenced by Brain::doCommand().

233 {
234  set<dword> refmod;
235  getRefModelIDs( insert_iterator<set<dword> >(refmod, refmod.begin()) );
236  Model model; // not attached to anything
237  //ofstream infile("info.dat");
238  for(map<string,SubStructure>::iterator si = m_SubStructures.begin();
239  si != m_SubStructures.end(); si++)
240  {
241  SubStructure& subs = si->second;
243  set<dword> strefmod; st.getRefModelIDs(
244  insert_iterator<set<dword> >(strefmod, strefmod.begin()) );
245  list<dword> comod;
246  set_intersection( refmod.begin(), refmod.end(),
247  strefmod.begin(), strefmod.end(),
248  back_inserter(comod) );
249  dword ncomod = comod.size();
250  DMatrixf tfmat(PropVec::size(), ncomod);
251  dword rowind = 0;
252  for(list<dword>::const_iterator idi = comod.begin();
253  idi != comod.end(); idi++, rowind++)
254  {
255  Point2D pivot(0,0); bool usepivot = false;
256  if(subs.m_Pivot>=0 && m_Model.getNNodes()>subs.m_Pivot) {
257  if(getRefModel(*idi, model)) { // find pivot
258  pivot = model.getNode(subs.m_Pivot);
259  pivot -= model.getCenter();
260  model.convertPointToMM(pivot);
261  usepivot = true;
262  } else cout << "error: could not find reference model "
263  << getInfoFilename(toString(*idi)) << endl;
264  }
265  //compute transformation
266  PropVec prop, ssprop;
267  if(getRefProp(*idi, prop) && st.getRefProp(*idi, ssprop)) {
268  setPropPos(prop, getPropPos(prop) + pivot);
269  PropTF sstf = getPropTF(prop, ssprop);
270  DMatrixf tfvec(PropVec::size(), 1, sstf.begin());
271  tfmat.setRange(0,rowind,tfvec);
272  } else cerr << "error getting propvec for " << m_Name
273  << " or " << st.m_Name << " for species "
274  << *idi << endl;
275  }
276  subs.analyseTF(tfmat);
278  showStats(subs);
279  }
281 }
std::string getInfoFilename(const std::string &suffix) const
Definition: MStruct.cpp:157
Model m_Model
Definition: MStruct.h:120
void analyseTF(const DMatrixf &tfmat)
Definition: MStruct.cpp:646
std::string m_SubStructName
Definition: MStruct.h:41
void showStats(const SubStructure &subs, std::ostream &os=std::cout) const
Definition: MStruct.cpp:561
dword m_Mode
Definition: MStruct.h:48
std::map< std::string, SubStructure > m_SubStructures
Definition: MStruct.h:122
std::map< std::string, MStructure > & getStructs()
Definition: StructTable.h:71
StructTable * m_PStructTable
Definition: MStruct.h:118
Point2D getPropPos(const PropVec &prop)
Definition: PropVec.h:13
std::string toString(T v)
Definition: utils.h:60
PropTF getPropTF(const PropVec &from, const PropVec &to)
Definition: PropVec.h:37
dword getRefModelIDs(Iter iter) const
Definition: MStruct.h:131
const Point getCenter() const
Definition: Model.cpp:852
bool getRefModel(dword id, Model &model) const
Definition: MStruct.cpp:167
bool getRefProp(dword id, PropVec &prop) const
Definition: MStruct.cpp:174
int getNNodes() const
Definition: Model.h:77
PropVec & setPropPos(PropVec &prop, const Point2D &p)
Definition: PropVec.h:16
Point2D & convertPointToMM(Point2D &pt) const
Definition: Model.cpp:1291
const Node & getNode(int index) const
Definition: Model.h:74
Definition: Model.h:33
std::string m_Name
Definition: MStruct.h:119
TPtr begin()
Definition: VVector.h:37
unsigned long dword
Definition: simpletypes.h:6
bool buildMasterModel(float scscale=1.f)
Definition: MStruct.cpp:283
MT & setRange(dword ox, dword oy, const MT &mat)
Definition: DMatrix.h:185
Definition: Point.h:16
static unsigned int size()
Definition: VVector.h:41
int m_Pivot
Definition: MStruct.h:43
bool MStructure::buildMasterModel ( float  scscale = 1.f)

Definition at line 283 of file MStruct.cpp.

References dmutil::abs(), Model::getDataScale(), Model::getEdge(), Model::getLiveliness(), Model::getNEdges(), getRefModel(), getRefModelIDs(), ParticleParam::global, ParticleParam::imgforce, Edge::lengthRatio(), m_Model, Model::phys, Edge::restlength, Model::scale(), SHAPEADAPTTIMESTEP, ParticleParam::springconst, Edge::springconstant, and Model::updateParticles().

Referenced by buildAllStats().

284 {
285  if(!m_Model) return false;
286  list<dword> refmod;
287  dword nrefmod = getRefModelIDs( back_inserter(refmod) );
288 // insert_iterator<list<dword> >(refmod, refmod.begin()) );
289  Model model; // not attached to anything
290  DMatrixf rlen(1, m_Model.getNEdges(), 0.f);
291  DMatrixf lenrat(1, m_Model.getNEdges(), 0.f);
292  dword nmod = 0;
293  for(list<dword>::const_iterator idi = refmod.begin();
294  idi != refmod.end(); idi++)
295  {
296  if(getRefModel(*idi, model)) { // get model instance
297  if(model.getNEdges() == m_Model.getNEdges()) {
298  for(int i=0;i<model.getNEdges();i++) {
299  const Edge& se = model.getEdge(i);
300  //Edge& me = m_Model.getEdge(i);
301  float rl = se.restlength/model.getDataScale();
302  float lr = se.lengthRatio();
303  if(lr>1) lr = 1/lr;
304  lr = 1-lr;
305  rlen.at(0,i) += rl;
306  lenrat.at(0,i) += lr;
307  }
308  nmod++;
309  }
310  }
311  }
312  if(nmod>1) { // setup spring constants according to statistics
313  float scmax = ParticleParam::global.springconst;
314  float minlr = 1/scmax;
315  int i;
316  float refallrl=0, nallrl=0;
317  for(int i=0;i<m_Model.getNEdges();i++) {
318  Edge& me = m_Model.getEdge(i);
319  float rl = rlen.at(0,i) /= nmod;
320  lenrat.at(0,i) /= nmod;
321  nallrl += rl;
322  refallrl += me.restlength;
323  }
324  nallrl *= m_Model.getDataScale();
325  m_Model.scale(nallrl/refallrl,true);
326  for(int i=0;i<m_Model.getNEdges();i++) {
327  Edge& me = m_Model.getEdge(i);
328  float rl = rlen.at(0,i);
329  float sc = lenrat.at(0,i);
330  sc *= scscale;
331  //DUMP(sc);
332  if(sc>minlr) sc = 1/sc;
333  else sc = scmax;
334  //cout << "springconst = " << sc << endl;
335  me.restlength = rl*m_Model.getDataScale();
336  me.springconstant = sc;
337  }
338 #define SHAPEADAPTTIMESTEP 0.01
339  float imgfscale = m_Model.phys.imgforce;
340  m_Model.phys.imgforce = 0; //disable image influence
342  float liveliness = 0;
343  dword timeout = 100;
344  while(abs(liveliness-m_Model.getLiveliness())>0.01 && timeout--) {
345  liveliness = m_Model.getLiveliness();
351  }
352  m_Model.phys.imgforce = imgfscale;
353  if(!timeout) cout << "timeout reached while calming model" << endl;
354 #undef SHAPEADAPTTIMESTEP
355  }
356  return true;
357 }
float getLiveliness() const
Definition: Model.cpp:1222
float imgforce
Definition: PartParam.h:67
static ParticleParam global
Definition: PartParam.h:72
Model m_Model
Definition: MStruct.h:120
int getNEdges() const
Definition: Model.h:78
#define SHAPEADAPTTIMESTEP
Implements an Edge with spring functionality.
Definition: Edge.h:14
ParticleParam phys
physical parameter set
Definition: Model.h:257
void scale(float factor, bool movepoints=false)
multiply all rest lengths by factor
Definition: Model.cpp:1140
dword getRefModelIDs(Iter iter) const
Definition: MStruct.h:131
bool getRefModel(dword id, Model &model) const
Definition: MStruct.cpp:167
float springconstant
spring constant
Definition: Edge.h:134
DMatrix< T > & abs(DMatrix< T > &mat)
Definition: DMatrixUtil.h:132
Definition: Model.h:33
float lengthRatio() const
Definition: Edge.h:91
unsigned long dword
Definition: simpletypes.h:6
const Edge & getEdge(int index) const
Definition: Model.h:71
void updateParticles(float dt, int method=0)
Definition: Model.cpp:752
float restlength
Definition: Edge.h:132
float springconst
Definition: PartParam.h:64
dword getDataScale() const
Definition: Model.h:204
void MStructure::clear ( )

Definition at line 61 of file MStruct.cpp.

References Model::clear(), m_FrameWinner, m_Model, m_Name, m_RefProp, m_Size, Winner::m_StructName, m_SubStructures, m_SupStructures, and m_Weight.

Referenced by read(), and ~MStructure().

62 {
63  m_Name.clear();
64  m_Model.clear();
65  m_Size = 1.0f;
66  m_Weight = 1.0f;
67  m_SupStructures.clear();
68  m_SubStructures.clear();
70  m_RefProp.clear();
71 }
std::string m_StructName
Definition: ExpMap.h:38
Model m_Model
Definition: MStruct.h:120
std::map< std::string, SubStructure > m_SubStructures
Definition: MStruct.h:122
std::map< std::string, SubStructure * > m_SupStructures
Definition: MStruct.h:123
float m_Size
stdradius in mm
Definition: MStruct.h:121
std::map< dword, PropVec > m_RefProp
Definition: MStruct.h:124
float m_Weight
Definition: MStruct.h:126
std::string m_Name
Definition: MStruct.h:119
void clear()
remove and destroy all geometry information (nodes and edges)
Definition: Model.cpp:95
Winner m_FrameWinner
Definition: MStruct.h:127
const ExpectationMap& MStructure::getExpMap ( ) const
inline

Definition at line 109 of file MStruct.h.

References dmutil::inverse(), and StructTable::stepSearch().

110  { return m_Searcher.getExpectationMap(); }
ExpectationMap & getExpectationMap()
Definition: Searcher.h:37
Searcher m_Searcher
Definition: MStruct.h:125
string MStructure::getInfoFilename ( const std::string &  suffix) const

Definition at line 157 of file MStruct.cpp.

References StructTable::getFilename(), m_Name, and m_PStructTable.

Referenced by buildAllStats(), Brain::doCommand(), getRefModel(), loadRefProp(), saveRefProp(), setRefModel(), and showStats().

157  {
158  string fn;
159  if(m_PStructTable) {
160  fn = m_PStructTable->getFilename();
161  fn = fn.substr(0, fn.rfind('.'));
162  } else fn = "struct";
163  fn = fn + "_" + m_Name + "_" + suffix + ".dm";
164  return fn;
165 }
StructTable * m_PStructTable
Definition: MStruct.h:118
const std::string & getFilename() const
Definition: StructTable.h:69
std::string m_Name
Definition: MStruct.h:119
const Model& MStructure::getModel ( ) const
inline

Definition at line 67 of file MStruct.h.

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

67 { return m_Model; }
Model m_Model
Definition: MStruct.h:120
Model& MStructure::getModel ( )
inline

Definition at line 68 of file MStruct.h.

68 { return m_Model; }
Model m_Model
Definition: MStruct.h:120
const std::string& MStructure::getName ( ) const
inline

Definition at line 63 of file MStruct.h.

Referenced by StructPath::getWinner(), Brain::load(), StructTable::read(), and Brain::triggerTest().

63 { return m_Name; }
std::string m_Name
Definition: MStruct.h:119
bool MStructure::getRefModel ( dword  id,
Model model 
) const

Definition at line 167 of file MStruct.cpp.

References getInfoFilename(), Model::readFile(), and toString().

Referenced by buildAllStats(), buildMasterModel(), Brain::load(), showStats(), and Brain::triggerTest().

168 {
169  string filename = getInfoFilename(toString(id));
170  bool readf = model.readFile(filename.c_str());
171  return readf;
172 }
std::string getInfoFilename(const std::string &suffix) const
Definition: MStruct.cpp:157
std::string toString(T v)
Definition: utils.h:60
bool readFile(const char *filename, bool fullread=true)
Definition: Model.cpp:365
template<class Iter >
dword MStructure::getRefModelIDs ( Iter  iter) const

Definition at line 131 of file MStruct.h.

References FFind::findFiles(), and fromString().

Referenced by buildAllStats(), buildMasterModel(), Brain::doCommand(), showStats(), and Brain::triggerTest().

131  {
132  dword count = 0;
133  if(!m_Model) {
134  for(std::map<dword,PropVec>::const_iterator rp=m_RefProp.begin();
135  rp!=m_RefProp.end(); rp++, count++)
136  *iter++ = rp->first;
137  return count;
138  }
139  std::string filemask = getInfoFilename("*");
140  std::list<std::string> files;
141  if(FFind::findFiles(filemask, back_inserter(files)))
142  {
143  for(std::list<std::string>::iterator cf=files.begin();
144  cf != files.end(); cf++) {
145  std::string suff = cf->substr(cf->rfind('_')+1);
146  suff = suff.substr(0, suff.find('.'));
147  dword id=0;
148  fromString(suff, id);
149  if(id) {
150  *iter++ = id;
151  count++;
152  }
153  }
154  }
155  return count;
156 }
std::string getInfoFilename(const std::string &suffix) const
Definition: MStruct.cpp:157
Model m_Model
Definition: MStruct.h:120
T & fromString(const std::string &str, T &v)
Definition: utils.h:67
int findFiles(const std::string &fmask, T iter)
Definition: ffind.cpp:33
std::map< dword, PropVec > m_RefProp
Definition: MStruct.h:124
unsigned long dword
Definition: simpletypes.h:6
bool MStructure::getRefProp ( dword  id,
PropVec prop 
) const

Definition at line 174 of file MStruct.cpp.

References m_RefProp.

Referenced by buildAllStats(), showStats(), and Brain::triggerTest().

175 {
176  map<dword,PropVec>::const_iterator rp = m_RefProp.find(id);
177  if(rp != m_RefProp.end()) {
178  prop = rp->second;
179  return true;
180  } else return false;
181 }
std::map< dword, PropVec > m_RefProp
Definition: MStruct.h:124
const Searcher& MStructure::getSearcher ( ) const
inline

Definition at line 73 of file MStruct.h.

Referenced by StructTable::findBestConnection(), Brain::triggerTest(), and verifyWinnerRating().

73 { return m_Searcher; }
Searcher m_Searcher
Definition: MStruct.h:125
float MStructure::getSize ( ) const
inline

Definition at line 65 of file MStruct.h.

65 { return m_Size; }
float m_Size
stdradius in mm
Definition: MStruct.h:121
StructTable* MStructure::getStructTable ( )
inline

Definition at line 72 of file MStruct.h.

72 { return m_PStructTable; }
StructTable * m_PStructTable
Definition: MStruct.h:118
const SubStructure& MStructure::getSubStruct ( const std::string  sname) const
inline

Definition at line 79 of file MStruct.h.

80  { return m_SubStructures.find(sname)->second; }
std::map< std::string, SubStructure > m_SubStructures
Definition: MStruct.h:122
const SubStructure& MStructure::getSupStruct ( const std::string  sname) const
inline

Definition at line 83 of file MStruct.h.

Referenced by StructPath::print().

84  { return *m_SupStructures.find(sname)->second; }
std::map< std::string, SubStructure * > m_SupStructures
Definition: MStruct.h:123
float MStructure::getWeight ( ) const
inline

Definition at line 70 of file MStruct.h.

Referenced by StructTable::findBestConnection(), and StructPath::print().

70 { return m_Weight; }
float m_Weight
Definition: MStruct.h:126
const Winner * MStructure::getWinner ( dword  wid) const

Definition at line 80 of file MStruct.cpp.

References Searcher::getWinner(), isFrame(), m_FrameWinner, m_Searcher, and Winner::WID_FRAME.

Referenced by StructTable::findBestConnection(), StructPath::getWinner(), and StructPath::print().

81 {
82  if(isFrame() && wid==Winner::WID_FRAME)
83  return &m_FrameWinner;
84  else return m_Searcher.getWinner(wid);
85 }
bool isFrame() const
Definition: MStruct.h:75
const Winner * getWinner(dword id) const
Definition: Searcher.cpp:668
Searcher m_Searcher
Definition: MStruct.h:125
Winner m_FrameWinner
Definition: MStruct.h:127
bool MStructure::hasSubStruct ( const std::string  sname) const
inline

Definition at line 81 of file MStruct.h.

82  { return m_SubStructures.find(sname) != m_SubStructures.end(); }
std::map< std::string, SubStructure > m_SubStructures
Definition: MStruct.h:122
bool MStructure::hasSupStruct ( const std::string  sname) const
inline

Definition at line 85 of file MStruct.h.

References SubStructure::read(), and StructTable::write().

Referenced by StructPath::print().

86  { return m_SupStructures.find(sname) != m_SupStructures.end(); }
std::map< std::string, SubStructure * > m_SupStructures
Definition: MStruct.h:123
bool MStructure::isFrame ( ) const
inline

Definition at line 75 of file MStruct.h.

Referenced by addExpectation(), getWinner(), stepSearch(), and verifyWinnerRating().

75 { return !m_Model; }
Model m_Model
Definition: MStruct.h:120
dword MStructure::loadRefProp ( )

Definition at line 198 of file MStruct.cpp.

References fromString(), getInfoFilename(), ParseFile::getKey(), ParseFile::getNextLine(), ParseFile::getValue(), and m_RefProp.

Referenced by read().

199 {
200  if(!*this) return 0;
201  string filename(getInfoFilename("pvec"));
202  ParseFile pf(filename);
203  if(pf) {
204  m_RefProp.clear();
205  while(pf.getNextLine()) {
206  dword id=0;
207  fromString(pf.getKey(),id);
208  if(id) {
209  PropVec prop(0.0);
210  fromString(pf.getValue(), prop);
211  m_RefProp[id] = prop;
212  }
213  }
214  return m_RefProp.size();
215  } return 0;
216 }
std::string getInfoFilename(const std::string &suffix) const
Definition: MStruct.cpp:157
T & fromString(const std::string &str, T &v)
Definition: utils.h:67
std::map< dword, PropVec > m_RefProp
Definition: MStruct.h:124
unsigned long dword
Definition: simpletypes.h:6
MStructure::operator bool ( ) const
inline

Definition at line 76 of file MStruct.h.

76 { return !m_Name.empty(); }
std::string m_Name
Definition: MStruct.h:119
MStructure & MStructure::operator= ( const MStructure rhs)

Definition at line 45 of file MStruct.cpp.

References m_FrameWinner, m_Model, m_Name, m_PStructTable, m_RefProp, m_Size, m_SubStructures, m_SupStructures, and m_Weight.

Referenced by MStructure().

46 {
47  if(this != &rhs) {
48  m_Name = rhs.m_Name;
49  m_Model = rhs.m_Model;
50  m_Size = rhs.m_Size;
54  m_RefProp = rhs.m_RefProp;
55  m_Weight = rhs.m_Weight;
57  }
58  return *this;
59 }
Model m_Model
Definition: MStruct.h:120
std::map< std::string, SubStructure > m_SubStructures
Definition: MStruct.h:122
std::map< std::string, SubStructure * > m_SupStructures
Definition: MStruct.h:123
StructTable * m_PStructTable
Definition: MStruct.h:118
float m_Size
stdradius in mm
Definition: MStruct.h:121
std::map< dword, PropVec > m_RefProp
Definition: MStruct.h:124
float m_Weight
Definition: MStruct.h:126
std::string m_Name
Definition: MStruct.h:119
Winner m_FrameWinner
Definition: MStruct.h:127
bool MStructure::read ( ParseFile is)

Definition at line 94 of file MStruct.cpp.

References addSubStruct(), clear(), ParseFile::error(), fromString(), ParseFile::getKey(), ParseFile::getNextLine(), ParseFile::getPath(), ParseFile::getValue(), loadRefProp(), m_Model, m_Name, m_Searcher, m_Size, m_Weight, ParseFile::pushLine(), SubStructure::read(), Model::readFile(), setName(), ParseFile::setParseError(), Searcher::setShapeWeight(), and STRUCT_SHAPEWEIGHT.

Referenced by StructTable::read().

95 {
96  clear();
97  bool readon = true;
98  SubStructure substruct;
99  while(readon && is.getNextLine()) {
100  const string& key = is.getKey();
101  const string& value = is.getValue();
102  if(key == "struct") {
103  if(!m_Name.empty()) is.setParseError(
104  "struct inside struct. (rather use substruct?)");
105  else {
106  setName(value.c_str());
107  loadRefProp();
108  }
109  } else if(m_Name.empty()) {
110  is.pushLine(); return false;
111  } else if(key == "end") readon = false;
112  else if(key == "model") {
113  string filename = is.getPath()+is.getValue();
114  if(!m_Model.readFile(filename.c_str())) {
115  is.setParseError(string("couldn't load model ")+filename);
116  }
117  } else if(key == "size") {
118  istringstream(value) >> m_Size;
119  } else if(key == "weight") {
120  fromString(value, m_Weight);
121  } else if(key == "shapeweight") {
122  float shapeweight=STRUCT_SHAPEWEIGHT;
123  fromString(value, shapeweight);
124  m_Searcher.setShapeWeight(shapeweight);
125  } else if(substruct.read(is)) addSubStruct(substruct);
126  else is.setParseError(string("(parsing struct) unknown token ") + key);
127  }
128  if(is.error()) return false;
129  return true;
130 }
Model m_Model
Definition: MStruct.h:120
T & fromString(const std::string &str, T &v)
Definition: utils.h:67
#define STRUCT_SHAPEWEIGHT
Definition: MStruct.cpp:19
void setShapeWeight(float shapeweight)
Definition: Searcher.h:46
bool read(ParseFile &is)
Definition: MStruct.cpp:834
dword loadRefProp()
Definition: MStruct.cpp:198
void clear()
Definition: MStruct.cpp:61
float m_Size
stdradius in mm
Definition: MStruct.h:121
const std::string & getValue() const
Definition: ParseFile.h:57
bool error() const
Definition: ParseFile.h:50
float m_Weight
Definition: MStruct.h:126
void setName(const std::string &name)
Definition: MStruct.cpp:73
void addSubStruct(const SubStructure &substruct)
Definition: MStruct.cpp:87
const std::string & getPath() const
Definition: ParseFile.h:52
const std::string & getKey() const
Definition: ParseFile.h:56
std::string m_Name
Definition: MStruct.h:119
Searcher m_Searcher
Definition: MStruct.h:125
void setParseError(const std::string &msg="")
Definition: ParseFile.h:80
bool readFile(const char *filename, bool fullread=true)
Definition: Model.cpp:365
void pushLine(const std::string &line)
Definition: ParseFile.h:74
const bool getNextLine()
Definition: ParseFile.h:59
void MStructure::rebuildExpMap ( )

Definition at line 482 of file MStruct.cpp.

References ExpectationMap::add(), addExpectation(), ExpectationMap::clear(), ExpectationMap::correctLBUB(), DUMP, StructTable::getDataset(), Searcher::getExpectationMap(), Model::getPropertiesMM(), getPropScale(), ExpectationMap::getRepresentative(), StructTable::getStructs(), EMDistribution::m_Integral, m_Model, m_Name, M_PI, m_PStructTable, m_Searcher, m_SubStructures, m_SupStructures, ExpectationMap::markAllOld(), Searcher::setExpectationMap(), EMDRect::setLB(), Model::setName(), setPropDir(), setPropPos(), setPropScale(), ExpectationMap::setRepresentative(), and EMDRect::setUB().

483 {
484  if(!m_Model) return;
485  //cout << "rebuild expmap for " << m_Name << endl;
487  expmap.markAllOld();
488  expmap.setRepresentative(m_Model);
489  expmap.getRepresentative().setName(m_Name);
490 //calculate upper and lower bounds from dataset (and avg Model)
491  PropVec propl(0.), propu(0.);
492  Point2D dims((float)m_PStructTable->getDataset()->getDim1Size(),
493  (float)m_PStructTable->getDataset()->getDim2Size());
494  float scale = getPropScale(m_Model.getPropertiesMM());
495  scale *= m_PStructTable->getDataset()->getPPMM();
496  setPropPos(propu, dims);
497  setPropDir(propu, 2*M_PI);
498  setPropScale(propu, scale*1.1); // is that good?
499  setPropScale(propl, scale*0.9);
500  ExpectationMap::correctLBUB(propl, propu);
501  expmap.setLB(propl);
502  expmap.setUB(propu);
503 #ifdef _USE_BACKGROUND_DIST_
504 //add a background distribution over entire allowed search range
505  EMDRect* drect = new EMDRect(propl,propu);
506  //drect->setIntegral(0.2); keep it 1 (like the winner)
507  expmap.add(drect); //DEBUG
508 #endif
509 //add expectation from connected super structures
510  for(map<string,SubStructure*>::iterator si = m_SupStructures.begin();
511  si != m_SupStructures.end(); si++)
512  {
513  MStructure& st = m_PStructTable->getStructs()[si->first];
514  // [si->second->m_SupStructName]
515  st.addExpectation(*si->second, expmap);
516  }
517 #if DO_INVERSE_TRANSFORM
518 //add expectation backwards from sub structures
519  for(map<string,SubStructure>::iterator si = m_SubStructures.begin();
520  si != m_SubStructures.end(); si++)
521  {
522  MStructure& st = m_PStructTable->getStructs()[si->first];
523  st.addExpectation(si->second, expmap, true);
524  }
525 #endif
526  expmap.clear(true); // remove old ones only
528  DUMP(m_Name<<" "<<expmap.m_Integral);
529 }
float m_Integral
Definition: ExpMap.h:67
ExpectationMap & getExpectationMap()
Definition: Searcher.h:37
Model m_Model
Definition: MStruct.h:120
#define DUMP(expr)
Definition: common.h:16
void setExpectationMap(const ExpectationMap &em)
Definition: Searcher.cpp:346
std::map< std::string, SubStructure > m_SubStructures
Definition: MStruct.h:122
std::map< std::string, SubStructure * > m_SupStructures
Definition: MStruct.h:123
void clear(bool oldonly=false)
Definition: ExpMap.cpp:141
std::map< std::string, MStructure > & getStructs()
Definition: StructTable.h:71
PropVec getPropertiesMM() const
return property vector using millimeter scale
Definition: Model.cpp:1274
StructTable * m_PStructTable
Definition: MStruct.h:118
static void correctLBUB(PropVec &lb, PropVec &ub)
Definition: ExpMap.cpp:193
float getPropScale(const PropVec &prop)
Definition: PropVec.h:19
void add(EMDistribution *ed)
Definition: ExpMap.cpp:23
PropVec & setPropDir(PropVec &prop, float dir)
Definition: PropVec.h:28
PropVec & setPropPos(PropVec &prop, const Point2D &p)
Definition: PropVec.h:16
void setUB(const PropVec &ub)
Definition: ExpMap.h:87
Definition: ExpMap.h:73
#define M_PI
Definition: mathutil.h:9
void setName(const std::string &name)
Definition: Model.cpp:399
std::string m_Name
Definition: MStruct.h:119
Model & getRepresentative()
Definition: ExpMap.h:156
Searcher m_Searcher
Definition: MStruct.h:125
void markAllOld()
Definition: ExpMap.cpp:159
Definition: Point.h:16
PropVec & setPropScale(PropVec &prop, float pscale)
Definition: PropVec.h:22
bool addExpectation(const SubStructure &subs, ExpectationMap &expmap, bool inverse=false) const
Definition: MStruct.cpp:373
void setLB(const PropVec &lb)
Definition: ExpMap.h:88
void setRepresentative(const Model &model)
Definition: ExpMap.cpp:18
dataset_ptr getDataset()
Definition: StructTable.cpp:43
void MStructure::refSubSuper ( bool  doclear = false)
protected

Definition at line 359 of file MStruct.cpp.

References StructTable::getStructs(), m_Name, m_PStructTable, m_SubStructures, and m_SupStructures.

360 {
361  if(doclear) { // just clear own list
362  m_SupStructures.clear();
363  return;
364  }
365  for(map<string,SubStructure>::iterator si = m_SubStructures.begin();
366  si != m_SubStructures.end(); si++)
367  {
368  MStructure& st = m_PStructTable->getStructs()[si->first];
369  st.m_SupStructures[m_Name] = &si->second;
370  }
371 }
std::map< std::string, SubStructure > m_SubStructures
Definition: MStruct.h:122
std::map< std::string, SubStructure * > m_SupStructures
Definition: MStruct.h:123
std::map< std::string, MStructure > & getStructs()
Definition: StructTable.h:71
StructTable * m_PStructTable
Definition: MStruct.h:118
std::string m_Name
Definition: MStruct.h:119
void MStructure::saveRefProp ( ) const

Definition at line 218 of file MStruct.cpp.

References getInfoFilename(), and m_RefProp.

Referenced by ~MStructure().

219 {
220  if(!*this) return;
221  string filename = getInfoFilename("pvec");
222  ofstream os(filename.c_str());
223  if(os)
224  for(map<dword,PropVec>::const_iterator rp=m_RefProp.begin();
225  rp != m_RefProp.end(); rp++)
226  {
227  if(rp->first)
228  os << rp->first << " " << rp->second << endl;
229  }
230 }
std::string getInfoFilename(const std::string &suffix) const
Definition: MStruct.cpp:157
std::map< dword, PropVec > m_RefProp
Definition: MStruct.h:124
void MStructure::setModel ( const Model model)
inline

Definition at line 66 of file MStruct.h.

Referenced by Brain::triggerTest().

66 { m_Model = model; }
Model m_Model
Definition: MStruct.h:120
void MStructure::setName ( const std::string &  name)

Definition at line 73 of file MStruct.cpp.

References m_FrameWinner, m_Name, Winner::m_StructName, Winner::m_WinnerID, and Winner::WID_FRAME.

Referenced by MStructure(), and read().

74 {
75  m_Name = name;
76  m_FrameWinner.m_StructName = name; //just in case it is used
78 }
std::string m_StructName
Definition: ExpMap.h:38
std::string m_Name
Definition: MStruct.h:119
dword m_WinnerID
Definition: ExpMap.h:37
Winner m_FrameWinner
Definition: MStruct.h:127
void MStructure::setRefModel ( dword  id,
const Model model 
)

Definition at line 188 of file MStruct.cpp.

References Model::convertPropToMM(), getInfoFilename(), Model::getProperties(), m_RefProp, toString(), and Model::writeFile().

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

189 {
190  PropVec pv(model.getProperties());
191  model.convertPropToMM(pv);
192  m_RefProp[id] = pv;
193  //save model file for geometry internal statistics
194  string filename = getInfoFilename(toString(id));
195  model.writeFile(filename.c_str());
196 }
std::string getInfoFilename(const std::string &suffix) const
Definition: MStruct.cpp:157
bool writeFile(const char *filename) const
Definition: Model.cpp:381
PropVec & convertPropToMM(PropVec &prop) const
Definition: Model.cpp:1304
const PropVec & getProperties() const
Definition: Model.cpp:1263
std::string toString(T v)
Definition: utils.h:60
std::map< dword, PropVec > m_RefProp
Definition: MStruct.h:124
void MStructure::setRefProp ( dword  id,
const PropVec prop 
)

Definition at line 183 of file MStruct.cpp.

References m_RefProp.

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

184 {
185  m_RefProp[id] = prop;
186 }
std::map< dword, PropVec > m_RefProp
Definition: MStruct.h:124
void MStructure::setSize ( float  size)
inline

Definition at line 64 of file MStruct.h.

64 { m_Size = size; }
float m_Size
stdradius in mm
Definition: MStruct.h:121
void MStructure::setWeight ( float  weight)
inline

Definition at line 69 of file MStruct.h.

69 { m_Weight = weight; }
float m_Weight
Definition: MStruct.h:126
void MStructure::showStats ( const SubStructure subs,
std::ostream &  os = std::cout 
) const

Definition at line 561 of file MStruct.cpp.

References DMatrix< T >::at(), dmutil::avg(), VVector< T, D >::begin(), Model::convertPointToMM(), DUMP, SubStructure::generateEMDist(), Model::getCenter(), getIdentityPropTF(), getInfoFilename(), Model::getNNodes(), Model::getNode(), getPropPos(), getPropTF(), getRefModel(), getRefModelIDs(), getRefProp(), getSearchPara(), StructTable::getStructs(), SubStructure::m_Mean, m_Model, m_Name, SubStructure::m_Pivot, m_PStructTable, SubStructure::m_Sigma, SubStructure::m_Stdev, SubStructure::m_SubStructName, SubStructure::m_SupStructName, DMatrix< T >::max(), DMatrix< T >::min(), EMDistribution::ratePropVec(), setPropPos(), DMatrix< T >::setRange(), VVector< T, D >::size(), dmutil::stdev(), and toString().

Referenced by buildAllStats().

562 {
563  os << " stats for ["<<subs.m_SupStructName<<"] --> ["
564  <<subs.m_SubStructName<<"]"<<endl;
565  set<dword> refmod;
566  getRefModelIDs( insert_iterator<set<dword> >(refmod, refmod.begin()) );
567  Model model; // not attached to anything
569  set<dword> strefmod; st.getRefModelIDs(
570  insert_iterator<set<dword> >(strefmod, strefmod.begin()) );
571  list<dword> comod;
572  set_intersection( refmod.begin(), refmod.end(),
573  strefmod.begin(), strefmod.end(),
574  back_inserter(comod) );
575  dword ncomod = comod.size();
576  DMatrixf tfmat(PropVec::size(), ncomod);
577  DMatrixf ratings(1,ncomod);
578  dword rowind = 0;
579  for(list<dword>::const_iterator idi = comod.begin();
580  idi != comod.end(); idi++, rowind++)
581  {
582  Point2D pivot(0,0); bool usepivot = false;
583  if(subs.m_Pivot>=0 && m_Model.getNNodes()>subs.m_Pivot) {
584  if(getRefModel(*idi, model)) { // find pivot
585  pivot = model.getNode(subs.m_Pivot);
586  pivot -= model.getCenter();
587  model.convertPointToMM(pivot);
588  usepivot = true;
589  } else os << "error: could not find reference model "
590  << getInfoFilename(toString(*idi)) << endl;
591  }
592  //compute transformation
593  PropVec prop, ssprop;
594  if(getRefProp(*idi, prop) && st.getRefProp(*idi, ssprop)) {
595  setPropPos(prop, getPropPos(prop) + pivot);
596  PropTF sstf = getPropTF(prop, ssprop);
597  DMatrixf tfvec(PropVec::size(), 1, sstf.begin());
598  tfmat.setRange(0,rowind,tfvec);
599  //determine rating
600  EMDistribution* ed = subs.generateEMDist(prop,1,false,
601  getSearchPara().m_PDist);
602  if(ed) {
603  ratings.at(0,rowind) = ed->ratePropVec(ssprop);
604  os << *idi << ": " << ratings.at(0,rowind) << " pv:"
605  << getPropTF(prop,ssprop) << endl;
606  delete ed;
607  } else os << "error generating exp.distr. for " << *idi << endl;
608  } else os << "error getting propvec for " << m_Name
609  << " or " << st.m_Name << " for species "
610  << *idi << endl;
611  }
612  EMDistribution* ed = subs.generateEMDist(getIdentityPropTF(),1,false,
613  getSearchPara().m_PDist);
614  if(ed) {
615  os << "central rating: " << ed->ratePropVec(subs.m_Mean) << endl;
616  DUMP(subs.m_Mean);
617  DUMP(subs.m_Stdev);
618  delete ed;
619 
620  os << "pcomp : " << PropVec(&subs.m_Sigma.at(0,0)) << endl;
621  os << "average: " << dmutil::avg(ratings).at(0,0) << endl;
622  os << "stdev : " << dmutil::stdev(ratings).at(0,0) << endl;
623  if(ncomod>0) {
624  os << "min : " << ratings.min() << endl;
625  os << "max : " << ratings.max() << endl;
626  }
627  } else os << "error generating exp.distr." << endl;
628 }
std::string getInfoFilename(const std::string &suffix) const
Definition: MStruct.cpp:157
Model m_Model
Definition: MStruct.h:120
#define DUMP(expr)
Definition: common.h:16
std::string m_SubStructName
Definition: MStruct.h:41
std::map< std::string, MStructure > & getStructs()
Definition: StructTable.h:71
StructTable * m_PStructTable
Definition: MStruct.h:118
Point2D getPropPos(const PropVec &prop)
Definition: PropVec.h:13
VVector< float, 4 > PropVec
Definition: PropVec.h:8
std::string toString(T v)
Definition: utils.h:60
PropTF getIdentityPropTF()
Definition: PropVec.h:81
PropTF getPropTF(const PropVec &from, const PropVec &to)
Definition: PropVec.h:37
dword getRefModelIDs(Iter iter) const
Definition: MStruct.h:131
const Point getCenter() const
Definition: Model.cpp:852
bool getRefModel(dword id, Model &model) const
Definition: MStruct.cpp:167
std::string m_SupStructName
Definition: MStruct.h:41
bool getRefProp(dword id, PropVec &prop) const
Definition: MStruct.cpp:174
int getNNodes() const
Definition: Model.h:77
PropVec & setPropPos(PropVec &prop, const Point2D &p)
Definition: PropVec.h:16
Point2D & convertPointToMM(Point2D &pt) const
Definition: Model.cpp:1291
const Node & getNode(int index) const
Definition: Model.h:74
DMatrixf m_Sigma
Definition: MStruct.h:46
Definition: Model.h:33
virtual float ratePropVec(const PropVec &prop, Winner *winner=NULL) const
Definition: ExpMap.h:56
std::string m_Name
Definition: MStruct.h:119
TPtr begin()
Definition: VVector.h:37
SearcherParams & getSearchPara()
Definition: Searcher.h:194
unsigned long dword
Definition: simpletypes.h:6
DMatrix< T > avg(const DMatrix< T > &mat)
Definition: DMatrixUtil.h:90
MT & setRange(dword ox, dword oy, const MT &mat)
Definition: DMatrix.h:185
DMatrix< T > stdev(const DMatrix< T > &mat)
Definition: DMatrixUtil.h:106
Definition: Point.h:16
EMDistribution * generateEMDist(const PropVec &wprop, float ppmm, bool inverse=false, dword dtype=EMD_RECT) const
Definition: MStruct.cpp:711
T & at(dword x, dword y)
Definition: DMatrix.h:46
PropVec m_Stdev
Definition: MStruct.h:45
static unsigned int size()
Definition: VVector.h:41
int m_Pivot
Definition: MStruct.h:43
PropVec m_Mean
Definition: MStruct.h:45
bool MStructure::stepSearch ( float  dt)

Definition at line 630 of file MStruct.cpp.

References isFrame(), m_Searcher, and Searcher::step().

631 {
632  return m_Searcher.step(dt) || isFrame();
633 }
bool isFrame() const
Definition: MStruct.h:75
bool step(float dt)
Definition: Searcher.cpp:288
Searcher m_Searcher
Definition: MStruct.h:125
void MStructure::verifyWinnerRating ( )

Definition at line 531 of file MStruct.cpp.

References getSearcher(), StructTable::getStructs(), Searcher::getWinList(), Searcher::getWinner(), isFrame(), m_Name, m_PStructTable, and m_Searcher.

532 {
533  int okcount = 0;
534  map<dword,Winner>& wl = m_Searcher.getWinList();
535  for(map<dword,Winner>::iterator wi = wl.begin(); wi!=wl.end(); wi++)
536  { // for each Winner wi
537  for(Winner::Ratings::iterator refstruct = wi->second.m_Ratings.begin();
538  refstruct != wi->second.m_Ratings.end(); refstruct++)
539  { // for each rating parent structure
540  MStructure& st = m_PStructTable->getStructs()[refstruct->first];
541  if(!st.isFrame()) {
542  map<dword,float>::iterator wr= refstruct->second.begin();
543  while(wr != refstruct->second.end())
544  { // for each rating wr
545  map<dword,float>::iterator nextwr = wr; nextwr++;
546  const Winner* refwin=st.getSearcher().getWinner(wr->first);
547  if(refwin) {
548  okcount++;
549  } else {
550  refstruct->second.erase(wr);
551  }
552  wr = nextwr;
553  }
554  } else okcount += refstruct->second.size();
555  }
556  wi->second.updateBestRating();
557  }
558  cout << okcount << " good connections to struct " << m_Name << endl;
559 }
std::map< dword, Winner > & getWinList()
Definition: Searcher.h:30
std::map< std::string, MStructure > & getStructs()
Definition: StructTable.h:71
StructTable * m_PStructTable
Definition: MStruct.h:118
const Searcher & getSearcher() const
Definition: MStruct.h:73
bool isFrame() const
Definition: MStruct.h:75
const Winner * getWinner(dword id) const
Definition: Searcher.cpp:668
Definition: ExpMap.h:10
std::string m_Name
Definition: MStruct.h:119
Searcher m_Searcher
Definition: MStruct.h:125
void MStructure::write ( std::ostream &  os) const

Definition at line 132 of file MStruct.cpp.

References Model::getFilename(), StructTable::getPath(), Searcher::getShapeWeight(), m_Model, m_Name, m_PStructTable, m_Searcher, m_Size, m_SubStructures, m_Weight, and STRUCT_SHAPEWEIGHT.

133 {
134  if(!(*this)) return;
135  os << "struct " << m_Name << endl;
136  if(!m_Model.getFilename().empty()) {
137  string filename = m_Model.getFilename();
138  if(m_PStructTable) {
139  if(filename.substr(0,m_PStructTable->getPath().size())
140  == m_PStructTable->getPath())
141  filename = filename.substr(m_PStructTable->getPath().size());
142  }
143  os << " model " << filename << endl;
144  }
145  if(m_Weight != 1.f) os << " weight " << m_Weight << endl;
147  os << " shapeweight " << m_Searcher.getShapeWeight() << endl;
148  os << " size " << m_Size << endl;
149  for(map<string,SubStructure>::const_iterator si = m_SubStructures.begin();
150  si != m_SubStructures.end(); si++)
151  {
152  os << si->second;
153  }
154  os << "end # of struct" << endl << endl;
155 }
Model m_Model
Definition: MStruct.h:120
const std::string & getPath() const
Definition: StructTable.h:70
std::map< std::string, SubStructure > m_SubStructures
Definition: MStruct.h:122
StructTable * m_PStructTable
Definition: MStruct.h:118
#define STRUCT_SHAPEWEIGHT
Definition: MStruct.cpp:19
float m_Size
stdradius in mm
Definition: MStruct.h:121
float m_Weight
Definition: MStruct.h:126
float getShapeWeight() const
Definition: Searcher.h:47
std::string m_Name
Definition: MStruct.h:119
Searcher m_Searcher
Definition: MStruct.h:125
const std::string & getFilename() const
Definition: Model.h:225

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const MStructure st 
)
friend

Definition at line 92 of file MStruct.h.

93  { st.write(os); return os; }
void write(std::ostream &os) const
Definition: MStruct.cpp:132
ParseFile& operator>> ( ParseFile is,
MStructure st 
)
friend

Definition at line 90 of file MStruct.h.

91  { st.read(is); return is; }
bool read(ParseFile &is)
Definition: MStruct.cpp:94
friend class StructTable
friend

Definition at line 54 of file MStruct.h.

Member Data Documentation

Winner MStructure::m_FrameWinner
protected

Definition at line 127 of file MStruct.h.

Referenced by addExpectation(), clear(), getWinner(), operator=(), and setName().

Model MStructure::m_Model
protected
std::string MStructure::m_Name
protected
StructTable* MStructure::m_PStructTable
protected
std::map<dword,PropVec> MStructure::m_RefProp
protected
Searcher MStructure::m_Searcher
protected
float MStructure::m_Size
protected

stdradius in mm

Definition at line 121 of file MStruct.h.

Referenced by clear(), operator=(), read(), and write().

std::map<std::string, SubStructure> MStructure::m_SubStructures
protected
std::map<std::string, SubStructure*> MStructure::m_SupStructures
protected

Definition at line 123 of file MStruct.h.

Referenced by clear(), operator=(), rebuildExpMap(), and refSubSuper().

float MStructure::m_Weight
protected

Definition at line 126 of file MStruct.h.

Referenced by clear(), operator=(), read(), and write().


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