Skip to content

Commit

Permalink
Merge pull request #57 from Leengit/visualize_oct
Browse files Browse the repository at this point in the history
BUG: Remove extraneous code and widgets from VPAWVisualizeOCT
  • Loading branch information
Leengit committed Jun 12, 2024
2 parents 63a597e + 4a4d7ac commit 53282e7
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 408 deletions.
38 changes: 18 additions & 20 deletions Modules/Scripted/VPAWModel/VPAWModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def registerSampleData():
Add data sets to Sample Data module.
"""
# It is always recommended to provide sample data for users to make it easy to try
# the module, but if no sample data is available then this method (and associated
# the module, but if no sample data are available then this method (and associated
# startupCompeted signal connection) can be removed.

pass
Expand Down Expand Up @@ -261,13 +261,13 @@ def updateButtonStatesAndTooltips(self):
else:
self.ui.linkPediatricAirwayAtlasButton.toolTip = (
"Install is disabled; first select a valid source code directory for"
+ " the Pediatric Airway Atlas"
" the Pediatric Airway Atlas"
)
self.ui.linkPediatricAirwayAtlasButton.enabled = False

self.ui.VPAWRootDirectory.toolTip = (
"Directory containing FilteredControlBlindingLogUniqueScanFiltered.xls,"
+ " images/*, and landmarks/*."
" images/*, and landmarks/*."
)
self.ui.VPAWModelDirectory.toolTip = (
"Directory containing file named like '116(158.10-38.AM.24.Mar).pth'"
Expand All @@ -283,7 +283,7 @@ def updateButtonStatesAndTooltips(self):
else:
self.ui.runPediatricAirwayAtlasButton.toolTip = (
"Run is disabled; first select input/output root directory and models"
+ " directory"
" directory"
)
self.ui.runPediatricAirwayAtlasButton.enabled = False

Expand Down Expand Up @@ -469,7 +469,7 @@ def linkPediatricAirwayAtlas(self, pediatricAirwayAtlasDirectory):
stopTime = time.time()
logging.info(
f"Pediatric Airway Atlas installation completed in {stopTime-startTime:.2f}"
+ " seconds",
" seconds",
)
return response

Expand Down Expand Up @@ -500,7 +500,7 @@ def ensureModulePath(self, directory):
except ImportError:
slicer.util.errorDisplay(
f"Unable to find pediatric_airway_atlas.{import_name}\n"
+ "Check the console for details.",
"Check the console for details.",
"Install Error",
)
return False
Expand Down Expand Up @@ -615,16 +615,14 @@ def runPediatricAirwayAtlas(
# self.convertCTScansToNRRD(vPAWRootDirectory)
response = self.convertFCSVLandmarksToP3(
vPAWRootDirectory, patientPrefix,
) and self.runSegmentation(
vPAWRootDirectory, vPAWModelDirectory, patientPrefix,
)
) and self.runSegmentation(vPAWRootDirectory, vPAWModelDirectory, patientPrefix)
if response:
slicer.util.infoDisplay("The pipeline has completed", "Pipeline ran")

stopTime = time.time()
logging.info(
f"Pediatric Airway Atlas pipeline completed in {stopTime-startTime:.2f}"
+ " seconds",
" seconds",
)
return response

Expand Down Expand Up @@ -655,11 +653,11 @@ def convertFCSVLandmarksToP3(self, vPAWRootDirectory, patientPrefix):
except Exception:
slicer.util.errorDisplay(
"The run failed. It may be that a non-blank patient prefix is"
+ " not supported by this version of pediatric_airway_atlas"
+ ".conversion_utils.generate_pixel_space_landmarks."
+ " Please update pediatric_airway_atlas and try again."
+ " Alternatively, it may be that you entered a patient prefix"
+ " that does not exist.",
" not supported by this version of pediatric_airway_atlas"
".conversion_utils.generate_pixel_space_landmarks."
" Please update pediatric_airway_atlas and try again."
" Alternatively, it may be that you entered a patient prefix"
" that does not exist.",
"Run Error",
)
return False
Expand Down Expand Up @@ -780,11 +778,11 @@ def runSegmentation(self, vPAWRootDirectory, vPAWModelDirectory, patientPrefix):
except Exception:
slicer.util.errorDisplay(
"The run failed. It may be that a non-blank patient prefix is"
+ " not supported by this version of pediatric_airway_atlas"
+ ".atlas_builder_configurable."
+ " Please update pediatric_airway_atlas and try again."
+ " Alternatively, it may be that you entered a patient prefix"
+ " that does not exist.",
" not supported by this version of pediatric_airway_atlas"
".atlas_builder_configurable."
" Please update pediatric_airway_atlas and try again."
" Alternatively, it may be that you entered a patient prefix"
" that does not exist.",
"Run Error",
)
return False
Expand Down
15 changes: 5 additions & 10 deletions Modules/Scripted/VPAWModelOCT/VPAWModelOCT.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def registerSampleData():
Add data sets to Sample Data module.
"""
# It is always recommended to provide sample data for users to make it easy to try
# the module, but if no sample data is available then this method (and associated
# the module, but if no sample data are available then this method (and associated
# startupCompeted signal connection) can be removed.

pass
Expand Down Expand Up @@ -240,7 +240,7 @@ def updateButtonStatesAndTooltips(self):
else:
self.ui.linkOCTSegButton.toolTip = (
"Install is disabled; first select a valid source code directory for"
+ " the OCT Segmentation"
" the OCT Segmentation"
)
self.ui.linkOCTSegButton.enabled = False

