Point Cloud Library (PCL)
1.11.1-dev
|
41 #include <pcl/registration/correspondence_rejection.h>
42 #include <pcl/point_cloud.h>
45 namespace registration {
62 template <
typename SourceT,
typename TargetT>
69 using Ptr = shared_ptr<CorrespondenceRejectorPoly<SourceT, TargetT>>;
70 using ConstPtr = shared_ptr<const CorrespondenceRejectorPoly<SourceT, TargetT>>;
84 , similarity_threshold_(0.75f)
85 , similarity_threshold_squared_(0.75f * 0.75f)
87 rejection_name_ =
"CorrespondenceRejectorPoly";
130 setInputSource(cloud);
146 setInputTarget(cloud);
155 cardinality_ = cardinality;
164 return (cardinality_);
174 similarity_threshold_ = similarity_threshold;
175 similarity_threshold_squared_ = similarity_threshold * similarity_threshold;
184 return (similarity_threshold_);
193 iterations_ = iterations;
202 return (iterations_);
217 return (thresholdEdgeLength(corr[idx[0]].index_query,
218 corr[idx[1]].index_query,
219 corr[idx[0]].index_match,
220 corr[idx[1]].index_match,
224 for (
int i = 0; i < cardinality_; ++i) {
225 if (!thresholdEdgeLength(corr[idx[i]].index_query,
226 corr[idx[(i + 1) % cardinality_]].index_query,
227 corr[idx[i]].index_match,
228 corr[idx[(i + 1) % cardinality_]].index_match,
229 similarity_threshold_squared_)) {
244 const std::vector<int>& target_indices)
248 std::vector<int> idx(cardinality_);
249 for (
int i = 0; i < cardinality_; ++i) {
250 corr[i].index_query = source_indices[i];
251 corr[i].index_match = target_indices[i];
255 return (thresholdPolygon(corr, idx));
265 getRemainingCorrespondences(*input_correspondences_, correspondences);
273 inline std::vector<int>
277 std::vector<bool> sampled(n,
false);
280 std::vector<int> result;
284 const int idx = (std::rand() % n);
291 result.push_back(idx);
293 }
while (samples < k);
306 const float dx = p2.x - p1.x;
307 const float dy = p2.y - p1.y;
308 const float dz = p2.z - p1.z;
310 return (dx * dx + dy * dy + dz * dz);
329 const float dist_src =
330 computeSquaredDistance((*input_)[index_query_1], (*input_)[index_query_2]);
332 const float dist_tgt =
333 computeSquaredDistance((*target_)[index_match_1], (*target_)[index_match_2]);
335 const float edge_sim =
336 (dist_src < dist_tgt ? dist_src / dist_tgt : dist_tgt / dist_src);
338 return (edge_sim >= simsq);
348 computeHistogram(
const std::vector<float>& data,
float lower,
float upper,
int bins);
355 findThresholdOtsu(
const std::vector<int>& histogram);
379 #include <pcl/registration/impl/correspondence_rejection_poly.hpp>
shared_ptr< CorrespondenceRejector > Ptr
void setTargetPoints(pcl::PCLPointCloud2::ConstPtr cloud2) override
Method for setting the target cloud.
CorrespondenceRejectorPoly()
Empty constructor.
typename PointCloudTarget::ConstPtr PointCloudTargetConstPtr
void setSimilarityThreshold(float similarity_threshold)
Set the similarity threshold in [0,1[ between edge lengths, where 1 is a perfect match.
shared_ptr< const CorrespondenceRejector > ConstPtr
CorrespondenceRejectorPoly implements a correspondence rejection method that exploits low-level and p...
void setIterations(int iterations)
Set the number of iterations.
float similarity_threshold_squared_
Squared value if similarity_threshold_, only for internal use.
int getCardinality()
Get the polygon cardinality.
PointCloudSourceConstPtr input_
The input point cloud dataset.
std::vector< int > getUniqueRandomIndices(int n, int k)
Get k unique random indices in range {0,...,n-1} (sampling without replacement)
const std::string & getClassName() const
Get a string representation of the name of this class.
bool thresholdPolygon(const std::vector< int > &source_indices, const std::vector< int > &target_indices)
Polygonal rejection of a single polygon, indexed by two point index vectors.
bool thresholdPolygon(const pcl::Correspondences &corr, const std::vector< int > &idx)
Polygonal rejection of a single polygon, indexed by a subset of correspondences.
PointCloud represents the base class in PCL for storing collections of 3D points.
typename PointCloudSource::Ptr PointCloudSourcePtr
typename PointCloudSource::ConstPtr PointCloudSourceConstPtr
float getSimilarityThreshold()
Get the similarity threshold between edge lengths.
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
void setInputSource(const PointCloudSourceConstPtr &cloud)
Provide a source point cloud dataset (must contain XYZ data!), used to compute the correspondence dis...
bool thresholdEdgeLength(int index_query_1, int index_query_2, int index_match_1, int index_match_2, float simsq)
Edge length similarity thresholding.
float computeSquaredDistance(const SourceT &p1, const TargetT &p2)
Squared Euclidean distance between two points using the members x, y and z.
float similarity_threshold_
Lower edge length threshold in [0,1] used for verifying polygon similarities, where 1 is a perfect ma...
void setInputTarget(const PointCloudTargetConstPtr &target)
Provide a target point cloud dataset (must contain XYZ data!), used to compute the correspondence dis...
PointCloudTargetConstPtr target_
The input point cloud dataset target.
int getIterations()
Get the number of iterations.
int iterations_
Number of iterations to run.
shared_ptr< PointCloud< PointT > > Ptr
typename PointCloudTarget::Ptr PointCloudTargetPtr
int cardinality_
The polygon cardinality used during rejection.
shared_ptr< const PointCloud< PointT > > ConstPtr
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
void setCardinality(int cardinality)
Set the polygon cardinality.
void setSourcePoints(pcl::PCLPointCloud2::ConstPtr cloud2) override
Blob method for setting the source cloud.
void applyRejection(pcl::Correspondences &correspondences) override
Apply the rejection algorithm.
bool requiresTargetPoints() const override
See if this rejector requires a target cloud.
CorrespondencesConstPtr input_correspondences_
The input correspondences.
std::string rejection_name_
The name of the rejection method.
CorrespondenceRejector represents the base class for correspondence rejection methods
void fromPCLPointCloud2(const pcl::PCLPointCloud2 &msg, pcl::PointCloud< PointT > &cloud, const MsgFieldMap &field_map)
Convert a PCLPointCloud2 binary data blob into a pcl::PointCloud<T> object using a field_map.
bool requiresSourcePoints() const override
See if this rejector requires source points.