Repository: SciKit-Surgery/scikit-surgeryvtk (language: python)

Issue:
Add outline option to vtk_surface_model_directory_loader.py
Now we have outline rendering setup #177, set up the file loaders so we can set it in json config files.


Discussion / hints:

Fix patch:
diff --git a/sksurgeryvtk/models/surface_model_loader.py b/sksurgeryvtk/models/surface_model_loader.py
index 71e09cfe..d862b6bc 100644
--- a/sksurgeryvtk/models/surface_model_loader.py
+++ b/sksurgeryvtk/models/surface_model_loader.py
@@ -33,7 +33,8 @@ class SurfaceModelLoader:
                 "visibility": true,
                 "pickable": true,
                 "toggleable": true,
-                "texture": "path/to/texture/image.png"
+                "texture": "path/to/texture/image.png",
+                "outline": false
             }
 
     Assemblies have format:
@@ -121,6 +122,10 @@ def __load_surface(self, config):
         else:
             raise KeyError("No 'pickable' section defined in config")
 
+        outline = False
+        if 'outline' in config.keys():
+            outline = config['outline']
+
         colour_as_float = [colour[0] / 255.0,
                            colour[1] / 255.0,
                            colour[2] / 255.0
@@ -134,7 +139,8 @@ def __load_surface(self, config):
                                    colour_as_float,
                                    visibility,
                                    opacity,
-                                   pickable)
+                                   pickable,
+                                   outline)
 
         if 'texture' in config.keys():
             texture_file = config['texture']
diff --git a/sksurgeryvtk/models/vtk_surface_model_directory_loader.py b/sksurgeryvtk/models/vtk_surface_model_directory_loader.py
index ffae0861..2fe13e5c 100644
--- a/sksurgeryvtk/models/vtk_surface_model_directory_loader.py
+++ b/sksurgeryvtk/models/vtk_surface_model_directory_loader.py
@@ -31,7 +31,8 @@ def __init__(self, directory_name, defaults_file=None):
                 "visibility": true,
                 "pickable": true,
                 "toggleable": true,
-                "texture": "path/to/texture/image.png"
+                "texture": "path/to/texture/image.png",
+                "outline": false
             }
 
         Alternatively, if a defaults_file is not present, a file called
@@ -127,6 +128,10 @@ def get_models(self, directory_name):
                             pickable = model_defaults['pickable']
                             model.set_pickable(pickable)
 
+                        if 'outline' in model_defaults.keys():
+                            outline = model_defaults['outline']
+                            model.set_outline(outline)
+
                         if 'texture' in model_defaults.keys():
                             texture_file = model_defaults['texture']
                             texture_file_path = os.path.join(directory_name,
diff --git a/sksurgeryvtk/widgets/vtk_overlay_window.py b/sksurgeryvtk/widgets/vtk_overlay_window.py
index 3793e033..7480fce0 100644
--- a/sksurgeryvtk/widgets/vtk_overlay_window.py
+++ b/sksurgeryvtk/widgets/vtk_overlay_window.py
@@ -357,6 +357,9 @@ def add_vtk_models(self, models, layer=1):
 
         for model in models:
             renderer.AddActor(model.actor)
+            if model.get_outline():
+                renderer.AddActor(
+                        model.get_outline_actor(renderer.GetActiveCamera()))
 
         if self.reset_camera:
             renderer.ResetCamera()


Test patch:
diff --git a/tests/data/config/surface_model_duplicates_in_assembly.json b/tests/data/config/surface_model_duplicates_in_assembly.json
index 82758dc9..b88f305a 100644
--- a/tests/data/config/surface_model_duplicates_in_assembly.json
+++ b/tests/data/config/surface_model_duplicates_in_assembly.json
@@ -5,14 +5,16 @@
       "colour": [255, 0, 0],
       "opacity": 0.5,
       "visibility": true,
-      "pickable": true
+      "pickable": true,
+      "outline": false
     },
     "portal veins": {
       "file": "tests/data/models/Liver/portal_vein.vtk",
       "colour": [0, 255, 0],
       "opacity": 0.7,
       "visibility": true,
-      "pickable": true
+      "pickable": true,
+      "outline": false
     }
   },
 
@@ -21,4 +23,4 @@
     "duplicate": ["portal veins"]
   }
 
-}
\ No newline at end of file
+}
diff --git a/tests/data/config/surface_model_no_shading.json b/tests/data/config/surface_model_no_shading.json
index b5dc1fde..6eebbbcf 100644
--- a/tests/data/config/surface_model_no_shading.json
+++ b/tests/data/config/surface_model_no_shading.json
@@ -6,7 +6,8 @@
       "opacity": 1.0,
       "visibility": true,
       "pickable": true,
-      "no shading": true
+      "no shading": true,
+      "outline": false
     }
   }
-}
\ No newline at end of file
+}
diff --git a/tests/data/config/surface_model_two.json b/tests/data/config/surface_model_two.json
index dfb0157b..50b50c68 100644
--- a/tests/data/config/surface_model_two.json
+++ b/tests/data/config/surface_model_two.json
@@ -5,14 +5,16 @@
       "colour": [255, 0, 0],
       "opacity": 0.5,
       "visibility": true,
