Skip to content

Commit 62095eb

Browse files
ADD: code.py to DF_joint_segmentator component
1 parent 4bb9d7b commit 62095eb

File tree

1 file changed

+36
-9
lines changed
  • src/gh/components/DF_joint_segmentator

1 file changed

+36
-9
lines changed
Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,44 @@
1+
#! python3
2+
13
import Rhino
24
import diffCheck
35
from diffCheck import diffcheck_bindings
46
from diffCheck import df_cvt_bindings as df_cvt
57
import diffCheck.df_util
8+
import scriptcontext as sc
9+
10+
ABSTOL = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance
11+
12+
def main(i_clusters, i_faces, i_joint_ids):
13+
n_joints = max(i_joint_ids) + 1
14+
joints = [ [] for i in range(n_joints) ]
15+
for face, id in zip(i_faces, i_joint_ids):
16+
face.Subdivide()
17+
face.Faces.ConvertQuadsToTriangles()
18+
joints[id].append(df_cvt.cvt_rhmesh_2_dfmesh(face))
19+
joint_clouds = []
20+
registrastions = []
21+
joint_segments = []
22+
df_clouds = [df_cvt.cvt_rhcloud_2_dfcloud(cluster) for cluster in i_clusters]
623

7-
def main():
8-
# assume two inputs: i_cloud and i_joints. i_cloud is the point cloud of the whole object, i_joints is a list of list the meshes of the joints. [[face_1_joint_A, face_2_joint_A, ...], [face_1_joint_B, face_2_joint_B, ...], ...]
9-
# segment the joints from the i_cloud and store them in a list that follows the same structure as i_joints: [joint_A, joint_B, ...]
10-
# for each joint point cloud, perform a registration by populating the corresponding mesh faces of each joint
11-
# apply the registration to the segmented joint point cloud and re-segment the joints
12-
# the result is a list of list of the segmented joints, where each segment is locally registered to the corresponding mesh faces: [[face_1_joint_A_arfter_reg_a, face_2_joint_A_after_reg_a, ...], [face_1_joint_B_after_reg_b, face_2_joint_B_after_reg_b, ...], ...]
13-
# that way we can analyse the joints individually (face 1 of joint A is too much to the left, ...)
14-
pass
24+
for joint in joints:
25+
joint_cloud = diffcheck_bindings.dfb_geometry.DFPointCloud()
26+
for face in joint:
27+
face_cloud = face.sample_points_uniformly(1000)
28+
face_cloud.estimate_normals(knn=30)
29+
joint_cloud.add_points(face_cloud)
30+
joint_clouds.append(df_cvt.cvt_dfcloud_2_rhcloud(joint_cloud))
31+
segment = diffcheck_bindings.dfb_segmentation.DFSegmentation.associate_clusters(joint, df_clouds )
32+
diffcheck_bindings.dfb_segmentation.DFSegmentation.clean_unassociated_clusters(df_clouds, [segment], [joint], 0.1, 0.02)
33+
registration = diffcheck_bindings.dfb_registrations.DFRefinedRegistration.O3DICP(segment, joint_cloud)
34+
res = registration.transformation_matrix
35+
registrastions.append(res)
36+
joint_segments.append(df_cvt.cvt_dfcloud_2_rhcloud(segment))
37+
38+
return joint_segments, joint_clouds, registrastions
1539

1640
if __name__ == "__main__":
17-
a = main()
41+
joint_segments, joint_clouds, registrastions = main(i_clusters, i_faces, i_joint_ids)
42+
43+
for i in range(len(joint_segments)):
44+
joint_segments[i].Transform(df_cvt.cvt_ndarray_2_rh_transform(registrastions[i]))

0 commit comments

Comments
 (0)