Skip to content

Commit ec0c5cf

Browse files
component safety fixes (#108)
* FIX: add default values and throw standard warning if no PC or assembly is given * UPTDATE: better standard values and info added to metadata * FIX: avoid error created by ghcomponentizer by importing Rhino and System in advance * FIX: name of output changed from o_clusters to o_cloud * FIX: missing rg --------- Co-authored-by: Andrea Settimi <andrea.settimi@epfl.ch>
1 parent 6744eed commit ec0c5cf

File tree

19 files changed

+88
-114
lines changed

19 files changed

+88
-114
lines changed

src/gh/components/DF_CAD_segmentator/code.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#! python3
22

3-
import typing
3+
import System
44

5-
import Rhino.Geometry as rg
5+
import Rhino
66
from ghpythonlib.componentbase import executingcomponent as component
7+
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
78

89

9-
import diffCheck
10-
import diffCheck.df_geometries
1110
from diffCheck.diffcheck_bindings import dfb_segmentation
1211

1312
from diffCheck import df_cvt_bindings
@@ -16,11 +15,19 @@
1615

1716
class DFCADSegmentator(component):
1817
def RunScript(self,
19-
i_clouds : typing.List[rg.PointCloud],
20-
i_assembly : diffCheck.df_geometries.DFAssembly,
21-
i_angle_threshold : float,
22-
i_association_threshold : float
23-
) -> rg.PointCloud:
18+
i_clouds: System.Collections.Generic.IList[Rhino.Geometry.PointCloud],
19+
i_assembly,
20+
i_angle_threshold: float = 0.1,
21+
i_association_threshold: float = 0.1) -> rg.PointCloud:
22+
23+
if i_clouds is None or i_assembly is None:
24+
self.AddRuntimeMessage(RML.Warning, "Please provide a cloud and an assembly to segmentate")
25+
return None
26+
if i_angle_threshold is None:
27+
i_angle_threshold = 0.1
28+
if i_association_threshold is None:
29+
i_association_threshold = 0.1
30+
2431
o_clusters = []
2532
df_clusters = []
2633
# we make a deepcopy of the input clouds

src/gh/components/DF_CAD_segmentator/metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
{
4141
"name": "i_angle_threshold",
4242
"nickname": "i_angle_threshold",
43-
"description": "From 0 to 1, it's the sin value. The closer to 0 the less permissive and viceversa to 1.",
43+
"description": "From 0 to 1, it's the sin value. By default 0.1. The closer to 0 the less permissive and viceversa to 1.",
4444
"optional": false,
4545
"allowTreeAccess": true,
4646
"showTypeHints": true,
@@ -52,7 +52,7 @@
5252
{
5353
"name": "i_association_threshold",
5454
"nickname": "i_association_threshold",
55-
"description": "From 0 to infinite. By default 0.5. The closer to 0 the less permissive your point.",
55+
"description": "From 0 to infinite. By default 0.1. The closer to 0 the less permissive your point.",
5656
"optional": false,
5757
"allowTreeAccess": true,
5858
"showTypeHints": true,

src/gh/components/DF_cloud_cloud_distance/code.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#! python3
22

3-
import typing
3+
import System
44

5-
import Rhino.Geometry as rg
5+
import Rhino
66
from ghpythonlib.componentbase import executingcomponent as component
77

88
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
@@ -14,8 +14,8 @@
1414

1515
class DFCloudCloudDistance(component):
1616
def RunScript(self,
17-
i_cloud_source: typing.List[rg.PointCloud],
18-
i_cloud_target: typing.List[rg.PointCloud],
17+
i_cloud_source: System.Collections.Generic.List[Rhino.Geometry.PointCloud],
18+
i_cloud_target: System.Collections.Generic.List[Rhino.Geometry.PointCloud],
1919
i_swap: bool):
2020
if i_cloud_source is None or i_cloud_target is None:
2121
ghenv.Component.AddRuntimeMessage(RML.Warning, "Please provide both objects of type point clouds to compare") # noqa: F821

src/gh/components/DF_cloud_mesh_distance/code.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
#! python3
22

3-
import typing
3+
import System
44

5-
import Rhino.Geometry as rg
5+
import Rhino
66
from ghpythonlib.componentbase import executingcomponent as component
77
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
88

99
import diffCheck
1010
from diffCheck import df_cvt_bindings
1111
from diffCheck import df_error_estimation
12-
from diffCheck.df_geometries import DFAssembly
1312

1413

1514
class DFCloudMeshDistance(component):
1615
def RunScript(self,
17-
i_cloud_source: typing.List[rg.PointCloud],
18-
i_assembly: DFAssembly,
19-
i_signed_flag: bool,
20-
i_swap: bool,
21-
i_analysis_resolution):
16+
i_cloud_source: System.Collections.Generic.List[Rhino.Geometry.PointCloud],
17+
i_assembly,
18+
i_signed_flag: bool,
19+
i_swap: bool,
20+
i_analysis_resolution: float):
2221

2322
if i_analysis_resolution is None:
2423
scalef = diffCheck.df_util.get_doc_2_meters_unitf()

src/gh/components/DF_cloud_normal_estimator/code.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
#! python3
22

3-
4-
import Rhino.Geometry as rg
3+
import Rhino
54
from ghpythonlib.componentbase import executingcomponent as component
65

76
from diffCheck import df_cvt_bindings
87

98
class DFCloudNormalEstimator(component):
109
def RunScript(self,
11-
i_cloud : rg.PointCloud = None,
12-
i_knn : int = None,
13-
i_radius : float = None,
14-
i_switch_mode : bool = True
15-
):
16-
o_cloud = rg.PointCloud()
10+
i_cloud: Rhino.Geometry.PointCloud,
11+
i_knn: int,
12+
i_radius: int,
13+
i_switch_mode: bool):
14+
o_cloud = Rhino.Geometry.PointCloud()
1715