Expand Down Expand Up @@ -435,7 +435,7 @@ def linkOCTSeg(self, octSegDirectory):
stopTime = time.time()
logging.info(
f"OCT Segmentation installation completed in {stopTime-startTime:.2f}"
+ " seconds",
" seconds",
)
return response

Expand Down Expand Up @@ -558,11 +558,7 @@ def installAndImportDependencies(self):
self.showInstalledModules(installed_modules)
return True

def runOCTSeg(
self,
octSegDirectory,
vPAWOCTConfigFile,
):
def runOCTSeg(self, octSegDirectory, vPAWOCTConfigFile):
"""
Run the OCT Segmentation pipeline.
Can be used without GUI widget.
Expand Down Expand Up @@ -597,8 +593,7 @@ def runOCTSeg(

stopTime = time.time()
logging.info(
f"OCT Segmentation pipeline completed in {stopTime-startTime:.2f}"
+ " seconds",
f"OCT Segmentation pipeline completed in {stopTime-startTime:.2f} seconds",
)
return response

Expand Down
97 changes: 70 additions & 27 deletions Modules/Scripted/VPAWVisualize/VPAWVisualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,102 @@
import pickle as pk
from pathlib import Path

import numpy as np
import vtk

import ctk
import numpy as np
import qt
import slicer
import slicer.ScriptedLoadableModule
import slicer.util
import vtk
from vpawvisualizelib.isosurfaces import isosurfaces_from_volume


def summary_repr(contents):
def summary_repr(contents, collapseSequences=False):
"""
Like Python `repr`, returns a string representing the contents. However, numpy
arrays are summarized as their shape and unknown types are summarized by their type.
Parameters
----------
contents : Python object
contents :
Python object
collapseSequences :
Set to True to summarize only the first of any list, tuple, or set that has
length longer than one. In contrast, a dict will be presented in full.
Returns
-------
A string representation of a summary of the object
"""
if isinstance(
contents, (bool, int, float, str, np.int32, np.int64, np.float32, np.float64),
):
return repr(contents)
if isinstance(contents, (list, tuple, dict, set)) and len(contents) == 0:
return repr(type(contents)())
if isinstance(contents, list):
return "[" + ", ".join([summary_repr(elem) for elem in contents]) + "]"
elif isinstance(contents, tuple):
if len(contents) == 1:
return "(" + summary_repr(contents[0]) + ",)"
else:
return "(" + ", ".join([summary_repr(elem) for elem in contents]) + ")"
elif isinstance(contents, dict):
if collapseSequences and len(contents) > 1:
return (
"["
+ summary_repr(contents[0], collapseSequences)
+ f", 'and {len(contents) - 1} more'"
+ "]"
)
return (
"["
+ ", ".join([summary_repr(elem, collapseSequences) for elem in contents])
+ "]"
)
if isinstance(contents, tuple):
if collapseSequences and len(contents) > 1:
return (
"("
+ summary_repr(contents[0], collapseSequences)
+ f", 'and {len(contents) - 1} more'"
+ ",)"
)
return (
"("
+ ", ".join([summary_repr(elem, collapseSequences) for elem in contents])
+ ",)"
)
if isinstance(contents, dict):
return (
"{"
+ ", ".join(
[
summary_repr(key) + ": " + summary_repr(value)
for (key, value) in contents.items()
summary_repr(key, collapseSequences)
+ ": "
+ summary_repr(value, collapseSequences)
for key, value in contents.items()
],
)
+ "}"
)
elif isinstance(contents, set):
if len(contents) == 0:
return repr(set())
else:
return "{" + ", ".join([summary_repr(elem) for elem in contents]) + "}"
elif isinstance(contents, (int, float, np.float32, np.float64, bool, str)):
return repr(contents)
elif isinstance(contents, np.ndarray):
return repr(type(contents)) + ".shape=" + summary_repr(contents.shape)
else:
return repr(type(contents))
if isinstance(contents, set):
if collapseSequences and len(contents) > 1:
return (
"{"
+ summary_repr(next(iter(contents)), collapseSequences)
+ f", 'and {len(contents) - 1} more'"
+ "}"
)
return (
"{"
+ ", ".join([summary_repr(elem, collapseSequences) for elem in contents])
+ "}"
)
if isinstance(contents, np.ndarray):
return (
repr(type(contents))
+ "(shape="
+ repr(contents.shape)
+ ", dtype=np."
+ repr(contents.dtype)
+ ")"
)
return repr(type(contents))


#
Expand Down Expand Up @@ -108,7 +151,7 @@ def registerSampleData():
Add data sets to Sample Data module.
"""
# It is always recommended to provide sample data for users to make it easy to try
# the module, but if no sample data is available then this method (and associated
# the module, but if no sample data are available then this method (and associated
# startupCompeted signal connection) can be removed.

pass
Expand Down Expand Up @@ -636,7 +679,7 @@ def loadFromP3File(self, filename, properties):
return self.loadCenterlineFromP3FileContents(contents)

print(f"File type for {filename} is not currently supported")
print(f"{filename} contains {summary_repr(contents)}")
print(f"{filename} contains {summary_repr(contents,True)}")

return None

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import vtk

import slicer
import vtk


def isosurfaces_from_volume(
Expand Down
Loading

0 comments on commit 53282e7

Please sign in to comment.