Browse Source

Merge topic 'ctkVTKSliceView-OverlayRenderer-and-annotation'

* ctkVTKSliceView-OverlayRenderer-and-annotation:
  vtkLightBoxRendererManager - Maintain Annotation text when layout changes
  ctkVTKSliceView - Add method setActiveCamera and update resetCamera
  Add overlayRenderer and overlayCornerAnnotation to ctkVTKSliceView
  Add ctkVTKSliceView::cornerAnnotation convenienent method
  vtkLightBoxRendererManager - Add SetRendererLayer method
  Add vtkLightBoxRendererManager::GetCornerAnnotation convenient method
  vtkLightBoxRendererManager - Fix comment spell mistake
  ctkVTKSliceView - Extend doxygen documentation
Jean-Christophe Fillion-Robin 14 years ago
parent
commit
dcd3a5b7c3

+ 48 - 8
Libs/Visualization/VTK/Core/vtkLightBoxRendererManager.cpp

@@ -68,7 +68,7 @@ RenderWindowItem::RenderWindowItem(const double rendererBackgroundColor[3],
                                    const double highlightedBoxColor[3],
                                    double colorWindow, double colorLevel)
 {
-  // Instanciate a renderer
+  // Instantiate a renderer
   this->Renderer = vtkSmartPointer<vtkRenderer>::New();
   this->Renderer->SetBackground(rendererBackgroundColor[0],
                                 rendererBackgroundColor[1],
@@ -92,7 +92,7 @@ void RenderWindowItem::SetupImageMapperActor(double colorWindow, double colorLev
   assert(this->Renderer);
   assert(!this->ImageMapper);
 
-  // Instanciate an image mapper
+  // Instantiate an image mapper
   this->ImageMapper = vtkSmartPointer<vtkImageMapper>::New();
   this->ImageMapper->SetColorWindow(colorWindow);
   this->ImageMapper->SetColorLevel(colorLevel);
@@ -177,8 +177,10 @@ public:
   int                                           RenderWindowColumnCount;
   int                                           RenderWindowLayoutType;
   double                                        HighlightedBoxColor[3];
+  int                                           RendererLayer;
   vtkWeakPointer<vtkRenderWindowInteractor>     CurrentInteractor;
   vtkSmartPointer<vtkCornerAnnotation>          CornerAnnotation;
+  std::string                                   CornerAnnotationText;
 
   vtkWeakPointer<vtkImageData>                  ImageData;
   double                                        ColorWindow;
@@ -208,6 +210,7 @@ vtkLightBoxRendererManager::vtkInternal::vtkInternal(vtkLightBoxRendererManager*
   this->RenderWindowLayoutType = vtkLightBoxRendererManager::LeftRightTopBottom;
   this->ColorWindow = 255;
   this->ColorLevel = 127.5;
+  this->RendererLayer = 0;
   // Default background color: black
   this->RendererBackgroundColor[0] = 0.0;
   this->RendererBackgroundColor[1] = 0.0;
@@ -240,12 +243,15 @@ void vtkLightBoxRendererManager::vtkInternal::SetupCornerAnnotation()
     if (!(*it)->Renderer->HasViewProp(this->CornerAnnotation))
       {
       (*it)->Renderer->AddViewProp(this->CornerAnnotation);
-      this->CornerAnnotation->SetMaximumLineHeight(0.07);
-      vtkTextProperty *tprop = this->CornerAnnotation->GetTextProperty();
-      tprop->ShadowOn();
       }
-    this->CornerAnnotation->ClearAllTexts();
     }
+
+  this->CornerAnnotation->SetMaximumLineHeight(0.07);
+  vtkTextProperty *tprop = this->CornerAnnotation->GetTextProperty();
+  tprop->ShadowOn();
+
+  this->CornerAnnotation->ClearAllTexts();
+  this->CornerAnnotation->SetText(2, this->CornerAnnotationText.c_str());
 }
 
 //---------------------------------------------------------------------------
@@ -253,7 +259,13 @@ void vtkLightBoxRendererManager::vtkInternal::setupRendering()
 {
   assert(this->RenderWindow);
   
-  this->RenderWindow->GetRenderers()->RemoveAllItems();
+  // Remove only renderers managed by this light box
+  for(RenderWindowItemListIt it = this->RenderWindowItemList.begin();
+      it != this->RenderWindowItemList.end();
+      ++it)
+    {
+    this->RenderWindow->GetRenderers()->RemoveItem((*it)->Renderer);
+    }
 
   // Compute the width and height of each RenderWindowItem
   double viewportWidth  = 1.0 / static_cast<double>(this->RenderWindowColumnCount);
@@ -335,6 +347,25 @@ void vtkLightBoxRendererManager::PrintSelf(ostream& os, vtkIndent indent)
 }
 
 //----------------------------------------------------------------------------
+void vtkLightBoxRendererManager::SetRendererLayer(int newLayer)
+{
+  if (this->IsInitialized())
+    {
+    vtkErrorMacro(<< "SetRendererLayer failed - vtkLightBoxRendererManager is initialized");
+    return;
+    }
+
+  if (newLayer == this->Internal->RendererLayer)
+    {
+    return;
+    }
+
+  this->Internal->RendererLayer = newLayer;
+
+  this->Modified();
+}
+
+//----------------------------------------------------------------------------
 vtkRenderWindow* vtkLightBoxRendererManager::GetRenderWindow()
 {
   return this->Internal->RenderWindow;
@@ -538,6 +569,7 @@ void vtkLightBoxRendererManager::SetRenderWindowLayout(int rowCount, int columnC
           new RenderWindowItem(this->Internal->RendererBackgroundColor,
                                this->Internal->HighlightedBoxColor,
                                this->Internal->ColorWindow, this->Internal->ColorLevel);
+      item->Renderer->SetLayer(this->Internal->RendererLayer);
       item->ImageMapper->SetInput(this->Internal->ImageData);
       this->Internal->RenderWindowItemList.push_back(item);
       --extraItem;
@@ -690,7 +722,7 @@ void vtkLightBoxRendererManager::SetCornerAnnotationText(const std::string& text
                   "vtkLightBoxRendererManager is NOT initialized");
     return;
     }
-  if (text.compare(this->Internal->CornerAnnotation->GetText(2)) == 0)
+  if (text.compare(this->Internal->CornerAnnotationText) == 0)
     {
     return;
     }
@@ -698,6 +730,8 @@ void vtkLightBoxRendererManager::SetCornerAnnotationText(const std::string& text
   this->Internal->CornerAnnotation->ClearAllTexts();
   this->Internal->CornerAnnotation->SetText(2, text.c_str());
 
+  this->Internal->CornerAnnotationText = text;
+
   this->Modified();
 }
 
@@ -709,6 +743,12 @@ const std::string vtkLightBoxRendererManager::GetCornerAnnotationText() const
 }
 
 // --------------------------------------------------------------------------
+vtkCornerAnnotation * vtkLightBoxRendererManager::GetCornerAnnotation() const
+{
+  return this->Internal->CornerAnnotation;
+}
+
+// --------------------------------------------------------------------------
 void vtkLightBoxRendererManager::SetBackgroundColor(const double newBackgroundColor[3])
 {
   if (!this->IsInitialized())

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

@@ -9,6 +9,7 @@ class vtkRenderWindow;
 class vtkRenderer;
 class vtkImageData;
 class vtkCamera;
+class vtkCornerAnnotation;
 
 class CTK_VISUALIZATION_VTK_CORE_EXPORT vtkLightBoxRendererManager : public vtkObject
 {
@@ -20,6 +21,11 @@ class CTK_VISUALIZATION_VTK_CORE_EXPORT vtkLightBoxRendererManager : public vtkO
 
   bool IsInitialized();
 
+  /// Set the layer associated with the renderers
+  /// \note By default, the value is 0
+  /// \sa vtkRenderer::SetLayer
+  void SetRendererLayer(int newLayer);
+
   /// Get associated RenderWindow
   vtkRenderWindow* GetRenderWindow();
 
@@ -114,6 +120,10 @@ class CTK_VISUALIZATION_VTK_CORE_EXPORT vtkLightBoxRendererManager : public vtkO
   /// Get current corner annotation
   const std::string GetCornerAnnotationText()const;
 
+  /// Get corner annotation actor
+  /// The same annotation is associated with all renderers managed by the light box
+  vtkCornerAnnotation * GetCornerAnnotation()const;
+
   /// Set background color
   void SetBackgroundColor(const double newBackgroundColor[3]);
 

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

@@ -68,9 +68,26 @@ void ctkVTKSliceViewPrivate::setupRendering()
   this->RenderWindow->SetAlphaBitPlanes(1);
   this->RenderWindow->SetMultiSamples(0);
   this->RenderWindow->StereoCapableWindowOn();
+  this->RenderWindow->SetNumberOfLayers(2);
 
+  // Initialize light box
   this->LightBoxRendererManager->Initialize(this->RenderWindow);
 
+  // Setup overlay renderer
+  this->OverlayRenderer = vtkSmartPointer<vtkRenderer>::New();
+  this->OverlayRenderer->SetLayer(1);
+  this->RenderWindow->AddRenderer(this->OverlayRenderer);
+
+  // Create cornerAnnotation and set its default property
+  this->OverlayCornerAnnotation = vtkSmartPointer<vtkCornerAnnotation>::New();
+  this->OverlayCornerAnnotation->SetMaximumLineHeight(0.07);
+  vtkTextProperty *tprop = this->OverlayCornerAnnotation->GetTextProperty();
+  tprop->ShadowOn();
+  this->OverlayCornerAnnotation->ClearAllTexts();
+
+  // Add corner annotation to overlay renderer
+  this->OverlayRenderer->AddViewProp(this->OverlayCornerAnnotation);
+
   this->VTKWidget->SetRenderWindow(this->RenderWindow);
 }
 
@@ -133,10 +150,21 @@ void ctkVTKSliceView::forceRender()
 CTK_GET_CPP(ctkVTKSliceView, vtkRenderWindow*, renderWindow, RenderWindow);
 
 //----------------------------------------------------------------------------
+void ctkVTKSliceView::setActiveCamera(vtkCamera * newActiveCamera)
+{
+  Q_D(ctkVTKSliceView);
+  d->LightBoxRendererManager->SetActiveCamera(newActiveCamera);
+  d->OverlayRenderer->SetActiveCamera(newActiveCamera);
+}
+
+//----------------------------------------------------------------------------
 CTK_GET_CPP(ctkVTKSliceView, vtkLightBoxRendererManager*,
             lightBoxRendererManager, LightBoxRendererManager);
 
 //----------------------------------------------------------------------------
+CTK_GET_CPP(ctkVTKSliceView, vtkRenderer*, overlayRenderer, OverlayRenderer);
+
+//----------------------------------------------------------------------------
 CTK_SET_CPP(ctkVTKSliceView, bool, setRenderEnabled, RenderEnabled);
 CTK_GET_CPP(ctkVTKSliceView, bool, renderEnabled, RenderEnabled);
 
@@ -169,6 +197,7 @@ vtkInteractorObserver* ctkVTKSliceView::interactorStyle()const
 void ctkVTKSliceView::resetCamera()
 {
   Q_D(ctkVTKSliceView);
+  d->OverlayRenderer->ResetCamera();
   d->LightBoxRendererManager->ResetCamera();
 }
 
@@ -188,6 +217,13 @@ QString ctkVTKSliceView::cornerAnnotationText()const
 }
 
 //----------------------------------------------------------------------------
+vtkCornerAnnotation * ctkVTKSliceView::cornerAnnotation()const
+{
+  Q_D(const ctkVTKSliceView);
+  return d->LightBoxRendererManager->GetCornerAnnotation();
+}
+
+//----------------------------------------------------------------------------
 void ctkVTKSliceView::setCornerAnnotationText(const QString& text)
 {
   Q_D(ctkVTKSliceView);
@@ -195,6 +231,13 @@ void ctkVTKSliceView::setCornerAnnotationText(const QString& text)
 }
 
 //----------------------------------------------------------------------------
+vtkCornerAnnotation * ctkVTKSliceView::overlayCornerAnnotation()const
+{
+  Q_D(const ctkVTKSliceView);
+  return d->OverlayCornerAnnotation;
+}
+
+//----------------------------------------------------------------------------
 QColor ctkVTKSliceView::backgroundColor()const
 {
   Q_D(const ctkVTKSliceView);

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

@@ -37,6 +37,7 @@ class vtkRenderWindow;
 class vtkRenderer;
 class vtkCamera; 
 class vtkImageData;
+class vtkCornerAnnotation;
 
 class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKSliceView : public QWidget
 {
@@ -68,9 +69,15 @@ public:
   /// Convenient method to get the underlying RenderWindow
   vtkRenderWindow* renderWindow() const;
 
+  /// Set active camera
+  void setActiveCamera(vtkCamera * newActiveCamera);
+
   /// Get lightBoxRendererManager
   vtkLightBoxRendererManager* lightBoxRendererManager() const;
 
+  /// Get overlay renderer
+  vtkRenderer* overlayRenderer() const;
+
   /// Set/Get window interactor
   vtkRenderWindowInteractor* interactor() const;
   void setInteractor(vtkRenderWindowInteractor* newInteractor);
@@ -82,6 +89,16 @@ public:
   /// \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
+  /// This corresponds to the cornerAnnotation associated added in the single overlay renderer
+  vtkCornerAnnotation* overlayCornerAnnotation()const;
+
   /// Get background color
   /// \sa setBackgroundColor();
   QColor backgroundColor()const;
@@ -95,9 +112,11 @@ public:
   RenderWindowLayoutType renderWindowLayoutType()const;
 
   /// Get color level
+  /// \sa setColorLevel();
   double colorLevel()const;
 
   /// Get color window
+  /// \sa setColorWindow();
   double colorWindow()const;
 
 public slots:
@@ -109,38 +128,48 @@ public slots:
   void forceRender();
 
   /// Reset cameras associated with all renderWindowItem
+  /// \sa vtkLightBoxRendererManager::ResetCamera
   void resetCamera();
 
   /// Set image data
+  /// \sa vtkLightBoxRendererManager::SetImageData
   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
+  /// \sa vtkLightBoxRendererManager::SetHighlightedBoxColor
   void setHighlightedBoxColor(const QColor& newHighlightedBoxColor);
 
   /// Enable/Disable rendering
   void setRenderEnabled(bool value);
 
   /// Set RenderWindow layout type
+  /// \sa vtkLightBoxRendererManager::SetRenderWindowLayoutType
   void setRenderWindowLayoutType(RenderWindowLayoutType layoutType);
 
   /// Set color level
+  /// \sa vtkLightBoxRendererManager::SetColorLevel
   void setColorLevel(double newColorLevel);
 
   /// Set color window
+  /// \sa vtkLightBoxRendererManager::SetColorWindow
   void setColorWindow(double newColorWindow);
 
   /// Change the number of row of the associated lightBox
   /// \sa lightBoxRendererManager()
+  /// \sa vtkLightBoxRendererManager::SetRenderWindowRowCount
   void setLightBoxRendererManagerRowCount(int newRowCount);
 
   /// Change the number of column of the associated lightBox
   /// \sa lightBoxRendererManager()
+  /// \sa vtkLightBoxRendererManager::SetRenderWindowColumnCount
   void setLightBoxRendererManagerColumnCount(int newColumnCount);
   
 signals:

+ 3 - 0
Libs/Visualization/VTK/Widgets/ctkVTKSliceView_p.h

@@ -40,6 +40,7 @@
 #include <vtkSmartPointer.h>
 #include <vtkWeakPointer.h>
 #include <vtkImageMapper.h>
+#include <vtkCornerAnnotation.h>
 
 class vtkRenderWindowInteractor;
 
@@ -60,6 +61,8 @@ public:
   vtkSmartPointer<vtkLightBoxRendererManager>   LightBoxRendererManager;
   bool                                          RenderPending;
   bool                                          RenderEnabled;
+  vtkSmartPointer<vtkRenderer>                  OverlayRenderer;
+  vtkSmartPointer<vtkCornerAnnotation>          OverlayCornerAnnotation;
 
 };