Skip to content

Commit 864f445

Browse files
committed
FIX: absolute to relative in cpp
1 parent e0fcce4 commit 864f445

File tree

8 files changed

+69
-101
lines changed

8 files changed

+69
-101
lines changed

src/diffCheck/registrations/DFGlobalRegistrations.cc

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,8 @@ namespace diffCheck::registrations
4040
// voxelize at the scale of the point cloud
4141
if (voxelise)
4242
{
43-
double absoluteVoxelSize =
44-
voxelSize * std::abs(sourceO3D->GetMaxBound().norm() - sourceO3D->GetMinBound().norm());
45-
46-
sourceO3D->VoxelDownSample(absoluteVoxelSize);
47-
targetO3D->VoxelDownSample(absoluteVoxelSize);
43+
sourceO3D->VoxelDownSample(voxelSize);
44+
targetO3D->VoxelDownSample(voxelSize);
4845
}
4946

5047
if (sourceO3D->normals_.size() == 0)
@@ -57,18 +54,15 @@ namespace diffCheck::registrations
5754
targetO3D->EstimateNormals();
5855
}
5956

60-
double absoluteRadiusKDTreeSearch =
61-
radiusKDTreeSearch * std::abs(sourceO3D->GetMaxBound().norm() - sourceO3D->GetMinBound().norm());
62-
6357
std::shared_ptr<open3d::pipelines::registration::Feature> sourceFPFHFeatures =
6458
open3d::pipelines::registration::ComputeFPFHFeature(
6559
*sourceO3D,
66-
open3d::geometry::KDTreeSearchParamHybrid(absoluteRadiusKDTreeSearch, maxNeighborKDTreeSearch));
60+
open3d::geometry::KDTreeSearchParamHybrid(radiusKDTreeSearch, maxNeighborKDTreeSearch));
6761

6862
std::shared_ptr<open3d::pipelines::registration::Feature> targetFPFHFeatures =
6963
open3d::pipelines::registration::ComputeFPFHFeature(
7064
*targetO3D,
71-
open3d::geometry::KDTreeSearchParamHybrid(absoluteRadiusKDTreeSearch, maxNeighborKDTreeSearch));
65+
open3d::geometry::KDTreeSearchParamHybrid(radiusKDTreeSearch, maxNeighborKDTreeSearch));
7266

7367
std::shared_ptr<open3d::pipelines::registration::FastGlobalRegistrationOption> option =
7468
std::make_shared<open3d::pipelines::registration::FastGlobalRegistrationOption>();
@@ -115,11 +109,8 @@ namespace diffCheck::registrations
115109
// voxelize at the scale of the point cloud
116110
if (voxelise)
117111
{
118-
double absoluteVoxelSize =
119-
voxelSize * std::abs(sourceO3D->GetMaxBound().norm() - sourceO3D->GetMinBound().norm());
120-
121-
sourceO3D->VoxelDownSample(absoluteVoxelSize);
122-
targetO3D->VoxelDownSample(absoluteVoxelSize);
112+
sourceO3D->VoxelDownSample(voxelSize);
113+
targetO3D->VoxelDownSample(voxelSize);
123114
}
124115

125116
if (sourceO3D->normals_.size() == 0)
@@ -132,30 +123,20 @@ namespace diffCheck::registrations
132123
targetO3D->EstimateNormals();
133124
}
134125

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-
145126
std::shared_ptr<open3d::pipelines::registration::Feature> sourceFPFHFeatures =
146127
open3d::pipelines::registration::ComputeFPFHFeature(
147128
*sourceO3D,
148-
open3d::geometry::KDTreeSearchParamHybrid(absoluteRadiusKDTreeSearch, maxNeighborKDTreeSearch));
129+
open3d::geometry::KDTreeSearchParamHybrid(radiusKDTreeSearch, maxNeighborKDTreeSearch));
149130

150131
std::shared_ptr<open3d::pipelines::registration::Feature> targetFPFHFeatures =
151132
open3d::pipelines::registration::ComputeFPFHFeature(
152133
*targetO3D,
153-
open3d::geometry::KDTreeSearchParamHybrid(absoluteRadiusKDTreeSearch, maxNeighborKDTreeSearch));
134+
open3d::geometry::KDTreeSearchParamHybrid(radiusKDTreeSearch, maxNeighborKDTreeSearch));
154135

