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

#include <SensorSet.h>

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

Public Member Functions

 CombiSensor (int nchannels=0)
 
virtual ~CombiSensor ()
 
int getNChannels () const
 
int getSkip () const
 
void changeSource (sensor_cptr _source)
 
std::ostream & print (std::ostream &os) const
 
std::ostream & hprint (std::ostream &os, SensorCollection *sc) const
 
void clearSources ()
 
void setNSources (int n)
 
void setSource (sensor_ptr _source, float weight, int id)
 
void setSource (sensor_ptr _source, float weight)
 
Sensorassign (const Sensor &rhs)
 
void normalizeInput (bool doit=true)
 
bool isInputNormalized () const
 
- Public Member Functions inherited from PPSensor
 PPSensor ()
 
virtual float getValue (int x, int y) const
 
virtual Point getGradient (int x, int y) const
 
virtual bool performUpdate ()
 
void togglePP (enum PPState state=PP_DO)
 
dword getPPState () const
 
- Public Member Functions inherited from Sensor
virtual ~Sensor ()
 
sensor_cptr getSource ()
 
void replaceBy (sensor_ptr target)
 
bool assignRef (sensor_cptr rhs)
 
float getValue (const Point &p) const
 get value at position p using nearest neighbour interpolation More...
 
virtual std::vector< float > getMValue (int x, int y) const
 get multi-channel value More...
 
Point2D getGradient (const Point2D &p) const
 get gradient at position p using nearest neighbor interpolation More...
 
float getMax () const
 
float getMin () const
 
float getMinMaxRange () const
 
float getWeightedValue (int x, int y) const
 get max normalized value at discrete position range [0,1] More...
 
Point2D getWeightedGradient (int x, int y) const
 get range weighted gradient at discrete position More...
 
void setCWeights (const std::vector< float > &weights)
 
const std::vector< float > & getCWeights () const
 
void setDirection (const Point &dir)
 
const PointgetDirection () const
 
void setScale (float _scale)
 
float getScale () const
 
bool isModified (dword mask=UPD_ALL) const
 
void setModified (dword mask=UPD_ALL)
 
void unsetModified (dword mask=UPD_ALL)
 
bool isUpdate (dword udMask) const
 
void enableUpdate (dword udMask)
 
void disableUpdate (dword udMask)
 
virtual int getDim1Size () const
 
virtual int getDim2Size () const
 
virtual int getDim3Size () const
 
bool isValid (int x, int y) const
 
virtual Image< float > createSensorImage () const
 
const std::string & getID () const
 
void setID (const std::string &id)
 
void refSuperSensor (sensor_ptr super)
 
void unrefSuperSensor (sensor_ptr super)
 
void invalidateSource ()
 
template<typename Derived >
std::shared_ptr< Derived > shared_from_base ()
 

Protected Member Functions

float calcValue (int x, int y) const
 Computes a scalar product between the multi-channel intensities and the cweights vector. More...
 
std::vector< float > calcMValue (int x, int y) const
 
- Protected Member Functions inherited from PPSensor
void fitSheets ()
 
virtual void calcAllValues ()
 
virtual void calcAllGradients ()
 
- Protected Member Functions inherited from Sensor
 Sensor (dword updateMask)
 
 Sensor ()
 
virtual Point calcGradient (int x, int y) const
 
virtual void calcMinMax ()
 

Protected Attributes

std::vector< sensor_ptrsources
 
bool m_NormalizeInput
 
- Protected Attributes inherited from PPSensor
Image< float > values
 caching sheet for sensed values More...
 
Image< Pointgradients
 caching sheet for gradients More...
 
dword doPP
 do preprocessing? More...
 
- Protected Attributes inherited from Sensor
sensor_cptr source
 
float scale
 
std::vector< float > cweights
 multi-channel weights ('color') More...
 
Point dir
 direction parameter More...
 
float maxval
 
float minval
 overall minimum and maximum More...
 
float mean
 
float stdev
 overall mean and stdev More...
 
dword toupdate
 bitflag for updates More...
 
dword updateMask
 bitflag to mask unimportant updates More...
 
std::string m_ID
 
int m_Skip
 
int m_AddSkip
 

Additional Inherited Members

- Public Types inherited from PPSensor
enum  PPState { PP_DONT =0, PP_DO, PP_FORCE }
 
- Public Types inherited from Sensor
enum  UpdateParam {
  UPD_NOTHING =0, UPD_DATA =1, UPD_SCALE =2, UPD_CWEIGHTS =4,
  UPD_DIR =8, UPD_MINMAX =16, UPD_LAST =32, UPD_ALL =0xffffffff
}
 
- Static Public Member Functions inherited from Sensor
static dword getStringNumber (const char *sid)
 
static void getNumberString (char sid[5], dword id)
 

Detailed Description

