55import Rhino
66from ghpythonlib .componentbase import executingcomponent as component
77from Grasshopper .Kernel import GH_RuntimeMessageLevel as RML
8+ import ghpythonlib .treehelpers as th
89
910
1011from diffCheck .diffcheck_bindings import dfb_segmentation
@@ -19,7 +20,7 @@ def RunScript(self,
1920 i_clouds : System .Collections .Generic .IList [Rhino .Geometry .PointCloud ],
2021 i_assembly ,
2122 i_angle_threshold : float = 0.1 ,
22- i_association_threshold : float = 0.1 ) -> Rhino . Geometry . PointCloud :
23+ i_association_threshold : float = 0.1 ):
2324
2425 if i_clouds is None or i_assembly is None :
2526 self .AddRuntimeMessage (RML .Warning , "Please provide a cloud and an assembly to segment." )
@@ -29,7 +30,8 @@ def RunScript(self,
2930 if i_association_threshold is None :
3031 i_association_threshold = 0.1
3132
32- o_clusters = []
33+ o_aggregated_clusters = []
34+ o_face_clusters = []
3335 df_clusters = []
3436 # we make a deepcopy of the input clouds
3537 df_clouds = [df_cvt_bindings .cvt_rhcloud_2_dfcloud (cloud .Duplicate ()) for cloud in i_clouds ]
@@ -39,6 +41,8 @@ def RunScript(self,
3941 rh_beams_meshes = []
4042
4143 for df_b in df_beams :
44+ o_face_clusters .append ([])
45+
4246 rh_b_mesh_faces = [df_b_f .to_mesh () for df_b_f in df_b .side_faces ]
4347 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 ]
4448 df_beams_meshes .append (df_b_mesh_faces )
@@ -53,27 +57,30 @@ def RunScript(self,
5357 association_threshold = i_association_threshold
5458 )
5559
56- df_asssociated_cluster = dfb_geometry .DFPointCloud ()
57- for df_associated_face in df_asssociated_cluster_faces :
58- df_asssociated_cluster .add_points (df_associated_face )
59-
6060 dfb_segmentation .DFSegmentation .clean_unassociated_clusters (
6161 is_roundwood = df_b .is_roundwood ,
6262 unassociated_clusters = df_clouds ,
63- associated_clusters = [df_asssociated_cluster ],
63+ associated_clusters = [df_asssociated_cluster_faces ],
6464 reference_mesh = [df_b_mesh_faces ],
6565 angle_threshold = i_angle_threshold ,
6666 association_threshold = i_association_threshold
6767 )
6868
69+ o_face_clusters [- 1 ] = [df_cvt_bindings .cvt_dfcloud_2_rhcloud (cluster ) for cluster in df_asssociated_cluster_faces ]
70+
71+ df_asssociated_cluster = dfb_geometry .DFPointCloud ()
72+ for df_associated_face in df_asssociated_cluster_faces :
73+ df_asssociated_cluster .add_points (df_associated_face )
74+
6975 df_clusters .append (df_asssociated_cluster )
7076
71- o_clusters = [df_cvt_bindings .cvt_dfcloud_2_rhcloud (cluster ) for cluster in df_clusters ]
77+ o_aggregated_clusters = [df_cvt_bindings .cvt_dfcloud_2_rhcloud (cluster ) for cluster in df_clusters ]
7278
73- for o_cluster in o_clusters :
74- if not o_cluster .IsValid :
75- o_cluster = None
79+ for o_aggregated_cluster in o_aggregated_clusters :
80+ if not o_aggregated_cluster .IsValid :
81+ o_aggregated_cluster = None
7682 ghenv .Component .AddRuntimeMessage (RML .Warning , "Some beams could not be segmented and were replaced by 'None'" ) # noqa: F821
7783
84+ o_face_clusters = th .list_to_tree (o_face_clusters )
7885
79- return o_clusters
86+ return o_aggregated_clusters , o_face_clusters
0 commit comments