Explorar o código

Factorize ctkVTKRenderView and ctkVTKSliceView into ctkVTKAbstractView

ctkVTKRenderView and ctkVTKSliceView had a methods in common that could be
factorized.
Julien Finet %!s(int64=14) %!d(string=hai) anos
pai
achega
c15d277fba

+ 21 - 4
Libs/Visualization/VTK/Core/vtkLightBoxRendererManager.cpp

@@ -219,6 +219,10 @@ vtkLightBoxRendererManager::vtkInternal::vtkInternal(vtkLightBoxRendererManager*
   this->HighlightedBoxColor[0] = 0.0;
   this->HighlightedBoxColor[0] = 0.0;
   this->HighlightedBoxColor[1] = 1.0;
   this->HighlightedBoxColor[1] = 1.0;
   this->HighlightedBoxColor[2] = 0.0;
   this->HighlightedBoxColor[2] = 0.0;
+
+  this->CornerAnnotation->SetMaximumLineHeight(0.07);
+  vtkTextProperty *tprop = this->CornerAnnotation->GetTextProperty();
+  tprop->ShadowOn();
 }
 }
 
 
 // --------------------------------------------------------------------------
 // --------------------------------------------------------------------------
@@ -246,10 +250,6 @@ void vtkLightBoxRendererManager::vtkInternal::SetupCornerAnnotation()
       }
       }
     }
     }
 
 
-  this->CornerAnnotation->SetMaximumLineHeight(0.07);
-  vtkTextProperty *tprop = this->CornerAnnotation->GetTextProperty();
-  tprop->ShadowOn();
-
   this->CornerAnnotation->ClearAllTexts();
   this->CornerAnnotation->ClearAllTexts();
   this->CornerAnnotation->SetText(2, this->CornerAnnotationText.c_str());
   this->CornerAnnotation->SetText(2, this->CornerAnnotationText.c_str());
 }
 }
@@ -749,6 +749,23 @@ vtkCornerAnnotation * vtkLightBoxRendererManager::GetCornerAnnotation() const
 }
 }
 
 
 // --------------------------------------------------------------------------
 // --------------------------------------------------------------------------
