From e2d2096e1a3a4afdad6446bf09d0e05f47d9b7eb Mon Sep 17 00:00:00 2001 From: Romulo Pinho Date: Fri, 25 Jan 2013 14:51:47 +0100 Subject: [PATCH] correct bugs related to new window/level option - also refactored to avoid similar problems in the future --- vv/vvMainWindow.cxx | 16 ++++++++-------- vv/vvSlicerManager.cxx | 21 +++++++++++---------- vv/vvSlicerManager.h | 12 ++++++++++++ vv/vvSlicerManagerCommand.cxx | 16 ++++++++-------- 4 files changed, 39 insertions(+), 26 deletions(-) diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index eb5fe7e..5c7bbfd 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -958,7 +958,7 @@ void vvMainWindow::LoadImages(std::vector files, vvImageReader::Loa double range[2]; mSlicerManagers.back()->GetImage()->GetFirstVTKImageData()->GetScalarRange(range); if ((range[0] == 0) && (range[1] == 1)) { - presetComboBox->setCurrentIndex(5);// binary + presetComboBox->setCurrentIndex(WL_BINARY);// binary } else { // TODO } @@ -1797,7 +1797,7 @@ void vvMainWindow::WindowLevelChanged() //------------------------------------------------------------------------------ void vvMainWindow::WindowLevelEdited() { - presetComboBox->setCurrentIndex(6); + presetComboBox->setCurrentIndex(WL_USER); UpdateWindowLevel(); } //------------------------------------------------------------------------------ @@ -1807,7 +1807,7 @@ void vvMainWindow::SetWindowLevel(double w, double l) { windowSpinBox->setValue(w); levelSpinBox->setValue(l); - presetComboBox->setCurrentIndex(6); + presetComboBox->setCurrentIndex(WL_USER); colorMapComboBox->setCurrentIndex(0); UpdateWindowLevel(); } @@ -1817,7 +1817,7 @@ void vvMainWindow::SetWindowLevel(double w, double l) void vvMainWindow::UpdateWindowLevel() { if (DataTree->selectedItems().size()) { - if (presetComboBox->currentIndex() == 7) //For ventilation + if (presetComboBox->currentIndex() == WL_VENTILATION) //For ventilation colorMapComboBox->setCurrentIndex(5); int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]); mSlicerManagers[index]->SetColorWindow(windowSpinBox->value()); @@ -1853,7 +1853,7 @@ void vvMainWindow::SwitchWindowLevel() { int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]); int window = mSlicerManagers[index]->GetColorWindow(); - presetComboBox->setCurrentIndex(6); + presetComboBox->setCurrentIndex(WL_USER); windowSpinBox->setValue(-window); UpdateWindowLevel(); } @@ -1872,7 +1872,7 @@ void vvMainWindow::ApplyWindowLevelToAllImages() continue; mSlicerManagers[i]->SetColorWindow(window); mSlicerManagers[i]->SetColorLevel(level); - mSlicerManagers[i]->SetPreset(6); + mSlicerManagers[i]->SetPreset(WL_USER); mSlicerManagers[i]->Render(); } } @@ -1885,7 +1885,7 @@ void vvMainWindow::ApplyWindowToSetOfImages(double window, unsigned int indexMin if (mSlicerManagers[i] == NULL) continue; mSlicerManagers[i]->SetColorWindow(window); - mSlicerManagers[i]->SetPreset(6); + mSlicerManagers[i]->SetPreset(WL_USER); mSlicerManagers[i]->Render(); } } @@ -1898,7 +1898,7 @@ void vvMainWindow::ApplyLevelToSetOfImages(double level, unsigned int indexMin, if (mSlicerManagers[i] == NULL) continue; mSlicerManagers[i]->SetColorLevel(level); - mSlicerManagers[i]->SetPreset(6); + mSlicerManagers[i]->SetPreset(WL_USER); mSlicerManagers[i]->Render(); } } diff --git a/vv/vvSlicerManager.cxx b/vv/vvSlicerManager.cxx index 5e799a0..e975da2 100644 --- a/vv/vvSlicerManager.cxx +++ b/vv/vvSlicerManager.cxx @@ -1244,45 +1244,46 @@ void vvSlicerManager::SetSlicingPreset(SlicingPresetType preset) //---------------------------------------------------------------------------- void vvSlicerManager::SetPreset(int preset) { + //vtkLookupTable* LUT = static_cast(mSlicers[0]->GetWindowLevel()->GetLookupTable()); double window = mSlicers[0]->GetColorWindow(); double level = mSlicers[0]->GetColorLevel(); std::string component_type=mImage->GetScalarTypeAsITKString(); switch (preset) { - case 0: + case WL_AUTO: double range[2]; mImage->GetScalarRange(range); window = range[1] - range[0]; level = (range[1] + range[0])* 0.5; break; - case 1: + case WL_HOUNSFIELD: window = 2000; level = 0; break; - case 2: + case WL_SOFTTISSUE: window = 400; level = 20; break; - case 3: // lungs (same as FOCAL) + case WL_LUNGS: // lungs (same as FOCAL) window = 1700; level = -300; break; - case 4: + case WL_BONES: window = 1000; level = 500; break; - case 5: + case WL_HEAD: window = 200; level = 70; break; - case 6: + case WL_BINARY: window = 1; level = 0.5; break; - case 7: + case WL_USER: break; - case 8: + case WL_VENTILATION: window=1.; level=0.; break; @@ -1332,7 +1333,7 @@ void vvSlicerManager::SetLocalColorWindowing(const int slicer, const bool bCtrlK this->mSlicers[slicer]->GetConcatenatedTransform()); this->SetColorWindow(max-min); this->SetColorLevel(0.5*(min+max)); - this->SetPreset(6); + this->SetPreset(WL_USER); } this->Render(); this->UpdateWindowLevel(); diff --git a/vv/vvSlicerManager.h b/vv/vvSlicerManager.h index d634fbd..3479dc6 100644 --- a/vv/vvSlicerManager.h +++ b/vv/vvSlicerManager.h @@ -47,6 +47,18 @@ class vvImageReader; class vvImageReader; class vvLandmarks; +enum WindowLevelPreset { + WL_AUTO, + WL_HOUNSFIELD, + WL_SOFTTISSUE, + WL_LUNGS, + WL_BONES, + WL_HEAD, + WL_BINARY, + WL_USER, + WL_VENTILATION +}; + //------------------------------------------------------------------------------ class vvSlicerManager : public QObject { Q_OBJECT diff --git a/vv/vvSlicerManagerCommand.cxx b/vv/vvSlicerManagerCommand.cxx index ad80b92..f5d2b69 100644 --- a/vv/vvSlicerManagerCommand.cxx +++ b/vv/vvSlicerManagerCommand.cxx @@ -113,33 +113,33 @@ void vvSlicerManagerCommand::Execute(vtkObject *caller, return; } if (KeyPress == "0") { - this->SM->SetPreset(0); + this->SM->SetPreset(WL_AUTO); this->SM->UpdateWindowLevel(); return; } if (KeyPress == "1") { - this->SM->SetPreset(1); + this->SM->SetPreset(WL_HOUNSFIELD); this->SM->UpdateWindowLevel(); return; } if (KeyPress == "2") { - this->SM->SetPreset(2); + this->SM->SetPreset(WL_SOFTTISSUE); this->SM->UpdateWindowLevel(); return; } if (KeyPress == "3") { - this->SM->SetPreset(3); + this->SM->SetPreset(WL_LUNGS); this->SM->UpdateWindowLevel(); return; } if (KeyPress == "4") { - this->SM->SetPreset(4); + this->SM->SetPreset(WL_BONES); this->SM->UpdateWindowLevel(); return; } if (KeyPress == "5") { - this->SM->SetPreset(5); + this->SM->SetPreset(WL_HEAD); this->SM->UpdateWindowLevel(); return; } @@ -164,7 +164,7 @@ void vvSlicerManagerCommand::Execute(vtkObject *caller, return; } if (KeyPress == "equal") { //keycodes are in vtkWin32RenderWindowInteractor - this->SM->SetPreset(7); + this->SM->SetPreset(WL_VENTILATION); //this->SM->SetColorMap(1); this->SM->UpdateWindowLevel(); return; @@ -420,7 +420,7 @@ void vvSlicerManagerCommand::Execute(vtkObject *caller, this->SM->SetColorWindow(window*dx); this->SM->SetColorLevel(level-dy); - this->SM->SetPreset(6); + this->SM->SetPreset(WL_USER); this->SM->Render(); this->SM->UpdateWindowLevel(); return; -- 2.46.1