Skip to content

Commit

Permalink
Merge pull request #5 from dzenanz/main
Browse files Browse the repository at this point in the history
Miscellaneous fixes
  • Loading branch information
wyli authored Feb 27, 2023
2 parents 7696226 + dc1451e commit 27c6fa8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
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

0 comments on commit 27c6fa8

Please sign in to comment.