Structural deformable models
Brain.h
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 #ifndef _BRAIN_H_
3 #define _BRAIN_H_
4 
5 
6 #ifdef WIN32
7 #include <windows.h>
8 #endif
9 #include <GL/gl.h>
10 #include <GL/glu.h>
11 
12 #include <list>
13 #include <map>
14 #include <vector>
15 
16 #include "vuThread.h"
17 #include "common.h"
18 #include "Model.h"
19 #include "SensorColl.h"
20 #include "SpeciesDB.h"
21 #include "Searcher.h"
22 #include "StructTable.h"
23 #include "Data.h"
24 
25 #define TIMESTEP 0.02
26 
27 class Brain : public vuThread {
28 public:
29  Brain();
30  ~Brain();
31 
32  bool load(const char *bfile);
33  bool loadModel(const char* filename);
34  bool loadData(const char* filename, dword ppmm=0);
35  bool loadDB(const char* filename);
36  bool loadDBSelector(const char* filename);
37  bool loadSpecies(const Species& spec);
38 
39  const Model& getModel() {return *m_Geom;}
40  const Dataset& getData() const;
42 
43  void attachBrowseData();
44 
45  void drawAllModels() const;
46  bool triggerTest(int mx, int my, int what=0);
47  bool doCommand(const std::string& command, const std::string& value,
48  int mx=0, int my=0);
49  bool isDone() const { return m_Done; }
50 
54  void run(int whatsup, void* data);
55 
58  dword duplicateState(const Model *model = NULL);
59 
60  bool switchState(dword newstate);
61  void killState(dword state);
62  void killAllStates();
64  void toggleUpdateForAll(bool onoff=true) { m_UpdateAllModels=onoff; }
65 
66  void evolve(float dt);
67 
68  void findWinners();
69 
70  const SensorCollection& getSensors() const { return m_Sensors; }
72 
73  void getQualityRange(float &lqof, float &hqof, float shapeweight=-1) const;
74  int distributeModel(const Model &model,
75  int n=-1, float qth=0, bool count=false);
77  bool changeModel(const std::string &mname);
79  bool mergeInstances();
80  template<class Iter>
81  dword getAllModels( Iter iter );
83 protected:
84  int getBindex(int bx, int by, bool &culled=*((bool*)NULL));
86  void setupSearch(enum SearchWhat what=SW_RESET,
87  const PropVec& prop=PropVec());
88 protected:
93  std::vector<Model*> *m_CStates;
94  std::map<std::string,Model*> m_Prototypes;
95  std::map<std::string, std::vector<Model*> > m_Instances;
96  std::string m_CurPrototype;
101  float m_TimeStep;
102  float m_TimeScale;
106  bool m_Done;
111  std::list<Model> m_Winners;
113 };
114 
115 template<class Iter>
116 inline dword Brain::getAllModels( Iter iter )
117 {
118  dword nm=0;
119  if(m_CStates)
120  for(std::vector<Model*>::iterator mi = m_CStates->begin();
121  mi != m_CStates->end(); mi++)
122  {
123  *iter++ = *mi;
124  nm++;
125  }
126 // for(std::map<std::string, std::vector<Model*> >::iterator
127 // ti=m_Instances.begin(); ti != m_Instances.end(); ti++) {
128 // for(std::vector<Model*>::iterator gi=ti->second.begin();
129 // gi!=ti->second.end(); gi++)
130 // {
131 // *iter++ = *gi;
132 // nm++;
133 // }
134 // }
135 // for(std::map<std::string,Model*>::iterator gi=m_Prototypes.begin();
136 // gi!=m_Prototypes.end(); gi++)
137 // {
138 // *iter++ = gi->second;
139 // nm++;
140 // }
141  return nm;
142 }
143 
144 #endif
std::shared_ptr< Dataset > dataset_ptr
Definition: types_fwd.h:19
bool loadData(const char *filename, dword ppmm=0)
Definition: Brain.cpp:288
bool changeModel(const std::string &mname)
Definition: Brain.cpp:231
#define NULL
Definition: simpletypes.h:9
std::string m_CurPrototype
Definition: Brain.h:96
bool load(const char *bfile)
Definition: Brain.cpp:87
SpeciesDB m_DB
Definition: Brain.h:98
bool triggerTest(int mx, int my, int what=0)
Definition: Brain.cpp:442
bool loadModel(const char *filename)
Definition: Brain.cpp:163
DBSelector m_DBSelector
Definition: Brain.h:99
~Brain()
Definition: Brain.cpp:46
bool loadSpecies(const Species &spec)
Definition: Brain.cpp:210
void drawAllModels() const
Definition: Brain.cpp:1344
bool isDone() const
Definition: Brain.h:49
bool mergeInstances()
Definition: Brain.cpp:261
VVector< float, 4 > PropVec
Definition: PropVec.h:8
dword duplicateState(const Model *model=NULL)
Definition: Brain.cpp:1267
Model * m_Geom
Definition: Brain.h:92
void attachBrowseData()
Definition: Brain.cpp:300
bool switchState(dword newstate)
Definition: Brain.cpp:1255
Species m_CSpecies
Definition: Brain.h:100
bool doCommand(const std::string &command, const std::string &value, int mx=0, int my=0)
Definition: Brain.cpp:1150
SensorCollection & getSensors()
Definition: Brain.h:71
bool m_UpdateAllModels
Definition: Brain.h:103
void killAllStates()
Definition: Brain.cpp:1291
Brain()
Definition: Brain.cpp:27
RunWhat
some options for run(whatsup)
Definition: Brain.h:52
void setupSearch(enum SearchWhat what=SW_RESET, const PropVec &prop=PropVec())
Definition: Brain.cpp:1520
bool loadDBSelector(const char *filename)
Definition: Brain.cpp:203
bool m_Done
Definition: Brain.h:106
std::map< std::string, Model * > m_Prototypes
Definition: Brain.h:94
void findWinners()
const SensorCollection & getSensors() const
Definition: Brain.h:70
void evolve(float dt)
Definition: Brain.cpp:1424
void toggleUpdateForAll(bool onoff=true)
Definition: Brain.h:64
const Dataset & getData() const
Definition: Brain.cpp:77
Definition: Brain.h:27
Searcher m_Search
Definition: Brain.h:110
Definition: Model.h:33
dword m_CurState
Definition: Brain.h:97
std::list< Model > m_Winners
Definition: Brain.h:111
bool m_ImmediateData
Definition: Brain.h:108
bool m_ThreadActive[DO_LAST]
Definition: Brain.h:105
unsigned long dword
Definition: simpletypes.h:6
dataset_ptr m_Data
Definition: Brain.h:89
void killState(dword state)
Definition: Brain.cpp:1280
float m_TimeStep
Definition: Brain.h:101
bool m_DrawOwnState
Definition: Brain.h:109
Definition: Data.h:21
dword getAllModels(Iter iter)
Definition: Brain.h:116
vuMutex m_GeomMutex
Definition: Brain.h:104
vuMutex & getGeomMutex()
Definition: Brain.h:82
vuMutex m_DataMutex
Definition: Brain.h:104
StructTable m_SModel
Definition: Brain.h:112
int distributeModel(const Model &model, int n=-1, float qth=0, bool count=false)
Definition: Brain.cpp:1299
int getBindex(int bx, int by, bool &culled=*((bool *) NULL))
dataset_ptr m_BrowseData
Definition: Brain.h:90
void getQualityRange(float &lqof, float &hqof, float shapeweight=-1) const
Definition: Brain.cpp:1506
Dataset & getSensorData()
Definition: Brain.cpp:82
SensorCollection m_Sensors
Definition: Brain.h:91
std::vector< Model * > * m_CStates
Definition: Brain.h:93
bool m_DesignMode
Definition: Brain.h:107
float m_TimeScale
Definition: Brain.h:102
void killCurrentState()
Definition: Brain.h:63
vuMutex m_RunMutex[DO_LAST]
Definition: Brain.h:104
std::map< std::string, std::vector< Model * > > m_Instances
Definition: Brain.h:95
void run(int whatsup, void *data)
virtual from vuThread
Definition: Brain.cpp:334
bool loadDB(const char *filename)
Definition: Brain.cpp:195
const Model & getModel()
Definition: Brain.h:39
SearchWhat
Definition: Brain.h:85