Skip to content

Commit 0fc6d32

Browse files
UPDATE: unit tests registration working
1 parent b3f18a0 commit 0fc6d32

File tree

1 file changed

+53
-48
lines changed

1 file changed

+53
-48
lines changed

tests/integration_tests/pybinds_tests/test_pybind_units.py

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,20 @@ def create_DFPointCloudSampleRoof():
6969
yield df_pcd
7070

7171
@pytest.fixture
72-
def create_DFPointCloudSphere():
73-
df_pcd = dfb.dfb_geometry.DFPointCloud()
74-
df_pcd.load_from_PLY(get_ply_cloud_sphere_path())
75-
yield df_pcd
72+
def create_two_DFPointCloudSphere():
73+
df_pcd_1 = dfb.dfb_geometry.DFPointCloud()
74+
df_pcd_2 = dfb.dfb_geometry.DFPointCloud()
75+
df_pcd_1.load_from_PLY(get_ply_cloud_sphere_path())
76+
df_pcd_2.load_from_PLY(get_ply_cloud_sphere_path())
77+
yield df_pcd_1, df_pcd_2
7678

7779
@pytest.fixture
78-
def create_DFPointCloudBunny():
79-
df_pcd = dfb.dfb_geometry.DFPointCloud()
80-
df_pcd.load_from_PLY(get_ply_cloud_bunny_path())
81-
yield df_pcd
80+
def create_two_DFPointCloudBunny():
81+
df_pcd_1 = dfb.dfb_geometry.DFPointCloud()
82+
df_pcd_2 = dfb.dfb_geometry.DFPointCloud()
83+
df_pcd_1.load_from_PLY(get_ply_cloud_bunny_path())
84+
df_pcd_2.load_from_PLY(get_ply_cloud_bunny_path())
85+
yield df_pcd_1, df_pcd_2
8286

8387
def test_DFPointCloud_properties(create_DFPointCloudSampleRoof):
8488
pc = create_DFPointCloudSampleRoof
@@ -160,90 +164,91 @@ def test_DFTransform_read_write(create_DFPointCloudSampleRoof):
160164
#------------------------------------------------------------------------------
161165
# dfb_registrations namespace
162166
#------------------------------------------------------------------------------
163-
def test_DFRegistration_pure_translation(create_DFPointCloudSphere):
167+
def test_DFRegistration_pure_translation(create_two_DFPointCloudSphere):
164168

165169
def make_assertions(df_transformation_result):
166170
assert df_transformation_result is not None, "DFRegistration should return a transformation matrix"
167-
assert abs(df_transformation_result.transformation_matrix[0][3] - 20) > 0.5, "The translation in x should be around 20"
168-
assert abs(df_transformation_result.transformation_matrix[1][3] - 20) > 0.5, "The translation in y should be around 20"
169-
assert abs(df_transformation_result.transformation_matrix[2][3] - 20) > 0.5, "The translation in z should be around 20"
171+
assert abs(df_transformation_result.transformation_matrix[0][3] - 20) < 0.5, "The translation in x should be around 20"
172+
assert abs(df_transformation_result.transformation_matrix[1][3] - 20) < 0.5, "The translation in y should be around 20"
173+
assert abs(df_transformation_result.transformation_matrix[2][3] - 20) < 0.5, "The translation in z should be around 20"
174+
175+
sphere_1, sphere_2 = create_two_DFPointCloudSphere
170176

171-
pc_1 = create_DFPointCloudSphere
172-
pc_2 = create_DFPointCloudSphere
173177
t = dfb.dfb_transformation.DFTransformation()
174178
t.transformation_matrix = [[1.0, 0.0, 0.0, 20],
175179
[0.0, 1.0, 0.0, 20],
176180
[0.0, 0.0, 1.0, 20],
177181
[0.0, 0.0, 0.0, 1.0]]
178-
pc_2.apply_transformation(t)
179182

180-
df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(pc_1, pc_2)
181-
df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(pc_1, pc_2)
182-
df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(pc_1, pc_2)
183-
df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(pc_1, pc_2)
183+
sphere_2.apply_transformation(t)
184+
185+
df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(sphere_1, sphere_2)
186+
df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(sphere_1, sphere_2)
187+
df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(sphere_1, sphere_2, max_correspondence_distance=20)
188+
df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(sphere_1, sphere_2, max_correspondence_distance=20)
189+
184190
make_assertions(df_transformation_result_o3dfgrfm)
185191
make_assertions(df_transformation_result_o3drfm)
186192
make_assertions(df_transformation_result_o3dicp)
187193
make_assertions(df_transformation_result_o3dgicp)
188194

189195

190-
def test_DFRegistration_pure_rotation():
196+
def test_DFRegistration_rotation_bunny(create_two_DFPointCloudBunny):
191197

