Skip to content

Commit 2fdef56

Browse files
brep to cloud component (#107)
* WIP-ADD: create component for bre2cloud conversion * FIX-UPDATE: DFMeshToCloud component returns one single point cloud * WIP: working on corrections * CAP-FIX: finsihed cleaning minor + docuemtnation --------- Co-authored-by: Andrea Settimi <andreasettimi39@gmail.com>
1 parent 07c2aef commit 2fdef56

File tree

7 files changed

+130
-12
lines changed

7 files changed

+130
-12
lines changed

doc/gh_DFBrepToCloud.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. image:: ../src/gh/components/DF_brep_to_cloud/icon.png
2+
:align: left
3+
:width: 40px
4+
5+
``DFBrepToCloud`` component
6+
===========================
7+
8+
.. ghcomponent_to_rst:: ../src/gh/components/DF_brep_to_cloud

doc/gh_components.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ DF has a Grasshopper_ plugin with a set of components that allows the user to in
7676
- .. image:: ../src/gh/components/DF_colorize_cloud/icon.png
7777
- `gh_DFColorizeCloud <gh_DFColorizeCloud.html>`_
7878

79+
* - .. image:: ../src/gh/components/DF_brep_to_cloud/icon.png
80+
- `gh_DFBrepToCloud <gh_DFBrepToCloud.html>`_
81+
-
82+
-
83+
7984

8085

8186
.. toctree::
@@ -107,4 +112,5 @@ DF has a Grasshopper_ plugin with a set of components that allows the user to in
107112
gh_DFXMLExporter
108113
gh_DFPreviewAssembly
109114
gh_DFRemoveBeam
110-
gh_DFColorizeCloud
115+
gh_DFColorizeCloud
116+
gh_DFBrepToCloud
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#! python3
2+
3+
import Rhino
4+
from ghpythonlib.componentbase import executingcomponent as component
5+
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
6+
7+
from diffCheck import df_cvt_bindings
8+
import System
9+
10+
11+
class DFBrepToCloud(component):
12+
def RunScript(self,
13+
i_breps: System.Collections.Generic.IList[Rhino.Geometry.Brep],
14+
i_num_points: int):
15+
self.meshing_parameters = Rhino.Geometry.MeshingParameters.DefaultAnalysisMesh
16+
17+
mesh_versions = []
18+
19+
if i_breps is None or i_num_points is None:
20+
return None
21+
22+
for i_brep in i_breps:
23+
if not isinstance(i_brep, Rhino.Geometry.Brep):
24+
self.AddRuntimeMessage(RML.Warning, "Please provide a brep to convert to a cloud")
25+
return None
26+
meshes = Rhino.Geometry.Mesh.CreateFromBrep(i_brep, self.meshing_parameters)
27+
for mesh in meshes:
28+
mesh_versions.append(mesh)
29+
30+
unified_mesh = mesh_versions[0]
31+
unified_mesh.Append(mesh_versions)
32+
unified_mesh.Faces.ConvertQuadsToTriangles()
33+
df_mesh = df_cvt_bindings.cvt_rhmesh_2_dfmesh(unified_mesh)
34+
df_cloud = df_mesh.sample_points_uniformly(i_num_points)
35+
rgpoints = [Rhino.Geometry.Point3d(pt[0], pt[1], pt[2]) for pt in df_cloud.points]
36+
rh_cloud = Rhino.Geometry.PointCloud(rgpoints)
37+
print(rh_cloud)
38+
return [rh_cloud]
12.6 KB
Loading
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "DFBrepToMesh",
3+
"nickname": "DFBrepToMesh",
4+
"category": "diffCheck",
5+
"subcategory": "Cloud",
6+
"description": "Create unique point cloud from list of breps.",
7+
"exposure": 4,
8+
"instanceGuid": "0194cbfc-1a6d-44a7-ae5d-7495db20edbe",
9+
"ghpython": {
10+
"hideOutput": true,
11+
"hideInput": true,
12+
"isAdvancedMode": true,
13+
"marshalOutGuids": true,
14+
"iconDisplay": 2,
15+
"inputParameters": [
16+
{
17+
"name": "i_breps",
18+
"nickname": "i_breps",
19+
"description": "The breps to convert to point cloud.",
20+
"optional": false,
21+
"allowTreeAccess": false,
22+
"showTypeHints": true,
23+
"scriptParamAccess": "list",
24+
"wireDisplay": "default",
25+
"sourceCount": 0,
26+
"typeHintID": "brep"
27+
},
28+
{
29+
"name": "i_num_points",
30+
"nickname": "i_num_points",
31+
"description": "The number of points in the new point cloud.",
32+
"optional": false,
33+
"allowTreeAccess": false,
34+
"showTypeHints": true,
35+
"scriptParamAccess": "item",
36+
"wireDisplay": "default",
37+
"sourceCount": 0,
38+
"typeHintID": "int"
39+
}
40+
],
41+
"outputParameters": [
42+
{
43+
"name": "o_pointcloud",
44+
"nickname": "o_pointcloud",
45+
"description": "The generated point cloud.",
46+
"optional": false,
47+
"sourceCount": 0,
48+
"graft": false
49+
}
50+
]
51+
}
52+
}
Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#! python3
22

