|
1 | 1 | #! python3
|
2 | 2 |
|
3 |
| -import System |
4 |
| - |
5 | 3 | import Rhino
|
| 4 | +import Grasshopper |
6 | 5 | from ghpythonlib.componentbase import executingcomponent as component
|
7 | 6 | from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
|
8 | 7 |
|
|
12 | 11 |
|
13 | 12 |
|
14 | 13 | class DFCloudMeshDistance(component):
|
| 14 | + |
15 | 15 | def RunScript(self,
|
16 |
| - i_cloud_source: System.Collections.Generic.List[Rhino.Geometry.PointCloud], |
| 16 | + i_cloud_source: Grasshopper.DataTree[Rhino.Geometry.PointCloud], |
17 | 17 | i_assembly,
|
18 | 18 | i_signed_flag: bool,
|
19 | 19 | i_swap: bool,
|
20 | 20 | i_analysis_resolution: float):
|
21 | 21 |
|
| 22 | + if i_cloud_source is None or i_assembly is None: |
| 23 | + return None, None, None, None, None, None |
| 24 | + |
22 | 25 | if i_analysis_resolution is None:
|
23 | 26 | scalef = diffCheck.df_util.get_doc_2_meters_unitf()
|
24 | 27 | i_analysis_resolution = 0.1 / scalef
|
25 | 28 |
|
| 29 | + # if the input is Gh tree, flatten it |
| 30 | + flat_list = [] |
| 31 | + for branch in i_cloud_source.Branches: |
| 32 | + flat_list.extend(list(branch)) |
| 33 | + i_cloud_list = flat_list |
| 34 | + |
26 | 35 | # Based on cloud source input + beam size, decide whether to calculate joints or entire assembly and output respective message
|
27 |
| - if len(i_assembly.beams) == len(i_cloud_source): |
| 36 | + if len(i_assembly.beams) == len(i_cloud_list): |
28 | 37 | ghenv.Component.Message = "Per Beam" # noqa: F821
|
29 | 38 | rh_mesh_target_list = [beam.to_mesh(i_analysis_resolution) for beam in i_assembly.beams]
|
30 |
| - elif len(i_assembly.all_joints) == len(i_cloud_source): |
| 39 | + elif len(i_assembly.all_joints) == len(i_cloud_list): |
31 | 40 | ghenv.Component.Message = "Per Joint" # noqa: F821
|
32 | 41 | rh_mesh_target_list = [joint.to_mesh(i_analysis_resolution) for joint in i_assembly._all_joints]
|
| 42 | + elif len(i_assembly.all_joint_faces) == len(i_cloud_list): |
| 43 | + ghenv.Component.Message = "Per Joint Face" # noqa: F821 |
| 44 | + rh_mesh_target_list = [joint_face.to_mesh() for joint_face in i_assembly.all_joint_faces] |
33 | 45 | else:
|
34 | 46 | ghenv.Component.AddRuntimeMessage(RML.Warning, "The input number of objects to compare matches neither the number of beams nor the number of joints") # noqa: F821
|
35 | 47 | return None, None, None, None, None, None
|
36 | 48 |
|
37 | 49 | # conversion
|
38 |
| - siffed_df_cloud_source_list = [] |
39 |
| - siffed_rh_mesh_target_list = [] |
40 |
| - for i in range(len(i_cloud_source)): |
41 |
| - if i_cloud_source[i] is not None: |
42 |
| - siffed_df_cloud_source_list.append(df_cvt_bindings.cvt_rhcloud_2_dfcloud(i_cloud_source[i])) |
43 |
| - siffed_rh_mesh_target_list.append(rh_mesh_target_list[i]) |
44 |
| - |
| 50 | + df_cloud_source_list = [df_cvt_bindings.cvt_rhcloud_2_dfcloud(i_cl_s) for i_cl_s in i_cloud_list] |
45 | 51 |
|
46 | 52 | # calculate distances
|
47 | 53 | o_result = df_error_estimation.df_cloud_2_rh_mesh_comparison(siffed_df_cloud_source_list, siffed_rh_mesh_target_list, i_signed_flag, i_swap)
|
48 | 54 |
|
49 |
| - return o_result.distances, o_result.distances_rmse, o_result.distances_max_deviation, o_result.distances_min_deviation, o_result.distances_sd_deviation, o_result |
| 55 | + # distances to tree |
| 56 | + distances_tree = Grasshopper.DataTree[object]() |
| 57 | + for i, sublist in enumerate(o_result.distances): |
| 58 | + for j, item in enumerate(sublist): |
| 59 | + path = Grasshopper.Kernel.Data.GH_Path(i) |
| 60 | + distances_tree.Add(item, path) |
| 61 | + |
| 62 | + return distances_tree, o_result.distances_rmse, o_result.distances_max_deviation, o_result.distances_min_deviation, o_result.distances_sd_deviation, o_result |
0 commit comments