00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #pragma once
00036
00037 #include "PointMatcher.h"
00038
00040 template<typename T>
00041 struct ElipsoidsDataPointsFilter: public PointMatcher<T>::DataPointsFilter
00042 {
00043 typedef PointMatcherSupport::Parametrizable Parametrizable;
00044 typedef PointMatcherSupport::Parametrizable P;
00045 typedef Parametrizable::Parameters Parameters;
00046 typedef Parametrizable::ParameterDoc ParameterDoc;
00047 typedef Parametrizable::ParametersDoc ParametersDoc;
00048 typedef Parametrizable::InvalidParameter InvalidParameter;
00049
00050 typedef typename PointMatcher<T>::Vector Vector;
00051 typedef typename PointMatcher<T>::Matrix Matrix;
00052 typedef typename PointMatcher<T>::DataPoints DataPoints;
00053 typedef typename PointMatcher<T>::DataPoints::InvalidField InvalidField;
00054
00055 inline static const std::string description()
00056 {
00057 return "Subsampling, Surfels (Elipsoids). This filter decomposes the point-cloud space in boxes, by recursively splitting the cloud through axis-aligned hyperplanes such as to maximize the evenness of the aspect ratio of the box. When the number of points in a box reaches a value knn or lower, the filter computes the center of mass of these points and its normal by taking the eigenvector corresponding to the smallest eigenvalue of all points in the box.";
00058 }
00059 inline static const ParametersDoc availableParameters()
00060 {
00061 return {
00062 {"ratio", "ratio of points to keep with random subsampling. Matrix (normal, density, etc.) will be associated to all points in the same bin.", "0.5", "0.0000001", "0.9999999", &P::Comp<T> },
00063 {"knn", "determined how many points are used to compute the normals. Direct link with the rapidity of the computation (large = fast). Technically, limit over which a box is splitted in two", "7", "3", "2147483647", &P::Comp<unsigned> },
00064 {"samplingMethod", "if set to 0, random subsampling using the parameter ratio. If set to 1, bin subsampling with the resulting number of points being 1/knn.", "0", "0", "1", &P::Comp<unsigned> },
00065 {"maxBoxDim", "maximum length of a box above which the box is discarded", "inf" },
00066 {"averageExistingDescriptors", "whether the filter keep the existing point descriptors and average them or should it drop them", "1" },
00067 {"maxTimeWindow", "maximum spread of times in a surfel", "inf" },
00068 {"minPlanarity", "to what extend planarity of surfels needs to be enforced", "0"},
00069 {"keepNormals", "whether the normals should be added as descriptors to the resulting cloud", "1" },
00070 {"keepDensities", "whether the point densities should be added as descriptors to the resulting cloud", "0" },
00071 {"keepEigenValues", "whether the eigen values should be added as descriptors to the resulting cloud", "0" },
00072 {"keepEigenVectors", "whether the eigen vectors should be added as descriptors to the resulting cloud", "0" },
00073 {"keepMeans", "whether the means should be added as descriptors to the resulting cloud", "0" },
00074 {"keepCovariances", "whether the covariances should be added as descriptors to the resulting cloud", "0" },
00075 {"keepWeights", "whether the original number of points should be added as descriptors to the resulting cloud", "0" },
00076 {"keepShapes", "whether the shape parameters of cylindricity (C), sphericality (S) and planarity (P) shall be calculated", "0" },
00077 {"keepIndices", "whether the indices of points an ellipsoid is constructed of shall be kept", "0" }
00078 }
00079 ;
00080 }
00081
00082 const T ratio;
00083 const unsigned knn;
00084 const unsigned samplingMethod;
00085 const T maxBoxDim;
00086 const T maxTimeWindow;
00087 const T minPlanarity;
00088 const bool averageExistingDescriptors;
00089 const bool keepNormals;
00090 const bool keepDensities;
00091 const bool keepEigenValues;
00092 const bool keepEigenVectors;
00093 const bool keepCovariances;
00094 const bool keepWeights;
00095 const bool keepMeans;
00096 const bool keepShapes;
00097 const bool keepIndices;
00098
00099
00100 public:
00101 ElipsoidsDataPointsFilter(const Parameters& params = Parameters());
00102 virtual ~ElipsoidsDataPointsFilter() {}
00103 virtual DataPoints filter(const DataPoints& input);
00104 virtual void inPlaceFilter(DataPoints& cloud);
00105
00106 protected:
00107 struct BuildData
00108 {
00109 typedef std::vector<int> Indices;
00110 typedef typename DataPoints::View View;
00111 typedef typename Eigen::Matrix<std::int64_t, Eigen::Dynamic, Eigen::Dynamic> Int64Matrix;
00112 typedef typename Eigen::Matrix<std::int64_t, 1, Eigen::Dynamic> Int64Vector;
00113
00114 Indices indices;
00115 Indices indicesToKeep;
00116 Matrix& features;
00117 Matrix& descriptors;
00118 Int64Matrix& times;
00119 boost::optional<View> normals;
00120 boost::optional<View> densities;
00121 boost::optional<View> eigenValues;
00122 boost::optional<View> eigenVectors;
00123 boost::optional<View> weights;
00124 boost::optional<View> covariance;
00125 boost::optional<View> means;
00126 boost::optional<View> shapes;
00127 boost::optional<View> pointIds;
00128 boost::optional<View> pointX;
00129 boost::optional<View> pointY;
00130 boost::optional<View> pointZ;
00131 boost::optional<View> numOfNN;
00132 int outputInsertionPoint;
00133 int unfitPointsCount;
00134
00135 BuildData(Matrix& features, Matrix& descriptors, Int64Matrix& times):
00136 features(features),
00137 descriptors(descriptors),
00138 times(times),
00139 unfitPointsCount(0)
00140 {
00141 const int pointsCount(features.cols());
00142 indices.reserve(pointsCount);
00143 for (int i = 0; i < pointsCount; ++i)
00144 indices.push_back(i);
00145 }
00146 };
00147
00148 struct CompareDim
00149 {
00150 const int dim;
00151 const BuildData& buildData;
00152 CompareDim(const int dim, const BuildData& buildData):dim(dim),buildData(buildData){}
00153 bool operator() (const int& p0, const int& p1)
00154 {
00155 return buildData.features(dim, p0) <
00156 buildData.features(dim, p1);
00157 }
00158 };
00159
00160 protected:
00161 void buildNew(BuildData& data, const int first, const int last, Vector&& minValues, Vector&& maxValues) const;
00162 void fuseRange(BuildData& data, const int first, const int last) const;
00163 };