|
| 1 | +"""Crops a point cloud by giving the bounding box or a brep.""" |
1 | 2 | from diffCheck import df_cvt_bindings as df_cvt |
2 | 3 |
|
3 | 4 | import numpy as np |
|
7 | 8 |
|
8 | 9 | from ghpythonlib.componentbase import executingcomponent as component |
9 | 10 |
|
| 11 | +TOL = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance |
| 12 | + |
10 | 13 | class DFCloudCrop(component): |
11 | 14 | def __init__(self): |
12 | 15 | super(DFCloudCrop, self).__init__() |
| 16 | + |
13 | 17 | def RunScript(self, |
14 | 18 | i_cloud: Rhino.Geometry.PointCloud, |
15 | | - i_box: Rhino.Geometry.Brep): |
| 19 | + i_box: Rhino.Geometry.Brep, |
| 20 | + i_brep: Rhino.Geometry.Brep): |
16 | 21 | 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 |
18 | 23 | return None |
19 | 24 |
|
20 | 25 | if i_box is not None: |
21 | 26 | bbox = i_box.GetBoundingBox(True) |
22 | 27 | bb_min_as_array = np.asarray([bbox.Min.X, bbox.Min.Y, bbox.Min.Z]) |
23 | 28 | 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) |
24 | 47 |
|
25 | 48 | 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 |
27 | 50 |
|
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