Skip to content

Commit 5745db8

Browse files
feat: update DFMainPCAxes to save the new poses only when user triggers it
1 parent de7b580 commit 5745db8

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed
Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#! python3
22

3-
from diffCheck import diffcheck_bindings
43
from diffCheck import df_cvt_bindings
54
from diffCheck import df_poses
65

@@ -14,6 +13,8 @@
1413
class DFMainPCAxes(component):
1514
def RunScript(self,
1615
i_clouds: System.Collections.Generic.List[Rhino.Geometry.PointCloud],
16+
i_assembly,
17+
i_save: bool,
1718
i_reset: bool):
1819

1920
planes = []
@@ -22,7 +23,6 @@ def RunScript(self,
2223
all_poses_in_time.reset()
2324
return None, None
2425

25-
previous_poses = all_poses_in_time.get_last_poses()
2626
all_poses_this_time = []
2727
for i, cloud in enumerate(i_clouds):
2828
df_cloud = df_cvt_bindings.cvt_rhcloud_2_dfcloud(cloud)
@@ -34,23 +34,13 @@ def RunScript(self,
3434
df_points = df_cloud.get_axis_aligned_bounding_box()
3535
df_point = (df_points[0] + df_points[1]) / 2
3636
rh_point = Rhino.Geometry.Point3d(df_point[0], df_point[1], df_point[2])
37-
vectors = []
38-
# Get the main axes of the point cloud
39-
previous_pose = previous_poses[i] if previous_poses else None
40-
if previous_pose:
41-
rh_previous_xDirection = Rhino.Geometry.Vector3d(previous_pose.xDirection[0], previous_pose.xDirection[1], previous_pose.xDirection[2])
42-
rh_previous_yDirection = Rhino.Geometry.Vector3d(previous_pose.yDirection[0], previous_pose.yDirection[1], previous_pose.yDirection[2])
43-
n_faces = all_poses_in_time.poses_per_element_dictionary[f"element_{i}"].n_faces
44-
else:
45-
rh_previous_xDirection = None
46-
rh_previous_yDirection = None
47-
n_faces = len(diffcheck_bindings.dfb_segmentation.DFSegmentation.segment_by_normal(df_cloud, 12, int(len(df_cloud.points)/20), True, int(len(df_cloud.points)/200), 1))
4837

49-
axes = df_cloud.get_principal_axes(n_faces)
38+
axes = df_cloud.get_principal_axes(3)
39+
vectors = []
5040
for axe in axes:
5141
vectors.append(Rhino.Geometry.Vector3d(axe[0], axe[1], axe[2]))
5242

53-
new_xDirection, new_yDirection = df_poses.select_vectors(vectors, rh_previous_xDirection, rh_previous_yDirection)
43+
new_xDirection, new_yDirection = df_poses.select_vectors(vectors, i_assembly.beams[i].plane.XAxis, i_assembly.beams[i].plane.YAxis)
5444

5545
pose = df_poses.DFPose(
5646
origin = [rh_point.X, rh_point.Y, rh_point.Z],
@@ -60,6 +50,7 @@ def RunScript(self,
6050
plane = Rhino.Geometry.Plane(origin = rh_point, xDirection=new_xDirection, yDirection=new_yDirection)
6151
planes.append(plane)
6252

63-
all_poses_in_time.add_step(all_poses_this_time)
53+
if i_save:
54+
all_poses_in_time.add_step(all_poses_this_time)
6455

6556
return [planes, all_poses_in_time]

src/gh/components/DF_main_pc_axes/metadata.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
"sourceCount": 0,
2626
"typeHintID": "pointcloud"
2727
},
28+
{
29+
"name": "i_assembly",
30+
"nickname": "i_assembly",
31+
"description": "The DFAssembly object to deconstruct.",
32+
"optional": false,
33+
"allowTreeAccess": true,
34+
"showTypeHints": true,
35+
"scriptParamAccess": "item",
36+
"wireDisplay": "default",
37+
"sourceCount": 0,
38+
"typeHintID": "ghdoc"
39+
},
2840
{
2941
"name": "i_reset",
3042
"nickname": "i_reset",
@@ -36,6 +48,18 @@
3648
"wireDisplay": "default",
3749
"sourceCount": 0,
3850
"typeHintID": "bool"
51+
},
52+
{
53+
"name": "i_save",
54+
"nickname": "i_save",
55+
"description": "save the poses computed at this iteration",
56+
"optional": true,
57+
"allowTreeAccess": false,
58+
"showTypeHints": true,
59+
"scriptParamAccess": "item",
60+
"wireDisplay": "default",
61+
"sourceCount": 0,
62+
"typeHintID": "bool"
3963
}
4064
],
4165
"outputParameters": [

0 commit comments

Comments
 (0)