Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/gh/components/DF_pose_comparison/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#! python3

import Rhino
from ghpythonlib.componentbase import executingcomponent as component

import System

import numpy


class DFPoseComparison(component):
def RunScript(self,
i_CAD_poses: System.Collections.Generic.List[Rhino.Geometry.Plane],
i_measured_poses: System.Collections.Generic.List[Rhino.Geometry.Plane]):

if len(i_CAD_poses) != len(i_measured_poses):
ghenv.Component.Message = "evaluation during assembly" # noqa: F821
else:
ghenv.Component.Message = "evaluation of completed assembly" # noqa: F821

o_distances = []
o_angles = []
o_transforms_cad_to_measured = []
# Compare the origins
# measure the distance between the origins of the CAD pose and the measured pose and output this in the component
for i in range(len(i_measured_poses)):
cad_origin = i_CAD_poses[i].Origin
measured_origin = i_measured_poses[i].Origin
distance = cad_origin.DistanceTo(measured_origin)
o_distances.append(distance)

# Compare the orientations using the formula: $$ \theta = \arccos\left(\frac{\text{trace}(R_{\text{pred}}^T R_{\text{meas}}) - 1}{2}\right) $$
transform_o_to_cad = Rhino.Geometry.Transform.PlaneToPlane(Rhino.Geometry.Plane.WorldXY, i_CAD_poses[i])
transform_o_to_measured = Rhino.Geometry.Transform.PlaneToPlane(Rhino.Geometry.Plane.WorldXY, i_measured_poses[i])
np_transform_o_to_cad = numpy.array(transform_o_to_cad.ToDoubleArray(rowDominant=True)).reshape((4, 4))
np_transform_o_to_measured = numpy.array(transform_o_to_measured.ToDoubleArray(rowDominant=True)).reshape((4, 4))

R_cad = np_transform_o_to_cad[:3, :3]
R_measured = np_transform_o_to_measured[:3, :3]
R_rel = numpy.dot(R_cad.T, R_measured)
theta = numpy.arccos(numpy.clip((numpy.trace(R_rel) - 1) / 2, -1.0, 1.0))
o_angles.append(theta)

# Compute the transformation matrix between the CAD pose and the measured pose
transform_cad_to_measured = Rhino.Geometry.Transform.PlaneToPlane(i_CAD_poses[i], i_measured_poses[i])
o_transforms_cad_to_measured.append(transform_cad_to_measured)

return [o_distances, o_angles, o_transforms_cad_to_measured]
Binary file added src/gh/components/DF_pose_comparison/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions src/gh/components/DF_pose_comparison/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"name": "DFPoseComparison",
"nickname": "DFPoseComparison",
"category": "diffCheck",
"subcategory": "Analysis",
"description": "Compares CAD poses with measured poses to compute errors.",
"exposure": 4,
"instanceGuid": "13d76641-6f4f-4e78-a7dd-e64e176ffb2a",
"ghpython": {
"hideOutput": true,
"hideInput": true,
"isAdvancedMode": true,
"marshalOutGuids": true,
"iconDisplay": 2,
"inputParameters": [
{
"name": "i_CAD_poses",
"nickname": "i_CAD_poses",
"description": "The CAD poses to compare.",
"optional": false,
"allowTreeAccess": true,
"showTypeHints": true,
"scriptParamAccess": "list",
"wireDisplay": "default",
"sourceCount": 0,
"typeHintID": "plane"
},
{
"name": "i_measured_poses",
"nickname": "i_measured_poses",
"description": "The measured poses to compare against the CAD poses.",
"optional": false,
"allowTreeAccess": true,
"showTypeHints": true,
"scriptParamAccess": "list",
"wireDisplay": "default",
"sourceCount": 0,
"typeHintID": "plane"
}
],
"outputParameters": [
{
"name": "o_distances",
"nickname": "o_distances",
"description": "The distances between the CAD pose origins and measured pose origins.",
"optional": false,
"sourceCount": 0,
"graft": false
},
{
"name": "o_angles",
"nickname": "o_angles",
"description": "The angles between the CAD pose orientations and measured pose orientations.",
"optional": false,
"sourceCount": 0,
"graft": false
},
{
"name": "o_transforms_cad_to_measured",
"nickname": "o_transforms_cad_to_measured",
"description": "The transformation matrices from CAD poses to measured poses.",
"optional": false,
"sourceCount": 0,
"graft": false
}
]
}
}
Loading