From 44ffdaab5bccdf51f45079a3278c8cd8f65bc119 Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 6 Aug 2024 09:49:17 +0200 Subject: [PATCH 01/26] ADD: stanford bunny pointcloud for registration test suite --- tests/test_data/stanford_bunny_50kpts_with_normals.ply | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/test_data/stanford_bunny_50kpts_with_normals.ply diff --git a/tests/test_data/stanford_bunny_50kpts_with_normals.ply b/tests/test_data/stanford_bunny_50kpts_with_normals.ply new file mode 100644 index 00000000..5dc2156d --- /dev/null +++ b/tests/test_data/stanford_bunny_50kpts_with_normals.ply @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c5af80113153bfc7e52ba6d0966a020f4a0b96ef4021b2704ebdbedbef40994a +size 1195348 From 63ab712c3905208a87683bb27fd9162287e1e20b Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 6 Aug 2024 11:48:11 +0200 Subject: [PATCH 02/26] WIP-CI: test x 1 --- .../pybinds_tests/test_pybind_units.py | 31 +++++++++++++++++-- tests/test_data/sphere_5kpts_with_normals.ply | 3 ++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tests/test_data/sphere_5kpts_with_normals.ply diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index 4b518d02..3f1ac502 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -27,6 +27,13 @@ def get_ply_cloud_roof_quarter_path(): raise FileNotFoundError(f"PLY file not found at: {ply_file_path}") return ply_file_path +def get_ply_cloud_sphere_path(): + base_test_data_dir = os.getenv('DF_TEST_DATA_DIR', os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'test_data'))) + ply_file_path = os.path.join(base_test_data_dir, "sphere_5kpts_with_normals.ply") + if not os.path.exists(ply_file_path): + raise FileNotFoundError(f"PLY file not found at: {ply_file_path}") + return ply_file_path + #------------------------------------------------------------------------------ # dfb_geometry namespace #------------------------------------------------------------------------------ @@ -54,6 +61,12 @@ def create_DFPointCloudSampleRoof(): df_pcd.load_from_PLY(get_ply_cloud_roof_quarter_path()) yield df_pcd +@pytest.fixture +def create_DFPointCloudSphere(): + df_pcd = dfb.dfb_geometry.DFPointCloud() + df_pcd.load_from_PLY(get_ply_cloud_sphere_path()) + yield df_pcd + def test_DFPointCloud_properties(create_DFPointCloudSampleRoof): pc = create_DFPointCloudSampleRoof assert pc.points.__len__() == 7379, "DFPointCloud should have 7379 points" @@ -134,8 +147,22 @@ def test_DFTransform_read_write(create_DFPointCloudSampleRoof): #------------------------------------------------------------------------------ # dfb_registrations namespace #------------------------------------------------------------------------------ -# TODO: to be implemented - +def test_DFRegistration_pure_translation(create_DFPointCloudSphere): + pc = create_DFPointCloudSphere + pc2 = create_DFPointCloudSphere + t = dfb.dfb_transformation.DFTransformation() + t.transformation_matrix = [[1.0, 0.0, 0.0, 20], + [0.0, 1.0, 0.0, 20], + [0.0, 0.0, 1.0, 20], + [0.0, 0.0, 0.0, 1.0]] + pc2.transform(t) + + df_transformation_result = dfb.dfb_registrations.O3DFastGlobalRegistrationFeatureMatching(pc, pc2, 0.01, 100) + assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" + assert abs(df_transformation_result[0][3] - 20) > 0.5, "The translation in x should be around 20" + assert abs(df_transformation_result[1][3] - 20) > 0.5, "The translation in y should be around 20" + assert abs(df_transformation_result[2][3] - 20) > 0.5, "The translation in z should be around 20" + #------------------------------------------------------------------------------ # dfb_segmentation namespace #------------------------------------------------------------------------------ diff --git a/tests/test_data/sphere_5kpts_with_normals.ply b/tests/test_data/sphere_5kpts_with_normals.ply new file mode 100644 index 00000000..57659d60 --- /dev/null +++ b/tests/test_data/sphere_5kpts_with_normals.ply @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0374e977d8f8a23e99eb19682d1429a572b8a1f4db297d06afe8aeafdf389db9 +size 120891 From 86d78019f99e16aac565a4bf78c2f8ec52060247 Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 6 Aug 2024 12:06:20 +0200 Subject: [PATCH 03/26] WIP-CI: test x 2 --- .../pybinds_tests/test_pybind_units.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index 3f1ac502..bf2252b6 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -155,14 +155,14 @@ def test_DFRegistration_pure_translation(create_DFPointCloudSphere): [0.0, 1.0, 0.0, 20], [0.0, 0.0, 1.0, 20], [0.0, 0.0, 0.0, 1.0]] - pc2.transform(t) + pc2.apply_transformation(t) df_transformation_result = dfb.dfb_registrations.O3DFastGlobalRegistrationFeatureMatching(pc, pc2, 0.01, 100) assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" - assert abs(df_transformation_result[0][3] - 20) > 0.5, "The translation in x should be around 20" - assert abs(df_transformation_result[1][3] - 20) > 0.5, "The translation in y should be around 20" - assert abs(df_transformation_result[2][3] - 20) > 0.5, "The translation in z should be around 20" - + assert abs(df_transformation_result.transformation_matrix[0][3] - 20) > 0.5, "The translation in x should be around 20" + assert abs(df_transformation_result.transformation_matrix[1][3] - 20) > 0.5, "The translation in y should be around 20" + assert abs(df_transformation_result.transformation_matrix[2][3] - 20) > 0.5, "The translation in z should be around 20" + #------------------------------------------------------------------------------ # dfb_segmentation namespace #------------------------------------------------------------------------------ From 1d7f162d17a1dce4d91cbb07c3d6ea3dd92ef00b Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 6 Aug 2024 12:14:36 +0200 Subject: [PATCH 04/26] FIX-UPDATE: apply_transformation method binding added --- src/diffCheckBindings.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/diffCheckBindings.cc b/src/diffCheckBindings.cc index 9b7d2af0..20e9a84b 100644 --- a/src/diffCheckBindings.cc +++ b/src/diffCheckBindings.cc @@ -40,6 +40,9 @@ PYBIND11_MODULE(diffcheck_bindings, m) { .def("downsample_by_size", &diffCheck::geometry::DFPointCloud::DownsampleBySize, py::arg("target_size")) + .def("apply_transformation", &diffCheck::geometry::DFPointCloud::ApplyTransformation, + py::arg("transformation")) + .def("estimate_normals", &diffCheck::geometry::DFPointCloud::EstimateNormals, py::arg("use_cilantro_evaluator") = false, py::arg("knn") = 100, From a33d297abbe635d087c92daedf986f0de7195ad1 Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 6 Aug 2024 12:23:57 +0200 Subject: [PATCH 05/26] WIP-CI: test x 3 --- tests/integration_tests/pybinds_tests/test_pybind_units.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index bf2252b6..d6630e1d 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -157,7 +157,7 @@ def test_DFRegistration_pure_translation(create_DFPointCloudSphere): [0.0, 0.0, 0.0, 1.0]] pc2.apply_transformation(t) - df_transformation_result = dfb.dfb_registrations.O3DFastGlobalRegistrationFeatureMatching(pc, pc2, 0.01, 100) + df_transformation_result = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(pc, pc2) assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" assert abs(df_transformation_result.transformation_matrix[0][3] - 20) > 0.5, "The translation in x should be around 20" assert abs(df_transformation_result.transformation_matrix[1][3] - 20) > 0.5, "The translation in y should be around 20" From 59f325e5448f61091178f90de721ab102b2334ac Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 6 Aug 2024 14:02:47 +0200 Subject: [PATCH 06/26] WIP-CI: test x 4 --- .../pybinds_tests/test_pybind_units.py | 108 ++++++++++++++++-- 1 file changed, 99 insertions(+), 9 deletions(-) diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index d6630e1d..d521f74a 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -34,6 +34,13 @@ def get_ply_cloud_sphere_path(): raise FileNotFoundError(f"PLY file not found at: {ply_file_path}") return ply_file_path +def get_ply_cloud_bunny_path(): + base_test_data_dir = os.getenv('DF_TEST_DATA_DIR', os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'test_data'))) + ply_file_path = os.path.join(base_test_data_dir, "stanford_bunny_50kpts_with_normals.ply") + if not os.path.exists(ply_file_path): + raise FileNotFoundError(f"PLY file not found at: {ply_file_path}") + return ply_file_path + #------------------------------------------------------------------------------ # dfb_geometry namespace #------------------------------------------------------------------------------ @@ -67,6 +74,12 @@ def create_DFPointCloudSphere(): df_pcd.load_from_PLY(get_ply_cloud_sphere_path()) yield df_pcd +@pytest.fixture +def create_DFPointCloudBunny(): + df_pcd = dfb.dfb_geometry.DFPointCloud() + df_pcd.load_from_PLY(get_ply_cloud_bunny_path()) + yield df_pcd + def test_DFPointCloud_properties(create_DFPointCloudSampleRoof): pc = create_DFPointCloudSampleRoof assert pc.points.__len__() == 7379, "DFPointCloud should have 7379 points" @@ -148,26 +161,103 @@ def test_DFTransform_read_write(create_DFPointCloudSampleRoof): # dfb_registrations namespace #------------------------------------------------------------------------------ def test_DFRegistration_pure_translation(create_DFPointCloudSphere): - pc = create_DFPointCloudSphere - pc2 = create_DFPointCloudSphere + + def make_assertions(df_transformation_result): + assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" + assert abs(df_transformation_result.transformation_matrix[0][3] - 20) > 0.5, "The translation in x should be around 20" + assert abs(df_transformation_result.transformation_matrix[1][3] - 20) > 0.5, "The translation in y should be around 20" + assert abs(df_transformation_result.transformation_matrix[2][3] - 20) > 0.5, "The translation in z should be around 20" + + pc_1 = create_DFPointCloudSphere + pc_2 = create_DFPointCloudSphere t = dfb.dfb_transformation.DFTransformation() t.transformation_matrix = [[1.0, 0.0, 0.0, 20], [0.0, 1.0, 0.0, 20], [0.0, 0.0, 1.0, 20], [0.0, 0.0, 0.0, 1.0]] - pc2.apply_transformation(t) + pc_2.apply_transformation(t) - df_transformation_result = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(pc, pc2) - assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" - assert abs(df_transformation_result.transformation_matrix[0][3] - 20) > 0.5, "The translation in x should be around 20" - assert abs(df_transformation_result.transformation_matrix[1][3] - 20) > 0.5, "The translation in y should be around 20" - assert abs(df_transformation_result.transformation_matrix[2][3] - 20) > 0.5, "The translation in z should be around 20" + df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(pc_1, pc_2) + df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(pc_1, pc_2) + df_transformation_result_o3dicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DDICP(pc_1, pc_2) + df_transformation_result_o3dgicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DGeneralizedICP(pc_1, pc_2) + make_assertions(df_transformation_result_o3dfgrfm) + make_assertions(df_transformation_result_o3drfm) + make_assertions(df_transformation_result_o3dicp) + make_assertions(df_transformation_result_o3dgicp) + +def test_DFRegistration_pure_rotation(): + + def make_assertions(df_transformation_result): + assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" + assert df_transformation_result.transformation_matrix[0][2] < -0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied " + assert df_transformation_result.transformation_matrix[1][1] > 0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + assert df_transformation_result.transformation_matrix[2][0] > 0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + + vertices = [[-1, -1, 0], [1, -1, 0], [1, 1, 0], [-1, 1, 0]] + faces = [[0, 1, 2], [0, 2, 3]] + mesh = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], []) + mesh2 = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], []) + + r = dfb.dfb_transformation.DFTransformation() + r.transformation_matrix = [[0.0, 0.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0], + [-1.0, 0.0, 1.0, 0.0], + [0.0, 0.0, 0.0, 1.0]] # 90 degree rotation around y-axis + + mesh2.apply_transformation(r) + + pc_1 = mesh.sample_points_uniformly(1000) + pc_2 = mesh2.sample_points_uniformly(1000) + + df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(pc_1, pc_2) + df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(pc_1, pc_2) + df_transformation_result_o3dicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DDICP(pc_1, pc_2) + df_transformation_result_o3dgicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DGeneralizedICP(pc_1, pc_2) + make_assertions(df_transformation_result_o3dfgrfm) + make_assertions(df_transformation_result_o3drfm) + make_assertions(df_transformation_result_o3dicp) + make_assertions(df_transformation_result_o3dgicp) + +def test_DFRegistration_bunny(create_DFPointCloudBunny): + + def make_assertions(df_transformation_result): + assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" + assert abs(df_transformation_result.transformation_matrix[0][3] - 0.1) < 0.02, "The translation in x should be around 0.1" + assert abs(df_transformation_result.transformation_matrix[1][3] - 0.2) < 0.02, "The translation in y should be around 0.2" + assert abs(df_transformation_result.transformation_matrix[2][3] + 0.1) < 0.02, "The translation in z should be around -0.1" + assert df_transformation_result.transformation_matrix[0][0] > 0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + assert df_transformation_result.transformation_matrix[1][2] > 0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied " + assert df_transformation_result.transformation_matrix[2][1] < -0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied"$ + + pc_1 = create_DFPointCloudBunny + pc_2 = create_DFPointCloudBunny + + transform = dfb.dfb_transformation.DFTransformation() + transform.transformation_matrix = [[1.0, 0.0, 0.0, 0.1], + [0.0, 0.0, -1.0, 0.2], + [0.0, 1.0, 0.0, -0.1], + [0.0, 0.0, 0.0, 1.0]] + pc_2.apply_transformation(transform) + + df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(pc_1, pc_2) + df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(pc_1, pc_2) + df_transformation_result_o3dicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DDICP(pc_1, pc_2) + df_transformation_result_o3dgicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DGeneralizedICP(pc_1, pc_2) + make_assertions(df_transformation_result_o3dfgrfm) + make_assertions(df_transformation_result_o3drfm) + make_assertions(df_transformation_result_o3dicp) + make_assertions(df_transformation_result_o3dgicp) + + #------------------------------------------------------------------------------ # dfb_segmentation namespace #------------------------------------------------------------------------------ -# TODO: to be implemented + # vertices = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 1, -1], [0, 0, -1]] + # faces = [[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5]] + # mesh = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], []) if __name__ == "__main__": pytest.main() \ No newline at end of file From 380d784665c9cdd70916d6d9d3b4b62414c5bead Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 6 Aug 2024 14:11:06 +0200 Subject: [PATCH 07/26] FIX: typo $ in code --- tests/integration_tests/pybinds_tests/test_pybind_units.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index d521f74a..b6306674 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -229,8 +229,8 @@ def make_assertions(df_transformation_result): assert abs(df_transformation_result.transformation_matrix[2][3] + 0.1) < 0.02, "The translation in z should be around -0.1" assert df_transformation_result.transformation_matrix[0][0] > 0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" assert df_transformation_result.transformation_matrix[1][2] > 0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied " - assert df_transformation_result.transformation_matrix[2][1] < -0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied"$ - + assert df_transformation_result.transformation_matrix[2][1] < -0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + pc_1 = create_DFPointCloudBunny pc_2 = create_DFPointCloudBunny From 52e6e8b83261766c49b20d87f987f104b766da00 Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 6 Aug 2024 14:20:50 +0200 Subject: [PATCH 08/26] FIX: several typos in code --- .../pybinds_tests/test_pybind_units.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index b6306674..66943d7f 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -179,7 +179,7 @@ def make_assertions(df_transformation_result): df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(pc_1, pc_2) df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(pc_1, pc_2) - df_transformation_result_o3dicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DDICP(pc_1, pc_2) + df_transformation_result_o3dicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DICP(pc_1, pc_2) df_transformation_result_o3dgicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DGeneralizedICP(pc_1, pc_2) make_assertions(df_transformation_result_o3dfgrfm) make_assertions(df_transformation_result_o3drfm) @@ -205,15 +205,15 @@ def make_assertions(df_transformation_result): [0.0, 1.0, 0.0, 0.0], [-1.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]] # 90 degree rotation around y-axis - - mesh2.apply_transformation(r) pc_1 = mesh.sample_points_uniformly(1000) pc_2 = mesh2.sample_points_uniformly(1000) + pc_2.apply_transformation(r) + df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(pc_1, pc_2) df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(pc_1, pc_2) - df_transformation_result_o3dicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DDICP(pc_1, pc_2) + df_transformation_result_o3dicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DICP(pc_1, pc_2) df_transformation_result_o3dgicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DGeneralizedICP(pc_1, pc_2) make_assertions(df_transformation_result_o3dfgrfm) make_assertions(df_transformation_result_o3drfm) @@ -243,7 +243,7 @@ def make_assertions(df_transformation_result): df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(pc_1, pc_2) df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(pc_1, pc_2) - df_transformation_result_o3dicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DDICP(pc_1, pc_2) + df_transformation_result_o3dicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DICP(pc_1, pc_2) df_transformation_result_o3dgicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DGeneralizedICP(pc_1, pc_2) make_assertions(df_transformation_result_o3dfgrfm) make_assertions(df_transformation_result_o3drfm) From db9b9673ef72d41bc676ff6baafb78f61fbca176 Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 6 Aug 2024 14:37:05 +0200 Subject: [PATCH 09/26] FIX: ICP part of refined registration, not global --- .../pybinds_tests/test_pybind_units.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index 66943d7f..ea3fa3bc 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -179,8 +179,8 @@ def make_assertions(df_transformation_result): df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(pc_1, pc_2) df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(pc_1, pc_2) - df_transformation_result_o3dicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DICP(pc_1, pc_2) - df_transformation_result_o3dgicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DGeneralizedICP(pc_1, pc_2) + df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(pc_1, pc_2) + df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(pc_1, pc_2) make_assertions(df_transformation_result_o3dfgrfm) make_assertions(df_transformation_result_o3drfm) make_assertions(df_transformation_result_o3dicp) @@ -213,8 +213,8 @@ def make_assertions(df_transformation_result): df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(pc_1, pc_2) df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(pc_1, pc_2) - df_transformation_result_o3dicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DICP(pc_1, pc_2) - df_transformation_result_o3dgicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DGeneralizedICP(pc_1, pc_2) + df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(pc_1, pc_2) + df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(pc_1, pc_2) make_assertions(df_transformation_result_o3dfgrfm) make_assertions(df_transformation_result_o3drfm) make_assertions(df_transformation_result_o3dicp) @@ -243,8 +243,8 @@ def make_assertions(df_transformation_result): df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(pc_1, pc_2) df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(pc_1, pc_2) - df_transformation_result_o3dicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DICP(pc_1, pc_2) - df_transformation_result_o3dgicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DGeneralizedICP(pc_1, pc_2) + df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(pc_1, pc_2) + df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(pc_1, pc_2) make_assertions(df_transformation_result_o3dfgrfm) make_assertions(df_transformation_result_o3drfm) make_assertions(df_transformation_result_o3dicp) From 9ff439cf997d33e87029cae6bda6697e9997464b Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 6 Aug 2024 14:50:11 +0200 Subject: [PATCH 10/26] WIP-CI: test x 5 --- .../integration_tests/pybinds_tests/test_pybind_units.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index ea3fa3bc..ebd4beee 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -208,6 +208,8 @@ def make_assertions(df_transformation_result): pc_1 = mesh.sample_points_uniformly(1000) pc_2 = mesh2.sample_points_uniformly(1000) + pc_1.estimate_normals() + pc_2.estimate_normals() pc_2.apply_transformation(r) @@ -224,9 +226,9 @@ def test_DFRegistration_bunny(create_DFPointCloudBunny): def make_assertions(df_transformation_result): assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" - assert abs(df_transformation_result.transformation_matrix[0][3] - 0.1) < 0.02, "The translation in x should be around 0.1" - assert abs(df_transformation_result.transformation_matrix[1][3] - 0.2) < 0.02, "The translation in y should be around 0.2" - assert abs(df_transformation_result.transformation_matrix[2][3] + 0.1) < 0.02, "The translation in z should be around -0.1" + assert abs(df_transformation_result.transformation_matrix[0][3] + 0.1) < 0.02, "The translation in x should be around 0.1" + assert abs(df_transformation_result.transformation_matrix[1][3] + 0.2) < 0.02, "The translation in y should be around 0.2" + assert abs(df_transformation_result.transformation_matrix[2][3] - 0.1) < 0.02, "The translation in z should be around -0.1" assert df_transformation_result.transformation_matrix[0][0] > 0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" assert df_transformation_result.transformation_matrix[1][2] > 0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied " assert df_transformation_result.transformation_matrix[2][1] < -0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" From 1a488e71dd7539ee638946e53f60803adfef493c Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 6 Aug 2024 15:12:55 +0200 Subject: [PATCH 11/26] WIP-CI: test pure rotation case --- tests/integration_tests/pybinds_tests/test_pybind_units.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index ebd4beee..ab4bc7f5 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -191,7 +191,7 @@ def test_DFRegistration_pure_rotation(): def make_assertions(df_transformation_result): assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" - assert df_transformation_result.transformation_matrix[0][2] < -0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied " + assert df_transformation_result.transformation_matrix[0][2] < -0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" assert df_transformation_result.transformation_matrix[1][1] > 0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" assert df_transformation_result.transformation_matrix[2][0] > 0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" @@ -203,7 +203,7 @@ def make_assertions(df_transformation_result): r = dfb.dfb_transformation.DFTransformation() r.transformation_matrix = [[0.0, 0.0, 1.0, 0.0], [0.0, 1.0, 0.0, 0.0], - [-1.0, 0.0, 1.0, 0.0], + [-1.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.0]] # 90 degree rotation around y-axis pc_1 = mesh.sample_points_uniformly(1000) From 14d8cc7b72a24697c5f5cad31d4cdde70f3e930c Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 6 Aug 2024 15:39:31 +0200 Subject: [PATCH 12/26] WIP-CI: test x 6 --- .../pybinds_tests/test_pybind_units.py | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index ab4bc7f5..22f39321 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -191,20 +191,20 @@ def test_DFRegistration_pure_rotation(): def make_assertions(df_transformation_result): assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" - assert df_transformation_result.transformation_matrix[0][2] < -0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" - assert df_transformation_result.transformation_matrix[1][1] > 0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" - assert df_transformation_result.transformation_matrix[2][0] > 0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + assert abs(df_transformation_result.transformation_matrix[0][0] - 0.866) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + assert abs(df_transformation_result.transformation_matrix[0][1]) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + assert abs(df_transformation_result.transformation_matrix[0][2] + 0.5) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" - vertices = [[-1, -1, 0], [1, -1, 0], [1, 1, 0], [-1, 1, 0]] + vertices = [[-2, -1, 0], [2, -1, 0], [2, 1, 0], [-2, 1, 0]] faces = [[0, 1, 2], [0, 2, 3]] mesh = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], []) mesh2 = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], []) r = dfb.dfb_transformation.DFTransformation() - r.transformation_matrix = [[0.0, 0.0, 1.0, 0.0], + r.transformation_matrix = [[0.866, 0.0, 0.5, 0.0], [0.0, 1.0, 0.0, 0.0], - [-1.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 1.0]] # 90 degree rotation around y-axis + [-0.5, 0.0, 0.866, 0.0], + [0.0, 0.0, 0.0, 1.0]] # 30 degree rotation around y-axis pc_1 = mesh.sample_points_uniformly(1000) pc_2 = mesh2.sample_points_uniformly(1000) @@ -226,9 +226,9 @@ def test_DFRegistration_bunny(create_DFPointCloudBunny): def make_assertions(df_transformation_result): assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" - assert abs(df_transformation_result.transformation_matrix[0][3] + 0.1) < 0.02, "The translation in x should be around 0.1" - assert abs(df_transformation_result.transformation_matrix[1][3] + 0.2) < 0.02, "The translation in y should be around 0.2" - assert abs(df_transformation_result.transformation_matrix[2][3] - 0.1) < 0.02, "The translation in z should be around -0.1" + assert abs(df_transformation_result.transformation_matrix[0][3] + 0.05) < 0.02, "The translation in x should be around -0.05" + assert abs(df_transformation_result.transformation_matrix[1][3] + 0.05) < 0.02, "The translation in y should be around -0.05" + assert abs(df_transformation_result.transformation_matrix[2][3] - 0.05) < 0.02, "The translation in z should be around 0.05" assert df_transformation_result.transformation_matrix[0][0] > 0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" assert df_transformation_result.transformation_matrix[1][2] > 0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied " assert df_transformation_result.transformation_matrix[2][1] < -0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" @@ -237,9 +237,9 @@ def make_assertions(df_transformation_result): pc_2 = create_DFPointCloudBunny transform = dfb.dfb_transformation.DFTransformation() - transform.transformation_matrix = [[1.0, 0.0, 0.0, 0.1], - [0.0, 0.0, -1.0, 0.2], - [0.0, 1.0, 0.0, -0.1], + transform.transformation_matrix = [[1.0, 0.0, 0.0, 0.05], + [0.0, 0.0, -1.0, 0.05], + [0.0, 1.0, 0.0, -0.05], [0.0, 0.0, 0.0, 1.0]] pc_2.apply_transformation(transform) From 00412d97b280eb55f04c3a39a1804c9cafdcc89e Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 6 Aug 2024 15:54:57 +0200 Subject: [PATCH 13/26] WIP-CI: test x 7 --- .../pybinds_tests/test_pybind_units.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index 22f39321..55b6f9c2 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -191,9 +191,9 @@ def test_DFRegistration_pure_rotation(): def make_assertions(df_transformation_result): assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" - assert abs(df_transformation_result.transformation_matrix[0][0] - 0.866) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + assert abs(df_transformation_result.transformation_matrix[0][0] + 0.866) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" assert abs(df_transformation_result.transformation_matrix[0][1]) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" - assert abs(df_transformation_result.transformation_matrix[0][2] + 0.5) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + assert abs(df_transformation_result.transformation_matrix[0][2] - 0.5) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" vertices = [[-2, -1, 0], [2, -1, 0], [2, 1, 0], [-2, 1, 0]] faces = [[0, 1, 2], [0, 2, 3]] @@ -226,9 +226,9 @@ def test_DFRegistration_bunny(create_DFPointCloudBunny): def make_assertions(df_transformation_result): assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" - assert abs(df_transformation_result.transformation_matrix[0][3] + 0.05) < 0.02, "The translation in x should be around -0.05" - assert abs(df_transformation_result.transformation_matrix[1][3] + 0.05) < 0.02, "The translation in y should be around -0.05" - assert abs(df_transformation_result.transformation_matrix[2][3] - 0.05) < 0.02, "The translation in z should be around 0.05" + assert abs(df_transformation_result.transformation_matrix[0][3] - 0.05) < 0.02, "The translation in x should be around -0.05" + assert abs(df_transformation_result.transformation_matrix[1][3] - 0.05) < 0.02, "The translation in y should be around -0.05" + assert abs(df_transformation_result.transformation_matrix[2][3] + 0.05) < 0.02, "The translation in z should be around 0.05" assert df_transformation_result.transformation_matrix[0][0] > 0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" assert df_transformation_result.transformation_matrix[1][2] > 0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied " assert df_transformation_result.transformation_matrix[2][1] < -0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" From d11a0b2046acae79556ac63093e72acd0fa6feae Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 6 Aug 2024 16:13:52 +0200 Subject: [PATCH 14/26] WIP-CI: test x 8 --- .../pybinds_tests/test_pybind_units.py | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index 55b6f9c2..64425fe7 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -191,7 +191,7 @@ def test_DFRegistration_pure_rotation(): def make_assertions(df_transformation_result): assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" - assert abs(df_transformation_result.transformation_matrix[0][0] + 0.866) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + assert abs(df_transformation_result.transformation_matrix[0][0] - 0.866) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" assert abs(df_transformation_result.transformation_matrix[0][1]) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" assert abs(df_transformation_result.transformation_matrix[0][2] - 0.5) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" @@ -226,21 +226,22 @@ def test_DFRegistration_bunny(create_DFPointCloudBunny): def make_assertions(df_transformation_result): assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" - assert abs(df_transformation_result.transformation_matrix[0][3] - 0.05) < 0.02, "The translation in x should be around -0.05" - assert abs(df_transformation_result.transformation_matrix[1][3] - 0.05) < 0.02, "The translation in y should be around -0.05" - assert abs(df_transformation_result.transformation_matrix[2][3] + 0.05) < 0.02, "The translation in z should be around 0.05" - assert df_transformation_result.transformation_matrix[0][0] > 0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" - assert df_transformation_result.transformation_matrix[1][2] > 0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied " - assert df_transformation_result.transformation_matrix[2][1] < -0.9, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + assert abs(df_transformation_result.transformation_matrix[0][3] - 0.1) < 0.02, "The translation in x should be around -0.05" + assert abs(df_transformation_result.transformation_matrix[1][3] - 0.1) < 0.02, "The translation in y should be around -0.05" + assert abs(df_transformation_result.transformation_matrix[2][3] - 0.1) < 0.02, "The translation in z should be around 0.05" + assert abs(df_transformation_result.transformation_matrix[0][0] - 0.866) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + assert abs(df_transformation_result.transformation_matrix[0][1]) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + assert abs(df_transformation_result.transformation_matrix[0][2] - 0.5) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" pc_1 = create_DFPointCloudBunny pc_2 = create_DFPointCloudBunny transform = dfb.dfb_transformation.DFTransformation() - transform.transformation_matrix = [[1.0, 0.0, 0.0, 0.05], - [0.0, 0.0, -1.0, 0.05], - [0.0, 1.0, 0.0, -0.05], - [0.0, 0.0, 0.0, 1.0]] + transform.transformation_matrix = [[0.866, 0.0, 0.5, 0.1], + [0.0, 1.0, 0.0, 0.1], + [-0.5, 0.0, 0.866, 0.1], + [0.0, 0.0, 0.0, 1.0]] # 30 degree rotation around y-axis + translation + pc_2.apply_transformation(transform) df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(pc_1, pc_2) From a1f56df7a476a92af32c31a436025b729392df96 Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 6 Aug 2024 16:53:13 +0200 Subject: [PATCH 15/26] WIP-CI: test x 9 --- .../pybinds_tests/test_pybind_units.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index 64425fe7..bcd64be4 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -191,9 +191,9 @@ def test_DFRegistration_pure_rotation(): def make_assertions(df_transformation_result): assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" - assert abs(df_transformation_result.transformation_matrix[0][0] - 0.866) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" - assert abs(df_transformation_result.transformation_matrix[0][1]) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" - assert abs(df_transformation_result.transformation_matrix[0][2] - 0.5) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + assert abs(df_transformation_result.transformation_matrix[0][0] - 0.866) < 0.2, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + assert abs(df_transformation_result.transformation_matrix[0][1]) < 0.2, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + assert abs(df_transformation_result.transformation_matrix[0][2] - 0.5) < 0.2, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" vertices = [[-2, -1, 0], [2, -1, 0], [2, 1, 0], [-2, 1, 0]] faces = [[0, 1, 2], [0, 2, 3]] @@ -226,20 +226,20 @@ def test_DFRegistration_bunny(create_DFPointCloudBunny): def make_assertions(df_transformation_result): assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" - assert abs(df_transformation_result.transformation_matrix[0][3] - 0.1) < 0.02, "The translation in x should be around -0.05" - assert abs(df_transformation_result.transformation_matrix[1][3] - 0.1) < 0.02, "The translation in y should be around -0.05" - assert abs(df_transformation_result.transformation_matrix[2][3] - 0.1) < 0.02, "The translation in z should be around 0.05" - assert abs(df_transformation_result.transformation_matrix[0][0] - 0.866) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" - assert abs(df_transformation_result.transformation_matrix[0][1]) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" - assert abs(df_transformation_result.transformation_matrix[0][2] - 0.5) < 0.1, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + assert abs(df_transformation_result.transformation_matrix[0][3] - 1) < 0.2, "The translation in x should be around -0.05" + assert abs(df_transformation_result.transformation_matrix[1][3] - 1) < 0.2, "The translation in y should be around -0.05" + assert abs(df_transformation_result.transformation_matrix[2][3] - 1) < 0.2, "The translation in z should be around 0.05" + assert abs(df_transformation_result.transformation_matrix[0][0] - 0.866) < 0.2, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + assert abs(df_transformation_result.transformation_matrix[0][1]) < 0.2, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + assert abs(df_transformation_result.transformation_matrix[0][2] - 0.5) < 0.2, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" pc_1 = create_DFPointCloudBunny pc_2 = create_DFPointCloudBunny transform = dfb.dfb_transformation.DFTransformation() - transform.transformation_matrix = [[0.866, 0.0, 0.5, 0.1], - [0.0, 1.0, 0.0, 0.1], - [-0.5, 0.0, 0.866, 0.1], + transform.transformation_matrix = [[0.866, 0.0, 0.5, 1], + [0.0, 1.0, 0.0, 1], + [-0.5, 0.0, 0.866, 1], [0.0, 0.0, 0.0, 1.0]] # 30 degree rotation around y-axis + translation pc_2.apply_transformation(transform) From 7bffa1403af22482f9e5569fc22e18a719845b1c Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:33:20 +0200 Subject: [PATCH 16/26] WIP-CI: test x 10 --- .../pybinds_tests/test_pybind_units.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index bcd64be4..0e0b3c6b 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -195,7 +195,7 @@ def make_assertions(df_transformation_result): assert abs(df_transformation_result.transformation_matrix[0][1]) < 0.2, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" assert abs(df_transformation_result.transformation_matrix[0][2] - 0.5) < 0.2, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" - vertices = [[-2, -1, 0], [2, -1, 0], [2, 1, 0], [-2, 1, 0]] + vertices = [[-2.0, -1.0, 0.0], [2.0, -1.0, 0.0], [2.0, 1.0, 0.0], [-2.0, 1.0, 0.0]] faces = [[0, 1, 2], [0, 2, 3]] mesh = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], []) mesh2 = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], []) @@ -213,12 +213,10 @@ def make_assertions(df_transformation_result): pc_2.apply_transformation(r) - df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(pc_1, pc_2) - df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(pc_1, pc_2) + df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(pc_1, pc_2) df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(pc_1, pc_2) - make_assertions(df_transformation_result_o3dfgrfm) - make_assertions(df_transformation_result_o3drfm) + make_assertions(df_transformation_result_o3dicp) make_assertions(df_transformation_result_o3dgicp) @@ -244,12 +242,8 @@ def make_assertions(df_transformation_result): pc_2.apply_transformation(transform) - df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(pc_1, pc_2) - df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(pc_1, pc_2) df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(pc_1, pc_2) df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(pc_1, pc_2) - make_assertions(df_transformation_result_o3dfgrfm) - make_assertions(df_transformation_result_o3drfm) make_assertions(df_transformation_result_o3dicp) make_assertions(df_transformation_result_o3dgicp) From b3f18a04f6c1f111755aa5d887c529f6b63a793e Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:54:57 +0200 Subject: [PATCH 17/26] WIP-CI: test x 11 --- .../pybinds_tests/test_pybind_units.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index 0e0b3c6b..98108cf5 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -214,8 +214,8 @@ def make_assertions(df_transformation_result): pc_2.apply_transformation(r) - df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(pc_1, pc_2) - df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(pc_1, pc_2) + df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(pc_1, pc_2, max_correspondence_distance=1) + df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(pc_1, pc_2, max_correspondence_distance=1) make_assertions(df_transformation_result_o3dicp) make_assertions(df_transformation_result_o3dgicp) @@ -224,26 +224,26 @@ def test_DFRegistration_bunny(create_DFPointCloudBunny): def make_assertions(df_transformation_result): assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" - assert abs(df_transformation_result.transformation_matrix[0][3] - 1) < 0.2, "The translation in x should be around -0.05" - assert abs(df_transformation_result.transformation_matrix[1][3] - 1) < 0.2, "The translation in y should be around -0.05" - assert abs(df_transformation_result.transformation_matrix[2][3] - 1) < 0.2, "The translation in z should be around 0.05" + assert abs(df_transformation_result.transformatiotrix[0][3] - 0.5) < 0.2, "The translation in x should be around -0.05" + assert abs(df_transformation_result.transformation_matrix[1][3] - 0.5) < 0.2, "The translation in y should be around -0.05" + assert abs(df_transformation_result.transformation_matrix[2][3] - 0.5) < 0.2, "The translation in z should be around 0.05" assert abs(df_transformation_result.transformation_matrix[0][0] - 0.866) < 0.2, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" - assert abs(df_transformation_result.transformation_matrix[0][1]) < 0.2, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + assert abs(df_transformation_result.transformn_maation_matrix[0][1]) < 0.2, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" assert abs(df_transformation_result.transformation_matrix[0][2] - 0.5) < 0.2, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" pc_1 = create_DFPointCloudBunny pc_2 = create_DFPointCloudBunny transform = dfb.dfb_transformation.DFTransformation() - transform.transformation_matrix = [[0.866, 0.0, 0.5, 1], - [0.0, 1.0, 0.0, 1], - [-0.5, 0.0, 0.866, 1], + transform.transformation_matrix = [[0.866, 0.0, 0.5, 0.5], + [0.0, 1.0, 0.0, 0.5], + [-0.5, 0.0, 0.866, 0.5], [0.0, 0.0, 0.0, 1.0]] # 30 degree rotation around y-axis + translation pc_2.apply_transformation(transform) - df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(pc_1, pc_2) - df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(pc_1, pc_2) + df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(pc_1, pc_2, max_correspondence_distance=1) + df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(pc_1, pc_2, max_correspondence_distance=1) make_assertions(df_transformation_result_o3dicp) make_assertions(df_transformation_result_o3dgicp) From 0fc6d3288811467e2aa237bb4c1e47d59d92446e Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Wed, 7 Aug 2024 16:23:06 +0200 Subject: [PATCH 18/26] UPDATE: unit tests registration working --- .../pybinds_tests/test_pybind_units.py | 101 +++++++++--------- 1 file changed, 53 insertions(+), 48 deletions(-) diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index 98108cf5..ce630770 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -69,16 +69,20 @@ def create_DFPointCloudSampleRoof(): yield df_pcd @pytest.fixture -def create_DFPointCloudSphere(): - df_pcd = dfb.dfb_geometry.DFPointCloud() - df_pcd.load_from_PLY(get_ply_cloud_sphere_path()) - yield df_pcd +def create_two_DFPointCloudSphere(): + df_pcd_1 = dfb.dfb_geometry.DFPointCloud() + df_pcd_2 = dfb.dfb_geometry.DFPointCloud() + df_pcd_1.load_from_PLY(get_ply_cloud_sphere_path()) + df_pcd_2.load_from_PLY(get_ply_cloud_sphere_path()) + yield df_pcd_1, df_pcd_2 @pytest.fixture -def create_DFPointCloudBunny(): - df_pcd = dfb.dfb_geometry.DFPointCloud() - df_pcd.load_from_PLY(get_ply_cloud_bunny_path()) - yield df_pcd +def create_two_DFPointCloudBunny(): + df_pcd_1 = dfb.dfb_geometry.DFPointCloud() + df_pcd_2 = dfb.dfb_geometry.DFPointCloud() + df_pcd_1.load_from_PLY(get_ply_cloud_bunny_path()) + df_pcd_2.load_from_PLY(get_ply_cloud_bunny_path()) + yield df_pcd_1, df_pcd_2 def test_DFPointCloud_properties(create_DFPointCloudSampleRoof): pc = create_DFPointCloudSampleRoof @@ -160,34 +164,36 @@ def test_DFTransform_read_write(create_DFPointCloudSampleRoof): #------------------------------------------------------------------------------ # dfb_registrations namespace #------------------------------------------------------------------------------ -def test_DFRegistration_pure_translation(create_DFPointCloudSphere): +def test_DFRegistration_pure_translation(create_two_DFPointCloudSphere): def make_assertions(df_transformation_result): assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" - assert abs(df_transformation_result.transformation_matrix[0][3] - 20) > 0.5, "The translation in x should be around 20" - assert abs(df_transformation_result.transformation_matrix[1][3] - 20) > 0.5, "The translation in y should be around 20" - assert abs(df_transformation_result.transformation_matrix[2][3] - 20) > 0.5, "The translation in z should be around 20" + assert abs(df_transformation_result.transformation_matrix[0][3] - 20) < 0.5, "The translation in x should be around 20" + assert abs(df_transformation_result.transformation_matrix[1][3] - 20) < 0.5, "The translation in y should be around 20" + assert abs(df_transformation_result.transformation_matrix[2][3] - 20) < 0.5, "The translation in z should be around 20" + + sphere_1, sphere_2 = create_two_DFPointCloudSphere - pc_1 = create_DFPointCloudSphere - pc_2 = create_DFPointCloudSphere t = dfb.dfb_transformation.DFTransformation() t.transformation_matrix = [[1.0, 0.0, 0.0, 20], [0.0, 1.0, 0.0, 20], [0.0, 0.0, 1.0, 20], [0.0, 0.0, 0.0, 1.0]] - pc_2.apply_transformation(t) - df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(pc_1, pc_2) - df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(pc_1, pc_2) - df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(pc_1, pc_2) - df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(pc_1, pc_2) + sphere_2.apply_transformation(t) + + df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(sphere_1, sphere_2) + df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(sphere_1, sphere_2) + df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(sphere_1, sphere_2, max_correspondence_distance=20) + df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(sphere_1, sphere_2, max_correspondence_distance=20) + make_assertions(df_transformation_result_o3dfgrfm) make_assertions(df_transformation_result_o3drfm) make_assertions(df_transformation_result_o3dicp) make_assertions(df_transformation_result_o3dgicp) -def test_DFRegistration_pure_rotation(): +def test_DFRegistration_rotation_bunny(create_two_DFPointCloudBunny): def make_assertions(df_transformation_result): assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" @@ -195,55 +201,54 @@ def make_assertions(df_transformation_result): assert abs(df_transformation_result.transformation_matrix[0][1]) < 0.2, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" assert abs(df_transformation_result.transformation_matrix[0][2] - 0.5) < 0.2, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" - vertices = [[-2.0, -1.0, 0.0], [2.0, -1.0, 0.0], [2.0, 1.0, 0.0], [-2.0, 1.0, 0.0]] - faces = [[0, 1, 2], [0, 2, 3]] - mesh = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], []) - mesh2 = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], []) + bunny_1, bunny_2 =create_two_DFPointCloudBunny r = dfb.dfb_transformation.DFTransformation() r.transformation_matrix = [[0.866, 0.0, 0.5, 0.0], [0.0, 1.0, 0.0, 0.0], [-0.5, 0.0, 0.866, 0.0], [0.0, 0.0, 0.0, 1.0]] # 30 degree rotation around y-axis + bunny_2.apply_transformation(r) - pc_1 = mesh.sample_points_uniformly(1000) - pc_2 = mesh2.sample_points_uniformly(1000) - pc_1.estimate_normals() - pc_2.estimate_normals() - - pc_2.apply_transformation(r) - - - df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(pc_1, pc_2, max_correspondence_distance=1) - df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(pc_1, pc_2, max_correspondence_distance=1) + df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(bunny_1, bunny_2) + df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(bunny_1, bunny_2) + df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(bunny_1, bunny_2, max_correspondence_distance=1.0) + df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(bunny_1, bunny_2, max_correspondence_distance=15.0) + make_assertions(df_transformation_result_o3dfgrfm) + make_assertions(df_transformation_result_o3drfm) make_assertions(df_transformation_result_o3dicp) make_assertions(df_transformation_result_o3dgicp) -def test_DFRegistration_bunny(create_DFPointCloudBunny): + +def test_DFRegistration_composite_bunny(create_two_DFPointCloudBunny): def make_assertions(df_transformation_result): assert df_transformation_result is not None, "DFRegistration should return a transformation matrix" - assert abs(df_transformation_result.transformatiotrix[0][3] - 0.5) < 0.2, "The translation in x should be around -0.05" - assert abs(df_transformation_result.transformation_matrix[1][3] - 0.5) < 0.2, "The translation in y should be around -0.05" - assert abs(df_transformation_result.transformation_matrix[2][3] - 0.5) < 0.2, "The translation in z should be around 0.05" + assert abs(df_transformation_result.transformation_matrix[0][3] - 0.1) < 0.02, "The translation in x should be around -0.05" + assert abs(df_transformation_result.transformation_matrix[1][3] - 0.1) < 0.02, "The translation in y should be around -0.05" + assert abs(df_transformation_result.transformation_matrix[2][3] - 0.1) < 0.02, "The translation in z should be around 0.05" assert abs(df_transformation_result.transformation_matrix[0][0] - 0.866) < 0.2, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" - assert abs(df_transformation_result.transformn_maation_matrix[0][1]) < 0.2, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" + assert abs(df_transformation_result.transformation_matrix[0][1]) < 0.2, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" assert abs(df_transformation_result.transformation_matrix[0][2] - 0.5) < 0.2, "The rotation part of transformation matrix should be close to the transposed rotation matrix initially applied" - pc_1 = create_DFPointCloudBunny - pc_2 = create_DFPointCloudBunny + bunny_1 ,bunny_2 = create_two_DFPointCloudBunny transform = dfb.dfb_transformation.DFTransformation() - transform.transformation_matrix = [[0.866, 0.0, 0.5, 0.5], - [0.0, 1.0, 0.0, 0.5], - [-0.5, 0.0, 0.866, 0.5], - [0.0, 0.0, 0.0, 1.0]] # 30 degree rotation around y-axis + translation + transform.transformation_matrix = [[0.866, 0.0, 0.5, 0.1], + [0.0, 1.0, 0.0, 0.1], + [-0.5, 0.0, 0.866, 0.1], + [0.0, 0.0, 0.0, 1.0]] # 30 degree rotation around y-axis + translation - pc_2.apply_transformation(transform) + bunny_2.apply_transformation(transform) - df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(pc_1, pc_2, max_correspondence_distance=1) - df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(pc_1, pc_2, max_correspondence_distance=1) + df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(bunny_1, bunny_2) + df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(bunny_1, bunny_2) + df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(bunny_1, bunny_2) + df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(bunny_1, bunny_2) + + make_assertions(df_transformation_result_o3dfgrfm) + make_assertions(df_transformation_result_o3drfm) make_assertions(df_transformation_result_o3dicp) make_assertions(df_transformation_result_o3dgicp) From 712c4b0c1cdd816232e84b04c561f207fad85e81 Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Wed, 7 Aug 2024 21:42:48 +0200 Subject: [PATCH 19/26] ADD-UPDATE: ply mesh tests and point cloud segmentation tests added --- .../pybinds_tests/test_pybind_units.py | 66 +++++++++++++++++-- tests/test_data/cube_mesh.ply | 3 + 2 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 tests/test_data/cube_mesh.ply diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index ce630770..b036ffba 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -41,6 +41,13 @@ def get_ply_cloud_bunny_path(): raise FileNotFoundError(f"PLY file not found at: {ply_file_path}") return ply_file_path +def get_ply_mesh_cube_path(): + base_test_data_dir = os.getenv('DF_TEST_DATA_DIR', os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'test_data'))) + ply_file_path = os.path.join(base_test_data_dir, "cube_mesh.ply") + if not os.path.exists(ply_file_path): + raise FileNotFoundError(f"PLY file not found at: {ply_file_path}") + return ply_file_path + #------------------------------------------------------------------------------ # dfb_geometry namespace #------------------------------------------------------------------------------ @@ -84,6 +91,13 @@ def create_two_DFPointCloudBunny(): df_pcd_2.load_from_PLY(get_ply_cloud_bunny_path()) yield df_pcd_1, df_pcd_2 +@pytest.fixture +def create_DFMeshCube(): + df_mesh = dfb.dfb_geometry.DFMesh() + df_mesh.load_from_PLY(get_ply_mesh_cube_path()) + yield df_mesh + + def test_DFPointCloud_properties(create_DFPointCloudSampleRoof): pc = create_DFPointCloudSampleRoof assert pc.points.__len__() == 7379, "DFPointCloud should have 7379 points" @@ -132,9 +146,33 @@ def test_DFPointCloud_get_tight_bounding_box(create_DFPointCloudSampleRoof): # round to the 3 decimal places assert round(obb[0][0], 3) == 0.196, "The min x of the OBB should be 0.196" -# TODO: to implement DFMesh tests def test_DFMesh_init(): - pass + mesh = dfb.dfb_geometry.DFMesh() + assert mesh is not None, "DFMesh should be initialized successfully" + +def test_DFMesh_load_from_PLY(create_DFMeshCube): + mesh = create_DFMeshCube + assert mesh.vertices.__len__() == 726, "DFMesh should have 726 vertices" + assert mesh.faces.__len__() == 1200, "DFMesh should have 800 faces" + +def test_DFMesh_sample_points(create_DFMeshCube): + mesh = create_DFMeshCube + pc = mesh.sample_points_uniformly(1000) + assert pc.points.__len__() == 1000, "DFPointCloud should have 1000 points" + +def test_DFMesh_compute_bounding_box(create_DFMeshCube): + mesh = create_DFMeshCube + obb = mesh.get_tight_bounding_box() + assert obb[0][0] == 0, "The x coordinate of the first corner of the OBB should be 0" + assert obb[1][0] == 100, "The y coordinate of the second corner of the OBB should be 100" + assert obb[2][0] == 0, "The y coordinate of the third corner of the OBB should be 0" + assert obb[6][2] == 100, "The z coordinate of the second to last corner of the OBB should be 100" + +def test_DFMesh_getters(create_DFMeshCube): + mesh = create_DFMeshCube + assert mesh.get_num_vertices() == 726, "get_num_vertices() should return 726" + assert mesh.get_num_faces() == 1200, "get_num_faces() should return 1200" + #------------------------------------------------------------------------------ # dfb_transformation namespace @@ -257,9 +295,27 @@ def make_assertions(df_transformation_result): # dfb_segmentation namespace #------------------------------------------------------------------------------ - # vertices = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 1, -1], [0, 0, -1]] - # faces = [[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5]] - # mesh = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], []) +def test_DFPlaneSegmentation(): + vertices = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 1, -1], [0, 0, -1]] + faces = [[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5]] + mesh = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], []) + pc = mesh.sample_points_uniformly(1000) + pc.estimate_normals(knn=200) + + segments = dfb.dfb_segmentation.DFSegmentation.segment_by_normal(pc, min_cluster_size=250) + + assert len(segments) == 2, "DFPlaneSegmentation should return 2 segments" + +def test_DFPlaneSegmentation_disconnected_plans(): + vertices = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 1, -1], [0, 0, -1]] + faces = [[0, 1, 2], [3, 4, 5]] + mesh = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], []) + pc = mesh.sample_points_uniformly(1000) + pc.estimate_normals(knn=200) + + segments = dfb.dfb_segmentation.DFSegmentation.segment_by_normal(pc, min_cluster_size=250) + + assert len(segments) == 2, "DFPlaneSegmentation should return 2 segments" if __name__ == "__main__": pytest.main() \ No newline at end of file diff --git a/tests/test_data/cube_mesh.ply b/tests/test_data/cube_mesh.ply new file mode 100644 index 00000000..38ad7a06 --- /dev/null +++ b/tests/test_data/cube_mesh.ply @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8a7804c4bfc0fbebb68ffb9a7d616c6dc21199d1e43a0b9434168ee47ce5a09e +size 36134 From 0d74df49f4b9840ae5a414136cc5ebb4cc7d53de Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Wed, 7 Aug 2024 22:09:40 +0200 Subject: [PATCH 20/26] FIX: segmentation parameters for segmentation test adapted for more robust results --- .../pybinds_tests/test_pybind_units.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index b036ffba..779f1158 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -300,9 +300,12 @@ def test_DFPlaneSegmentation(): faces = [[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5]] mesh = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], []) pc = mesh.sample_points_uniformly(1000) - pc.estimate_normals(knn=200) + pc.estimate_normals(knn=50) - segments = dfb.dfb_segmentation.DFSegmentation.segment_by_normal(pc, min_cluster_size=250) + segments = dfb.dfb_segmentation.DFSegmentation.segment_by_normal(pc, + normal_threshold_degree=10, + min_cluster_size=200, + knn_neighborhood_size=200) assert len(segments) == 2, "DFPlaneSegmentation should return 2 segments" @@ -311,9 +314,12 @@ def test_DFPlaneSegmentation_disconnected_plans(): faces = [[0, 1, 2], [3, 4, 5]] mesh = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], []) pc = mesh.sample_points_uniformly(1000) - pc.estimate_normals(knn=200) + pc.estimate_normals(knn=50) - segments = dfb.dfb_segmentation.DFSegmentation.segment_by_normal(pc, min_cluster_size=250) + segments = dfb.dfb_segmentation.DFSegmentation.segment_by_normal(pc, + normal_threshold_degree=10, + min_cluster_size=200, + knn_neighborhood_size=200) assert len(segments) == 2, "DFPlaneSegmentation should return 2 segments" From 9f3d1f53f7847675ce5921b81552b5a9db8d1b8c Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Wed, 7 Aug 2024 22:29:46 +0200 Subject: [PATCH 21/26] FIX: second adaptation of segmentation parameters --- .../pybinds_tests/test_pybind_units.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index 779f1158..d0cb9fb6 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -299,12 +299,12 @@ def test_DFPlaneSegmentation(): vertices = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 1, -1], [0, 0, -1]] faces = [[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5]] mesh = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], []) - pc = mesh.sample_points_uniformly(1000) - pc.estimate_normals(knn=50) + pc = mesh.sample_points_uniformly(5000) + pc.estimate_normals(knn=20) segments = dfb.dfb_segmentation.DFSegmentation.segment_by_normal(pc, - normal_threshold_degree=10, - min_cluster_size=200, + normal_threshold_degree=5, + min_cluster_size=1000, knn_neighborhood_size=200) assert len(segments) == 2, "DFPlaneSegmentation should return 2 segments" @@ -313,12 +313,12 @@ def test_DFPlaneSegmentation_disconnected_plans(): vertices = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 1, -1], [0, 0, -1]] faces = [[0, 1, 2], [3, 4, 5]] mesh = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], []) - pc = mesh.sample_points_uniformly(1000) - pc.estimate_normals(knn=50) + pc = mesh.sample_points_uniformly(5000) + pc.estimate_normals(knn=20) segments = dfb.dfb_segmentation.DFSegmentation.segment_by_normal(pc, - normal_threshold_degree=10, - min_cluster_size=200, + normal_threshold_degree=5, + min_cluster_size=1000, knn_neighborhood_size=200) assert len(segments) == 2, "DFPlaneSegmentation should return 2 segments" From 6905b1b7dd850292647f1181e693a8a4410dec6d Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 13 Aug 2024 10:57:16 +0200 Subject: [PATCH 22/26] UPDATE: add python test for add_points() method of DFPointCloud --- .../integration_tests/pybinds_tests/test_pybind_units.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index d0cb9fb6..9e66ea6d 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -97,6 +97,7 @@ def create_DFMeshCube(): df_mesh.load_from_PLY(get_ply_mesh_cube_path()) yield df_mesh +# point cloud tests def test_DFPointCloud_properties(create_DFPointCloudSampleRoof): pc = create_DFPointCloudSampleRoof @@ -119,6 +120,11 @@ def test_DFPointCloud_properties(create_DFPointCloudSampleRoof): assert pc.has_colors() == False, "has_colors() should return False" assert pc.has_normals() == False, "has_normals() should return False" +def test_DFPointCloud_add_points(create_two_DFPointCloudSphere): + sphere_1, sphere_2 = create_two_DFPointCloudSphere + sphere_1.add_points(sphere_2) + assert sphere_1.points.__len__() == 10050, "two pointclouds of 5025 pts combined into one should have 10050 pts" + def test_DFPointCloud_apply_color(create_DFPointCloudSampleRoof): pc = create_DFPointCloudSampleRoof pc.apply_color(255, 0, 0) @@ -146,6 +152,8 @@ def test_DFPointCloud_get_tight_bounding_box(create_DFPointCloudSampleRoof): # round to the 3 decimal places assert round(obb[0][0], 3) == 0.196, "The min x of the OBB should be 0.196" +# mesh tests + def test_DFMesh_init(): mesh = dfb.dfb_geometry.DFMesh() assert mesh is not None, "DFMesh should be initialized successfully" From e20ef0d5a60002ced580a59081061bdfded728bf Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 13 Aug 2024 14:31:58 +0200 Subject: [PATCH 23/26] FIX: small modification of naming for GetAxixAlignedBoundingBox for more consistency --- src/diffCheck/geometry/DFPointCloud.cc | 2 +- src/diffCheck/geometry/DFPointCloud.hh | 2 +- src/diffCheck/registrations/DFRefinedRegistration.cc | 4 ++-- src/diffCheckBindings.cc | 2 +- tests/unit_tests/DFPointCloudTest.cc | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/diffCheck/geometry/DFPointCloud.cc b/src/diffCheck/geometry/DFPointCloud.cc index db3bcf76..2ed6934c 100644 --- a/src/diffCheck/geometry/DFPointCloud.cc +++ b/src/diffCheck/geometry/DFPointCloud.cc @@ -116,7 +116,7 @@ namespace diffCheck::geometry return cilantroPointCloud; } - std::vector DFPointCloud::ComputeBoundingBox() + std::vector DFPointCloud::GetAxixAlignedBoundingBox() { auto O3DPointCloud = this->Cvt2O3DPointCloud(); auto boundingBox = O3DPointCloud->GetAxisAlignedBoundingBox(); diff --git a/src/diffCheck/geometry/DFPointCloud.hh b/src/diffCheck/geometry/DFPointCloud.hh index b66a78d3..5a172385 100644 --- a/src/diffCheck/geometry/DFPointCloud.hh +++ b/src/diffCheck/geometry/DFPointCloud.hh @@ -54,7 +54,7 @@ namespace diffCheck::geometry * @return std::vector A vector of two Eigen::Vector3d, with the first one being the minimum * point and the second one the maximum point of the bounding box. */ - std::vector ComputeBoundingBox(); + std::vector GetAxixAlignedBoundingBox(); /** * @brief Estimate the normals of the point cloud by either knn or if the radius diff --git a/src/diffCheck/registrations/DFRefinedRegistration.cc b/src/diffCheck/registrations/DFRefinedRegistration.cc index 503382d6..83d64f5a 100644 --- a/src/diffCheck/registrations/DFRefinedRegistration.cc +++ b/src/diffCheck/registrations/DFRefinedRegistration.cc @@ -13,7 +13,7 @@ namespace diffCheck::registrations int maxIteration, bool usePointToPlane) { - std::vector minMax = source->ComputeBoundingBox(); + std::vector minMax = source->GetAxixAlignedBoundingBox(); std::shared_ptr O3Dsource = source->Cvt2O3DPointCloud(); std::shared_ptr O3Dtarget = target->Cvt2O3DPointCloud(); @@ -65,7 +65,7 @@ namespace diffCheck::registrations double relativeFitness, double relativeRMSE) { - std::vector minMax = source->ComputeBoundingBox(); + std::vector minMax = source->GetAxixAlignedBoundingBox(); std::shared_ptr O3Dsource = source->Cvt2O3DPointCloud(); std::shared_ptr O3Dtarget = target->Cvt2O3DPointCloud(); diff --git a/src/diffCheckBindings.cc b/src/diffCheckBindings.cc index 20e9a84b..55e2db7e 100644 --- a/src/diffCheckBindings.cc +++ b/src/diffCheckBindings.cc @@ -31,7 +31,6 @@ PYBIND11_MODULE(diffcheck_bindings, m) { .def("compute_distance", &diffCheck::geometry::DFPointCloud::ComputeDistance, py::arg("target_cloud")) - .def("compute_BoundingBox", &diffCheck::geometry::DFPointCloud::ComputeBoundingBox) .def("voxel_downsample", &diffCheck::geometry::DFPointCloud::VoxelDownsample, py::arg("voxel_size")) @@ -55,6 +54,7 @@ PYBIND11_MODULE(diffcheck_bindings, m) { .def("add_points", &diffCheck::geometry::DFPointCloud::AddPoints) .def("get_tight_bounding_box", &diffCheck::geometry::DFPointCloud::GetTightBoundingBox) + .def("get_axis_aligned_bounding_box", &diffCheck::geometry::DFPointCloud::GetAxixAlignedBoundingBox) .def("get_num_points", &diffCheck::geometry::DFPointCloud::GetNumPoints) .def("get_num_colors", &diffCheck::geometry::DFPointCloud::GetNumColors) diff --git a/tests/unit_tests/DFPointCloudTest.cc b/tests/unit_tests/DFPointCloudTest.cc index d33cd2e9..c2e1fc7b 100644 --- a/tests/unit_tests/DFPointCloudTest.cc +++ b/tests/unit_tests/DFPointCloudTest.cc @@ -118,7 +118,7 @@ TEST_F(DFPointCloudTestFixture, ComputeDistance) { } TEST_F(DFPointCloudTestFixture, ComputeAABB) { - std::vector bbox = dfPointCloud.ComputeBoundingBox(); + std::vector bbox = dfPointCloud.GetAxixAlignedBoundingBox(); EXPECT_EQ(bbox.size(), 2); } From 3fb136b58334e80a6d5cf59029be028bf761aa68 Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 13 Aug 2024 14:33:17 +0200 Subject: [PATCH 24/26] UPDATE: missing python unit tests added for pointclouds and meshes --- .../pybinds_tests/test_pybind_units.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index 9e66ea6d..46ca8d66 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -152,6 +152,27 @@ def test_DFPointCloud_get_tight_bounding_box(create_DFPointCloudSampleRoof): # round to the 3 decimal places assert round(obb[0][0], 3) == 0.196, "The min x of the OBB should be 0.196" +def test_DFPointCloud_get_axis_aligned_bounding_box(create_DFPointCloudSampleRoof): + pc = create_DFPointCloudSampleRoof + aabb = pc.get_axis_aligned_bounding_box() + # round to the 3 decimal places + assert round(aabb[0][0], 3) == -2.339, "The min x of the AABB should be 0.196" + +def test_DFPointCloud_compute_distance(): + point_pc_1 = [(0, 0, 0)] + point_pc_2 = [(1, 0, 0)] + normal_pc_1 = [(0, 0, 1)] + normal_pc_2 = [(0, 0, 1)] + color_pc_1 = [(0, 0, 0)] + color_pc_2 = [(0, 0, 0)] + + pc_1 = dfb.dfb_geometry.DFPointCloud(point_pc_1, normal_pc_1, color_pc_1) + pc_2 = dfb.dfb_geometry.DFPointCloud(point_pc_2, normal_pc_2, color_pc_2) + + distance = pc_1.compute_distance(pc_2)[0] + + assert distance == 1. , "The distance between the two points should be 1." + # mesh tests def test_DFMesh_init(): @@ -163,6 +184,32 @@ def test_DFMesh_load_from_PLY(create_DFMeshCube): assert mesh.vertices.__len__() == 726, "DFMesh should have 726 vertices" assert mesh.faces.__len__() == 1200, "DFMesh should have 800 faces" +def test_DFMesh_properties(): + vertices = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 1, -1], [0, 0, -1]] + faces = [[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5]] + mesh = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], []) + assert mesh.get_num_vertices() == 6, "get_num_vertices() should return 6" + assert mesh.get_num_faces() == 4, "get_num_faces() should return 4" + assert isinstance(mesh.vertices, list), "vertices should be a list" + assert isinstance(mesh.faces, list), "faces should be a list" + assert isinstance(mesh.normals_face, list), "normals_faces should be a list" + assert isinstance(mesh.normals_vertex, list), "normals_vertex should be a list" + assert isinstance(mesh.colors_face, list), "colors_faces should be a list" + assert isinstance(mesh.colors_vertex, list), "colors_vertex should be a list" + assert len(mesh.vertices[0]) == 3, "vertices should be a list of 3 coordinates" + assert len(mesh.faces[0]) == 3, "faces should be a list of 3 indexes" + +def test_DFMesh_compute_distance(): + vertices = [[0, 0, 0], [1, 0, 0], [0, 1, 0]] + faces = [[0, 1, 2]] + mesh = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], []) + point = [(0, 0, 1)] + normal = [(0, 0, 1)] + color = [(0, 0, 0)] + pc = dfb.dfb_geometry.DFPointCloud(point, normal, color) + distance = mesh.compute_distance(pc)[0] + assert distance == 1.0, "The distance between the point and the mesh should be 1.0" + def test_DFMesh_sample_points(create_DFMeshCube): mesh = create_DFMeshCube pc = mesh.sample_points_uniformly(1000) From 01dfd00ef468df006f4a2a13d9300257c610f899 Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 13 Aug 2024 21:38:42 +0200 Subject: [PATCH 25/26] UPDATE-FIX: remove python test of ad_points() as it was moved into another PR --- tests/integration_tests/pybinds_tests/test_pybind_units.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index 46ca8d66..eee17ea2 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -120,10 +120,6 @@ def test_DFPointCloud_properties(create_DFPointCloudSampleRoof): assert pc.has_colors() == False, "has_colors() should return False" assert pc.has_normals() == False, "has_normals() should return False" -def test_DFPointCloud_add_points(create_two_DFPointCloudSphere): - sphere_1, sphere_2 = create_two_DFPointCloudSphere - sphere_1.add_points(sphere_2) - assert sphere_1.points.__len__() == 10050, "two pointclouds of 5025 pts combined into one should have 10050 pts" def test_DFPointCloud_apply_color(create_DFPointCloudSampleRoof): pc = create_DFPointCloudSampleRoof From db9451566157ce33ff8d1cf9761f4718d82a075a Mon Sep 17 00:00:00 2001 From: DamienGilliard <127743632+DamienGilliard@users.noreply.github.com> Date: Tue, 13 Aug 2024 22:20:28 +0200 Subject: [PATCH 26/26] UPDATE: segmentation tests use ply with normals pre-computed --- .../pybinds_tests/test_pybind_units.py | 52 +++++++++++++------ .../two_connected_planes_with_normals.ply | 3 ++ .../two_separate_planes_with_normals.ply | 3 ++ 3 files changed, 41 insertions(+), 17 deletions(-) create mode 100644 tests/test_data/two_connected_planes_with_normals.ply create mode 100644 tests/test_data/two_separate_planes_with_normals.ply diff --git a/tests/integration_tests/pybinds_tests/test_pybind_units.py b/tests/integration_tests/pybinds_tests/test_pybind_units.py index eee17ea2..61c76794 100644 --- a/tests/integration_tests/pybinds_tests/test_pybind_units.py +++ b/tests/integration_tests/pybinds_tests/test_pybind_units.py @@ -48,6 +48,20 @@ def get_ply_mesh_cube_path(): raise FileNotFoundError(f"PLY file not found at: {ply_file_path}") return ply_file_path +def get_two_separate_planes_ply_path(): + base_test_data_dir = os.getenv('DF_TEST_DATA_DIR', os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'test_data'))) + ply_file_path = os.path.join(base_test_data_dir, "two_separate_planes_with_normals.ply") + if not os.path.exists(ply_file_path): + raise FileNotFoundError(f"PLY file not found at: {ply_file_path}") + return ply_file_path + +def get_two_connected_planes_ply_path(): + base_test_data_dir = os.getenv('DF_TEST_DATA_DIR', os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'test_data'))) + ply_file_path = os.path.join(base_test_data_dir, "two_connected_planes_with_normals.ply") + if not os.path.exists(ply_file_path): + raise FileNotFoundError(f"PLY file not found at: {ply_file_path}") + return ply_file_path + #------------------------------------------------------------------------------ # dfb_geometry namespace #------------------------------------------------------------------------------ @@ -91,6 +105,18 @@ def create_two_DFPointCloudBunny(): df_pcd_2.load_from_PLY(get_ply_cloud_bunny_path()) yield df_pcd_1, df_pcd_2 +@pytest.fixture +def create_DFPointCloudTwoSeparatePlanes(): + df_pcd = dfb.dfb_geometry.DFPointCloud() + df_pcd.load_from_PLY(get_two_separate_planes_ply_path()) + yield df_pcd + +@pytest.fixture +def create_DFPointCloudTwoConnectedPlanes(): + df_pcd = dfb.dfb_geometry.DFPointCloud() + df_pcd.load_from_PLY(get_two_connected_planes_ply_path()) + yield df_pcd + @pytest.fixture def create_DFMeshCube(): df_mesh = dfb.dfb_geometry.DFMesh() @@ -346,32 +372,24 @@ def make_assertions(df_transformation_result): # dfb_segmentation namespace #------------------------------------------------------------------------------ -def test_DFPlaneSegmentation(): - vertices = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 1, -1], [0, 0, -1]] - faces = [[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5]] - mesh = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], []) - pc = mesh.sample_points_uniformly(5000) - pc.estimate_normals(knn=20) +def test_DFPlaneSegmentation_separate_plans(create_DFPointCloudTwoSeparatePlanes): + pc = create_DFPointCloudTwoSeparatePlanes segments = dfb.dfb_segmentation.DFSegmentation.segment_by_normal(pc, normal_threshold_degree=5, - min_cluster_size=1000, - knn_neighborhood_size=200) + min_cluster_size=100, + knn_neighborhood_size=20) assert len(segments) == 2, "DFPlaneSegmentation should return 2 segments" -def test_DFPlaneSegmentation_disconnected_plans(): - vertices = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 1, -1], [0, 0, -1]] - faces = [[0, 1, 2], [3, 4, 5]] - mesh = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], []) - pc = mesh.sample_points_uniformly(5000) - pc.estimate_normals(knn=20) +def test_DFPlaneSegmentation_connected_plans(create_DFPointCloudTwoConnectedPlanes): + pc = create_DFPointCloudTwoConnectedPlanes segments = dfb.dfb_segmentation.DFSegmentation.segment_by_normal(pc, normal_threshold_degree=5, - min_cluster_size=1000, - knn_neighborhood_size=200) - + min_cluster_size=100, + knn_neighborhood_size=20) + assert len(segments) == 2, "DFPlaneSegmentation should return 2 segments" if __name__ == "__main__": diff --git a/tests/test_data/two_connected_planes_with_normals.ply b/tests/test_data/two_connected_planes_with_normals.ply new file mode 100644 index 00000000..0a0406e0 --- /dev/null +++ b/tests/test_data/two_connected_planes_with_normals.ply @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:878ac619b461a9e1385a74cdaab7e9a9e553221da8bf59c407c1130eb16faff5 +size 48291 diff --git a/tests/test_data/two_separate_planes_with_normals.ply b/tests/test_data/two_separate_planes_with_normals.ply new file mode 100644 index 00000000..1e41e554 --- /dev/null +++ b/tests/test_data/two_separate_planes_with_normals.ply @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:94ca289b7e9eedeabae77b8ab764e95d3817877a060b44eb2375b048f576514c +size 48291