#include "vvSlicerManager.h"
#include "vvSlicer.h"
#include "vvToolInputSelectorWidget.h"
+#include "vvToolHistogramCommand.h"
// vtk
#include <vtkAxis.h>
// GUI Initialization
Ui_vvToolHistogram::setupUi(mToolWidget);
+ mModificationsDone = false;
+
// Connect signals & slots
connect(mSaveHistogramButton, SIGNAL(clicked()), this, SLOT(SaveAs()));
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();
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();
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);
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();
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void vvToolHistogram::RemoveVTKObjects()
{
- if (mCurrentSlicerManager)
- {
- connect(mCurrentSlicerManager, SIGNAL(callAddLandmark(float,float,float,float)), mCurrentSlicerManager, SLOT(AddLandmark(float,float,float,float)));
-
- mCurrentSlicerManager->Render();
- }
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
bool vvToolHistogram::close()
{
- //RemoveVTKObjects();
-
+ if (!mModificationsDone)
+ {
+ mCurrentSlicerManager->SetColorLevel(originalLevel);
+ mCurrentSlicerManager->SetColorWindow(originalWindow);
+ mCurrentSlicerManager->UpdateWindowLevel();
+ mCurrentSlicerManager->Render();
+ }
return vvToolWidgetBase::close();
}
//------------------------------------------------------------------------------
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);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+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()
{
//------------------------------------------------------------------------------
void vvToolHistogram::apply()
-{
+{
+ mModificationsDone = true;
close();
}
//------------------------------------------------------------------------------
--- /dev/null
+/*=========================================================================
+ 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]);
+ }
+ }
+}
+//------------------------------------------------------------------------------