From e2e07b38fd3916b7e26991b19cb2ce7342408c73 Mon Sep 17 00:00:00 2001 From: tbaudier Date: Wed, 15 Feb 2017 17:09:34 +0100 Subject: [PATCH] Add window/level lines in histogram tool --- vv/vvToolHistogram.cxx | 96 ++++++++++++++++++++++++++++++++++++++---- vv/vvToolHistogram.h | 7 +++ 2 files changed, 95 insertions(+), 8 deletions(-) diff --git a/vv/vvToolHistogram.cxx b/vv/vvToolHistogram.cxx index e9418c4..b647fdd 100644 --- a/vv/vvToolHistogram.cxx +++ b/vv/vvToolHistogram.cxx @@ -84,7 +84,7 @@ vvToolHistogram::vvToolHistogram(vvMainWindowBase * parent, Qt::WindowFlags f) // Initialize some widget HistogramWidget->hide(); - + mView = vtkSmartPointer::New(); vtkSmartPointer chart = vtkSmartPointer::New(); chart->SetAutoSize(false); @@ -121,12 +121,12 @@ void vvToolHistogram::computeHistogram() QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); GetArgsInfoFromGUI(); HistogramWidget->hide(); - + // Main filter mFilter->SetInputVVImage(mCurrentImage); mFilter->SetArgsInfo(mArgsInfo); mFilter->Update(); - + //Creation of the XY chart vtkSmartPointer table = vtkSmartPointer::New(); vtkSmartPointer arrX = vtkSmartPointer::New(); @@ -135,12 +135,12 @@ void vvToolHistogram::computeHistogram() 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 chart = vtkSmartPointer::New(); chart->SetAutoSize(true); mView->GetScene()->ClearItems(); @@ -153,17 +153,76 @@ void vvToolHistogram::computeHistogram() #endif line->SetColor(0, 255, 0, 255); line->SetWidth(1.0); + + //Upper and Lower lines for window/level + vtkSmartPointer tableWindowLevel = vtkSmartPointer::New(); + vtkSmartPointer arrXUpperWindowLevel = vtkSmartPointer::New(); + vtkSmartPointer arrXLowerWindowLevel = vtkSmartPointer::New(); + vtkSmartPointer arrYWindowLevel = vtkSmartPointer::New(); + arrXUpperWindowLevel->InsertNextTuple1(mMaxWindowLevel); + arrXUpperWindowLevel->InsertNextTuple1(mMaxWindowLevel); + arrXLowerWindowLevel->InsertNextTuple1(mMinWindowLevel); + arrXLowerWindowLevel->InsertNextTuple1(mMinWindowLevel); + arrYWindowLevel->InsertNextTuple1(0.0); + arrYWindowLevel->InsertNextTuple1(arrY->GetMaxNorm()); + arrXUpperWindowLevel->SetName("IntensityUp"); + arrXLowerWindowLevel->SetName("IntensityLow"); + arrYWindowLevel->SetName("#Voxels"); + tableWindowLevel->AddColumn(arrXUpperWindowLevel); + tableWindowLevel->AddColumn(arrXLowerWindowLevel); + tableWindowLevel->AddColumn(arrYWindowLevel); + 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); +#else + upperWindowLine->SetInputData(tableWindowLevel, 0, 2); + lowerWindowLine->SetInputData(tableWindowLevel, 1, 2); +#endif + upperWindowLine->SetColor(255, 0, 0, 255); + lowerWindowLine->SetColor(255, 0, 0, 255); + upperWindowLine->SetWidth(1.0); + lowerWindowLine->SetWidth(1.0); + chart->GetAxis(vtkAxis::LEFT)->SetTitle("#Voxels"); chart->GetAxis(vtkAxis::BOTTOM)->SetTitle("Intensity"); - + this->HistogramWidget->GetRenderWindow()->GetRenderers()->RemoveAllItems(); this->HistogramWidget->GetRenderWindow()->AddRenderer(mView->GetRenderer()); HistogramWidget->show(); - + + //mView->GetInteractor()->Start(); + QApplication::restoreOverrideCursor(); } //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +void vvToolHistogram::changeWindowLevel() +{ + vtkChartXY* chart = vtkChartXY::New(); + chart = static_cast(mView->GetScene()->GetItem(0)); + vtkFloatArray* upperArray = vtkFloatArray::New(); + upperArray = static_cast(chart->GetPlot(1)->GetInput()->GetColumn(0)); + upperArray->SetTuple1(0, mMaxWindowLevel); + upperArray->SetTuple1(1, mMaxWindowLevel); + vtkFloatArray* lowerArray = vtkFloatArray::New(); + lowerArray = static_cast(chart->GetPlot(2)->GetInput()->GetColumn(1)); + lowerArray->SetTuple1(0, mMinWindowLevel); + lowerArray->SetTuple1(1, mMinWindowLevel); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvToolHistogram::windowLevelChanged() +{ + computeMinMax(); + changeWindowLevel(); +} +//------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ void vvToolHistogram::RemoveVTKObjects() @@ -215,6 +274,9 @@ void vvToolHistogram::InputIsSelected(vvSlicerManager * m) mSaveHistogramButton->setEnabled(true); mTextFileName = "Histogram.txt"; + //Compute Min & Max for Window/Level + computeMinMax(); + computeHistogram(); disconnect(mCurrentSlicerManager, SIGNAL(callAddLandmark(float,float,float,float)), mCurrentSlicerManager, SLOT(AddLandmark(float,float,float,float))); @@ -222,6 +284,24 @@ void vvToolHistogram::InputIsSelected(vvSlicerManager * m) //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +void vvToolHistogram::computeMinMax() +{ + mMinWindowLevel = mCurrentSlicerManager->GetColorLevel() - mCurrentSlicerManager->GetColorWindow()/2.0; + mMaxWindowLevel = mCurrentSlicerManager->GetColorLevel() + mCurrentSlicerManager->GetColorWindow()/2.0; +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvToolHistogram::computeWindowLevel() +{ + double window = mMaxWindowLevel - mMinWindowLevel; + double level = (mMaxWindowLevel + mMinWindowLevel)/2.0; +} +//------------------------------------------------------------------------------ + + //------------------------------------------------------------------------------ void vvToolHistogram::GetArgsInfoFromGUI() { diff --git a/vv/vvToolHistogram.h b/vv/vvToolHistogram.h index c567862..d81aee7 100644 --- a/vv/vvToolHistogram.h +++ b/vv/vvToolHistogram.h @@ -48,6 +48,9 @@ class vvToolHistogram: virtual void InputIsSelected(vvSlicerManager * m); void computeHistogram(); + void changeWindowLevel(); + void computeWindowLevel(); + void computeMinMax(); void SetPoints(); //----------------------------------------------------- @@ -55,6 +58,7 @@ class vvToolHistogram: virtual void apply(); virtual bool close(); virtual void reject(); + virtual void windowLevelChanged(); void SaveAs(); @@ -64,6 +68,9 @@ class vvToolHistogram: Ui::vvToolHistogram ui; args_info_clitkHistogramImage mArgsInfo; + double mMinWindowLevel; + double mMaxWindowLevel; + vtkSmartPointer mView; clitk::HistogramImageGenericFilter::Pointer mFilter; std::string mTextFileName; -- 2.47.1