ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Registration.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include "pipelines/registration/Registration.h"
9 
10 #include <Logging.h>
11 #include <benchmark/benchmark.h>
12 #include <ecvKDTreeFlann.h>
13 #include <ecvPointCloud.h>
14 
15 #include <Eigen/Eigen>
16 
20 
21 namespace cloudViewer {
22 namespace pipelines {
23 namespace registration {
24 
25 // Testing parameters:
26 // ICP ConvergenceCriteria.
27 static const double relative_fitness = 1e-6;
28 static const double relative_rmse = 1e-6;
29 static const int max_iterations = 10;
30 
31 static const double voxel_downsampling_factor = 0.02;
32 
33 // NNS parameter.
34 static const double max_correspondence_distance = 0.05;
35 
36 static std::tuple<ccPointCloud, ccPointCloud> LoadPointCloud(
37  const std::string& source_filename,
38  const std::string& target_filename,
39  const double voxel_downsample_factor) {
40  ccPointCloud source;
41  ccPointCloud target;
42 
43  io::ReadPointCloud(source_filename, source, {"auto", false, false, true});
44  io::ReadPointCloud(target_filename, target, {"auto", false, false, true});
45 
46  // Eliminates the case of impractical values (including negative).
47  if (voxel_downsample_factor > 0.001) {
48  source = *source.VoxelDownSample(voxel_downsample_factor);
49  target = *target.VoxelDownSample(voxel_downsample_factor);
50  } else {
52  " VoxelDownSample: Impractical voxel size [< 0.001], skiping "
53  "downsampling.");
54  }
55 
56  return std::make_tuple(source, target);
57 }
58 
59 static void BenchmarkICPLegacy(benchmark::State& state,
61  data::DemoICPPointClouds demo_icp_pointclouds;
62  ccPointCloud source, target;
63  std::tie(source, target) = LoadPointCloud(demo_icp_pointclouds.GetPaths(0),
64  demo_icp_pointclouds.GetPaths(1),
66 
67  std::shared_ptr<TransformationEstimation> estimation;
69  estimation = std::make_shared<TransformationEstimationPointToPlane>();
71  estimation = std::make_shared<TransformationEstimationPointToPoint>();
72  }
73 
74  Eigen::Matrix4d init_trans;
75  init_trans << 0.862, 0.011, -0.507, 0.5, -0.139, 0.967, -0.215, 0.7, 0.487,
76  0.255, 0.835, -1.4, 0.0, 0.0, 0.0, 1.0;
77 
78  RegistrationResult reg_result(init_trans);
79  // Warm up.
80  reg_result = RegistrationICP(
81  source, target, max_correspondence_distance, init_trans,
82  *estimation,
85  for (auto _ : state) {
86  reg_result = RegistrationICP(
87  source, target, max_correspondence_distance, init_trans,
88  *estimation,
91  }
92 
93  utility::LogDebug(" Max iterations: {}, Max_correspondence_distance : {}",
95  utility::LogDebug(" Fitness: {} Inlier RMSE: {}", reg_result.fitness_,
96  reg_result.inlier_rmse_);
97 }
98 
100  PointToPlane / CPU,
102  ->Unit(benchmark::kMillisecond);
103 
105  PointToPoint / CPU,
107  ->Unit(benchmark::kMillisecond);
108 
109 } // namespace registration
110 } // namespace pipelines
111 } // namespace cloudViewer
char type
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
std::shared_ptr< ccPointCloud > VoxelDownSample(double voxel_size)
Function to downsample input ccPointCloud into output ccPointCloud with a voxel.
Data class for DemoICPPointClouds contains 3 point clouds of binary PCD format. This data is used in ...
Definition: Dataset.h:423
std::vector< std::string > GetPaths() const
Returns list of 3 point cloud paths.
Definition: Dataset.h:428
Class that defines the convergence criteria of ICP.
Definition: Registration.h:36
double inlier_rmse_
RMSE of all inlier correspondences. Lower is better.
Definition: Registration.h:120
#define LogWarning(...)
Definition: Logging.h:72
#define LogDebug(...)
Definition: Logging.h:90
bool ReadPointCloud(const std::string &filename, ccPointCloud &pointcloud, const ReadPointCloudOption &params)
BENCHMARK_CAPTURE(BenchmarkCreateFromPointCloudBallPivoting, Without Non Finite Points, true) -> Unit(benchmark::kMillisecond)
static std::tuple< ccPointCloud, ccPointCloud > LoadPointCloud(const std::string &source_filename, const std::string &target_filename, const double voxel_downsample_factor)
static void BenchmarkICPLegacy(benchmark::State &state, const TransformationEstimationType &type)
RegistrationResult RegistrationICP(const ccPointCloud &source, const ccPointCloud &target, double max_correspondence_distance, const Eigen::Matrix4d &init, const TransformationEstimation &estimation, const ICPConvergenceCriteria &criteria)
Functions for ICP registration.
static const double max_correspondence_distance
static const double voxel_downsampling_factor
Generic file read and write utility for python interface.