浏览代码

Merge topic 'ctkVTKSliceView'

  ENH: ctkVTKSliceView - Add highlightedBoxColor / setHighlightedBoxColor
  ENH: vtkLightBoxRendererManager - Add {Set, Get}HighlightedBoxColor
Jean-Christophe Fillion-Robin 15 年之前
父节点
当前提交
6fd07d1f48

+ 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.

+ 2 - 0
Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKSliceViewTest1.cpp

@@ -92,6 +92,7 @@ int ctkVTKSliceViewTest1(int argc, char * argv [] )
 
   // .. and its associated layout
   QVBoxLayout * topLevelLayout = new QVBoxLayout(&widget);
+  topLevelLayout->setContentsMargins(0, 0, 0, 0);
 
   // Horizontal layout to contain the spinboxes
   QHBoxLayout * spinBoxLayout = new QHBoxLayout;
@@ -118,6 +119,7 @@ int ctkVTKSliceViewTest1(int argc, char * argv [] )
   sliceView->setRenderEnabled(true);
   sliceView->setMinimumSize(600, 600);
   sliceView->setImageData(image);
+  sliceView->setHighlightedBoxColor(QColor(Qt::yellow));
   sliceView->lightBoxRendererManager()->SetRenderWindowLayout(defaultRowCount, defaultColumnCount);
   sliceView->lightBoxRendererManager()->SetHighlighted(0, 0, true);
   sliceView->setCornerAnnotationText("CTK");

+ 21 - 0
Libs/Visualization/VTK/Widgets/ctkVTKSliceView.cpp

@@ -216,6 +216,27 @@ void ctkVTKSliceView::setBackgroundColor(const QColor& newBackgroundColor)
 }
 
 //----------------------------------------------------------------------------
+QColor ctkVTKSliceView::highlightedBoxColor()const
+{
+  CTK_D(const ctkVTKSliceView);
+  double* color = d->LightBoxRendererManager->GetHighlightedBoxColor();
+  QColor c;
+  c.setRgbF(color[0], color[1], color[2]);
+  return c;
+}
+
+//----------------------------------------------------------------------------
+void ctkVTKSliceView::setHighlightedBoxColor(const QColor& newHighlightedBoxColor)
+{
+  CTK_D(ctkVTKSliceView);
+  double color[3];
+  color[0] = newHighlightedBoxColor.redF();
+  color[1] = newHighlightedBoxColor.greenF();
+  color[2] = newHighlightedBoxColor.blueF();
+  d->LightBoxRendererManager->SetHighlightedBoxColor(color);
+}
+
+//----------------------------------------------------------------------------
 ctkVTKSliceView::RenderWindowLayoutType ctkVTKSliceView::renderWindowLayoutType()const
 {
   CTK_D(const ctkVTKSliceView);

+ 8 - 0
Libs/Visualization/VTK/Widgets/ctkVTKSliceView.h

@@ -46,6 +46,7 @@ class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKSliceView : public QWidget
              READ renderWindowLayoutType WRITE setRenderWindowLayoutType)
   Q_PROPERTY(QString cornerAnnotationText READ cornerAnnotationText WRITE setCornerAnnotationText)
   Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
+  Q_PROPERTY(QColor highlightedBoxColor READ highlightedBoxColor WRITE setHighlightedBoxColor)
   Q_PROPERTY(bool renderEnabled READ renderEnabled WRITE setRenderEnabled)
   Q_PROPERTY(double ColorLevel READ colorLevel WRITE setColorLevel)
   Q_PROPERTY(double ColorWindow READ colorWindow WRITE setColorWindow)
@@ -85,6 +86,10 @@ public:
   /// \sa setBackgroundColor();
   QColor backgroundColor()const;
 
+  /// Get highlightedBox color
+  /// \sa setHighlightedBoxColor();
+  QColor highlightedBoxColor()const;
+
   /// Get renderWindow layout type
   /// \sa setRenderWindowLayoutType();
   RenderWindowLayoutType renderWindowLayoutType()const;
@@ -115,6 +120,9 @@ public slots:
   /// Set background color
   void setBackgroundColor(const QColor& newBackgroundColor);
 
+  /// Set highlightedBox color
+  void setHighlightedBoxColor(const QColor& newHighlightedBoxColor);
+
   /// Enable/Disable rendering
   void setRenderEnabled(bool value);