22 #define __SHAPEWEIGHT 0.1 23 #define MERGENAME "all" 28 m_UpdateAllModels(false), m_DrawOwnState(false),
31 m_Data = std::make_shared<Dataset>();
61 for(vector<Model*>::iterator gi=
m_CStates->begin();
90 cout <<
"loading " << bfile << endl;
95 string param = is.
getKey();
98 cerr <<
"Couldn't load data base " << is.
getValue()<< endl;
101 }
else if(param ==
"dbsel") {
103 cerr<<
"Couldn't load data base selector " 107 }
else if(param ==
"data") {
109 cerr <<
"Couldn't load data set " <<is.
getValue()<< endl;
112 }
else if(param ==
"model") {
113 cout <<
"loading model " << is.
getValue() << endl;
115 cerr <<
"Couldn't load model file " <<is.
getValue()<< endl;
118 }
else if(param ==
"structure") {
119 cout <<
"loading structure " << is.
getValue() << endl;
122 cerr <<
"Couldn't load structure description " 135 }
else if(param ==
"searcher") {
136 cout <<
"configuring searcher from " << is.
getValue() << endl;
139 cerr <<
"Couldn't searcher config "<<is.
getValue()<< endl;
143 }
else if(param.size()>0) {
151 if(cs) cout <<
"current structure is: " << cs.
getName() << endl;
155 cout <<
"finished loading " << bfile << endl;
157 cerr <<
"Could not open " << bfile << endl;
197 if(!
m_DB.
load(filename))
return false;
213 map<string,string>::const_iterator in = spec.find(
"image");
214 if(in == spec.end())
return false;
216 string msg =
"species_id: ";
223 +
" scale (pixels per mm): "+number;
239 map<string, vector<Model*> >::iterator fs =
264 static const string mergename(
MERGENAME);
267 for(vector<Model*>::iterator mi=
m_CStates->begin();
272 for(map<
string, vector<Model*> >::iterator ii =
m_Instances.begin();
274 msize+=ii->second.size();
276 for(map<
string, vector<Model*> >::iterator ii =
m_Instances.begin();
279 if(ii->first != mergename)
280 for(vector<Model*>::iterator mi=ii->second.begin();
281 mi!=ii->second.end(); mi++)
303 cout <<
"dataset already attached" << endl;
306 cout <<
"attaching data..." << endl;
310 for(list<Model*>::iterator m=ml.begin(); m!=ml.end(); m++)
311 (*m)->adaptDataScale();
315 cout <<
"attaching data done." << endl;
318 #define EXIT_THREAD(t) \ 320 m_ThreadActive[t] = false; \ 321 m_RunMutex[t].unlock(); \ 324 #define CHECK_THREAD(t) \ 326 m_RunMutex[t].unlock(); \ 327 vuThread::usleep(100); \ 328 if(!m_RunMutex[t].trylock()) { \ 336 unsigned long lastticks = 0;
337 static int anastate = 0;
349 dt = (nowticks-lastticks)*0.001;
356 if(
m_Data->getDim1Size()) {
360 for(vector<Model*>::iterator m =
m_CStates->begin();
385 anastate = (int)(intptr_t)data;
394 ofstream os(
"structmatch.txt",ios::app);
395 os <<
"checking structural matches" << endl << endl;
402 cout <<
"hello" << endl;
414 const map<string,StructPath>& interp =
416 os <<
"best interpretation: " 418 for(map<string,StructPath>::const_iterator ip =
419 interp.begin(); ip != interp.end(); ip++)
421 os << ip->first <<
": " 422 << ip->second.getRelGoodness() << endl;
426 cout <<
"best interpretation: " 430 if(anastate == -1) {
EXIT_THREAD(DO_ANALYSIS);
break; }
434 cout <<
"analysis terminated" << endl;
443 static int keymode=0;
444 static int curpid=-1;
445 static string command;
446 static list<vector<float> > colors;
456 if(what == KEY_Return) {
457 cout <<
"command: " << command << endl;
461 command += char(what);
462 cout << char(what) << flush;
477 cout <<
"type command: " << flush;
484 ofstream os(
"antcol.dat",ios::app);
485 for(list< vector<float> >::const_iterator col=
486 colors.begin(); col != colors.end(); col++, cnt++)
488 for(vector<float>::const_iterator c=col->begin();
494 cout <<
"wrote " << cnt <<
" colors to antcol.dat" << endl;
498 }
else keymode = 128;
503 ofstream os(
"antbg.dat",ios::app);
505 for(list< vector<float> >::const_iterator col=
506 colors.begin(); col != colors.end(); col++, cnt++)
508 for(vector<float>::const_iterator c=col->begin();
514 cout <<
"wrote " << cnt <<
" colors to antbg.dat" << endl;
518 }
else keymode = 129;
520 if(keymode == 128 || keymode == 129) {
523 for(vector<float>::const_iterator c=col.begin();
527 colors.push_back(col);
547 cout<<
"adding edge ["<<curpid+1
548 <<
" "<<cnid+1<<
"]"<<endl;
569 cout <<
"smodel key: " << endl;
577 static bool ison =
true;
585 cout <<
"searcher key: " << endl;
651 float qth = hqof*0.7;
652 TRACE(
"quality th " <<qth);
657 cout <<
"distributing " << pt->
getName() << endl;
663 for(map<string,Model*>::iterator gi=
m_Prototypes.begin();
666 cout <<
"distributing " << gi->second->getName() << endl;
709 Node n((
float)mx,(
float)my);
710 bool doubleclick=
false;
713 doubleclick = ((n-ln).norm()<2);
791 sensor_ptr zs = std::make_shared<ZeroSensor>();
839 float kill_quality_th = 0.05;
840 float relq = (hqof-lqof)*kill_quality_th+lqof;
845 Model *m = (*m_CStates)[mi];
856 int mind=0;
float md=1000000;
858 for(vector<Model*>::iterator m =
m_CStates->begin();
861 float d = ((*m)->getCenter()-mouse).norm2();
872 cout <<
"deformation: " << lv <<
" mapped: "<<exp(-5*
abs(lv))<<endl;
876 cout <<
" nedgesensors: " << nes << endl;
884 float lqof,hqof,aqof;
888 for(vector<Model*>::const_iterator m =
m_CStates->begin();
891 float lv = (*m)->getDeformation()*10;
903 Model *m = (*m_CStates)[mi];
906 float relq = (hqof!=0.0) ? (lv-lqof)/hqof :1;
908 if(lv < aqof && !m->isWinner()) {
917 list<const Model*> winners;
919 if(!winners.empty()) {
922 for(list<const Model*>::iterator wpi = winners.begin();
923 wpi != winners.end(); wpi++)
926 cout <<
"copied " << winners.size() <<
" winners" << endl;
934 cout <<
"created " << nesensors <<
" edge sensors" << endl;
956 Node n((
float)mx,(
float)my);
957 bool doubleclick=
false;
960 doubleclick = ((n-ln).norm()<2);
1029 cout <<
"image resolution is " <<
m_BrowseData->getDim1Size()
1035 cout <<
"current flags <" 1037 <<
"> change to (type 'savedb' to save DB): ";
1039 getline(cin, cmdline);
1040 dword split = cmdline.find(
' ');
1041 string command = cmdline.substr(0,split);
1043 if(split != cmdline.npos) value = cmdline.substr(split+1);
1044 cout <<
"command <" << command <<
"> value <"<<value<<
">"<< endl;
1056 cout <<
"scanning " << st.
getName() << endl;
1059 for(list<dword>::iterator mid = ids.begin();
1060 mid != ids.end(); mid++) {
1061 cout << *mid << endl;
1071 cout <<
"setting reference model for species id " 1075 cout <<
"setting reference frame for species id " 1089 cout <<
"found reference model!" << endl;
1102 }
else cout <<
"could not find reference model" << endl;
1109 if(cs) cout <<
"current structure is: " << cs.
getName() << endl;
1120 map<string,StructPath>::const_iterator cp =
1124 qual = cp->second.getRelGoodness();
1126 <<
" (" << qual <<
")" << endl;
1134 cout <<
"switching to best interpretation" << endl;
1135 map<string,StructPath>::const_iterator cp =
1139 qual = cp->second.getRelGoodness();
1141 <<
" (" << qual <<
")" << endl;
1153 if(command ==
"savedb") {
1159 cout <<
" done." << endl;
1161 }
else if(command ==
"scale0" || command ==
"scale1" ||
1162 command ==
"scaleh" || command ==
"scaled") {
1163 static int oldmx = -1;
1164 static float scale = 1;
1165 if(command ==
"scaleh") scale *= 0.5;
1166 else if(command ==
"scaled") scale *= 2;
1167 cout <<
"using scale " << scale <<
" mm" << endl;
1168 if(command ==
"scale0") oldmx = mx;
1169 else if(command ==
"scale1") {
1173 <<
" pixels per mm" << endl;
1175 }
else if(command ==
"flags") {
1177 cout << endl <<
"new flags are <" 1180 }
else if(command ==
"go") {
1184 }
else if(command ==
"calstat") {
1187 }
else if(command ==
"selall") {
1189 cout <<
"selected all " << nsel
1190 <<
" species in data base" << endl;
1191 }
else if(command ==
"process") {
1200 cout <<
"setting reference frame for species id " 1210 }
else if(command ==
"setdir") {
1212 cout <<
"current dir node: " 1219 cout <<
m_DB.
select(refmod) <<
" species selected" << endl;
1221 for(list<dword>::const_iterator idi = refmod.begin();
1222 idi != refmod.end(); idi++) {
1233 }
else if(command ==
"savesearcher") {
1234 string fname = value.empty() ?
"searcher.cnf" : value;
1235 ofstream os(fname.c_str());
1237 }
else if(command ==
"hbs") {
1240 cout <<
"image resolution is halved beyond a size of " 1242 }
else if(command ==
"analysis") {
1245 }
else if(command ==
"noise") {
1246 cout <<
"going for noise" << endl;
1250 cout <<
"command not recognized" << endl;
1256 if(state < m_CStates->size()) {
1258 m_Geom = (*m_CStates)[state];
1262 m_Geom = (*m_CStates)[0];
1268 if(!model) model =
m_Geom;
1284 delete (*m_CStates)[state];
1305 int sx =
m_Data->getDim1Size()/dist;
1306 int sy =
m_Data->getDim2Size()/dist;
1309 for(j=0; j<
m_Data->getDim2Size(); j+=dist)
1310 for(i=0; i<
m_Data->getDim1Size(); i+=dist)
1325 n = (int)(
m_Data->getDim1Size()*
m_Data->getDim2Size()/(dist*dist));
1326 for(i=0; i<n; i++) {
1359 for(vector<Model*>::const_iterator m =
m_CStates->begin();
1363 float alpha = (hqof!=0.0) ? ((*m)->getQualityOfFit()-lqof)/hqof :0;
1364 alpha = alpha*0.8+0.2;
1365 glColor4f(0.1,0.2,0.9,alpha);
1379 alpha = alpha*0.6+0.4;
1380 glEnable(GL_LINE_SMOOTH);
1382 glColor4f(0.0f, 0.0f, 0.0f,alpha);
1386 glColor4f(1.0f, 1.0f, 1.0f,alpha);
1388 glDisable(GL_LINE_SMOOTH);
1392 #ifdef _DRAW_MODEL_NAMES_ 1393 for(vector<Model*>::const_iterator m =
m_CStates->begin();
1396 if((*m)->isWinner() || (*m) ==
m_Geom ) {
1397 Point c = (*m)->getCenter();
1399 descr << (*m)->getName();
1408 map<string,StructPath>::const_iterator spath =
1413 descr << spath->second.getRelGoodness();
1433 static float search_evolve_t = 0;
1436 search_evolve_t = t;
1448 static float kill_t = 0;
1450 float kill_quality_th = 0.1;
1454 Model *m = (*m_CStates)[mi];
1456 if(relq < kill_quality_th) {
1466 if(0 && hqof-lqof < 0.001 && m_Geom->getNNodes()>0) {
1467 static bool duplicated=
false;
1468 if(duplicated && hqof-lqof>0)
m_Done =
true;
1474 for(j=dist/2;j<
m_Data->getDim2Size(); j+=dist)
1475 for(i=dist/2;i<
m_Data->getDim1Size(); i+=dist) {
1484 static float laze_t = 0;
1486 static float change_t = 0;
1487 if(t-change_t > 0.2)
1490 float change_quality_th = 0.7;
1491 for(vector<Model*>::iterator m=
m_CStates->begin();
1494 float relq = (hqof!=0.0) ? ((*m)->getQualityOfFit()-lqof)/hqof :1;
1496 if(relq < change_quality_th && (*m)->getLiveliness()<1) {
1497 (*m)->pushRotate((*m)->getCenter(), -1+
frand(2));
1498 (*m)->addNoise(0.05);
1501 }
else if(t-laze_t > 3) laze_t = t;
1508 bool cw = (shapeweight!=-1);
1509 if(cw) (*
m_CStates->begin())->setShapeWeight(shapeweight);
1510 lqof=hqof=(*
m_CStates->begin())->getQualityOfFit();
1511 for(vector<Model*>::const_iterator m =
m_CStates->begin();
1514 if(cw)(*m)->setShapeWeight(shapeweight);
1515 if((*m)->getQualityOfFit()>hqof) hqof=(*m)->getQualityOfFit();
1516 if((*m)->getQualityOfFit()<lqof) lqof=(*m)->getQualityOfFit();
1524 if(what ==
SW_SET && cem) {
1530 propu = cem.
getUB();
1531 propl = cem.
getLB();
1534 (float)
m_Data->getDim2Size());
1541 if(what ==
SW_UB) propu = prop;
1542 else if(what ==
SW_LB) propl = prop;
1549 propu = prop+plusminus;
1550 propl = prop-plusminus;
bool loadData(const char *filename, dword ppmm=0)
const std::map< std::string, StructPath > & getIPaths() const
ExpectationMap & getExpectationMap()
std::string getInfoFilename(const std::string &suffix) const
bool changeModel(const std::string &mname)
void startSearch(bool dostart=true)
dword readFlagString(const std::string &flags)
void setExpectationMap(const ExpectationMap &em)
bool writeFile(const char *filename) const
float getQualityOfFit() const
std::string m_CurPrototype
bool load(const char *bfile)
void attachSensor(sensor_cptr _sensor)
void rotate(float angle, const Point &c)
T & fromString(const std::string &str, T &v)
Implements a Node used by Model and Edge.
float getEdgeSensorFit(dword *npts=NULL) const
get average fit of sensors along edges
int getHLNode() const
Returns ID of highlighted node. Value is -1 if none is selected.
const std::string & getShownIP() const
std::map< std::string, MStructure > & getStructs()
const PropVec & getProperties() const
float getStdRadius(const Point ¢er) const
Returns mean squared distance from centroid.
bool triggerTest(int mx, int my, int what=0)
bool loadModel(const char *filename)
bool triggerTest(int mx, int my, int what)
bool triggerTest(int mx, int my, int what)
void setHLNode(int hlnode)
bool loadSpecies(const Species &spec)
void drawAllModels() const
const Model & getRepresentative() const
void adaptProportion(float ratio)
overall rest lengths sum is adapted to overall edge lengths by ratio
bool nextSelector(int walkdir=1, bool wrap=true, dword mincount=1)
void setShapeWeight(float weight)
const Node & getDirNode() const
void updateModels() const
dword duplicateState(const Model *model=NULL)
dword createEdgeSensors(float dist=0.1)
auto-create appropriate edge sensors (dist*stdRadius is distance)
std::string toString(T v)
const std::string & getDirectory() const
static void correctLBUB(PropVec &lb, PropVec &ub)
unsigned long getMilliSeconds()
const std::string & getSelectedSensor() const
Implements an Edge with spring functionality.
ParticleParam phys
physical parameter set
float getPropScale(const PropVec &prop)
bool hasFlag(dword flag) const
bool switchState(dword newstate)
bool startThread(int whatsup, void *data=NULL)
bool doCommand(const std::string &command, const std::string &value, int mx=0, int my=0)
std::shared_ptr< Sensor > sensor_ptr
void disableState(dword nstate=0xffffffff)
void setShownIP(const std::string &curip) const
void scale(float factor, bool movepoints=false)
multiply all rest lengths by factor
int sglBitmapString(const char *msg, int x, int y, void *font=(void *) GLUT_BITMAP_8_BY_13)
dword connectNodes()
Connect selected nodes.
void add(EMDistribution *ed)
int nearestNode(const Point &pos, float &dist=*(float *)(NULL)) const
void adaptRestLength(float ratio)
adapt restlengths towards current lengths by ratio
sensor_ptr getSensor(const std::string &id)
Node & setPos(const Point &p)
const std::string & getValue() const
dword getRefModelIDs(Iter iter) const
void setupSearch(enum SearchWhat what=SW_RESET, const PropVec &prop=PropVec())
bool stepSearch(float dt)
const Point getCenter() const
bool loadDBSelector(const char *filename)
float getSensorFit(dword *npts=NULL) const
get average sensor value
std::ostream & write(std::ostream &os, bool showcomment=false) const
bool getRefModel(dword id, Model &model) const
PropVec & setPropDir(PropVec &prop, float dir)
bool setTitle(const char *title)
const Searcher & getSearcher() const
bool getRefProp(dword id, PropVec &prop) const
void reattachSensors()
get sensors from sensor collection
bool load(const std::string &filename)
bool load(const char *filename)
bool showNextIP(int dir=1) const
const Model & getModel() const
std::map< std::string, Model * > m_Prototypes
const std::string & getFilename() const
PropVec & setPropPos(PropVec &prop, const Point2D &p)
float springconstant
spring constant
dword setFlag(dword flag)
void setUB(const PropVec &ub)
const std::string & getFilename() const
void toggleUpdateForAll(bool onoff=true)
const Dataset & getData() const
bool load(const char *filename)
const std::string & getPath() const
const std::string & getKey() const
const std::string & getBestInterpretation() const
DMatrix< T > & abs(DMatrix< T > &mat)
dword removeEdges()
Remove edges between selected nodes.
int addNode(const Node &node)
const Node & getNode(int index) const
const PropVec & getLB() const
dword getSelectedNodesN(dword state=Node::ST_SELECT) const
get number of selected nodes
SearcherParams & getSearchPara()
void setRefProp(dword id, const PropVec &prop)
bool m_ThreadActive[DO_LAST]
void setModel(const Model &model)
void adaptRestLengthSel(float ratio, const DMatrixf &selm)
adapt restlengths of selected edges towards current lengths by ratio
SensorCollection * getSensorCollection()
void translate(const Point &t)
const std::string & getName() const
void killState(dword state)
void setRefModel(dword id, const Model &model)
void draw(bool drawPoints=false) const
Draw using OpenGL.
dword getAllModels(Iter iter)
const Edge & getEdge(int index) const
int addEdge(const Edge &edge)
void removeNode(int nid)
Removes a node and its adjacent edges.
int distributeModel(const Model &model, int n=-1, float qth=0, bool count=false)
const PropVec & getUB() const
const std::string & getFilename() const
void setParseError(const std::string &msg="")
int sglBitmapStringOutlined(const char *msg, int x, int y, void *font=(void *) GLUT_BITMAP_8_BY_13)
void getQualityRange(float &lqof, float &hqof, float shapeweight=-1) const
dword select(const Species &rhs, enum Species::SpCompare how=Species::CMP_CONTAINS)
unsigned int getWinners(Iter iter) const
std::string getFlagString() const
Dataset & getSensorData()
std::string getErrorMsg() const
SensorCollection m_Sensors
bool readFile(const char *filename, bool fullread=true)
dword unsetFlag(dword flag)
std::vector< Model * > * m_CStates
bool nextSelection(int dir=1, bool wrap=true)
DMatrixf selMaskMat() const
compute mask matrix of selected nodes
void scaleSel(float factor, const DMatrixf &selm)
multiply all rest lengths of selected edges by factor
const std::string & getName() const
PropVec & setPropScale(PropVec &prop, float pscale)
MStructure & getNextStruct(int dir=1, bool wrap=true)
Species & getCurSpecies()
Returns a handle to the currently selected species in the data base.
vuMutex m_RunMutex[DO_LAST]
std::map< std::string, std::vector< Model * > > m_Instances
float getDeformation() const
normalized length variation to compensate for different sizes
void run(int whatsup, void *data)
virtual from vuThread
bool setStatusText(const char *stext)
bool loadDB(const char *filename)
static void usleep(unsigned long ms)
sleep for n microseconds (!!not yet implemented for win32)
void enableState(dword nstate)
void setLB(const PropVec &lb)
sensor_ptr addSensor(const std::string &key, sensor_ptr s)
void setRepresentative(const Model &model)
void update()
should be called when data base has changed