2#include <NDEVR/RTree.h>
3#include <NDEVR/Buffer.h>
4#include <NDEVR/LineSegment.h>
5#include <NDEVR/Distance.h>
6#include <pcl/registration/correspondence_types.h>
10 using namespace pcl::registration;
16 template <
typename PointSource,
19 typename Scalar =
float>
33 using PointCloudSource = pcl::PointCloud<PointSource>;
34 using PointCloudSourcePtr =
typename PointCloudSource::Ptr;
35 using PointCloudSourceConstPtr =
typename PointCloudSource::ConstPtr;
37 using PointCloudTarget = pcl::PointCloud<PointTarget>;
38 using PointCloudTargetPtr =
typename PointCloudTarget::Ptr;
39 using PointCloudTargetConstPtr =
typename PointCloudTarget::ConstPtr;
41 using PointCloudNormals = pcl::PointCloud<NormalT>;
42 using NormalsPtr =
typename PointCloudNormals::Ptr;
43 using NormalsConstPtr =
typename PointCloudNormals::ConstPtr;
51 , source_normals_transformed_()
67 m_tree_sorted_params = tree_sorted_params;
74 source_normals_ = normals;
81 return (source_normals_);
89 target_normals_ = normals;
96 return (target_normals_);
115 NormalsPtr cloud(
new PointCloudNormals);
116 fromPCLPointCloud2(*cloud2, *cloud);
129 NormalsPtr cloud(
new PointCloudNormals);
130 fromPCLPointCloud2(*cloud2, *cloud);
146 const auto& pt = input_->at(index);
156 const auto& pt = input_->at(index);
159 , (*target_normals_)[index].normal_y
160 , (*target_normals_)[index].normal_z);
161 ls[B] = ls[A] + m_normal_expansion_factor * nm;
162 ls[A] = ls[A] - m_normal_expansion_factor * nm;
174 index = m_tree->closestElementPresorted(vert, *m_tree_sorted_params, k_sqr_distances, m_epsilon);
177 index = m_tree->indices()[index];
189 index = m_tree->closestElementPresorted(seg, *m_tree_sorted_params, k_sqr_distances, m_epsilon);
192 index = m_tree->indices()[index];
206 m_tree->presortedClosestElements(vert, k, heap, *m_tree_sorted_params, max_distance_squared, m_epsilon);
207 const uint04 size = heap.size();
209 for (
uint04 i = 0; i < size; i++)
210 heap.values()[i].first = m_tree->indices()[heap.values()[i].first];
224 m_tree->presortedClosestElements(seg, k, heap, *m_tree_sorted_params, max_distance_squared, m_epsilon);
225 const uint04 size = heap.size();
227 for (
uint04 i = 0; i < size; i++)
228 heap.values()[i].first = m_tree->indices()[heap.values()[i].first];
239 fltp04 cos_angle = (*source_normals_)[b].normal_x *
240 (*target_normals_)[a].normal_x +
241 (*source_normals_)[b].normal_y *
242 (*target_normals_)[a].normal_y +
243 (*source_normals_)[b].normal_z *
244 (*target_normals_)[a].normal_z;
245 return d * (2.0f - cos_angle * cos_angle);
255 int count = input_->size();
256 correspondences.clear();
258 for (
int idx_i = offset; idx_i < count; idx_i += m_skip_factor)
261 fltp04 dist = max_distance;
264 if (dist <= max_distance)
266 pcl::Correspondence corr;
267 corr.index_query = idx_i;
268 corr.index_match = idx;
269 corr.distance = dist;
270 correspondences.push_back(corr);
283 int count = input_->size();
284 correspondences.clear();
286 for (
int idx_i = offset; idx_i < count; idx_i += m_skip_factor)
292 fltp04 dist = max_distance;
296 if (distance <= max_distance)
298 pcl::Correspondence corr;
299 corr.index_query = idx_i;
300 corr.index_match = idx;
301 corr.distance = distance;
302 correspondences.push_back(corr);
309 const uint04 size = heap.size();
312 uint04 min_index = heap.values()[0].first;
314 for (
uint04 i = 1; i < size; i++)
316 float dist =
calcDistance(idx_i, heap.values()[i].first);
320 min_index = heap.values()[i].first;
323 if (min_dist <= max_distance)
325 pcl::Correspondence corr;
326 corr.index_query = idx_i;
327 corr.index_match = min_index;
328 corr.distance = min_dist;
329 correspondences.push_back(corr);
353 const RTree<3, fltp04>* m_tree;
356 fltp04 m_normal_expansion_factor = 0.1f;
358 NormalsConstPtr source_normals_;
361 NormalsPtr source_normals_transformed_;
362 PointCloudSourcePtr input_;
365 PointCloudSourcePtr source_cloud_transformed_;
368 NormalsConstPtr target_normals_;
373 int m_skip_factor = 5;
The equivelent of std::vector but with a bit more control.
void determineCorrespondencesMinDistance(uint04 offset, pcl::Correspondences &correspondences, fltp04 max_distance)
Determine correspondences using minimum distance search.
MaxHeap< fltp04, uint04 > radiusNormalKSearch(uint04 tgt_idx, fltp04 max_distance_squared, uint04 k=0) const
Find k closest points using normal-expanded line segment search within a max distance.
void determineCorrespondencesBackProjection(uint04 offset, pcl::Correspondences &correspondences, fltp04 max_distance)
Determine correspondences using back-projection along normals.
void setTargetNormals(pcl::PCLPointCloud2::ConstPtr cloud2)
Method for setting the target normals.
void setTree(const RTree< 3, fltp04 > *tree, const Buffer< Vertex< 3, fltp04 > > *params, const Buffer< Vertex< 3, fltp04 > > *tree_sorted_params)
Set the spatial search tree and associated point data.
void setSourceNormals(pcl::PCLPointCloud2::ConstPtr cloud2)
Blob method for setting the source normals.
NormalsConstPtr getTargetNormals() const
Get the normals of the target point cloud.
void setTargetNormals(const NormalsConstPtr &normals)
Set the normals computed on the target point cloud.
fltp04 calcDistance(uint04 a, uint04 b) const
Calculate the weighted distance between two points, factoring in normal alignment.
bool radiusSearch(uint04 tgt_idx, uint04 &index, fltp04 &k_sqr_distances) const
Find the closest point in the tree to the target point.
bool radiusNormalSearch(uint04 tgt_idx, uint04 &index, fltp04 &k_sqr_distances) const
Find the closest point in the tree using normal-expanded line segment search.
virtual ~NDEVRCorrespondenceEstimation()=default
Empty destructor.
void setSourceNormals(const NormalsConstPtr &normals)
Set the normals computed on the source point cloud.
NDEVRCorrespondenceEstimation()
Empty constructor.
void setKSearch(unsigned int k)
Set the number of nearest neighbours to be considered in the target point cloud.
bool requiresSourceNormals() const
See if this rejector requires source normals.
void setInputTarget(PointCloudSourcePtr input)
Set the input target point cloud.
LineSegment< 3, fltp04 > lineSegment(uint04 index) const
Returns a line segment along the normal at the given index, expanded by m_normal_expansion_factor.
MaxHeap< fltp04, uint04 > radiusKSearch(uint04 tgt_idx, fltp04 max_distance_squared, uint04 k=0) const
Find k closest points within a maximum distance.
bool requiresTargetNormals() const
See if this rejector requires target normals.
unsigned int getKSearch() const
Get the number of nearest neighbours considered in the target point cloud for computing correspondenc...
NormalsConstPtr getSourceNormals() const
Get the normals of the source point cloud.
Vertex< 3, fltp04 > vertex(uint04 index) const
Determine the correspondences between input and target cloud.
A point in N-dimensional space, used primarily for spatial location information.
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
static constexpr bool IsInvalid(const Angle< t_type > &value)
Checks whether the given Angle holds an invalid value.
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.