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

#include <SensorColl.h>

Inheritance diagram for SensorCollection:
Inheritance graph
[legend]
Collaboration diagram for SensorCollection:
Collaboration graph
[legend]

Public Member Functions

 SensorCollection ()
 
 ~SensorCollection ()
 
sensor_ptr addSensor (const std::string &key, sensor_ptr s)
 
sensor_ptr addSensor (sensor_ptr s)
 
sensor_ptr readSensor (ParseFile &is)
 
sensor_ptr getSensor (const std::string &id)
 
SensorCollectionmerge (SensorCollection &rhs)
 
bool isPrinted (const std::string &id) const
 
void setPrinted (const std::string &id)
 
void clearPrintList (bool skipdefaults=true)
 
void refModel (Model *model) const
 
void unrefModel (Model *model) const
 
void updateModels () const
 
void selectSensor (const std::string &name)
 
const std::string & getSelectedSensor () const
 

Protected Attributes

std::set< std::string > m_Printlist
 
std::set< Model * > m_Models
 references to attached geometry More...
 
std::string m_SelSensor
 

Friends

std::ostream & operator<< (std::ostream &os, const SensorCollection &sc)
 

Detailed Description

Definition at line 11 of file SensorColl.h.

Constructor & Destructor Documentation

SensorCollection::SensorCollection ( )

Definition at line 16 of file SensorColl.cpp.

References getZeroSensor().

17 {
18  addSensor(getZeroSensor()); // this is our zeroth sensor
19 }
sensor_ptr getZeroSensor()
Definition: Sensor.cpp:234
sensor_ptr addSensor(const std::string &key, sensor_ptr s)
Definition: SensorColl.cpp:24
SensorCollection::~SensorCollection ( )

Definition at line 21 of file SensorColl.cpp.

22 { }

Member Function Documentation

sensor_ptr SensorCollection::addSensor ( const std::string &  key,
sensor_ptr  s 
)

Definition at line 24 of file SensorColl.cpp.

Referenced by Model::attachDataset(), Brain::Brain(), Model::readSensor(), and Brain::triggerTest().

25 {
26  s->setID(key);
27  return addSensor(s);
28 }
sensor_ptr addSensor(const std::string &key, sensor_ptr s)
Definition: SensorColl.cpp:24
sensor_ptr SensorCollection::addSensor ( sensor_ptr  s)

Definition at line 30 of file SensorColl.cpp.

References NULL, and SHOW.

30  {
31  if(!s) return NULL;
32  if(s->getID().empty()) return NULL; //s->setID(size());
33  sensor_ptr &spr = operator[](s->getID());
34  selectSensor(s->getID());
35  if(spr == NULL) {
36  spr = s;
37  return s;
38  }else {
39  SHOW("replacing sensor "<<s->getID());
40  if(spr->assignRef(s)) {
41  SHOW("assigning");
42  s->replaceBy(spr);
43  } else {
44  SHOW("replacing");
45  spr->replaceBy(s);
46  spr = s;
47  }
48  return spr;
49  }
50 }
#define NULL
Definition: simpletypes.h:9
std::shared_ptr< Sensor > sensor_ptr
Definition: types_fwd.h:15
void selectSensor(const std::string &name)
Definition: SensorColl.h:30
#define SHOW(a)
Definition: SensorColl.cpp:13
void SensorCollection::clearPrintList ( bool  skipdefaults = true)

Definition at line 66 of file SensorColl.cpp.

Referenced by operator<<().

67 {
68  m_Printlist.clear();
69  if(skipdefaults) {
70  m_Printlist.insert("d0");
71  m_Printlist.insert("0");
72  }
73 }
std::set< std::string > m_Printlist
Definition: SensorColl.h:35
const std::string& SensorCollection::getSelectedSensor ( ) const
inline

Definition at line 32 of file SensorColl.h.

References m_SelSensor.

Referenced by Brain::triggerTest().

33  { return m_SelSensor; }
std::string m_SelSensor
Definition: SensorColl.h:37
sensor_ptr SensorCollection::getSensor ( const std::string &  id)

Definition at line 52 of file SensorColl.cpp.

Referenced by Model::attachDataset(), Model::readNode(), Model::reattachSensors(), and Brain::triggerTest().

52  {
53  iterator fs = find(id);
54  if(fs != end()) {
55  return fs->second;
56  } else {
57 // char sid[5];
58 // Sensor::getNumberString(sid,id);
59 // cout << "zeroing " << sid << endl;
60  sensor_ptr zs = makeSensor<ZeroSensor>();
61  zs->setID(id);
62  return addSensor(zs);
63  }
64 }
std::shared_ptr< Sensor > sensor_ptr
Definition: types_fwd.h:15
sensor_ptr addSensor(const std::string &key, sensor_ptr s)
Definition: SensorColl.cpp:24
bool SensorCollection::isPrinted ( const std::string &  id) const

