99
1010
1111from diffCheck .diffcheck_bindings import dfb_segmentation
12- from diffCheck .diffcheck_bindings import dfb_geometry , dfb_registrations , dfb_transformation
12+ from diffCheck .diffcheck_bindings import dfb_geometry , dfb_registrations
1313
1414from diffCheck import df_cvt_bindings
1515
@@ -24,7 +24,7 @@ def RunScript(self,
2424 i_angle_association_threshold : float ,
2525 i_maximum_face_segment_distance : float ,
2626 i_radius_normal_estimation : float ,
27- i_max_correspondence_distance_icp : float , ):
27+ i_max_correspondence_distance_icp : float ):
2828
2929 if i_clouds is None or i_assembly is None :
3030 self .AddRuntimeMessage (RML .Warning , "Please provide a cloud and an assembly to segment." )
@@ -38,60 +38,17 @@ def RunScript(self,
3838 if i_radius_normal_estimation is None :
3939 i_radius_normal_estimation = 0.01
4040 o_face_clusters = []
41- df_clusters_temp = []
41+ o_transforms = []
4242 df_clusters = []
4343 # we make a deepcopy of the input clouds
44- df_clouds_copy = [df_cvt_bindings .cvt_rhcloud_2_dfcloud (cloud .Duplicate ()) for cloud in i_clouds ]
4544 df_clouds = [df_cvt_bindings .cvt_rhcloud_2_dfcloud (cloud .Duplicate ()) for cloud in i_clouds ]
4645 df_merged_cloud = dfb_geometry .DFPointCloud ()
46+ df_merged_cloud .remove_statistical_outliers (100 , 1.5 )
4747 for pc in df_clouds :
4848 df_merged_cloud .add_points (pc )
4949
5050 df_beams = i_assembly .beams
51- df_asssociated_cluster_faces_per_beam = []
52-
53- for df_b in df_beams :
54- rh_b_mesh_faces = [df_b_f .to_mesh () for df_b_f in df_b .side_faces ]
55- df_b_mesh_faces = [df_cvt_bindings .cvt_rhmesh_2_dfmesh (rh_b_mesh_face ) for rh_b_mesh_face in rh_b_mesh_faces ]
56-
57- # different association depending on the type of beam
58- df_asssociated_cluster_faces = dfb_segmentation .DFSegmentation .associate_clusters (
59- is_roundwood = df_b .is_roundwood ,
60- discriminate_points = True ,
61- reference_mesh = df_b_mesh_faces ,
62- unassociated_clusters = df_clouds_copy ,
63- angle_threshold = i_angle_threshold ,
64- association_threshold = i_association_threshold ,
65- angle_association_threshold = i_angle_association_threshold ,
66- maximum_face_segment_distance = i_maximum_face_segment_distance
67- )
68- df_asssociated_cluster_faces_per_beam .append (df_asssociated_cluster_faces )
69-
70- for i , df_b in enumerate (df_beams ):
71- rh_b_mesh_faces = [df_b_f .to_mesh () for df_b_f in df_b .side_faces ]
72- df_b_mesh_faces = [df_cvt_bindings .cvt_rhmesh_2_dfmesh (rh_b_mesh_face ) for rh_b_mesh_face in rh_b_mesh_faces ]
73-
74- dfb_segmentation .DFSegmentation .clean_unassociated_clusters (
75- is_roundwood = df_b .is_roundwood ,
76- discriminate_points = True ,
77- unassociated_clusters = df_clouds_copy ,
78- associated_clusters = [df_asssociated_cluster_faces_per_beam [i ]],
79- reference_mesh = [df_b_mesh_faces ],
80- angle_threshold = i_angle_threshold ,
81- association_threshold = i_association_threshold ,
82- angle_association_threshold = i_angle_association_threshold ,
83- maximum_face_segment_distance = i_maximum_face_segment_distance
84- )
85-
86- df_asssociated_cluster = dfb_geometry .DFPointCloud ()
87- for df_associated_face in df_asssociated_cluster_faces_per_beam [i ]:
88- df_asssociated_cluster .add_points (df_associated_face )
89-
90- df_clusters_temp .append (df_asssociated_cluster )
9151
92- # Now with the df_clusters, we sample a point cloud on the beam of the assembly, and perform an ICP to align the beam mesh to the point cloud.
93- # Then we re-compute the association on the scan with thigher thresholds to have a better segmentation.
94- o_transforms = []
9552 rh_meshes = []
9653 for i , df_b in enumerate (df_beams ):
9754 rh_b_mesh_faces = [df_b_f .to_mesh () for df_b_f in df_b .side_faces ]
@@ -106,30 +63,22 @@ def RunScript(self,
10663 df_sampled_cloud .estimate_normals (use_cilantro_evaluator = False ,
10764 search_radius = i_radius_normal_estimation ,
10865 )
109- cluster_without_normals = df_clusters_temp [i ]
110- cluster_without_normals .estimate_normals (use_cilantro_evaluator = False ,
111- search_radius = i_radius_normal_estimation ,
112- )
113- df_merged_cloud .remove_statistical_outliers (100 , 1.5 )
114- self .AddRuntimeMessage (RML .Warning , f"size of pc: { cluster_without_normals .get_num_points ()} " )
115- if cluster_without_normals .get_num_points () != 0 :
116- transform = dfb_registrations .DFRefinedRegistration .O3DICP (
117- source = df_sampled_cloud ,
118- target = df_merged_cloud ,
119- max_correspondence_distance = i_max_correspondence_distance_icp ,
120- max_iteration = 1000
12166
67+ transform = dfb_registrations .DFRefinedRegistration .O3DICP (
68+ source = df_sampled_cloud ,
69+ target = df_merged_cloud ,
70+ max_correspondence_distance = i_max_correspondence_distance_icp ,
71+ max_iteration = 1000
12272 )
123- else :
124- transform = dfb_transformation .DFTransformation ()
73+
12574 df_xform = transform .transformation_matrix
12675 rh_xform = Rhino .Geometry .Transform ()
12776 for i in range (4 ):
12877 for j in range (4 ):
12978 rh_xform [i , j ] = df_xform [i , j ]
13079 o_transforms .append (rh_xform )
13180
132- df_new_asssociated_cluster_faces_per_beam = []
81+ df_asssociated_cluster_faces_per_beam = []
13382 for i , df_b in enumerate (df_beams ):
13483 rh_b_mesh_faces = [df_b_f .to_mesh () for df_b_f in df_b .side_faces ]
13584 rh_test_mesh = Rhino .Geometry .Mesh ()
@@ -151,7 +100,7 @@ def RunScript(self,
151100 angle_association_threshold = i_angle_association_threshold ,
152101 maximum_face_segment_distance = i_maximum_face_segment_distance
153102 )
154- df_new_asssociated_cluster_faces_per_beam .append (df_new_asssociated_cluster_faces )
103+ df_asssociated_cluster_faces_per_beam .append (df_new_asssociated_cluster_faces )
155104
156105 for i , df_b in enumerate (df_beams ):
157106 o_face_clusters .append ([])
@@ -164,23 +113,22 @@ def RunScript(self,
164113 is_roundwood = df_b .is_roundwood ,
165114 discriminate_points = True ,
166115 unassociated_clusters = df_clouds ,
167- associated_clusters = [df_new_asssociated_cluster_faces_per_beam [i ]],
116+ associated_clusters = [df_asssociated_cluster_faces_per_beam [i ]],
168117 reference_mesh = [df_b_mesh_faces ],
169118 angle_threshold = i_angle_threshold ,
170119 association_threshold = i_association_threshold ,
171120 angle_association_threshold = i_angle_association_threshold ,
172121 maximum_face_segment_distance = i_maximum_face_segment_distance
173122 )
174123
175- o_face_clusters [- 1 ] = [df_cvt_bindings .cvt_dfcloud_2_rhcloud (cluster ) for cluster in df_new_asssociated_cluster_faces_per_beam [i ]]
124+ o_face_clusters [- 1 ] = [df_cvt_bindings .cvt_dfcloud_2_rhcloud (cluster ) for cluster in df_asssociated_cluster_faces_per_beam [i ]]
176125
177126 df_asssociated_cluster = dfb_geometry .DFPointCloud ()
178- for df_associated_face in df_new_asssociated_cluster_faces_per_beam [i ]:
127+ for df_associated_face in df_asssociated_cluster_faces_per_beam [i ]:
179128 df_asssociated_cluster .add_points (df_associated_face )
180129
181130 df_clusters .append (df_asssociated_cluster )
182131
183- o_beam_intermediary_clouds = [df_cvt_bindings .cvt_dfcloud_2_rhcloud (cluster ) for cluster in df_clusters_temp ]
184132 o_beam_clouds = [df_cvt_bindings .cvt_dfcloud_2_rhcloud (cluster ) for cluster in df_clusters ]
185133
186134 for i , o_beam_cloud in enumerate (o_beam_clouds ):
@@ -190,4 +138,4 @@ def RunScript(self,
190138
191139 o_face_clouds = th .list_to_tree (o_face_clusters )
192140
193- return [o_beam_clouds , o_face_clouds , o_transforms , o_beam_intermediary_clouds , rh_meshes ]
141+ return [o_beam_clouds , o_face_clouds ]
0 commit comments