Skip to content

Commit 3c90378

Browse files
feat: add a component to crop point clouds
1 parent e80b266 commit 3c90378

File tree

3 files changed

+174
-0
lines changed

3 files changed

+174
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from diffCheck import df_cvt_bindings as df_cvt
2+
3+
import numpy as np
4+
5+
import Rhino
6+
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
7+
8+
from ghpythonlib.componentbase import executingcomponent as component
9+
10+
class DFCloudCrop(component):
11+
def __init__(self):
12+
super(DFCloudCrop, self).__init__()
13+
def RunScript(self,
14+
i_cloud: Rhino.Geometry.PointCloud,
15+
i_box: Rhino.Geometry.Brep,
16+
i_x_min: float,
17+
i_y_min: float,
18+
i_z_min: float,
19+
i_x_max: float,
20+
i_y_max: float,
21+
i_z_max: float):
22+
if i_cloud is None:
23+
ghenv.Component.AddRuntimeMessage(RML.Warning, "No point cloud provided. Please connect a point cloud to the input.") # noqa: F821
24+
return None
25+
26+
if i_box is not None:
27+
bbox = i_box.GetBoundingBox(True)
28+
bb_min_as_array = np.asarray([bbox.Min.X, bbox.Min.Y, bbox.Min.Z])
29+
bb_max_as_array = np.asarray([bbox.Max.X, bbox.Max.Y, bbox.Max.Z])
30+
31+
ghenv.Component.AddRuntimeMessage(RML.Remark, "A box is provided and is used to crop the point cloud, all other inputs neglected. To use min/max values, disconnect the box") # noqa: F821
32+
else:
33+
if i_x_min is None:
34+
i_x_min = -np.inf
35+
if i_y_min is None:
36+
i_y_min = -np.inf
37+
if i_z_min is None:
38+
i_z_min = -np.inf
39+
if i_x_max is None:
40+
i_x_max = np.inf
41+
if i_y_max is None:
42+
i_y_max = np.inf
43+
if i_z_max is None:
44+
i_z_max = np.inf
45+
bb_min_as_array = np.asarray([i_x_min, i_y_min, i_z_min])
46+
bb_max_as_array = np.asarray([i_x_max, i_y_max, i_z_max])
47+
df_cloud = df_cvt.cvt_rhcloud_2_dfcloud(i_cloud)
48+
df_cloud.crop(bb_min_as_array, bb_max_as_array)
49+
rh_cloud = df_cvt.cvt_dfcloud_2_rhcloud(df_cloud)
50+
return [rh_cloud]
723 Bytes
Loading
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{
2+
"name": "DFCropCloud",
3+
"nickname": "Crop",
4+
"category": "diffCheck",
5+
"subcategory": "Cloud",
6+
"description": "Crops a point cloud by giving the bounding box or limit values.",
7+
"exposure": 4,
8+
"instanceGuid": "f0461287-b1aa-47ec-87c4-0f03924cea24",
9+
"ghpython": {
10+
"hideOutput": true,
11+
"hideInput": true,
12+
"isAdvancedMode": true,
13+
"marshalOutGuids": true,
14+
"iconDisplay": 2,
15+
"inputParameters": [
16+
{
17+
"name": "i_cloud",
18+
"nickname": "i_cloud",
19+
"description": "The point cloud to crop.",
20+
"optional": true,
21+
"allowTreeAccess": true,
22+
"showTypeHints": true,
23+
"scriptParamAccess": "item",
24+
"wireDisplay": "default",
25+
"sourceCount": 0,
26+
"typeHintID": "pointcloud"
27+
},
28+
{
29+
"name": "i_box",
30+
"nickname": "i_box",
31+
"description": "The brep box to crop the point cloud with.",
32+
"optional": true,
33+
"allowTreeAccess": true,
34+
"showTypeHints": true,
35+
"scriptParamAccess": "item",
36+
"wireDisplay": "default",
37+
"sourceCount": 0,
38+
"typeHintID": "brep"
39+
},
40+
{
41+
"name": "i_x_min",
42+
"nickname": "i_x_min",
43+
"description": "The minimum x value to crop the point cloud with.",
44+
"optional": true,
45+
"allowTreeAccess": true,
46+
"showTypeHints": true,
47+
"scriptParamAccess": "item",
48+
"wireDisplay": "default",
49+
"sourceCount": 0,
50+
"typeHintID": "float"
51+
},
52+
{
53+
"name": "i_y_min",
54+
"nickname": "i_y_min",
55+
"description": "The minimum y value to crop the point cloud with.",
56+
"optional": true,
57+
"allowTreeAccess": true,
58+
"showTypeHints": true,
59+
"scriptParamAccess": "item",
60+
"wireDisplay": "default",
61+
"sourceCount": 0,
62+
"typeHintID": "float"
63+
},
64+
{
65+
"name": "i_z_min",
66+
"nickname": "i_z_min",
67+
"description": "The minimum z value to crop the point cloud with.",
68+
"optional": true,
69+
"allowTreeAccess": true,
70+
"showTypeHints": true,
71+
"scriptParamAccess": "item",
72+
"wireDisplay": "default",
73+
"sourceCount": 0,
74+
"typeHintID": "float"
75+
},
76+
{
77+
"name": "i_x_max",
78+
"nickname": "i_x_max",
79+
"description": "The maximum x value to crop the point cloud with.",
80+
"optional": true,
81+
"allowTreeAccess": true,
82+
"showTypeHints": true,
83+
"scriptParamAccess": "item",
84+
"wireDisplay": "default",
85+
"sourceCount": 0,
86+
"typeHintID": "float"
87+
},
88+
{
89+
"name": "i_y_max",
90+
"nickname": "i_y_max",
91+
"description": "The maximum y value to crop the point cloud with.",
92+
"optional": true,
93+
"allowTreeAccess": true,
94+
"showTypeHints": true,
95+
"scriptParamAccess": "item",
96+
"wireDisplay": "default",
97+
"sourceCount": 0,
98+
"typeHintID": "float"
99+
},
100+
{
101+
"name": "i_z_max",
102+
"nickname": "i_z_max",
103+
"description": "The maximum z value to crop the point cloud with.",
104+
"optional": true,
105+
"allowTreeAccess": true,
106+
"showTypeHints": true,
107+
"scriptParamAccess": "item",
108+
"wireDisplay": "default",
109+
"sourceCount": 0,
110+
"typeHintID": "float"
111+
}
112+
],
113+
"outputParameters": [
114+
{
115+
"name": "o_cloud",
116+
"nickname": "o_cloud",
117+
"description": "The downsampled cloud.",
118+
"optional": false,
119+
"sourceCount": 0,
120+
"graft": false
121+
}
122+
]
123+
}
124+
}

0 commit comments

Comments
 (0)