Browse Source

Add support for gradient background in ctkVTKRenderView

Don't support gradient background in ctkVTKSliceView as it would require
some architecture redesign (vtkLightboxRenderingManager)
Julien Finet 13 years ago
parent
commit
c1256efb4a

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

@@ -55,6 +55,8 @@ int ctkVTKRenderViewTest1(int argc, char * argv [] )
   // Instanciate widget
   ctkVTKRenderView renderView;
   renderView.setBackgroundColor(QColor(Qt::red));
+  renderView.setBackgroundColor2(QColor(Qt::yellow));
+  renderView.setGradientBackground(true);
   renderView.setCornerAnnotationText("CTK Rocks !");
   renderView.show();
 

+ 68 - 0
Libs/Visualization/VTK/Widgets/ctkVTKAbstractView.cpp

@@ -261,3 +261,71 @@ int ctkVTKAbstractView::heightForWidth(int width)const
   // typically VTK render window tend to be square...
   return width;
 }
+
+//----------------------------------------------------------------------------
+void ctkVTKAbstractView::setBackgroundColor(const QColor& newBackgroundColor)
+{
+  Q_D(ctkVTKAbstractView);
+  double color[3];
+  color[0] = newBackgroundColor.redF();
+  color[1] = newBackgroundColor.greenF();
+  color[2] = newBackgroundColor.blueF();
+  foreach(vtkRenderer* renderer, d->renderers())
+    {
+    renderer->SetBackground(color);
+    }
+}
+
+//----------------------------------------------------------------------------
+QColor ctkVTKAbstractView::backgroundColor()const
+{
+  Q_D(const ctkVTKAbstractView);
+  vtkRenderer* firstRenderer = d->firstRenderer();
+  return firstRenderer ? QColor::fromRgbF(firstRenderer->GetBackground()[0],
+                                          firstRenderer->GetBackground()[1],
+                                          firstRenderer->GetBackground()[2])
+                       : QColor();
+}
+
+//----------------------------------------------------------------------------
+void ctkVTKAbstractView::setBackgroundColor2(const QColor& newBackgroundColor)
+{
+  Q_D(ctkVTKAbstractView);
+  double color[3];
+  color[0] = newBackgroundColor.redF();
+  color[1] = newBackgroundColor.greenF();
+  color[2] = newBackgroundColor.blueF();
+  foreach(vtkRenderer* renderer, d->renderers())
+    {
+    renderer->SetBackground2(color);
+    }
+}
+
+//----------------------------------------------------------------------------
+QColor ctkVTKAbstractView::backgroundColor2()const
+{
+  Q_D(const ctkVTKAbstractView);
+  vtkRenderer* firstRenderer = d->firstRenderer();
+  return firstRenderer ? QColor::fromRgbF(firstRenderer->GetBackground2()[0],
+                                          firstRenderer->GetBackground2()[1],
+                                          firstRenderer->GetBackground2()[2])
+                       : QColor();
+}
+
+//----------------------------------------------------------------------------
+void ctkVTKAbstractView::setGradientBackground(bool enable)
+{
+  Q_D(ctkVTKAbstractView);
+  foreach(vtkRenderer* renderer, d->renderers())
+    {
+    renderer->SetGradientBackground(enable);
+    }
+}
+
+//----------------------------------------------------------------------------
+bool ctkVTKAbstractView::gradientBackground()const
+{
+  Q_D(const ctkVTKAbstractView);
+  vtkRenderer* firstRenderer = d->firstRenderer();
+  return firstRenderer ? firstRenderer->GetGradientBackground() : false;
+}

+ 19 - 3
Libs/Visualization/VTK/Widgets/ctkVTKAbstractView.h

@@ -41,6 +41,8 @@ class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKAbstractView : public QWidget
   Q_OBJECT
   Q_PROPERTY(QString cornerAnnotationText READ cornerAnnotationText WRITE setCornerAnnotationText)
   Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
+  Q_PROPERTY(QColor backgroundColor2 READ backgroundColor2 WRITE setBackgroundColor)
+  Q_PROPERTY(bool gradientBackground READ gradientBackground WRITE setGradientBackground)
   Q_PROPERTY(bool renderEnabled READ renderEnabled WRITE setRenderEnabled)
 public:
 
@@ -56,8 +58,16 @@ public slots:
   /// Force a render even if a render is already ocurring
   void forceRender();
 
-  /// Set background color
-  virtual void setBackgroundColor(const QColor& newBackgroundColor) = 0;
+  /// Set the background color of the rendering screen.
+  virtual void setBackgroundColor(const QColor& newBackgroundColor);
+
+  /// Set the second background color of the rendering screen for gradient
+  /// backgrounds.
+  virtual void setBackgroundColor2(const QColor& newBackgroundColor);
+
+  /// Set/Get whether this view should have a gradient background using the
+  /// Background (top) and Background2 (bottom) colors. Default is off.
+  virtual void setGradientBackground(bool enable);
 
   /// Enable/Disable rendering
   void setRenderEnabled(bool value);
@@ -84,7 +94,13 @@ public:
   Q_INVOKABLE QVTKWidget * VTKWidget() const;
 
   /// Get background color
-  virtual QColor backgroundColor() const = 0;
+  virtual QColor backgroundColor() const;
+
+  /// Get the second background color
+  virtual QColor backgroundColor2() const;
+
+  /// Is the background a gradient
+  virtual bool gradientBackground() const;
 
   /// Return if rendering is enabled
   bool renderEnabled() const;

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

@@ -222,27 +222,6 @@ void ctkVTKRenderView::setInteractor(vtkRenderWindowInteractor* newInteractor)
   d->Orientation->SetInteractor(newInteractor);
 }
 
-// --------------------------------------------------------------------------
-void ctkVTKRenderView::setBackgroundColor(const QColor& newBackgroundColor)
-{
-  Q_D(ctkVTKRenderView);
-
-  logger.trace(QString("setBackgroundColor: %1").arg(newBackgroundColor.name()));
-
-  d->Renderer->SetBackground(newBackgroundColor.redF(),
-                             newBackgroundColor.greenF(),
-                             newBackgroundColor.blueF());
-}
-
-//----------------------------------------------------------------------------
-QColor ctkVTKRenderView::backgroundColor() const
-{
-  Q_D(const ctkVTKRenderView);
-  double color[3] = {0, 0, 0};
-  d->Renderer->GetBackground(color);
-  return QColor::fromRgbF(color[0], color[1], color[2]);
-}
-
 //----------------------------------------------------------------------------
 void ctkVTKRenderView::setOrientationWidgetVisible(bool visible)
 {

+ 0 - 6
Libs/Visualization/VTK/Widgets/ctkVTKRenderView.h

@@ -124,12 +124,6 @@ public slots:
 
 public:
 
-  /// Set background color
-  virtual void setBackgroundColor(const QColor& newBackgroundColor);
-
-  /// Get background color
-  virtual QColor backgroundColor() const;
-
   /// Get Orientation widget visibility
   bool orientationWidgetVisible();
 

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

@@ -30,6 +30,8 @@ class vtkCamera;
 class vtkImageData;
 class vtkRenderer;
 
+/// Specific implementation for a 2D view that supports lightbox display.
+/// \note There is no support for gradient background yet.
 class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKSliceView : public ctkVTKAbstractView
 {
   Q_OBJECT