Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Fix 4DCT vrg pipeline not properly centering sequences #106

Closed

Conversation

NicerNewerCar
Copy link
Contributor

@NicerNewerCar NicerNewerCar commented Jun 21, 2024

Regression introduced in e036c22

Closes #105

Also resolves this comment #102 (comment)

@NicerNewerCar NicerNewerCar requested review from jcfr and amymmorton June 21, 2024 19:49
@NicerNewerCar

This comment was marked as resolved.

@jcfr
Copy link
Contributor

jcfr commented Jul 8, 2024

We are getting close 🙏

Few nitpicks:

  • move fix into its own commit
  • add the performance change into its own commit
  • move the removal of the threadexecutor into its own pull request

@NicerNewerCar NicerNewerCar force-pushed the bugfix-4dct branch 3 times, most recently from 3cb2228 to 89fb6aa Compare July 8, 2024 20:03
Copy link
Contributor

@jcfr jcfr left a comment

Choose a reason for hiding this comment

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

in onGenerateVRG, after line 512, I suggest to simplify doing something like this:

            # center the volume
            transformOutputDir = os.path.join(mainOutputDir, tfmPath)
            self.logic.createPathsIfNotExists(transformOutputDir)
            
            
            if not self.logic.IsSequenceVolume(volumeNode):
                IO.exportOrigin2DicomTransform(volumeNode, transformOutputDir)
            else:
                # Just export the first frame
                proxyNode = self.logic.getItemInSequence(volumeNode, 0)[0]
                IO.exportOrigin2DicomTransform(proxyNode, transformOutputDir)

                if tfmNode is not None:

                    # if still needed, explain here why calling "AddCenteringTransform" and reverting its effect is still needed

And here is the function exportOrigin2DicomTransform:

def exportOrigin2DicomTransform(volumeNode, exportDir):
    """If volume is not already centered, save corresponding transform as `Origin2Dicom.tfm`"""

    if volumeNode.IsCentered():
        return False

    volumeNode.AddCenteringTransform():

    # Get reference to the centering transform (Volume to Center)
    tfmNode = volumeNode.GetParentTransformNode()

    # Revert effect of "AddCenteringTransform"
    volumeNode.HardenTransform()
    volumeNode.SetAndObserveTransformNodeID(None)

    # Update from "Volume to Center" to "Center to Volume"
    tfmNode.Inverse()

    # Save as "Origin2Dicom.tfm"
    tfmPath = os.path.join(exportDir, "Origin2Dicom.tfm")
    slicer.util.saveNode(tfmNode, tfmPath)

    slicer.mrmlScene.RemoveNode(tfmNode)

    return True

Ideally, we should also look into adding support to call GetCenterPositionRAS from Python, this would simplify the logic.

AutoscoperM/AutoscoperM.py Outdated Show resolved Hide resolved
AutoscoperM/AutoscoperM.py Show resolved Hide resolved
AutoscoperM/AutoscoperM.py Outdated Show resolved Hide resolved
@NicerNewerCar
Copy link
Contributor Author

Ideally, we should also look into adding support to call GetCenterPositionRAS from Python, this would simplify the logic.

This doesn't seem to be exposed in the Python API:

>>> x.GetCenterPositionRAS()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'MRMLCorePython.vtkMRMLScalarVolumeNode' object has no attribute 'GetCenterPositionRAS'

It also seems to be a protected function for the vtkMRMLVolumeNode. Was this exposed somewhere else?

@amymmorton
Copy link
Contributor

Suggest with the depreciation of vrgs- also close this

@amymmorton amymmorton closed this Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatic camera placement for 4DCT
3 participants