Browse Source

ENH: vtkLightBoxRendererManager - Add {Set, Get}HighlightedBoxColor

Allows to change dynamically the color associated with all the highlightedBoxes
Jean-Christophe Fillion-Robin 15 years ago
parent
commit
9abdfe6df9

+ 4 - 2
Libs/Visualization/VTK/Core/Testing/Cpp/vtkLightBoxRendererManagerTest1.cpp

@@ -183,8 +183,10 @@ int vtkLightBoxRendererManagerTest1(int argc, char* argv[])
   lightBoxRendererManager->SetRenderWindowLayout(4, 5);
   lightBoxRendererManager->SetHighlighted(2,2,true);
   lightBoxRendererManager->SetColorWindowAndLevel(100, 100);
-  double color[3] = {0.5, 0.5, 0.5};
-  lightBoxRendererManager->SetBackgroundColor(color);
+  double backgroundColor[3] = {0.5, 0.5, 0.5};
+  lightBoxRendererManager->SetBackgroundColor(backgroundColor);
+  double highlightedBoxColor[3] = {1.0, 1.0, 0.0};
+  lightBoxRendererManager->SetHighlightedBoxColor(highlightedBoxColor);
 
   int retval = vtkRegressionTestImage(rw);
   if (retval == vtkRegressionTester::DO_INTERACTOR)

+ 64 - 13
Libs/Visualization/VTK/Core/vtkLightBoxRendererManager.cpp

@@ -48,11 +48,14 @@ public:
   void SetupImageMapperActor(double colorWindow, double colorLevel);
 
   /// Create a box around the renderer.
-  void SetupHighlightBoxActor(bool visible = false);
+  void SetupHighlightedBoxActor(bool visible = false);
+
+  /// Set HighlightedBox color
+  void SetHighlightedBoxColor(double* newHighlightedBoxColor);
 
   vtkSmartPointer<vtkRenderer>                Renderer;
   vtkSmartPointer<vtkImageMapper>             ImageMapper;
-  vtkSmartPointer<vtkActor2D>                 HighlightBoxActor;
+  vtkSmartPointer<vtkActor2D>                 HighlightedBoxActor;
 };
 }
 
@@ -70,7 +73,7 @@ RenderWindowItem::RenderWindowItem(const double rendererBackgroundColor[3],
                                 rendererBackgroundColor[2]);
 
   this->SetupImageMapperActor(colorWindow, colorLevel);
-  this->SetupHighlightBoxActor();
+  this->SetupHighlightedBoxActor();
 }
 
 //-----------------------------------------------------------------------------
@@ -102,10 +105,10 @@ void RenderWindowItem::SetupImageMapperActor(double colorWindow, double colorLev
 }
 
 //---------------------------------------------------------------------------
-void RenderWindowItem::SetupHighlightBoxActor(bool visible)
+void RenderWindowItem::SetupHighlightedBoxActor(bool visible)
 {
   assert(this->Renderer);
-  assert(!this->HighlightBoxActor);
+  assert(!this->HighlightedBoxActor);
   
   // Create a highlight actor (2D box around viewport)
   VTK_CREATE(vtkPolyData, poly);
@@ -134,14 +137,20 @@ void RenderWindowItem::SetupHighlightBoxActor(bool visible)
   polyDataMapper->SetInput(poly);
   polyDataMapper->SetTransformCoordinate(coordinate);
 
-  this->HighlightBoxActor = vtkSmartPointer<vtkActor2D>::New();
-  this->HighlightBoxActor->SetMapper(polyDataMapper);
-  this->HighlightBoxActor->GetProperty()->SetColor(1, 1, 0);
-  this->HighlightBoxActor->GetProperty()->SetDisplayLocationToForeground();
-  this->HighlightBoxActor->GetProperty()->SetLineWidth(3); // wide enough so not clipped
-  this->HighlightBoxActor->SetVisibility(visible);
+  this->HighlightedBoxActor = vtkSmartPointer<vtkActor2D>::New();
+  this->HighlightedBoxActor->SetMapper(polyDataMapper);
+  this->HighlightedBoxActor->GetProperty()->SetColor(0, 1, 0); // Default to green
+  this->HighlightedBoxActor->GetProperty()->SetDisplayLocationToForeground();
+  this->HighlightedBoxActor->GetProperty()->SetLineWidth(3); // wide enough so not clipped
+  this->HighlightedBoxActor->SetVisibility(visible);
+
+  this->Renderer->AddActor2D(this->HighlightedBoxActor);
+}
 
