Configure ROI to match volume through code

Hi,

I’m trying to use a ROI markup to designate a rotation transform (I don’t want an actual transform because reasons). I initially configure the ROI as recommended in the script repository. The problem is that this seems to create a “fragile” ROI – there is something funny going on between its ObjectToNodeMatrix and ObjectToWorldMatrix, and as a result, any further attempt to modify it via code throws it aside (the image origin is not at 0,0,0).

More details:

Right after running the code from the repository, if I pick up the ROI:

>>> nodes = slicer.mrmlScene.GetNodesByClass("vtkMRMLMarkupsROINode")
>>> roi = nodes.GetItemAsObject(0)

And look at its matrices (some unimportant details removed)

>>> print(roi.GetObjectToNodeMatrix())
    1 0 0 -64.8817 
    0 1 0 -65.6043 
    0 0 1 81.1599 
    0 0 0 1 
>>> print(roi.GetObjectToWorldMatrix())
    1 0 0 -64.8817 
    0 1 0 -65.6043 
    0 0 1 81.1599 
    0 0 0 1 

But if now I trigger computations (which apparently should have happened) – without otherwise touching anything –

>>> roi.GetObjectToNodeMatrix().Modified()

Then I can already see the ROI jump. If I now repeat the above, the ObjectToNodeMatrix looks the same, but

>>> print(roi.GetObjectToWorldMatrix())
    1 0 0 0 
    0 1 0 0 
    0 0 1 0 
    0 0 0 1 

Is this as intended? Am I doing something wrong?

(Just to be on the safe side – in my code, I also set up two display nodes for the ROI, and turn interaction controls on and off, but I don’t think that should affect the translation matrices in any way)

Thanks!