Multi-Sensor

Definition at line 259 of file SensorSet.h.

Constructor & Destructor Documentation

CombiSensor::CombiSensor ( int  nchannels = 0)

Definition at line 94 of file SensorSet.cpp.

References Sensor::enableUpdate(), setNSources(), Sensor::UPD_CWEIGHTS, and Sensor::UPD_DATA.

95  : m_NormalizeInput(true)
96 {
97  setNSources(nchannels);
99  //togglePP(PP_FORCE);
100 }
bool m_NormalizeInput
Definition: SensorSet.h:288
void setNSources(int n)
Definition: SensorSet.cpp:123
void enableUpdate(dword udMask)
Definition: Sensor.h:113
CombiSensor::~CombiSensor ( )
virtual

Definition at line 102 of file SensorSet.cpp.

References sources.

103 {
104  for(vector<sensor_ptr>::iterator s=sources.begin();
105  s!=sources.end(); s++)
106  {
107  (*s)->unrefSuperSensor( shared_from_this() );
108  }
109 }
std::vector< sensor_ptr > sources
Definition: SensorSet.h:287

Member Function Documentation

Sensor & CombiSensor::assign ( const Sensor rhs)
virtual

Reimplemented from PPSensor.

Definition at line 188 of file SensorSet.cpp.

References PPSensor::assign(), Sensor::getCWeights(), setNSources(), setSource(), and sources.

189 {
190  if(&rhs != this) {
191  PPSensor::assign(rhs);
192  if(typeid(&rhs) == typeid(CombiSensor*)) {
193  const CombiSensor& crhs = (const CombiSensor&) rhs;
194  if(sources != crhs.sources) {
195  setNSources(crhs.sources.size());
196  int sid = 0;
197  const vector<float>& weights = crhs.getCWeights();
198  for(vector<sensor_ptr>::const_iterator s = crhs.sources.begin();
199  s != crhs.sources.end(); s++, sid++)
200  setSource(std::const_pointer_cast<Sensor>(*s), weights[sid], sid);
201  }
202  }
203  }
204  return *this;
205 }
std::vector< sensor_ptr > sources
Definition: SensorSet.h:287
const std::vector< float > & getCWeights() const
Definition: Sensor.h:97
void setNSources(int n)
Definition: SensorSet.cpp:123
Sensor & assign(const Sensor &rhs)
Definition: Sensor.cpp:324
void setSource(sensor_ptr _source, float weight, int id)
Definition: SensorSet.cpp:133
std::vector<float> CombiSensor::calcMValue ( int  x,
int  y 
) const
inlineprotectedvirtual

Calculate a multi-valued sensor result. The size of the returned vector is the same as getNChannels().

Reimplemented from Sensor.

Definition at line 306 of file SensorSet.h.

References Sensor::cweights, and Sensor::getNChannels().

