36 #ifndef __POINTMATCHER_CORE_H 37 #define __POINTMATCHER_CORE_H 39 #ifndef EIGEN_USE_NEW_STDVECTOR 40 #define EIGEN_USE_NEW_STDVECTOR 41 #endif // EIGEN_USE_NEW_STDVECTOR 45 #define EIGEN_NO_DEBUG 47 #include "Eigen/StdVector" 49 #include "Eigen/Geometry" 52 #include <boost/thread/mutex.hpp> 60 #include <boost/cstdint.hpp> 62 #include "DeprecationWarnings.h" 63 #include "Parametrizable.h" 64 #include "Registrar.h" 72 #define POINTMATCHER_VERSION "1.3.1" 74 #define POINTMATCHER_VERSION_INT 10301 102 virtual bool hasInfoChannel()
const;
103 virtual void beginInfoEntry(
const char *file,
unsigned line,
const char *func);
104 virtual std::ostream* infoStream();
105 virtual void finishInfoEntry(
const char *file,
unsigned line,
const char *func);
106 virtual bool hasWarningChannel()
const;
107 virtual void beginWarningEntry(
const char *file,
unsigned line,
const char *func);
108 virtual std::ostream* warningStream();
109 virtual void finishWarningEntry(
const char *file,
unsigned line,
const char *func);
112 void setLogger(std::shared_ptr<Logger> newLogger);
117 typedef std::map<std::string, std::vector<std::string> >
CsvElements;
129 #define ZERO_PLUS_EPS (0. + std::numeric_limits<double>::epsilon()) 130 #define ONE_MINUS_EPS (1. - std::numeric_limits<double>::epsilon()) 153 typedef typename Eigen::Matrix<T, Eigen::Dynamic, 1>
Vector;
155 typedef std::vector<Vector, Eigen::aligned_allocator<Vector> >
VectorVector;
161 typedef typename Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
Matrix;
163 typedef typename Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic>
IntMatrix;
165 typedef typename Eigen::Matrix<std::int64_t, Eigen::Dynamic, Eigen::Dynamic>
Int64Matrix;
167 typedef typename Eigen::Array<T, Eigen::Dynamic, Eigen::Dynamic>
Array;
202 typedef Eigen::Block<Matrix>
View;
210 typedef typename Matrix::Index
Index;
217 Label(
const std::string& text =
"",
const size_t span = 0);
218 bool operator ==(
const Label& that)
const;
226 bool contains(
const std::string& text)
const;
227 size_t totalDim()
const;
228 friend std::ostream&
operator<< (std::ostream& stream,
const Labels& labels)
230 for(
size_t i=0; i<labels.size(); i++)
232 stream << labels[i].text;
233 if(i != (labels.size() -1))
254 DataPoints(
const Matrix& features,
const Labels& featureLabels,
const Matrix& descriptors,
const Labels& descriptorLabels);
255 DataPoints(
const Matrix& features,
const Labels& featureLabels,
const Matrix& descriptors,
const Labels& descriptorLabels,
const Int64Matrix& times,
const Labels& timeLabels);
257 bool operator ==(
const DataPoints& that)
const;
259 unsigned getNbPoints()
const;
260 unsigned getEuclideanDim()
const;
261 unsigned getHomogeneousDim()
const;
262 unsigned getNbGroupedDescriptors()
const;
263 unsigned getDescriptorDim()
const;
264 unsigned getTimeDim()
const;
266 void save(
const std::string& fileName,
bool binary =
false)
const;
267 static DataPoints load(
const std::string& fileName);
270 void conservativeResize(Index pointCount);
272 DataPoints createSimilarEmpty(Index pointCount)
const;
273 void setColFrom(Index thisCol,
const DataPoints& that, Index thatCol);
274 void swapCols(Index iCol,Index jCol);
277 void allocateFeature(
const std::string& name,
const unsigned dim);
278 void allocateFeatures(
const Labels& newLabels);
279 void addFeature(
const std::string& name,
const Matrix& newFeature);
280 void removeFeature(
const std::string& name);
281 Matrix getFeatureCopyByName(
const std::string& name)
const;
282 ConstView getFeatureViewByName(
const std::string& name)
const;
283 View getFeatureViewByName(
const std::string& name);
284 ConstView getFeatureRowViewByName(
const std::string& name,
const unsigned row)
const;
285 View getFeatureRowViewByName(
const std::string& name,
const unsigned row);
286 bool featureExists(
const std::string& name)
const;
287 bool featureExists(
const std::string& name,
const unsigned dim)
const;
288 unsigned getFeatureDimension(
const std::string& name)
const;
289 unsigned getFeatureStartingRow(
const std::string& name)
const;
292 void allocateDescriptor(
const std::string& name,
const unsigned dim);
293 void allocateDescriptors(
const Labels& newLabels);
294 void addDescriptor(
const std::string& name,
const Matrix& newDescriptor);
295 void removeDescriptor(
const std::string& name);
296 Matrix getDescriptorCopyByName(
const std::string& name)
const;
297 ConstView getDescriptorViewByName(
const std::string& name)
const;
298 View getDescriptorViewByName(
const std::string& name);
299 ConstView getDescriptorRowViewByName(
const std::string& name,
const unsigned row)
const;
300 View getDescriptorRowViewByName(
const std::string& name,
const unsigned row);
301 bool descriptorExists(
const std::string& name)
const;
302 bool descriptorExists(
const std::string& name,
const unsigned dim)
const;
303 unsigned getDescriptorDimension(
const std::string& name)
const;
304 unsigned getDescriptorStartingRow(
const std::string& name)
const;
305 void assertDescriptorConsistency()
const;
308 void allocateTime(
const std::string& name,
const unsigned dim);
309 void allocateTimes(
const Labels& newLabels);
310 void addTime(
const std::string& name,
const Int64Matrix& newTime);
311 void removeTime(
const std::string& name);
312 Int64Matrix getTimeCopyByName(
const std::string& name)
const;
313 TimeConstView getTimeViewByName(
const std::string& name)
const;
314 TimeView getTimeViewByName(
const std::string& name);
315 TimeConstView getTimeRowViewByName(
const std::string& name,
const unsigned row)
const;
316 TimeView getTimeRowViewByName(
const std::string& name,
const unsigned row);
317 bool timeExists(
const std::string& name)
const;
318 bool timeExists(
const std::string& name,
const unsigned dim)
const;
319 unsigned getTimeDimension(
const std::string& name)
const;
320 unsigned getTimeStartingRow(
const std::string& name)
const;
321 void assertTimesConsistency()
const;
331 void assertConsistency(
const std::string& dataName,
const int dataRows,
const int dataCols,
const Labels& labels)
const;
332 template<
typename MatrixType>
333 void allocateFields(
const Labels& newLabels,
Labels& labels, MatrixType& data)
const;
334 template<
typename MatrixType>
335 void allocateField(
const std::string& name,
const unsigned dim,
Labels& labels, MatrixType& data)
const;
336 template<
typename MatrixType>
337 void addField(
const std::string& name,
const MatrixType& newField,
Labels& labels, MatrixType& data)
const;
338 template<
typename MatrixType>
339 void removeField(
const std::string& name,
Labels& labels, MatrixType& data)
const;
340 template<
typename MatrixType>
341 const Eigen::Block<const MatrixType> getConstViewByName(
const std::string& name,
const Labels& labels,
const MatrixType& data,
const int viewRow = -1)
const;
342 template<
typename MatrixType>
343 Eigen::Block<MatrixType> getViewByName(
const std::string& name,
const Labels& labels, MatrixType& data,
const int viewRow = -1)
const;
344 bool fieldExists(
const std::string& name,
const unsigned dim,
const Labels& labels)
const;
345 unsigned getFieldDimension(
const std::string& name,
const Labels& labels)
const;
346 unsigned getFieldStartingRow(
const std::string& name,
const Labels& labels)
const;
348 template<
typename MatrixType>
349 void concatenateLabelledMatrix(
Labels* labels, MatrixType* data,
const Labels extraLabels,
const MatrixType extraData);
369 static constexpr
int InvalidId = -1;
370 static constexpr T InvalidDist = std::numeric_limits<T>::infinity();
373 Matches(
const Dists& dists,
const Ids ids);
374 Matches(
const int knn,
const int pointsCount);
379 T getDistsQuantile(
const T quantile)
const;
380 T getMedianAbsDeviation()
const;
381 T getStandardDeviation()
const;
399 Transformation(
const std::string& className,
const ParametersDoc paramsDoc,
const Parameters& params);
403 virtual DataPoints compute(
const DataPoints& input,
const TransformationParameters& parameters)
const = 0;
406 virtual bool checkParameters(
const TransformationParameters& parameters)
const = 0;
409 virtual TransformationParameters correctParameters(
const TransformationParameters& parameters)
const = 0;
416 void apply(
DataPoints& cloud,
const TransformationParameters& parameters)
const;
432 DataPointsFilter(
const std::string& className,
const ParametersDoc paramsDoc,
const Parameters& params);
440 virtual void inPlaceFilter(
DataPoints& cloud) = 0;
467 Matcher(
const std::string& className,
const ParametersDoc paramsDoc,
const Parameters& params);
470 void resetVisitCount();
471 unsigned long getVisitCount()
const;
474 virtual void init(
const DataPoints& filteredReference) = 0;
491 OutlierFilter(
const std::string& className,
const ParametersDoc paramsDoc,
const Parameters& params);
538 ErrorMinimizer(
const std::string& className,
const ParametersDoc paramsDoc,
const Parameters& params);
541 T getPointUsedRatio()
const;
542 T getWeightedPointUsedRatio()
const;
544 virtual T getOverlap()
const;
545 virtual Matrix getCovariance()
const;
546 virtual T getResidualError(
const DataPoints& filteredReading,
const DataPoints& filteredReference,
const OutlierWeights& outlierWeights,
const Matches& matches)
const;
549 virtual TransformationParameters compute(
const DataPoints& filteredReading,
const DataPoints& filteredReference,
const OutlierWeights& outlierWeights,
const Matches& matches);
551 virtual TransformationParameters compute(
const ErrorElements& matchedPoints) = 0;
554 static Matrix crossProduct(
const Matrix& A,
const Matrix& B);
583 TransformationChecker(
const std::string& className,
const ParametersDoc paramsDoc,
const Parameters& params);
586 virtual void init(
const TransformationParameters& parameters,
bool& iterate) = 0;
588 virtual void check(
const TransformationParameters& parameters,
bool& iterate) = 0;
590 const Vector& getLimits()
const;
591 const Vector& getConditionVariables()
const;
592 const StringVector& getLimitNames()
const;
593 const StringVector& getConditionVariableNames()
const;
596 static Vector matrixToAngles(
const TransformationParameters& parameters);
602 void init(
const TransformationParameters& parameters,
bool& iterate);
603 void check(
const TransformationParameters& parameters,
bool& iterate);
617 Inspector(
const std::string& className,
const ParametersDoc paramsDoc,
const Parameters& params);
624 virtual void addStat(
const std::string& name,
double data);
625 virtual void dumpStats(std::ostream& stream);
626 virtual void dumpStatsHeader(std::ostream& stream);
629 virtual void dumpIteration(
const size_t iterationNumber,
const TransformationParameters& parameters,
const DataPoints& filteredReference,
const DataPoints& reading,
const Matches& matches,
const OutlierWeights& outlierWeights,
const TransformationCheckers& transformationCheckers);
630 virtual void finish(
const size_t iterationCount);
657 virtual ~ICPChainBase();
659 virtual void setDefault();
661 void loadFromYaml(std::istream& in);
662 unsigned getPrefilteredReadingPtsCount()
const;
663 unsigned getPrefilteredReferencePtsCount()
const;
665 bool getMaxNumIterationsReached()
const;
676 virtual void loadAdditionalYAMLContent(PointMatcherSupport::YAML::Node& doc);
680 const std::string& createModulesFromRegistrar(
const std::string& regName,
const PointMatcherSupport::YAML::Node& doc,
const R& registrar, std::vector<std::shared_ptr<typename R::TargetType> >& modules);
684 const std::string& createModuleFromRegistrar(
const std::string& regName,
const PointMatcherSupport::YAML::Node& doc,
const R& registrar, std::shared_ptr<typename R::TargetType>& module);
687 std::string nodeVal(
const std::string& regName,
const PointMatcherSupport::YAML::Node& doc);
693 TransformationParameters operator()(
697 TransformationParameters operator()(
700 const TransformationParameters& initialTransformationParameters);
702 TransformationParameters compute(
705 const TransformationParameters& initialTransformationParameters);
711 TransformationParameters computeWithTransformedReference(
714 const TransformationParameters& T_refIn_refMean,
715 const TransformationParameters& initialTransformationParameters);
724 TransformationParameters operator()(
726 TransformationParameters operator()(
728 const TransformationParameters& initialTransformationParameters);
729 TransformationParameters compute(
731 const TransformationParameters& initialTransformationParameters);
736 PM_DEPRECATED(
"Use getPrefilteredInternalMap instead. " 737 "Function now always returns map with filter chain applied. " 738 "This may have altered your program behavior." 739 "Reasons for this stated here and in associated PR: " 740 "https://github.com/ethz-asl/libpointmatcher/issues/209.")
742 const DataPoints& getPrefilteredInternalMap()
const;
743 PM_DEPRECATED(
"Use getPrefilteredMap instead. " 744 "Function now always returns map with filter chain applied. " 745 "This may have altered your program behavior." 746 "Reasons for this stated here and in associated PR: " 747 "https://github.com/ethz-asl/libpointmatcher/issues/209")
767 #endif // __POINTMATCHER_CORE_H Matrix OutlierWeights
Weights of the associations between the points in Matches and the points in the reference.
Definition: PointMatcher.h:389
std::vector< Vector, Eigen::aligned_allocator< Vector > > VectorVector
A vector of vector over ScalarType, not a matrix.
Definition: PointMatcher.h:155
A vector of Label.
Definition: PointMatcher.h:221
A matcher links points in the reading to points in the reference.
Definition: PointMatcher.h:462
const Eigen::Block< const Int64Matrix > TimeConstView
a view on a const time
Definition: PointMatcher.h:208
Parametrizable::ParametersDoc ParametersDoc
alias
Definition: PointMatcher.h:180
A structure holding data ready for minimization. The data are "normalized", for instance there are no...
Definition: PointMatcher.h:522
DataPointsFilters::const_iterator DataPointsFiltersConstIt
alias
Definition: PointMatcher.h:452
The logger interface, used to output warnings and informations.
Definition: PointMatcher.h:96
Matrix descriptors
descriptors of points in the cloud, might be empty
Definition: PointMatcher.h:325
Eigen::Block< Int64Matrix > TimeView
A view on a time.
Definition: PointMatcher.h:204
InvalidModuleType(const std::string &reason)
Construct an invalid–module-type exception.
Definition: ICP.cpp:59
void setLogger(std::shared_ptr< Logger > newLogger)
Set a new logger, protected by a mutex.
Definition: Logger.cpp:98
A point cloud.
Definition: PointMatcher.h:199
Point matcher did not converge.
Definition: PointMatcher.h:140
Matrix::Index Index
An index to a row or a column.
Definition: PointMatcher.h:210
std::ostream & operator<<(std::ostream &o, const Parametrizable::ParametersDoc &p)
Dump the documentation of these parameters to a stream.
Definition: Parametrizable.cpp:69
Eigen::Quaternion< T > Quaternion
A quaternion over ScalarType.
Definition: PointMatcher.h:157
void validateFile(const std::string &fileName)
Throw a runtime_error exception if fileName cannot be opened.
Definition: IO.cpp:355
PointMatcherSupport::Parametrizable Parametrizable
alias
Definition: PointMatcher.h:177
TransformationCheckers::iterator TransformationCheckersIt
alias
Definition: PointMatcher.h:605
DataPointsFilters referenceDataPointsFilters
filters for reference
Definition: PointMatcher.h:649
T weightedPointUsedRatio
the ratio of how many points were used (with weight) for error minimization
Definition: PointMatcher.h:531
Matrix Dists
Squared distances to closest points, dense matrix of ScalarType.
Definition: PointMatcher.h:365
ICP alogrithm, taking a sequence of clouds and using a map Warning: used with caution, you need to set the map manually.
Definition: PointMatcher.h:722
bool maxNumIterationsReached
store if we reached the maximum number of iterations last time compute was called ...
Definition: PointMatcher.h:670
Labels featureLabels
labels of features
Definition: PointMatcher.h:324
TransformationCheckers transformationCheckers
transformation checkers
Definition: PointMatcher.h:654
DataPoints reference
reference point cloud
Definition: PointMatcher.h:525
DataPoints mapPointCloud
point cloud of the map, always in global frame (frame of first point cloud)
Definition: PointMatcher.h:752
Eigen::Matrix< int, Eigen::Dynamic, Eigen::Dynamic > IntMatrix
A dense integer matrix.
Definition: PointMatcher.h:163
An error minimizer will compute a transformation matrix such as to minimize the error between the rea...
Definition: PointMatcher.h:519
TransformationCheckers::const_iterator TransformationCheckersConstIt
alias
Definition: PointMatcher.h:606
unsigned long visitCounter
number of points visited
Definition: PointMatcher.h:464
Labels timeLabels
labels of times.
Definition: PointMatcher.h:328
The name for a certain number of dim.
Definition: PointMatcher.h:213
std::map< std::string, std::vector< std::string > > CsvElements
Data from a CSV file.
Definition: PointMatcher.h:117
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dense matrix over ScalarType.
Definition: PointMatcher.h:161
int nbRejectedPoints
number of points with all matches set to zero weights
Definition: PointMatcher.h:529
Parametrizable::Parameters Parameters
alias
Definition: PointMatcher.h:178
DataPointsFilters readingDataPointsFilters
filters for reading, applied once
Definition: PointMatcher.h:647
std::map< std::string, Parameter > Parameters
Parameters stored as a map of string->string.
Definition: Parametrizable.h:156
DataPoints readingFiltered
reading point cloud after the filters were applied
Definition: PointMatcher.h:717
OutlierWeights weights
weights for every association
Definition: PointMatcher.h:526
int nbRejectedMatches
number of matches with zero weights
Definition: PointMatcher.h:528
T ScalarType
The scalar type.
Definition: PointMatcher.h:151
Functions and classes that are not dependant on scalar type are defined in this namespace.
Definition: PointMatcher.h:78
Parametrizable::ParameterDoc ParameterDoc
alias
Definition: PointMatcher.h:179
An inspector allows to log data at the different steps, for analysis.
Definition: PointMatcher.h:613
An exception thrown when one tries to use a module type that does not exist.
Definition: PointMatcher.h:83
const Eigen::Block< const Matrix > ConstView
A view on a const feature or const descriptor.
Definition: PointMatcher.h:206
Functions and classes that are dependant on scalar type are defined in this templatized class...
Definition: PointMatcher.h:122
Transformations::const_iterator TransformationsConstIt
alias
Definition: PointMatcher.h:419
OutlierFilters outlierFilters
outlier filters
Definition: PointMatcher.h:652
const DataPoints & getReadingFiltered() const
Return the filtered point cloud reading used in the ICP chain.
Definition: PointMatcher.h:708
Result of the data-association step (Matcher::findClosests), before outlier rejection.
Definition: PointMatcher.h:363
std::vector< Quaternion, Eigen::aligned_allocator< Quaternion > > QuaternionVector
A vector of quaternions over ScalarType.
Definition: PointMatcher.h:159
A data filter takes a point cloud as input, transforms it, and produces another point cloud as output...
Definition: PointMatcher.h:429
std::shared_ptr< ErrorMinimizer > errorMinimizer
error minimizer
Definition: PointMatcher.h:653
An outlier filter removes or weights links between points in reading and their matched points in refe...
Definition: PointMatcher.h:488
Eigen::Matrix< std::int64_t, Eigen::Dynamic, Eigen::Dynamic > Int64Matrix
A dense signed 64-bits matrix.
Definition: PointMatcher.h:165
The documentation of a parameter.
Definition: Parametrizable.h:117
A chain of DataPointsFilter.
Definition: PointMatcher.h:444
Parametrizable::InvalidParameter InvalidParameter
alias
Definition: PointMatcher.h:181
The superclass of classes that are constructed using generic parameters. This class provides the para...
Definition: Parametrizable.h:98
An exception thrown when one tries to fetch the value of an unexisting parameter. ...
Definition: Parametrizable.h:101
Transformations::iterator TransformationsIt
alias
Definition: PointMatcher.h:418
std::vector< ParameterDoc > ParametersDoc
The documentation of all parameters.
Definition: Parametrizable.h:144
A chain of OutlierFilter.
Definition: PointMatcher.h:501
std::shared_ptr< Matcher > matcher
matcher
Definition: PointMatcher.h:651
IntMatrix Ids
Identifiers of closest points, dense matrix of integers.
Definition: PointMatcher.h:366
DataPointsFilters::iterator DataPointsFiltersIt
alias
Definition: PointMatcher.h:451
size_t span
number of data dimensions the label spans
Definition: PointMatcher.h:216
TransformationParameters T_refIn_refMean
offset for centered map
Definition: PointMatcher.h:753
ErrorElements lastErrorElements
memory of the last computed error
Definition: PointMatcher.h:560
std::shared_ptr< Inspector > inspector
inspector
Definition: PointMatcher.h:655
Eigen::Block< Matrix > View
A view on a feature or descriptor.
Definition: PointMatcher.h:202
Transformations transformations
transformations
Definition: PointMatcher.h:650
unsigned prefilteredReadingPtsCount
remaining number of points after prefiltering but before the iterative process
Definition: PointMatcher.h:668
An exception thrown when one tries to access features or descriptors unexisting or of wrong dimension...
Definition: PointMatcher.h:242
T pointUsedRatio
the ratio of how many points were used for error minimization
Definition: PointMatcher.h:530
Int64Matrix times
time associated to each points, might be empty
Definition: PointMatcher.h:327
Dists dists
squared distances to closest points
Definition: PointMatcher.h:376
std::vector< Label >::const_iterator const_iterator
alias
Definition: PointMatcher.h:223
Eigen::Array< T, Eigen::Dynamic, Eigen::Dynamic > Array
A dense array over ScalarType.
Definition: PointMatcher.h:167
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vector
A vector over ScalarType.
Definition: PointMatcher.h:153
Matches matches
associations
Definition: PointMatcher.h:527
OutlierFilters::iterator OutlierFiltersIt
alias
Definition: PointMatcher.h:509
Ids ids
identifiers of closest points
Definition: PointMatcher.h:377
Matrix features
features of points in the cloud
Definition: PointMatcher.h:323
DataPointsFilters readingStepDataPointsFilters
filters for reading, applied at each step
Definition: PointMatcher.h:648
Stuff common to all ICP algorithms.
Definition: PointMatcher.h:644
OutlierFilters::const_iterator OutlierFiltersConstIt
alias
Definition: PointMatcher.h:508
ICP algorithm.
Definition: PointMatcher.h:691
DataPoints reading
reading point cloud
Definition: PointMatcher.h:524
std::string text
name of the label
Definition: PointMatcher.h:215
Matrix TransformationParameters
A matrix holding the parameters a transformation.
Definition: PointMatcher.h:174
unsigned prefilteredReferencePtsCount
remaining number of points after prefiltering but before the iterative process
Definition: PointMatcher.h:669
Labels descriptorLabels
labels of descriptors
Definition: PointMatcher.h:326