-      "pickable": true
+      "pickable": true,
+      "outline": false
     },
     "portal veins": {
       "file": "tests/data/models/Liver/portal_vein.vtk",
       "colour": [0, 255, 0],
       "opacity": 0.7,
       "visibility": true,
-      "pickable": true
+      "pickable": true,
+      "outline": true
     }
   }
-}
\ No newline at end of file
+}
diff --git a/tests/data/config/surface_model_two_assemblies.json b/tests/data/config/surface_model_two_assemblies.json
index 88876965..83f99678 100644
--- a/tests/data/config/surface_model_two_assemblies.json
+++ b/tests/data/config/surface_model_two_assemblies.json
@@ -6,7 +6,8 @@
       "colour": [255, 0, 0],
       "opacity": 0.5,
       "visibility": true,
-      "pickable": true
+      "pickable": true,
+      "outline": false
     },
 
     "portal veins": {
@@ -14,7 +15,8 @@
       "colour": [0, 255, 0],
       "opacity": 0.7,
       "visibility": true,
-      "pickable": true
+      "pickable": true,
+      "outline": false
     },
 
     "liver": {
@@ -24,7 +26,8 @@
       "opacity": 0.9,
       "visibility": true,
       "pickable": true,
-      "texture": "tests/data/calibration/left-1095.png"
+      "texture": "tests/data/calibration/left-1095.png",
+      "outline": false
     }
   },
 
@@ -32,4 +35,4 @@
     "veins": ["hepatic veins", "portal veins"],
     "liver": ["liver"]
   }
-}
\ No newline at end of file
+}
diff --git a/tests/data/config/surface_model_two_in_assembly.json b/tests/data/config/surface_model_two_in_assembly.json
index d6e606e1..5764a139 100644
--- a/tests/data/config/surface_model_two_in_assembly.json
+++ b/tests/data/config/surface_model_two_in_assembly.json
@@ -5,14 +5,16 @@
       "colour": [255, 0, 0],
       "opacity": 0.5,
       "visibility": true,
-      "pickable": true
+      "pickable": true,
+      "outline": true
     },
     "portal veins": {
       "file": "tests/data/models/Liver/portal_vein.vtk",
       "colour": [0, 255, 0],
       "opacity": 0.7,
       "visibility": true,
-      "pickable": true
+      "pickable": true,
+      "outline": false
     }
   },
 
@@ -20,4 +22,4 @@
     "veins": ["hepatic veins", "portal veins"]
   }
 
-}
\ No newline at end of file
+}
diff --git a/tests/data/config/surface_model_two_no_prefix.json b/tests/data/config/surface_model_two_no_prefix.json
index 54f3e2ca..f879c365 100644
--- a/tests/data/config/surface_model_two_no_prefix.json
+++ b/tests/data/config/surface_model_two_no_prefix.json
@@ -5,14 +5,16 @@
       "colour": [255, 0, 0],
       "opacity": 0.5,
       "visibility": true,
-      "pickable": true
+      "pickable": true,
+      "outline": false
     },
     "portal veins": {
       "file": "portal_vein.vtk",
       "colour": [0, 255, 0],
       "opacity": 0.7,
       "visibility": true,
-      "pickable": true
+      "pickable": true,
+      "outline": false
     }
   }
-}
\ No newline at end of file
+}
diff --git a/tests/data/models/Liver/patient_defaults.json b/tests/data/models/Liver/patient_defaults.json
index f127a995..b702d87d 100644
--- a/tests/data/models/Liver/patient_defaults.json
+++ b/tests/data/models/Liver/patient_defaults.json
@@ -39,7 +39,8 @@
         "opacity": 0.6,
         "visibility": true,
         "pickable": true,
-        "toggleable": true
+        "toggleable": true,
+	"outline": true
     },
     "liver_cyst": {
         "colour": [255, 255, 255],
diff --git a/tests/widgets/test_vtk_overlay_window_with_outlines.py b/tests/widgets/test_vtk_overlay_window_with_outlines.py
index c0d85b75..085adfe1 100644
--- a/tests/widgets/test_vtk_overlay_window_with_outlines.py
+++ b/tests/widgets/test_vtk_overlay_window_with_outlines.py
@@ -46,13 +46,6 @@ def test_surface_outline_overlay(vtk_overlay_with_gradient_image):
     surface = [sm.VTKSurfaceModel('tests/data/models/Liver/liver.vtk', (1.0, 1.0, 1.0),
         opacity = 0.1, outline=True)]
     widget.add_vtk_models(surface)
-    outline_actor = surface[0].get_outline_actor(
-            widget.foreground_renderer.GetActiveCamera())
-
-    foreground_actors = widget.foreground_renderer.GetActors()
-    assert foreground_actors.GetNumberOfItems() == 1
-
-    widget.add_vtk_actor(outline_actor)
 
     foreground_actors = widget.foreground_renderer.GetActors()
     assert foreground_actors.GetNumberOfItems() == 2