From 451bf6e6b01c3e841b09a897a70900fb17fc70b9 Mon Sep 17 00:00:00 2001
From: Pat Marion <james.patrick.marion@gmail.com>
Date: Mon, 10 Dec 2018 10:40:02 -0800
Subject: [PATCH] add code to render mesh bounding boxes in color image

---
 modules/labelfusion/rendertrainingimages.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/modules/labelfusion/rendertrainingimages.py b/modules/labelfusion/rendertrainingimages.py
index c442c66..ad36f7b 100644
--- a/modules/labelfusion/rendertrainingimages.py
+++ b/modules/labelfusion/rendertrainingimages.py
@@ -30,6 +30,7 @@ def __init__(self, view, viewOptions, pathDict):
         self.colors = cm.nipy_spectral(np.linspace(0, 1, len(self.objectData.keys())))
         self.colors = np.append(self.colors, [[0.5, 0.5, 0.5, 1.0]], axis=0)
         self.objectToWorld = dict()
+        self.renderBoundingBox = True
         self.initialize()
 
     def initialize(self):
@@ -67,6 +68,8 @@ def disableLighting(self):
             obj.actor.GetProperty().LightingOff()
             self.storedColors[obj.getProperty('Name')] = list(obj.getProperty('Color'))
             obj.setProperty('Color', [objLabel / 255.0] * 3)
+            bbox = obj.findChild(objName + ' bbox')
+            bbox.setProperty('Visible', False)
         view.forceRender()
 
     def enableLighting(self):
@@ -83,6 +86,8 @@ def enableLighting(self):
         for obj in om.findObjectByName('data files').children():
             obj.actor.GetProperty().LightingOn()
             obj.setProperty('Color', self.storedColors[obj.getProperty('Name')])
+            bbox = obj.findChild(objName + ' bbox')
+            bbox.setProperty('Visible', self.renderBoundingBox)
         view.forceRender()
 
 
@@ -180,6 +185,16 @@ def loadObjectMeshes(self):
             self.objectToWorld[objName] = objToWorld
             obj.actor.SetUserTransform(objToWorld)
 
+            outlineFilter = vtk.vtkOutlineFilter()
+            outlineFilter.SetInput(polyData)
+            outlineFilter.Update()
+            bbox = vis.showPolyData(outlineFilter.GetOutput(), objName + ' bbox', parent=obj)
+            bbox.actor.GetProperty().SetLineWidth(1)
+            bbox.actor.SetUserTransform(objToWorld)
+            bbox.setProperty('Color', [1, 1, 1])
+            bbox.setProperty('Alpha', 0.8)
+            bbox.setProperty('Visible', False)
+
     def setupImage(self, imageNumber, saveColorLabeledImages=False, saveLabeledImages=False, savePoses=False):
 
         """