1816
df_cloud = df_cvt_bindings.cvt_rhcloud_2_dfcloud(i_cloud)
1917

src/gh/components/DF_cloud_size_downsample/code.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
#! python3
22

33

4-
import Rhino.Geometry as rg
4+
import Rhino
55
from ghpythonlib.componentbase import executingcomponent as component
66

77

88
from diffCheck import df_cvt_bindings
99

1010
class DFCloudSizeDownsample(component):
11-
def RunScript(self,
12-
i_cloud: rg.PointCloud,
13-
i_size: int,
14-
) -> rg.PointCloud:
11+
def RunScript(self, i_cloud: Rhino.Geometry.PointCloud, i_size: float) -> Rhino.Geometry.PointCloud:
1512
df_cloud = df_cvt_bindings.cvt_rhcloud_2_dfcloud(i_cloud)
1613
df_cloud.downsample_by_size(i_size)
1714
o_cloud = df_cvt_bindings.cvt_dfcloud_2_rhcloud(df_cloud)

src/gh/components/DF_cloud_uniform_downsample/code.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
#! python3
22

33

4-
import Rhino.Geometry as rg
4+
import Rhino
55
from ghpythonlib.componentbase import executingcomponent as component
66

77

88
from diffCheck import df_cvt_bindings
99

1010
class DFCloudUniformDownsample(component):
11-
def RunScript(self,
12-
i_cloud: rg.PointCloud,
13-
i_every_k_points: int,
14-
) -> rg.PointCloud:
11+
def RunScript(self, i_cloud: Rhino.Geometry.PointCloud, i_every_k_points: int) -> Rhino.Geometry.PointCloud:
1512
df_cloud = df_cvt_bindings.cvt_rhcloud_2_dfcloud(i_cloud)
1613
df_cloud.uniform_downsample(i_every_k_points)
1714
o_cloud = df_cvt_bindings.cvt_dfcloud_2_rhcloud(df_cloud)

src/gh/components/DF_cloud_voxel_downsample/code.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
#! python3
22

33

4-
import Rhino.Geometry as rg
4+
import Rhino
55
from ghpythonlib.componentbase import executingcomponent as component
66

77

88
from diffCheck import df_cvt_bindings
99

1010
class DFCloudVoxelDownsample(component):
11-
def RunScript(self,
12-
i_cloud: rg.PointCloud,
13-
i_voxel_size: float,
14-
) -> rg.PointCloud:
11+
def RunScript(self, i_cloud: Rhino.Geometry.PointCloud, i_voxel_size: float) -> Rhino.Geometry.PointCloud:
1512
df_cloud = df_cvt_bindings.cvt_rhcloud_2_dfcloud(i_cloud)
1613
df_cloud.voxel_downsample(i_voxel_size)
1714
o_cloud = df_cvt_bindings.cvt_dfcloud_2_rhcloud(df_cloud)

src/gh/components/DF_csv_exporter/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
},
5252
{
5353
"name": "i_export_seperate_files",
54-
"nickname": "i_export_seperate_file",
54+
"nickname": "i_export_seperate_files",
5555
"description": "Whether to export one single file or seperate files per element.",
5656
"optional": true,
5757
"allowTreeAccess": true,

src/gh/components/DF_deconstruct_beam/code.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
#! python3
22

3-
import typing
4-
3+
import System
54

65
from ghpythonlib.componentbase import executingcomponent as component
76

8-
from diffCheck.df_geometries import DFBeam
9-
107

118
class DFDeconstructBeam(component):
12-
def RunScript(self,
13-
i_beams : typing.List[DFBeam]):
9+
def RunScript(self, i_beams: System.Collections.Generic.List[object]):
1410
o_side_faces, o_joint_faces, o_joint_ids = [], [], []
1511

1612
for i_b in i_beams:

0 commit comments

Comments
 (0)