Skip to content

Commit 028a744

Browse files
ADD: relative parameters, and tuned default values
1 parent 3338447 commit 028a744

File tree

2 files changed

+74
-32
lines changed

2 files changed

+74
-32
lines changed

src/diffCheck/registrations/DFGlobalRegistrations.cc

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ namespace diffCheck::registrations
1111
for(int i = 0; i < transforms.size(); i++)
1212
{
1313
std::shared_ptr<open3d::geometry::PointCloud> o3DPointCloud = source->Cvt2O3DPointCloud();
14-
std::shared_ptr<open3d::geometry::PointCloud> o3DPointCloudAfterTrans = std::make_shared<open3d::geometry::PointCloud>(o3DPointCloud->Transform(transforms[i]));
14+
15+
std::shared_ptr<open3d::geometry::PointCloud> o3DPointCloudAfterTrans =
16+
std::make_shared<open3d::geometry::PointCloud>(o3DPointCloud->Transform(transforms[i]));
17+
1518
std::shared_ptr<geometry::DFPointCloud> dfPointCloudPtrAfterTrans = std::make_shared<geometry::DFPointCloud>();
1619
dfPointCloudPtrAfterTrans->Cvt2DFPointCloud(o3DPointCloudAfterTrans);
1720
std::vector<double> registrationErrors = dfPointCloudPtrAfterTrans->ComputeP2PDistance(target);
@@ -34,9 +37,12 @@ namespace diffCheck::registrations
3437
std::shared_ptr<open3d::geometry::PointCloud> sourceO3D = source->Cvt2O3DPointCloud();
3538
std::shared_ptr<open3d::geometry::PointCloud> targetO3D = target->Cvt2O3DPointCloud();
3639

40+
// voxelize at the scale of the point cloud
3741
if (voxelise)
3842
{
39-
double absoluteVoxelSize = voxelSize * sourceO3D->GetMaxBound().norm();
43+
double absoluteVoxelSize =
44+
voxelSize * std::abs(sourceO3D->GetMaxBound().norm() - sourceO3D->GetMinBound().norm());
45+
4046
sourceO3D->VoxelDownSample(absoluteVoxelSize);
4147
targetO3D->VoxelDownSample(absoluteVoxelSize);
4248
}
@@ -51,24 +57,36 @@ namespace diffCheck::registrations
5157
targetO3D->EstimateNormals();
5258
}
5359

54-
double absoluteRadiusKDTreeSearch = radiusKDTreeSearch * sourceO3D->GetMaxBound().norm();
55-
std::shared_ptr<open3d::pipelines::registration::Feature> sourceFPFHFeatures = open3d::pipelines::registration::ComputeFPFHFeature(*sourceO3D,
56-
open3d::geometry::KDTreeSearchParamHybrid(absoluteRadiusKDTreeSearch, maxNeighborKDTreeSearch));
57-
std::shared_ptr<open3d::pipelines::registration::Feature> targetFPFHFeatures = open3d::pipelines::registration::ComputeFPFHFeature(*targetO3D,
58-
open3d::geometry::KDTreeSearchParamHybrid(absoluteRadiusKDTreeSearch, maxNeighborKDTreeSearch));
59-
std::shared_ptr<open3d::pipelines::registration::FastGlobalRegistrationOption> option = std::make_shared<open3d::pipelines::registration::FastGlobalRegistrationOption>();
60+
double absoluteRadiusKDTreeSearch =
61+
radiusKDTreeSearch * std::abs(sourceO3D->GetMaxBound().norm() - sourceO3D->GetMinBound().norm());
62+
63+
std::shared_ptr<open3d::pipelines::registration::Feature> sourceFPFHFeatures =
64+
open3d::pipelines::registration::ComputeFPFHFeature(
65+
*sourceO3D,
66+
open3d::geometry::KDTreeSearchParamHybrid(absoluteRadiusKDTreeSearch, maxNeighborKDTreeSearch));
67+
68+
std::shared_ptr<open3d::pipelines::registration::Feature> targetFPFHFeatures =
69+
open3d::pipelines::registration::ComputeFPFHFeature(
70+
*targetO3D,
71+
open3d::geometry::KDTreeSearchParamHybrid(absoluteRadiusKDTreeSearch, maxNeighborKDTreeSearch));
72+
73+
std::shared_ptr<open3d::pipelines::registration::FastGlobalRegistrationOption> option =
74+
std::make_shared<open3d::pipelines::registration::FastGlobalRegistrationOption>();
75+
6076
option->maximum_correspondence_distance_ = maxCorrespondenceDistance;
6177
option->iteration_number_ = iterationNumber;
6278
option->maximum_tuple_count_ = maxTupleCount;
6379

