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

#include <Sensor.h>

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

Public Types

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
}
 

Public Member Functions

 PPSensor ()
 
virtual float getValue (int x, int y) const
 
virtual Point getGradient (int x, int y) const
 
virtual bool performUpdate ()
 
Sensorassign (const Sensor &rhs)
 
void togglePP (enum PPState state=PP_DO)
 
dword getPPState () const
 
- Public Member Functions inherited from Sensor
virtual ~Sensor ()
 
sensor_cptr getSource ()
 
virtual void changeSource (sensor_cptr _source)
 
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
 
virtual int getNChannels () const
 
virtual int getSkip () const
 
bool isValid (int x, int y) const
 
virtual Image< float > createSensorImage () const
 
const std::string & getID () const
 
void setID (const std::string &id)
 
virtual std::ostream & hprint (std::ostream &os, SensorCollection *sc) const
 
virtual std::ostream & print (std::ostream &os) const
 
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

void fitSheets ()
 
virtual void calcAllValues ()
 
virtual void calcAllGradients ()
 
- Protected Member Functions inherited from Sensor
 Sensor (dword updateMask)
 
 Sensor ()
 
virtual float calcValue (int x, int y) const =0
 
virtual std::vector< float > calcMValue (int x, int y) const
 
virtual Point calcGradient (int x, int y) const
 
virtual void calcMinMax ()
 

Protected Attributes

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

- Static Public Member Functions inherited from Sensor
static dword getStringNumber (const char *sid)
 
static void getNumberString (char sid[5], dword id)
 

Detailed Description

Sensor with preprocessing

Definition at line 228 of file Sensor.h.

Member Enumeration Documentation

Enumerator
PP_DONT 
PP_DO 
PP_FORCE 

Definition at line 230 of file Sensor.h.

Constructor & Destructor Documentation

PPSensor::PPSensor ( )

Definition at line 242 of file Sensor.cpp.