3+
import System
34

4-
import Rhino.Geometry as rg
5+
import Rhino
56
from ghpythonlib.componentbase import executingcomponent as component
67

78

@@ -12,13 +13,26 @@
1213

1314
class DFMeshToCloud(component):
1415
def RunScript(self,
15-
i_mesh: rg.Mesh,
16-
i_points: int) -> rg.PointCloud:
17-
df_mesh = diffCheck.df_cvt_bindings.cvt_rhmesh_2_dfmesh(i_mesh)
18-
df_cloud = df_mesh.sample_points_uniformly(i_points)
16+
i_meshes:System.Collections.Generic.IList[Rhino.Geometry.Mesh],
17+
i_points: int) -> Rhino.Geometry.PointCloud:
18+
19+
if i_meshes is None:
20+
return None
21+
22+
if i_points is None:
23+
i_points = 1000
1924

25+
rh_mesh = i_meshes[0]
26+
for i in range(1, len(i_meshes)):
27+
if i_meshes[i] is None:
28+
return None
29+
rh_mesh.Append(i_meshes[i])
30+
rh_mesh.Faces.ConvertQuadsToTriangles()
31+
32+
df_mesh = diffCheck.df_cvt_bindings.cvt_rhmesh_2_dfmesh(rh_mesh)
33+
df_cloud = df_mesh.sample_points_uniformly(i_points)
34+
rgpoints = [Rhino.Geometry.Point3d(p[0], p[1], p[2]) for p in df_cloud.points]
2035
# convert the df_cloud to a rhino cloud
21-
rgpoints = [rg.Point3d(pt[0], pt[1], pt[2]) for pt in df_cloud.points]
22-
rh_cloud = rg.PointCloud(rgpoints)
36+
rh_cloud = Rhino.Geometry.PointCloud(rgpoints)
2337

2438
return [rh_cloud]

src/gh/components/DF_mesh_to_cloud/metadata.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
"iconDisplay": 2,
1515
"inputParameters": [
1616
{
17-
"name": "i_mesh",
18-
"nickname": "i_mesh",
19-
"description": "Mesh to sample into a point cloud.",
17+
"name": "i_meshes",
18+
"nickname": "i_meshes",
19+
"description": "Meshes to sample into a point cloud.",
2020
"optional": true,
2121
"allowTreeAccess": true,
2222
"showTypeHints": true,
23-
"scriptParamAccess": "item",
23+
"scriptParamAccess": "list",
2424
"wireDisplay": "default",
2525
"sourceCount": 0,
2626
"typeHintID": "mesh"

0 commit comments

Comments
 (0)