46 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void
49 if (cloud->points.empty ())
51 PCL_ERROR (
"[pcl::%s::setInputTarget] Invalid or empty point cloud dataset given!\n", getClassName ().c_str ());
55 target_cloud_updated_ =
true;
59 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
bool
64 PCL_ERROR (
"[pcl::registration::%s::compute] No input target dataset was given!\n", getClassName ().c_str ());
69 if (target_cloud_updated_ && !force_no_recompute_)
71 tree_->setInputCloud (target_);
72 target_cloud_updated_ =
false;
76 if (correspondence_estimation_)
78 correspondence_estimation_->setSearchMethodTarget (tree_, force_no_recompute_);
79 correspondence_estimation_->setSearchMethodSource (tree_reciprocal_, force_no_recompute_reciprocal_);
89 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
bool
94 PCL_ERROR (
"[pcl::registration::%s::compute] No input source dataset was given!\n", getClassName ().c_str ());
98 if (source_cloud_updated_ && !force_no_recompute_reciprocal_)
100 tree_reciprocal_->setInputCloud (input_);
101 source_cloud_updated_ =
false;
107 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline double
109 const std::vector<float> &distances_a,
110 const std::vector<float> &distances_b)
112 unsigned int nr_elem =
static_cast<unsigned int> (std::min (distances_a.size (), distances_b.size ()));
113 Eigen::VectorXf map_a = Eigen::VectorXf::Map (&distances_a[0], nr_elem);
114 Eigen::VectorXf map_b = Eigen::VectorXf::Map (&distances_b[0], nr_elem);
115 return (static_cast<double> ((map_a - map_b).sum ()) / static_cast<double> (nr_elem));
119 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline double
122 double fitness_score = 0.0;
128 std::vector<int> nn_indices (1);
129 std::vector<float> nn_dists (1);
133 for (std::size_t i = 0; i < input_transformed.
points.size (); ++i)
136 tree_->nearestKSearch (input_transformed.
points[i], 1, nn_indices, nn_dists);
139 if (nn_dists[0] <= max_range)
142 fitness_score += nn_dists[0];
148 return (fitness_score / nr);
149 return (std::numeric_limits<double>::max ());
154 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void
157 align (output, Matrix4::Identity ());
161 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void
168 if (output.
points.size () != indices_->size ())
169 output.
points.resize (indices_->size ());
171 output.
header = input_->header;
173 if (indices_->size () != input_->points.size ())
175 output.
width =
static_cast<std::uint32_t
> (indices_->size ());
180 output.
width =
static_cast<std::uint32_t
> (input_->width);
181 output.
height = input_->height;
186 for (std::size_t i = 0; i < indices_->size (); ++i)
187 output.
points[i] = input_->points[(*indices_)[i]];
190 if (point_representation_ && !force_no_recompute_)
191 tree_->setPointRepresentation (point_representation_);
195 final_transformation_ = transformation_ = previous_transformation_ = Matrix4::Identity ();
199 for (std::size_t i = 0; i < indices_->size (); ++i)
200 output.
points[i].data[3] = 1.0;
202 computeTransformation (output, guess);
bool initComputeReciprocal()
Internal computation when reciprocal lookup is needed.
void align(PointCloudSource &output)
Call the registration algorithm which estimates the transformation and returns the transformed source...
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
double getFitnessScore(double max_range=std::numeric_limits< double >::max())
Obtain the Euclidean fitness score (e.g., mean of squared distances from the source to the target) ...
Eigen::Matrix< Scalar, 4, 4 > Matrix4
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...
std::uint32_t width
The point cloud width (if organized as an image-structure).
void transformPointCloud(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, const Eigen::Transform< Scalar, 3, Eigen::Affine > &transform, bool copy_all_fields)
Apply an affine transform defined by an Eigen Transform.
bool initCompute()
Internal computation initialization.
std::uint32_t height
The point cloud height (if organized as an image-structure).
pcl::PCLHeader header
The point cloud header.
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields)...
typename PointCloudTarget::ConstPtr PointCloudTargetConstPtr