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

#include <SensorSet.h>

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

Public Member Functions

 MahalSensor (const std::string &fname="")
 
int getNChannels () const
 
Sensorassign (const Sensor &rhs)
 
std::ostream & print (std::ostream &os) const
 
bool loadConfig (const std::string &fname="")
 
bool saveConfig (const std::string &fname="") const
 
void setCovi (const DMatrix< float > &icov)
 
void setMean (const DMatrix< float > &mean)
 
const DMatrix< float > & getICov () const
 
const DMatrix< float > & getMean () const
 
const std::string & getFilename () 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 ()
 
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

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

DMatrix< float > m
 
DMatrix< float > icov
 
std::string m_Filename
 
- 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

Mahalanobis distance Sensor

Definition at line 324 of file SensorSet.h.

Constructor & Destructor Documentation

MahalSensor::MahalSensor ( const std::string &  fname = "")
inline

Definition at line 326 of file SensorSet.h.

References Sensor::m_AddSkip.

327  {
328  m_AddSkip = 1;
329  loadConfig(fname);
330  }
int m_AddSkip
Definition: Sensor.h:183
bool loadConfig(const std::string &fname="")
Definition: SensorSet.cpp:250

Member Function Documentation

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

Reimplemented from PPSensor.

Definition at line 236 of file SensorSet.cpp.

References PPSensor::assign(), icov, m, and m_Filename.

237 {
238  if(&rhs != this) {
239  PPSensor::assign(rhs);
240  if(typeid(&rhs) == typeid(MahalSensor*)) {
241  const MahalSensor& crhs = (const MahalSensor&) rhs;
242  m = crhs.m;
243  icov = crhs.icov;
244  m_Filename = crhs.m_Filename;
245  }
246  }
247  return *this;
248 }
Sensor & assign(const Sensor &rhs)
Definition: Sensor.cpp:324
DMatrix< float > icov
Definition: SensorSet.h:355
std::string m_Filename
Definition: SensorSet.h:356
DMatrix< float > m
Definition: SensorSet.h:355
float MahalSensor::calcValue ( int  x,
int  y 
) const
inlineprotectedvirtual

Computes saturation or some other colour indicator.

Implements Sensor.

Definition at line 347 of file SensorSet.h.

References DMatrix< T >::at(), DMatrix< T >::mulRight(), Sensor::source, and DMatrix< T >::transpose().

347  {
348  std::vector<float> mv = source->getMValue(x,y);
349  DMatrix<float> v(1,std::min(mv.size(),size_t(3)),&mv.front());
350  v -= m;
351  DMatrix<float> vt(v); vt.transpose();
352  float d = (vt.mulRight(icov.mulRight(v))).at(0,0);
353  return exp(-0.5*d);
354  }
DMatrix< float > icov
Definition: SensorSet.h:355
DMatrix< float > m
Definition: SensorSet.h:355
sensor_cptr source
Definition: Sensor.h:170
MT mulRight(const MT &rhs) const
Definition: DMatrix.h:149
const std::string& MahalSensor::getFilename ( ) const
inline

Definition at line 344 of file SensorSet.h.

344 { return m_Filename; }
std::string m_Filename
Definition: SensorSet.h:356
const DMatrix<float>& MahalSensor::getICov ( ) const
inline

Definition at line 342 of file SensorSet.h.

342 { return icov; }
DMatrix< float > icov
Definition: SensorSet.h:355
const DMatrix<float>& MahalSensor::getMean ( ) const
inline

Definition at line 343 of file SensorSet.h.

343 { return m; }
DMatrix< float > m
Definition: SensorSet.h:355
int MahalSensor::getNChannels ( ) const
inlinevirtual

Reimplemented from Sensor.

Definition at line 331 of file SensorSet.h.

References Sensor::assign().

331 { return 1; }
bool MahalSensor::loadConfig ( const std::string &  fname = "")

Definition at line 250 of file SensorSet.cpp.

251 {
252  const string& fn = fname.empty() ? m_Filename : fname;
253  ifstream is(fn.c_str());
254  if(!is) return false;
255  is >> icov;
256  is >> m;
257  if(icov.sizeX() != 3 || icov.sizeY() != 3) {
258  icov = dmutil::makeIdentity<float>(3);
259  }
260  if(m.sizeX() != 1 || m.sizeY() != 3) {
261  m.resize(1,3,0);
262  }
263  if(!fname.empty()) m_Filename = fname;
264  return true;
265 }
MT & resize(dword _sx, dword _sy, const T &inival=T())
Definition: DMatrix.h:30
DMatrix< float > icov
Definition: SensorSet.h:355
std::string m_Filename
Definition: SensorSet.h:356
DMatrix< float > m
Definition: SensorSet.h:355
std::ostream& MahalSensor::print ( std::ostream &  os) const
inlinevirtual

Reimplemented from Sensor.

Definition at line 333 of file SensorSet.h.

References Sensor::print().

333  {
334  Sensor::print(os)
335  << "C " << m_Filename;
336  return os;
337  }
std::string m_Filename
Definition: SensorSet.h:356
virtual std::ostream & print(std::ostream &os) const
Definition: Sensor.cpp:213
bool MahalSensor::saveConfig ( const std::string &  fname = "") const

Definition at line 267 of file SensorSet.cpp.

References Sensor::mean, and MappingSensor::s_MappingNames.

268 {
269  const string& fn = fname.empty() ? m_Filename : fname;
270  ofstream os(fn.c_str());
271  if(!os) return false;
272  os << icov;
273  os << mean;
274  if(!fname.empty()) m_Filename = fname;
275  return true;
276 }
DMatrix< float > icov
Definition: SensorSet.h:355
std::string m_Filename
Definition: SensorSet.h:356
float mean
Definition: Sensor.h:177
void MahalSensor::setCovi ( const DMatrix< float > &  icov)
inline

Definition at line 340 of file SensorSet.h.

340 { this->icov = icov; }
DMatrix< float > icov
Definition: SensorSet.h:355
void MahalSensor::setMean ( const DMatrix< float > &  mean)
inline

Definition at line 341 of file SensorSet.h.

References Sensor::mean.

341 { this->m = mean; }
float mean
Definition: Sensor.h:177
DMatrix< float > m
Definition: SensorSet.h:355

Member Data Documentation

DMatrix<float> MahalSensor::icov
protected

Definition at line 355 of file SensorSet.h.

Referenced by assign().

DMatrix<float> MahalSensor::m
protected

Definition at line 355 of file SensorSet.h.

Referenced by assign().

std::string MahalSensor::m_Filename
mutableprotected

Definition at line 356 of file SensorSet.h.

Referenced by assign().


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