Commit 5c7ce3ea authored by Matt Clarkson's avatar Matt Clarkson

Issue #92: Tidy up vtk_surface_model_directory_loader and test.

parent eb5087f2
Pipeline #4012 passed with stages
in 6 minutes and 9 seconds
......@@ -17,15 +17,13 @@ LOGGER = logging.getLogger(__name__)
class VTKSurfaceModelDirectoryLoader:
"""
Class to load all VTK surface models in a directory.
Given a directory name, will also load colours from
a file called colours.txt.
"""
def __init__(self, directory_name, defaults_file=None):
"""
Loads surface models from a given directory.
Constructor loads surface models from a given directory.
If a defaults_file is given, will match filename to a key in
the defaults file, and set defaults, e.g.
the defaults file, and set defaults, e.g. tumor.vtk matched to:
"tumor": {
"colour": [255, 0, 0],
......@@ -36,6 +34,14 @@ class VTKSurfaceModelDirectoryLoader:
"texture": "path/to/texture/image.png"
}
Alternatively, if a defaults_file is not present, a file called
colours.txt can be used to specify colours for each file.
If that's not present, then colours are just picked in order from
an in-built list.
defaults_file takes precedence over colours.txt if both present.
:param directory_name: string, directory name.
:param defaults_file: filename of json file with default settings
:raises: ValueError if directory_name is unreadable.
......@@ -65,7 +71,6 @@ class VTKSurfaceModelDirectoryLoader:
if directory_name:
self.get_model_colours(directory_name)
self.files = []
self.models = []
self.get_models(directory_name)
......@@ -80,18 +85,18 @@ class VTKSurfaceModelDirectoryLoader:
LOGGER.info("Loading models from %s", directory_name)
# Reset
self.files = []
files = []
self.models = []
# This may well throw FileNotFoundError which is fine.
# If its not valid I want the Exception raised.
self.files = os.listdir(directory_name)
self.files.sort()
files = os.listdir(directory_name)
files.sort()
# Loop through each file, trying to load it.
counter = 0
for filename in self.files:
for filename in files:
full_path = os.path.join(directory_name, filename)
......
{
"liver": {
"colour": [255, 170, 127],
"opacity": 0.6,
"arteries": {
"colour": [255, 0, 0],
"opacity": 0.8,
"visibility": true,
"pickable": true,
"toggleable": true
},
"portal_vein": {
"colour": [255, 85, 255],
"biliary_tract": {
"colour": [0, 255, 0],
"opacity": 0.8,
"visibility": true,
"pickable": true,
"pickable": false,
"toggleable": true
},
"hepatic_veins": {
"colour": [0, 0, 255],
"drain": {
"colour": [255, 255, 0],
"opacity": 0.8,
"visibility": true,
"pickable": true,
"pickable": false,
"toggleable": true
},
"arteries": {
"colour": [255, 0, 0],
"gallbladder": {
"colour": [85, 170, 0],
"opacity": 0.5,
"visibility": true,
"pickable": false,
"toggleable": true
},
"hepatic_veins": {
"colour": [0, 0, 255],
"opacity": 0.8,
"visibility": true,
"pickable": true,
"toggleable": true
},
"gallbladder": {
"colour": [85, 170, 0],
"opacity": 0.5,
"liver": {
"colour": [255, 170, 127],
"opacity": 0.6,
"visibility": true,
"pickable": true,
"toggleable": true
......@@ -38,18 +45,25 @@
"colour": [255, 255, 255],
"opacity": 0.8,
"visibility": true,
"pickable": true,
"pickable": false,
"toggleable": true
},
"biliary_tract": {
"colour": [0, 255, 0],
"liver_tumor": {
"colour": [255, 255, 0],
"opacity": 0.8,
"visibility": true,
"pickable": true,
"pickable": false,
"toggleable": true
},
"drain": {
"colour": [255, 255, 0],
"mass": {
"colour": [255, 255, 255],
"opacity": 0.8,
"visibility": true,
"pickable": false,
"toggleable": true
},
"portal_vein": {
"colour": [255, 85, 255],
"opacity": 0.8,
"visibility": true,
"pickable": true,
......
......@@ -86,8 +86,11 @@ def test_consistent_model_order_issue_89():
def test_valid_dir_with_defaults_from_json():
dir_name = 'tests/data/models/Liver'
loader = VTKSurfaceModelDirectoryLoader(dir_name,
"tests/data/models/Liver/patient.json")
assert len(loader.models) == 9
loader_no_json = VTKSurfaceModelDirectoryLoader(dir_name)
loader_with_json = VTKSurfaceModelDirectoryLoader(dir_name,
"tests/data/models/Liver/patient_defaults.json")
assert len(loader_no_json.models) == 9
assert len(loader_with_json.models) == 9
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment