@@ -48,6 +48,20 @@ def get_ply_mesh_cube_path():
4848 raise FileNotFoundError (f"PLY file not found at: { ply_file_path } " )
4949 return ply_file_path
5050
51+ def get_two_separate_planes_ply_path ():
52+ base_test_data_dir = os .getenv ('DF_TEST_DATA_DIR' , os .path .abspath (os .path .join (os .path .dirname (__file__ ), '..' , '..' , 'test_data' )))
53+ ply_file_path = os .path .join (base_test_data_dir , "two_separate_planes_with_normals.ply" )
54+ if not os .path .exists (ply_file_path ):
55+ raise FileNotFoundError (f"PLY file not found at: { ply_file_path } " )
56+ return ply_file_path
57+
58+ def get_two_connected_planes_ply_path ():
59+ base_test_data_dir = os .getenv ('DF_TEST_DATA_DIR' , os .path .abspath (os .path .join (os .path .dirname (__file__ ), '..' , '..' , 'test_data' )))
60+ ply_file_path = os .path .join (base_test_data_dir , "two_connected_planes_with_normals.ply" )
61+ if not os .path .exists (ply_file_path ):
62+ raise FileNotFoundError (f"PLY file not found at: { ply_file_path } " )
63+ return ply_file_path
64+
5165#------------------------------------------------------------------------------
5266# dfb_geometry namespace
5367#------------------------------------------------------------------------------
@@ -91,6 +105,18 @@ def create_two_DFPointCloudBunny():
91105 df_pcd_2 .load_from_PLY (get_ply_cloud_bunny_path ())
92106 yield df_pcd_1 , df_pcd_2
93107
108+ @pytest .fixture
109+ def create_DFPointCloudTwoSeparatePlanes ():
110+ df_pcd = dfb .dfb_geometry .DFPointCloud ()
111+ df_pcd .load_from_PLY (get_two_separate_planes_ply_path ())
112+ yield df_pcd
113+
114+ @pytest .fixture
115+ def create_DFPointCloudTwoConnectedPlanes ():
116+ df_pcd = dfb .dfb_geometry .DFPointCloud ()
117+ df_pcd .load_from_PLY (get_two_connected_planes_ply_path ())
118+ yield df_pcd
119+
94120@pytest .fixture
95121def create_DFMeshCube ():
96122 df_mesh = dfb .dfb_geometry .DFMesh ()
@@ -346,32 +372,24 @@ def make_assertions(df_transformation_result):
346372# dfb_segmentation namespace
347373#------------------------------------------------------------------------------
348374
349- def test_DFPlaneSegmentation ():
350- vertices = [[0 , 0 , 0 ], [1 , 0 , 0 ], [1 , 1 , 0 ], [0 , 1 , 0 ], [0 , 1 , - 1 ], [0 , 0 , - 1 ]]
351- faces = [[0 , 1 , 2 ], [0 , 2 , 3 ], [0 , 3 , 4 ], [0 , 4 , 5 ]]
352- mesh = dfb .dfb_geometry .DFMesh (vertices , faces , [], [], [])
353- pc = mesh .sample_points_uniformly (5000 )
354- pc .estimate_normals (knn = 20 )
375+ def test_DFPlaneSegmentation_separate_plans (create_DFPointCloudTwoSeparatePlanes ):
376+ pc = create_DFPointCloudTwoSeparatePlanes
355377
356378 segments = dfb .dfb_segmentation .DFSegmentation .segment_by_normal (pc ,
357379 normal_threshold_degree = 5 ,
358- min_cluster_size = 1000 ,
359- knn_neighborhood_size = 200 )
380+ min_cluster_size = 100 ,
381+ knn_neighborhood_size = 20 )
360382
361383 assert len (segments ) == 2 , "DFPlaneSegmentation should return 2 segments"
362384
363- def test_DFPlaneSegmentation_disconnected_plans ():
364- vertices = [[0 , 0 , 0 ], [1 , 0 , 0 ], [1 , 1 , 0 ], [0 , 1 , 0 ], [0 , 1 , - 1 ], [0 , 0 , - 1 ]]
365- faces = [[0 , 1 , 2 ], [3 , 4 , 5 ]]
366- mesh = dfb .dfb_geometry .DFMesh (vertices , faces , [], [], [])
367- pc = mesh .sample_points_uniformly (5000 )
368- pc .estimate_normals (knn = 20 )
385+ def test_DFPlaneSegmentation_connected_plans (create_DFPointCloudTwoConnectedPlanes ):
386+ pc = create_DFPointCloudTwoConnectedPlanes
369387
370388 segments = dfb .dfb_segmentation .DFSegmentation .segment_by_normal (pc ,
371389 normal_threshold_degree = 5 ,
372- min_cluster_size = 1000 ,
373- knn_neighborhood_size = 200 )
374-
390+ min_cluster_size = 100 ,
391+ knn_neighborhood_size = 20 )
392+
375393 assert len (segments ) == 2 , "DFPlaneSegmentation should return 2 segments"
376394
377395if __name__ == "__main__" :
0 commit comments