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

#include <SensorSet.h>

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

Public Types

enum  MappingTypes {
  MS_IDENTITY, MS_CLAMPLU, MS_CLAMPL, MS_CLAMPU,
  MS_GAUSSNORM, MS_MGAUSSNORM, MS_MCLAMPU, MS_BIAS,
  MS_LAST
}
 
- 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
}
 

Public Member Functions

 MappingSensor (const std::string &mapn="")
 
int getNChannels () const
 
Sensorassign (const Sensor &rhs)
 
std::ostream & print (std::ostream &os) const
 
const char * getMappingName () const
 
dword getMappingID () const
 
dword setMappingID (dword id)
 
dword setMapping (const std::string &mname)
 
bool readParams (std::istream &is)
 
bool performUpdate ()
 
- Public Member Functions inherited from PPSensor
 PPSensor ()
 
virtual float getValue (int x, int y) const
 
virtual Point getGradient (int x, int y) const
 
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 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
 
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

virtual float calcValue (int x, int y) const
 Computes saturation or some other colour indicator. More...
 
- 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 std::vector< float > calcMValue (int x, int y) const
 
virtual Point calcGradient (int x, int y) const
 
virtual void calcMinMax ()
 

Protected Attributes

dword m_MappingID
 
std::vector< float > m_Param
 
- 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
 

Static Protected Attributes

static const char * s_MappingNames []
 

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 performing various mappings

Definition at line 360 of file SensorSet.h.

Member Enumeration Documentation

Enumerator
MS_IDENTITY 
MS_CLAMPLU 
MS_CLAMPL 
MS_CLAMPU 
MS_GAUSSNORM 
MS_MGAUSSNORM 
MS_MCLAMPU 
MS_BIAS 
MS_LAST 

Definition at line 362 of file SensorSet.h.

Constructor & Destructor Documentation

MappingSensor::MappingSensor ( const std::string &  mapn = "")
inline

Definition at line 366 of file SensorSet.h.

References Sensor::m_AddSkip.

367  : m_MappingID()
368  {
369  m_AddSkip = 1;
370  setMapping(mapn);
371  }
dword m_MappingID
Definition: SensorSet.h:420
int m_AddSkip
Definition: Sensor.h:183
dword setMapping(const std::string &mname)
Definition: SensorSet.cpp:314

Member Function Documentation

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

Reimplemented from PPSensor.

Definition at line 284 of file SensorSet.cpp.

References PPSensor::assign(), m_MappingID, and m_Param.

285 {
286  if(&rhs != this) {
287  PPSensor::assign(rhs);
288  if(typeid(&rhs) == typeid(MappingSensor*)) {
289  const MappingSensor& crhs = (const MappingSensor&) rhs;
290  m_MappingID = crhs.m_MappingID;
291  m_Param = crhs.m_Param;
292  }
293  }
294  return *this;
295 }
dword m_MappingID
Definition: SensorSet.h:420
Sensor & assign(const Sensor &rhs)
Definition: Sensor.cpp:324
std::vector< float > m_Param
Definition: SensorSet.h:421
virtual float MappingSensor::calcValue ( int  x,
int  y 
) const
inlineprotectedvirtual

Computes saturation or some other colour indicator.

Implements Sensor.

Definition at line 385 of file SensorSet.h.

References Sensor::source.

385  {
386  float v = source->getValue(x,y);
387  switch(m_MappingID) {
388 // case MS_IDENTITY:
389 // break;
390  case MS_CLAMPL:
391  if(v < m_Param[0]) v = m_Param[0];
392  break;
393  case MS_CLAMPU:
394  if(v > m_Param[0]) v = m_Param[0];
395  break;
396  case MS_CLAMPLU:
397  if(v < m_Param[0]) v = m_Param[0];
398  else if(v > m_Param[1]) v = m_Param[1];
399  break;
400  case MS_MCLAMPU:
401  if(v > m_Param[1]) v = m_Param[1];
402  break;
403  case MS_GAUSSNORM:
404  v = (v-m_Param[1])*m_Param[2]+0.5;
405  break;
406  case MS_MGAUSSNORM:
407  if(v>0.f) v = (v-m_Param[1])*m_Param[2];
408  break;
409  case MS_BIAS:
410  //if(v>0.f) {
411  v = (v-m_Param[1])*m_Param[2];
412  v = erf(v)*0.5+0.5;
413  //} else v = 0.f;
414  break;
415  }
416  return v;
417  }
dword m_MappingID
Definition: SensorSet.h:420
std::vector< float > m_Param
Definition: SensorSet.h:421
sensor_cptr source
Definition: Sensor.h:170
dword MappingSensor::getMappingID ( ) const
inline

Definition at line 377 of file SensorSet.h.

References Sensor::performUpdate().

377 { return m_MappingID; }
dword m_MappingID
Definition: SensorSet.h:420
const char* MappingSensor::getMappingName ( ) const
inline

Definition at line 375 of file SensorSet.h.

376  { return s_MappingNames[m_MappingID]; }
dword m_MappingID
Definition: SensorSet.h:420
static const char * s_MappingNames[]
Definition: SensorSet.h:383
int MappingSensor::getNChannels ( ) const
inlinevirtual

Reimplemented from Sensor.

Definition at line 372 of file SensorSet.h.

References Sensor::assign(), and IntensitySensor::print().

372 { return 1; }
bool MappingSensor::performUpdate ( )
virtual

clear all data sheets

Reimplemented from PPSensor.

Definition at line 350 of file SensorSet.cpp.

References Sensor::isModified(), PPSensor::performUpdate(), Sensor::source, and dmutil::sqrt().