Definition at line 75 of file SensorColl.cpp.

Referenced by Sensor::hprint(), CombiSensor::hprint(), and operator<<().

76 {
77  return m_Printlist.find(id) != m_Printlist.end();
78 }
std::set< std::string > m_Printlist
Definition: SensorColl.h:35
SensorCollection & SensorCollection::merge ( SensorCollection rhs)

Definition at line 256 of file SensorColl.cpp.

References Sensor::replaceBy().

Referenced by Model::mergeSensorCollection().

257 {
258  if(this == &rhs) return *this;
259  for(map<string, sensor_ptr >::iterator si = rhs.begin();
260  si != rhs.end(); si++)
261  {
262  if(!si->first.empty() && si->first!="0") {
263  sensor_ptr spr = operator[](si->first); // sensor from lhs of collection assignment
264  if(!spr) {
265  spr = si->second;
266  } else {
267  bool lnzs = !std::dynamic_pointer_cast<ZeroSensor>(spr); // lhs sensor not zero
268  bool rnzs = !std::dynamic_pointer_cast<ZeroSensor>(si->second); // rhs sensor not zero
269  // TODO: inverted original logic, test if still valid
270  if(rnzs) {
271  spr->replaceBy(si->second);
272  // spr = si->second;
273  } else {
274  si->second->replaceBy(spr);
275  }
276  }
277  }
278  }
279  return *this;
280 }
void replaceBy(sensor_ptr target)
Definition: Sensor.cpp:44
std::shared_ptr< Sensor > sensor_ptr
Definition: types_fwd.h:15
sensor_ptr SensorCollection::readSensor ( ParseFile is)

Definition at line 101 of file SensorColl.cpp.

References ParseFile::getKey(), ParseFile::getNextLine(), ParseFile::getValue(), getZeroSensor(), NULL, ParseFile::pushLine(), ParseFile::setParseError(), and SHOW.

Referenced by Model::readSensor().

102 {
103  if(!is.getNextLine()) return NULL;
104  if(is.getKey() != "s") {
105  is.pushLine();
106  return NULL;
107  }
108  istringstream vs(is.getValue());
109  vs >> ws; // read key
110  string skey;
111  //vs.width(2047);
112  vs >> skey;
113  vs >> ws; // read type
114  string para1;
115  vs >> para1;
116  char stype;
117  sensor_cptr source = NULL;
118  if (para1 == "source") {
119  string sname;
120  vs >> sname;
121  source = getSensor(sname);
122  if(std::dynamic_pointer_cast<const ZeroSensor>(source))
123  cout << "Using zero sensor as source. Source name was: "
124  << sname <<endl;
125  else {
126  SHOW("Using source " << source->getID());
127  }
128  vs >> stype;
129  } else {
130  stype = para1[0];
131  }
132  if(source == NULL) {
133  source = getSensor(string("d0"));
134  }
135  sensor_ptr s = NULL;
136  switch(stype) {
137  case 'i' :
138  s = makeSensor<IntensitySensor>(source);
139  SHOW("created intensity sensor");
140  break;
141  case 'g' :
142  {
143  float scale=0;
144  vs >> scale;
145  s = makeSensor<SmoothIntensitySensor>(source, scale);
146  SHOW("created Gaussian sensor of scale " << scale);
147  break;
148  }
149  case 'd' :
150  {
151  //float scale=0;
152  //vs >> scale;
153  s = makeSensor<GradMagSensor>(source);
154  SHOW("created gm sensor");// of scale " << scale);
155  break;
156  }
157  case 'c' :
158  {
159 // float scale=0;
160 // vs >> scale;
161  s = makeSensor<CornerSensor>(source);
162  SHOW("created corner sensor");// of scale " << scale);
163  break;
164  }
165  case 'K' :
166  s = makeSensor<CombiSensor>();
167  std::dynamic_pointer_cast<CombiSensor>(s)->normalizeInput(false);
168  // is legally constructed in the next case 'k'
169  case 'k' :
170  {
171  int nsensors=0;
172  //vs >> nsensors;
173  if(!s) s = makeSensor<CombiSensor>(); //normalized input
174  string sname;
175  while(vs >> sname) {
176  float weight=1;
177  vs >> weight;
178  sensor_ptr ss = getSensor(sname);
179  if(ss == getZeroSensor())
180  cout << "added zero sensor" << endl;
181  std::dynamic_pointer_cast<CombiSensor>(s)->setSource(ss,weight);
182  nsensors++;
183  }
184  SHOW("created combi sensor with " << nsensors<<" sub-sensors.");
185  break;
186  }
187  case 'm' :
188  {
189  int nc = source ? source->getNChannels() : 0;
190  vector<float> weights;
191  weights.reserve(nc);
192  float weight=1;
193  while(vs >> weight) {
194  weights.push_back(weight);
195  cout << weight << " ";
196  }
197  cout << endl;
198  s = makeSensor<MCIntensitySensor>(source);
199  s->setCWeights(weights);
200  SHOW("created multi-channel sensor.");
201  break;
202  }
203  case 'M' :
204  {
205  s = makeSensor<MCGSensor>(source);
206  SHOW("created multi-channel gradient sensor.");
207  break;
208  }
209  case 'r' :
210  {
211  s = makeSensor<CRSensor>(source);
212  SHOW("created multi-channel chrominance sensor.");
213  break;
214  }
215  case 'C' :
216  {
217  string fname;
218  vs >> fname;
219  if(!fname.empty()) {
220  s = makeSensor<MahalSensor>(source, fname);
221  if(!std::dynamic_pointer_cast<MahalSensor>(s)->getFilename().empty()) {
222  SHOW("created colour classification sensor");
223  } else {
224  SHOW("error loading configuration file for colour sensor "
225  << fname);
226  s = sensor_ptr();
227  }
228  }
229  break;
230  }
231  case 'f' :
232  {
233  string mapping;
234  vs >> mapping;
235  s = makeSensor<MappingSensor>(source, mapping);
236  std::dynamic_pointer_cast<MappingSensor>(s)->readParams(vs);
237  SHOW("created mapping sensor of type " <<
238  std::dynamic_pointer_cast<MappingSensor>(s)->getMappingName());
239  break;
240  }
241  case 'o' :
242  {
243  s = makeSensor<ZeroSensor>();
244  SHOW("created zero sensor");
245  break;
246  }
247  }
248  if(!s) {
249  is.setParseError(string("unknown sensor type ")+stype);
250  throw new IOException("Error reading sensor.");
251  }
252  s->setID(skey);
253  return s;
254 }
#define NULL
Definition: simpletypes.h:9
std::shared_ptr< Sensor > sensor_ptr
Definition: types_fwd.h:15
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
const std::string & getKey() const
Definition: ParseFile.h:56
void setParseError(const std::string &msg="")
Definition: ParseFile.h:80
std::shared_ptr< const Sensor > sensor_cptr
Definition: types_fwd.h:17
void pushLine(const std::string &line)
Definition: ParseFile.h:74
#define SHOW(a)
Definition: SensorColl.cpp:13
const bool getNextLine()
Definition: ParseFile.h:59
void SensorCollection::refModel ( Model model) const

