-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcode.py
More file actions
81 lines (59 loc) · 3.11 KB
/
code.py
File metadata and controls
81 lines (59 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#! python3
import System
import Rhino
from ghpythonlib.componentbase import executingcomponent as component
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
import ghpythonlib.treehelpers as th
from diffCheck.diffcheck_bindings import dfb_segmentation
from diffCheck.diffcheck_bindings import dfb_geometry
from diffCheck import df_cvt_bindings
class DFCADSegmentator(component):
def RunScript(self,
i_clouds: System.Collections.Generic.IList[Rhino.Geometry.PointCloud],
i_assembly,
i_angle_threshold: float = 0.1,
i_association_threshold: float = 0.1):
if i_clouds is None or i_assembly is None:
self.AddRuntimeMessage(RML.Warning, "Please provide a cloud and an assembly to segment.")
return None
if i_angle_threshold is None:
i_angle_threshold = 0.1
if i_association_threshold is None:
i_association_threshold = 0.1
o_face_clusters = []
df_clusters = []
# we make a deepcopy of the input clouds
df_clouds = [df_cvt_bindings.cvt_rhcloud_2_dfcloud(cloud.Duplicate()) for cloud in i_clouds]
df_beams = i_assembly.beams
for df_b in df_beams:
o_face_clusters.append([])
rh_b_mesh_faces = [df_b_f.to_mesh() for df_b_f in df_b.side_faces]
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]
# different association depending on the type of beam
df_asssociated_cluster_faces = dfb_segmentation.DFSegmentation.associate_clusters(
is_roundwood=df_b.is_roundwood,
reference_mesh=df_b_mesh_faces,
unassociated_clusters=df_clouds,
angle_threshold=i_angle_threshold,
association_threshold=i_association_threshold
)
dfb_segmentation.DFSegmentation.clean_unassociated_clusters(
is_roundwood=df_b.is_roundwood,
unassociated_clusters=df_clouds,
associated_clusters=[df_asssociated_cluster_faces],
reference_mesh=[df_b_mesh_faces],
angle_threshold=i_angle_threshold,
association_threshold=i_association_threshold
)
o_face_clusters[-1] = [df_cvt_bindings.cvt_dfcloud_2_rhcloud(cluster) for cluster in df_asssociated_cluster_faces]
df_asssociated_cluster = dfb_geometry.DFPointCloud()
for df_associated_face in df_asssociated_cluster_faces:
df_asssociated_cluster.add_points(df_associated_face)
df_clusters.append(df_asssociated_cluster)
o_beam_clouds = [df_cvt_bindings.cvt_dfcloud_2_rhcloud(cluster) for cluster in df_clusters]
for i, o_beam_cloud in enumerate(o_beam_clouds):
if not o_beam_cloud.IsValid:
o_beam_clouds[i] = None
ghenv.Component.AddRuntimeMessage(RML.Warning, "Some beams could not be segmented and were replaced by 'None'") # noqa: F821
o_face_clouds = th.list_to_tree(o_face_clusters)
return [o_beam_clouds, o_face_clouds]