Skip to content

Commit e2dead4

Browse files
feat-wip: creation of pose comparison component
1 parent 8f668b1 commit e2dead4

File tree

4 files changed

+117
-0
lines changed

4 files changed

+117
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#! python3
2+
3+
import Rhino
4+
from ghpythonlib.componentbase import executingcomponent as component
5+
6+
import System
7+
8+
import numpy
9+
10+
11+
class DFPoseComparison(component):
12+
def RunScript(self,
13+
i_CAD_poses: System.Collections.Generic.List[Rhino.Geometry.Plane],
14+
i_measured_poses: System.Collections.Generic.List[Rhino.Geometry.Plane]):
15+
16+
if len(i_CAD_poses) != len(i_measured_poses):
17+
ghenv.Component.Message = "evaluation during assembly" # noqa: F821
18+
else:
19+
ghenv.Component.Message = "evaluation of completed assembly" # noqa: F821
20+
21+
o_distances = []
22+
o_angles = []
23+
o_transforms_cad_to_measured = []
24+
# Compare the origins
25+
# measure the distance between the origins of the CAD pose and the measured pose and output this in the component
26+
for i in range(len(i_measured_poses)):
27+
cad_origin = i_CAD_poses[i].Origin
28+
measured_origin = i_measured_poses[i].Origin
29+
distance = cad_origin.DistanceTo(measured_origin)
30+
o_distances.append(distance)
31+
32+
# Compare the orientations using the formula: $$ \theta = \arccos\left(\frac{\text{trace}(R_{\text{pred}}^T R_{\text{meas}}) - 1}{2}\right) $$
33+
transform_o_to_cad = Rhino.Geometry.Transform.PlaneToPlane(Rhino.Geometry.Plane.WorldXY, i_CAD_poses[i])
34+
transform_o_to_measured = Rhino.Geometry.Transform.PlaneToPlane(Rhino.Geometry.Plane.WorldXY, i_measured_poses[i])
35+
np_transform_o_to_cad = numpy.array(transform_o_to_cad.ToDoubleArray(rowDominant=True)).reshape((4, 4))
36+
np_transform_o_to_measured = numpy.array(transform_o_to_measured.ToDoubleArray(rowDominant=True)).reshape((4, 4))
37+
38+
R_cad = np_transform_o_to_cad[:3, :3]
39+
R_measured = np_transform_o_to_measured[:3, :3]
40+
R_rel = numpy.dot(R_cad.T, R_measured)
41+
theta = numpy.arccos(numpy.clip((numpy.trace(R_rel) - 1) / 2, -1.0, 1.0))
42+
o_angles.append(theta)
43+
44+
# Compute the transformation matrix between the CAD pose and the measured pose
45+
transform_cad_to_measured = Rhino.Geometry.Transform.PlaneToPlane(i_CAD_poses[i], i_measured_poses[i])
46+
o_transforms_cad_to_measured.append(transform_cad_to_measured)
47+
48+
return [o_distances, o_angles, o_transforms_cad_to_measured]
14.7 KB
Loading
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"name": "DFPoseComparison",
3+
"nickname": "DFPoseComparison",
4+
"category": "diffCheck",
5+
"subcategory": "Analysis",
6+
"description": "Compares CAD poses with measured poses to compute errors.",
7+
"exposure": 4,
8+
"instanceGuid": "13d76641-6f4f-4e78-a7dd-e64e176ffb2a",
9+
"ghpython": {
10+
"hideOutput": true,
11+
"hideInput": true,
12+
"isAdvancedMode": true,
13+
"marshalOutGuids": true,
14+
"iconDisplay": 2,
15+
"inputParameters": [
16+
{
17+
"name": "i_CAD_poses",
18+
"nickname": "i_CAD_poses",
19+
"description": "The CAD poses to compare.",
20+
"optional": false,
21+
"allowTreeAccess": true,
22+
"showTypeHints": true,
23+
"scriptParamAccess": "list",
24+
"wireDisplay": "default",
25+
"sourceCount": 0,
26+
"typeHintID": "plane"
27+
},
28+
{
29+
"name": "i_measured_poses",
30+
"nickname": "i_measured_poses",
31+
"description": "The measured poses to compare against the CAD poses.",
32+
"optional": false,
33+
"allowTreeAccess": true,
34+
"showTypeHints": true,
35+
"scriptParamAccess": "list",
36+
"wireDisplay": "default",
37+
"sourceCount": 0,
38+
"typeHintID": "plane"
39+
}
40+
],
41+
"outputParameters": [
42+
{
43+
"name": "o_distances",
44+
"nickname": "o_distances",
45+
"description": "The distances between the CAD pose origins and measured pose origins.",
46+
"optional": false,
47+
"sourceCount": 0,
48+
"graft": false
49+
},
50+
{
51+
"name": "o_angles",
52+
"nickname": "o_angles",
53+
"description": "The angles between the CAD pose orientations and measured pose orientations.",
54+
"optional": false,
55+
"sourceCount": 0,
56+
"graft": false
57+
},
58+
{
59+
"name": "o_transforms_cad_to_measured",
60+
"nickname": "o_transforms_cad_to_measured",
61+
"description": "The transformation matrices from CAD poses to measured poses.",
62+
"optional": false,
63+
"sourceCount": 0,
64+
"graft": false
65+
}
66+
]
67+
}
68+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$$ \theta = \arccos\left(\frac{\text{trace}(R_{\text{pred}}^T R_{\text{meas}}) - 1}{2}\right) $$

0 commit comments

Comments
 (0)