243  : values(source->getDim1Size(), source->getDim2Size(), AIR_NAN),
244  gradients(source->getDim1Size(), source->getDim2Size(),
247 {}
Image< float > values
caching sheet for sensed values
Definition: Sensor.h:256
Point2D Point
Definition: Point.h:251
#define AIR_NAN
Definition: airnan.h:80
Image< Point > gradients
caching sheet for gradients
Definition: Sensor.h:257
sensor_cptr source
Definition: Sensor.h:170
dword doPP
do preprocessing?
Definition: Sensor.h:258

Member Function Documentation

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

Reimplemented from Sensor.

Reimplemented in MappingSensor, MahalSensor, and CombiSensor.

Definition at line 324 of file Sensor.cpp.

References Sensor::assign(), and doPP.

Referenced by CombiSensor::assign(), MahalSensor::assign(), and MappingSensor::assign().

325 {
326  if(&rhs != this) {
327  Sensor::assign(rhs);
328  if(typeid(&rhs) == typeid(PPSensor*)) {
329  const PPSensor& crhs = (const PPSensor&) rhs;
330  doPP = crhs.doPP;
331  }
332  }
333  return *this;
334 }
virtual Sensor & assign(const Sensor &rhs)
Definition: Sensor.cpp:54
dword doPP
do preprocessing?
Definition: Sensor.h:258
void PPSensor::calcAllGradients ( )
protectedvirtual

Definition at line 278 of file Sensor.cpp.

References calcAllValues(), Sensor::calcGradient(), fitSheets(), gradients, Sensor::isModified(), Sensor::performUpdate(), Sensor::setModified(), Sensor::source, Sensor::toupdate, and Sensor::unsetModified().

278  {
279  if(gradients.getSizeX() == source->getDim1Size() &&
280  gradients.getSizeY() == source->getDim2Size())
281  {
282  int i,j;
284  for(j=0; j<source->getDim2Size()-1; j++, g++) {
285  for(i=0; i<source->getDim1Size()-1; i++, g++) {
286  *g = calcGradient(i,j);
287  }
288  }
289  }
290 }
std::vector< T >::iterator iterator
Definition: Image.h:19
virtual Point calcGradient(int x, int y) const
Definition: Sensor.h:149
Image< Point > gradients
caching sheet for gradients
Definition: Sensor.h:257
sensor_cptr source
Definition: Sensor.h:170
void PPSensor::calcAllValues ( )
protectedvirtual

Reimplemented in SmoothIntensitySensor.

Definition at line 262 of file Sensor.cpp.

References Sensor::calcValue(), Image< T >::getSizeX(), Image< T >::getSizeY(), Sensor::source, and values.

Referenced by calcAllGradients(), and SmoothIntensitySensor::calcAllValues().

262  {
263  if(values.getSizeX() == source->getDim1Size() &&
264  values.getSizeY() == source->getDim2Size())
265  {
266  int i,j;
267  Image<float>::iterator v=values.begin();
268  for(j=0; j<source->getDim2Size(); j++) {
269  for(i=0; i<source->getDim1Size(); i++, v++)
270  {
271  *v = calcValue(i,j);
272  assert(!isnan(*v));
273  }
274  }
275  }
276 }
Image< float > values
caching sheet for sensed values
Definition: Sensor.h:256
virtual float calcValue(int x, int y) const =0
int getSizeX() const
Definition: Image.h:42
Definition: Image.h:16
sensor_cptr source
Definition: Sensor.h:170
int getSizeY() const
Definition: Image.h:43
void PPSensor::fitSheets ( )
protected

Definition at line 249 of file Sensor.cpp.

References Image< T >::getSizeX(), Image< T >::getSizeY(), gradients, Image< T >::setSize(), Sensor::source, and values.

Referenced by calcAllGradients(), and performUpdate().

249  {
250  if(values.getSizeX() != source->getDim1Size() ||
251  values.getSizeY() != source->getDim2Size()) {
252  values.setSize(source->getDim1Size(), source->getDim2Size());
253  gradients.setSize(source->getDim1Size(), source->getDim2Size());
254  }
255  //this is also done later on by Sensor::performUpdate,
256  //but we might need it earlier
257  //if(cweights.size() != source->getNChannels()) {
258 // cweights.resize(source->getNChannels());
259 // }
260 }
Image< float > values
caching sheet for sensed values
Definition: Sensor.h:256
int getSizeX() const
Definition: Image.h:42
Image< Point > gradients
caching sheet for gradients
Definition: Sensor.h:257
void setSize(int nx, int ny)
Definition: Image.h:268
sensor_cptr source
Definition: Sensor.h:170
int getSizeY() const
Definition: Image.h:43
Point PPSensor::getGradient ( int  x,
int  y 
) const
inlinevirtual

Return cached gradient or compute and cache new one.

Reimplemented from Sensor.

Definition at line 284 of file Sensor.h.

References Sensor::calcGradient(), Sensor::isModified(), and Sensor::performUpdate().

284  {
285  if(doPP) {
286  if(isModified()) const_cast<PPSensor*>(this)->performUpdate();
287  int index = gradients.getBoundedIndex(x,y);
288  if(index<0) return Point();
289  if(std::isnan(gradients[index].x)) { // no precalculated value?
290 // if(doPP == PP_FORCE) {
291 // //this should not happen
292 // assert(false);
293 // const_cast<PPSensor*>(this)->performFullUpdate();
294 // return gradients[index];
295 // } else
296  return (const_cast<PPSensor*>(this)->gradients[index]
297  = calcGradient(x,y));
298  } else return gradients[index];
299  } else return calcGradient(x,y);
300 }
bool isModified(dword mask=UPD_ALL) const
Definition: Sensor.h:108
virtual Point calcGradient(int x, int y) const
Definition: Sensor.h:149
Point2D Point
Definition: Point.h:251
virtual bool performUpdate()
Definition: Sensor.cpp:306
Image< Point > gradients
caching sheet for gradients
Definition: Sensor.h:257
dword doPP
do preprocessing?
Definition: Sensor.h:258
dword PPSensor::getPPState ( ) const
inline

Definition at line 244 of file Sensor.h.

244 { return doPP; }
dword doPP
do preprocessing?
Definition: Sensor.h:258
float PPSensor::getValue ( int  x,
int  y 
) const
inlinevirtual

Return cached value or compute and cache new one.

Reimplemented from Sensor.

Definition at line 266 of file Sensor.h.

References Sensor::calcValue(), Sensor::isModified(), Sensor::performUpdate(), and PP_FORCE.

266  {
267  if(doPP) {
268  if(isModified()) const_cast<PPSensor*>(this)->performUpdate();
269  int index = (int)values.getBoundedIndex(x,y);
270  if(index==-1) return 0;
271  float v;
272  if(std::isnan((v = values[index]))) {
273  if(doPP == PPSensor::PP_FORCE) {
274  assert(false); //no NAN values in forced full update at this point
275  const_cast<PPSensor*>(this)->performFullUpdate();
276  return values[index];
277  } else {
278  return (const_cast<PPSensor*>(this)->values[index] = calcValue(x,y));
279  }
280  } else return v;
281  } else return calcValue(x,y);
282 }
int getBoundedIndex(int x, int y) const
Definition: Image.h:52
bool isModified(dword mask=UPD_ALL) const
Definition: Sensor.h:108
Image< float > values
caching sheet for sensed values
Definition: Sensor.h:256
virtual float calcValue(int x, int y) const =0
virtual bool performUpdate()
Definition: Sensor.cpp:306
dword doPP
do preprocessing?
Definition: Sensor.h:258
bool PPSensor::performUpdate ( )
virtual

clear all data sheets

Reimplemented from Sensor.

Reimplemented in MappingSensor, CornerSensor, GradMagSensor, and SmoothIntensitySensor.

Definition at line 306 of file Sensor.cpp.

References AIR_NAN, doPP, fitSheets(), gradients, Sensor::isModified(), Sensor::performUpdate(), PP_FORCE, and values.

Referenced by SmoothIntensitySensor::performUpdate(), GradMagSensor::performUpdate(), CornerSensor::performUpdate(), and MappingSensor::performUpdate().

307 {
308  if(isModified()) {
309  if(doPP == PPSensor::PP_FORCE) return performFullUpdate();
310  else {
311  fitSheets();
312  for(Image<float>::iterator v=values.begin(); v!=values.end(); v++) {
313  *v = AIR_NAN;
314  }
315  for(Image<Point>::iterator g=gradients.begin(); g!=gradients.end(); g++) {
316  g->x = AIR_NAN;
317  }
319  return true;
320  }
321  }else return false;
322 }
bool isModified(dword mask=UPD_ALL) const
Definition: Sensor.h:108
Image< float > values
caching sheet for sensed values
Definition: Sensor.h:256
std::vector< T >::iterator iterator
Definition: Image.h:19
void fitSheets()
Definition: Sensor.cpp:249
virtual bool performUpdate()
Definition: Sensor.cpp:123
#define AIR_NAN
Definition: airnan.h:80
Image< Point > gradients
caching sheet for gradients
Definition: Sensor.h:257
Definition: Image.h:16
dword doPP
do preprocessing?
Definition: Sensor.h:258
void PPSensor::togglePP ( enum PPState  state = PP_DO)
inline

Tell how strict precomputation will be done. PPState::PP_DO will compute and cache on the fly. PPState::PP_FORCE will compute entire caching sheet.

Definition at line 243 of file Sensor.h.

243 { doPP = state; }
dword doPP
do preprocessing?
Definition: Sensor.h:258

Member Data Documentation

dword PPSensor::doPP
protected

do preprocessing?

Definition at line 258 of file Sensor.h.

Referenced by assign(), and performUpdate().

Image<Point> PPSensor::gradients
protected

caching sheet for gradients

Definition at line 257 of file Sensor.h.

Referenced by calcAllGradients(), fitSheets(), and performUpdate().

Image<float> PPSensor::values
protected

caching sheet for sensed values

Definition at line 256 of file Sensor.h.

Referenced by calcAllValues(), fitSheets(), and performUpdate().


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