64-
open3d::pipelines::registration::RegistrationResult result = open3d::pipelines::registration::FastGlobalRegistrationBasedOnFeatureMatching(
80+
81+
open3d::pipelines::registration::RegistrationResult result =
82+
open3d::pipelines::registration::FastGlobalRegistrationBasedOnFeatureMatching(
6583
*sourceO3D,
6684
*targetO3D,
6785
*sourceFPFHFeatures,
6886
*targetFPFHFeatures,
6987
*option);
7088
diffCheck::transformation::DFTransformation transformation =
71-
diffCheck::transformation::DFTransformation(result.transformation_);
89+
diffCheck::transformation::DFTransformation(result.transformation_);
7290

7391
return transformation;
7492
}
@@ -94,9 +112,12 @@ namespace diffCheck::registrations
94112
open3d::pipelines::registration::TransformationEstimationPointToPoint transformationEstimation =
95113
open3d::pipelines::registration::TransformationEstimationPointToPoint(isTEstimatePt2Pt);
96114

115+
// voxelize at the scale of the point cloud
97116
if (voxelise)
98117
{
99-
double absoluteVoxelSize = voxelSize * (sourceO3D->GetMaxBound().norm() - sourceO3D->GetMinBound().norm());
118+
double absoluteVoxelSize =
119+
voxelSize * std::abs(sourceO3D->GetMaxBound().norm() - sourceO3D->GetMinBound().norm());
120+
100121
sourceO3D->VoxelDownSample(absoluteVoxelSize);
101122
targetO3D->VoxelDownSample(absoluteVoxelSize);
102123
}
@@ -111,22 +132,43 @@ namespace diffCheck::registrations
111132
targetO3D->EstimateNormals();
112133
}
113134

114-
double absoluteRadiusKDTreeSearch = radiusKDTreeSearch * sourceO3D->GetMaxBound().norm();
115-
std::shared_ptr<open3d::pipelines::registration::Feature> sourceFPFHFeatures = open3d::pipelines::registration::ComputeFPFHFeature(*sourceO3D,
116-
open3d::geometry::KDTreeSearchParamHybrid(absoluteRadiusKDTreeSearch, maxNeighborKDTreeSearch));
117-
std::shared_ptr<open3d::pipelines::registration::Feature> targetFPFHFeatures = open3d::pipelines::registration::ComputeFPFHFeature(*targetO3D,
118-
open3d::geometry::KDTreeSearchParamHybrid(absoluteRadiusKDTreeSearch, maxNeighborKDTreeSearch));
135+
// convert the relative values to absolute ones
136+
double absoluteRadiusKDTreeSearch =
137+
radiusKDTreeSearch * std::abs(sourceO3D->GetMaxBound().norm() - sourceO3D->GetMinBound().norm());
138+
139+
double absoluteCorrespodenceCheckerDistance =
140+
correspondenceCheckerDistance * std::abs(sourceO3D->GetMaxBound().norm() - sourceO3D->GetMinBound().norm());
141+
142+
double absoluteMaxCorrespondenceDistance =
143+
maxCorrespondenceDistance * std::abs(sourceO3D->GetMaxBound().norm() - sourceO3D->GetMinBound().norm());
144+
145+
std::shared_ptr<open3d::pipelines::registration::Feature> sourceFPFHFeatures =
146+
open3d::pipelines::registration::ComputeFPFHFeature(
147+
*sourceO3D,
148+
open3d::geometry::KDTreeSearchParamHybrid(absoluteRadiusKDTreeSearch, maxNeighborKDTreeSearch));
149+
150+
std::shared_ptr<open3d::pipelines::registration::Feature> targetFPFHFeatures =
151+
open3d::pipelines::registration::ComputeFPFHFeature(
152+
*targetO3D,
153+
open3d::geometry::KDTreeSearchParamHybrid(absoluteRadiusKDTreeSearch, maxNeighborKDTreeSearch));
154+
119155
std::vector<std::reference_wrapper<const open3d::pipelines::registration::CorrespondenceChecker>> correspondanceChecker;
120-
open3d::pipelines::registration::CorrespondenceCheckerBasedOnDistance checkerOnDistance = open3d::pipelines::registration::CorrespondenceCheckerBasedOnDistance(correspondenceCheckerDistance);
121-
open3d::pipelines::registration::CorrespondenceCheckerBasedOnEdgeLength checkerOnEdgeLength = open3d::pipelines::registration::CorrespondenceCheckerBasedOnEdgeLength(similarityThreshold);
156+
157+
open3d::pipelines::registration::CorrespondenceCheckerBasedOnDistance checkerOnDistance =
158+
open3d::pipelines::registration::CorrespondenceCheckerBasedOnDistance(absoluteCorrespodenceCheckerDistance);
159+
160+
open3d::pipelines::registration::CorrespondenceCheckerBasedOnEdgeLength checkerOnEdgeLength =
161+
open3d::pipelines::registration::CorrespondenceCheckerBasedOnEdgeLength(similarityThreshold);
122162
correspondanceChecker.push_back(checkerOnDistance);
123163

