|
9 | 9 |
|
10 | 10 | ABSTOL = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance |
11 | 11 |
|
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 |
13 | 28 | n_joints = max(i_joint_ids) + 1 |
14 | 29 | 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): |
16 | 31 | face.Subdivide() |
17 | 32 | face.Faces.ConvertQuadsToTriangles() |
18 | 33 | joints[id].append(df_cvt.cvt_rhmesh_2_dfmesh(face)) |
| 34 | + |
19 | 35 | joint_clouds = [] |
20 | | - registrastions = [] |
| 36 | + registrations = [] |
21 | 37 | joint_segments = [] |
22 | 38 | df_clouds = [df_cvt.cvt_rhcloud_2_dfcloud(cluster) for cluster in i_clusters] |
23 | 39 |
|
| 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 |
24 | 41 | for joint in joints: |
| 42 | + |
| 43 | + # create the reference point cloud |
25 | 44 | joint_cloud = diffcheck_bindings.dfb_geometry.DFPointCloud() |
| 45 | + |
26 | 46 | for face in joint: |
27 | 47 | face_cloud = face.sample_points_uniformly(1000) |
28 | 48 | face_cloud.estimate_normals(knn=30) |
29 | 49 | joint_cloud.add_points(face_cloud) |
| 50 | + |
30 | 51 | joint_clouds.append(df_cvt.cvt_dfcloud_2_rhcloud(joint_cloud)) |
| 52 | + |
| 53 | + # find the corresponding clusters and merge them |
31 | 54 | segment = diffcheck_bindings.dfb_segmentation.DFSegmentation.associate_clusters(joint, df_clouds ) |
32 | 55 | 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 |
33 | 58 | registration = diffcheck_bindings.dfb_registrations.DFRefinedRegistration.O3DICP(segment, joint_cloud) |
34 | 59 | res = registration.transformation_matrix |
35 | | - registrastions.append(res) |
| 60 | + |
| 61 | + registrations.append(df_cvt.cvt_ndarray_2_rh_transform(res)) |
36 | 62 | joint_segments.append(df_cvt.cvt_dfcloud_2_rhcloud(segment)) |
37 | 63 |
|
38 | | - return joint_segments, joint_clouds, registrastions |
| 64 | + return joint_segments, joint_clouds, registrations |
39 | 65 |
|
40 | 66 | 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) |
42 | 68 |
|
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]) |
0 commit comments