Skip to content

Commit 3eebaa5

Browse files
feat: improve cropping component following @eleniv3d 's comments
1 parent 8cdd175 commit 3eebaa5

File tree

2 files changed

+13
-35
lines changed

2 files changed

+13
-35
lines changed

src/gh/components/DF_crop_cloud/code.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import numpy as np
55

66
import Rhino
7-
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
87

98
from ghpythonlib.componentbase import executingcomponent as component
109

@@ -16,36 +15,28 @@ def __init__(self):
1615

1716
def RunScript(self,
1817
i_cloud: Rhino.Geometry.PointCloud,
19-
i_box: Rhino.Geometry.Brep,
20-
i_brep: Rhino.Geometry.Brep):
21-
if i_cloud is None:
22-
ghenv.Component.AddRuntimeMessage(RML.Warning,"No point cloud provided. Please connect a point cloud to the input.")# noqa: F821
23-
return None
24-
25-
if i_box is not None:
26-
bbox = i_box.GetBoundingBox(True)
27-
bb_min_as_array = np.asarray([bbox.Min.X, bbox.Min.Y, bbox.Min.Z])
28-
bb_max_as_array = np.asarray([bbox.Max.X, bbox.Max.Y, bbox.Max.Z])
18+
i_boundary: Rhino.Geometry.Brep):
19+
20+
if i_boundary.IsBox():
21+
vertices = i_boundary.Vertices
22+
bb_as_array = [np.asarray([vertice.Location.X, vertice.Location.Y, vertice.Location.Z]) for vertice in vertices]
2923
df_cloud = df_cvt.cvt_rhcloud_2_dfcloud(i_cloud)
3024
df_cloud_copy = df_cloud.duplicate()
31-
df_cloud.crop(bb_min_as_array, bb_max_as_array)
25+
df_cloud.crop(bb_as_array)
3226
df_cloud_copy.subtract_points(df_cloud, TOL)
3327
o_pts_out = df_cvt.cvt_dfcloud_2_rhcloud(df_cloud_copy)
3428
o_pts_in = df_cvt.cvt_dfcloud_2_rhcloud(df_cloud)
3529

36-
elif i_brep is not None:
30+
else:
3731
pts_in = []
3832
pts_out = []
3933
for pc_item in i_cloud:
4034
point = Rhino.Geometry.Point3d(pc_item.X, pc_item.Y, pc_item.Z)
41-
if i_brep.IsPointInside(point, TOL, True):
35+
if i_boundary.IsPointInside(point, TOL, True):
4236
pts_in.append(point)
4337
else:
4438
pts_out.append(point)
4539
o_pts_in = Rhino.Geometry.PointCloud(pts_in)
4640
o_pts_out = Rhino.Geometry.PointCloud(pts_out)
4741

48-
else:
49-
ghenv.Component.AddRuntimeMessage(RML.Warning, "Please provide a box to crop the point cloud with") # noqa: F821
50-
5142
return [o_pts_in, o_pts_out]

src/gh/components/DF_crop_cloud/metadata.json

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"nickname": "Crop",
44
"category": "diffCheck",
55
"subcategory": "Cloud",
6-
"description": "Crops a point cloud by giving the bounding box or limit values.",
6+
"description": "Crops a point cloud by giving a boundary volume.",
77
"exposure": 4,
88
"instanceGuid": "f0461287-b1aa-47ec-87c4-0f03924cea24",
99
"ghpython": {
@@ -26,29 +26,16 @@
2626
"typeHintID": "pointcloud"
2727
},
2828
{
29-
"name": "i_box",
30-
"nickname": "i_box",
31-
"description": "The brep box to crop the point cloud with. Can only be a box.",
32-
"optional": true,
29+
"name": "i_boundary",
30+
"nickname": "i_boundary",
31+
"description": "The brep boundary to crop the point cloud with. If a box is provided, computation will be faster. If a generic brep is provided, it will be used but may be slower.",
32+
"optional": false,
3333
"allowTreeAccess": true,
3434
"showTypeHints": true,
3535
"scriptParamAccess": "item",
3636
"wireDisplay": "default",
3737
"sourceCount": 0,
3838
"typeHintID": "brep"
39-
},
40-
{
41-
"name": "i_brep",
42-
"nickname": "i_brep",
43-
"description": "The brep to crop the point cloud with. This is slower than the box, but accommodates any Brep.",
44-
"optional": true,
45-
"allowTreeAccess": true,
46-
"showTypeHints": true,
47-
"scriptParamAccess": "item",
48-
"wireDisplay": "default",
49-
"sourceCount": 0,
50-
"typeHintID": "brep",
51-
"flatten": false
5239
}
5340
],
5441
"outputParameters": [

0 commit comments

Comments
 (0)