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

Miscellaneous fixes #5

Merged
merged 3 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(EXTENSION_CONTRIBUTORS "MONAI Consortium")
set(EXTENSION_DESCRIPTION "This extension helps to run chain of MONAI transforms and visualize every stage over an image/label. See more information in <a href=\"https://github.com/Project-MONAI/MONAILabel\">MONAILabel documentation</a>.")
set(EXTENSION_ICONURL "https://raw.githubusercontent.com/Project-MONAI/SlicerMONAIViz/main/MONAIViz/Resources/Icons/MONAIViz.png")
set(EXTENSION_SCREENSHOTURLS "https://github.com/Project-MONAI/SlicerMONAIViz/raw/main/Screenshots/1.jpg https://github.com/Project-MONAI/SlicerMONAIViz/raw/main/Screenshots/2.jpg https://github.com/Project-MONAI/SlicerMONAIViz/raw/main/Screenshots/3.jpg https://github.com/Project-MONAI/SlicerMONAIViz/raw/main/Screenshots/4.jpg")
set(EXTENSION_DEPENDS "NA") # Specified as a list or "NA" if no dependencies
set(EXTENSION_DEPENDS "PyTorch") # Specified as a list or "NA" if no dependencies

#-----------------------------------------------------------------------------
# Extension dependencies
Expand Down
17 changes: 14 additions & 3 deletions MONAIViz/MONAIViz.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,16 @@ def onAddTransform(self):

t = self.ui.transformsComboBox.currentText
m = self.ui.modulesComboBox.currentText
self.addTransform(-1, None, t, None)

v = ""
if t[-1] == "d": # this is a dictionary transform
# now exclude some transforms whose name happens to end with d
if t not in ["AffineGrid", "Decollated", "RandAffineGrid", "RandDeformGrid"]:
image_key = slicer.util.settingsValue("SlicerMONAIViz/imageKey", "image")
label_key = slicer.util.settingsValue("SlicerMONAIViz/labelKey", "label")
v = f"keys=['{image_key}', '{label_key}']"

self.addTransform(-1, None, t, v)

def addTransform(self, pos, m, t, v):
table = self.ui.transformTable
Expand Down Expand Up @@ -558,6 +567,7 @@ def onRunTransform(self):
volumeNode.SetOrigin(origin)
volumeNode.SetSpacing(spacing)
volumeNode.SetIJKToRASDirections(direction)
# logging.info(f"Volume direction: {direction}")

l = self.ctx.get_tensor(key=label_key)
labelNode = None
Expand All @@ -568,6 +578,7 @@ def onRunTransform(self):
labelNode.SetOrigin(origin)
labelNode.SetSpacing(spacing)
labelNode.SetIJKToRASDirections(direction)
# logging.info(f"Label direction: {direction}")
slicer.util.setSliceViewerLayers(volumeNode, label=labelNode, fit=True)

self.ctx.set_next(next_idx, next_exp)
Expand Down Expand Up @@ -852,8 +863,8 @@ def get_tensor_osd(self, key, scale=False):
else key_tensor.affine.numpy()
)

convert_aff_mat = np.diag([-1, -1, 1, 1])
affine = convert_aff_mat @ affine
# convert_aff_mat = np.diag([-1, -1, 1, 1]) # RAS <-> LPS conversion matrix
# affine = convert_aff_mat @ affine # convert from RAS to LPS

dim = affine.shape[0] - 1
_origin_key = (slice(-1), -1)
Expand Down