@@ -41,6 +41,13 @@ def get_ply_cloud_bunny_path():
4141 raise FileNotFoundError (f"PLY file not found at: { ply_file_path } " )
4242 return ply_file_path
4343
44+ def get_ply_mesh_cube_path ():
45+ base_test_data_dir = os .getenv ('DF_TEST_DATA_DIR' , os .path .abspath (os .path .join (os .path .dirname (__file__ ), '..' , '..' , 'test_data' )))
46+ ply_file_path = os .path .join (base_test_data_dir , "cube_mesh.ply" )
47+ if not os .path .exists (ply_file_path ):
48+ raise FileNotFoundError (f"PLY file not found at: { ply_file_path } " )
49+ return ply_file_path
50+
4451#------------------------------------------------------------------------------
4552# dfb_geometry namespace
4653#------------------------------------------------------------------------------
@@ -84,6 +91,13 @@ def create_two_DFPointCloudBunny():
8491 df_pcd_2 .load_from_PLY (get_ply_cloud_bunny_path ())
8592 yield df_pcd_1 , df_pcd_2
8693
94+ @pytest .fixture
95+ def create_DFMeshCube ():
96+ df_mesh = dfb .dfb_geometry .DFMesh ()
97+ df_mesh .load_from_PLY (get_ply_mesh_cube_path ())
98+ yield df_mesh
99+
100+
87101def test_DFPointCloud_properties (create_DFPointCloudSampleRoof ):
88102 pc = create_DFPointCloudSampleRoof
89103 assert pc .points .__len__ () == 7379 , "DFPointCloud should have 7379 points"
@@ -132,9 +146,33 @@ def test_DFPointCloud_get_tight_bounding_box(create_DFPointCloudSampleRoof):
132146 # round to the 3 decimal places
133147 assert round (obb [0 ][0 ], 3 ) == 0.196 , "The min x of the OBB should be 0.196"
134148
135- # TODO: to implement DFMesh tests
136149def test_DFMesh_init ():
137- pass
150+ mesh = dfb .dfb_geometry .DFMesh ()
151+ assert mesh is not None , "DFMesh should be initialized successfully"
152+
153+ def test_DFMesh_load_from_PLY (create_DFMeshCube ):
154+ mesh = create_DFMeshCube
155+ assert mesh .vertices .__len__ () == 726 , "DFMesh should have 726 vertices"
156+ assert mesh .faces .__len__ () == 1200 , "DFMesh should have 800 faces"
157+
158+ def test_DFMesh_sample_points (create_DFMeshCube ):
159+ mesh = create_DFMeshCube
160+ pc = mesh .sample_points_uniformly (1000 )
161+ assert pc .points .__len__ () == 1000 , "DFPointCloud should have 1000 points"
162+
163+ def test_DFMesh_compute_bounding_box (create_DFMeshCube ):
164+ mesh = create_DFMeshCube
165+ obb = mesh .get_tight_bounding_box ()
166+ assert obb [0 ][0 ] == 0 , "The x coordinate of the first corner of the OBB should be 0"
167+ assert obb [1 ][0 ] == 100 , "The y coordinate of the second corner of the OBB should be 100"
168+ assert obb [2 ][0 ] == 0 , "The y coordinate of the third corner of the OBB should be 0"
169+ assert obb [6 ][2 ] == 100 , "The z coordinate of the second to last corner of the OBB should be 100"
170+
171+ def test_DFMesh_getters (create_DFMeshCube ):
172+ mesh = create_DFMeshCube
173+ assert mesh .get_num_vertices () == 726 , "get_num_vertices() should return 726"
174+ assert mesh .get_num_faces () == 1200 , "get_num_faces() should return 1200"
175+
138176
139177#------------------------------------------------------------------------------
140178# dfb_transformation namespace
@@ -257,9 +295,27 @@ def make_assertions(df_transformation_result):
257295# dfb_segmentation namespace
258296#------------------------------------------------------------------------------
259297
260- # vertices = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 1, -1], [0, 0, -1]]
261- # faces = [[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5]]
262- # mesh = dfb.dfb_geometry.DFMesh(vertices, faces, [], [], [])
298+ def test_DFPlaneSegmentation ():
299+ vertices = [[0 , 0 , 0 ], [1 , 0 , 0 ], [1 , 1 , 0 ], [0 , 1 , 0 ], [0 , 1 , - 1 ], [0 , 0 , - 1 ]]
300+ faces = [[0 , 1 , 2 ], [0 , 2 , 3 ], [0 , 3 , 4 ], [0 , 4 , 5 ]]
301+ mesh = dfb .dfb_geometry .DFMesh (vertices , faces , [], [], [])
302+ pc = mesh .sample_points_uniformly (1000 )
303+ pc .estimate_normals (knn = 200 )
304+
305+ segments = dfb .dfb_segmentation .DFSegmentation .segment_by_normal (pc , min_cluster_size = 250 )
306+
307+ assert len (segments ) == 2 , "DFPlaneSegmentation should return 2 segments"
308+
309+ def test_DFPlaneSegmentation_disconnected_plans ():
310+ vertices = [[0 , 0 , 0 ], [1 , 0 , 0 ], [1 , 1 , 0 ], [0 , 1 , 0 ], [0 , 1 , - 1 ], [0 , 0 , - 1 ]]
311+ faces = [[0 , 1 , 2 ], [3 , 4 , 5 ]]
312+ mesh = dfb .dfb_geometry .DFMesh (vertices , faces , [], [], [])
313+ pc = mesh .sample_points_uniformly (1000 )
314+ pc .estimate_normals (knn = 200 )
315+
316+ segments = dfb .dfb_segmentation .DFSegmentation .segment_by_normal (pc , min_cluster_size = 250 )
317+
318+ assert len (segments ) == 2 , "DFPlaneSegmentation should return 2 segments"
263319
264320if __name__ == "__main__" :
265321 pytest .main ()
0 commit comments