Parcourir la source

Merge topic 'ctkVTKSliceView'

  ENH: ctkVTKSliceViewTest1 - Add two QSpinBoxes allowing to dynamically change lightbox layout
  ENH: ctkVTKSliceView - Added convenient slots setLightBoxRendererManager{Row, Column}Count
  ENH: vtkLightBoxRendererManager - Add method Set/GetRenderWindowRowCount and Set/GetRenderWindowColumnCount
Jean-Christophe Fillion-Robin il y a 14 ans
Parent
commit
4eaf276983

+ 24 - 0
Libs/Visualization/VTK/Core/vtkLightBoxRendererManager.cpp

@@ -552,6 +552,30 @@ void vtkLightBoxRendererManager::SetRenderWindowLayout(int rowCount, int columnC
 }
 
 //----------------------------------------------------------------------------
+int vtkLightBoxRendererManager::GetRenderWindowRowCount()
+{
+  return this->Internal->RenderWindowRowCount;
+}
+
+//----------------------------------------------------------------------------
+void vtkLightBoxRendererManager::SetRenderWindowRowCount(int newRowCount)
+{
+  this->SetRenderWindowLayout(newRowCount, this->GetRenderWindowColumnCount());
+}
+
+//----------------------------------------------------------------------------
+int vtkLightBoxRendererManager::GetRenderWindowColumnCount()
+{
+  return this->Internal->RenderWindowColumnCount;
+}
+
+//----------------------------------------------------------------------------
+void vtkLightBoxRendererManager::SetRenderWindowColumnCount(int newColumnCount)
+{
+  this->SetRenderWindowLayout(this->GetRenderWindowRowCount(), newColumnCount);
+}
+
+//----------------------------------------------------------------------------
 void vtkLightBoxRendererManager::SetHighlightedById(int id, bool highlighted)
 {
   if (!this->IsInitialized())

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

@@ -61,6 +61,22 @@ class CTK_VISUALIZATION_VTK_CORE_EXPORT vtkLightBoxRendererManager : public vtkO
   /// Split the current vtkRenderWindow in \a rowCount per \a columnCount grid
   void SetRenderWindowLayout(int rowCount, int columnCount);
 
+  /// Set the \a rowCount
+  /// \sa SetRenderWindowLayout
+  void SetRenderWindowRowCount(int newRowCount);
+
+  /// Get number of rows
+  /// \sa SetRenderWindowLayout
+  int GetRenderWindowRowCount();
+
+  /// Set the \a columnCount
+  /// \sa SetRenderWindowLayout
+  void SetRenderWindowColumnCount(int newColumnCount);
+
+  /// Get number of columns
+  /// \sa SetRenderWindowLayout
+  int GetRenderWindowColumnCount();
+
   /// Highlight / Unhighlight a render view item given its \a id
   void SetHighlightedById(int id, bool highlighted);
 

+ 54 - 8
Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKSliceViewTest1.cpp

@@ -22,9 +22,13 @@
 #include <QApplication>
 #include <QTimer>
 #include <QDebug>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QSpinBox>
 
 // CTK includes
 #include "ctkCommandLineParser.h"
+#include "ctkVTKObjectEventsObserver.h"
 #include "ctkVTKSliceView.h"
 
 // VTK includes
@@ -83,14 +87,56 @@ int ctkVTKSliceViewTest1(int argc, char * argv [] )
   imageReader->Update();
   vtkSmartPointer<vtkImageData> image = imageReader->GetOutput();
 
-  ctkVTKSliceView sliceView;
-  sliceView.resize(300, 300);
-  sliceView.setImageData(image);
-  sliceView.lightBoxRendererManager()->SetRenderWindowLayout(4, 3);
-  sliceView.lightBoxRendererManager()->SetHighlighted(1, 1, true);
-  sliceView.setCornerAnnotationText("CTK");
-  sliceView.scheduleRender();
-  sliceView.show();
+  // Top level widget
+  QWidget widget;
+
+  // .. and its associated layout
+  QVBoxLayout * topLevelLayout = new QVBoxLayout(&widget);
+
+  // Horizontal layout to contain the spinboxes
+  QHBoxLayout * spinBoxLayout = new QHBoxLayout;
+  topLevelLayout->addLayout(spinBoxLayout);
+
+  int defaultRowCount = 4;
+  int defaultColumnCount = 3;
+
+  // SpinBox to change number of row in lightBox
+  QSpinBox * rowSpinBox = new QSpinBox;
+  rowSpinBox->setRange(1, 10);
+  rowSpinBox->setSingleStep(1);
+  rowSpinBox->setValue(defaultRowCount);
+  spinBoxLayout->addWidget(rowSpinBox);
+
+  // SpinBox to change number of column in lightBox
+  QSpinBox * columnSpinBox = new QSpinBox;
+  columnSpinBox->setRange(1, 10);
+  columnSpinBox->setSingleStep(1);
+  columnSpinBox->setValue(defaultColumnCount);
+  spinBoxLayout->addWidget(columnSpinBox);
+
+  ctkVTKSliceView * sliceView = new ctkVTKSliceView;
+  sliceView->setRenderEnabled(true);
+  sliceView->setMinimumSize(600, 600);
+  sliceView->setImageData(image);
+  sliceView->lightBoxRendererManager()->SetRenderWindowLayout(defaultRowCount, defaultColumnCount);
+  sliceView->lightBoxRendererManager()->SetHighlighted(0, 0, true);
+  sliceView->setCornerAnnotationText("CTK");
+  sliceView->scheduleRender();
+  topLevelLayout->addWidget(sliceView);
+
+  // Set connection
+  QObject::connect(rowSpinBox, SIGNAL(valueChanged(int)),
+                   sliceView, SLOT(setLightBoxRendererManagerRowCount(int)));
+  QObject::connect(columnSpinBox, SIGNAL(valueChanged(int)),
+                   sliceView, SLOT(setLightBoxRendererManagerColumnCount(int)));
+
+  ctkVTKObjectEventsObserver vtkObserver;
+  vtkObserver.addConnection(sliceView->lightBoxRendererManager(), vtkCommand::ModifiedEvent,
+                            sliceView, SLOT(scheduleRender()));
+
+  widget.show();
+
+  // TODO Add image regression test
 
   if (!interactive)
     {

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

@@ -265,3 +265,17 @@ void ctkVTKSliceView::resizeEvent(QResizeEvent * event)
   emit this->resized(event->size(), event->oldSize());
 }
 
+//----------------------------------------------------------------------------
+void ctkVTKSliceView::setLightBoxRendererManagerRowCount(int newRowCount)
+{
+  CTK_D(ctkVTKSliceView);
+  d->LightBoxRendererManager->SetRenderWindowRowCount(newRowCount);
+}
+
+//----------------------------------------------------------------------------
+void ctkVTKSliceView::setLightBoxRendererManagerColumnCount(int newColumnCount)
+{
+  CTK_D(ctkVTKSliceView);
+  d->LightBoxRendererManager->SetRenderWindowColumnCount(newColumnCount);
+}
+

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

@@ -126,6 +126,14 @@ public slots:
 
   /// Set color window
   void setColorWindow(double newColorWindow);
+
+  /// Change the number of row of the associated lightBox
+  /// \sa lightBoxRendererManager()
+  void setLightBoxRendererManagerRowCount(int newRowCount);
+
+  /// Change the number of column of the associated lightBox
+  /// \sa lightBoxRendererManager()
+  void setLightBoxRendererManagerColumnCount(int newColumnCount);
   
 signals:
   void resized(const QSize& size, const QSize& oldSize);