124-
auto result = open3d::pipelines::registration::RegistrationRANSACBasedOnFeatureMatching(*sourceO3D,
164+
165+
auto result = open3d::pipelines::registration::RegistrationRANSACBasedOnFeatureMatching(
166+
*sourceO3D,
125167
*targetO3D,
126168
*sourceFPFHFeatures,
127169
*targetFPFHFeatures,
128170
true,
129-
maxCorrespondenceDistance,
171+
absoluteMaxCorrespondenceDistance,
130172
transformationEstimation,
131173
ransacN,
132174
correspondanceChecker,

src/diffCheck/registrations/DFGlobalRegistrations.hh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ namespace diffCheck::registrations
2020
*
2121
* @param source the source diffCheck point cloud
2222
* @param target the target diffCheck point cloud
23-
* @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).
24-
* @param radiusKDTreeSearch the radius used to search for neighbors in the KDTree. It is used for the calculation of FPFHFeatures. A higher value will result in heavier computation but potentially more precise.
23+
* @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).
24+
* @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
2525
* @param maxNeighborKDTreeSearch the maximum number of neighbors to search for in the KDTree. It is used for the calculation of FPFHFeatures. A higher value will result in heavier computation but potentially more precise.
2626
* @param maxCorrespondenceDistance the maximum distance between correspondences. A higher value will result in more correspondences, but potentially include wrong ones.
2727
* @param iterationNumber the number of iterations to run the RanSaC registration algorithm. A higher value will take more time to compute but increases the chances of finding a good transformation. As parameter of the FastGlobalRegistrationOption options
@@ -37,11 +37,11 @@ namespace diffCheck::registrations
3737
std::shared_ptr<geometry::DFPointCloud> source,
3838
std::shared_ptr<geometry::DFPointCloud> target,
3939
bool voxelize = true,
40-
double voxelSize = 0.01,
41-
double radiusKDTreeSearch = 0.05,
42-
int maxNeighborKDTreeSearch = 20,
43-
double maxCorrespondenceDistance = 10,
44-
int iterationNumber = 64,
40+
double voxelSize = 0.005,
41+
double radiusKDTreeSearch = 0.1,
42+
int maxNeighborKDTreeSearch = 50,
43+
double maxCorrespondenceDistance = 0.05,
44+
int iterationNumber = 128,
4545
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
@@ -54,10 +54,10 @@ namespace diffCheck::registrations
5454
* @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).
5555
* @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
57-
* @param maxCorrespondenceDistance the maximum distance between correspondences in the FPFH space. A higher value will result in more correspondences, but potentially include wrong ones.
57+
* @param maxCorrespondenceDistance the maximum distance between correspondences in the FPFH space. A higher value will result in more correspondences, but potentially include wrong ones. It is exprimed in relative values (it is scaled by the size of the bounding box of the poinnt cloud).
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. It is exprimed in relative values (it is scaled by the size of the bounding box of the poinnt cloud).
6161
* @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.
6262
* @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.
6363
* @param ransacConfidenceThreshold the threshold for the convergence criteria of the ransac models. A higher value will be stricter, discarding more ransac models.
@@ -69,14 +69,14 @@ namespace diffCheck::registrations
6969
std::shared_ptr<geometry::DFPointCloud> source,
7070
std::shared_ptr<geometry::DFPointCloud> target,
7171
bool voxelize = true,
72-
double voxelSize = 0.01,
73-
double radiusKDTreeSearch = 0.05,
72+
double voxelSize = 0.005,
73+
double radiusKDTreeSearch = 0.1,
7474
int maxNeighborKDTreeSearch = 50,
7575
double maxCorrespondenceDistance = 0.05,
7676
bool isTEstimatePt2Pt = false,
7777
int ransacN = 3,
7878
double correspondenceCheckerDistance = 0.05,
79-
double similarityThreshold = 0.95,
79+
double similarityThreshold = 0.9,
8080
int ransacMaxIteration = 100000,
8181
double ransacConfidenceThreshold = 0.999);
8282

0 commit comments

Comments
 (0)