48template <
typename Po
intSource,
typename Po
intTarget,
typename FeatureT>
55 "[pcl::%s::setSourceFeatures] Invalid or empty point cloud dataset given!\n",
62template <
typename Po
intSource,
typename Po
intTarget,
typename FeatureT>
69 "[pcl::%s::setTargetFeatures] Invalid or empty point cloud dataset given!\n",
77template <
typename Po
intSource,
typename Po
intTarget,
typename FeatureT>
81 unsigned int nr_samples,
82 float min_sample_distance,
85 if (nr_samples > cloud.size()) {
86 PCL_ERROR(
"[pcl::%s::selectSamples] ",
getClassName().c_str());
87 PCL_ERROR(
"The number of samples (%u) must not be greater than the number of "
90 static_cast<std::size_t
>(cloud.size()));
95 index_t iterations_without_a_sample = 0;
96 const auto max_iterations_without_a_sample = 3 * cloud.size();
97 sample_indices.clear();
98 while (sample_indices.size() < nr_samples) {
103 bool valid_sample =
true;
104 for (
const auto& sample_idx : sample_indices) {
105 float distance_between_samples =
108 if (sample_index == sample_idx ||
109 distance_between_samples < min_sample_distance) {
110 valid_sample =
false;
117 sample_indices.push_back(sample_index);
118 iterations_without_a_sample = 0;
121 ++iterations_without_a_sample;
124 if (
static_cast<std::size_t
>(iterations_without_a_sample) >=
125 max_iterations_without_a_sample) {
126 PCL_WARN(
"[pcl::%s::selectSamples] ",
getClassName().c_str());
127 PCL_WARN(
"No valid sample found after %zu iterations. Relaxing "
128 "min_sample_distance_ to %f\n",
129 static_cast<std::size_t
>(iterations_without_a_sample),
130 0.5 * min_sample_distance);
134 iterations_without_a_sample = 0;
139template <
typename Po
intSource,
typename Po
intTarget,
typename FeatureT>
149 corresponding_indices.resize(sample_indices.size());
150 for (std::size_t i = 0; i < sample_indices.size(); ++i) {
160 corresponding_indices[i] = nn_indices[random_correspondence];
164template <
typename Po
intSource,
typename Po
intTarget,
typename FeatureT>
170 std::vector<float> nn_distance(1);
175 for (
const auto& point : cloud) {
178 tree_->nearestKSearch(point, 1, nn_index, nn_distance);
181 error += compute_error(nn_distance[0]);
186template <
typename Po
intSource,
typename Po
intTarget,
typename FeatureT>
193 PCL_ERROR(
"[pcl::%s::computeTransformation] ",
getClassName().c_str());
195 "No source features were given! Call setSourceFeatures before aligning.\n");
199 PCL_ERROR(
"[pcl::%s::computeTransformation] ",
getClassName().c_str());
201 "No target features were given! Call setTargetFeatures before aligning.\n");
206 PCL_ERROR(
"[pcl::%s::computeTransformation] ",
getClassName().c_str());
207 PCL_ERROR(
"The source points and source feature points need to be in a one-to-one "
208 "relationship! Current input cloud sizes: %ld vs %ld.\n",
215 PCL_ERROR(
"[pcl::%s::computeTransformation] ",
getClassName().c_str());
216 PCL_ERROR(
"The target points and target feature points need to be in a one-to-one "
217 "relationship! Current input cloud sizes: %ld vs %ld.\n",
229 float lowest_error(0);
234 if (!guess.isApprox(Eigen::Matrix4f::Identity(), 0.01f)) {
259 if (i_iter == 0 || error < lowest_error) {
260 lowest_error = error;
PointCloudConstPtr input_
Matrix4 final_transformation_
The final transformation matrix estimated by the registration method after N iterations.
double corr_dist_threshold_
The maximum distance threshold between two correspondent points in source <-> target.
Matrix4 transformation_
The transformation matrix estimated by the registration method.
KdTreePtr tree_
A pointer to the spatial search object.
bool converged_
Holds internal convergence state, given user parameters.
TransformationEstimationPtr transformation_estimation_
A TransformationEstimation object, used to calculate the 4x4 rigid transformation.
int max_iterations_
The maximum number of iterations the internal optimization should run for.
PointCloudTargetConstPtr target_
The input point cloud dataset target.
const std::string & getClassName() const
Abstract class get name method.
void computeTransformation(PointCloudSource &output, const Eigen::Matrix4f &guess) override
Rigid transformation computation method.
typename Registration< PointSource, PointTarget >::PointCloudSource PointCloudSource
float computeErrorMetric(const PointCloudSource &cloud, float threshold)
An error metric for that computes the quality of the alignment between the given cloud and the target...
FeatureKdTreePtr feature_tree_
The KdTree used to compare feature descriptors.
pcl::index_t getRandomIndex(int n)
Choose a random index between 0 and n-1.
pcl::PointCloud< FeatureT > FeatureCloud
void setTargetFeatures(const FeatureCloudConstPtr &features)
Provide a shared pointer to the target point cloud's feature descriptors.
FeatureCloudConstPtr target_features_
The target point cloud's feature descriptors.
float min_sample_distance_
The minimum distances between samples.
FeatureCloudConstPtr input_features_
The source point cloud's feature descriptors.
int nr_samples_
The number of samples to use during each iteration.
void selectSamples(const PointCloudSource &cloud, unsigned int nr_samples, float min_sample_distance, pcl::Indices &sample_indices)
Select nr_samples sample points from cloud while making sure that their pairwise distances are greate...
void findSimilarFeatures(const FeatureCloud &input_features, const pcl::Indices &sample_indices, pcl::Indices &corresponding_indices)
For each of the sample points, find a list of points in the target cloud whose features are similar t...
typename FeatureCloud::ConstPtr FeatureCloudConstPtr
int k_correspondences_
The number of neighbors to use when selecting a random feature correspondence.
ErrorFunctorPtr error_functor_
void setSourceFeatures(const FeatureCloudConstPtr &features)
Provide a shared pointer to the source point cloud's feature descriptors.
Define standard C methods to do distance calculations.
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.
detail::int_type_t< detail::index_type_size, detail::index_type_signed > index_t
Type used for an index in PCL.
IndicesAllocator<> Indices
Type used for indices in PCL.
float euclideanDistance(const PointType1 &p1, const PointType2 &p2)
Calculate the euclidean distance between the two given points.