350  {
351  if(!isModified()) return false;
352  if(source->getDim1Size()>0) {
353  bool doanalysis = true;
354  switch(m_MappingID) {
355  case MS_MCLAMPU:
356  case MS_GAUSSNORM:
357  case MS_MGAUSSNORM:
358  case MS_BIAS:
359  if(m_Param.size() < 4) m_Param.resize(4);
360  m_Param[1] = m_Param[2] = m_Param[3] = 0.f;
361  break;
362  default:
363  doanalysis = false;
364  }
365  if(doanalysis) {
366  int i,j;
367  for(j=0; j<source->getDim2Size(); j++) {
368  for(i=0; i<source->getDim1Size(); i++)
369  {
370  float v = source->getValue(i,j);
371  switch(m_MappingID) {
372  case MS_BIAS:
373  case MS_GAUSSNORM:
374  m_Param[1] += v;
375  m_Param[2] += v*v;
376  m_Param[3]++;
377  break;
378  case MS_MCLAMPU:
379  case MS_MGAUSSNORM:
380  if(v>0) {
381  m_Param[1] += v;
382  m_Param[2] += v*v;
383  m_Param[3]++;
384  }
385  break;
386  }
387  }
388  }
389  switch(m_MappingID) {
390  case MS_MCLAMPU:
391  m_Param[1] /= m_Param[3];
392  m_Param[2] /= m_Param[3];
393  m_Param[2] = sqrt(m_Param[2]-m_Param[1]*m_Param[1]);
394  m_Param[1] = m_Param[1]+m_Param[2]*m_Param[0];
395  break;
396  case MS_BIAS:
397  case MS_GAUSSNORM:
398  m_Param[1] /= m_Param[3];
399  m_Param[2] /= m_Param[3];
400  m_Param[2] = sqrt(m_Param[2]-m_Param[1]*m_Param[1]);
401  m_Param[2] = 1/(m_Param[2]*m_Param[0]);
402  break;
403  case MS_MGAUSSNORM:
404  m_Param[1] /= m_Param[3];
405  m_Param[2] /= m_Param[3];
406  m_Param[2] = sqrt(m_Param[2]-m_Param[1]*m_Param[1]);
407  m_Param[2] = 1/(m_Param[2]*m_Param[0]);
408  m_Param[1] = m_Param[1] - (m_Param[1]/m_Param[2]);
409  break;
410  }
411  }
412  }
413  return PPSensor::performUpdate();
414 }
dword m_MappingID
Definition: SensorSet.h:420
bool isModified(dword mask=UPD_ALL) const
Definition: Sensor.h:108
virtual bool performUpdate()
Definition: Sensor.cpp:306
std::vector< float > m_Param
Definition: SensorSet.h:421
sensor_cptr source
Definition: Sensor.h:170
DMatrix< T > & sqrt(DMatrix< T > &mat)
Definition: DMatrixUtil.h:81
std::ostream & MappingSensor::print ( std::ostream &  os) const
virtual

Reimplemented from Sensor.

Definition at line 297 of file SensorSet.cpp.

References Sensor::print().

298 {
299  Sensor::print(os)
300  << "f " << getMappingName();
301  for(vector<float>::const_iterator p=m_Param.begin(); p!=m_Param.end(); p++)
302  {
303  os << " " << *p;
304  }
305  return os;
306 }
const char * getMappingName() const
Definition: SensorSet.h:375
std::vector< float > m_Param
Definition: SensorSet.h:421
virtual std::ostream & print(std::ostream &os) const
Definition: Sensor.cpp:213
bool MappingSensor::readParams ( std::istream &  is)

Definition at line 321 of file SensorSet.cpp.

322 {
323  m_Param.clear();
324  is >> ws;
325  while(is) {
326  float para= -0.12347891f;
327  is >> para;
328  if(para != -0.12347891f) m_Param.push_back(para);
329  is >> ws;
330  }
331  dword psize = m_Param.size();
332  if((m_MappingID == MS_CLAMPL ||
333  m_MappingID == MS_CLAMPU ||
336  m_MappingID == MS_MCLAMPU ||
337  m_MappingID == MS_BIAS)
338  && psize<1)
339  {
341  return false;
342  }
343  if(m_MappingID == MS_CLAMPLU && psize<2)
344  {
345  m_MappingID = MS_IDENTITY; return false;
346  }
347  return true;
348 }
dword m_MappingID
Definition: SensorSet.h:420
unsigned long dword
Definition: simpletypes.h:6
std::vector< float > m_Param
Definition: SensorSet.h:421
dword MappingSensor::setMapping ( const std::string &  mname)

Definition at line 314 of file SensorSet.cpp.

315 {
316  dword mid = 0;
317  while(mid < MS_LAST && mname != s_MappingNames[mid]) mid++;
318  return setMappingID(mid);
319 }
static const char * s_MappingNames[]
Definition: SensorSet.h:383
unsigned long dword
Definition: simpletypes.h:6
dword setMappingID(dword id)
Definition: SensorSet.cpp:308
dword MappingSensor::setMappingID ( dword  id)

Definition at line 308 of file SensorSet.cpp.

309 {
310  if(id>=MS_LAST) m_MappingID = 0; else m_MappingID = id;
311  return m_MappingID;
312 }
dword m_MappingID
Definition: SensorSet.h:420

Member Data Documentation

dword MappingSensor::m_MappingID
protected

Definition at line 420 of file SensorSet.h.

Referenced by assign().

std::vector<float> MappingSensor::m_Param
protected

Definition at line 421 of file SensorSet.h.

Referenced by assign().

const char * MappingSensor::s_MappingNames
staticprotected
Initial value:
=
{"identity","clamplu","clampl","clampu","gaussnorm","mgaussnorm",
"mclampu", "bias", 0}

Definition at line 383 of file SensorSet.h.

Referenced by MahalSensor::saveConfig().


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