Skip to content

Commit e8119d4

Browse files
UPDATE-CAP: component code cleaned, defensive checks added, and metadata updated
1 parent 62095eb commit e8119d4

File tree

2 files changed

+75
-21
lines changed

2 files changed

+75
-21
lines changed

src/gh/components/DF_joint_segmentator/code.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,62 @@
99

1010
ABSTOL = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance
1111

12-
def main(i_clusters, i_faces, i_joint_ids):
12+
def main(i_clusters, i_joints, i_joint_ids):
13+
14+
if len(i_joints) != len(i_joint_ids):
15+
raise ValueError("The number of joints and joint ids must be the same.")
16+
17+
if len(i_clusters) == 0:
18+
raise ValueError("No clusters given.")
19+
20+
if not isinstance(i_clusters[0], Rhino.Geometry.PointCloud):
21+
raise ValueError("The input clusters must be PointClouds.")
22+
23+
if not isinstance(i_joints[0], Rhino.Geometry.Mesh):
24+
raise ValueError("The input joints must be convertible to Meshes.")
25+
26+
27+
# prepping the reference meshes
1328
n_joints = max(i_joint_ids) + 1
1429
joints = [ [] for i in range(n_joints) ]
15-
for face, id in zip(i_faces, i_joint_ids):
30+
for face, id in zip(i_joints, i_joint_ids):
1631
face.Subdivide()
1732
face.Faces.ConvertQuadsToTriangles()
1833
joints[id].append(df_cvt.cvt_rhmesh_2_dfmesh(face))
34+
1935
joint_clouds = []
20-
registrastions = []
36+
registrations = []
2137
joint_segments = []
2238
df_clouds = [df_cvt.cvt_rhcloud_2_dfcloud(cluster) for cluster in i_clusters]
2339

40+
# for each joint, find the corresponding clusters and merge them, generate a reference point cloud, and register the merged clusters to the reference point cloud
2441
for joint in joints:
42+
43+
# create the reference point cloud
2544
joint_cloud = diffcheck_bindings.dfb_geometry.DFPointCloud()
45+
2646
for face in joint:
2747
face_cloud = face.sample_points_uniformly(1000)
2848
face_cloud.estimate_normals(knn=30)
2949
joint_cloud.add_points(face_cloud)
50+
3051
joint_clouds.append(df_cvt.cvt_dfcloud_2_rhcloud(joint_cloud))
52+
53+
# find the corresponding clusters and merge them
3154
segment = diffcheck_bindings.dfb_segmentation.DFSegmentation.associate_clusters(joint, df_clouds )
3255
diffcheck_bindings.dfb_segmentation.DFSegmentation.clean_unassociated_clusters(df_clouds, [segment], [joint], 0.1, 0.02)
56+
57+
# register the merged clusters to the reference point cloud
3358
registration = diffcheck_bindings.dfb_registrations.DFRefinedRegistration.O3DICP(segment, joint_cloud)
3459
res = registration.transformation_matrix
35-
registrastions.append(res)
60+
61+
registrations.append(df_cvt.cvt_ndarray_2_rh_transform(res))
3662
joint_segments.append(df_cvt.cvt_dfcloud_2_rhcloud(segment))
3763

38-
return joint_segments, joint_clouds, registrastions
64+
return joint_segments, joint_clouds, registrations
3965

4066
if __name__ == "__main__":
41-
joint_segments, joint_clouds, registrastions = main(i_clusters, i_faces, i_joint_ids)
67+
o_joint_segments, o_reference_point_clouds, o_transforms = main(i_clusters, i_joints, i_joint_ids)
4268

43-
for i in range(len(joint_segments)):
44-
joint_segments[i].Transform(df_cvt.cvt_ndarray_2_rh_transform(registrastions[i]))
69+
for i in range(len(o_joint_segments)):
70+
o_joint_segments[i].Transform(o_transforms[i])

src/gh/components/DF_joint_segmentator/metadata.json

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,46 +18,74 @@
1818
"nickname": "i_recompute",
1919
"description": "Connect a button to recompute the registration.",
2020
"optional": true,
21-
"allowTreeAccess": true,
21+
"allowListAccess": false,
2222
"showTypeHints": true,
2323
"scriptParamAccess": "item",
2424
"wireDisplay": "default",
2525
"sourceCount": 0,
2626
"typeHintID": "bool"
2727
},
2828
{
29-
"name": "i_cloud_source",
30-
"nickname": "i_cloud_source",
31-
"description": "The source point cloud.",
32-
"optional": true,
33-
"allowTreeAccess": true,
29+
"name": "i_clusters",
30+
"nickname": "i_clusters",
31+
"description": "The cluster point clouds from normal segmentation.",
32+
"optional": false,
33+
"allowTreeAccess": false,
3434
"showTypeHints": true,
35-
"scriptParamAccess": "item",
35+
"scriptParamAccess": "list",
3636
"wireDisplay": "default",
3737
"sourceCount": 0,
3838
"typeHintID": "pointcloud"
3939
},
4040
{
41-
"name": "i_joints",
41+
"name": "i_joint_faces",
4242
"nickname": "i_joints",
4343
"description": "The joints to extract and analyze",
44-
"optional": true,
45-
"allowTreeAccess": true,
44+
"optional": false,
45+
"allowTreeAccess": false,
4646
"showTypeHints": true,
47-
"scriptParamAccess": "item",
47+
"scriptParamAccess": "list",
4848
"wireDisplay": "default",
4949
"sourceCount": 0,
5050
"typeHintID": "mesh"
51+
},
52+
{
53+
"name": "i_joint_ids",
54+
"nickname": "i_joint_ids",
55+
"description": "The joint ids of the assembly",
56+
"optional": false,
57+
"allowTreeAccess": true,
58+
"showTypeHints": true,
59+
"scriptParamAccess": "list",
60+
"wireDisplay": "default",
61+
"sourceCount": 0,
62+
"typeHintID": "int"
5163
}
5264
],
5365
"outputParameters": [
5466
{
55-
"name": "o_joints",
56-
"nickname": "o_joints",
67+
"name": "o_joint_segments",
68+
"nickname": "o_joint_segments",
5769
"description": "The extracted joints.",
5870
"optional": false,
5971
"sourceCount": 0,
6072
"graft": false
73+
},
74+
{
75+
"name": "o_transforms",
76+
"nickname": "o_transforms",
77+
"description": "The transformations for each joint.",
78+
"optional": false,
79+
"sourceCount": 0,
80+
"graft": false
81+
},
82+
{
83+
"name": "o_reference_point_clouds",
84+
"nickname": "o_reference_point_clouds",
85+
"description": "The reference point clouds of the joints. They are generated from the ",
86+
"optional": false,
87+
"sourceCount": 0,
88+
"graft": false
6189
}
6290
]
6391
}

0 commit comments

Comments
 (0)