Skip to content
Open
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
54 changes: 38 additions & 16 deletions OpenLIFUTransducerTracker/OpenLIFUTransducerTracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,19 +639,8 @@ def setupTransformNode(self):
self.wizard().photoscanMarkupPage.facial_landmarks_fiducial_node.SetAndObserveTransformNodeID(self.photoscan_to_volume_transform_node.GetID())

# Set the center of the transformation to the center of the photocan model node
bounds = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
self.wizard().photoscan.model_node.GetRASBounds(bounds)
center_world = [
(bounds[0] + bounds[1]) / 2,
(bounds[2] + bounds[3]) / 2,
(bounds[4] + bounds[5]) / 2
]

center_local = [0.0,0.0,0.0]
transform_from_world = vtk.vtkGeneralTransform()
self.photoscan_to_volume_transform_node.GetTransformFromWorld(transform_from_world)
transform_from_world.TransformPoint(center_world,center_local )
self.photoscan_to_volume_transform_node.SetCenterOfTransformation(center_local)
photoscan_centroid = self.getTransformedPhotoscanCentroid()
self.photoscan_to_volume_transform_node.SetCenterOfTransformation(photoscan_centroid)

self.photoscan_to_volume_transform_node.SetAndObserveTransformNodeID(self.scaling_transform_node.GetID())
# Add observer after setup
Expand Down Expand Up @@ -737,11 +726,44 @@ def disable_manual_registration(self):
self.update_runICPRegistrationPV_button()

def updateScaledTransformNode(self):
"""Creates a composite transform that scales the photoscan from the centroid of the model, applying the scaling value
set using the the sliding widget"""

compositeTransform = vtk.vtkTransform()
compositeTransform.Identity()
photoscan_centroid = self.getTransformedPhotoscanCentroid()
compositeTransform.Translate(-photoscan_centroid[0], -photoscan_centroid[1], -photoscan_centroid[2]) # Translate the centroid to the origin

scaling_value = self.ui.scalingTransformMRMLSliderWidget.value
scaling_matrix = np.diag([scaling_value, scaling_value, scaling_value, 1])
# Need to also update the origin of the scaling transform
self.scaling_transform_node.SetMatrixTransformToParent(numpy_to_vtk_4x4(scaling_matrix))
compositeTransform.Scale(scaling_value, scaling_value, scaling_value) # apply scaling

compositeTransform.Translate(photoscan_centroid[0], photoscan_centroid[1], photoscan_centroid[2])

finalMatrix = vtk.vtkMatrix4x4()
compositeTransform.GetMatrix(finalMatrix)

self.scaling_transform_node.SetMatrixTransformToParent(finalMatrix)

def getTransformedPhotoscanCentroid(self):
"""Returns the centroid of the photoscan model node.
The centroid is initially calculated in the photoscan's native RAS coordinate
system and then transformed into the volume's coordinate space
using the `photoscan_to_volume_transform_node`."""

bounds = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
self.wizard().photoscan.model_node.GetRASBounds(bounds)
centroid_world = [
(bounds[0] + bounds[1]) / 2,
(bounds[2] + bounds[3]) / 2,
(bounds[4] + bounds[5]) / 2
]

centroid_transformed = [0.0,0.0,0.0]
transform_from_world = vtk.vtkGeneralTransform()
self.photoscan_to_volume_transform_node.GetTransformFromWorld(transform_from_world)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When locking and unlocking things in the transducer tracking wizard, here I sometimes get AttributeError: 'NoneType' object has no attribute 'GetTransformFromWorld', so it seems getTransformedPhotoscanCentroid can get called while self.photoscan_to_volume_transform_node is None

transform_from_world.TransformPoint(centroid_world,centroid_transformed)

return centroid_transformed

def isComplete(self):
"""" Determines if the 'Next' button should be enabled"""
Expand Down