iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nrt::ModelBase Class Referenceabstract

#include <nrt/PointCloud2/SampleConcensus/Models/ModelBase.H>

Interface for all sample concensus methods.

Definition at line 48 of file ModelBase.H.

Inheritance diagram for nrt::ModelBase:
nrt::SourceCloud nrt::ModelPlane nrt::ModelRegistration

Public Types

typedef std::shared_ptr
< ModelBase
SharedPtr
 Convenience typedef for shared ptr to this.
 
typedef std::function< bool(Indices
const &)> 
SampleValidFunction
 A function that returns true if a set of points returns a valid sample. More...
 

Public Member Functions

 ModelBase (PointCloud2 const source, SampleValidFunction func, double inlierThreshold=std::numeric_limits< double >::max(), size_t sampleMaxIterations=1000, bool seedRandom=false)
 Constructor with no subset. More...
 
 ModelBase (PointCloud2 const source, Indices const indices, SampleValidFunction func, double inlierThreshold=std::numeric_limits< double >::max(), size_t sampleMaxIterations=1000, bool seedRandom=false)
 Constructor with a subset. More...
 
virtual ~ModelBase ()
 Virtual destructor.
 
Indices getSamples () const
 
virtual size_t getSampleSize () const =0
 Returns the minimum valid sample size for the model.
 
virtual VectorX computeModelCoefficients (Indices const sampleIndices) const =0
 Attempts to form a valid model from the points at the selected indices. More...
 
virtual VectorX optimizeModelCoefficients (Indices const inlierIndices, VectorX const &modelCoefficients) const =0
 Recomputes the model coefficients using the provided inlier indices. More...
 
virtual std::vector< double > getDistancesToModel (VectorX const &modelCoefficients) const =0
 Computes distances from transformed points to their correspondences.
 
virtual Indices selectWithinDistance (VectorX const &modelCoefficients) const =0
 
virtual int countWithinDistance (VectorX const &modelCoefficients) const =0
 Counts all of the points which respect the model coefficients that are inliers.
 
- Public Member Functions inherited from nrt::SourceCloud
 SourceCloud ()
 Initializes with no data.
 
 SourceCloud (PointCloud2 const cloud)
 Initializes with a point cloud and no subset.
 
 SourceCloud (PointCloud2 const cloud, Indices const indices)
 Initializes with a point cloud and a specific subset.
 
size_t getWorkingSize () const
 Returns the current working size of the Source. More...
 

Protected Attributes

PointCloud2 itsCloud
 The input point cloud.
 
SampleValidFunction itsIsSampleValidFunction
 Evaluates whether a set of indices is valid.
 
const double itsInlierThreshold
 used during sample selection
 
const size_t itsSampleMaxIterations
 distance threshold for selection and counting
 
std::mt19937 itsRNG
 The random number generator.
 

Additional Inherited Members

- Public Attributes inherited from nrt::SourceCloud
PointCloud2 cloud
 The source point cloud.
 
Indices indices
 The optional indices.
 
bool useSubset
 Whether we use a subset or not.
 
- Protected Member Functions inherited from nrt::SourceCloud
void setCloud (PointCloud2 const cloud)
 Sets to use a specific cloud.
 
void setCloud (PointCloud2 const cloud, Indices const indices)
 Sets to sue a specific subset of a cloud.
 

Member Typedef Documentation

typedef std::function<bool(Indices const &)> nrt::ModelBase::SampleValidFunction

A function that returns true if a set of points returns a valid sample.

A validation function takes in a set of indices that correspond to indices from the point cloud (regardless of whether a subset was used) that should be evaluated as to whether the values at these indices can produce a valid model.

The typical way to create one of these functions is to capture relevant information in a lambda function or some functor, e.g.:

MyCoolModel model( myCloud,
[myCloud]( Indices const & indices )
{
for( auto point : myCloud.const_subset_range( indices ) )
// do something with the points
return true;
},
other_parameters... );

Be sure to capture any copy on write data by value unless you can be sure that it will be accessed in a thread safe manner. Also be careful to utilize const accessors for your point cloud or other data if you will not be modifying it

Definition at line 78 of file ModelBase.H.

Constructor & Destructor Documentation

nrt::ModelBase::ModelBase ( PointCloud2 const  source,
SampleValidFunction  func,
double  inlierThreshold = std::numeric_limits< double >::max(),
size_t  sampleMaxIterations = 1000,
bool  seedRandom = false 
)

Constructor with no subset.

Parameters
sourceThe source cloud
funcThe function to evaluate whether a set of samples is valid
inlierThresholdDistance threshold to use for select and countWithinDistance()
sampleMaxIterationsMaximum number of iterations to use during sample selection
seedRandomIf true, the random number generator will be seeded with the current time, otherwise it will always receive the same default seed
nrt::ModelBase::ModelBase ( PointCloud2 const  source,
Indices const  indices,
SampleValidFunction  func,
double  inlierThreshold = std::numeric_limits< double >::max(),
size_t  sampleMaxIterations = 1000,
bool  seedRandom = false 
)

Constructor with a subset.

Parameters
sourceThe point cloud to use
indicesThe subset of the cloud to consider
funcThe function to evaluate whether a set of samples is valid
inlierThresholdDistance threshold to use for select and countWithinDistance()
sampleMaxIterationsMaximum number of iterations to use during sample selection
seedRandomIf true, the random number generator will be seeded with the current time, otherwise it will always receive the same default seed

Member Function Documentation

Indices nrt::ModelBase::getSamples ( ) const

Generates a set of randomly chosen indices according to the models minimum sample size

Returns
The indices that made a valid sample
virtual VectorX nrt::ModelBase::computeModelCoefficients ( Indices const  sampleIndices) const
pure virtual

Attempts to form a valid model from the points at the selected indices.

Parameters
sampleIndicesThe valid indices (check with itsIsSampleValidFunction() ) to use
Returns
The coefficients for the model

Implemented in nrt::ModelPlane, and nrt::ModelRegistration.

virtual VectorX nrt::ModelBase::optimizeModelCoefficients ( Indices const  inlierIndices,
VectorX const &  modelCoefficients 
) const
pure virtual

Recomputes the model coefficients using the provided inlier indices.

This can be called after inliers have been computed to refine a solution

Parameters
inlierIndicesThe inlier indices
modelCoefficientsThe coefficients found via computeModelCoefficients()
Returns
The optimized set of model coefficients

Implemented in nrt::ModelPlane, and nrt::ModelRegistration.

virtual Indices nrt::ModelBase::selectWithinDistance ( VectorX const &  modelCoefficients) const
pure virtual

Selects all points from the input data set that are inliers under the model according to some threshold

Implemented in nrt::ModelPlane, and nrt::ModelRegistration.


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