42 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void
45 if (cloud->points.empty ())
47 PCL_ERROR (
"[pcl::%s::setInputTarget] Invalid or empty point cloud dataset given!\n", getClassName ().c_str ());
51 target_cloud_updated_ =
true;
55 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
bool
60 PCL_ERROR (
"[pcl::registration::%s::compute] No input target dataset was given!\n", getClassName ().c_str ());
65 if (target_cloud_updated_ && !force_no_recompute_)
67 tree_->setInputCloud (target_);
68 target_cloud_updated_ =
false;
73 if (correspondence_estimation_)
75 correspondence_estimation_->setSearchMethodTarget (tree_, force_no_recompute_);
76 correspondence_estimation_->setSearchMethodSource (tree_reciprocal_, force_no_recompute_reciprocal_);
86 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
bool
91 PCL_ERROR (
"[pcl::registration::%s::compute] No input source dataset was given!\n", getClassName ().c_str ());
95 if (source_cloud_updated_ && !force_no_recompute_reciprocal_)
97 tree_reciprocal_->setInputCloud (input_);
98 source_cloud_updated_ =
false;
104 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline double
106 const std::vector<float> &distances_a,
107 const std::vector<float> &distances_b)
109 unsigned int nr_elem =
static_cast<unsigned int> (std::min (distances_a.size (), distances_b.size ()));
110 Eigen::VectorXf map_a = Eigen::VectorXf::Map (&distances_a[0], nr_elem);
111 Eigen::VectorXf map_b = Eigen::VectorXf::Map (&distances_b[0], nr_elem);
112 return (static_cast<double> ((map_a - map_b).sum ()) / static_cast<double> (nr_elem));
116 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline double
120 double fitness_score = 0.0;
126 std::vector<int> nn_indices (1);
127 std::vector<float> nn_dists (1);
131 for (
size_t i = 0; i < input_transformed.
points.size (); ++i)
134 tree_->nearestKSearch (input_transformed.
points[i], 1, nn_indices, nn_dists);
137 if (nn_dists[0] <= max_range)
140 fitness_score += nn_dists[0];
146 return (fitness_score / nr);
148 return (std::numeric_limits<double>::max ());
153 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void
156 align (output, Matrix4::Identity ());
160 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void
167 if (output.
points.size () != indices_->size ())
168 output.
points.resize (indices_->size ());
170 output.
header = input_->header;
172 if (indices_->size () != input_->points.size ())
174 output.
width =
static_cast<uint32_t
> (indices_->size ());
179 output.
width =
static_cast<uint32_t
> (input_->width);
180 output.
height = input_->height;
185 for (
size_t i = 0; i < indices_->size (); ++i)
186 output.
points[i] = input_->points[(*indices_)[i]];
189 if (point_representation_ && !force_no_recompute_)
190 tree_->setPointRepresentation (point_representation_);
194 final_transformation_ = transformation_ = previous_transformation_ = Matrix4::Identity ();
198 for (
size_t i = 0; i < indices_->size (); ++i)
199 output.
points[i].data[3] = 1.0;
201 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...
uint32_t width
The point cloud width (if organized as an image-structure).
double getFitnessScore(double max_range=std::numeric_limits< double >::max())
Obtain the Euclidean fitness score (e.g., sum of squared distances from the source to the target) ...
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...
Eigen::Matrix< Scalar, 4, 4 > Matrix4
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
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=true)
Apply an affine transform defined by an Eigen Transform.
bool initCompute()
Internal computation initialization.
uint32_t height
The point cloud height (if organized as an image-structure).
PointCloudTarget::ConstPtr PointCloudTargetConstPtr
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields)...
pcl::PCLHeader header
The point cloud header.