From 3a48c78bd96d3a1ebccf93d0c0991c5f883db975 Mon Sep 17 00:00:00 2001 From: "Mauro I. Dominguez" Date: Tue, 3 Jan 2023 19:49:00 -0300 Subject: [PATCH 1/2] ENH: harden transformToWorld of exported models Related #14 --- OpenAnatomyExport/OpenAnatomyExport.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/OpenAnatomyExport/OpenAnatomyExport.py b/OpenAnatomyExport/OpenAnatomyExport.py index b654e7b..85e39f9 100644 --- a/OpenAnatomyExport/OpenAnatomyExport.py +++ b/OpenAnatomyExport/OpenAnatomyExport.py @@ -469,6 +469,12 @@ def addModelToRenderer(self, inputModelNode, outputModelNode, boostGouraudColor= outputPolyData.GetPointData().GetNormals().SetName("NORMAL") outputModelNode.SetAndObservePolyData(outputPolyData) + transformOutputModelToWorld = vtk.vtkGeneralTransform() + slicer.vtkMRMLTransformNode.GetTransformBetweenNodes(inputModelNode.GetParentTransformNode(), None, transformOutputModelToWorld) + transformToWorldFilter = vtk.vtkTransformPolyDataFilter() + transformToWorldFilter.SetTransform(transformOutputModelToWorld) + transformToWorldFilter.SetInputData(outputPolyData) + ras2lps = vtk.vtkMatrix4x4() ras2lps.SetElement(0,0,-1) ras2lps.SetElement(1,1,-1) @@ -476,7 +482,7 @@ def addModelToRenderer(self, inputModelNode, outputModelNode, boostGouraudColor= ras2lpsTransform.SetMatrix(ras2lps) transformer = vtk.vtkTransformPolyDataFilter() transformer.SetTransform(ras2lpsTransform) - transformer.SetInputConnection(outputModelNode.GetPolyDataConnection()) + transformer.SetInputConnection(transformToWorldFilter.GetOutputPort()) actor = vtk.vtkActor() mapper = vtk.vtkPolyDataMapper() From 330bb3e62fe796cb4b10d9b7e3acf1c68e003af1 Mon Sep 17 00:00:00 2001 From: "Mauro I. Dominguez" Date: Fri, 24 Feb 2023 19:09:34 -0300 Subject: [PATCH 2/2] ENH: concatenate transforms instead of using two transformPolyDataFilters --- OpenAnatomyExport/OpenAnatomyExport.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/OpenAnatomyExport/OpenAnatomyExport.py b/OpenAnatomyExport/OpenAnatomyExport.py index 85e39f9..3bcf67e 100644 --- a/OpenAnatomyExport/OpenAnatomyExport.py +++ b/OpenAnatomyExport/OpenAnatomyExport.py @@ -469,24 +469,19 @@ def addModelToRenderer(self, inputModelNode, outputModelNode, boostGouraudColor= outputPolyData.GetPointData().GetNormals().SetName("NORMAL") outputModelNode.SetAndObservePolyData(outputPolyData) - transformOutputModelToWorld = vtk.vtkGeneralTransform() - slicer.vtkMRMLTransformNode.GetTransformBetweenNodes(inputModelNode.GetParentTransformNode(), None, transformOutputModelToWorld) + transformOutputModelToWorldRAS = vtk.vtkGeneralTransform() + transformOutputModelToWorldRAS.PostMultiply() + slicer.vtkMRMLTransformNode.GetTransformBetweenNodes(inputModelNode.GetParentTransformNode(), None, transformOutputModelToWorldRAS) + + transformOutputModelToWorldLPS = transformOutputModelToWorldRAS + transformOutputModelToWorldLPS.Scale(-1.0, -1.0, 1.0) #ras2lpsTransform transformToWorldFilter = vtk.vtkTransformPolyDataFilter() - transformToWorldFilter.SetTransform(transformOutputModelToWorld) + transformToWorldFilter.SetTransform(transformOutputModelToWorldLPS) transformToWorldFilter.SetInputData(outputPolyData) - ras2lps = vtk.vtkMatrix4x4() - ras2lps.SetElement(0,0,-1) - ras2lps.SetElement(1,1,-1) - ras2lpsTransform = vtk.vtkTransform() - ras2lpsTransform.SetMatrix(ras2lps) - transformer = vtk.vtkTransformPolyDataFilter() - transformer.SetTransform(ras2lpsTransform) - transformer.SetInputConnection(transformToWorldFilter.GetOutputPort()) - actor = vtk.vtkActor() mapper = vtk.vtkPolyDataMapper() - mapper.SetInputConnection(transformer.GetOutputPort()) + mapper.SetInputConnection(transformToWorldFilter.GetOutputPort()) actor.SetMapper(mapper) displayNode = outputModelNode.GetDisplayNode()