]> Creatis software - clitk.git/commitdiff
Add interactions with window/level bars in the histogram tool
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Mon, 20 Feb 2017 15:52:52 +0000 (16:52 +0100)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Mon, 20 Feb 2017 15:52:52 +0000 (16:52 +0100)
vv/CMakeLists.txt
vv/vvToolHistogram.cxx
vv/vvToolHistogram.h
vv/vvToolHistogramCommand.cxx [new file with mode: 0644]
vv/vvToolHistogramCommand.h [new file with mode: 0644]

index 43b71a1b34bd033b9404abae504f2d9670edc35c..436dfc64449e004af7fa4a11f8c8a04f3bcd2994 100644 (file)
@@ -91,6 +91,7 @@ set(vv_SRCS
   vvGlyph2D.cxx
   vvSlicerManager.cxx
   vvSlicerManagerCommand.cxx
+  vvToolHistogramCommand.cxx
   vvUtils.cxx
 #  vvMaximumIntensityProjection.cxx 
  vvMesh.cxx
index b647fdd3abbd83004a8eebc4a744b056b5929d66..24b0864f70b59621695c02937f5f51700d644f8e 100644 (file)
@@ -27,6 +27,7 @@
 #include "vvSlicerManager.h"
 #include "vvSlicer.h"
 #include "vvToolInputSelectorWidget.h"
+#include "vvToolHistogramCommand.h"
 
 // vtk
 #include <vtkAxis.h>
@@ -79,6 +80,8 @@ vvToolHistogram::vvToolHistogram(vvMainWindowBase * parent, Qt::WindowFlags f)
   // GUI Initialization
   Ui_vvToolHistogram::setupUi(mToolWidget);
 
+  mModificationsDone = false;
+
   // Connect signals & slots
   connect(mSaveHistogramButton, SIGNAL(clicked()), this, SLOT(SaveAs()));
 
@@ -90,6 +93,7 @@ vvToolHistogram::vvToolHistogram(vvMainWindowBase * parent, Qt::WindowFlags f)
   chart->SetAutoSize(false);
   chart->SetRenderEmpty(true);
   mView->GetScene()->AddItem(chart);
+  mView->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
   this->HistogramWidget->GetRenderWindow()->GetRenderers()->RemoveAllItems();
   this->HistogramWidget->GetRenderWindow()->AddRenderer(mView->GetRenderer());
   HistogramWidget->show();
@@ -128,34 +132,16 @@ void vvToolHistogram::computeHistogram()
     mFilter->Update();
 
     //Creation of the XY chart
-    vtkSmartPointer<vtkTable> table = vtkSmartPointer<vtkTable>::New();
     vtkSmartPointer<vtkFloatArray> arrX = vtkSmartPointer<vtkFloatArray>::New();
     vtkSmartPointer<vtkFloatArray> arrY = vtkSmartPointer<vtkFloatArray>::New();
     arrX = mFilter->GetArrayX();
     arrY = mFilter->GetArrayY();
     arrX->SetName("Intensity");
     arrY->SetName("#Voxels");
-
-    table->AddColumn(arrX);
-    table->AddColumn(arrY);
-
-    mView->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
-
-    vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
-    chart->SetAutoSize(true);
-    mView->GetScene()->ClearItems();
-    mView->GetScene()->AddItem(chart);
-    vtkPlot *line = chart->AddPlot(vtkChart::LINE);
-#if VTK_MAJOR_VERSION <= 5
-    line->SetInput(table, 0, 1);
-#else
-    line->SetInputData(table, 0, 1);
-#endif
-    line->SetColor(0, 255, 0, 255);
-    line->SetWidth(1.0);
+    mTable->AddColumn(arrX);
+    mTable->AddColumn(arrY);
 
     //Upper and Lower lines for window/level
-    vtkSmartPointer<vtkTable> tableWindowLevel = vtkSmartPointer<vtkTable>::New();
     vtkSmartPointer<vtkFloatArray> arrXUpperWindowLevel = vtkSmartPointer<vtkFloatArray>::New();
     vtkSmartPointer<vtkFloatArray> arrXLowerWindowLevel = vtkSmartPointer<vtkFloatArray>::New();
     vtkSmartPointer<vtkFloatArray> arrYWindowLevel = vtkSmartPointer<vtkFloatArray>::New();
@@ -168,17 +154,44 @@ void vvToolHistogram::computeHistogram()
     arrXUpperWindowLevel->SetName("IntensityUp");
     arrXLowerWindowLevel->SetName("IntensityLow");
     arrYWindowLevel->SetName("#Voxels");
-    tableWindowLevel->AddColumn(arrXUpperWindowLevel);
-    tableWindowLevel->AddColumn(arrXLowerWindowLevel);
-    tableWindowLevel->AddColumn(arrYWindowLevel);
+    mTableWindowLevel->AddColumn(arrXUpperWindowLevel);
+    mTableWindowLevel->AddColumn(arrXLowerWindowLevel);
+    mTableWindowLevel->AddColumn(arrYWindowLevel);
+
+    displayHistogram();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolHistogram::displayHistogram()
+{
+    if (!mCurrentSlicerManager) close();
+    HistogramWidget->hide();
+
+
+    vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
+    chart->SetAutoSize(true);
+    mView->GetScene()->ClearItems();
+    mView->GetScene()->AddItem(chart);
+    vtkPlot *line = chart->AddPlot(vtkChart::LINE);
+#if VTK_MAJOR_VERSION <= 5
+    line->SetInput(mTable, 0, 1);
+#else
+    line->SetInputData(mTable, 0, 1);
+#endif
+    line->SetColor(0, 255, 0, 255);
+    line->SetWidth(1.0);
+
+
     vtkPlot *upperWindowLine = chart->AddPlot(vtkChart::LINE);
     vtkPlot *lowerWindowLine = chart->AddPlot(vtkChart::LINE);
 #if VTK_MAJOR_VERSION <= 5
-    upperWindowLine->SetInput(tableWindowLevel, 0, 2);
-    lowerWindowLine->SetInput(tableWindowLevel, 1, 2);
+    upperWindowLine->SetInput(mTableWindowLevel, 0, 2);
+    lowerWindowLine->SetInput(mTableWindowLevel, 1, 2);
 #else
-    upperWindowLine->SetInputData(tableWindowLevel, 0, 2);
-    lowerWindowLine->SetInputData(tableWindowLevel, 1, 2);
+    upperWindowLine->SetInputData(mTableWindowLevel, 0, 2);
+    lowerWindowLine->SetInputData(mTableWindowLevel, 1, 2);
 #endif
     upperWindowLine->SetColor(255, 0, 0, 255);
     lowerWindowLine->SetColor(255, 0, 0, 255);
@@ -192,25 +205,25 @@ void vvToolHistogram::computeHistogram()
     this->HistogramWidget->GetRenderWindow()->AddRenderer(mView->GetRenderer());
     HistogramWidget->show();
 
-    //mView->GetInteractor()->Start();
-
     QApplication::restoreOverrideCursor();
 }
 //------------------------------------------------------------------------------
 
+
 //------------------------------------------------------------------------------
 void vvToolHistogram::changeWindowLevel()
 {
-  vtkChartXY* chart = vtkChartXY::New();
-  chart = static_cast<vtkChartXY*>(mView->GetScene()->GetItem(0));
   vtkFloatArray* upperArray = vtkFloatArray::New();
-  upperArray = static_cast<vtkFloatArray*>(chart->GetPlot(1)->GetInput()->GetColumn(0));
+  upperArray = static_cast<vtkFloatArray*>(mTableWindowLevel->GetColumn(0));
   upperArray->SetTuple1(0, mMaxWindowLevel);
   upperArray->SetTuple1(1, mMaxWindowLevel);
   vtkFloatArray* lowerArray = vtkFloatArray::New();
-  lowerArray = static_cast<vtkFloatArray*>(chart->GetPlot(2)->GetInput()->GetColumn(1));
+  lowerArray = static_cast<vtkFloatArray*>(mTableWindowLevel->GetColumn(1));
   lowerArray->SetTuple1(0, mMinWindowLevel);
   lowerArray->SetTuple1(1, mMinWindowLevel);
+  displayHistogram();
+  mCurrentSlicerManager->UpdateWindowLevel();
+  mCurrentSlicerManager->Render();
 }
 //------------------------------------------------------------------------------
 
@@ -227,12 +240,6 @@ void vvToolHistogram::windowLevelChanged()
 //------------------------------------------------------------------------------
 void vvToolHistogram::RemoveVTKObjects()
 { 
-  if (mCurrentSlicerManager)
-  {
-    connect(mCurrentSlicerManager, SIGNAL(callAddLandmark(float,float,float,float)), mCurrentSlicerManager, SLOT(AddLandmark(float,float,float,float)));
-
-    mCurrentSlicerManager->Render();
-  }
 }
 //------------------------------------------------------------------------------
 
@@ -240,8 +247,13 @@ void vvToolHistogram::RemoveVTKObjects()
 //------------------------------------------------------------------------------
 bool vvToolHistogram::close()
 { 
-  //RemoveVTKObjects();
-
+  if (!mModificationsDone)
+  {
+    mCurrentSlicerManager->SetColorLevel(originalLevel);
+    mCurrentSlicerManager->SetColorWindow(originalWindow);
+    mCurrentSlicerManager->UpdateWindowLevel();
+    mCurrentSlicerManager->Render();
+  }
   return vvToolWidgetBase::close();
 }
 //------------------------------------------------------------------------------
@@ -274,12 +286,34 @@ void vvToolHistogram::InputIsSelected(vvSlicerManager * m)
   mSaveHistogramButton->setEnabled(true);
   mTextFileName = "Histogram.txt";
 
+  mTableWindowLevel = vtkSmartPointer<vtkTable>::New();
+  mTable = vtkSmartPointer<vtkTable>::New();
+
+  originalWindow = mCurrentSlicerManager->GetColorWindow();
+  originalLevel = mCurrentSlicerManager->GetColorLevel();
+
   //Compute Min & Max for Window/Level
   computeMinMax();
 
   computeHistogram();
 
-  disconnect(mCurrentSlicerManager, SIGNAL(callAddLandmark(float,float,float,float)), mCurrentSlicerManager, SLOT(AddLandmark(float,float,float,float)));
+  // Connect signals & slots
+  vvToolHistogramCommand *smc = vvToolHistogramCommand::New();
+  smc->mHist = this;
+  HistogramWidget->GetRenderWindow()->GetInteractor()->GetInteractorStyle()->AddObserver(vtkCommand::LeftButtonPressEvent, smc);
+  HistogramWidget->GetRenderWindow()->GetInteractor()->GetInteractorStyle()->AddObserver(vtkCommand::MouseMoveEvent, smc);
+  HistogramWidget->GetRenderWindow()->GetInteractor()->GetInteractorStyle()->AddObserver(vtkCommand::MouseWheelForwardEvent, smc);
+  HistogramWidget->GetRenderWindow()->GetInteractor()->GetInteractorStyle()->AddObserver(vtkCommand::MouseWheelBackwardEvent, smc);
+  smc->Delete();
+
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+QVTKWidget* vvToolHistogram::GetHistogramWidget()
+{
+  return(HistogramWidget);
 }
 //------------------------------------------------------------------------------
 
@@ -302,6 +336,36 @@ void vvToolHistogram::computeWindowLevel()
 //------------------------------------------------------------------------------
 
 
+//------------------------------------------------------------------------------
+void vvToolHistogram::expandWindow()
+{
+  mCurrentSlicerManager->SetColorWindow(mCurrentSlicerManager->GetColorWindow()+10.0);
+  computeMinMax();
+  changeWindowLevel();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolHistogram::reduceWindow()
+{
+  mCurrentSlicerManager->SetColorWindow(mCurrentSlicerManager->GetColorWindow()-10.0);
+  computeMinMax();
+  changeWindowLevel();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolHistogram::translateWindow(double x)
+{
+  mCurrentSlicerManager->SetColorLevel(mCurrentSlicerManager->GetColorLevel()+10.0*x);
+  computeMinMax();
+  changeWindowLevel();
+}
+//------------------------------------------------------------------------------
+
+
 //------------------------------------------------------------------------------
 void vvToolHistogram::GetArgsInfoFromGUI()
 { 
@@ -333,7 +397,8 @@ void vvToolHistogram::GetArgsInfoFromGUI()
 
 //------------------------------------------------------------------------------
 void vvToolHistogram::apply()
-{ 
+{
+  mModificationsDone = true;
   close();
 }
 //------------------------------------------------------------------------------
index d81aee7d1bc558daacf22336bb94b1142daf0038..ce58d079d62cdabebe1b981c7529b461911f7c6b 100644 (file)
@@ -30,6 +30,8 @@
 #include <vtkTable.h>
 #include <vtkContextView.h>
 #include <vtkContextScene.h>
+#include <vtkInteractorObserver.h>
+#include <vtkEventQtSlotConnect.h>
 
 //------------------------------------------------------------------------------
 class vvToolHistogram:
@@ -53,12 +55,20 @@ class vvToolHistogram:
   void computeMinMax();
   void SetPoints();
 
+  void displayHistogram();
+
+  QVTKWidget* GetHistogramWidget();
+
   //-----------------------------------------------------
   public slots:
   virtual void apply();
   virtual bool close();
   virtual void reject();
-  virtual void windowLevelChanged();
+
+  void windowLevelChanged();
+  void reduceWindow();
+  void expandWindow();
+  void translateWindow(double x);
 
   void SaveAs();
 
@@ -70,8 +80,15 @@ class vvToolHistogram:
 
   double mMinWindowLevel;
   double mMaxWindowLevel;
+  double originalWindow;
+  double originalLevel;
+  bool mModificationsDone;
 
   vtkSmartPointer<vtkContextView> mView;
+
+  vtkSmartPointer<vtkTable> mTableWindowLevel;
+  vtkSmartPointer<vtkTable> mTable;
+  //vtkSmartPointer<vtkContextView> mView;
   clitk::HistogramImageGenericFilter::Pointer mFilter;
   std::string mTextFileName;
 
diff --git a/vv/vvToolHistogramCommand.cxx b/vv/vvToolHistogramCommand.cxx
new file mode 100644 (file)
index 0000000..585f16c
--- /dev/null
@@ -0,0 +1,73 @@
+/*=========================================================================
+  Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
+
+  Authors belong to:
+  - University of LYON              http://www.universite-lyon.fr/
+  - Léon Bérard cancer center       http://www.centreleonberard.fr
+  - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
+
+  This software is distributed WITHOUT ANY WARRANTY; without even
+  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+  PURPOSE.  See the copyright notices for more information.
+
+  It is distributed under dual licence
+
+  - BSD        See included LICENSE.txt file
+  - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================**/
+#include "vvToolHistogramCommand.h"
+#include "vvSlicerManager.h"
+
+#include <vtkTextProperty.h>
+#include <vtkRenderer.h>
+#include <vtkImageActor.h>
+#include <vtkRenderWindowInteractor.h>
+#include <vtkPropPicker.h>
+#include <vtkCamera.h>
+#include <vtkImageMapToWindowLevelColors.h>
+#include <vtkLookupTable.h>
+#include <vtkMath.h>
+#include <vtkAbstractPropPicker.h>
+#include <vtkAssemblyPath.h>
+#include <vtkCornerAnnotation.h>
+#include <vtkRenderWindow.h>
+#include <vvImage.h>
+#include <vtkImageReslice.h>
+#include "vvSlicer.h"
+#include "vvInteractorStyleNavigator.h"
+#include "vtkTransform.h"
+
+#include <cmath>
+//------------------------------------------------------------------------------
+vvToolHistogramCommand::vvToolHistogramCommand()
+{
+  mFollowMouse = false;
+}
+//------------------------------------------------------------------------------
+
+
+
+
+//------------------------------------------------------------------------------
+void vvToolHistogramCommand::Execute(vtkObject *caller,
+                                     unsigned long event,
+                                     void *vtkNotUsed(callData))
+{
+  if (event == vtkCommand::MouseWheelForwardEvent) {
+    mHist->expandWindow();
+  }
+  if (event == vtkCommand::MouseWheelBackwardEvent) {
+    mHist->reduceWindow();
+  }
+  if (event == vtkCommand::LeftButtonPressEvent) {
+    mFollowMouse = !mFollowMouse;
+  }
+  if (event == vtkCommand::MouseMoveEvent) {
+    if (mFollowMouse) {
+      vtkSmartPointer<vtkRenderWindowInteractor> interactor = mHist->GetHistogramWidget()->GetRenderWindow()->GetInteractor();
+      if (interactor->GetEventPosition()[0] != interactor->GetLastEventPosition()[0])
+        mHist->translateWindow(interactor->GetEventPosition()[0] - interactor->GetLastEventPosition()[0]);
+    }
+  }
+}
+//------------------------------------------------------------------------------
diff --git a/vv/vvToolHistogramCommand.h b/vv/vvToolHistogramCommand.h
new file mode 100644 (file)
index 0000000..0a73dbe
--- /dev/null
@@ -0,0 +1,56 @@
+/*=========================================================================
+  Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
+
+  Authors belong to: 
+  - University of LYON              http://www.universite-lyon.fr/
+  - Léon Bérard cancer center       http://www.centreleonberard.fr
+  - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
+
+  This software is distributed WITHOUT ANY WARRANTY; without even
+  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+  PURPOSE.  See the copyright notices for more information.
+
+  It is distributed under dual licence
+
+  - BSD        See included LICENSE.txt file
+  - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================**/
+#ifndef __vvToolHistogramCommand_h
+#define __vvToolHistogramCommand_h
+#include "vtkCommand.h"
+#include "vvSlicerManager.h"
+#include "vvToolHistogram.h"
+#include "vtkRenderWindow.h"
+#include "vtkRenderer.h"
+#include "vtkImageData.h"
+#include "vtkImageActor.h"
+#include "vvInteractorStyleNavigator.h"
+#include "vtkRenderWindowInteractor.h"
+#include "vtkInteractorStyleImage.h"
+#include "vtkPropPicker.h"
+
+#include <iostream>
+#include <string>
+#include <sstream>
+
+class vvToolHistogramCommand : public vtkCommand
+{
+public:
+    static vvToolHistogramCommand *New() {
+        return new vvToolHistogramCommand;
+    }
+
+    void Execute(vtkObject *caller,
+                 unsigned long event,
+                 void *vtkNotUsed(callData));
+
+    vvToolHistogram* mHist;
+
+protected :
+    vvToolHistogramCommand();
+    ~vvToolHistogramCommand() {}
+
+    bool mFollowMouse;
+};
+
+#endif