This continues the topic Configure ROI to match volume through code but I think that post was not phrased very well, so let’s start again:
I’m creating a ROI with code based on an example from the script repository:
self.roiNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsROINode")
cropVolumeParameters = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLCropVolumeParametersNode")
cropVolumeParameters.SetInputVolumeNodeID(self.volumeNode.GetID())
cropVolumeParameters.SetROINodeID(self.roiNode.GetID())
slicer.modules.cropvolume.logic().FitROIToInputVolume(cropVolumeParameters)
slicer.mrmlScene.RemoveNode(cropVolumeParameters)
I get this ROI object:
But now if I tell it its ObjectToNode matrix is updated, it jumps (I need this because, as you can see, I give users rotation handles, and I also want to give them a “reset” button). And indeed, the center in the world has changed:
Now, here come some funnier parts: If I try to reset the center in the world, it doesn’t work:
>>> roi.SetCenterWorld(center)
>>> roi.GetCenterWorld()
vtkmodules.vtkCommonDataModel.vtkVector3d([0.0, 0.0, 0.0])
>>> center
vtkmodules.vtkCommonDataModel.vtkVector3d([0.38079845905303955, -22.919204711914062, -175.25])
If I first reset the center to 0, then it semi-works: After
>>> roi.SetCenterWorld([0,0,0])
>>> roi.SetCenterWorld(center)
the ROI is visually back to its place fitting the volume, but
>>> roi.GetCenterWorld()
vtkmodules.vtkCommonDataModel.vtkVector3d([0.0, 0.0, 0.0])
I’m not even sure what exactly is the bug I should report, but I’m pretty convinced that this Can’t Be Right .
Slicer 5.6.2 on Ubuntu 20.04.