Created
June 26, 2025 17:56
-
-
Save drouin-simon/e2b5ecf77d53697e2e20c1d8fd016ea3 to your computer and use it in GitHub Desktop.
Tie a sphere transform to the ROI of a FiberBundle managed by SlicerDMRI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| # Get the transform of the sphere | |
| t = slicer.mrmlScene.GetNodesByName("center").GetItemAsObject(0) | |
| mat = vtk.vtkMatrix4x4() | |
| t.GetMatrixTransformToParent(mat) | |
| # Get the region extracting the ROI from the fibers | |
| fbn = slicer.mrmlScene.GetNodesByClass("vtkMRMLFiberBundleNode").GetItemAsObject(0) | |
| efr = fbn.GetExtractFromROI() | |
| # Create a sphere implicit function and enable masking | |
| sphereFunc = vtk.vtkSphere() | |
| sphereFunc.SetRadius(5.0) | |
| sphereFunc.SetCenter([mat.GetElement(0, 3), mat.GetElement(1, 3), mat.GetElement(2, 3)]) | |
| efr.SetImplicitFunction(sphereFunc) | |
| efr.Modified() | |
| fbn.SetSelectWithMarkups(True) | |
| # Setup the callback to move the roi when the transform changes | |
| def onTransformModified(caller, event): | |
| caller.GetMatrixTransformToParent(mat) | |
| sphereFunc.SetCenter([mat.GetElement(0, 3), mat.GetElement(1, 3), mat.GetElement(2, 3)]) | |
| efr.Modified() | |
| observerTag = t.AddObserver(slicer.vtkMRMLTransformNode.TransformModifiedEvent, onTransformModified) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script will clip a fiber bundle to maintain only the fibers going through a spherical region. The script updates the clipping every time a transform named "center" is modified.
To use this script:
After running the script, fibers going through the sphere should be conserved and others clipped. Moving the transform should automatically update the clipping.