43#include <pcl/search/auto.h>
47template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
52 if (cloud->points.empty()) {
53 PCL_ERROR(
"[pcl::%s::setInputSource] Invalid or empty point cloud dataset given!\n",
54 getClassName().c_str());
57 source_cloud_updated_ =
true;
61template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
66 if (cloud->points.empty()) {
67 PCL_ERROR(
"[pcl::%s::setInputTarget] Invalid or empty point cloud dataset given!\n",
68 getClassName().c_str());
72 target_cloud_updated_ =
true;
75template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
80 PCL_ERROR(
"[pcl::registration::%s::compute] No input target dataset was given!\n",
81 getClassName().c_str());
86 if (target_cloud_updated_ && !force_no_recompute_) {
87 if (point_representation_) {
88 if (!tree_ || !tree_->setPointRepresentation(point_representation_) ||
89 !tree_->setInputCloud(target_))
90 tree_.reset(pcl::search::autoSelectMethod<PointTarget>(
93 point_representation_,
97 else if (!tree_ || !tree_->setInputCloud(target_))
98 tree_.reset(pcl::search::autoSelectMethod<PointTarget>(
100 target_cloud_updated_ =
false;
104 if (correspondence_estimation_) {
105 correspondence_estimation_->setSearchMethodTarget(tree_, force_no_recompute_);
106 correspondence_estimation_->setSearchMethodSource(tree_reciprocal_,
107 force_no_recompute_reciprocal_);
117template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
122 PCL_ERROR(
"[pcl::registration::%s::compute] No input source dataset was given!\n",
123 getClassName().c_str());
127 if (source_cloud_updated_ && !force_no_recompute_reciprocal_) {
128 if (!tree_reciprocal_ || !tree_reciprocal_->setInputCloud(input_))
129 tree_reciprocal_.reset(pcl::search::autoSelectMethod<PointSource>(input_,
false));
130 source_cloud_updated_ =
false;
135template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
138 const std::vector<float>& distances_a,
const std::vector<float>& distances_b)
140 unsigned int nr_elem =
141 static_cast<unsigned int>(std::min(distances_a.size(), distances_b.size()));
142 Eigen::VectorXf map_a = Eigen::VectorXf::Map(distances_a.data(), nr_elem);
143 Eigen::VectorXf map_b = Eigen::VectorXf::Map(distances_b.data(), nr_elem);
144 return (
static_cast<double>((map_a - map_b).sum()) /
static_cast<double>(nr_elem));
147template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
152 double fitness_score = 0.0;
156 if (use_indices && indices_ && indices_->size() != input_->size())
162 std::vector<float> nn_dists(1);
166 for (
const auto& point : input_transformed) {
170 tree_->nearestKSearchT(point, 1, nn_indices, nn_dists);
173 if (nn_dists[0] <= max_range) {
175 fitness_score += nn_dists[0];
181 return (fitness_score / nr);
182 return (std::numeric_limits<double>::max());
185template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
189 align(output, Matrix4::Identity());
192template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
201 output.
resize(indices_->size());
203 output.
header = input_->header;
205 if (indices_->size() != input_->size()) {
206 output.
width = indices_->size();
210 output.
width =
static_cast<std::uint32_t
>(input_->width);
211 output.
height = input_->height;
216 for (std::size_t i = 0; i < indices_->size(); ++i)
217 output[i] = (*input_)[(*indices_)[i]];
221 final_transformation_ = transformation_ = previous_transformation_ =
226 for (std::size_t i = 0; i < indices_->size(); ++i)
227 output[i].data[3] = 1.0;
229 computeTransformation(output, guess);
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields).
void resize(std::size_t count)
Resizes the container to contain count elements.
std::uint32_t width
The point cloud width (if organized as an image-structure).
pcl::PCLHeader header
The point cloud header.
std::uint32_t height
The point cloud height (if organized as an image-structure).
bool initCompute()
Internal computation initialization.
virtual void setInputSource(const PointCloudSourceConstPtr &cloud)
Provide a pointer to the input source (e.g., the point cloud that we want to align to the target)
typename PointCloudSource::ConstPtr PointCloudSourceConstPtr
virtual void setInputTarget(const PointCloudTargetConstPtr &cloud)
Provide a pointer to the input target (e.g., the point cloud that we want to align the input source t...
typename PointCloudTarget::ConstPtr PointCloudTargetConstPtr
Eigen::Matrix< Scalar, 4, 4 > Matrix4
void align(PointCloudSource &output)
Call the registration algorithm which estimates the transformation and returns the transformed source...
double getFitnessScore(double max_range=std::numeric_limits< double >::max(), bool use_indices=false)
Obtain the Euclidean fitness score (e.g., mean of squared distances from the source to the target)
bool initComputeReciprocal()
Internal computation when reciprocal lookup is needed.
void transformPointCloud(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, const Eigen::Matrix< Scalar, 4, 4 > &transform, bool copy_all_fields)
Apply a rigid transform defined by a 4x4 matrix.
@ one_knn_search
The search method will mainly be used for nearestKSearch where k is 1.
shared_ptr< const Indices > IndicesConstPtr
IndicesAllocator<> Indices
Type used for indices in PCL.
constexpr bool isXYZFinite(const PointT &) noexcept