Skip to content

Commit 59f325e

Browse files
WIP-CI: test x 4
1 parent a33d297 commit 59f325e

File tree

1 file changed

+99
-9
lines changed

1 file changed

+99
-9
lines changed

tests/integration_tests/pybinds_tests/test_pybind_units.py

Lines changed: 99 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ def get_ply_cloud_sphere_path():
3434
raise FileNotFoundError(f"PLY file not found at: {ply_file_path}")
3535
return ply_file_path
3636

37+
def get_ply_cloud_bunny_path():
38+
base_test_data_dir = os.getenv('DF_TEST_DATA_DIR', os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'test_data')))
39+
ply_file_path = os.path.join(base_test_data_dir, "stanford_bunny_50kpts_with_normals.ply")
40+
if not os.path.exists(ply_file_path):
41+
raise FileNotFoundError(f"PLY file not found at: {ply_file_path}")
42+
return ply_file_path
43+
3744
#------------------------------------------------------------------------------
3845
# dfb_geometry namespace
3946
#------------------------------------------------------------------------------
@@ -67,6 +74,12 @@ def create_DFPointCloudSphere():
6774
df_pcd.load_from_PLY(get_ply_cloud_sphere_path())
6875
yield df_pcd
6976

77+
@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
82+
7083
def test_DFPointCloud_properties(create_DFPointCloudSampleRoof):
7184
pc = create_DFPointCloudSampleRoof
7285
assert pc.points.__len__() == 7379, "DFPointCloud should have 7379 points"
@@ -148,26 +161,103 @@ def test_DFTransform_read_write(create_DFPointCloudSampleRoof):
148161
# dfb_registrations namespace
149162
#------------------------------------------------------------------------------
150163
def test_DFRegistration_pure_translation(create_DFPointCloudSphere):
151-
pc = create_DFPointCloudSphere
152-
pc2 = create_DFPointCloudSphere
164+
165+
def make_assertions(df_transformation_result):
166+
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"
170+
171+
pc_1 = create_DFPointCloudSphere
172+
pc_2 = create_DFPointCloudSphere
153173
t = dfb.dfb_transformation.DFTransformation()
154174
t.transformation_matrix = [[1.0, 0.0, 0.0, 20],
155175
[0.0, 1.0, 0.0, 20],
156176
[0.0, 0.0, 1.0, 20],
157177
[0.0, 0.0, 0.0, 1.0]]
158-
pc2.apply_transformation(t)
178+
pc_2.apply_transformation(t)
159179

160-
df_transformation_result = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(pc, pc2)
161-
assert df_transformation_result is not None, "DFRegistration should return a transformation matrix"
162-
assert abs(df_transformation_result.transformation_matrix[0][3] - 20) > 0.5, "The translation in x should be around 20"
163-
assert abs(df_transformation_result.transformation_matrix[1][3] - 20) > 0.5, "The translation in y should be around 20"
164-
assert abs(df_transformation_result.transformation_matrix[2][3] - 20) > 0.5, "The translation in z should be around 20"
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.DFGlobalRegistrations.O3DDICP(pc_1, pc_2)
183+
df_transformation_result_o3dgicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DGeneralizedICP(pc_1, pc_2)
184+
make_assertions(df_transformation_result_o3dfgrfm)
185+
make_assertions(df_transformation_result_o3drfm)
186+
make_assertions(df_transformation_result_o3dicp)
187+
make_assertions(df_transformation_result_o3dgicp)
188+
165189

190+
def test_DFRegistration_pure_rotation():
191+
192+
def make_assertions(df_transformation_result):
193+
assert df_transformation_result is not None, "DFRegistration should return a transformation matrix"
194+
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 "
195+
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"
196+
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"
197+
198+
vertices = [[-1, -1, 0], [1, -1, 0], [1, 1, 0], [-1, 1, 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, [], [], [])
202+
203+
r = dfb.dfb_transformation.DFTransformation()
204+
r.transformation_matrix = [[0.0, 0.0, 1.0, 0.0],
205+
[0.0, 1.0, 0.0, 0.0],
206+
[-1.0, 0.0, 1.0, 0.0],
207+
[0.0, 0.0, 0.0, 1.0]] # 90 degree rotation around y-axis
208+
209+
mesh2.apply_transformation(r)
210+
211+
pc_1 = mesh.sample_points_uniformly(1000)
212+
pc_2 = mesh2.sample_points_uniformly(1000)
213+
214+
df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(pc_1, pc_2)
215+
df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(pc_1, pc_2)
216+
df_transformation_result_o3dicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DDICP(pc_1, pc_2)
217+
df_transformation_result_o3dgicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DGeneralizedICP(pc_1, pc_2)
218+
make_assertions(df_transformation_result_o3dfgrfm)
219+
make_assertions(df_transformation_result_o3drfm)
220+
make_assertions(df_transformation_result_o3dicp)
221+
make_assertions(df_transformation_result_o3dgicp)
222+
223+
def test_DFRegistration_bunny(create_DFPointCloudBunny):
224+
225+
def make_assertions(df_transformation_result):
226+
assert df_transformation_result is not None, "DFRegistration should return a transformation matrix"
227+
assert abs(df_transformation_result.transformation_matrix[0][3] - 0.1) < 0.02, "The translation in x should be around 0.1"
228+
assert abs(df_transformation_result.transformation_matrix[1][3] - 0.2) < 0.02, "The translation in y should be around 0.2"
229+
assert abs(df_transformation_result.transformation_matrix[2][3] + 0.1) < 0.02, "The translation in z should be around -0.1"
230+
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"
231+
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 "
232+
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"$
233+
234+
pc_1 = create_DFPointCloudBunny
235+
pc_2 = create_DFPointCloudBunny
236+
237+
transform = dfb.dfb_transformation.DFTransformation()
238+
transform.transformation_matrix = [[1.0, 0.0, 0.0, 0.1],
239+
[0.0, 0.0, -1.0, 0.2],
240+
[0.0, 1.0, 0.0, -0.1],
241+
[0.0, 0.0, 0.0, 1.0]]
242+
pc_2.apply_transformation(transform)
243+
244+
df_transformation_result_o3dfgrfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DFastGlobalRegistrationFeatureMatching(pc_1, pc_2)
245+
df_transformation_result_o3drfm = dfb.dfb_registrations.DFGlobalRegistrations.O3DRansacOnFeatureMatching(pc_1, pc_2)
246+
df_transformation_result_o3dicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DDICP(pc_1, pc_2)
247+
df_transformation_result_o3dgicp = dfb.dfb_registrations.DFGlobalRegistrations.O3DGeneralizedICP(pc_1, pc_2)
248+
make_assertions(df_transformation_result_o3dfgrfm)
249+
make_assertions(df_transformation_result_o3drfm)
250+
make_assertions(df_transformation_result_o3dicp)
251+
make_assertions(df_transformation_result_o3dgicp)
252+
253+
166254
#------------------------------------------------------------------------------
167255
# dfb_segmentation namespace
168256
#------------------------------------------------------------------------------
169-
# TODO: to be implemented
170257

258+
# vertices = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 1, -1], [0, 0, -1]]
259+
# faces = [[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5]]
260+
# mesh = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], [])
171261

172262
if __name__ == "__main__":
173263
pytest.main()

0 commit comments

Comments
 (0)