1+
12import Rhino
23import scriptcontext as sc
34import Rhino .Geometry as rg
1011
1112from Grasshopper .Kernel import GH_RuntimeMessageLevel as RML
1213
13- # import numpy as np
14-
1514
1615@dataclass
1716class JointDetector :
@@ -31,29 +30,12 @@ def __post_init__(self):
3130 # list of DFFaces from joints and sides
3231 self ._faces = []
3332
34- # debug list of various geometries
35- self ._debug = []
36-
3733 def _compute_mass_center (self , b_face : rg .BrepFace ) -> rg .Point3d :
3834 """
39- Compute the mass center of a brep face in 3d space
40-
35+ Compute the mass center of a brep face
4136 :param b_face: The brep face to compute the mass center from
4237 :return mass_center: The mass center of the brep face
4338 """
44- # vertices = b_face.DuplicateFace(False).DuplicateVertices()
45-
46- # points_x = [v.X for v in vertices]
47- # points_y = [v.Y for v in vertices]
48- # points_z = [v.Z for v in vertices]
49- # points_xyz = np.array([points_x, points_y, points_z])
50-
51-
52- # centroid = np.mean(points_xyz, axis=1)
53-
54- # return rg.Point3d(centroid[0], centroid[1], centroid[2])
55-
56-
5739 amp = rg .AreaMassProperties .Compute (b_face )
5840 if amp :
5941 return amp .Centroid
@@ -62,7 +44,6 @@ def _compute_mass_center(self, b_face: rg.BrepFace) -> rg.Point3d:
6244 def run (self ) :
6345 """
6446 Run the joint detector
65-
6647 :return: a list of faces from joins and faces
6748 """
6849 ############################################################################
@@ -104,6 +85,7 @@ def run(self) :
10485 if not f .IsPlanar ():
10586 is_cut = False
10687 is_hole = True
88+
10789 b_faces = diffCheck .df_util .explode_brep (b )
10890 for b_face in b_faces :
10991 if b_face .Faces [0 ].IsPlanar ():
@@ -129,7 +111,7 @@ def run(self) :
129111 is_hole = False
130112 is_cut = False
131113 is_mix = False
132-
114+
133115 # deal with mix
134116 candidate_cuts = []
135117 candidate_holes = []
@@ -152,10 +134,10 @@ def run(self) :
152134 flat_faces_b .append (f_b )
153135 else :
154136 non_flat_faces_b .append (f_b )
155-
137+
156138 # (*) cap the cylinders
157139 non_flat_faces_b = [f_b .CapPlanarHoles (sc .doc .ModelAbsoluteTolerance ) for f_b in non_flat_faces_b ]
158-
140+
159141 # (4) boolunion every object in both lists
160142 flat_faces_b = Rhino .Geometry .Brep .CreateBooleanUnion (flat_faces_b , sc .doc .ModelAbsoluteTolerance )
161143 non_flat_faces_b = Rhino .Geometry .Brep .CreateBooleanUnion (non_flat_faces_b , sc .doc .ModelAbsoluteTolerance )
@@ -184,17 +166,13 @@ def run(self) :
184166 # 3. Sort faces from joints and faces from sides
185167 ############################################################################
186168 # retransform back everything
187- # for b in self._holes:
188- # b.Transform(x_form_back)
189- # for b in self._cuts:
190- # b.Transform(x_form_back)
191- # for b in self._mix:
192- # b.Transform(x_form_back)
193- # self.brep.Transform(x_form_back)
194-
195- # TODO: get rid debugging
196- # bbox_b.Transform(x_form_back)
197- self ._debug .append (bbox_b )
169+ for b in self ._holes :
170+ b .Transform (x_form_back )
171+ for b in self ._cuts :
172+ b .Transform (x_form_back )
173+ for b in self ._mix :
174+ b .Transform (x_form_back )
175+ self .brep .Transform (x_form_back )
198176
199177 # get all the medians of the faces of cuts only
200178 cuts_faces_centroids : typing .Dict [int , typing .List [rg .Point3d ]] = {}
@@ -204,7 +182,6 @@ def run(self) :
204182 for f in b .Faces :
205183 centroid = self ._compute_mass_center (f )
206184 temp_face_centroids .append (centroid )
207- self ._debug .append (centroid )
208185 cuts_faces_centroids [idx ] = temp_face_centroids
209186
210187 # compare with the brep medians faces to get the joint/sides's faces
@@ -225,4 +202,4 @@ def run(self) :
225202 if self ._faces is None or len (self ._faces ) == 0 :
226203 ghenv .Component .AddRuntimeMessage (RML .Error , "No faces found after joint detection." )
227204
228- return self ._faces , self . _debug
205+ return self ._faces
0 commit comments