155136
std::vector<std::reference_wrapper<const open3d::pipelines::registration::CorrespondenceChecker>> correspondanceChecker;
156137

157138
open3d::pipelines::registration::CorrespondenceCheckerBasedOnDistance checkerOnDistance =
158-
open3d::pipelines::registration::CorrespondenceCheckerBasedOnDistance(absoluteCorrespodenceCheckerDistance);
139+
open3d::pipelines::registration::CorrespondenceCheckerBasedOnDistance(correspondenceCheckerDistance);
159140

160141
open3d::pipelines::registration::CorrespondenceCheckerBasedOnEdgeLength checkerOnEdgeLength =
161142
open3d::pipelines::registration::CorrespondenceCheckerBasedOnEdgeLength(similarityThreshold);
@@ -168,7 +149,7 @@ namespace diffCheck::registrations
168149
*sourceFPFHFeatures,
169150
*targetFPFHFeatures,
170151
true,
171-
absoluteMaxCorrespondenceDistance,
152+
maxCorrespondenceDistance,
172153
transformationEstimation,
173154
ransacN,
174155
correspondanceChecker,

src/diffCheck/registrations/DFGlobalRegistrations.hh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ namespace diffCheck::registrations
3737
static diffCheck::transformation::DFTransformation O3DFastGlobalRegistrationFeatureMatching(
3838
std::shared_ptr<geometry::DFPointCloud> source,
3939
std::shared_ptr<geometry::DFPointCloud> target,
40-
bool voxelize = true,
40+
bool voxelize = false,
4141
double voxelSize = 0.005,
42-
double radiusKDTreeSearch = 0.1,
42+
double radiusKDTreeSearch = 0.8,
4343
int maxNeighborKDTreeSearch = 50,
4444
double maxCorrespondenceDistance = 0.05,
4545
int iterationNumber = 128,
@@ -69,9 +69,9 @@ namespace diffCheck::registrations
6969
static diffCheck::transformation::DFTransformation O3DRansacOnFeatureMatching(
7070
std::shared_ptr<geometry::DFPointCloud> source,
7171
std::shared_ptr<geometry::DFPointCloud> target,
72-
bool voxelize = true,
72+
bool voxelize = false,
7373
double voxelSize = 0.005,
74-
double radiusKDTreeSearch = 0.1,
74+
double radiusKDTreeSearch = 0.8,
7575
int maxNeighborKDTreeSearch = 50,
7676
double maxCorrespondenceDistance = 0.05,
7777
bool isTEstimatePt2Pt = false,

src/diffCheck/registrations/DFRefinedRegistration.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ namespace diffCheck::registrations
1414
bool usePointToPlane)
1515
{
1616
std::vector<Eigen::Vector3d> minMax = source->ComputeBoundingBox();
17-
double scale = (minMax[1] - minMax[0]).norm();
18-
double absoluteMaxCorrespondenceDistance = maxCorrespondenceDistance * scale;
1917

2018
std::shared_ptr<open3d::geometry::PointCloud> O3Dsource = source->Cvt2O3DPointCloud();
2119
std::shared_ptr<open3d::geometry::PointCloud> O3Dtarget = target->Cvt2O3DPointCloud();
@@ -37,7 +35,7 @@ namespace diffCheck::registrations
3735
result = open3d::pipelines::registration::RegistrationICP(
3836
*O3Dsource,
3937
*O3Dtarget,
40-
absoluteMaxCorrespondenceDistance,
38+
maxCorrespondenceDistance,
4139
initialTransformation,
4240
transformation_estimation,
4341
criteria);
@@ -49,7 +47,7 @@ namespace diffCheck::registrations
4947
result = open3d::pipelines::registration::RegistrationICP(
5048
*O3Dsource,
5149
*O3Dtarget,
52-
absoluteMaxCorrespondenceDistance,
50+
maxCorrespondenceDistance,
5351
initialTransformation,
5452
transformation_estimation,
5553
criteria);
@@ -68,8 +66,6 @@ namespace diffCheck::registrations
6866
double relativeRMSE)
6967
{
7068
std::vector<Eigen::Vector3d> minMax = source->ComputeBoundingBox();
71-
double scale = (minMax[1] - minMax[0]).norm();
72-
double absoluteMaxCorrespondenceDistance = maxCorrespondenceDistance * scale;
7369

7470
std::shared_ptr<open3d::geometry::PointCloud> O3Dsource = source->Cvt2O3DPointCloud();
7571
std::shared_ptr<open3d::geometry::PointCloud> O3Dtarget = target->Cvt2O3DPointCloud();
@@ -91,7 +87,7 @@ namespace diffCheck::registrations
9187
= open3d::pipelines::registration::RegistrationGeneralizedICP(
9288
*O3Dsource,
9389
*O3Dtarget,
94-
absoluteMaxCorrespondenceDistance,
90+
maxCorrespondenceDistance,
9591
initialTransformation,
9692
transformation_estimation,
9793
criteria);

src/diffCheck/transformation/DFTransformation.hh

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,11 @@ namespace diffCheck::transformation
1010
DFTransformation(const Eigen::Matrix4d& transformationMatrix)
1111
: TransformationMatrix(transformationMatrix)
1212
{}
13-
DFTransformation(const Eigen::Matrix3d& rotationMatrix, const Eigen::Vector3d& translationVector)
14-
: RotationMatrix(rotationMatrix), TranslationVector(translationVector)
15-
{}
1613

1714
public:
1815
/**
1916
* @brief 4x4 Transformation matrix for point clouds
2017
*/
2118
Eigen::Matrix4d TransformationMatrix;
22-
23-
/**
24-
* @brief 3x3 Rotation matrix for point clouds
25-
*/
26-
Eigen::Matrix3d RotationMatrix;
27-
28-
/**
29-
* @brief 3x1 Translation vector for point clouds
30-
*/
31-
Eigen::Vector3d TranslationVector;
3219
};
3320
}