+void vtkLightBoxRendererManager::SetCornerAnnotation(vtkCornerAnnotation* annotation)
+{
+  // Remove current corner annotation
+  vtkInternal::RenderWindowItemListIt it;
+  for(it = this->Internal->RenderWindowItemList.begin();
+      it != this->Internal->RenderWindowItemList.end();
+      ++it)
+    {
+    if (!(*it)->Renderer->HasViewProp(this->Internal->CornerAnnotation))
+      {
+      (*it)->Renderer->RemoveViewProp(this->Internal->CornerAnnotation);
+      }
+    }
+  this->Internal->CornerAnnotation = annotation;
+}
+
+// --------------------------------------------------------------------------
 void vtkLightBoxRendererManager::SetBackgroundColor(const double newBackgroundColor[3])
 void vtkLightBoxRendererManager::SetBackgroundColor(const double newBackgroundColor[3])
 {
 {
   if (!this->IsInitialized())
   if (!this->IsInitialized())

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

@@ -123,6 +123,7 @@ class CTK_VISUALIZATION_VTK_CORE_EXPORT vtkLightBoxRendererManager : public vtkO
   /// Get corner annotation actor
   /// Get corner annotation actor
   /// The same annotation is associated with all renderers managed by the light box
   /// The same annotation is associated with all renderers managed by the light box
   vtkCornerAnnotation * GetCornerAnnotation()const;
   vtkCornerAnnotation * GetCornerAnnotation()const;
+  void SetCornerAnnotation(vtkCornerAnnotation* annotation);
 
 
   /// Set background color
   /// Set background color
   void SetBackgroundColor(const double newBackgroundColor[3]);
   void SetBackgroundColor(const double newBackgroundColor[3]);

+ 5 - 0
Libs/Visualization/VTK/Widgets/CMakeLists.txt

@@ -12,6 +12,9 @@ SET(KIT_SRCS
   ctkVTKAbstractMatrixWidget.cpp
   ctkVTKAbstractMatrixWidget.cpp
   ctkVTKAbstractMatrixWidget.h
   ctkVTKAbstractMatrixWidget.h
   ctkVTKAbstractMatrixWidget_p.h
   ctkVTKAbstractMatrixWidget_p.h
+  ctkVTKAbstractView.cpp
+  ctkVTKAbstractView.h
+  ctkVTKAbstractView_p.h
   ctkVTKDataSetModel.cpp
   ctkVTKDataSetModel.cpp
   ctkVTKDataSetModel.h
   ctkVTKDataSetModel.h
   ctkVTKDataSetArrayComboBox.cpp
   ctkVTKDataSetArrayComboBox.cpp
@@ -37,6 +40,8 @@ SET(KIT_SRCS
 # Headers that should run through moc
 # Headers that should run through moc
 SET(KIT_MOC_SRCS
 SET(KIT_MOC_SRCS
   ctkVTKAbstractMatrixWidget_p.h
   ctkVTKAbstractMatrixWidget_p.h
+  ctkVTKAbstractView.h
+  ctkVTKAbstractView_p.h
   ctkVTKDataSetArrayComboBox.h
   ctkVTKDataSetArrayComboBox.h
   ctkVTKDataSetModel.h
   ctkVTKDataSetModel.h
   ctkVTKMatrixWidget.h
   ctkVTKMatrixWidget.h

+ 5 - 4
Libs/Visualization/VTK/Widgets/Testing/Cpp/CMakeLists.txt

@@ -34,8 +34,8 @@ ENDIF(CTK_USE_CHARTS)
 #
 #
 IF(EXISTS "${CTKData_DIR}")
 IF(EXISTS "${CTKData_DIR}")
   LIST(APPEND TEST_SOURCES
   LIST(APPEND TEST_SOURCES
-    ctkVTKSliceViewTest1.cpp
-    ctkVTKRenderViewTest1.cpp
+    ctkVTKSliceViewTest2.cpp
+    ctkVTKRenderViewTest2.cpp
     )
     )
 ENDIF()
 ENDIF()
 
 
@@ -89,6 +89,7 @@ SIMPLE_TEST( ctkVTKThumbnailViewTest1 )
 #
 #
 IF(EXISTS "${CTKData_DIR}")
 IF(EXISTS "${CTKData_DIR}")
   #
   #
-  SIMPLE_TEST( ctkVTKSliceViewTest1 )
-  SIMPLE_TEST( ctkVTKRenderViewTest1 )
+  SIMPLE_TEST( ctkVTKSliceViewTest2 )
+  SIMPLE_TEST( ctkVTKRenderViewTest2 )
 ENDIF()
 ENDIF()
+

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

@@ -60,6 +60,7 @@ int ctkVTKRenderViewTest1(int argc, char * argv [] )
 
 
   bool interactive = parsedArgs["-I"].toBool();
   bool interactive = parsedArgs["-I"].toBool();
   QString data_directory = parsedArgs["-D"].toString();
   QString data_directory = parsedArgs["-D"].toString();
+  Q_UNUSED(data_directory);
 
 
   // Instanciate widget
   // Instanciate widget
   ctkVTKRenderView renderView;
   ctkVTKRenderView renderView;

Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKSliceViewTest1.cpp → Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKSliceViewTest2.cpp


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

@@ -0,0 +1,205 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+// Qt includes
+#include <QTimer>
+#include <QVBoxLayout>
+#include <QDebug>
+
+// CTK includes
+#include "ctkVTKAbstractView.h"
+#include "ctkVTKAbstractView_p.h"
+#include "ctkLogger.h"
+
+// VTK includes
+#include <vtkRenderWindowInteractor.h>
+#include <vtkTextProperty.h>
+
+//--------------------------------------------------------------------------
+static ctkLogger logger("org.commontk.visualization.vtk.widgets.ctkVTKAbstractView");
+//--------------------------------------------------------------------------
+
+// --------------------------------------------------------------------------
+// ctkVTKAbstractViewPrivate methods
+
+// --------------------------------------------------------------------------
+ctkVTKAbstractViewPrivate::ctkVTKAbstractViewPrivate(ctkVTKAbstractView& object)
+  : q_ptr(&object)
+{
+  this->RenderWindow = vtkSmartPointer<vtkRenderWindow>::New();
+  this->CornerAnnotation = vtkSmartPointer<vtkCornerAnnotation>::New();
+  this->RenderPending = false;
+  this->RenderEnabled = true;
+}
+
+// --------------------------------------------------------------------------
+void ctkVTKAbstractViewPrivate::init()
+{
+  Q_Q(ctkVTKAbstractView);
+
+  this->setParent(q);
+
+  this->VTKWidget = new QVTKWidget;
+  q->setLayout(new QVBoxLayout);
+  q->layout()->setMargin(0);
+  q->layout()->setSpacing(0);
+  q->layout()->addWidget(this->VTKWidget);
+
+  this->setupCornerAnnotation();
+  this->setupRendering();
+}
+
+// --------------------------------------------------------------------------
+void ctkVTKAbstractViewPrivate::setupCornerAnnotation()
+{
+  logger.trace("setupCornerAnnotation");
+  this->CornerAnnotation->SetMaximumLineHeight(0.07);
+  vtkTextProperty *tprop = this->CornerAnnotation->GetTextProperty();
+  tprop->ShadowOn();
+  this->CornerAnnotation->ClearAllTexts();
+}
+
+//---------------------------------------------------------------------------
+void ctkVTKAbstractViewPrivate::setupRendering()
+{
+  logger.trace("setupRendering");
+  Q_ASSERT(this->RenderWindow);
+  this->RenderWindow->SetAlphaBitPlanes(1);
+  this->RenderWindow->SetMultiSamples(0);
+  this->RenderWindow->StereoCapableWindowOn();
+
+  this->VTKWidget->SetRenderWindow(this->RenderWindow);
+}
+
+//---------------------------------------------------------------------------
+// ctkVTKAbstractView methods
+
+// --------------------------------------------------------------------------
+ctkVTKAbstractView::ctkVTKAbstractView(QWidget* parentWidget)
+  : Superclass(parentWidget)
+  , d_ptr(new ctkVTKAbstractViewPrivate(*this))
+{
+  Q_D(ctkVTKAbstractView);
+  d->init();
+}
+
+// --------------------------------------------------------------------------
+ctkVTKAbstractView::ctkVTKAbstractView(ctkVTKAbstractViewPrivate* pimpl, QWidget* parentWidget)
+  : Superclass(parentWidget)
+  , d_ptr(pimpl)
+{
+  Q_D(ctkVTKAbstractView);
+  d->init();
+}
+
+//----------------------------------------------------------------------------
+ctkVTKAbstractView::~ctkVTKAbstractView()
+{
+}
+
+//----------------------------------------------------------------------------
+void ctkVTKAbstractView::scheduleRender()
+{
+  Q_D(ctkVTKAbstractView);
+
+  logger.trace(QString("scheduleRender - RenderEnabled: %1 - RenderPending: %2").
+               arg(d->RenderEnabled ? "true" : "false")
+               .arg(d->RenderPending ? "true:" : "false"));
+
+  if (!d->RenderEnabled)
+    {
+    return;
+    }
+  if (!d->RenderPending)
+    {
+    d->RenderPending = true;
+    QTimer::singleShot(0, this, SLOT(forceRender()));
+    }
+}
+
+//----------------------------------------------------------------------------
+void ctkVTKAbstractView::forceRender()
+{
+  Q_D(ctkVTKAbstractView);
+
+  d->RenderPending = false;
+  logger.trace(QString("forceRender - RenderEnabled: %1")
+               .arg(d->RenderEnabled ? "true" : "false"));
+
+  if (!d->RenderEnabled || !this->isVisible())
+    {
+    return;
+    }
+  d->RenderWindow->Render();
+}
+
+//----------------------------------------------------------------------------
+CTK_GET_CPP(ctkVTKAbstractView, vtkRenderWindow*, renderWindow, RenderWindow);
+
+//----------------------------------------------------------------------------
+void ctkVTKAbstractView::setInteractor(vtkRenderWindowInteractor* newInteractor)
+{
+  Q_D(ctkVTKAbstractView);
+
+  logger.trace("setInteractor");
+
+  d->RenderWindow->SetInteractor(newInteractor);
+}
+
+//----------------------------------------------------------------------------
+vtkRenderWindowInteractor* ctkVTKAbstractView::interactor()const
+{
+  Q_D(const ctkVTKAbstractView);
+  return d->RenderWindow->GetInteractor();
+}
+
+//----------------------------------------------------------------------------
+vtkInteractorObserver* ctkVTKAbstractView::interactorStyle()const
+{
+  return this->interactor() ?
+    this->interactor()->GetInteractorStyle() : 0;
+}
+
+//----------------------------------------------------------------------------
+void ctkVTKAbstractView::setCornerAnnotationText(const QString& text)
+{
+  Q_D(ctkVTKAbstractView);
+  logger.trace(QString("setCornerAnnotationText: %1").arg(text));
+  d->CornerAnnotation->ClearAllTexts();
+  d->CornerAnnotation->SetText(2, text.toLatin1());
+}
+
+//----------------------------------------------------------------------------
+QString ctkVTKAbstractView::cornerAnnotationText() const
+{
+  Q_D(const ctkVTKAbstractView);
+  return QLatin1String(d->CornerAnnotation->GetText(2));
+}
+
+//----------------------------------------------------------------------------
+vtkCornerAnnotation* ctkVTKAbstractView::cornerAnnotation() const
+{
+  Q_D(const ctkVTKAbstractView);
+  return d->CornerAnnotation;
+}
+
+//----------------------------------------------------------------------------
+CTK_SET_CPP(ctkVTKAbstractView, bool, setRenderEnabled, RenderEnabled);
+CTK_GET_CPP(ctkVTKAbstractView, bool, renderEnabled, RenderEnabled);

+ 95 - 0
Libs/Visualization/VTK/Widgets/ctkVTKAbstractView.h

@@ -0,0 +1,95 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#ifndef __ctkVTKAbstractView_h
+#define __ctkVTKAbstractView_h
+
+// Qt includes
+#include <QWidget>
+
+// CTK includes
+#include "ctkVisualizationVTKWidgetsExport.h"
+class ctkVTKAbstractViewPrivate;
+
+class vtkCornerAnnotation;
+class vtkInteractorObserver;
+class vtkRenderWindowInteractor;
+class vtkRenderWindow;
+
+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(bool renderEnabled READ renderEnabled WRITE setRenderEnabled)
+public:
+
+  typedef QWidget Superclass;
+  explicit ctkVTKAbstractView(QWidget* parent = 0);
+  virtual ~ctkVTKAbstractView();
+
+public slots:
+
+  /// If a render has already been scheduled, this called is a no-op
+  void scheduleRender();
+
+  /// Force a render even if a render is already ocurring
+  void forceRender();
+
+  /// Set background color
+  virtual void setBackgroundColor(const QColor& newBackgroundColor) = 0;
+
+  /// Enable/Disable rendering
+  void setRenderEnabled(bool value);
+
+  /// Set corner annotation \a text
+  virtual void setCornerAnnotationText(const QString& text);
+
+public:
+  /// Get underlying RenderWindow
+  vtkRenderWindow* renderWindow()const;
+
+  /// Set/Get window interactor
+  vtkRenderWindowInteractor* interactor()const;
+  virtual void setInteractor(vtkRenderWindowInteractor* interactor);
+
+  /// Get current interactor style
+  vtkInteractorObserver* interactorStyle()const;
+
+  /// Get corner annotation \a text
+  QString cornerAnnotationText() const;
+  vtkCornerAnnotation* cornerAnnotation()const;
+
+  /// Get background color
+  virtual QColor backgroundColor() const = 0;
+
+  /// Return if rendering is enabled
+  bool renderEnabled() const;
+
+protected:
+  QScopedPointer<ctkVTKAbstractViewPrivate> d_ptr;
+  ctkVTKAbstractView(ctkVTKAbstractViewPrivate* pimpl, QWidget* parent);
+
+private:
+  Q_DECLARE_PRIVATE(ctkVTKAbstractView);
+  Q_DISABLE_COPY(ctkVTKAbstractView);
+};
+
+#endif

+ 62 - 0
Libs/Visualization/VTK/Widgets/ctkVTKAbstractView_p.h

@@ -0,0 +1,62 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#ifndef __ctkVTKAbstractView_p_h
+#define __ctkVTKAbstractView_p_h
+
+// Qt includes
+#include <QObject>
+
+// CTK includes
+#include "ctkVTKAbstractView.h"
+
+// VTK includes
+#include <QVTKWidget.h>
+#include <vtkCornerAnnotation.h>
+#include <vtkRenderWindow.h>
+#include <vtkSmartPointer.h>
+#include <vtkWeakPointer.h>
+
+//-----------------------------------------------------------------------------
+class ctkVTKAbstractViewPrivate : public QObject
+{
+  Q_OBJECT
+  Q_DECLARE_PUBLIC(ctkVTKAbstractView);
+
+protected:
+  ctkVTKAbstractView* const q_ptr;
+
+public:
+  ctkVTKAbstractViewPrivate(ctkVTKAbstractView& object);
+
+  /// Convenient setup methods
+  virtual void init();
+  virtual void setupCornerAnnotation();
+  virtual void setupRendering();
+
+  QVTKWidget*                                   VTKWidget;
+  vtkSmartPointer<vtkRenderWindow>              RenderWindow;
+  bool                                          RenderPending;
+  bool                                          RenderEnabled;
+
+  vtkSmartPointer<vtkCornerAnnotation>          CornerAnnotation;
+};
+
+#endif

+ 6 - 123
Libs/Visualization/VTK/Widgets/ctkVTKRenderView.cpp

@@ -43,16 +43,11 @@ static ctkLogger logger("org.commontk.visualization.vtk.widgets.ctkVTKRenderView
 
 
 // --------------------------------------------------------------------------
 // --------------------------------------------------------------------------
 ctkVTKRenderViewPrivate::ctkVTKRenderViewPrivate(ctkVTKRenderView& object)
 ctkVTKRenderViewPrivate::ctkVTKRenderViewPrivate(ctkVTKRenderView& object)
-  :q_ptr(&object)
+  :ctkVTKAbstractViewPrivate(object)
 {
 {
   qRegisterMetaType<ctkAxesWidget::Axis>("ctkAxesWidget::Axis");
   qRegisterMetaType<ctkAxesWidget::Axis>("ctkAxesWidget::Axis");
   this->Renderer = vtkSmartPointer<vtkRenderer>::New();
   this->Renderer = vtkSmartPointer<vtkRenderer>::New();
-  this->RenderWindow = vtkSmartPointer<vtkRenderWindow>::New();
-  this->Axes = vtkSmartPointer<vtkAxesActor>::New();
   this->Orientation = vtkSmartPointer<vtkOrientationMarkerWidget>::New();
   this->Orientation = vtkSmartPointer<vtkOrientationMarkerWidget>::New();
-  this->CornerAnnotation = vtkSmartPointer<vtkCornerAnnotation>::New();
-  this->RenderPending = false;
-  this->RenderEnabled = true;
   this->ZoomFactor = 0.05;
   this->ZoomFactor = 0.05;
   this->PitchRollYawIncrement = 5;
   this->PitchRollYawIncrement = 5;
   this->PitchDirection = ctkVTKRenderView::PitchUp;
   this->PitchDirection = ctkVTKRenderView::PitchUp;
@@ -71,42 +66,19 @@ ctkVTKRenderViewPrivate::ctkVTKRenderViewPrivate(ctkVTKRenderView& object)
 void ctkVTKRenderViewPrivate::setupCornerAnnotation()
 void ctkVTKRenderViewPrivate::setupCornerAnnotation()
 {
 {
   logger.trace("setupCornerAnnotation");
   logger.trace("setupCornerAnnotation");
+  this->ctkVTKAbstractViewPrivate::setupCornerAnnotation();
   if (!this->Renderer->HasViewProp(this->CornerAnnotation))
   if (!this->Renderer->HasViewProp(this->CornerAnnotation))
     {
     {
     this->Renderer->AddViewProp(this->CornerAnnotation);
     this->Renderer->AddViewProp(this->CornerAnnotation);
-    this->CornerAnnotation->SetMaximumLineHeight(0.07);
-    vtkTextProperty *tprop = this->CornerAnnotation->GetTextProperty();
-    tprop->ShadowOn();
     }
     }
-  this->CornerAnnotation->ClearAllTexts();
 }
 }
 
 
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 void ctkVTKRenderViewPrivate::setupRendering()
 void ctkVTKRenderViewPrivate::setupRendering()
 {
 {
-  logger.trace("setupRendering");
-  Q_ASSERT(this->RenderWindow);
-  this->RenderWindow->SetAlphaBitPlanes(1);
-  this->RenderWindow->SetMultiSamples(0);
-  this->RenderWindow->StereoCapableWindowOn();
-  
-  this->RenderWindow->GetRenderers()->RemoveAllItems();
-  
   // Add renderer
   // Add renderer
   this->RenderWindow->AddRenderer(this->Renderer);
   this->RenderWindow->AddRenderer(this->Renderer);
-  
-  // Setup the corner annotation
-  this->setupCornerAnnotation();
-
-  this->VTKWidget->SetRenderWindow(this->RenderWindow);
-}
-
-//---------------------------------------------------------------------------
-void ctkVTKRenderViewPrivate::setupDefaultInteractor()
-{
-  logger.trace("setupDefaultInteractor");
-  Q_Q(ctkVTKRenderView);
-  q->setInteractor(this->RenderWindow->GetInteractor());
+  this->ctkVTKAbstractViewPrivate::setupRendering();
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
@@ -222,111 +194,26 @@ void ctkVTKRenderViewPrivate::doRock()
 // ctkVTKRenderView methods
 // ctkVTKRenderView methods
 
 
 // --------------------------------------------------------------------------
 // --------------------------------------------------------------------------
-ctkVTKRenderView::ctkVTKRenderView(QWidget* _parent) : Superclass(_parent)
-  , d_ptr(new ctkVTKRenderViewPrivate(*this))
+ctkVTKRenderView::ctkVTKRenderView(QWidget* parentWidget)
+  : Superclass(new ctkVTKRenderViewPrivate(*this), parentWidget)
 {
 {
-  Q_D(ctkVTKRenderView);
-  
-  d->VTKWidget = new QVTKWidget(this);
-  this->setLayout(new QVBoxLayout);
-  this->layout()->setMargin(0);
-  this->layout()->setSpacing(0);
-  this->layout()->addWidget(d->VTKWidget);
-
-  d->setupRendering();
-  d->setupDefaultInteractor();
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
 ctkVTKRenderView::~ctkVTKRenderView()
 ctkVTKRenderView::~ctkVTKRenderView()
 {
 {
 }
 }
-
-//----------------------------------------------------------------------------
-void ctkVTKRenderView::scheduleRender()
-{
-  Q_D(ctkVTKRenderView);
-
-  logger.trace(QString("scheduleRender - RenderEnabled: %1 - RenderPending: %2").
-               arg(d->RenderEnabled ? "true" : "false")
-               .arg(d->RenderPending ? "true:" : "false"));
-
-  if (!d->RenderEnabled)
-    {
-    return;
-    }
-  if (!d->RenderPending)
-    {
-    d->RenderPending = true;
-    QTimer::singleShot(0, this, SLOT(forceRender()));
-    }
-}
-
-//----------------------------------------------------------------------------
-void ctkVTKRenderView::forceRender()
-{
-  Q_D(ctkVTKRenderView);
-
-  d->RenderPending = false;
-  logger.trace(QString("forceRender - RenderEnabled: %1")
-               .arg(d->RenderEnabled ? "true" : "false"));
-
-  if (!d->RenderEnabled || !this->isVisible())
-    {
-    return;
-    }
-  d->RenderWindow->Render();
-}
-
-//----------------------------------------------------------------------------
-CTK_GET_CPP(ctkVTKRenderView, vtkRenderWindow*, renderWindow, RenderWindow);
-
-//----------------------------------------------------------------------------
-CTK_GET_CPP(ctkVTKRenderView, vtkRenderWindowInteractor*, interactor, CurrentInteractor);
-
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
 void ctkVTKRenderView::setInteractor(vtkRenderWindowInteractor* newInteractor)
 void ctkVTKRenderView::setInteractor(vtkRenderWindowInteractor* newInteractor)
 {
 {
   Q_D(ctkVTKRenderView);
   Q_D(ctkVTKRenderView);
 
 
   logger.trace("setInteractor");
   logger.trace("setInteractor");
-
-  d->RenderWindow->SetInteractor(newInteractor);
+  this->Superclass::setInteractor(newInteractor);
   d->Orientation->SetOrientationMarker(d->Axes);
   d->Orientation->SetOrientationMarker(d->Axes);
   d->Orientation->SetInteractor(newInteractor);
   d->Orientation->SetInteractor(newInteractor);
   d->Orientation->SetEnabled(1);
   d->Orientation->SetEnabled(1);
   d->Orientation->InteractiveOff();
   d->Orientation->InteractiveOff();
-  d->CurrentInteractor = newInteractor; 
-}
-
-//----------------------------------------------------------------------------
-vtkInteractorObserver* ctkVTKRenderView::interactorStyle()
-{
-  Q_D(ctkVTKRenderView);
-  if (d->CurrentInteractor)
-    {
-    return d->CurrentInteractor->GetInteractorStyle();
-    }
-  else
-    {
-    return 0;
-    }
-}
-
-//----------------------------------------------------------------------------
-void ctkVTKRenderView::setCornerAnnotationText(const QString& text)
-{
-  Q_D(ctkVTKRenderView);
-  logger.trace(QString("setCornerAnnotationText: %1").arg(text));
-  d->CornerAnnotation->ClearAllTexts();
-  d->CornerAnnotation->SetText(2, text.toLatin1());
-}
-
-//----------------------------------------------------------------------------
-QString ctkVTKRenderView::cornerAnnotationText() const
-{
-  Q_D(const ctkVTKRenderView);
-  return QLatin1String(d->CornerAnnotation->GetText(2));
 }
 }
 
 
 // --------------------------------------------------------------------------
 // --------------------------------------------------------------------------
@@ -390,10 +277,6 @@ void ctkVTKRenderView::resetCamera()
 CTK_GET_CPP(ctkVTKRenderView, vtkRenderer*, renderer, Renderer);
 CTK_GET_CPP(ctkVTKRenderView, vtkRenderer*, renderer, Renderer);
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
-CTK_SET_CPP(ctkVTKRenderView, bool, setRenderEnabled, RenderEnabled);
-CTK_GET_CPP(ctkVTKRenderView, bool, renderEnabled, RenderEnabled);
-
-//----------------------------------------------------------------------------
 CTK_GET_CPP(ctkVTKRenderView, int, pitchRollYawIncrement, PitchRollYawIncrement);
 CTK_GET_CPP(ctkVTKRenderView, int, pitchRollYawIncrement, PitchRollYawIncrement);
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------

+ 14 - 52
Libs/Visualization/VTK/Widgets/ctkVTKRenderView.h

@@ -21,28 +21,17 @@
 #ifndef __ctkVTKRenderView_h
 #ifndef __ctkVTKRenderView_h
 #define __ctkVTKRenderView_h
 #define __ctkVTKRenderView_h
 
 
-// Qt includes
-#include <QWidget>
-
 // CTK includes
 // CTK includes
 #include <ctkAxesWidget.h>
 #include <ctkAxesWidget.h>
-#include <ctkPimpl.h>
-
-#include "ctkVisualizationVTKWidgetsExport.h"
-
+#include "ctkVTKAbstractView.h"
 class ctkVTKRenderViewPrivate;
 class ctkVTKRenderViewPrivate;
-class vtkInteractorObserver;
-class vtkRenderWindowInteractor;
-class vtkRenderWindow;
+
+class vtkCamera;
 class vtkRenderer;
 class vtkRenderer;
-class vtkCamera; 
 
 
-class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKRenderView : public QWidget
+class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKRenderView : public ctkVTKAbstractView
 {
 {
   Q_OBJECT
   Q_OBJECT
-  Q_PROPERTY(QString cornerAnnotationText READ cornerAnnotationText WRITE setCornerAnnotationText)
-  Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
-  Q_PROPERTY(bool renderEnabled READ renderEnabled WRITE setRenderEnabled)
   Q_PROPERTY(bool orientationWidgetVisible READ orientationWidgetVisible
   Q_PROPERTY(bool orientationWidgetVisible READ orientationWidgetVisible
              WRITE setOrientationWidgetVisible)
              WRITE setOrientationWidgetVisible)
   Q_PROPERTY(double zoomFactor READ zoomFactor WRITE setZoomFactor)
   Q_PROPERTY(double zoomFactor READ zoomFactor WRITE setZoomFactor)
@@ -62,27 +51,11 @@ public:
 
 
   enum RotateDirection { PitchUp, PitchDown, RollLeft, RollRight, YawLeft, YawRight };
   enum RotateDirection { PitchUp, PitchDown, RollLeft, RollRight, YawLeft, YawRight };
 
 
-  typedef QWidget Superclass;
+  typedef ctkVTKAbstractView Superclass;
   explicit ctkVTKRenderView(QWidget* parent = 0);
   explicit ctkVTKRenderView(QWidget* parent = 0);
   virtual ~ctkVTKRenderView();
   virtual ~ctkVTKRenderView();
 
 
 public slots:
 public slots:
-
-  /// If a render has already been scheduled, this called is a no-op
-  void scheduleRender();
-
-  /// Force a render even if a render is already ocurring
-  void forceRender();
-
-  /// Set background color
-  void setBackgroundColor(const QColor& newBackgroundColor);
-
-  /// Enable/Disable rendering
-  void setRenderEnabled(bool value);
-
-  /// Set corner annotation \a text
-  void setCornerAnnotationText(const QString& text);
-
   /// Show/Hide Orientation widget
   /// Show/Hide Orientation widget
   void setOrientationWidgetVisible(bool visible);
   void setOrientationWidgetVisible(bool visible);
 
 
@@ -142,29 +115,20 @@ public slots:
   /// \brief Reset focal point
   /// \brief Reset focal point
   /// The visible scene bbox is computed, then the camera is recentered around its centroid.
   /// The visible scene bbox is computed, then the camera is recentered around its centroid.
   void resetFocalPoint();
   void resetFocalPoint();
-  
+
   /// \brief Change camera to look from a given axis to the focal point
   /// \brief Change camera to look from a given axis to the focal point
   /// Translate/Rotate the camera to look from a given axis
   /// Translate/Rotate the camera to look from a given axis
-  /// The Field of View (fov) controls how far from the focal point the 
+  /// The Field of View (fov) controls how far from the focal point the
   /// camera must be (final_pos = focal_point + 3*fov).
   /// camera must be (final_pos = focal_point + 3*fov).
   void lookFromAxis(const ctkAxesWidget::Axis& axis, double fov = 10.);
   void lookFromAxis(const ctkAxesWidget::Axis& axis, double fov = 10.);
 
 
 public:
 public:
-  /// Get underlying RenderWindow
-  vtkRenderWindow* renderWindow()const;
-  
-  /// Set/Get window interactor
-  vtkRenderWindowInteractor* interactor()const;
-  void setInteractor(vtkRenderWindowInteractor* newInteractor);
-
-  /// Get current interactor style
-  vtkInteractorObserver* interactorStyle();
 
 
-  /// Get corner annotation \a text
-  QString cornerAnnotationText() const;
+  /// Set background color
+  virtual void setBackgroundColor(const QColor& newBackgroundColor);
 
 
   /// Get background color
   /// Get background color
-  QColor backgroundColor() const;
+  virtual QColor backgroundColor() const;
 
 
   /// Get Orientation widget visibility
   /// Get Orientation widget visibility
   bool orientationWidgetVisible();
   bool orientationWidgetVisible();
@@ -178,8 +142,9 @@ public:
   /// Get a reference to the associated vtkRenderer
   /// Get a reference to the associated vtkRenderer
   vtkRenderer* renderer()const;
   vtkRenderer* renderer()const;
 
 
-  /// Return if rendering is enabled
-  bool renderEnabled() const;
+  /// Set window interactor
+  /// Reimplemented to propagate interaction to Orientation widget
+  virtual void setInteractor(vtkRenderWindowInteractor* interactor);
 
 
   /// Return pitch, roll or yaw increment (in degree)
   /// Return pitch, roll or yaw increment (in degree)
   int pitchRollYawIncrement()const;
   int pitchRollYawIncrement()const;
@@ -218,13 +183,10 @@ public:
 
 
   /// Return zoom factor
   /// Return zoom factor
   double zoomFactor()const;
   double zoomFactor()const;
-  
-protected:
-  QScopedPointer<ctkVTKRenderViewPrivate> d_ptr;
 
 
 private:
 private:
   Q_DECLARE_PRIVATE(ctkVTKRenderView);
   Q_DECLARE_PRIVATE(ctkVTKRenderView);
   Q_DISABLE_COPY(ctkVTKRenderView);
   Q_DISABLE_COPY(ctkVTKRenderView);
-}; 
+};
 
 
 #endif
 #endif

+ 6 - 15
Libs/Visualization/VTK/Widgets/ctkVTKRenderView_p.h

@@ -26,6 +26,7 @@
 
 
 // CTK includes
 // CTK includes
 #include <ctkPimpl.h>
 #include <ctkPimpl.h>
+#include "ctkVTKAbstractView_p.h"
 #include <ctkVTKObject.h>
 #include <ctkVTKObject.h>
 #include "ctkVTKRenderView.h"
 #include "ctkVTKRenderView.h"
 
 
@@ -42,21 +43,17 @@
 class vtkRenderWindowInteractor;
 class vtkRenderWindowInteractor;
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-class ctkVTKRenderViewPrivate : public QObject
+class ctkVTKRenderViewPrivate : public ctkVTKAbstractViewPrivate
 {
 {
   Q_OBJECT
   Q_OBJECT
   Q_DECLARE_PUBLIC(ctkVTKRenderView);
   Q_DECLARE_PUBLIC(ctkVTKRenderView);
 
 
-protected:
-  ctkVTKRenderView* const q_ptr;
-
 public:
 public:
   ctkVTKRenderViewPrivate(ctkVTKRenderView& object);
   ctkVTKRenderViewPrivate(ctkVTKRenderView& object);
 
 
   /// Convenient setup methods
   /// Convenient setup methods
-  void setupCornerAnnotation();
-  void setupRendering();
-  void setupDefaultInteractor();
+  virtual void setupCornerAnnotation();
+  virtual void setupRendering();
 
 
   void zoom(double zoomFactor);
   void zoom(double zoomFactor);
 
 
@@ -72,13 +69,10 @@ public:
 
 
   QVTKWidget*                                   VTKWidget;
   QVTKWidget*                                   VTKWidget;
   vtkSmartPointer<vtkRenderer>                  Renderer;
   vtkSmartPointer<vtkRenderer>                  Renderer;
-  vtkSmartPointer<vtkRenderWindow>              RenderWindow;
-  bool                                          RenderPending;
-  bool                                          RenderEnabled;
-  
+
   vtkSmartPointer<vtkAxesActor>                 Axes;
   vtkSmartPointer<vtkAxesActor>                 Axes;
   vtkSmartPointer<vtkOrientationMarkerWidget>   Orientation;
   vtkSmartPointer<vtkOrientationMarkerWidget>   Orientation;
-  vtkSmartPointer<vtkCornerAnnotation>          CornerAnnotation;
+
   double                                        ZoomFactor;
   double                                        ZoomFactor;
   int                                           PitchRollYawIncrement;
   int                                           PitchRollYawIncrement;
   ctkVTKRenderView::RotateDirection             PitchDirection;
   ctkVTKRenderView::RotateDirection             PitchDirection;
@@ -91,9 +85,6 @@ public:
   bool                                          RockEnabled;
   bool                                          RockEnabled;
   int                                           RockIncrement;
   int                                           RockIncrement;
   int                                           RockLength;
   int                                           RockLength;
-
-  vtkWeakPointer<vtkRenderWindowInteractor>     CurrentInteractor;
-
 };
 };
 
 
 #endif
 #endif

+ 17 - 109
Libs/Visualization/VTK/Widgets/ctkVTKSliceView.cpp

@@ -19,8 +19,6 @@
 =========================================================================*/
 =========================================================================*/
 
 
 // Qt includes
 // Qt includes
-#include <QTimer>
-#include <QVBoxLayout>
 #include <QDebug>
 #include <QDebug>
 #include <QResizeEvent>
 #include <QResizeEvent>
 
 
@@ -53,28 +51,33 @@ static ctkLogger logger("org.commontk.visualization.vtk.widgets.ctkVTKSliceView"
 // ctkVTKSliceViewPrivate methods
 // ctkVTKSliceViewPrivate methods
 
 
 // --------------------------------------------------------------------------
 // --------------------------------------------------------------------------
-ctkVTKSliceViewPrivate::ctkVTKSliceViewPrivate()
+ctkVTKSliceViewPrivate::ctkVTKSliceViewPrivate(ctkVTKSliceView& object)
+  : ctkVTKAbstractViewPrivate(object)
 {
 {
-  this->RenderWindow = vtkSmartPointer<vtkRenderWindow>::New();
   this->LightBoxRendererManager = vtkSmartPointer<vtkLightBoxRendererManager>::New();
   this->LightBoxRendererManager = vtkSmartPointer<vtkLightBoxRendererManager>::New();
-  this->RenderPending = false;
-  this->RenderEnabled = false;
+  this->OverlayRenderer = vtkSmartPointer<vtkRenderer>::New();
+}
+
+// --------------------------------------------------------------------------
+void ctkVTKSliceViewPrivate::setupCornerAnnotation()
+{
+  logger.trace("setupCornerAnnotation");
+  // whatever is done in ctkVTKAbsrtactViewPrivate would be overriden anyway
+  this->ctkVTKAbstractViewPrivate::setupCornerAnnotation();
+  this->LightBoxRendererManager->SetCornerAnnotation(this->CornerAnnotation);
 }
 }
 
 
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 void ctkVTKSliceViewPrivate::setupRendering()
 void ctkVTKSliceViewPrivate::setupRendering()
 {
 {
   Q_ASSERT(this->RenderWindow);
   Q_ASSERT(this->RenderWindow);
-  this->RenderWindow->SetAlphaBitPlanes(1);
-  this->RenderWindow->SetMultiSamples(0);
-  this->RenderWindow->StereoCapableWindowOn();
   this->RenderWindow->SetNumberOfLayers(2);
   this->RenderWindow->SetNumberOfLayers(2);
 
 
   // Initialize light box
   // Initialize light box
   this->LightBoxRendererManager->Initialize(this->RenderWindow);
   this->LightBoxRendererManager->Initialize(this->RenderWindow);
+  this->LightBoxRendererManager->SetRenderWindowLayout(1, 1);
 
 
   // Setup overlay renderer
   // Setup overlay renderer
-  this->OverlayRenderer = vtkSmartPointer<vtkRenderer>::New();
   this->OverlayRenderer->SetLayer(1);
   this->OverlayRenderer->SetLayer(1);
   this->RenderWindow->AddRenderer(this->OverlayRenderer);
   this->RenderWindow->AddRenderer(this->OverlayRenderer);
 
 
@@ -88,27 +91,16 @@ void ctkVTKSliceViewPrivate::setupRendering()
   // Add corner annotation to overlay renderer
   // Add corner annotation to overlay renderer
   this->OverlayRenderer->AddViewProp(this->OverlayCornerAnnotation);
   this->OverlayRenderer->AddViewProp(this->OverlayCornerAnnotation);
 
 
-  this->VTKWidget->SetRenderWindow(this->RenderWindow);
+  this->ctkVTKAbstractViewPrivate::setupRendering();
 }
 }
 
 
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 // ctkVTKSliceView methods
 // ctkVTKSliceView methods
 
 
 // --------------------------------------------------------------------------
 // --------------------------------------------------------------------------
-ctkVTKSliceView::ctkVTKSliceView(QWidget* _parent) : Superclass(_parent)
-  , d_ptr(new ctkVTKSliceViewPrivate)
+ctkVTKSliceView::ctkVTKSliceView(QWidget* parentWidget)
+  : Superclass(new ctkVTKSliceViewPrivate(*this), parentWidget)
 {
 {
-  Q_D(ctkVTKSliceView);
-  
-  d->VTKWidget = new QVTKWidget(this);
-  this->setLayout(new QVBoxLayout);
-  this->layout()->setMargin(0);
-  this->layout()->setSpacing(0);
-  this->layout()->addWidget(d->VTKWidget);
-
-  d->setupRendering();
-
-  d->LightBoxRendererManager->SetRenderWindowLayout(1, 1);
 }
 }
 
 
 // --------------------------------------------------------------------------
 // --------------------------------------------------------------------------
@@ -117,39 +109,6 @@ ctkVTKSliceView::~ctkVTKSliceView()
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
-void ctkVTKSliceView::scheduleRender()
-{
-  Q_D(ctkVTKSliceView);
-
-  logger.trace("scheduleRender");
-  if (!d->RenderEnabled)
-    {
-    return;
-    }
-  if (!d->RenderPending)
-    {
-    d->RenderPending = true;
-    QTimer::singleShot(0, this, SLOT(forceRender()));
-    }
-}
-
-//----------------------------------------------------------------------------
-void ctkVTKSliceView::forceRender()
-{
-  Q_D(ctkVTKSliceView);
-  d->RenderPending = false;
-  if (!d->RenderEnabled  || !this->isVisible())
-    {
-    return;
-    }
-  logger.trace("forceRender");
-  d->RenderWindow->Render();
-}
-
-//----------------------------------------------------------------------------
-CTK_GET_CPP(ctkVTKSliceView, vtkRenderWindow*, renderWindow, RenderWindow);
-
-//----------------------------------------------------------------------------
 void ctkVTKSliceView::setActiveCamera(vtkCamera * newActiveCamera)
 void ctkVTKSliceView::setActiveCamera(vtkCamera * newActiveCamera)
 {
 {
   Q_D(ctkVTKSliceView);
   Q_D(ctkVTKSliceView);
@@ -165,35 +124,6 @@ CTK_GET_CPP(ctkVTKSliceView, vtkLightBoxRendererManager*,
 CTK_GET_CPP(ctkVTKSliceView, vtkRenderer*, overlayRenderer, OverlayRenderer);
 CTK_GET_CPP(ctkVTKSliceView, vtkRenderer*, overlayRenderer, OverlayRenderer);
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
-CTK_SET_CPP(ctkVTKSliceView, bool, setRenderEnabled, RenderEnabled);
-CTK_GET_CPP(ctkVTKSliceView, bool, renderEnabled, RenderEnabled);
-
-//----------------------------------------------------------------------------
-vtkRenderWindowInteractor* ctkVTKSliceView::interactor() const
-{
-  Q_D(const ctkVTKSliceView);
-  return d->RenderWindow->GetInteractor();
-}
-
-//----------------------------------------------------------------------------
-void ctkVTKSliceView::setInteractor(vtkRenderWindowInteractor* newInteractor)
-{
-  Q_D(const ctkVTKSliceView);
-  d->RenderWindow->SetInteractor(newInteractor);
-}
-
-//----------------------------------------------------------------------------
-vtkInteractorObserver* ctkVTKSliceView::interactorStyle()const
-{
-  Q_D(const ctkVTKSliceView);
-  if (!d->RenderWindow->GetInteractor())
-    {
-    return 0;
-    }
-  return d->RenderWindow->GetInteractor()->GetInteractorStyle();
-}
-
-//----------------------------------------------------------------------------
 void ctkVTKSliceView::resetCamera()
 void ctkVTKSliceView::resetCamera()
 {
 {
   Q_D(ctkVTKSliceView);
   Q_D(ctkVTKSliceView);
@@ -201,7 +131,6 @@ void ctkVTKSliceView::resetCamera()
   d->LightBoxRendererManager->ResetCamera();
   d->LightBoxRendererManager->ResetCamera();
 }
 }
 
 
-
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
 void ctkVTKSliceView::setImageData(vtkImageData* newImageData)
 void ctkVTKSliceView::setImageData(vtkImageData* newImageData)
 {
 {
@@ -210,27 +139,6 @@ void ctkVTKSliceView::setImageData(vtkImageData* newImageData)
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
-QString ctkVTKSliceView::cornerAnnotationText()const
-{
-  Q_D(const ctkVTKSliceView);
-  return QString::fromStdString(d->LightBoxRendererManager->GetCornerAnnotationText());
-}
-
-//----------------------------------------------------------------------------
-vtkCornerAnnotation * ctkVTKSliceView::cornerAnnotation()const
-{
-  Q_D(const ctkVTKSliceView);
-  return d->LightBoxRendererManager->GetCornerAnnotation();
-}
-
-//----------------------------------------------------------------------------
-void ctkVTKSliceView::setCornerAnnotationText(const QString& text)
-{
-  Q_D(ctkVTKSliceView);
-  d->LightBoxRendererManager->SetCornerAnnotationText(text.toStdString());
-}
-
-//----------------------------------------------------------------------------
 vtkCornerAnnotation * ctkVTKSliceView::overlayCornerAnnotation()const
 vtkCornerAnnotation * ctkVTKSliceView::overlayCornerAnnotation()const
 {
 {
   Q_D(const ctkVTKSliceView);
   Q_D(const ctkVTKSliceView);
@@ -326,7 +234,7 @@ void ctkVTKSliceView::setColorWindow(double newColorWindow)
 void ctkVTKSliceView::resizeEvent(QResizeEvent * event)
 void ctkVTKSliceView::resizeEvent(QResizeEvent * event)
 {
 {
   this->QWidget::resizeEvent(event);
   this->QWidget::resizeEvent(event);
-  emit this->resized(event->size(), event->oldSize());
+  emit this->resized(event->size());
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------

+ 13 - 64
Libs/Visualization/VTK/Widgets/ctkVTKSliceView.h

@@ -21,40 +21,28 @@
 #ifndef __ctkVTKSliceView_h
 #ifndef __ctkVTKSliceView_h
 #define __ctkVTKSliceView_h
 #define __ctkVTKSliceView_h
 
 
-// Qt includes
-#include <QWidget>
-
 // CTK includes
 // CTK includes
-#include <ctkPimpl.h>
-
-#include "ctkVisualizationVTKWidgetsExport.h"
-
-class ctkVTKSliceViewPrivate;
+#include "ctkVTKAbstractView.h"
 class vtkLightBoxRendererManager;
 class vtkLightBoxRendererManager;
-class vtkInteractorObserver;
-class vtkRenderWindowInteractor;
-class vtkRenderWindow;
-class vtkRenderer;
-class vtkCamera; 
+class ctkVTKSliceViewPrivate;
+
+class vtkCamera;
 class vtkImageData;
 class vtkImageData;
-class vtkCornerAnnotation;
+class vtkRenderer;
 
 
-class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKSliceView : public QWidget
+class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKSliceView : public ctkVTKAbstractView
 {
 {
   Q_OBJECT
   Q_OBJECT
   Q_ENUMS(RenderWindowLayoutType)
   Q_ENUMS(RenderWindowLayoutType)
   Q_PROPERTY(RenderWindowLayoutType renderWindowLayoutType
   Q_PROPERTY(RenderWindowLayoutType renderWindowLayoutType
              READ renderWindowLayoutType WRITE setRenderWindowLayoutType)
              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(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 colorLevel READ colorLevel WRITE setColorLevel)
   Q_PROPERTY(double colorWindow READ colorWindow WRITE setColorWindow)
   Q_PROPERTY(double colorWindow READ colorWindow WRITE setColorWindow)
 
 
 public:
 public:
   /// Constructors
   /// Constructors
-  typedef QWidget   Superclass;
+  typedef ctkVTKAbstractView Superclass;
   explicit ctkVTKSliceView(QWidget* parent = 0);
   explicit ctkVTKSliceView(QWidget* parent = 0);
   virtual ~ctkVTKSliceView();
   virtual ~ctkVTKSliceView();
 
 
@@ -63,12 +51,6 @@ public:
   /// \sa setRenderWindowLayout() renderWindowLayoutType()
   /// \sa setRenderWindowLayout() renderWindowLayoutType()
   enum RenderWindowLayoutType{LeftRightTopBottom = 0, LeftRightBottomTop};
   enum RenderWindowLayoutType{LeftRightTopBottom = 0, LeftRightBottomTop};
 
 
-  /// Return if rendering is enabled
-  bool renderEnabled() const;
-
-  /// Convenient method to get the underlying RenderWindow
-  vtkRenderWindow* renderWindow() const;
-
   /// Set active camera
   /// Set active camera
   void setActiveCamera(vtkCamera * newActiveCamera);
   void setActiveCamera(vtkCamera * newActiveCamera);
 
 
@@ -78,30 +60,17 @@ public:
   /// Get overlay renderer
   /// Get overlay renderer
   vtkRenderer* overlayRenderer() const;
   vtkRenderer* overlayRenderer() const;
 
 
-  /// Set/Get window interactor
-  vtkRenderWindowInteractor* interactor() const;
-  void setInteractor(vtkRenderWindowInteractor* newInteractor);
-
-  /// Get current interactor style
-  vtkInteractorObserver* interactorStyle()const;
-
-  /// Get corner annotation text
-  /// \sa setCornerAnnotationText();
-  QString cornerAnnotationText()const;
-
-  /// Get corner annotation actor
-  /// This is the corner annotation associated with all renderers managed
-  /// by the lightBoxManager
-  /// \sa vtkLightBoxRendererManager::GetCornerAnnotation()
-  vtkCornerAnnotation * cornerAnnotation()const;
-
   /// Get overlay corner annotation actor
   /// Get overlay corner annotation actor
   /// This corresponds to the cornerAnnotation associated added in the single overlay renderer
   /// This corresponds to the cornerAnnotation associated added in the single overlay renderer
   vtkCornerAnnotation* overlayCornerAnnotation()const;
   vtkCornerAnnotation* overlayCornerAnnotation()const;
 
 
+  /// Set background color
+  /// \sa vtkLightBoxRendererManager::SetBackgroundColor
+  virtual void setBackgroundColor(const QColor& newBackgroundColor);
+
   /// Get background color
   /// Get background color
   /// \sa setBackgroundColor();
   /// \sa setBackgroundColor();
-  QColor backgroundColor()const;
+  virtual QColor backgroundColor()const;
 
 
   /// Get highlightedBox color
   /// Get highlightedBox color
   /// \sa setHighlightedBoxColor();
   /// \sa setHighlightedBoxColor();
@@ -121,12 +90,6 @@ public:
 
 
 public slots:
 public slots:
 
 
-  /// If a render has already been scheduled, this called is a no-op
-  void scheduleRender();
-
-  /// Force a render even if a render is already ocurring
-  void forceRender();
-
   /// Reset cameras associated with all renderWindowItem
   /// Reset cameras associated with all renderWindowItem
   /// \sa vtkLightBoxRendererManager::ResetCamera
   /// \sa vtkLightBoxRendererManager::ResetCamera
   void resetCamera();
   void resetCamera();
@@ -135,21 +98,10 @@ public slots:
   /// \sa vtkLightBoxRendererManager::SetImageData
   /// \sa vtkLightBoxRendererManager::SetImageData
   void setImageData(vtkImageData* newImageData);
   void setImageData(vtkImageData* newImageData);
 
 
-  /// Set corner annotation \a text
-  /// \sa vtkLightBoxRendererManager::SetCornerAnnotationText
-  void setCornerAnnotationText(const QString& text);
-
-  /// Set background color
-  /// \sa vtkLightBoxRendererManager::SetBackgroundColor
-  void setBackgroundColor(const QColor& newBackgroundColor);
-
   /// Set highlightedBox color
   /// Set highlightedBox color
   /// \sa vtkLightBoxRendererManager::SetHighlightedBoxColor
   /// \sa vtkLightBoxRendererManager::SetHighlightedBoxColor
   void setHighlightedBoxColor(const QColor& newHighlightedBoxColor);
   void setHighlightedBoxColor(const QColor& newHighlightedBoxColor);
 
 
-  /// Enable/Disable rendering
-  void setRenderEnabled(bool value);
-
   /// Set RenderWindow layout type
   /// Set RenderWindow layout type
   /// \sa vtkLightBoxRendererManager::SetRenderWindowLayoutType
   /// \sa vtkLightBoxRendererManager::SetRenderWindowLayoutType
   void setRenderWindowLayoutType(RenderWindowLayoutType layoutType);
   void setRenderWindowLayoutType(RenderWindowLayoutType layoutType);
@@ -173,14 +125,11 @@ public slots:
   void setLightBoxRendererManagerColumnCount(int newColumnCount);
   void setLightBoxRendererManagerColumnCount(int newColumnCount);
   
   
 signals:
 signals:
-  void resized(const QSize& size, const QSize& oldSize);
+  void resized(const QSize& size);
 
 
 protected:
 protected:
   virtual void resizeEvent(QResizeEvent * event);
   virtual void resizeEvent(QResizeEvent * event);
 
 
-protected:
-  QScopedPointer<ctkVTKSliceViewPrivate> d_ptr;
-  
 private:
 private:
   Q_DECLARE_PRIVATE(ctkVTKSliceView);
   Q_DECLARE_PRIVATE(ctkVTKSliceView);
   Q_DISABLE_COPY(ctkVTKSliceView);
   Q_DISABLE_COPY(ctkVTKSliceView);

+ 4 - 12
Libs/Visualization/VTK/Widgets/ctkVTKSliceView_p.h

@@ -28,36 +28,28 @@
 #include <QSharedPointer>
 #include <QSharedPointer>
 
 
 // CTK includes
 // CTK includes
-#include <ctkPimpl.h>
-#include <ctkVTKObject.h>
-#include <vtkLightBoxRendererManager.h>
 #include "ctkVTKSliceView.h"
 #include "ctkVTKSliceView.h"
+#include "ctkVTKAbstractView_p.h"
+#include <vtkLightBoxRendererManager.h>
 
 
 // VTK includes
 // VTK includes
-#include <QVTKWidget.h>
 #include <vtkRenderer.h>
 #include <vtkRenderer.h>
-#include <vtkRenderWindow.h>
 #include <vtkSmartPointer.h>
 #include <vtkSmartPointer.h>
-#include <vtkWeakPointer.h>
-#include <vtkImageMapper.h>
 #include <vtkCornerAnnotation.h>
 #include <vtkCornerAnnotation.h>
 
 
 class vtkRenderWindowInteractor;
 class vtkRenderWindowInteractor;
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-class ctkVTKSliceViewPrivate : public QObject
+class ctkVTKSliceViewPrivate : public ctkVTKAbstractViewPrivate
 {
 {
   Q_OBJECT
   Q_OBJECT
 public:
 public:
-  ctkVTKSliceViewPrivate();
+  ctkVTKSliceViewPrivate(ctkVTKSliceView&);
 
 
   /// Convenient setup methods
   /// Convenient setup methods
   void setupCornerAnnotation();
   void setupCornerAnnotation();
   void setupRendering();
   void setupRendering();
-  void setupDefaultInteractor();
 
 
-  QVTKWidget*                                   VTKWidget;
-  vtkSmartPointer<vtkRenderWindow>              RenderWindow;
   vtkSmartPointer<vtkLightBoxRendererManager>   LightBoxRendererManager;
   vtkSmartPointer<vtkLightBoxRendererManager>   LightBoxRendererManager;
   bool                                          RenderPending;
   bool                                          RenderPending;
   bool                                          RenderEnabled;
   bool                                          RenderEnabled;