-  this->Renderer->AddActor2D(this->HighlightBoxActor);
+//-----------------------------------------------------------------------------
+void RenderWindowItem::SetHighlightedBoxColor(double* newHighlightedBoxColor)
+{
+  this->HighlightedBoxActor->GetProperty()->SetColor(newHighlightedBoxColor);
 }
 
 //-----------------------------------------------------------------------------
@@ -164,6 +173,7 @@ public:
   int                                           RenderWindowRowCount;
   int                                           RenderWindowColumnCount;
   int                                           RenderWindowLayoutType;
+  double                                        HighlightedBoxColor[3];
   vtkWeakPointer<vtkRenderWindowInteractor>     CurrentInteractor;
   vtkSmartPointer<vtkCornerAnnotation>          CornerAnnotation;
 
@@ -199,6 +209,10 @@ vtkLightBoxRendererManager::vtkInternal::vtkInternal(vtkLightBoxRendererManager*
   this->RendererBackgroundColor[0] = 0.0;
   this->RendererBackgroundColor[1] = 0.0;
   this->RendererBackgroundColor[2] = 0.0;
+  // Default highlightedBox color: green
+  this->HighlightedBoxColor[0] = 1.0;
+  this->HighlightedBoxColor[1] = 1.0;
+  this->HighlightedBoxColor[2] = 0.0;
 }
 
 // --------------------------------------------------------------------------
@@ -587,7 +601,7 @@ void vtkLightBoxRendererManager::SetHighlightedById(int id, bool highlighted)
     {
     return;
     }
-  this->Internal->RenderWindowItemList.at(id)->HighlightBoxActor->SetVisibility(highlighted);
+  this->Internal->RenderWindowItemList.at(id)->HighlightedBoxActor->SetVisibility(highlighted);
 
   this->Modified();
 }
@@ -599,6 +613,43 @@ void vtkLightBoxRendererManager::SetHighlighted(int rowId, int columnId, bool hi
 }
 
 //----------------------------------------------------------------------------
+void vtkLightBoxRendererManager::SetHighlightedBoxColor(double newHighlightedBoxColor[3])
+{
+  if (!this->IsInitialized())
+    {
+    vtkErrorMacro(<< "SetHighlightedById failed - vtkLightBoxRendererManager is NOT initialized");
+    return;
+    }
+
+  if (this->Internal->HighlightedBoxColor[0] == newHighlightedBoxColor[0] &&
+      this->Internal->HighlightedBoxColor[1] == newHighlightedBoxColor[2] &&
+      this->Internal->HighlightedBoxColor[2] == newHighlightedBoxColor[3])
+    {
+    return;
+    }
+
+  this->Internal->HighlightedBoxColor[0] = newHighlightedBoxColor[0];
+  this->Internal->HighlightedBoxColor[1] = newHighlightedBoxColor[1];
+  this->Internal->HighlightedBoxColor[2] = newHighlightedBoxColor[2];
+
+  vtkInternal::RenderWindowItemListIt it;
+  for(it = this->Internal->RenderWindowItemList.begin();
+      it != this->Internal->RenderWindowItemList.end();
+      ++it)
+    {
+    (*it)->SetHighlightedBoxColor(newHighlightedBoxColor);
+    }
+
+  this->Modified();
+}
+
+//----------------------------------------------------------------------------
+double* vtkLightBoxRendererManager::GetHighlightedBoxColor() const
+{
+  return this->Internal->HighlightedBoxColor;
+}
+
+//----------------------------------------------------------------------------
 int vtkLightBoxRendererManager::ComputeRenderWindowItemId(int rowId, int columnId)
 {
   return this->Internal->RenderWindowColumnCount * rowId + columnId;

+ 9 - 0
Libs/Visualization/VTK/Core/vtkLightBoxRendererManager.h

@@ -83,6 +83,15 @@ class CTK_VISUALIZATION_VTK_CORE_EXPORT vtkLightBoxRendererManager : public vtkO
   ///  Highlight / Unhighlight a render view item given its position in the grid
   /// \sa setHighlighted(int, bool)
   void SetHighlighted(int rowId, int columnId, bool highlighted);
+
+  /// \sa SetHighlighted SetHighlightedBoxColorById
+  void SetHighlightedBoxColor(double highlightedBoxColor[3]);
+
+  /// \brief Set the color of the box displayed around the highlighted item
+  /// identified by \a id
+  /// The highlightedBox is set with a width of 3 screen units.
+  /// \sa SetHighlightedById SetHighlighted vtkProperty2D::SetLineWidth
+  double* GetHighlightedBoxColor()const;
   
   /// Convenient function allowing to compute the renderWindowItemId
   /// given \a rowId and \a columnId.