src/diffCheckBindings.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,8 @@ PYBIND11_MODULE(diffcheck_bindings, m) {
9191
py::class_<diffCheck::transformation::DFTransformation>(submodule_transformation, "DFTransformation")
9292
.def(py::init<>())
9393
.def(py::init<const Eigen::Matrix4d&>())
94-
.def(py::init<const Eigen::Matrix3d&, const Eigen::Vector3d&>())
9594

96-
.def_readwrite("transformation_matrix", &diffCheck::transformation::DFTransformation::TransformationMatrix)
97-
.def_readwrite("rotation_matrix", &diffCheck::transformation::DFTransformation::RotationMatrix)
98-
.def_readwrite("translation_vector", &diffCheck::transformation::DFTransformation::TranslationVector);
99-
95+
.def_readwrite("transformation_matrix", &diffCheck::transformation::DFTransformation::TransformationMatrix);
10096

10197
//#################################################################################################
10298
// dfb_registrations namespace

src/gh/components/DF_global_registration/code.py

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,69 +17,77 @@
1717

1818
class DFGlobalRegistration(component):
1919
def RunScript(self,
20-
i_cloud_source: rg.PointCloud = None,
21-
i_cloud_target: rg.PointCloud = None
20+
i_cloud_source: rg.PointCloud,
21+
i_cloud_target: rg.PointCloud,
22+
i_radius_kd_search: float,
23+
i_neighbours_kd_search: int,
24+
i_max_corrspondence_dist: float,
25+
i_iteration_number: int,
26+
i_max_tuple_count: int
2227
) -> rg.Transform:
2328
"""
2429
The global registration component aligns two point clouds in a rough way.
2530
2631
:param i_cloud_source: source point cloud
2732
:param i_cloud_target: target point cloud to align to
33+
:param i_radius_kd_search: radius for the kd search
34+
:param i_neighbours_kd_search: number of neighbours to consider
35+
:param i_max_corrspondence_dist: maximum correspondence distance
36+
:param i_iteration_number: number of iterations
37+
:param i_max_tuple_count: maximum tuple count
2838
2939
:return o_x_form : transformation matrix
3040
"""
41+
# set default values
42+
if i_radius_kd_search is None: i_radius_kd_search = 0.8
43+
if i_neighbours_kd_search is None: i_neighbours_kd_search = 50
44+
if i_max_corrspondence_dist is None: i_max_corrspondence_dist = 0.05
45+
if i_iteration_number is None: i_iteration_number = 128
46+
if i_max_tuple_count is None: i_max_tuple_count = 1000
3147

32-
# if i_cloud_source is None or i_cloud_target is None:
33-
# ghenv.Component.AddRuntimeMessage(RML.Error, "Please provide two point clouds to align")
34-
# return o_x_form
35-
36-
print(type(i_cloud_source))
48+
if i_cloud_source is None or i_cloud_target is None:
49+
ghenv.Component.AddRuntimeMessage(RML.Warning, "Please provide both objects of type point clouds to align")
50+
return None
3751

3852
df_cloud_source = df_cvt_bindings.cvt_rhcloud_2_dfcloud(i_cloud_source)
3953
df_cloud_target = df_cvt_bindings.cvt_rhcloud_2_dfcloud(i_cloud_target)
4054

41-
print(type(df_cloud_source))
42-
# # print all the available registration methods
43-
# print(dir(diffcheck_bindings.dfb_registrations))
44-
# registrations = diffcheck_bindings.dfb_registrations.DFGlobalRegistrations()
45-
46-
47-
4855
df_xform = diffcheck_bindings.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(
4956
source=df_cloud_source,
5057
target=df_cloud_target,
51-
voxelize=True,
52-
voxel_size=0.1,
53-
radius_kd_tree_search=0.1,
54-
max_neighbor_kd_tree_search=50,
55-
max_correspondence_distance=0.05,
56-
iteration_number=128,
57-
max_tuple_count=1000
58+
voxelize=False, # set as default
59+
voxel_size=0.1, # set as default
60+
radius_kd_tree_search=i_radius_kd_search,
61+
max_neighbor_kd_tree_search=i_neighbours_kd_search,
62+
max_correspondence_distance=i_max_corrspondence_dist,
63+
iteration_number=i_iteration_number,
64+
max_tuple_count=i_max_tuple_count
5865
)
59-
print(type(df_xform))
60-
61-
print(df_xform.transformation_matrix)
6266
print("-------------------")
63-
print(df_xform.rotation_matrix)
67+
print("Estimated transformation matrix:")
68+
print(df_xform.transformation_matrix)
6469
print("-------------------")
65-
print(df_xform.translation_vector)
6670

71+
# cvt df xform to rhino xform
6772
df_xform_matrix = df_xform.transformation_matrix
68-
69-
7073
rh_form = rg.Transform()
7174
for i in range(4):
7275
for j in range(4):
7376
rh_form[i, j] = df_xform_matrix[i, j]
7477

75-
print(rh_form)
76-
7778
o_x_form = rh_form
7879

79-
8080
return o_x_form
8181

8282

8383
if __name__ == "__main__":
8484
com = DFGlobalRegistration()
85-
o_x_form = com.RunScript(i_cloud_source, i_cloud_target)
85+
o_x_form = com.RunScript(
86+
i_cloud_source,
87+
i_cloud_target,
88+
i_radius_kd_search,
89+
i_neighbours_kd_search,
90+
i_max_corrspondence_dist,
91+
i_iteration_number,
92+
i_max_tuple_count
93+
)
-5.06 KB
Loading

src/gh/components/DF_global_registration/metadata.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,35 @@
1414
"iconDisplay": 2,
1515
"inputParameters": [
1616
{
17-
"name": "i_mesh",
18-
"nickname": "i_mesh",
19-
"description": "Mesh to sample into a point cloud.",
17+
"name": "i_cloud_source",
18+
"nickname": "i_cloud_source",
19+
"description": "The source point cloud.",
2020
"optional": true,
2121
"allowTreeAccess": true,
2222
"showTypeHints": true,
2323
"scriptParamAccess": "item",
2424
"wireDisplay": "default",
2525
"sourceCount": 0,
26-
"typeHintID": "mesh"
26+
"typeHintID": "pointcloud"
2727
},
2828
{
29-
"name": "i_points",
30-
"nickname": "i_points",
31-
"description": "The number of points of the created cloud.",
29+
"name": "i_cloud_target",
30+
"nickname": "i_cloud_target",
31+
"description": "The target cloud.",
3232
"optional": false,
3333
"allowTreeAccess": true,
3434
"showTypeHints": true,
3535
"scriptParamAccess": "item",
3636
"wireDisplay": "default",
3737
"sourceCount": 0,
38-
"typeHintID": "int"
38+
"typeHintID": "pointcloud"
3939
}
4040
],
4141
"outputParameters": [
4242
{
43-
"name": "o_rh_cloud",
44-
"nickname": "o_rh_cloud",
45-
"description": "The output sampled cloud.",
43+
"name": "o_x_form",
44+
"nickname": "o_x_form",
45+
"description": "The computed transformation.",
4646
"optional": false,
4747
"sourceCount": 0,
4848
"graft": false

0 commit comments

Comments
 (0)