Skip to content

Commit a5c2c6d

Browse files
ADD: refined registrations
1 parent e8f6cd7 commit a5c2c6d

File tree

3 files changed

+167
-0
lines changed

3 files changed

+167
-0
lines changed

src/diffCheck.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ const diffCheck::Log LOG = diffCheck::Log();
1313
#include "diffCheck/visualizer.hh"
1414
#include "diffCheck/transformation/DFTransformation.hh"
1515
#include "diffCheck/registrations/DFGlobalRegistrations.hh"
16+
#include "diffCheck/registrations/DFRefinedRegistration.hh
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#include "DFRefinedRegistration.hh"
2+
3+
4+
namespace diffCheck::registration
5+
{
6+
diffCheck::transformation::DFTransformation RefinedRegistration::O3DICP(
7+
std::shared_ptr<geometry::DFPointCloud> source,
8+
std::shared_ptr<geometry::DFPointCloud> target,
9+
double maxCorrespondenceDistance,
10+
bool scalingForPointToPointTransformationEstimation,
11+
double relativeFitness,
12+
double relativeRMSE,
13+
int maxIteration,
14+
bool usePointToPlane)
15+
{
16+
std::vector<Eigen::Vector3d> minMax = source->ComputeBoundingBox();
17+
double scale = (minMax[1] - minMax[0]).norm();
18+
double absoluteMaxCorrespondenceDistance = maxCorrespondenceDistance * scale;
19+
20+
std::shared_ptr<open3d::geometry::PointCloud> O3Dsource = source->Cvt2O3DPointCloud();
21+
std::shared_ptr<open3d::geometry::PointCloud> O3Dtarget = target->Cvt2O3DPointCloud();
22+
Eigen::Matrix4d initialTransformation = Eigen::Matrix4d::Identity();
23+
open3d::pipelines::registration::ICPConvergenceCriteria criteria
24+
= open3d::pipelines::registration::ICPConvergenceCriteria(
25+
relativeFitness,
26+
relativeRMSE,
27+
maxIteration);
28+
29+
open3d::pipelines::registration::RegistrationResult result;
30+
31+
if(usePointToPlane)
32+
{
33+
O3Dsource->EstimateNormals();
34+
O3Dtarget->EstimateNormals();
35+
open3d::pipelines::registration::TransformationEstimationPointToPlane transformation_estimation
36+
= open3d::pipelines::registration::TransformationEstimationPointToPlane();
37+
result = open3d::pipelines::registration::RegistrationICP(
38+
*O3Dsource,
39+
*O3Dtarget,
40+
absoluteMaxCorrespondenceDistance,
41+
initialTransformation,
42+
transformation_estimation,
43+
criteria);
44+
}
45+
else
46+
{
47+
open3d::pipelines::registration::TransformationEstimationPointToPoint transformation_estimation
48+
= open3d::pipelines::registration::TransformationEstimationPointToPoint(scalingForPointToPointTransformationEstimation);
49+
result = open3d::pipelines::registration::RegistrationICP(
50+
*O3Dsource,
51+
*O3Dtarget,
52+
absoluteMaxCorrespondenceDistance,
53+
initialTransformation,
54+
transformation_estimation,
55+
criteria);
56+
}
57+
58+
diffCheck::transformation::DFTransformation transformation
59+
= diffCheck::transformation::DFTransformation(result.transformation_);
60+
return transformation;
61+
}
62+
diffCheck::transformation::DFTransformation RefinedRegistration::O3DGeneralizedICP(
63+
std::shared_ptr<geometry::DFPointCloud> source,
64+
std::shared_ptr<geometry::DFPointCloud> target,
65+
double maxCorrespondenceDistance,
66+
int maxIteration,
67+
double relativeFitness,
68+
double relativeRMSE)
69+
{
70+
std::vector<Eigen::Vector3d> minMax = source->ComputeBoundingBox();
71+
double scale = (minMax[1] - minMax[0]).norm();
72+
double absoluteMaxCorrespondenceDistance = maxCorrespondenceDistance * scale;
73+
74+
std::shared_ptr<open3d::geometry::PointCloud> O3Dsource = source->Cvt2O3DPointCloud();
75+
std::shared_ptr<open3d::geometry::PointCloud> O3Dtarget = target->Cvt2O3DPointCloud();
76+
77+
O3Dsource->EstimateCovariances();
78+
O3Dtarget->EstimateCovariances();
79+
80+
Eigen::Matrix4d initialTransformation = Eigen::Matrix4d::Identity();
81+
open3d::pipelines::registration::ICPConvergenceCriteria criteria
82+
= open3d::pipelines::registration::ICPConvergenceCriteria(
83+
relativeFitness,
84+
relativeRMSE,
85+
maxIteration);
86+
87+
open3d::pipelines::registration::TransformationEstimationForGeneralizedICP transformation_estimation
88+
= open3d::pipelines::registration::TransformationEstimationForGeneralizedICP();
89+
90+
open3d::pipelines::registration::RegistrationResult result
91+
= open3d::pipelines::registration::RegistrationGeneralizedICP(
92+
*O3Dsource,
93+
*O3Dtarget,
94+
absoluteMaxCorrespondenceDistance,
95+
initialTransformation,
96+
transformation_estimation,
97+
criteria);
98+
99+
diffCheck::transformation::DFTransformation transformation
100+
= diffCheck::transformation::DFTransformation(result.transformation_);
101+
return transformation;
102+
}
103+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#pragma once
2+
# include "diffCheck.hh"
3+
4+
# include <open3d/pipelines/registration/Registration.h>
5+
6+
namespace diffCheck::registration
7+
{
8+
class RefinedRegistration
9+
{
10+
public: ///< open3d registration methods
11+
/**
12+
* @brief Perform ICP registration using Open3D
13+
*
14+
* The ICP registration looks for points in the target point cloud that are closest to the source
15+
* point cloud and computes the transformation that minimizes the distance between the two point clouds.
16+
* The way the distance is calculated is either with point to point or point to plane methods.
17+
*
18+
* @param source DFPointCloud source point cloud
19+
* @param target DFPointCloud Target point cloud
20+
* @param maxCorrespondenceDistance Maximum relative correspondence distance. 0.01 means 1% of the bounding box diagonal
21+
* @param scalingForPointToPointTransformationEstimation Enable scaling for point-to-point transformation estimation. by default it is false, to only allow rigid transformations
22+
* @param maxIteration Maximum number of ICP iterations to use in the p2p transformation estimation
23+
* @param relativeFitness Threshold for relative fitness to use in the p2p transformation estimation
24+
* @param relativeRMSE Threshold for relative RMSE to use in the p2p transformation estimation
25+
* @param usePointToPlane Use point-to-plane ICP instead of point-to-point. This replaces the p2p with the point-to-plane transformation estimation.
26+
* @return diffCheck::transformation::DFTransformation
27+
*/
28+
static diffCheck::transformation::DFTransformation O3DICP(
29+
std::shared_ptr<geometry::DFPointCloud> source,
30+
std::shared_ptr<geometry::DFPointCloud> target,
31+
double maxCorrespondenceDistance = 0.05,
32+
bool scalingForPointToPointTransformationEstimation = false,
33+
double relativeFitness = 1e-6,
34+
double relativeRMSE = 1e-6,
35+
int maxIteration = 30,
36+
bool usePointToPlane = false);
37+
38+
/**
39+
* @brief Perform Generalized ICP registration using Open3D
40+
*
41+
* The Generalized ICP registration additionally identifies planes in the source and target
42+
* point clouds and uses them to improve the registration. According to the original 2009 paper,
43+
* it can be seen as a "plane-to-plane" ICP. The paper is called "Generalized-ICP" and is referenced below.
44+
*
45+
* @param source DFPointCloud source point cloud
46+
* @param target DFPointCloud Target point cloud
47+
* @param maxCorrespondenceDistance Maximum relative correspondence distance. 0.01 means 1% of the bounding box diagonal
48+
* @param maxIteration Maximum number of ICP iterations to use in the p2p transformation estimation
49+
* @param relativeFitness Threshold for relative fitness to use in the p2p transformation estimation
50+
* @param relativeRMSE Threshold for relative RMSE to use in the p2p transformation estimation
51+
* @return diffCheck::transformation::DFTransformation
52+
*
53+
* @see http://dx.doi.org/10.15607/RSS.2009.V.021 for more information
54+
*/
55+
static diffCheck::transformation::DFTransformation O3DGeneralizedICP(
56+
std::shared_ptr<geometry::DFPointCloud> source,
57+
std::shared_ptr<geometry::DFPointCloud> target,
58+
double maxCorrespondenceDistance = 0.05,
59+
int maxIteration = 30,
60+
double relativeFitness = 1e-6,
61+
double relativeRMSE = 1e-6);
62+
};
63+
}

0 commit comments

Comments
 (0)