41#include <pcl/registration/correspondence_rejection.h>
42#include <pcl/point_cloud.h>
62template <
typename SourceT,
typename TargetT>
69 using Ptr = shared_ptr<CorrespondenceRejectorPoly<SourceT, TargetT>>;
70 using ConstPtr = shared_ptr<const CorrespondenceRejectorPoly<SourceT, TargetT>>;
214 corr[idx[1]].index_query,
215 corr[idx[0]].index_match,
216 corr[idx[1]].index_match,
223 corr[idx[i]].index_match,
248 corr[i].index_query = source_indices[i];
249 corr[i].index_match = target_indices[i];
272 inline std::vector<int>
276 std::vector<bool> sampled(n,
false);
279 std::vector<int> result;
283 const int idx = (std::rand() % n);
290 result.push_back(idx);
292 }
while (samples < k);
305 const float dx = p2.x - p1.x;
306 const float dy = p2.y - p1.y;
307 const float dz = p2.z - p1.z;
309 return (dx * dx + dy * dy + dz * dz);
328 const float dist_src =
331 const float dist_tgt =
334 const float edge_sim =
335 (dist_src < dist_tgt ? dist_src / dist_tgt : dist_tgt / dist_src);
337 return (edge_sim >= simsq);
382#include <pcl/registration/impl/correspondence_rejection_poly.hpp>
PointCloud represents the base class in PCL for storing collections of 3D points.
shared_ptr< PointCloud< SourceT > > Ptr
shared_ptr< const PointCloud< SourceT > > ConstPtr
CorrespondenceRejector()=default
Empty constructor.
CorrespondencesConstPtr input_correspondences_
The input correspondences.
std::string rejection_name_
The name of the rejection method.
const std::string & getClassName() const
Get a string representation of the name of this class.
float similarity_threshold_squared_
std::vector< int > getUniqueRandomIndices(int n, int k)
Get k unique random indices in range {0,...,n-1} (sampling without replacement).
bool thresholdPolygon(const pcl::Correspondences &corr, const std::vector< int > &idx)
Polygonal rejection of a single polygon, indexed by a subset of correspondences.
typename PointCloudSource::Ptr PointCloudSourcePtr
void getRemainingCorrespondences(const pcl::Correspondences &original_correspondences, pcl::Correspondences &remaining_correspondences) override
Get a list of valid correspondences after rejection from the original set of correspondences.
float similarity_threshold_
std::vector< int > computeHistogram(const std::vector< float > &data, float lower, float upper, int bins)
Compute a linear histogram.
float computeSquaredDistance(const SourceT &p1, const TargetT &p2)
Squared Euclidean distance between two points using the members x, y and z.
int getIterations()
Get the number of iterations.
typename PointCloudTarget::ConstPtr PointCloudTargetConstPtr
PointCloudSourceConstPtr input_
float getSimilarityThreshold()
Get the similarity threshold between edge lengths.
void setTargetPoints(pcl::PCLPointCloud2::ConstPtr cloud2) override
Method for setting the target cloud.
bool thresholdPolygon(const pcl::Indices &source_indices, const pcl::Indices &target_indices)
Polygonal rejection of a single polygon, indexed by two point index vectors.
void applyRejection(pcl::Correspondences &correspondences) override
Apply the rejection algorithm.
void setCardinality(int cardinality)
Set the polygon cardinality.
void setSimilarityThreshold(float similarity_threshold)
Set the similarity threshold in [0,1[ between edge lengths, where 1 is a perfect match.
int findThresholdOtsu(const std::vector< int > &histogram)
Find the optimal value for binary histogram thresholding using Otsu's method.
pcl::PointCloud< TargetT > PointCloudTarget
void setIterations(int iterations)
Set the number of iterations.
shared_ptr< CorrespondenceRejectorPoly< SourceT, TargetT > > Ptr
bool thresholdEdgeLength(int index_query_1, int index_query_2, int index_match_1, int index_match_2, float simsq)
CorrespondenceRejectorPoly()
Empty constructor.
typename PointCloudTarget::Ptr PointCloudTargetPtr
shared_ptr< const CorrespondenceRejectorPoly< SourceT, TargetT > > ConstPtr
PointCloudTargetConstPtr target_
void setInputTarget(const PointCloudTargetConstPtr &target)
Provide a target point cloud dataset (must contain XYZ data!), used to compute the correspondence dis...
void setSourcePoints(pcl::PCLPointCloud2::ConstPtr cloud2) override
Blob method for setting the source cloud.
void setInputSource(const PointCloudSourceConstPtr &cloud)
Provide a source point cloud dataset (must contain XYZ data!), used to compute the correspondence dis...
pcl::PointCloud< SourceT > PointCloudSource
bool requiresTargetPoints() const override
See if this rejector requires a target cloud.
bool requiresSourcePoints() const override
See if this rejector requires source points.
int getCardinality()
Get the polygon cardinality.
typename PointCloudSource::ConstPtr PointCloudSourceConstPtr
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
IndicesAllocator<> Indices
Type used for indices in PCL.
void fromPCLPointCloud2(const pcl::PCLPointCloud2 &msg, pcl::PointCloud< PointT > &cloud, const MsgFieldMap &field_map, const std::uint8_t *msg_data)
Convert a PCLPointCloud2 binary data blob into a pcl::PointCloud<T> object using a field_map.
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr