Skip to content

Commit ac494df

Browse files
FIX-ADD: registrations now with relative parameters for voxelization and RadiusKDTreeSearch
1 parent 61b6fc1 commit ac494df

File tree

2 files changed

+59
-29
lines changed

2 files changed

+59
-29
lines changed

src/diffCheck/registrations/DFGlobalRegistrations.cc

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,26 @@ namespace diffCheck::registrations
3636

3737
if (voxelise)
3838
{
39-
sourceO3D->VoxelDownSample(voxelSize);
40-
targetO3D->VoxelDownSample(voxelSize);
39+
double absoluteVoxelSize = voxelSize * sourceO3D->GetMaxBound().norm();
40+
sourceO3D->VoxelDownSample(absoluteVoxelSize);
41+
targetO3D->VoxelDownSample(absoluteVoxelSize);
4142
}
4243

44+
if (sourceO3D->normals_.size() == 0)
45+
{
46+
sourceO3D->EstimateNormals();
47+
}
48+
49+
if (targetO3D->normals_.size() == 0)
50+
{
51+
targetO3D->EstimateNormals();
52+
}
53+
54+
double absoluteRadiusKDTreeSearch = radiusKDTreeSearch * sourceO3D->GetMaxBound().norm();
4355
std::shared_ptr<open3d::pipelines::registration::Feature> sourceFPFHFeatures = open3d::pipelines::registration::ComputeFPFHFeature(*sourceO3D,
44-
open3d::geometry::KDTreeSearchParamHybrid(radiusKDTreeSearch, maxNeighborKDTreeSearch));
56+
open3d::geometry::KDTreeSearchParamHybrid(absoluteRadiusKDTreeSearch, maxNeighborKDTreeSearch));
4557
std::shared_ptr<open3d::pipelines::registration::Feature> targetFPFHFeatures = open3d::pipelines::registration::ComputeFPFHFeature(*targetO3D,
46-
open3d::geometry::KDTreeSearchParamHybrid(radiusKDTreeSearch, maxNeighborKDTreeSearch));
58+
open3d::geometry::KDTreeSearchParamHybrid(absoluteRadiusKDTreeSearch, maxNeighborKDTreeSearch));
4759
std::shared_ptr<open3d::pipelines::registration::FastGlobalRegistrationOption> option = std::make_shared<open3d::pipelines::registration::FastGlobalRegistrationOption>();
4860
option->maximum_correspondence_distance_ = maxCorrespondenceDistance;
4961
option->iteration_number_ = iterationNumber;
@@ -71,7 +83,8 @@ namespace diffCheck::registrations
7183
double maxCorrespondenceDistance,
7284
bool isTEstimatePt2Pt,
7385
int ransacN,
74-
double correspondenceCheckerDistance ,
86+
double correspondenceCheckerDistance,
87+
double similarityThreshold,
7588
int ransacMaxIteration,
7689
double ransacConfidenceThreshold)
7790
{
@@ -83,28 +96,41 @@ namespace diffCheck::registrations
8396

8497
if (voxelise)
8598
{
86-
sourceO3D->VoxelDownSample(voxelSize);
87-
targetO3D->VoxelDownSample(voxelSize);
99+
double absoluteVoxelSize = voxelSize * (sourceO3D->GetMaxBound().norm() - sourceO3D->GetMinBound().norm());
100+
sourceO3D->VoxelDownSample(absoluteVoxelSize);
101+
targetO3D->VoxelDownSample(absoluteVoxelSize);
102+
}
103+
104+
if (sourceO3D->normals_.size() == 0)
105+
{
106+
sourceO3D->EstimateNormals();
107+
}
108+
109+
if (targetO3D->normals_.size() == 0)
110+
{
111+
targetO3D->EstimateNormals();
88112
}
89113

114+
double absoluteRadiusKDTreeSearch = radiusKDTreeSearch * sourceO3D->GetMaxBound().norm();
90115
std::shared_ptr<open3d::pipelines::registration::Feature> sourceFPFHFeatures = open3d::pipelines::registration::ComputeFPFHFeature(*sourceO3D,
91-
open3d::geometry::KDTreeSearchParamHybrid(radiusKDTreeSearch, maxNeighborKDTreeSearch));
116+
open3d::geometry::KDTreeSearchParamHybrid(absoluteRadiusKDTreeSearch, maxNeighborKDTreeSearch));
92117
std::shared_ptr<open3d::pipelines::registration::Feature> targetFPFHFeatures = open3d::pipelines::registration::ComputeFPFHFeature(*targetO3D,
93-
open3d::geometry::KDTreeSearchParamHybrid(radiusKDTreeSearch, maxNeighborKDTreeSearch));
118+
open3d::geometry::KDTreeSearchParamHybrid(absoluteRadiusKDTreeSearch, maxNeighborKDTreeSearch));
94119
std::vector<std::reference_wrapper<const open3d::pipelines::registration::CorrespondenceChecker>> correspondanceChecker;
95120
open3d::pipelines::registration::CorrespondenceCheckerBasedOnDistance checkerOnDistance = open3d::pipelines::registration::CorrespondenceCheckerBasedOnDistance(correspondenceCheckerDistance);
121+
open3d::pipelines::registration::CorrespondenceCheckerBasedOnEdgeLength checkerOnEdgeLength = open3d::pipelines::registration::CorrespondenceCheckerBasedOnEdgeLength(similarityThreshold);
96122
correspondanceChecker.push_back(checkerOnDistance);
97123

98124
auto result = open3d::pipelines::registration::RegistrationRANSACBasedOnFeatureMatching(*sourceO3D,
99-
*targetO3D,
100-
*sourceFPFHFeatures,
101-
*targetFPFHFeatures,
102-
false,
103-
maxCorrespondenceDistance,
104-
transformationEstimation,
105-
ransacN,
106-
correspondanceChecker,
107-
open3d::pipelines::registration::RANSACConvergenceCriteria(ransacMaxIteration, ransacConfidenceThreshold));
125+
*targetO3D,
126+
*sourceFPFHFeatures,
127+
*targetFPFHFeatures,
128+
true,
129+
maxCorrespondenceDistance,
130+
transformationEstimation,
131+
ransacN,
132+
correspondanceChecker,
133+
open3d::pipelines::registration::RANSACConvergenceCriteria(ransacMaxIteration, ransacConfidenceThreshold));
108134

109135
diffCheck::transformation::DFTransformation transformation = diffCheck::transformation::DFTransformation(result.transformation_);
110136

src/diffCheck/registrations/DFGlobalRegistrations.hh

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ namespace diffCheck::registrations
3838
std::shared_ptr<geometry::DFPointCloud> target,
3939
bool voxelize = true,
4040
double voxelSize = 0.01,
41-
double radiusKDTreeSearch = 3,
42-
int maxNeighborKDTreeSearch = 50,
43-
double maxCorrespondenceDistance = 0.05,
44-
int iterationNumber = 100,
45-
int maxTupleCount = 500);
41+
double radiusKDTreeSearch = 0.05,
42+
int maxNeighborKDTreeSearch = 20,
43+
double maxCorrespondenceDistance = 10,
44+
int iterationNumber = 64,
45+
int maxTupleCount = 1000);
4646
/**
4747
* @brief Ransac registration based on Feature Matching using (Fast) Point Feature Histograms (FPFH) on the source and target point clouds
4848
*
@@ -51,13 +51,16 @@ namespace diffCheck::registrations
5151
*
5252
* @param source the source diffCheck point cloud
5353
* @param target the target diffCheck point cloud
54-
* @param voxelSize the size of the voxels used to downsample the point clouds. A higher value will result in a more coarse point cloud (less resulting points).
55-
* @param radiusKDTreeSearch the radius used to search for neighbors in the KDTree. It is used for the calculation of FPFHFeatures
54+
* @param voxelSize the size of the voxels used to downsample the point clouds. It is expressed relative to the point cloud size (0.01 means voxelSize = 1% of maxSize(pointCloud). A higher value will result in a more coarse point cloud (less resulting points).
55+
* @param radiusKDTreeSearch the radius used to search for neighbors in the KDTree.it is expressed relative to the point cloud size (0.01 means radiusKDTreeSearch = 1% of maxSize(pointCloud). It is used for the calculation of FPFHFeatures
5656
* @param maxNeighborKDTreeSearch the maximum number of neighbors to search for in the KDTree. It is used for the calculation of FPFHFeatures
5757
* @param maxCorrespondenceDistance the maximum distance between correspondences in the FPFH space. A higher value will result in more correspondences, but potentially include wrong ones.
5858
* @param isTEstimatePt2Pt the transformation estimation method to use. By default, it uses a point to point transformation estimation. If true it will scale and deform the cloud.
5959
* @param ransacN the number of points to sample in the source point cloud. A higher value can result in a more precise transformation, but will take more time to compute.
60-
* @param correspondenceCheckersDistance the maximum distance between correspondances in the FPFH space before testing a RanSaC model.
60+
* @param correspondenceCheckersDistance the maximum distance between correspondances in the FPFH space before testing a RanSaC model.
61+
* @param similarityThreshold the threshold for the ransac check based on edge length to consider a model as inlier. A higher value will be stricter, discarding more ransac models.
62+
* @param ransacMaxIteration the maximum number of iterations to run the Ransac algorithm. A higher value will take more time to compute but increases the chances of finding a good transformation.
63+
* @param ransacConfidenceThreshold the threshold for the convergence criteria of the ransac models. A higher value will be stricter, discarding more ransac models.
6164
* @return diffCheck::transformation::DFTransformation The result of the registration, containing the transformation matrix and the fitness score.
6265
*
6366
* @see https://www.open3d.org/docs/release/tutorial/pipelines/global_registration.html#RANSAC (from PCL, not Open3D)
@@ -67,14 +70,15 @@ namespace diffCheck::registrations
6770
std::shared_ptr<geometry::DFPointCloud> target,
6871
bool voxelize = true,
6972
double voxelSize = 0.01,
70-
double radiusKDTreeSearch = 3,
73+
double radiusKDTreeSearch = 0.05,
7174
int maxNeighborKDTreeSearch = 50,
7275
double maxCorrespondenceDistance = 0.05,
7376
bool isTEstimatePt2Pt = false,
7477
int ransacN = 3,
7578
double correspondenceCheckerDistance = 0.05,
76-
int ransacMaxIteration = 1000,
77-
double ransacConfidenceThreshold = 0.99);
79+
double similarityThreshold = 0.95,
80+
int ransacMaxIteration = 100000,
81+
double ransacConfidenceThreshold = 0.999);
7882

7983
private: ///< o3d utilities to evaluate registration errors
8084
/**

0 commit comments

Comments
 (0)