Definition at line 282 of file SensorColl.cpp.

Referenced by Model::attachSensorColl(), and Model::Model().

283 {
284  m_Models.insert(model);
285 }
std::set< Model * > m_Models
references to attached geometry
Definition: SensorColl.h:36
void SensorCollection::selectSensor ( const std::string &  name)
inline

Definition at line 30 of file SensorColl.h.

References m_SelSensor.

31  { m_SelSensor = name; }
std::string m_SelSensor
Definition: SensorColl.h:37
void SensorCollection::setPrinted ( const std::string &  id)

Definition at line 80 of file SensorColl.cpp.

Referenced by Sensor::hprint(), and CombiSensor::hprint().

81 {
82  m_Printlist.insert(id);
83 }
std::set< std::string > m_Printlist
Definition: SensorColl.h:35
void SensorCollection::unrefModel ( Model model) const

Definition at line 287 of file SensorColl.cpp.

Referenced by Model::attachSensorColl().

288 {
289  m_Models.erase(model);
290 }
std::set< Model * > m_Models
references to attached geometry
Definition: SensorColl.h:36
void SensorCollection::updateModels ( ) const

Definition at line 292 of file SensorColl.cpp.

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

293 {
294  for(set<Model*>::iterator mo = m_Models.begin();
295  mo != m_Models.end(); mo++)
296  (*mo)->reattachSensors();
297 }
std::set< Model * > m_Models
references to attached geometry
Definition: SensorColl.h:36

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const SensorCollection sc 
)
friend

Definition at line 85 of file SensorColl.cpp.

86 {
87  ((SensorCollection*)&sc)->m_Printlist.clear();
88  for(map<string,sensor_ptr>::const_iterator s=sc.begin(); s!=sc.end(); s++) {
89  if (s->second->getID() != "0" && // zero sensor
90  !s->second->getID().empty() && // uninitialized sensor
91  s->second->getID() != "d0" &&
92  !sc.isPrinted(s->second->getID())
93  )
94  {
95  s->second->hprint(os, (SensorCollection*)&sc);
96  }
97  }
98  return os;
99 }

Member Data Documentation

std::set<Model*> SensorCollection::m_Models
mutableprotected

references to attached geometry

Definition at line 36 of file SensorColl.h.

std::set<std::string> SensorCollection::m_Printlist
protected

Definition at line 35 of file SensorColl.h.

std::string SensorCollection::m_SelSensor
protected

Definition at line 37 of file SensorColl.h.

Referenced by getSelectedSensor(), and selectSensor().


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