Skip to content

Commit d65fb17

Browse files
feat: add capacity to crop with any brep, and keep trace of in and out points
1 parent fcc1936 commit d65fb17

File tree

1 file changed

+27
-7
lines changed
  • src/gh/components/DF_crop_cloud

1 file changed

+27
-7
lines changed
Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Crops a point cloud by giving the bounding box or a brep."""
12
from diffCheck import df_cvt_bindings as df_cvt
23

34
import numpy as np
@@ -7,25 +8,44 @@
78

89
from ghpythonlib.componentbase import executingcomponent as component
910

11+
TOL = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance
12+
1013
class DFCloudCrop(component):
1114
def __init__(self):
1215
super(DFCloudCrop, self).__init__()
16+
1317
def RunScript(self,
1418
i_cloud: Rhino.Geometry.PointCloud,
15-
i_box: Rhino.Geometry.Brep):
19+
i_box: Rhino.Geometry.Brep,
20+
i_brep: Rhino.Geometry.Brep):
1621
if i_cloud is None:
17-
ghenv.Component.AddRuntimeMessage(RML.Warning, "No point cloud provided. Please connect a point cloud to the input.") # noqa: F821
22+
ghenv.Component.AddRuntimeMessage(RML.Warning,"No point cloud provided. Please connect a point cloud to the input.")# noqa: F821
1823
return None
1924

2025
if i_box is not None:
2126
bbox = i_box.GetBoundingBox(True)
2227
bb_min_as_array = np.asarray([bbox.Min.X, bbox.Min.Y, bbox.Min.Z])
2328
bb_max_as_array = np.asarray([bbox.Max.X, bbox.Max.Y, bbox.Max.Z])
29+
df_cloud = df_cvt.cvt_rhcloud_2_dfcloud(i_cloud)
30+
df_cloud_copy = df_cloud.duplicate()
31+
df_cloud.crop(bb_min_as_array, bb_max_as_array)
32+
df_cloud_copy.subtract_points(df_cloud, TOL)
33+
o_pts_out = df_cvt.cvt_dfcloud_2_rhcloud(df_cloud_copy)
34+
o_pts_in = df_cvt.cvt_dfcloud_2_rhcloud(df_cloud)
35+
36+
elif i_brep is not None:
37+
pts_in = []
38+
pts_out = []
39+
for pc_item in i_cloud:
40+
point = Rhino.Geometry.Point3d(pc_item.X, pc_item.Y, pc_item.Z)
41+
if i_brep.IsPointInside(point, TOL, True):
42+
pts_in.append(point)
43+
else:
44+
pts_out.append(point)
45+
o_pts_in = Rhino.Geometry.PointCloud(pts_in)
46+
o_pts_out = Rhino.Geometry.PointCloud(pts_out)
2447

2548
else:
26-
ghenv.Component.AddRuntimeMessage(RML.Warning, "Please provide a box to crop the point cloud with") # noqa: F821
49+
ghenv.Component.AddRuntimeMessage(RML.Warning, "Please provide a box to crop the point cloud with") # noqa: F821
2750

28-
df_cloud = df_cvt.cvt_rhcloud_2_dfcloud(i_cloud)
29-
df_cloud.crop(bb_min_as_array, bb_max_as_array)
30-
rh_cloud = df_cvt.cvt_dfcloud_2_rhcloud(df_cloud)
31-
return [rh_cloud]
51+
return [o_pts_in, o_pts_out]

0 commit comments

Comments
 (0)