Skip to content

Commit 40a1a80

Browse files
committed
FIX: convertion functions mesh point clouds are not working
1 parent 2cb8141 commit 40a1a80

File tree

7 files changed

+162
-112
lines changed

7 files changed

+162
-112
lines changed

src/gh/components/DF_load_cloud_from_file/code.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import diffCheck
1313
from diffCheck import diffcheck_bindings
14+
import diffCheck.df_cvt_bindings
1415

1516
class DFLoadCloudFromFile(component):
1617
def RunScript(self,
@@ -27,8 +28,7 @@ def RunScript(self,
2728
# import and convert to rhino cloud
2829
df_cloud = diffcheck_bindings.dfb_geometry.DFPointCloud()
2930
df_cloud.load_from_PLY(i_path)
30-
rgpoints = [rg.Point3d(pt[0], pt[1], pt[2]) for pt in df_cloud.points]
31-
rh_cloud = rg.PointCloud(rgpoints)
31+
rh_cloud = diffCheck.df_cvt_bindings.cvt_dfcloud_2_rhcloud(df_cloud)
3232

3333
# scale if needed
3434
centroid = rh_cloud.GetBoundingBox(True).Center

src/gh/components/DF_load_mesh_from_file/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ def RunScript(self,
4949
# if __name__ == "__main__":
5050
# com = DFLoadMeshFromFile()
5151
# o_rh_mesh = com.RunScript(
52-
# i_path,
52+
# i_path,n
5353
# i_scalef
5454
# )

src/gh/components/DF_xml_exporter/code.py

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,52 @@ def RunScript(self,
2626
:param i_breps: list of breps
2727
"""
2828
# beams
29-
beams: typing.List[DFBeam] = []
30-
for brep in i_breps:
31-
beam = DFBeam.from_brep(brep)
32-
beams.append(beam)
29+
# beams: typing.List[DFBeam] = []
30+
# for brep in i_breps:
31+
# beam = DFBeam.from_brep(brep)
32+
# beams.append(beam)
3333

34-
# assembly
35-
assembly1 = DFAssembly(beams, i_assembly_name)
34+
# # assembly
35+
# assembly1 = DFAssembly(beams, i_assembly_name)
3636

37-
# dump the xml
38-
xml: str = assembly1.to_xml()
39-
if i_dump:
40-
assembly1.dump_xml(xml, i_export_dir)
41-
o_xml = xml
37+
# # dump the xml
38+
# xml: str = assembly1.to_xml()
39+
# if i_dump:
40+
# assembly1.dump_xml(xml, i_export_dir)
41+
# o_xml = xml
4242

43-
# show the joint/side faces
44-
o_joints = [jf.to_brep() for jf in assembly1.all_joint_faces]
45-
o_sides = [sf.to_brep() for sf in assembly1.all_side_faces]
43+
# # show the joint/side faces
44+
# o_joints = [jf.to_brep() for jf in assembly1.all_joint_faces]
45+
# o_sides = [sf.to_brep() for sf in assembly1.all_side_faces]
4646

47-
return o_xml, o_joints, o_sides
47+
###########################
48+
49+
faces, o_debug = diffCheck.df_joint_detector.JointDetector(i_breps[0]).run()
50+
51+
# o_joints = [f.to_brep() for f in faces]
52+
# o_sides = [f.to_brep() for f in faces]
53+
54+
o_xml = ""
55+
o_joints = []
56+
o_sides = []
57+
58+
for f in faces:
59+
if f[1] != None:
60+
o_joints.append(f[0])
61+
else:
62+
o_sides.append(f[0])
63+
64+
65+
66+
67+
return o_xml, o_joints, o_sides, o_debug
68+
69+
70+
if __name__ == "__main__":
71+
com = DFXMLExporter()
72+
o_xml, o_joints, o_sides, o_debug = com.RunScript(
73+
i_dump,
74+
i_assembly_name,
75+
i_export_dir,
76+
i_breps
77+
)
Binary file not shown.

src/gh/diffCheck/diffCheck/df_cvt_bindings.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ def cvt_dfcloud_2_rhcloud(df_cloud):
6161
df_cloud_normals = df_cloud.normals
6262

6363
df_cloud_points = [rg.Point3d(pt[0], pt[1], pt[2]) for pt in df_cloud_points]
64-
64+
df_cloud_normals = [rg.Vector3d(n[0], n[1], n[2]) for n in df_cloud_normals]
65+
df_cloud_colors = [Rhino.Display.Color4f(c[0], c[1], c[2], 1.0) for c in df_cloud_colors]
66+
6567
rh_cloud = rg.PointCloud()
6668

6769
if df_cloud.has_normals() and df_cloud.has_colors():
@@ -98,8 +100,8 @@ def cvt_dfmesh_2_rhmesh(df_mesh: diffcheck_bindings.dfb_geometry.DFMesh) -> rg.M
98100

99101
# faces
100102
for face in df_mesh.faces:
101-
print(face)
102-
rh_mesh.Faces.AddFace(face[0], face[1], face[2])
103+
int_face = [int(f) for f in face]
104+
rh_mesh.Faces.AddFace(int_face[0], int_face[1], int_face[2])
103105

104106
# normals
105107
if len(df_mesh.normals_vertex) > 0:

src/gh/diffCheck/diffCheck/df_joint_detector.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
1212

13+
# import numpy as np
14+
1315

1416
@dataclass
1517
class JointDetector:
@@ -29,13 +31,29 @@ def __post_init__(self):
2931
# list of DFFaces from joints and sides
3032
self._faces = []
3133

34+
# debug list of various geometries
35+
self._debug = []
36+
3237
def _compute_mass_center(self, b_face: rg.BrepFace) -> rg.Point3d:
3338
"""
34-
Compute the mass center of a brep face
39+
Compute the mass center of a brep face in 3d space
3540
3641
:param b_face: The brep face to compute the mass center from
3742
:return mass_center: The mass center of the brep face
3843
"""
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+
3957
amp = rg.AreaMassProperties.Compute(b_face)
4058
if amp:
4159
return amp.Centroid
@@ -86,7 +104,6 @@ def run(self) :
86104
if not f.IsPlanar():
87105
is_cut = False
88106
is_hole = True
89-
90107
b_faces = diffCheck.df_util.explode_brep(b)
91108
for b_face in b_faces:
92109
if b_face.Faces[0].IsPlanar():
@@ -167,13 +184,17 @@ def run(self) :
167184
# 3. Sort faces from joints and faces from sides
168185
############################################################################
169186
# retransform back everything
170-
for b in self._holes:
171-
b.Transform(x_form_back)
172-
for b in self._cuts:
173-
b.Transform(x_form_back)
174-
for b in self._mix:
175-
b.Transform(x_form_back)
176-
self.brep.Transform(x_form_back)
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)
177198

178199
# get all the medians of the faces of cuts only
179200
cuts_faces_centroids : typing.Dict[int, typing.List[rg.Point3d]] = {}
@@ -183,6 +204,7 @@ def run(self) :
183204
for f in b.Faces:
184205
centroid = self._compute_mass_center(f)
185206
temp_face_centroids.append(centroid)
207+
self._debug.append(centroid)
186208
cuts_faces_centroids[idx] = temp_face_centroids
187209

188210
# compare with the brep medians faces to get the joint/sides's faces
@@ -203,4 +225,4 @@ def run(self) :
203225
if self._faces is None or len(self._faces) == 0:
204226
ghenv.Component.AddRuntimeMessage(RML.Error, "No faces found after joint detection.")
205227

206-
return self._faces
228+
return self._faces, self._debug

src/gh/examples/tester.ghx

Lines changed: 77 additions & 81 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)