192198
def make_assertions(df_transformation_result):
193199
assert df_transformation_result is not None, "DFRegistration should return a transformation matrix"
194200
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"
195201
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"
196202
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"
197203

198-
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]]
199-
faces = [[0, 1, 2], [0, 2, 3]]
200-
mesh = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], [])
201-
mesh2 = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], [])
204+
bunny_1, bunny_2 =create_two_DFPointCloudBunny
202205

203206
r = dfb.dfb_transformation.DFTransformation()
204207
r.transformation_matrix = [[0.866, 0.0, 0.5, 0.0],
205208
[0.0, 1.0, 0.0, 0.0],
206209
[-0.5, 0.0, 0.866, 0.0],
207210
[0.0, 0.0, 0.0, 1.0]] # 30 degree rotation around y-axis
211+
bunny_2.apply_transformation(r)
208212

209-
pc_1 = mesh.sample_points_uniformly(1000)
210-
pc_2 = mesh2.sample_points_uniformly(1000)
211-
pc_1.estimate_normals()
212-
pc_2.estimate_normals()
213-
214-
pc_2.apply_transformation(r)
215-
216-
217-
df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(pc_1, pc_2, max_correspondence_distance=1)
218-
df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(pc_1, pc_2, max_correspondence_distance=1)
213+
df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(bunny_1, bunny_2)
214+
df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(bunny_1, bunny_2)
215+
df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(bunny_1, bunny_2, max_correspondence_distance=1.0)
216+
df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(bunny_1, bunny_2, max_correspondence_distance=15.0)
219217

218+
make_assertions(df_transformation_result_o3dfgrfm)
219+
make_assertions(df_transformation_result_o3drfm)
220220
make_assertions(df_transformation_result_o3dicp)
221221
make_assertions(df_transformation_result_o3dgicp)
222222

223-
def test_DFRegistration_bunny(create_DFPointCloudBunny):
223+
224+
def test_DFRegistration_composite_bunny(create_two_DFPointCloudBunny):
224225

225226
def make_assertions(df_transformation_result):
226227
assert df_transformation_result is not None, "DFRegistration should return a transformation matrix"
227-
assert abs(df_transformation_result.transformatiotrix[0][3] - 0.5) < 0.2, "The translation in x should be around -0.05"
228-
assert abs(df_transformation_result.transformation_matrix[1][3] - 0.5) < 0.2, "The translation in y should be around -0.05"
229-
assert abs(df_transformation_result.transformation_matrix[2][3] - 0.5) < 0.2, "The translation in z should be around 0.05"
228+
assert abs(df_transformation_result.transformation_matrix[0][3] - 0.1) < 0.02, "The translation in x should be around -0.05"
229+
assert abs(df_transformation_result.transformation_matrix[1][3] - 0.1) < 0.02, "The translation in y should be around -0.05"
230+
assert abs(df_transformation_result.transformation_matrix[2][3] - 0.1) < 0.02, "The translation in z should be around 0.05"
230231
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"
231-
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"
232+
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"
232233
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"
233234

234-
pc_1 = create_DFPointCloudBunny
235-
pc_2 = create_DFPointCloudBunny
235+
bunny_1 ,bunny_2 = create_two_DFPointCloudBunny
236236

237237
transform = dfb.dfb_transformation.DFTransformation()
238-
transform.transformation_matrix = [[0.866, 0.0, 0.5, 0.5],
239-
[0.0, 1.0, 0.0, 0.5],
240-
[-0.5, 0.0, 0.866, 0.5],
241-
[0.0, 0.0, 0.0, 1.0]] # 30 degree rotation around y-axis + translation
238+
transform.transformation_matrix = [[0.866, 0.0, 0.5, 0.1],
239+
[0.0, 1.0, 0.0, 0.1],
240+
[-0.5, 0.0, 0.866, 0.1],
241+
[0.0, 0.0, 0.0, 1.0]] # 30 degree rotation around y-axis + translation
242242

243-
pc_2.apply_transformation(transform)
243+
bunny_2.apply_transformation(transform)
244244

245-
df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(pc_1, pc_2, max_correspondence_distance=1)
246-
df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(pc_1, pc_2, max_correspondence_distance=1)
245+
df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(bunny_1, bunny_2)
246+
df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(bunny_1, bunny_2)
247+
df_transformation_result_o3dicp = dfb.dfb_registrations.DFRefinedRegistration.O3DICP(bunny_1, bunny_2)
248+
df_transformation_result_o3dgicp = dfb.dfb_registrations.DFRefinedRegistration.O3DGeneralizedICP(bunny_1, bunny_2)
249+
250+
make_assertions(df_transformation_result_o3dfgrfm)
251+
make_assertions(df_transformation_result_o3drfm)
247252
make_assertions(df_transformation_result_o3dicp)
248253
make_assertions(df_transformation_result_o3dgicp)
249254

0 commit comments

Comments
 (0)