Skip to content

Commit

Permalink
brep to cloud component (#107)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
DamienGilliard and 9and3 authored Sep 20, 2024
1 parent 07c2aef commit 2fdef56
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 12 deletions.
8 changes: 8 additions & 0 deletions doc/gh_DFBrepToCloud.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. image:: ../src/gh/components/DF_brep_to_cloud/icon.png
:align: left
:width: 40px

``DFBrepToCloud`` component
===========================

.. ghcomponent_to_rst:: ../src/gh/components/DF_brep_to_cloud
8 changes: 7 additions & 1 deletion doc/gh_components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ DF has a Grasshopper_ plugin with a set of components that allows the user to in
- .. image:: ../src/gh/components/DF_colorize_cloud/icon.png
- `gh_DFColorizeCloud <gh_DFColorizeCloud.html>`_

* - .. image:: ../src/gh/components/DF_brep_to_cloud/icon.png
- `gh_DFBrepToCloud <gh_DFBrepToCloud.html>`_
-
-



.. toctree::
Expand Down Expand Up @@ -107,4 +112,5 @@ DF has a Grasshopper_ plugin with a set of components that allows the user to in
gh_DFXMLExporter
gh_DFPreviewAssembly
gh_DFRemoveBeam
gh_DFColorizeCloud
gh_DFColorizeCloud
gh_DFBrepToCloud
38 changes: 38 additions & 0 deletions src/gh/components/DF_brep_to_cloud/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#! python3

import Rhino
from ghpythonlib.componentbase import executingcomponent as component
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML

from diffCheck import df_cvt_bindings
import System


class DFBrepToCloud(component):
def RunScript(self,
i_breps: System.Collections.Generic.IList[Rhino.Geometry.Brep],
i_num_points: int):
self.meshing_parameters = Rhino.Geometry.MeshingParameters.DefaultAnalysisMesh

mesh_versions = []

if i_breps is None or i_num_points is None:
return None

for i_brep in i_breps:
if not isinstance(i_brep, Rhino.Geometry.Brep):
self.AddRuntimeMessage(RML.Warning, "Please provide a brep to convert to a cloud")
return None
meshes = Rhino.Geometry.Mesh.CreateFromBrep(i_brep, self.meshing_parameters)
for mesh in meshes:
mesh_versions.append(mesh)

unified_mesh = mesh_versions[0]
unified_mesh.Append(mesh_versions)
unified_mesh.Faces.ConvertQuadsToTriangles()
df_mesh = df_cvt_bindings.cvt_rhmesh_2_dfmesh(unified_mesh)
df_cloud = df_mesh.sample_points_uniformly(i_num_points)
rgpoints = [Rhino.Geometry.Point3d(pt[0], pt[1], pt[2]) for pt in df_cloud.points]
rh_cloud = Rhino.Geometry.PointCloud(rgpoints)
print(rh_cloud)
return [rh_cloud]
Binary file added src/gh/components/DF_brep_to_cloud/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions src/gh/components/DF_brep_to_cloud/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "DFBrepToMesh",
"nickname": "DFBrepToMesh",
"category": "diffCheck",
"subcategory": "Cloud",
"description": "Create unique point cloud from list of breps.",
"exposure": 4,
"instanceGuid": "0194cbfc-1a6d-44a7-ae5d-7495db20edbe",
"ghpython": {
"hideOutput": true,
"hideInput": true,
"isAdvancedMode": true,
"marshalOutGuids": true,
"iconDisplay": 2,
"inputParameters": [
{
"name": "i_breps",
"nickname": "i_breps",
"description": "The breps to convert to point cloud.",
"optional": false,
"allowTreeAccess": false,
"showTypeHints": true,
"scriptParamAccess": "list",
"wireDisplay": "default",
"sourceCount": 0,
"typeHintID": "brep"
},
{
"name": "i_num_points",
"nickname": "i_num_points",
"description": "The number of points in the new point cloud.",
"optional": false,
"allowTreeAccess": false,
"showTypeHints": true,
"scriptParamAccess": "item",
"wireDisplay": "default",
"sourceCount": 0,
"typeHintID": "int"
}
],
"outputParameters": [
{
"name": "o_pointcloud",
"nickname": "o_pointcloud",
"description": "The generated point cloud.",
"optional": false,
"sourceCount": 0,
"graft": false
}
]
}
}
28 changes: 21 additions & 7 deletions src/gh/components/DF_mesh_to_cloud/code.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#! python3

import System

import Rhino.Geometry as rg
import Rhino
from ghpythonlib.componentbase import executingcomponent as component


Expand All @@ -12,13 +13,26 @@

class DFMeshToCloud(component):
def RunScript(self,
i_mesh: rg.Mesh,
i_points: int) -> rg.PointCloud:
df_mesh = diffCheck.df_cvt_bindings.cvt_rhmesh_2_dfmesh(i_mesh)
df_cloud = df_mesh.sample_points_uniformly(i_points)
i_meshes:System.Collections.Generic.IList[Rhino.Geometry.Mesh],
i_points: int) -> Rhino.Geometry.PointCloud:

if i_meshes is None:
return None

if i_points is None:
i_points = 1000

rh_mesh = i_meshes[0]
for i in range(1, len(i_meshes)):
if i_meshes[i] is None:
return None
rh_mesh.Append(i_meshes[i])
rh_mesh.Faces.ConvertQuadsToTriangles()

df_mesh = diffCheck.df_cvt_bindings.cvt_rhmesh_2_dfmesh(rh_mesh)
df_cloud = df_mesh.sample_points_uniformly(i_points)
rgpoints = [Rhino.Geometry.Point3d(p[0], p[1], p[2]) for p in df_cloud.points]
# convert the df_cloud to a rhino cloud
rgpoints = [rg.Point3d(pt[0], pt[1], pt[2]) for pt in df_cloud.points]
rh_cloud = rg.PointCloud(rgpoints)
rh_cloud = Rhino.Geometry.PointCloud(rgpoints)

return [rh_cloud]
8 changes: 4 additions & 4 deletions src/gh/components/DF_mesh_to_cloud/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
"iconDisplay": 2,
"inputParameters": [
{
"name": "i_mesh",
"nickname": "i_mesh",
"description": "Mesh to sample into a point cloud.",
"name": "i_meshes",
"nickname": "i_meshes",
"description": "Meshes to sample into a point cloud.",
"optional": true,
"allowTreeAccess": true,
"showTypeHints": true,
"scriptParamAccess": "item",
"scriptParamAccess": "list",
"wireDisplay": "default",
"sourceCount": 0,
"typeHintID": "mesh"
Expand Down

0 comments on commit 2fdef56

Please sign in to comment.