306  {
307  std::vector<float> vv(getNChannels());
308  std::vector<float>::iterator v = vv.begin();
309  std::vector<sensor_ptr>::const_iterator s = sources.begin();
310  std::vector<float>::const_iterator w = cweights.begin();
311  if(m_NormalizeInput)
312  for(; v != vv.end(); v++, s++,w++)
313  *v = (*s)->getWeightedValue(x,y)*(*w);
314  else
315  for(; v != vv.end(); v++, s++,w++)
316  *v = (*s)->getValue(x,y)*(*w);
317  return vv;
318  }
std::vector< sensor_ptr > sources
Definition: SensorSet.h:287
int getNChannels() const
Definition: SensorSet.h:265
bool m_NormalizeInput
Definition: SensorSet.h:288
std::vector< float > cweights
multi-channel weights (&#39;color&#39;)
Definition: Sensor.h:174
float CombiSensor::calcValue ( int  x,
int  y 
) const
inlineprotectedvirtual

Computes a scalar product between the multi-channel intensities and the cweights vector.

Implements Sensor.

Definition at line 291 of file SensorSet.h.

References Sensor::cweights.

291  {
292  float result = 0.0f;
293  std::vector<sensor_ptr>::const_iterator s = sources.begin();
294  std::vector<float>::const_iterator w = cweights.begin();
295  if(m_NormalizeInput)
296  for(; s != sources.end(); s++,w++) {
297  result += (*s)->getWeightedValue(x,y)*(*w);
298  }
299  else
300  for(; s != sources.end(); s++,w++) {
301  result += (*s)->getValue(x,y)*(*w);
302  }
303  return result;
304  }
std::vector< sensor_ptr > sources
Definition: SensorSet.h:287
bool m_NormalizeInput
Definition: SensorSet.h:288
std::vector< float > cweights
multi-channel weights (&#39;color&#39;)
Definition: Sensor.h:174
void CombiSensor::changeSource ( sensor_cptr  _source)
virtual

Reimplemented from Sensor.

Definition at line 154 of file SensorSet.cpp.

References Sensor::changeSource(), Sensor::enableUpdate(), print(), Sensor::setModified(), setSource(), Sensor::source, sources, TRACE, and Sensor::UPD_MINMAX.

155 {
156  if(!_source) return;
157  const string& sid = _source->getID();
158  vector<sensor_ptr>::iterator s = sources.begin();
159  while(s!=sources.end() && (*s)->getID()!=sid)
160  s++;
161  if(s!=sources.end()) { // && sid == (*s)->getID()) { // use assert?
162  source = *s;
163  PPSensor::changeSource(_source);
164  *s = std::const_pointer_cast<Sensor>(source);
165  if(!std::const_pointer_cast<Sensor>(source)->isUpdate(UPD_MINMAX)) {
166  std::const_pointer_cast<Sensor>(source)->enableUpdate(UPD_MINMAX);
167  std::const_pointer_cast<Sensor>(source)->setModified(UPD_MINMAX);
168  }
169  } else {
170  TRACE("error replacing element <" << sid << "> in combi sensor - appending instead.");
171  print(cout) << endl;
172  setSource(std::const_pointer_cast<Sensor>(_source),1.f);
173  }
174 }
std::vector< sensor_ptr > sources
Definition: SensorSet.h:287
virtual void changeSource(sensor_cptr _source)
Definition: Sensor.cpp:96
std::ostream & print(std::ostream &os) const
Definition: SensorSet.cpp:207
#define TRACE(msg)
Definition: common.h:14
Definition: Sensor.h:21
void enableUpdate(dword udMask)
Definition: Sensor.h:113
void setSource(sensor_ptr _source, float weight, int id)
Definition: SensorSet.cpp:133
sensor_cptr source
Definition: Sensor.h:170
void setModified(dword mask=UPD_ALL)
Definition: Sensor.h:110
void CombiSensor::clearSources ( )

Definition at line 111 of file SensorSet.cpp.

References Sensor::cweights, Sensor::setModified(), sources, Sensor::UPD_CWEIGHTS, and Sensor::UPD_DATA.

112 {
113  vector<sensor_ptr>::iterator s=sources.begin();
114  while(s!=sources.end()) {
115  (*s)->unrefSuperSensor( shared_from_this() );
116  s++;
117  }
118  sources.clear();
119  cweights.clear();
121 }
std::vector< sensor_ptr > sources
Definition: SensorSet.h:287
std::vector< float > cweights
multi-channel weights (&#39;color&#39;)
Definition: Sensor.h:174
void setModified(dword mask=UPD_ALL)
Definition: Sensor.h:110
int CombiSensor::getNChannels ( ) const
inlinevirtual

Reimplemented from Sensor.

Definition at line 265 of file SensorSet.h.

265 { return sources.size(); }
std::vector< sensor_ptr > sources
Definition: SensorSet.h:287
int CombiSensor::getSkip ( ) const
inlinevirtual

Reimplemented from Sensor.

Definition at line 266 of file SensorSet.h.

References Sensor::changeSource(), Sensor::hprint(), Sensor::m_Skip, and IntensitySensor::print().

266  {
267  int m_Skip = 0;
268  for(std::vector<sensor_ptr>::const_iterator s = sources.begin();
269  s!=sources.end(); s++)
270  if((*s)->getSkip() > m_Skip) m_Skip = (*s)->getSkip();
271  return m_Skip;
272  }
std::vector< sensor_ptr > sources
Definition: SensorSet.h:287
int m_Skip
Definition: Sensor.h:182
ostream & CombiSensor::hprint ( std::ostream &  os,
SensorCollection sc 
) const
virtual

Reimplemented from Sensor.

Definition at line 222 of file SensorSet.cpp.

References SensorCollection::isPrinted(), Sensor::m_ID, print(), SensorCollection::setPrinted(), and sources.

223 {
224  if(sc->isPrinted(m_ID)) return os;
225  for(vector<sensor_ptr>::const_iterator s=sources.begin();
226  s!=sources.end(); s++)
227  {
228  (*s)->hprint(os, sc);
229  }
230  if(sc->isPrinted(m_ID)) return os;
231  sc->setPrinted(m_ID);
232  return (print(os) << endl);
233 }
std::vector< sensor_ptr > sources
Definition: SensorSet.h:287
std::ostream & print(std::ostream &os) const
Definition: SensorSet.cpp:207
void setPrinted(const std::string &id)
Definition: SensorColl.cpp:80
bool isPrinted(const std::string &id) const
Definition: SensorColl.cpp:75
std::string m_ID
Definition: Sensor.h:181
bool CombiSensor::isInputNormalized ( ) const
inline

Definition at line 285 of file SensorSet.h.

285 { return m_NormalizeInput; }
bool m_NormalizeInput
Definition: SensorSet.h:288
void CombiSensor::normalizeInput ( bool  doit = true)
inline

Definition at line 284 of file SensorSet.h.

284 { m_NormalizeInput = doit; }
bool m_NormalizeInput
Definition: SensorSet.h:288
ostream & CombiSensor::print ( std::ostream &  os) const
virtual

Reimplemented from Sensor.

Definition at line 207 of file SensorSet.cpp.

References Sensor::cweights, Sensor::getID(), m_NormalizeInput, and sources.

Referenced by changeSource(), and hprint().

208 {
209  os << "s " << getID() << " ";
210  //Sensor::print(os); would print modified source
211  if(m_NormalizeInput) os << "k";
212  else os << "K";
213  vector<float>::const_iterator w = cweights.begin();
214  for(vector<sensor_ptr>::const_iterator s=sources.begin();
215  s!=sources.end(); s++, w++)
216  {
217  os << " " << (*s)->getID() << " " << *w;
218  }
219  return os;
220 }
std::vector< sensor_ptr > sources
Definition: SensorSet.h:287
bool m_NormalizeInput
Definition: SensorSet.h:288
std::vector< float > cweights
multi-channel weights (&#39;color&#39;)
Definition: Sensor.h:174
const std::string & getID() const
Definition: Sensor.h:128
void CombiSensor::setNSources ( int  n)

Definition at line 123 of file SensorSet.cpp.

References Sensor::cweights, getZeroSensor(), Sensor::setModified(), sources, Sensor::UPD_CWEIGHTS, and Sensor::UPD_DATA.

Referenced by assign(), CombiSensor(), and setSource().

124 {
125  if(n != (int)sources.size()) {
126  //clearSources();
127  sources.resize(n,(sensor_ptr)getZeroSensor());
128  cweights.resize(n, 1);
130  }
131 }
std::vector< sensor_ptr > sources
Definition: SensorSet.h:287
std::vector< float > cweights
multi-channel weights (&#39;color&#39;)
Definition: Sensor.h:174
std::shared_ptr< Sensor > sensor_ptr
Definition: types_fwd.h:15
sensor_ptr getZeroSensor()
Definition: Sensor.cpp:234
void setModified(dword mask=UPD_ALL)
Definition: Sensor.h:110
void CombiSensor::setSource ( sensor_ptr  _source,
float  weight,
int  id 
)

Definition at line 133 of file SensorSet.cpp.

References Sensor::cweights, Sensor::enableUpdate(), getZeroSensor(), Sensor::isUpdate(), Sensor::setModified(), setNSources(), Sensor::source, sources, Sensor::UPD_CWEIGHTS, Sensor::UPD_DATA, and Sensor::UPD_MINMAX.

Referenced by assign(), and changeSource().

134 {
135  assert(id>=0);
136  if(id>=(int)sources.size()) {
137  setNSources(id+1);
138  }
139  else if (sources[id] != 0 && sources[id] != getZeroSensor())
140  {
141  sources[id]->unrefSuperSensor( shared_from_this() );
142  }
143  sources[id] = _source;
144  cweights[id] = weight;
145  _source->refSuperSensor( shared_from_this() );
146  source = _source;
147  if(!std::const_pointer_cast<Sensor>(source)->isUpdate(UPD_MINMAX)) {
148  std::const_pointer_cast<Sensor>(source)->enableUpdate(UPD_MINMAX);
149  std::const_pointer_cast<Sensor>(source)->setModified(UPD_MINMAX);
150  }
152 }
std::vector< sensor_ptr > sources
Definition: SensorSet.h:287
std::vector< float > cweights
multi-channel weights (&#39;color&#39;)
Definition: Sensor.h:174
Definition: Sensor.h:21
sensor_ptr getZeroSensor()
Definition: Sensor.cpp:234
void setNSources(int n)
Definition: SensorSet.cpp:123
bool isUpdate(dword udMask) const
Definition: Sensor.h:112
void enableUpdate(dword udMask)
Definition: Sensor.h:113
sensor_cptr source
Definition: Sensor.h:170
void setModified(dword mask=UPD_ALL)
Definition: Sensor.h:110
void CombiSensor::setSource ( sensor_ptr  _source,
float  weight 
)
inline

Definition at line 281 of file SensorSet.h.

References Sensor::assign().

282  { setSource(_source, weight, sources.size()); }
std::vector< sensor_ptr > sources
Definition: SensorSet.h:287
void setSource(sensor_ptr _source, float weight, int id)
Definition: SensorSet.cpp:133

Member Data Documentation

bool CombiSensor::m_NormalizeInput
protected

Definition at line 288 of file SensorSet.h.

Referenced by print().

std::vector<sensor_ptr> CombiSensor::sources
protected

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