From 0a85e47a06c7d046d06a4645b724c4e81b19998d Mon Sep 17 00:00:00 2001 From: dsarrut Date: Wed, 24 Feb 2010 11:42:40 +0000 Subject: [PATCH] - toolbase --- CMakeLists.txt | 7 +- vv/CMakeLists.txt | 11 + vv/qt_ui/vvToolCropImage.ui | 127 ++++++ vv/qt_ui/vvToolFoo.ui | 49 ++ vv/qt_ui/vvToolWidgetBase.ui | 52 +++ vv/vvImageContour.cxx | 21 +- vv/vvImageContour.h | 5 +- vv/vvIntensityValueSlider.cxx | 14 +- vv/vvMainWindow.cxx | 204 +++++---- vv/vvMainWindow.h | 27 +- vv/vvMainWindowBase.cxx | 30 ++ vv/vvMainWindowBase.h | 63 +++ vv/vvSlicerManagerCommand.cxx | 752 ++++++++++++++++--------------- vv/vvToolBase.h | 102 +---- vv/vvToolBase.txx | 45 ++ vv/vvToolBinarize.cxx | 84 ++-- vv/vvToolBinarize.h | 40 +- vv/vvToolCreator.h | 60 +++ vv/vvToolCreator.txx | 45 ++ vv/vvToolCreatorBase.cxx | 28 +- vv/vvToolCreatorBase.h | 49 +- vv/vvToolCreatorBase.txx | 36 +- vv/vvToolCropImage.cxx | 64 +++ vv/vvToolCropImage.h | 78 ++++ vv/vvToolFoo.cxx | 63 +++ vv/vvToolFoo.h | 57 +++ vv/vvToolInputSelectorWidget.cxx | 7 +- vv/vvToolInputSelectorWidget.h | 7 +- vv/vvToolManager.cxx | 23 +- vv/vvToolManager.h | 27 +- vv/vvToolWidgetBase.cxx | 132 ++++++ vv/vvToolWidgetBase.h | 71 +++ 32 files changed, 1610 insertions(+), 770 deletions(-) create mode 100644 vv/qt_ui/vvToolCropImage.ui create mode 100644 vv/qt_ui/vvToolFoo.ui create mode 100644 vv/qt_ui/vvToolWidgetBase.ui create mode 100644 vv/vvMainWindowBase.cxx create mode 100644 vv/vvMainWindowBase.h create mode 100644 vv/vvToolBase.txx create mode 100644 vv/vvToolCreator.h create mode 100644 vv/vvToolCreator.txx create mode 100644 vv/vvToolCropImage.cxx create mode 100644 vv/vvToolCropImage.h create mode 100644 vv/vvToolFoo.cxx create mode 100644 vv/vvToolFoo.h create mode 100644 vv/vvToolWidgetBase.cxx create mode 100644 vv/vvToolWidgetBase.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 164b7d7..2e121c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,9 +7,10 @@ if(COMMAND cmake_policy) endif(COMMAND cmake_policy) PROJECT(clitk) #========================================================= -IF(CMAKE_COMPILER_IS_GNUCXX) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") -ENDIF(CMAKE_COMPILER_IS_GNUCXX) +#IF(CMAKE_COMPILER_IS_GNUCXX) +# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") +# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ") +#ENDIF(CMAKE_COMPILER_IS_GNUCXX) IF(MSVC) ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS) ENDIF(MSVC) diff --git a/vv/CMakeLists.txt b/vv/CMakeLists.txt index 8404ae2..8797f8c 100644 --- a/vv/CMakeLists.txt +++ b/vv/CMakeLists.txt @@ -73,6 +73,7 @@ SET(vv_SRCS vvResamplerDialog.cxx vvSegmentationDialog.cxx vvSurfaceViewerDialog.cxx + vvMainWindowBase.cxx vvMainWindow.cxx vvDeformationDialog.cxx vvImageWarp.cxx @@ -102,12 +103,16 @@ SET(vv_SRCS vvIntensityValueSlider.cxx vvToolManager.cxx vvToolCreatorBase.cxx + vvToolWidgetBase.cxx + vvToolFoo.cxx + vvToolCropImage.cxx vvToolBinarize.cxx vvToolInputSelectorWidget.cxx vvImageContour.cxx ) QT4_WRAP_CPP(vv_SRCS + vvMainWindowBase.h vvMainWindow.h QTreePushButton.h vvInfoPanel.h @@ -127,8 +132,11 @@ QT4_WRAP_CPP(vv_SRCS vvCropDialog.h vvIntensityValueSlider.h vvToolCreatorBase.h + vvToolFoo.h vvToolBinarize.h vvToolInputSelectorWidget.h + vvToolWidgetBase.h + vvToolCropImage.h ) QT4_WRAP_UI(vv_UI_CXX @@ -149,6 +157,9 @@ QT4_WRAP_UI(vv_UI_CXX qt_ui/vvCropDialog.ui qt_ui/vvDummyWindow.ui #For testing qt_ui/vvIntensityValueSlider.ui + qt_ui/vvToolWidgetBase.ui + qt_ui/vvToolFoo.ui + qt_ui/vvToolCropImage.ui qt_ui/vvToolBinarize.ui qt_ui/vvToolInputSelectorWidget.ui ) diff --git a/vv/qt_ui/vvToolCropImage.ui b/vv/qt_ui/vvToolCropImage.ui new file mode 100644 index 0000000..e7c0619 --- /dev/null +++ b/vv/qt_ui/vvToolCropImage.ui @@ -0,0 +1,127 @@ + + + vvToolCropImage + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + X min + + + + + + + Qt::Horizontal + + + + + + + X max + + + + + + + Qt::Horizontal + + + + + + + Y min + + + + + + + Qt::Horizontal + + + + + + + Y max + + + + + + + Qt::Horizontal + + + + + + + Z min + + + + + + + Qt::Horizontal + + + + + + + Z max + + + + + + + Qt::Horizontal + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vv/qt_ui/vvToolFoo.ui b/vv/qt_ui/vvToolFoo.ui new file mode 100644 index 0000000..9748f2b --- /dev/null +++ b/vv/qt_ui/vvToolFoo.ui @@ -0,0 +1,49 @@ + + + vvToolFoo + + + + 0 + 0 + 358 + 213 + + + + Form + + + + + 150 + 90 + 75 + 23 + + + + Foo ! + + + + + + + pushButton + clicked() + vvToolFoo + close() + + + 220 + 135 + + + 100 + -18 + + + + + diff --git a/vv/qt_ui/vvToolWidgetBase.ui b/vv/qt_ui/vvToolWidgetBase.ui new file mode 100644 index 0000000..0effdb5 --- /dev/null +++ b/vv/qt_ui/vvToolWidgetBase.ui @@ -0,0 +1,52 @@ + + + vvToolWidgetBase + + + + 0 + 0 + 615 + 372 + + + + Form + + + + + + Qt::Vertical + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + splitter + buttonBox + mToolInputSelectionWidget + groupBox + + + + vvToolInputSelectorWidget + QWidget +
vvToolInputSelectorWidget.h
+ 1 +
+
+ + +
diff --git a/vv/vvImageContour.cxx b/vv/vvImageContour.cxx index 63df2cb..85a9f2b 100644 --- a/vv/vvImageContour.cxx +++ b/vv/vvImageContour.cxx @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvImageContour.cxx,v $ Language: C++ - Date: $Date: 2010/02/07 12:00:59 $ - Version: $Revision: 1.2 $ + Date: $Date: 2010/02/24 11:42:42 $ + Version: $Revision: 1.3 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2010 @@ -76,15 +76,30 @@ void vvImageContour::setSlicer(vvSlicer * slicer) { mSquaresActorList.push_back(mSquaresActor); mSquaresList.push_back(mSquares); mClipperList.push_back(mClipper); - } //mSquares->Update(); } //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +void vvImageContour::removeActors() { + // DD("removeActors"); + if (!mSlicer) return; + mSlice = mSlicer->GetSlice(); + // DD(mSlice); + for(unsigned int i=0; iVisibilityOff(); + //mSquaresActorList[i]->Update(); + } +} +//------------------------------------------------------------------------------ + + //------------------------------------------------------------------------------ void vvImageContour::update(int value) { + // DD(value); + if (!mSlicer) return; mSlice = mSlicer->GetSlice(); // Only change actor visibility if tslice change diff --git a/vv/vvImageContour.h b/vv/vvImageContour.h index 0e9a943..be96b05 100644 --- a/vv/vvImageContour.h +++ b/vv/vvImageContour.h @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvImageContour.h,v $ Language: C++ - Date: $Date: 2010/02/07 12:00:59 $ - Version: $Revision: 1.2 $ + Date: $Date: 2010/02/24 11:42:42 $ + Version: $Revision: 1.3 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2010 @@ -50,6 +50,7 @@ class vvImageContour void setSlicer(vvSlicer * slicer); // vtkActor * getActor() { return mSquaresActor;} void update(int value); + void removeActors(); protected: vvSlicer * mSlicer; diff --git a/vv/vvIntensityValueSlider.cxx b/vv/vvIntensityValueSlider.cxx index 82d9258..55ae8f2 100644 --- a/vv/vvIntensityValueSlider.cxx +++ b/vv/vvIntensityValueSlider.cxx @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvIntensityValueSlider.cxx,v $ Language: C++ - Date: $Date: 2010/02/07 12:00:59 $ - Version: $Revision: 1.2 $ + Date: $Date: 2010/02/24 11:42:42 $ + Version: $Revision: 1.3 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2008 @@ -120,9 +120,9 @@ void vvIntensityValueSlider::SetMinimum(double min) { //------------------------------------------------------------------------------ void vvIntensityValueSlider::Update() { - DD(mImage->GetScalarTypeAsString()); - DD(mImage->GetFirstVTKImageData()->GetScalarTypeMax()); - DD(mImage->GetFirstVTKImageData()->GetScalarTypeMin()); + // DD(mImage->GetScalarTypeAsString()); +// DD(mImage->GetFirstVTKImageData()->GetScalarTypeMax()); +// DD(mImage->GetFirstVTKImageData()->GetScalarTypeMin()); // double max = mImage->GetFirstVTKImageData()->GetScalarTypeMax(); // double min = mImage->GetFirstVTKImageData()->GetScalarTypeMin(); @@ -137,8 +137,8 @@ void vvIntensityValueSlider::Update() { mImage->GetFirstVTKImageData()->GetScalarRange(range); mMin = range[0]; mMax = range[1]; - DD(mMax); - DD(mMin); + // DD(mMax); +// DD(mMin); mSlider->setMaximum(mMax); mSlider->setMinimum(mMin); mSpinBox->setMaximum(mMax); diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index f55ebea..924bf19 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvMainWindow.cxx,v $ Language: C++ - Date: $Date: 2010/02/17 20:52:39 $ - Version: $Revision: 1.11 $ + Date: $Date: 2010/02/24 11:42:42 $ + Version: $Revision: 1.12 $ Author : Pierre Seroul (pierre.seroul@gmail.com) Copyright (C) 200COLUMN_IMAGE_NAME @@ -56,6 +56,7 @@ #include "vvMeshReader.h" #include "vvCropDialog.h" #include "vvConstants.h" + #ifdef CLITK_VV_USE_BDCM #include #endif @@ -107,11 +108,12 @@ 5,Qt::UserRole mSlicerManager id*/ //------------------------------------------------------------------------------ -vvMainWindow::vvMainWindow() { +vvMainWindow::vvMainWindow():vvMainWindowBase() { setupUi(this); // this sets up the GUI mInputPathName = ""; - mCurrentToolInfo = 0; + mMenuTools = menuTools; + mMainWidget = this; //Init the contextMenu this->setContextMenuPolicy(Qt::CustomContextMenu); @@ -166,7 +168,6 @@ vvMainWindow::vvMainWindow() { connect(actionAdd_fusion_image,SIGNAL(triggered()),this,SLOT(AddFusionImage())); contextActions.push_back(actionAdd_fusion_image); - //init the DataTree mSlicerManagers.resize(0); @@ -319,7 +320,7 @@ vvMainWindow::vvMainWindow() { } // Adding all new tools (insertion in the menu) - vvToolManager::GetInstance()->Initialize(this); + vvToolManager::GetInstance()->InsertToolsInMenu(this); } //------------------------------------------------------------------------------ @@ -360,7 +361,10 @@ void vvMainWindow::ComputeMidPosition() QApplication::restoreOverrideCursor(); } } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvMainWindow::AddContour(int image_index, vvMesh::Pointer contour, bool propagation) { QTreeWidgetItem *item = new QTreeWidgetItem(); @@ -404,6 +408,8 @@ void vvMainWindow::AddContour(int image_index, vvMesh::Pointer contour, bool pro mSlicerManagers[image_index]->AddContour(contour,propagation); mSlicerManagers[image_index]->Render(); } +//------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ void vvMainWindow::OpenVTKContour() @@ -425,6 +431,9 @@ void vvMainWindow::OpenVTKContour() QApplication::restoreOverrideCursor(); } } +//------------------------------------------------------------------------------ + + //------------------------------------------------------------------------------ void vvMainWindow::OpenDCStructContour() { @@ -458,6 +467,8 @@ void vvMainWindow::OpenDCStructContour() } } } +//------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ void vvMainWindow::ComputeDeformableRegistration() @@ -477,6 +488,8 @@ void vvMainWindow::ComputeDeformableRegistration() } else QMessageBox::information(this, "Need to open image","You must open an image first."); } +//------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ void vvMainWindow::WarpImage() @@ -495,6 +508,8 @@ void vvMainWindow::WarpImage() else QMessageBox::warning(this,tr("No vector field"),tr("Sorry, can't warp without a vector field")); } +//------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ void vvMainWindow::WarpImage(vvSlicerManager* selected_slicer,int reference_phase) @@ -521,6 +536,8 @@ void vvMainWindow::WarpImage(vvSlicerManager* selected_slicer,int reference_phas else QMessageBox::warning(this,tr("No vector field"),tr("Sorry, can't warp without a vector field.")); } +//------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ vvMainWindow::~vvMainWindow() { @@ -532,6 +549,7 @@ vvMainWindow::~vvMainWindow() { } //------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ void vvMainWindow::MergeImages() { QString Extensions = EXTENSIONS; @@ -596,6 +614,7 @@ void vvMainWindow::MergeImages() { } //------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ void vvMainWindow::MergeImagesWithTime() { QString Extensions = EXTENSIONS; @@ -668,6 +687,7 @@ void vvMainWindow::MergeImagesWithTime() { } //------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ void vvMainWindow::OpenDicom() { std::vector files; @@ -873,9 +893,6 @@ void vvMainWindow::LoadImages(std::vector files, LoadedImageType fi } QApplication::restoreOverrideCursor(); - - // vvToolManager::GetInstance()->UpdateEnabledTool(); - // emit SlicerManagersHasChanged(); } //------------------------------------------------------------------------------ @@ -1076,69 +1093,69 @@ void vvMainWindow::ImageInfoChanged() { presetComboBox->setCurrentIndex(mSlicerManagers[index]->GetPreset()); colorMapComboBox->setCurrentIndex(mSlicerManagers[index]->GetColorMap()); - infoPanel->setFileName(image); - infoPanel->setDimension(dim); - infoPanel->setSizePixel(GetVectorIntAsString(inputSize)); - infoPanel->setSizeMM(GetVectorDoubleAsString(sizeMM)); - infoPanel->setOrigin(GetVectorDoubleAsString(origin)); - infoPanel->setSpacing(GetVectorDoubleAsString(inputSpacing)); - infoPanel->setNPixel(QString::number(NPixel)+" ("+inputSizeInBytes+")"); - - landmarksPanel->SetCurrentLandmarks(mSlicerManagers[index]->GetLandmarks(), - mSlicerManagers[index]->GetSlicer(0)->GetImage()->GetVTKImages().size()); - landmarksPanel->SetCurrentPath(mInputPathName.toStdString()); - landmarksPanel->SetCurrentImage(mSlicerManagers[index]->GetFileName().c_str()); - - overlayPanel->getCurrentImageName(mSlicerManagers[index]->GetFileName().c_str()); - for (int i = 0; i < 4;i++) - { - if (DataTree->selectedItems()[0]->data(i+1,Qt::CheckStateRole).toInt() > 0 || i == 3) - { - mSlicerManagers[index]->UpdateInfoOnCursorPosition(i); - break; - } - } - windowSpinBox->setValue(mSlicerManagers[index]->GetColorWindow()); - levelSpinBox->setValue(mSlicerManagers[index]->GetColorLevel()); - presetComboBox->setCurrentIndex(mSlicerManagers[index]->GetPreset()); - colorMapComboBox->setCurrentIndex(mSlicerManagers[index]->GetColorMap()); + infoPanel->setFileName(image); + infoPanel->setDimension(dim); + infoPanel->setSizePixel(GetVectorIntAsString(inputSize)); + infoPanel->setSizeMM(GetVectorDoubleAsString(sizeMM)); + infoPanel->setOrigin(GetVectorDoubleAsString(origin)); + infoPanel->setSpacing(GetVectorDoubleAsString(inputSpacing)); + infoPanel->setNPixel(QString::number(NPixel)+" ("+inputSizeInBytes+")"); - if (mSlicerManagers[index]->GetSlicer(0)->GetVF()) - { - overlayPanel->getVFName(mSlicerManagers[index]->GetVFName().c_str()); - overlayPanel->getVFProperty(mSlicerManagers[index]->GetSlicer(0)->GetVFSubSampling(), - mSlicerManagers[index]->GetSlicer(0)->GetVFScale(), - mSlicerManagers[index]->GetSlicer(0)->GetVFLog()); - } - else - { - overlayPanel->getVFName(mSlicerManagers[index]->GetVFName().c_str()); - overlayPanel->getVFProperty(-1,-1,-1); - } - if (mSlicerManagers[index]->GetSlicer(0)->GetOverlay()) - { - overlayPanel->getOverlayName(mSlicerManagers[index]->GetOverlayName().c_str()); - overlayPanel->getOverlayProperty(mSlicerManagers[index]->GetOverlayColor()); - } - else - { - overlayPanel->getOverlayName(mSlicerManagers[index]->GetOverlayName().c_str()); - overlayPanel->getOverlayProperty(-1); - } - if (mSlicerManagers[index]->GetSlicer(0)->GetFusion()) - { - overlayPanel->getFusionName(mSlicerManagers[index]->GetFusionName().c_str()); - overlayPanel->getFusionProperty(mSlicerManagers[index]->GetFusionOpacity(), - mSlicerManagers[index]->GetFusionColorMap(), - mSlicerManagers[index]->GetFusionWindow(), - mSlicerManagers[index]->GetFusionLevel()); - } - else - { - overlayPanel->getFusionName(mSlicerManagers[index]->GetFusionName().c_str()); - overlayPanel->getFusionProperty(-1, -1,-1,-1); - } - } + landmarksPanel->SetCurrentLandmarks(mSlicerManagers[index]->GetLandmarks(), + mSlicerManagers[index]->GetSlicer(0)->GetImage()->GetVTKImages().size()); + landmarksPanel->SetCurrentPath(mInputPathName.toStdString()); + landmarksPanel->SetCurrentImage(mSlicerManagers[index]->GetFileName().c_str()); + + overlayPanel->getCurrentImageName(mSlicerManagers[index]->GetFileName().c_str()); + for (int i = 0; i < 4;i++) + { + if (DataTree->selectedItems()[0]->data(i+1,Qt::CheckStateRole).toInt() > 0 || i == 3) + { + mSlicerManagers[index]->UpdateInfoOnCursorPosition(i); + break; + } + } + windowSpinBox->setValue(mSlicerManagers[index]->GetColorWindow()); + levelSpinBox->setValue(mSlicerManagers[index]->GetColorLevel()); + presetComboBox->setCurrentIndex(mSlicerManagers[index]->GetPreset()); + colorMapComboBox->setCurrentIndex(mSlicerManagers[index]->GetColorMap()); + + if (mSlicerManagers[index]->GetSlicer(0)->GetVF()) + { + overlayPanel->getVFName(mSlicerManagers[index]->GetVFName().c_str()); + overlayPanel->getVFProperty(mSlicerManagers[index]->GetSlicer(0)->GetVFSubSampling(), + mSlicerManagers[index]->GetSlicer(0)->GetVFScale(), + mSlicerManagers[index]->GetSlicer(0)->GetVFLog()); + } + else + { + overlayPanel->getVFName(mSlicerManagers[index]->GetVFName().c_str()); + overlayPanel->getVFProperty(-1,-1,-1); + } + if (mSlicerManagers[index]->GetSlicer(0)->GetOverlay()) + { + overlayPanel->getOverlayName(mSlicerManagers[index]->GetOverlayName().c_str()); + overlayPanel->getOverlayProperty(mSlicerManagers[index]->GetOverlayColor()); + } + else + { + overlayPanel->getOverlayName(mSlicerManagers[index]->GetOverlayName().c_str()); + overlayPanel->getOverlayProperty(-1); + } + if (mSlicerManagers[index]->GetSlicer(0)->GetFusion()) + { + overlayPanel->getFusionName(mSlicerManagers[index]->GetFusionName().c_str()); + overlayPanel->getFusionProperty(mSlicerManagers[index]->GetFusionOpacity(), + mSlicerManagers[index]->GetFusionColorMap(), + mSlicerManagers[index]->GetFusionWindow(), + mSlicerManagers[index]->GetFusionLevel()); + } + else + { + overlayPanel->getFusionName(mSlicerManagers[index]->GetFusionName().c_str()); + overlayPanel->getFusionProperty(-1, -1,-1,-1); + } + } } //------------------------------------------------------------------------------ @@ -1488,6 +1505,10 @@ void vvMainWindow::CloseImage(QTreeWidgetItem* item, int column) { msgBox.addButton(tr("Cancel"), QMessageBox::RejectRole); if (msgBox.exec() == QMessageBox::AcceptRole) { + + // Tell tools that we close an image + emit AnImageIsBeingClosed(mSlicerManagers[index]); + std::vector::iterator Manageriter = mSlicerManagers.begin(); DataTree->takeTopLevelItem(index); for (int i = 0; i < index; i++) @@ -1498,25 +1519,24 @@ void vvMainWindow::CloseImage(QTreeWidgetItem* item, int column) { mSlicerManagers[index]->RemoveActors(); delete mSlicerManagers[index]; mSlicerManagers.erase(Manageriter); + + // InitDisplay(); } } - - // vvToolManager::GetInstance()->UpdateEnabledTool(); - // emit SlicerManagersHasChanged(); } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ void vvMainWindow::ReloadImage(QTreeWidgetItem* item, int column) { // int index = GetSlicerIndexFromItem(item); -// QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); -// if (item->data(1,Qt::UserRole).toString() == "vector") -// mSlicerManagers[index]->ReloadVF(); -// else -// mSlicerManagers[index]->Reload(); + // QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + // if (item->data(1,Qt::UserRole).toString() == "vector") + // mSlicerManagers[index]->ReloadVF(); + // else + // mSlicerManagers[index]->Reload(); -// QApplication::restoreOverrideCursor(); + // QApplication::restoreOverrideCursor(); int index = GetSlicerIndexFromItem(item); QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QString role=item->data(1,Qt::UserRole).toString(); @@ -2330,7 +2350,7 @@ void vvMainWindow::NOVerticalSliderChanged() { if (DataTree->topLevelItem(i)->data(COLUMN_UL_VIEW,Qt::CheckStateRole).toInt() > 1) { mSlicerManagers[i]->GetSlicer(0)->SetSlice(value); - // mSlicerManagers[i]->UpdateSlice(0); // <-- too much update... + //mSlicerManagers[i]->UpdateSlice(0); // <-- NO ! too much update... break; } } @@ -2381,8 +2401,10 @@ void vvMainWindow::SEVerticalSliderChanged() { //------------------------------------------------------------------------------ void vvMainWindow::UpdateSlice(int slicer, int slice) { - if (slicer == 0) - NOVerticalSlider->setValue(slice); + if (slicer == 0) { + if (slice != NOVerticalSlider->value()) + NOVerticalSlider->setValue(slice); + } else if (slicer == 1) NEVerticalSlider->setValue(slice); else if (slicer == 2) @@ -2744,20 +2766,13 @@ void vvMainWindow::AddImage(vvSlicerManager * slicer_manager) { ShowLastImage(); InitDisplay(); qApp->processEvents(); - - // vvToolManager::GetInstance()->UpdateEnabledTool(); - // emit SlicerManagersHasChanged(); } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ -vvMainWindowToolInfo * vvMainWindow::GetInfoForTool() { - DD("GetInfoForTool"); - if (mCurrentToolInfo ==0) mCurrentToolInfo = new vvMainWindowToolInfo; - - mCurrentToolInfo->mMenuTools = menuTools; - mCurrentToolInfo->mSlicerManagers = &mSlicerManagers; +void vvMainWindow::UpdateCurrentSlicer() { + DD("UpdateCurrentSlicer"); int index = -1; DD(DataTree->selectedItems().size()); if (DataTree->selectedItems().size() > 0) { @@ -2765,10 +2780,7 @@ vvMainWindowToolInfo * vvMainWindow::GetInfoForTool() { DD(DataTree->selectedItems()[0]); DD(index); } - mCurrentToolInfo->mSlicerManagerCurrentIndex = index; - - return mCurrentToolInfo; + mSlicerManagerCurrentIndex = index; } //------------------------------------------------------------------------------ - diff --git a/vv/vvMainWindow.h b/vv/vvMainWindow.h index b3d6031..d929374 100644 --- a/vv/vvMainWindow.h +++ b/vv/vvMainWindow.h @@ -29,12 +29,10 @@ GNU General Public License for more details. #include #include "ui_vvMainWindow.h" - +#include "vvMainWindowBase.h" +#include "vvToolManager.h" #include "vvConstants.h" -#include "vvImage.h" #include "vvMesh.h" -#include "vvToolManager.h" -#include "clitkCommon.h" class vvSlicerManager; class vvHelpDialog; @@ -45,16 +43,8 @@ class vtkRenderer; class vvDicomSeriesSelector; //------------------------------------------------------------------------------ -struct vvMainWindowToolInfo { - QMenu * mMenuTools; - std::vector * mSlicerManagers; - int mSlicerManagerCurrentIndex; -}; -//------------------------------------------------------------------------------ - - -//------------------------------------------------------------------------------ -class vvMainWindow : public QMainWindow, private Ui::vvMainWindow +class vvMainWindow: public vvMainWindowBase, + private Ui::vvMainWindow { Q_OBJECT @@ -71,7 +61,9 @@ class vvMainWindow : public QMainWindow, private Ui::vvMainWindow ///This is used to show an image when opened or computed void ShowLastImage(); - vvMainWindowToolInfo * GetInfoForTool(); + virtual void UpdateCurrentSlicer(); + //vvMainWindowToolInfo * GetInfoForTool(); +// void AddRunningTool(vvToolCreatorBase * tool); public slots: ///Allows the user to open and select various surfaces contained in a dicom-struct file @@ -165,7 +157,7 @@ public slots: private: //variables - std::vector mSlicerManagers; + // std::vector mSlicerManagers; vvHelpDialog *help_dialog; vvDocumentation *documentation; vvDicomSeriesSelector *dicomSeriesSelector; @@ -197,7 +189,8 @@ private: std::vector verticalSliders; int mFrameRate; - vvMainWindowToolInfo * mCurrentToolInfo; + // vvMainWindowToolInfo * mCurrentToolInfo; + // std::vector mListOfRunningTool; static vvMainWindow * mSingleton; }; diff --git a/vv/vvMainWindowBase.cxx b/vv/vvMainWindowBase.cxx new file mode 100644 index 0000000..c7b58f7 --- /dev/null +++ b/vv/vvMainWindowBase.cxx @@ -0,0 +1,30 @@ +/*========================================================================= + + Program: vv + Module: $RCSfile: vvMainWindowBase.cxx,v $ + Language: C++ + Date: $Date: 2010/02/24 11:43:37 $ + Version: $Revision: 1.1 $ + Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) + + Copyright (C) 2010 + Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + CREATIS-LRMN http://www.creatis.insa-lyon.fr + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + =========================================================================*/ + +#include "vvMainWindowBase.h" + + diff --git a/vv/vvMainWindowBase.h b/vv/vvMainWindowBase.h new file mode 100644 index 0000000..1c10d5e --- /dev/null +++ b/vv/vvMainWindowBase.h @@ -0,0 +1,63 @@ +/*========================================================================= + + Program: vv + Module: $RCSfile: vvMainWindowBase.h,v $ + Language: C++ + Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) + +Copyright (C) 2010 +Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr +CREATIS-LRMN http://www.creatis.insa-lyon.fr + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 3 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + =========================================================================*/ + +#ifndef VVMAINWINDOWBASE_H +#define VVMAINWINDOWBASE_H + +#include "clitkCommon.h" +#include "vvImage.h" +#include + +class vvSlicerManager; +class QMenu; + +//------------------------------------------------------------------------------ +class vvMainWindowBase : public QMainWindow +{ + Q_OBJECT + +public: + vvMainWindowBase() { mSlicerManagerCurrentIndex = -1; } + ~vvMainWindowBase() { } + + virtual void AddImage(vvImage::Pointer image,std::string filename) = 0; + virtual void UpdateCurrentSlicer() = 0; + const std::vector & GetSlicerManagers() const { return mSlicerManagers; } + QMenu * GetMenu() const { return mMenuTools; } + int GetSlicerManagerCurrentIndex() const { return mSlicerManagerCurrentIndex; } + QWidget * GetMainWidget() { return mMainWidget; } + +signals: + void AnImageIsBeingClosed(vvSlicerManager *); + +protected: + std::vector mSlicerManagers; + QMenu * mMenuTools; + int mSlicerManagerCurrentIndex; + QWidget* mMainWidget; +}; +//------------------------------------------------------------------------------ + +#endif diff --git a/vv/vvSlicerManagerCommand.cxx b/vv/vvSlicerManagerCommand.cxx index f42ab28..6e3298b 100644 --- a/vv/vvSlicerManagerCommand.cxx +++ b/vv/vvSlicerManagerCommand.cxx @@ -1,26 +1,26 @@ /*========================================================================= -Program: vv -Language: C++ -Author : Pierre Seroul (pierre.seroul@gmail.com) + Program: vv + Language: C++ + Author : Pierre Seroul (pierre.seroul@gmail.com) -Copyright (C) 2008 -Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr -CREATIS-LRMN http://www.creatis.insa-lyon.fr + Copyright (C) 2008 + Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + CREATIS-LRMN http://www.creatis.insa-lyon.fr -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, version 3 of the License. + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 3 of the License. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . + You should have received a copy of the GNU General Public License + along with this program. If not, see . -=========================================================================*/ + =========================================================================*/ #include "vvSlicerManagerCommand.h" #include "vvSlicerManager.h" @@ -43,523 +43,533 @@ along with this program. If not, see . #include +//------------------------------------------------------------------------------ vvSlicerManagerCallback::vvSlicerManagerCallback() { - mStartSlicer = -1; + mStartSlicer = -1; } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ //return the num of the current slicer if visible (-1 else) int vvSlicerManagerCallback::FindSlicerNumber(vtkRenderWindow* renwin) { - int result=-1; - for (int i = 0; i < SM->NumberOfSlicers(); i++) + int result=-1; + for (int i = 0; i < SM->NumberOfSlicers(); i++) { - if (SM->GetSlicer(i)->GetRenderWindow() == renwin - && SM->GetSlicer(i)->GetRenderer()->GetDraw()) + if (SM->GetSlicer(i)->GetRenderWindow() == renwin + && SM->GetSlicer(i)->GetRenderer()->GetDraw()) { - DD(i); - result=i; + // DD(i); + result=i; } } - return result; + return result; } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvSlicerManagerCallback::Execute(vtkObject *caller, - unsigned long event, - void *vtkNotUsed(callData)) + unsigned long event, + void *vtkNotUsed(callData)) { - //KeyPress event - vvInteractorStyleNavigator *isi = - dynamic_cast(caller); - if (isi) + //KeyPress event + vvInteractorStyleNavigator *isi = + dynamic_cast(caller); + if (isi) { - double x = isi->GetInteractor()->GetEventPosition()[0]; - double y = isi->GetInteractor()->GetEventPosition()[1]; - double z; + double x = isi->GetInteractor()->GetEventPosition()[0]; + double y = isi->GetInteractor()->GetEventPosition()[1]; + double z; - int VisibleInWindow = this->FindSlicerNumber(isi->GetInteractor()->GetRenderWindow()); - vtkRenderer* renderer=NULL; - if (VisibleInWindow>-1) - renderer=this->SM->GetSlicer(VisibleInWindow)->GetRenderer(); - newLandmark = false; + int VisibleInWindow = this->FindSlicerNumber(isi->GetInteractor()->GetRenderWindow()); + vtkRenderer* renderer=NULL; + if (VisibleInWindow>-1) + renderer=this->SM->GetSlicer(VisibleInWindow)->GetRenderer(); + newLandmark = false; - if (event == vtkCommand::StartPickEvent && VisibleInWindow == -1) + if (event == vtkCommand::StartPickEvent && VisibleInWindow == -1) { - for (int i = 0; i < this->SM->NumberOfSlicers(); i++) + for (int i = 0; i < this->SM->NumberOfSlicers(); i++) { - if (this->SM->GetSlicer(i)->GetCursorVisibility()) + if (this->SM->GetSlicer(i)->GetCursorVisibility()) { - this->SM->GetSlicer(i)->SetCursorVisibility(0); - this->SM->GetSlicer(i)->Render(); + this->SM->GetSlicer(i)->SetCursorVisibility(0); + this->SM->GetSlicer(i)->Render(); } } } - if ( VisibleInWindow > -1 ) + if ( VisibleInWindow > -1 ) { - if (event == vtkCommand::KeyPressEvent) + if (event == vtkCommand::KeyPressEvent) { - std::string KeyPress = isi->GetInteractor()->GetKeySym(); - if (KeyPress == "f" || KeyPress == "F") + std::string KeyPress = isi->GetInteractor()->GetKeySym(); + if (KeyPress == "f" || KeyPress == "F") { - FlyToPosition(isi->GetInteractor(),this->SM->GetSlicer(VisibleInWindow)); + FlyToPosition(isi->GetInteractor(),this->SM->GetSlicer(VisibleInWindow)); } - if (KeyPress == "0") + if (KeyPress == "0") { - this->SM->SetPreset(0); - this->SM->UpdateWindowLevel(); - return; + this->SM->SetPreset(0); + this->SM->UpdateWindowLevel(); + return; } - if (KeyPress == "1") + if (KeyPress == "1") { - this->SM->SetPreset(1); - this->SM->UpdateWindowLevel(); - return; + this->SM->SetPreset(1); + this->SM->UpdateWindowLevel(); + return; } - if (KeyPress == "2") + if (KeyPress == "2") { - this->SM->SetPreset(2); - this->SM->UpdateWindowLevel(); + this->SM->SetPreset(2); + this->SM->UpdateWindowLevel(); - return; + return; } - if (KeyPress == "3") + if (KeyPress == "3") { - this->SM->SetPreset(3); - this->SM->UpdateWindowLevel(); - return; + this->SM->SetPreset(3); + this->SM->UpdateWindowLevel(); + return; } - if (KeyPress == "4") + if (KeyPress == "4") { - this->SM->SetPreset(4); - this->SM->UpdateWindowLevel(); - return; + this->SM->SetPreset(4); + this->SM->UpdateWindowLevel(); + return; } - if (KeyPress == "5") + if (KeyPress == "5") { - this->SM->SetPreset(5); - this->SM->UpdateWindowLevel(); - return; + this->SM->SetPreset(5); + this->SM->UpdateWindowLevel(); + return; } - if (KeyPress == "6") + if (KeyPress == "6") { - this->SM->SetColorMap(0); - this->SM->UpdateWindowLevel(); - return; + this->SM->SetColorMap(0); + this->SM->UpdateWindowLevel(); + return; } - if (KeyPress == "7") + if (KeyPress == "7") { - this->SM->SetColorMap(1); - this->SM->UpdateWindowLevel(); - return; + this->SM->SetColorMap(1); + this->SM->UpdateWindowLevel(); + return; } - if (KeyPress == "8") + if (KeyPress == "8") { - this->SM->SetColorMap(2); - this->SM->UpdateWindowLevel(); - return; + this->SM->SetColorMap(2); + this->SM->UpdateWindowLevel(); + return; } - if (KeyPress == "9") + if (KeyPress == "9") { - this->SM->SetColorMap(3); - this->SM->UpdateWindowLevel(); - return; + this->SM->SetColorMap(3); + this->SM->UpdateWindowLevel(); + return; } - if (KeyPress == "equal") //keycodes are in vtkWin32RenderWindowInteractor + if (KeyPress == "equal") //keycodes are in vtkWin32RenderWindowInteractor { - this->SM->SetPreset(7); - //this->SM->SetColorMap(1); - this->SM->UpdateWindowLevel(); - return; + this->SM->SetPreset(7); + //this->SM->SetColorMap(1); + this->SM->UpdateWindowLevel(); + return; } - if (KeyPress == "minus") + if (KeyPress == "minus") { - std::cout << "KeyPress : - " << std::endl; - this->SM->SetColorWindow(-this->SM->GetColorWindow()); - this->SM->SetColorMap(-1); - this->SM->UpdateWindowLevel(); - return; + std::cout << "KeyPress : - " << std::endl; + this->SM->SetColorWindow(-this->SM->GetColorWindow()); + this->SM->SetColorMap(-1); + this->SM->UpdateWindowLevel(); + return; } - if (KeyPress == "u") + if (KeyPress == "u") { - this->SM->ToggleContourSuperposition(); - this->SM->Render(); - return; + this->SM->ToggleContourSuperposition(); + this->SM->Render(); + return; } - if (KeyPress == "i") + if (KeyPress == "i") { - this->SM->ToggleInterpolation(); - this->SM->Render(); - return; + this->SM->ToggleInterpolation(); + this->SM->Render(); + return; } - if (KeyPress == "h") + if (KeyPress == "h") { - this->SM->SetCursorVisibility(0); - this->SM->Render(); - return; + this->SM->SetCursorVisibility(0); + this->SM->Render(); + return; } - if (KeyPress == "l") + if (KeyPress == "l") { - this->SM->Reload(); - this->SM->Render(); - return; + this->SM->Reload(); + this->SM->Render(); + return; } - if (KeyPress == "r" || KeyPress=="R") + if (KeyPress == "r" || KeyPress=="R") { - this->SM->GetSlicer(VisibleInWindow)->ResetCamera(); - this->SM->GetSlicer(VisibleInWindow)->Render(); - return; + this->SM->GetSlicer(VisibleInWindow)->ResetCamera(); + this->SM->GetSlicer(VisibleInWindow)->Render(); + return; } - if (KeyPress == "g") + if (KeyPress == "g") { - double* cursorPos = this->SM->GetSlicer(VisibleInWindow)->GetCursorPosition(); - this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition( - cursorPos[0],cursorPos[1],cursorPos[2],cursorPos[3]); - this->SM->UpdateViews(1,VisibleInWindow); - this->SM->UpdateLinked(VisibleInWindow); - return; + double* cursorPos = this->SM->GetSlicer(VisibleInWindow)->GetCursorPosition(); + this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition( + cursorPos[0],cursorPos[1],cursorPos[2],cursorPos[3]); + this->SM->UpdateViews(1,VisibleInWindow); + this->SM->UpdateLinked(VisibleInWindow); + return; } - if (KeyPress == "F5") + if (KeyPress == "F5") { - this->SM->GetSlicer(VisibleInWindow)->FlipHorizontalView(); - this->SM->GetSlicer(VisibleInWindow)->Render(); - return; + this->SM->GetSlicer(VisibleInWindow)->FlipHorizontalView(); + this->SM->GetSlicer(VisibleInWindow)->Render(); + return; } - if (KeyPress == "F6") + if (KeyPress == "F6") { - this->SM->GetSlicer(VisibleInWindow)->FlipVerticalView(); - this->SM->GetSlicer(VisibleInWindow)->Render(); - return; + this->SM->GetSlicer(VisibleInWindow)->FlipVerticalView(); + this->SM->GetSlicer(VisibleInWindow)->Render(); + return; } - if (KeyPress == "Up") + if (KeyPress == "Up") { - this->SM->GetSlicer(VisibleInWindow)->SetSlice(this->SM->GetSlicer(VisibleInWindow)->GetSlice()+1); - this->SM->UpdateSlice(VisibleInWindow); - this->SM->UpdateInfoOnCursorPosition(VisibleInWindow); + this->SM->GetSlicer(VisibleInWindow)->SetSlice(this->SM->GetSlicer(VisibleInWindow)->GetSlice()+1); + this->SM->UpdateSlice(VisibleInWindow); + this->SM->UpdateInfoOnCursorPosition(VisibleInWindow); } - if (KeyPress == "Down") + if (KeyPress == "Down") { - this->SM->GetSlicer(VisibleInWindow)->SetSlice(this->SM->GetSlicer(VisibleInWindow)->GetSlice()-1); - this->SM->UpdateSlice(VisibleInWindow); - this->SM->UpdateInfoOnCursorPosition(VisibleInWindow); + this->SM->GetSlicer(VisibleInWindow)->SetSlice(this->SM->GetSlicer(VisibleInWindow)->GetSlice()-1); + this->SM->UpdateSlice(VisibleInWindow); + this->SM->UpdateInfoOnCursorPosition(VisibleInWindow); } - if (KeyPress == "space") + if (KeyPress == "space") { - newLandmark = true; + newLandmark = true; } - if (KeyPress == "Left") - this->SM->SetPreviousTSlice(VisibleInWindow); - if (KeyPress == "Right") - this->SM->SetNextTSlice(VisibleInWindow); + if (KeyPress == "Left") + this->SM->SetPreviousTSlice(VisibleInWindow); + if (KeyPress == "Right") + this->SM->SetNextTSlice(VisibleInWindow); - if (KeyPress == "F1") + if (KeyPress == "F1") { - this->SM->GetSlicer(VisibleInWindow)->GetAnnotation()->SetText(2,"Sagital\n"); - this->SM->GetSlicer(VisibleInWindow)->SetSliceOrientation(0); - this->SM->UpdateSliceRange(VisibleInWindow); - this->SM->UpdateInfoOnCursorPosition(VisibleInWindow); + this->SM->GetSlicer(VisibleInWindow)->GetAnnotation()->SetText(2,"Sagital\n"); + this->SM->GetSlicer(VisibleInWindow)->SetSliceOrientation(0); + this->SM->UpdateSliceRange(VisibleInWindow); + this->SM->UpdateInfoOnCursorPosition(VisibleInWindow); } - if (KeyPress == "F2") + if (KeyPress == "F2") { - this->SM->GetSlicer(VisibleInWindow)->GetAnnotation()->SetText(2,"Coronal\n"); - this->SM->GetSlicer(VisibleInWindow)->SetSliceOrientation(1); - this->SM->UpdateSliceRange(VisibleInWindow); - this->SM->UpdateInfoOnCursorPosition(VisibleInWindow); + this->SM->GetSlicer(VisibleInWindow)->GetAnnotation()->SetText(2,"Coronal\n"); + this->SM->GetSlicer(VisibleInWindow)->SetSliceOrientation(1); + this->SM->UpdateSliceRange(VisibleInWindow); + this->SM->UpdateInfoOnCursorPosition(VisibleInWindow); } - if (KeyPress == "F3") + if (KeyPress == "F3") { - this->SM->GetSlicer(VisibleInWindow)->GetAnnotation()->SetText(2,"Axial\n"); - this->SM->GetSlicer(VisibleInWindow)->SetSliceOrientation(2); - this->SM->UpdateSliceRange(VisibleInWindow); - this->SM->UpdateInfoOnCursorPosition(VisibleInWindow); + this->SM->GetSlicer(VisibleInWindow)->GetAnnotation()->SetText(2,"Axial\n"); + this->SM->GetSlicer(VisibleInWindow)->SetSliceOrientation(2); + this->SM->UpdateSliceRange(VisibleInWindow); + this->SM->UpdateInfoOnCursorPosition(VisibleInWindow); } } - //All type of mouse events - if (event == vtkCommand::LeaveEvent) + //All type of mouse events + if (event == vtkCommand::LeaveEvent) { - this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(-VTK_DOUBLE_MAX,-VTK_DOUBLE_MAX, - -VTK_DOUBLE_MAX,this->SM->GetSlicer(VisibleInWindow)->GetTSlice()); - this->SM->GetSlicer(VisibleInWindow)->Render(); - return; + this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(-VTK_DOUBLE_MAX,-VTK_DOUBLE_MAX, + -VTK_DOUBLE_MAX,this->SM->GetSlicer(VisibleInWindow)->GetTSlice()); + this->SM->GetSlicer(VisibleInWindow)->Render(); + return; } - if (event == vtkCommand::StartWindowLevelEvent) + if (event == vtkCommand::StartWindowLevelEvent) { - mStartSlicer = -1; - this->InitialWindow = this->SM->GetColorWindow(); - this->InitialLevel = this->SM->GetColorLevel(); + mStartSlicer = -1; + this->InitialWindow = this->SM->GetColorWindow(); + this->InitialLevel = this->SM->GetColorLevel(); - if (VisibleInWindow > -1) + if (VisibleInWindow > -1) { - mStartSlicer = VisibleInWindow; + mStartSlicer = VisibleInWindow; } - return; + return; } - if (event == vtkCommand::EndWindowLevelEvent) + if (event == vtkCommand::EndWindowLevelEvent) { - mStartSlicer = -1; + mStartSlicer = -1; } } - if (VisibleInWindow > -1) + if (VisibleInWindow > -1) { - this->SM->Activated(); - //if(!this->SM->GetSlicer(VisibleInWindow)->GetAnnotation()->GetVisibility()) - this->SM->GetSlicer(VisibleInWindow)->GetAnnotation()->SetVisibility(1); + this->SM->Activated(); + //if(!this->SM->GetSlicer(VisibleInWindow)->GetAnnotation()->GetVisibility()) + this->SM->GetSlicer(VisibleInWindow)->GetAnnotation()->SetVisibility(1); - if (event == vtkCommand::MouseWheelForwardEvent && !isi->GetInteractor()->GetControlKey()) + if (event == vtkCommand::MouseWheelForwardEvent && !isi->GetInteractor()->GetControlKey()) { - this->SM->GetSlicer(VisibleInWindow)->SetSlice(this->SM->GetSlicer(VisibleInWindow)->GetSlice()+1); - this->SM->UpdateSlice(VisibleInWindow); - this->SM->UpdateInfoOnCursorPosition(VisibleInWindow); + this->SM->GetSlicer(VisibleInWindow)->SetSlice(this->SM->GetSlicer(VisibleInWindow)->GetSlice()+1); + this->SM->UpdateSlice(VisibleInWindow); + this->SM->UpdateInfoOnCursorPosition(VisibleInWindow); } - else if (event == vtkCommand::MouseWheelForwardEvent && isi->GetInteractor()->GetControlKey()) + else if (event == vtkCommand::MouseWheelForwardEvent && isi->GetInteractor()->GetControlKey()) { - double factor = 2; - this->Dolly(pow((double)1.1, factor),isi->GetInteractor()); + double factor = 2; + this->Dolly(pow((double)1.1, factor),isi->GetInteractor()); } - else if (event == vtkCommand::MouseWheelBackwardEvent && !isi->GetInteractor()->GetControlKey()) + else if (event == vtkCommand::MouseWheelBackwardEvent && !isi->GetInteractor()->GetControlKey()) { - this->SM->GetSlicer(VisibleInWindow)->SetSlice(this->SM->GetSlicer(VisibleInWindow)->GetSlice()-1); - this->SM->UpdateSlice(VisibleInWindow); - this->SM->UpdateInfoOnCursorPosition(VisibleInWindow); + this->SM->GetSlicer(VisibleInWindow)->SetSlice(this->SM->GetSlicer(VisibleInWindow)->GetSlice()-1); + this->SM->UpdateSlice(VisibleInWindow); + this->SM->UpdateInfoOnCursorPosition(VisibleInWindow); } - else if (event == vtkCommand::MouseWheelBackwardEvent && isi->GetInteractor()->GetControlKey()) + else if (event == vtkCommand::MouseWheelBackwardEvent && isi->GetInteractor()->GetControlKey()) { - double factor = -2; - this->Dolly(pow((double)1.1, factor),isi->GetInteractor()); + double factor = -2; + this->Dolly(pow((double)1.1, factor),isi->GetInteractor()); } - double xWorld=0; double yWorld=0; double zWorld=0; - - //Move into World Coordinate - renderer->DisplayToNormalizedDisplay(x,y); - renderer->NormalizedDisplayToViewport(x,y); - renderer->ViewportToNormalizedViewport(x,y); - renderer->NormalizedViewportToView(x,y,z); - renderer->ViewToWorld(x,y,z); - switch (this->SM->GetSlicer(VisibleInWindow)->GetSliceOrientation()) + double xWorld=0; double yWorld=0; double zWorld=0; + + //Move into World Coordinate + renderer->DisplayToNormalizedDisplay(x,y); + renderer->NormalizedDisplayToViewport(x,y); + renderer->ViewportToNormalizedViewport(x,y); + renderer->NormalizedViewportToView(x,y,z); + renderer->ViewToWorld(x,y,z); + switch (this->SM->GetSlicer(VisibleInWindow)->GetSliceOrientation()) { case vtkImageViewer2::SLICE_ORIENTATION_XY: - xWorld = x; - yWorld = y; - zWorld = this->SM->GetSlicer(VisibleInWindow)->GetSlice()* - this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetSpacing()[2] + - this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetOrigin()[2]; - break; + xWorld = x; + yWorld = y; + zWorld = this->SM->GetSlicer(VisibleInWindow)->GetSlice()* + this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetSpacing()[2] + + this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetOrigin()[2]; + break; case vtkImageViewer2::SLICE_ORIENTATION_XZ: - xWorld = x; - yWorld = this->SM->GetSlicer(VisibleInWindow)->GetSlice()* - this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetSpacing()[1] + - this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetOrigin()[1]; - zWorld = z; - break; + xWorld = x; + yWorld = this->SM->GetSlicer(VisibleInWindow)->GetSlice()* + this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetSpacing()[1] + + this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetOrigin()[1]; + zWorld = z; + break; case vtkImageViewer2::SLICE_ORIENTATION_YZ: - xWorld = this->SM->GetSlicer(VisibleInWindow)->GetSlice()* - this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetSpacing()[0] + - this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetOrigin()[0]; - yWorld = y; - zWorld = z; - break; + xWorld = this->SM->GetSlicer(VisibleInWindow)->GetSlice()* + this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetSpacing()[0] + + this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetOrigin()[0]; + yWorld = y; + zWorld = z; + break; } - this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(xWorld,yWorld,zWorld, - this->SM->GetSlicer(VisibleInWindow)->GetTSlice()); - if (newLandmark) + this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(xWorld,yWorld,zWorld, + this->SM->GetSlicer(VisibleInWindow)->GetTSlice()); + if (newLandmark) { - this->SM->AddLandmark(xWorld,yWorld,zWorld, - this->SM->GetSlicer(VisibleInWindow)->GetTSlice()); - this->SM->GetSlicer(VisibleInWindow)->UpdateLandmarks(); - this->SM->Render(); + this->SM->AddLandmark(xWorld,yWorld,zWorld, + this->SM->GetSlicer(VisibleInWindow)->GetTSlice()); + this->SM->GetSlicer(VisibleInWindow)->UpdateLandmarks(); + this->SM->Render(); } - if (event == vtkCommand::PickEvent || event == vtkCommand::StartPickEvent) + if (event == vtkCommand::PickEvent || event == vtkCommand::StartPickEvent) { - this->SM->UpdateViews(1,VisibleInWindow); - this->SM->UpdateLinked(VisibleInWindow); - this->SM->UpdateInfoOnCursorPosition(VisibleInWindow); + this->SM->UpdateViews(1,VisibleInWindow); + this->SM->UpdateLinked(VisibleInWindow); + this->SM->UpdateInfoOnCursorPosition(VisibleInWindow); } - else + else { - this->SM->GetSlicer(VisibleInWindow)->Render(); + this->SM->GetSlicer(VisibleInWindow)->Render(); } - //this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(-VTK_DOUBLE_MAX,-VTK_DOUBLE_MAX, - //-VTK_DOUBLE_MAX,this->SM->GetSlicer(VisibleInWindow)->GetTSlice()); - //this->SM->GetSlicer(VisibleInWindow)->Render(); + //this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(-VTK_DOUBLE_MAX,-VTK_DOUBLE_MAX, + //-VTK_DOUBLE_MAX,this->SM->GetSlicer(VisibleInWindow)->GetTSlice()); + //this->SM->GetSlicer(VisibleInWindow)->Render(); } - if (event == vtkCommand::WindowLevelEvent && mStartSlicer > -1) + if (event == vtkCommand::WindowLevelEvent && mStartSlicer > -1) { - this->SM->GetSlicer(mStartSlicer)->GetAnnotation()->SetVisibility(1); - // Adjust the window level here - int *size = isi->GetInteractor()->GetRenderWindow()->GetSize(); - double window = this->InitialWindow; - double level = this->InitialLevel; - double range[2]; - this->SM->GetImage()->GetScalarRange(range); - - // Compute normalized delta - double dx = static_cast(isi->GetWindowLevelCurrentPosition()[0] - - isi->GetWindowLevelStartPosition()[0]) / size[0]; - double dy = static_cast(isi->GetWindowLevelStartPosition()[1] - - isi->GetWindowLevelCurrentPosition()[1]) / size[1]; - //Window is exponential in nature, use exponential to avoid falling into negative numbers - dx = std::exp(1.0 * (dx*fabs(dx) + dx)) ; //Quadratic behavior for more reactive interface - dy = 0.15 * (dy*fabs(dy) + dy) * (range[1]-range[0]);//Quadratic behavior for more reactive interface - - this->SM->SetColorWindow(window*dx); - this->SM->SetColorLevel(level-dy); - this->SM->SetPreset(6); - this->SM->UpdateWindowLevel(); - this->SM->Render(); - return; + this->SM->GetSlicer(mStartSlicer)->GetAnnotation()->SetVisibility(1); + // Adjust the window level here + int *size = isi->GetInteractor()->GetRenderWindow()->GetSize(); + double window = this->InitialWindow; + double level = this->InitialLevel; + double range[2]; + this->SM->GetImage()->GetScalarRange(range); + + // Compute normalized delta + double dx = static_cast(isi->GetWindowLevelCurrentPosition()[0] - + isi->GetWindowLevelStartPosition()[0]) / size[0]; + double dy = static_cast(isi->GetWindowLevelStartPosition()[1] - + isi->GetWindowLevelCurrentPosition()[1]) / size[1]; + //Window is exponential in nature, use exponential to avoid falling into negative numbers + dx = std::exp(1.0 * (dx*fabs(dx) + dx)) ; //Quadratic behavior for more reactive interface + dy = 0.15 * (dy*fabs(dy) + dy) * (range[1]-range[0]);//Quadratic behavior for more reactive interface + + this->SM->SetColorWindow(window*dx); + this->SM->SetColorLevel(level-dy); + this->SM->SetPreset(6); + this->SM->UpdateWindowLevel(); + this->SM->Render(); + return; } } } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvSlicerManagerCallback::Dolly(double factor, vtkRenderWindowInteractor *interactor) { - int VisibleInWindow = this->FindSlicerNumber(interactor->GetRenderWindow()); - vtkRenderer* renderer; - if (VisibleInWindow>-1) - renderer=this->SM->GetSlicer(VisibleInWindow)->GetRenderer(); - else + int VisibleInWindow = this->FindSlicerNumber(interactor->GetRenderWindow()); + vtkRenderer* renderer; + if (VisibleInWindow>-1) + renderer=this->SM->GetSlicer(VisibleInWindow)->GetRenderer(); + else { - return; + return; } - double viewFocus[4],viewPoint[4],motionVector[3], focalDepth; - double oldPos[3], newPos[3], distance[2]; - vtkCamera *camera = renderer->GetActiveCamera(); - camera->GetFocalPoint(viewFocus); - - renderer->SetWorldPoint(viewFocus[0], viewFocus[0], viewFocus[0], 1.0); - renderer->WorldToDisplay(); - renderer->GetDisplayPoint(viewFocus); - - focalDepth = viewFocus[2]; - - oldPos[0] = renderer->GetCenter()[0]; - oldPos[1] = renderer->GetCenter()[1]; - oldPos[2] = focalDepth; - - distance[0] = 1/factor* - (interactor->GetEventPosition()[0]-renderer->GetCenter()[0]); - distance[1] = 1/factor* - (interactor->GetEventPosition()[1]-renderer->GetCenter()[1]); - - newPos[0] = interactor->GetEventPosition()[0] - distance[0]; - newPos[1] = interactor->GetEventPosition()[1] - distance[1]; - newPos[2] = focalDepth; - - renderer->DisplayToNormalizedDisplay(oldPos[0],oldPos[1]); - renderer->NormalizedDisplayToViewport(oldPos[0],oldPos[1]); - renderer->ViewportToNormalizedViewport(oldPos[0],oldPos[1]); - renderer->NormalizedViewportToView(oldPos[0],oldPos[1],oldPos[2]); - renderer->ViewToWorld(oldPos[0],oldPos[1],oldPos[2]); - - renderer->DisplayToNormalizedDisplay(newPos[0],newPos[1]); - renderer->NormalizedDisplayToViewport(newPos[0],newPos[1]); - renderer->ViewportToNormalizedViewport(newPos[0],newPos[1]); - renderer->NormalizedViewportToView(newPos[0],newPos[1],newPos[2]); - renderer->ViewToWorld(newPos[0],newPos[1],newPos[2]); - - motionVector[0] = newPos[0] - oldPos[0]; - motionVector[1] = newPos[1] - oldPos[1]; - motionVector[2] = newPos[2] - oldPos[2]; - - camera->GetFocalPoint(viewFocus); - camera->GetPosition(viewPoint); - camera->SetFocalPoint(motionVector[0] + viewFocus[0], - motionVector[1] + viewFocus[1], - motionVector[2] + viewFocus[2]); - - camera->SetPosition(motionVector[0] + viewPoint[0], - motionVector[1] + viewPoint[1], - motionVector[2] + viewPoint[2]); - - if (camera->GetParallelProjection()) + double viewFocus[4],viewPoint[4],motionVector[3], focalDepth; + double oldPos[3], newPos[3], distance[2]; + vtkCamera *camera = renderer->GetActiveCamera(); + camera->GetFocalPoint(viewFocus); + + renderer->SetWorldPoint(viewFocus[0], viewFocus[0], viewFocus[0], 1.0); + renderer->WorldToDisplay(); + renderer->GetDisplayPoint(viewFocus); + + focalDepth = viewFocus[2]; + + oldPos[0] = renderer->GetCenter()[0]; + oldPos[1] = renderer->GetCenter()[1]; + oldPos[2] = focalDepth; + + distance[0] = 1/factor* + (interactor->GetEventPosition()[0]-renderer->GetCenter()[0]); + distance[1] = 1/factor* + (interactor->GetEventPosition()[1]-renderer->GetCenter()[1]); + + newPos[0] = interactor->GetEventPosition()[0] - distance[0]; + newPos[1] = interactor->GetEventPosition()[1] - distance[1]; + newPos[2] = focalDepth; + + renderer->DisplayToNormalizedDisplay(oldPos[0],oldPos[1]); + renderer->NormalizedDisplayToViewport(oldPos[0],oldPos[1]); + renderer->ViewportToNormalizedViewport(oldPos[0],oldPos[1]); + renderer->NormalizedViewportToView(oldPos[0],oldPos[1],oldPos[2]); + renderer->ViewToWorld(oldPos[0],oldPos[1],oldPos[2]); + + renderer->DisplayToNormalizedDisplay(newPos[0],newPos[1]); + renderer->NormalizedDisplayToViewport(newPos[0],newPos[1]); + renderer->ViewportToNormalizedViewport(newPos[0],newPos[1]); + renderer->NormalizedViewportToView(newPos[0],newPos[1],newPos[2]); + renderer->ViewToWorld(newPos[0],newPos[1],newPos[2]); + + motionVector[0] = newPos[0] - oldPos[0]; + motionVector[1] = newPos[1] - oldPos[1]; + motionVector[2] = newPos[2] - oldPos[2]; + + camera->GetFocalPoint(viewFocus); + camera->GetPosition(viewPoint); + camera->SetFocalPoint(motionVector[0] + viewFocus[0], + motionVector[1] + viewFocus[1], + motionVector[2] + viewFocus[2]); + + camera->SetPosition(motionVector[0] + viewPoint[0], + motionVector[1] + viewPoint[1], + motionVector[2] + viewPoint[2]); + + if (camera->GetParallelProjection()) { - camera->SetParallelScale(camera->GetParallelScale() / factor); + camera->SetParallelScale(camera->GetParallelScale() / factor); } - else + else { - camera->Dolly(factor); + camera->Dolly(factor); } - if (interactor->GetLightFollowCamera()) + if (interactor->GetLightFollowCamera()) { - renderer->UpdateLightsGeometryToFollowCamera(); + renderer->UpdateLightsGeometryToFollowCamera(); } - renderer->ResetCameraClippingRange(); - //interactor->Render(); + renderer->ResetCameraClippingRange(); + //interactor->Render(); } void vvSlicerManagerCallback::FlyToPosition(vtkRenderWindowInteractor *interactor,vvSlicer* slicer) { - double flyFrom[3], flyTo[3]; - double d[3], focalPt[3], position[3], positionFrom[3]; - int i, j; - int VisibleInWindow = this->FindSlicerNumber(interactor->GetRenderWindow()); - vtkRenderer* renderer=NULL; - if (VisibleInWindow>-1) - renderer=this->SM->GetSlicer(VisibleInWindow)->GetRenderer(); - else - return; - - interactor->GetPicker()->Pick(interactor->GetEventPosition()[0], - interactor->GetEventPosition()[1], 0.0, - renderer); - - vtkAssemblyPath *path=NULL; - vtkAbstractPropPicker *picker; - if ( (picker=vtkAbstractPropPicker::SafeDownCast(interactor->GetPicker()))) + double flyFrom[3], flyTo[3]; + double d[3], focalPt[3], position[3], positionFrom[3]; + int i, j; + int VisibleInWindow = this->FindSlicerNumber(interactor->GetRenderWindow()); + vtkRenderer* renderer=NULL; + if (VisibleInWindow>-1) + renderer=this->SM->GetSlicer(VisibleInWindow)->GetRenderer(); + else + return; + + interactor->GetPicker()->Pick(interactor->GetEventPosition()[0], + interactor->GetEventPosition()[1], 0.0, + renderer); + + vtkAssemblyPath *path=NULL; + vtkAbstractPropPicker *picker; + if ( (picker=vtkAbstractPropPicker::SafeDownCast(interactor->GetPicker()))) { - path = picker->GetPath(); + path = picker->GetPath(); } - if ( path != NULL ) + if ( path != NULL ) { - flyTo[0] = picker->GetPickPosition()[0]; - flyTo[1] = picker->GetPickPosition()[1]; - flyTo[2] = picker->GetPickPosition()[2]; - renderer->GetActiveCamera()->GetFocalPoint(flyFrom); - renderer->GetActiveCamera()->GetPosition(positionFrom); + flyTo[0] = picker->GetPickPosition()[0]; + flyTo[1] = picker->GetPickPosition()[1]; + flyTo[2] = picker->GetPickPosition()[2]; + renderer->GetActiveCamera()->GetFocalPoint(flyFrom); + renderer->GetActiveCamera()->GetPosition(positionFrom); - switch (slicer->GetSliceOrientation()) + switch (slicer->GetSliceOrientation()) { case vtkImageViewer2::SLICE_ORIENTATION_XY: - flyTo[2] = flyFrom[2]; - break; + flyTo[2] = flyFrom[2]; + break; case vtkImageViewer2::SLICE_ORIENTATION_XZ: - flyTo[1] = flyFrom[1]; - break; + flyTo[1] = flyFrom[1]; + break; case vtkImageViewer2::SLICE_ORIENTATION_YZ: - flyTo[0] = flyFrom[0]; - break; + flyTo[0] = flyFrom[0]; + break; } - for (i=0; i<3; i++) + for (i=0; i<3; i++) { - d[i] = flyTo[i] - flyFrom[i]; + d[i] = flyTo[i] - flyFrom[i]; } - double distance = vtkMath::Normalize(d); - double delta = distance/15; + double distance = vtkMath::Normalize(d); + double delta = distance/15; - for (i=1; i<=15; i++) + for (i=1; i<=15; i++) { - for (j=0; j<3; j++) + for (j=0; j<3; j++) { - focalPt[j] = flyFrom[j] + d[j]*i*delta; - position[j] = positionFrom[j] + d[j]*i*delta; + focalPt[j] = flyFrom[j] + d[j]*i*delta; + position[j] = positionFrom[j] + d[j]*i*delta; } - renderer->GetActiveCamera()->SetFocalPoint(focalPt); - renderer->GetActiveCamera()->SetPosition(position); - renderer->GetActiveCamera()->Dolly(0.3/15 + 1.0); - renderer->ResetCameraClippingRange(); - interactor->Render(); + renderer->GetActiveCamera()->SetFocalPoint(focalPt); + renderer->GetActiveCamera()->SetPosition(position); + renderer->GetActiveCamera()->Dolly(0.3/15 + 1.0); + renderer->ResetCameraClippingRange(); + interactor->Render(); } } } diff --git a/vv/vvToolBase.h b/vv/vvToolBase.h index 9e371f5..005217f 100644 --- a/vv/vvToolBase.h +++ b/vv/vvToolBase.h @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvToolBase.h,v $ Language: C++ - Date: $Date: 2010/02/09 14:19:32 $ - Version: $Revision: 1.2 $ + Date: $Date: 2010/02/24 11:42:42 $ + Version: $Revision: 1.3 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2008 @@ -28,113 +28,25 @@ #ifndef VVTOOLBASE_H #define VVTOOLBASE_H -#include "vvToolCreatorBase.h" -#include "vvToolInputSelectorWidget.h" -#include "clitkImageToImageGenericFilter.h" +#include "vvToolBaseBase.h" +#include "vvToolCreator.h" //------------------------------------------------------------------------------ template -class vvToolBase { +class vvToolBase : public vvToolBaseBase { public: + vvToolBase(vvMainWindowBase * m); static void Initialize(); // can't be virtual, must be overwritten - void UpdateInfoFromMainWindow(); - vvMainWindowToolInfo * mMainWindowToolInfo; static void SetToolName(QString n) { vvToolCreator::mSingleton->mToolName = n; } static void SetToolMenuName(QString n) { vvToolCreator::mSingleton->mToolMenuName = n; } static void SetToolIconFilename(QString n) { vvToolCreator::mSingleton->mToolIconFilename = n; } static void SetToolTip(QString n) { vvToolCreator::mSingleton->mToolTip = n; } - void InitializeListOfInputImages(); - void InitializeListOfInputImages(vvToolInputSelectorWidget * w, - clitk::ImageToImageGenericFilterBase * f); - std::vector mSlicerManagersCompatible; - unsigned int mCurrentIndex; - - vvImage::Pointer mCurrentImage; - vvSlicerManager * mCurrentSliceManager; - clitk::ImageToImageGenericFilterBase * mFilter; - }; //------------------------------------------------------------------------------ - -//------------------------------------------------------------------------------ -template -void vvToolBase::UpdateInfoFromMainWindow() { - mMainWindowToolInfo = vvToolCreator::mSingleton->mMainWindow->GetInfoForTool(); -} -//------------------------------------------------------------------------------ - - -//------------------------------------------------------------------------------ -template -void vvToolBase::Initialize() { - SetToolName("Unnamed tool"); - SetToolMenuName("Unnamed tool"); - SetToolIconFilename(""); - SetToolTip("Unamed tool."); -} -//------------------------------------------------------------------------------ - - -//------------------------------------------------------------------------------ -template -void vvToolBase::InitializeListOfInputImages(vvToolInputSelectorWidget * w, - clitk::ImageToImageGenericFilterBase * f) { - mFilter = f; - InitializeListOfInputImages(); - w->Initialize(mSlicerManagersCompatible, mCurrentIndex); - w->SetToolTip(mFilter->GetAvailableImageTypes().c_str()); -} -//------------------------------------------------------------------------------ - -//------------------------------------------------------------------------------ -template -void vvToolBase::InitializeListOfInputImages() { - UpdateInfoFromMainWindow(); - - std::vector & mSlicerManagers = *mMainWindowToolInfo->mSlicerManagers; - mCurrentIndex = mMainWindowToolInfo->mSlicerManagerCurrentIndex; - DD("InputUpdate"); - DD(mCurrentIndex); - // HERE : Check if image is ok (dimension, type etc ...) - - if (mFilter) { - mFilter->PrintAvailableImageTypes(); - - } - else { - /// if not set, do not check filter type - std::cerr << "*** ERROR, set mFilter member in the vvTool class before calling InitializeListOfInputImages" << std::endl; - exit(0); - } - - //unsigned int previousIndex = mInputSequenceBox->mCurrentIndex(); - mSlicerManagersCompatible.clear(); - // mInputSequenceBox->clear(); - for (unsigned int i = 0; i < mSlicerManagers.size(); i++) { - - vvImage * image = mSlicerManagers[i]->GetImage(); - - if (mFilter->CheckImageType(image->GetNumberOfDimensions(), - image->GetNumberOfScalarComponents(), - image->GetScalarTypeAsString())) { - mSlicerManagersCompatible.push_back(mSlicerManagers[i]); - if (mCurrentIndex == i) { - mCurrentIndex = mSlicerManagersCompatible.size()-1; - } - } - else { - std::cerr << mSlicerManagers[i]->GetFileName().c_str() << " not compatible image" << std::endl; - if (mCurrentIndex == i) { - mCurrentIndex = 0; - } - } - } -} -//------------------------------------------------------------------------------ - +#include "vvToolBase.txx" #endif diff --git a/vv/vvToolBase.txx b/vv/vvToolBase.txx new file mode 100644 index 0000000..661a423 --- /dev/null +++ b/vv/vvToolBase.txx @@ -0,0 +1,45 @@ +/*========================================================================= + + Program: vv + Module: $RCSfile: vvToolBase.txx,v $ + Language: C++ + Date: $Date: 2010/02/24 11:43:37 $ + Version: $Revision: 1.1 $ + Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) + + Copyright (C) 2008 + Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + CREATIS http://www.creatis.insa-lyon.fr + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + =========================================================================*/ + +//------------------------------------------------------------------------------ +template +vvToolBase::vvToolBase(vvMainWindowBase * m) { + mMainWindowBase = m; +} +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Default value (to be overwritten) +template +void vvToolBase::Initialize() { + SetToolName("Unnamed tool (use SetToolName in Initialize())"); + SetToolMenuName("Unnamed tool"); + SetToolIconFilename(""); + SetToolTip("Unamed tool."); +} +//------------------------------------------------------------------------------ + diff --git a/vv/vvToolBinarize.cxx b/vv/vvToolBinarize.cxx index d8fb488..bccf021 100644 --- a/vv/vvToolBinarize.cxx +++ b/vv/vvToolBinarize.cxx @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvToolBinarize.cxx,v $ Language: C++ - Date: $Date: 2010/02/07 12:00:59 $ - Version: $Revision: 1.7 $ + Date: $Date: 2010/02/24 11:42:42 $ + Version: $Revision: 1.8 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2008 @@ -44,54 +44,45 @@ ADD_TOOL(vvToolBinarize); //------------------------------------------------------------------------------ -vvToolBinarize::vvToolBinarize(QWidget * parent, Qt::WindowFlags f) - :QDialog(parent,f), vvToolBase(), Ui::vvToolBinarize() -{ - // Set Modality : dialog is not modal but stay always on top because - // parent is set at construction - setModal(false); - setAttribute(Qt::WA_DeleteOnClose); +void vvToolBinarize::Initialize() { + SetToolName("Binarize"); + SetToolMenuName("Binarize"); + SetToolIconFilename(":/new/prefix1/icons/binarize.png"); + SetToolTip("Image interactive binarization with thresholds."); +} +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +vvToolBinarize::vvToolBinarize(vvMainWindowBase * parent, Qt::WindowFlags f) + :vvToolWidgetBase(parent,f), + vvToolBase(parent), + Ui::vvToolBinarize() +{ // GUI Initialization - setupUi(this); + Ui_vvToolBinarize::setupUi(mToolWidget); // Connect signals & slots - connect(mToolInputSelectionWidget, SIGNAL(accepted()), this, SLOT(InputIsSelected())); - connect(mToolInputSelectionWidget, SIGNAL(rejected()), this, SLOT(close())); - connect(buttonBox, SIGNAL(accepted()), this, SLOT(apply())); - connect(buttonBox, SIGNAL(rejected()), this, SLOT(close())); connect(mThresholdSlider1, SIGNAL(valueChanged(double)), this, SLOT(valueChangedT1(double))); connect(mThresholdSlider2, SIGNAL(valueChanged(double)), this, SLOT(valueChangedT2(double))); connect(mRadioButtonLowerThan, SIGNAL(toggled(bool)), this, SLOT(enableLowerThan(bool))); connect(mCheckBoxUseFG, SIGNAL(toggled(bool)), this, SLOT(useFGBGtoggled(bool))); connect(mCheckBoxUseBG, SIGNAL(toggled(bool)), this, SLOT(useFGBGtoggled(bool))); - // VTK objects - //mImageContour = new vvImageContour; - - //new vector of contours - // Initialize some widget mThresholdSlider1->SetText(""); mThresholdSlider2->SetText(""); mFGSlider->SetText("Foreground value"); mBGSlider->SetText("Background value"); - // Disable main widget while input image is not selected - toolMainWidget->setEnabled(false); - // Main filter mFilter = new clitk::BinarizeImageGenericFilter; //DS PUT IN BASECLASS ? - - // Initialize the input selection (mFilter should be create before !) - InitializeListOfInputImages(mToolInputSelectionWidget, mFilter); } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ vvToolBinarize::~vvToolBinarize() { - //delete mImageContour; } //------------------------------------------------------------------------------ @@ -117,13 +108,10 @@ void vvToolBinarize::useFGBGtoggled(bool) { //------------------------------------------------------------------------------ -void vvToolBinarize::InputIsSelected() { - +void vvToolBinarize::InputIsSelected(vvSlicerManager * m) { + mCurrentSlicerManager = m; // Common - int index = mToolInputSelectionWidget->GetSelectedInputIndex(); - mCurrentSliceManager = mSlicerManagersCompatible[index]; - mCurrentImage = mCurrentSliceManager->GetImage(); - toolMainWidget->setEnabled(true); + mCurrentImage = mCurrentSlicerManager->GetImage(); // Specific for this gui mThresholdSlider1->SetValue(0); @@ -132,7 +120,7 @@ void vvToolBinarize::InputIsSelected() { mThresholdSlider2->SetImage(mCurrentImage); mFGSlider->SetImage(mCurrentImage); mBGSlider->SetImage(mCurrentImage); - DD(mCurrentSliceManager->GetFileName().c_str()); + // DD(mCurrentSlicerManager->GetFileName().c_str()); mFGSlider->SetMaximum(mCurrentImage->GetFirstVTKImageData()->GetScalarTypeMax()); mFGSlider->SetMinimum(mCurrentImage->GetFirstVTKImageData()->GetScalarTypeMin()); mBGSlider->SetMaximum(mCurrentImage->GetFirstVTKImageData()->GetScalarTypeMax()); @@ -141,13 +129,13 @@ void vvToolBinarize::InputIsSelected() { mBGSlider->SetValue(0); // VTK objects for interactive display - for(int i=0;iNumberOfSlicers(); i++) { + for(int i=0;iNumberOfSlicers(); i++) { mImageContour.push_back(new vvImageContour); - mImageContour[i]->setSlicer(mCurrentSliceManager->GetSlicer(i)); + mImageContour[i]->setSlicer(mCurrentSlicerManager->GetSlicer(i)); } valueChangedT1(mThresholdSlider1->GetValue()); - connect(mCurrentSliceManager,SIGNAL(UpdateSlice(int,int)),this,SLOT(UpdateSlice(int, int))); - connect(mCurrentSliceManager,SIGNAL(UpdateTSlice(int,int)),this,SLOT(UpdateSlice(int, int))); + connect(mCurrentSlicerManager,SIGNAL(UpdateSlice(int,int)),this,SLOT(UpdateSlice(int, int))); + connect(mCurrentSlicerManager,SIGNAL(UpdateTSlice(int,int)),this,SLOT(UpdateSlice(int, int))); } //------------------------------------------------------------------------------ @@ -155,11 +143,11 @@ void vvToolBinarize::InputIsSelected() { //------------------------------------------------------------------------------ void vvToolBinarize::UpdateSlice(int slicer,int slices) { - DD(slicer); - for(int i=0;iNumberOfSlicers(); i++) { + if (!mCurrentSlicerManager) close(); + for(int i=0;iNumberOfSlicers(); i++) { mImageContour[i]->update(mThresholdSlider1->GetValue()); } - mCurrentSliceManager->Render(); + mCurrentSlicerManager->Render(); } //------------------------------------------------------------------------------ @@ -183,7 +171,7 @@ void vvToolBinarize::GetArgsInfoFromGUI() { mArgsInfo.lower_given = 1; mArgsInfo.lower_arg = mThresholdSlider1->GetValue(); - DD(mArgsInfo.lower_arg); + // DD(mArgsInfo.lower_arg); if (mRadioButtonLowerThan->isChecked()) { mArgsInfo.upper_given = 1; mArgsInfo.upper_arg = mThresholdSlider2->GetValue(); @@ -196,7 +184,7 @@ void vvToolBinarize::GetArgsInfoFromGUI() { mArgsInfo.fg_arg = mFGSlider->GetValue(); mArgsInfo.bg_arg = mBGSlider->GetValue(); - DD(inverseBGandFG); + // DD(inverseBGandFG); if (inverseBGandFG) { mArgsInfo.fg_arg = mFGSlider->GetValue(); mArgsInfo.bg_arg = mBGSlider->GetValue(); @@ -224,6 +212,7 @@ void vvToolBinarize::GetArgsInfoFromGUI() { //------------------------------------------------------------------------------ void vvToolBinarize::apply() { + if (!mCurrentSlicerManager) close(); GetArgsInfoFromGUI(); // Main filter @@ -236,8 +225,8 @@ void vvToolBinarize::apply() { // Output ??? vvImage::Pointer output = filter->GetOutputVVImage(); std::ostringstream osstream; - osstream << "Binarized_" << mCurrentSliceManager->GetSlicer(0)->GetFileName(); - CREATOR(vvToolBinarize)->mMainWindow->AddImage(output,osstream.str()); + osstream << "Binarized_" << mCurrentSlicerManager->GetSlicer(0)->GetFileName(); + CREATOR(vvToolBinarize)->GetMainWindow()->AddImage(output,osstream.str()); close(); } //------------------------------------------------------------------------------ @@ -252,12 +241,15 @@ void vvToolBinarize::valueChangedT2(double v) { //------------------------------------------------------------------------------ void vvToolBinarize::valueChangedT1(double v) { + // DD(v); + if (!mCurrentSlicerManager) close(); +// DD(mCurrentSlicerManager->GetSlicer(0)); mThresholdSlider2->SetMinimum(v); int m1 = (int)lrint(v); - for(int i=0;iNumberOfSlicers(); i++) { + for(int i=0;iNumberOfSlicers(); i++) { mImageContour[i]->update(m1); } - mCurrentSliceManager->Render(); + mCurrentSlicerManager->Render(); } //------------------------------------------------------------------------------ diff --git a/vv/vvToolBinarize.h b/vv/vvToolBinarize.h index a1bd7d5..f29d119 100644 --- a/vv/vvToolBinarize.h +++ b/vv/vvToolBinarize.h @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvToolBinarize.h,v $ Language: C++ - Date: $Date: 2010/02/07 12:00:59 $ - Version: $Revision: 1.5 $ + Date: $Date: 2010/02/24 11:42:42 $ + Version: $Revision: 1.6 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2010 @@ -29,9 +29,10 @@ #define VVTOOLBINARIZE_H #include -#include +//#include #include "vvToolBase.h" +#include "vvToolWidgetBase.h" #include "vvImageContour.h" #include "ui_vvToolBinarize.h" #include "clitkBinarizeImage_ggo.h" @@ -47,24 +48,17 @@ //------------------------------------------------------------------------------ class vvToolBinarize: - public QDialog, public vvToolBase, private Ui::vvToolBinarize + public vvToolWidgetBase, + public vvToolBase, + private Ui::vvToolBinarize { Q_OBJECT public: - vvToolBinarize(QWidget * parent=0, Qt::WindowFlags f=0); + vvToolBinarize(vvMainWindowBase * parent=0, Qt::WindowFlags f=0); ~vvToolBinarize(); //----------------------------------------------------- - typedef vvToolBinarize Self; - - //----------------------------------------------------- - static void Initialize() { - SetToolName("Binarize"); - SetToolMenuName("Binarize"); - SetToolIconFilename(":/new/prefix1/icons/binarize.png"); - SetToolTip("Image interactive binarization with thresholds."); - } - + static void Initialize(); void InputIsSet(bool b); void GetArgsInfoFromGUI(); @@ -74,9 +68,23 @@ class vvToolBinarize: void valueChangedT1(double v); void valueChangedT2(double v); void UpdateSlice(int slicer,int slices); - void InputIsSelected(); + void InputIsSelected(vvSlicerManager * m); void enableLowerThan(bool b); void useFGBGtoggled(bool); + virtual bool close() { DD("vvToolBinarize::close"); + for(unsigned int i=0; iremoveActors(); + if (mCurrentSlicerManager) + mCurrentSlicerManager->Render(); + return vvToolWidgetBase::close(); } + + virtual void reject() { DD("vvToolBinarize::reject"); + for(unsigned int i=0; iremoveActors(); + if (mCurrentSlicerManager) + mCurrentSlicerManager->Render(); + return vvToolWidgetBase::reject(); } + protected: Ui::vvToolBinarize ui; diff --git a/vv/vvToolCreator.h b/vv/vvToolCreator.h new file mode 100644 index 0000000..e2d108a --- /dev/null +++ b/vv/vvToolCreator.h @@ -0,0 +1,60 @@ +/*========================================================================= + + Program: vv + Module: $RCSfile: vvToolCreator.h,v $ + Language: C++ + Date: $Date: 2010/02/24 11:43:37 $ + Version: $Revision: 1.1 $ + Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) + + Copyright (C) 2008 + Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + CREATIS-LRMN http://www.creatis.insa-lyon.fr + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + =========================================================================*/ + +#ifndef VVTOOLCREATOR_H +#define VVTOOLCREATOR_H + +#include "vvToolCreatorBase.h" + +//------------------------------------------------------------------------------ +template +class vvToolCreator: public vvToolCreatorBase { +public: + vvToolCreator(QString name):vvToolCreatorBase(name) {;} + virtual void InsertToolInMenu(vvMainWindowBase * m); + virtual void MenuSpecificToolSlot() { CreateTool(); } + static vvToolCreator * mSingleton; +}; +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +#define CREATOR(CLASSNAME) vvToolCreator::mSingleton +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +#define ADD_TOOL(NAME) \ + template<> \ + vvToolCreator * vvToolCreator::mSingleton = \ + new vvToolCreator(#NAME); +//------------------------------------------------------------------------------ + +#include "vvToolCreator.txx" + +#endif + diff --git a/vv/vvToolCreator.txx b/vv/vvToolCreator.txx new file mode 100644 index 0000000..bee8cbb --- /dev/null +++ b/vv/vvToolCreator.txx @@ -0,0 +1,45 @@ +/*========================================================================= + + Program: vv + Module: $RCSfile: vvToolCreator.txx,v $ + Language: C++ + Date: $Date: 2010/02/24 11:43:37 $ + Version: $Revision: 1.1 $ + Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) + + Copyright (C) 2008 + Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + CREATIS-LRMN http://www.creatis.insa-lyon.fr + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + =========================================================================*/ + +//------------------------------------------------------------------------------ +// Call when the ToolType is inserted into the menu +template +void vvToolCreator::InsertToolInMenu(vvMainWindowBase * m) { + mMainWindow = m; + + // Default Initialization + mToolMenuName = mToolName; + mToolIconFilename = "noicon"; + mToolTip = mToolName; + + // User Tool Initialization + ToolType::Initialize(); + + // Common Initialization (insertion into menu) + vvToolCreatorBase::InsertToolInMenu(mMainWindow); +} +//------------------------------------------------------------------------------ diff --git a/vv/vvToolCreatorBase.cxx b/vv/vvToolCreatorBase.cxx index e47fa14..57a1d9f 100644 --- a/vv/vvToolCreatorBase.cxx +++ b/vv/vvToolCreatorBase.cxx @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvToolCreatorBase.cxx,v $ Language: C++ - Date: $Date: 2010/01/29 13:54:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2010/02/24 11:42:42 $ + Version: $Revision: 1.2 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2008 @@ -26,9 +26,9 @@ =========================================================================*/ #include "vvToolCreatorBase.h" -#include "vvSlicerManager.h" #include "vvToolManager.h" #include +#include //------------------------------------------------------------------------------ vvToolCreatorBase::vvToolCreatorBase(QString name) { @@ -39,30 +39,18 @@ vvToolCreatorBase::vvToolCreatorBase(QString name) { //------------------------------------------------------------------------------ -void vvToolCreatorBase::Initialize(vvMainWindow * m) { - mMainWindow = m; - - // Create main Action +void vvToolCreatorBase::InsertToolInMenu(vvMainWindowBase * m) { + mMainWindow = m; + // Create main action if (mToolIconFilename == "noicon") mAction = new QAction(QString("&").append(mToolMenuName), this); else mAction = new QAction(QIcon(mToolIconFilename), QString("&").append(mToolMenuName), this); mAction->setStatusTip(mToolTip); + // Connect the action connect(mAction, SIGNAL(triggered()), this, SLOT(MenuToolSlot())); - mMainWindow->GetInfoForTool()->mMenuTools->addAction(mAction); - //UpdateEnabledTool(); + mMainWindow->GetMenu()->addAction(mAction); } //------------------------------------------------------------------------------ - -//------------------------------------------------------------------------------ -void vvToolCreatorBase::UpdateEnabledTool() { - DD("Update enabled tool"); - - DD(mMainWindow->GetInfoForTool()->mSlicerManagers->size()); - if (mMainWindow->GetInfoForTool()->mSlicerManagers->size() < 1) - mAction->setEnabled(false); - else mAction->setEnabled(true); -} -//------------------------------------------------------------------------------ diff --git a/vv/vvToolCreatorBase.h b/vv/vvToolCreatorBase.h index 4f7538b..2143239 100644 --- a/vv/vvToolCreatorBase.h +++ b/vv/vvToolCreatorBase.h @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvToolCreatorBase.h,v $ Language: C++ - Date: $Date: 2010/01/29 13:54:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2010/02/24 11:42:42 $ + Version: $Revision: 1.2 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2008 @@ -28,14 +28,12 @@ #ifndef VVTOOLCREATORBASE_H #define VVTOOLCREATORBASE_H -#include "clitkCommon.h" #include +#include "vvSlicerManager.h" +#include "vvMainWindowBase.h" -// For vvMainWindowToolInfo -#include "vvMainWindow.h" -class vvMainWindow; -// struct vvMainWindowToolInfo; class QAction; +class vvToolBaseBase; //------------------------------------------------------------------------------ class vvToolCreatorBase: public QObject { @@ -43,50 +41,27 @@ class vvToolCreatorBase: public QObject { public: vvToolCreatorBase(QString name); - virtual ~vvToolCreatorBase() {;} - - virtual void Initialize(vvMainWindow * m); - virtual void UpdateEnabledTool(); + virtual ~vvToolCreatorBase() {;} + virtual void InsertToolInMenu(vvMainWindowBase * m); template void CreateTool(); virtual void MenuSpecificToolSlot() = 0; - + vvMainWindowBase * GetMainWindow() const { return mMainWindow; } + QString mToolName; QString mToolMenuName; QString mToolIconFilename; QString mToolTip; QAction * mAction; - vvMainWindow * mMainWindow; - public slots: virtual void MenuToolSlot() { MenuSpecificToolSlot(); } -}; -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ -template -class vvToolCreator: public vvToolCreatorBase { -public: - vvToolCreator(QString name):vvToolCreatorBase(name) {;} - virtual void Initialize(vvMainWindow * m); - static vvToolCreator * mSingleton; - virtual void MenuSpecificToolSlot() { CreateTool(); } +protected: + vvMainWindowBase * mMainWindow; + std::vector mListOfTool; }; //------------------------------------------------------------------------------ - -//------------------------------------------------------------------------------ -#define CREATOR(CLASSNAME) vvToolCreator::mSingleton -//------------------------------------------------------------------------------ - - -//------------------------------------------------------------------------------ -#define ADD_TOOL(NAME) \ - template<> \ - vvToolCreator * vvToolCreator::mSingleton = \ - new vvToolCreator(#NAME); -//------------------------------------------------------------------------------ - #include "vvToolCreatorBase.txx" #endif diff --git a/vv/vvToolCreatorBase.txx b/vv/vvToolCreatorBase.txx index 1548266..334771e 100644 --- a/vv/vvToolCreatorBase.txx +++ b/vv/vvToolCreatorBase.txx @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvToolCreatorBase.txx,v $ Language: C++ - Date: $Date: 2010/01/29 13:54:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2010/02/24 11:42:42 $ + Version: $Revision: 1.2 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2008 @@ -25,36 +25,18 @@ =========================================================================*/ -#include "vvMainWindow.h" -#include "vvSlicerManager.h" - //------------------------------------------------------------------------------ +// Called when the tool is created template void vvToolCreatorBase::CreateTool() { - DD("Create new tool "); + // Get information on the current image + mMainWindow->UpdateCurrentSlicer(); + // Create the tool ToolType * tool = new ToolType(mMainWindow); + // Put it in the list of open tools + mListOfTool.push_back(tool); + // Go ! tool->show(); } //------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ -template -void vvToolCreator::Initialize(vvMainWindow * m) { - // Set MainWindow pointer - mMainWindow = m; - - // Default Initialization - mToolMenuName = mToolName; - mToolIconFilename = "noicon"; - mToolTip = mToolName; - - // User Tool Initialization - ToolType::Initialize(); - - // Common Initialization (insertion into menu) - vvToolCreatorBase::Initialize(mMainWindow); -} -//------------------------------------------------------------------------------ - -// template -// void vvToolCreator::UpdateInfoFromMainWindow() { mMainWindowToolInfo = CREATOR(ToolType)->mMainWindow->GetInfoForTool(); } diff --git a/vv/vvToolCropImage.cxx b/vv/vvToolCropImage.cxx new file mode 100644 index 0000000..126a46f --- /dev/null +++ b/vv/vvToolCropImage.cxx @@ -0,0 +1,64 @@ +/*========================================================================= + + Program: vv + Module: $RCSfile: vvToolCropImage.cxx,v $ + Language: C++ + Date: $Date: 2010/02/24 11:43:37 $ + Version: $Revision: 1.1 $ + Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) + + Copyright (C) 2008 + Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + CREATIS-LRMN http://www.creatis.insa-lyon.fr + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + =========================================================================*/ + +#include "vvToolCropImage.h" + +//------------------------------------------------------------------------------ +// Create the tool and automagically (I like this word) insert it in +// the main window menu. +ADD_TOOL(vvToolCropImage); +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +vvToolCropImage::vvToolCropImage(vvMainWindowBase * parent, Qt::WindowFlags f): + vvToolWidgetBase(parent, f), + vvToolBase(parent), + Ui::vvToolCropImage() { + // GUI Initialization + Ui_vvToolCropImage::setupUi(mToolWidget); + + // Initialize the input selection + //UpdateInfoFromMainWindow(); + // InitializeListOfInputImages(*mMainWindowToolInfo->mSlicerManagers, +// mMainWindowToolInfo->mSlicerManagerCurrentIndex); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +vvToolCropImage::~vvToolCropImage() { + +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvToolCropImage::InputIsSelected(vvSlicerManager * slicer) { + DD("InputIsSelected"); +} +//------------------------------------------------------------------------------ diff --git a/vv/vvToolCropImage.h b/vv/vvToolCropImage.h new file mode 100644 index 0000000..c039653 --- /dev/null +++ b/vv/vvToolCropImage.h @@ -0,0 +1,78 @@ +/*========================================================================= + + Program: vv + Module: $RCSfile: vvToolCropImage.h,v $ + Language: C++ + Date: $Date: 2010/02/24 11:43:37 $ + Version: $Revision: 1.1 $ + Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) + + Copyright (C) 2010 + Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + CREATIS http://www.creatis.insa-lyon.fr + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + =========================================================================*/ + +#ifndef VVTOOLCROPIMAGE_H +#define VVTOOLCROPIMAGE_H + +#include +#include + +#include "vvToolBase.h" +#include "vvToolWidgetBase.h" +#include "vvMainWindowBase.h" +#include "ui_vvToolCropImage.h" + +//------------------------------------------------------------------------------ +class vvToolCropImage: + public vvToolWidgetBase, + public vvToolBase, + private Ui::vvToolCropImage +{ + Q_OBJECT + public: + vvToolCropImage(vvMainWindowBase * parent=0, Qt::WindowFlags f=0); + ~vvToolCropImage(); + + //----------------------------------------------------- + typedef vvToolCropImage Self; + bool close() { return QWidget::close(); } + virtual void InputIsSelected(vvSlicerManager *m); + //void AnImageIsBeingClosed(vvSlicerManager * m) { vvToolWidgetBase::TTAnImageIsBeingClosed(m); } + + void bar() { DD("crop::bar"); } + + +public slots: + void apply() { DD("Apply"); } + + //----------------------------------------------------- + static void Initialize() { + SetToolName("Crop"); + SetToolMenuName("Crop"); + SetToolIconFilename(":/new/prefix1/icons/binarize.png"); + SetToolTip("Crop image."); + } + + protected: + Ui::vvToolCropImage ui; + + +}; // end class vvToolCropImage +//------------------------------------------------------------------------------ + +#endif + diff --git a/vv/vvToolFoo.cxx b/vv/vvToolFoo.cxx new file mode 100644 index 0000000..4976654 --- /dev/null +++ b/vv/vvToolFoo.cxx @@ -0,0 +1,63 @@ +/*========================================================================= + + Program: vv + Module: $RCSfile: vvToolFoo.cxx,v $ + Language: C++ + Date: $Date: 2010/02/24 11:43:37 $ + Version: $Revision: 1.1 $ + Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) + + Copyright (C) 2010 + Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + CREATIS http://www.creatis.insa-lyon.fr + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + =========================================================================*/ + +#include "vvToolFoo.h" + +//------------------------------------------------------------------------------ +// Create the tool and automagically (I like this word) insert it in +// the main window menu. +ADD_TOOL(vvToolFoo); +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +vvToolFoo::vvToolFoo(vvMainWindowBase * parent, Qt::WindowFlags f) + :QDialog(parent), + vvToolBase(parent), + Ui::vvToolFoo() { + // Setup the UI + Ui_vvToolFoo::setupUi(this); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +vvToolFoo::~vvToolFoo() { +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvToolFoo::Initialize() { + SetToolName("Foo"); + SetToolMenuName("Foo"); + SetToolIconFilename(":/new/prefix1/icons/ducky.png"); + SetToolTip("Make 'foo' on an image."); +} +//------------------------------------------------------------------------------ + + + diff --git a/vv/vvToolFoo.h b/vv/vvToolFoo.h new file mode 100644 index 0000000..2e2b221 --- /dev/null +++ b/vv/vvToolFoo.h @@ -0,0 +1,57 @@ +/*========================================================================= + + Program: vv + Module: $RCSfile: vvToolFoo.h,v $ + Language: C++ + Date: $Date: 2010/02/24 11:43:37 $ + Version: $Revision: 1.1 $ + Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) + + Copyright (C) 2010 + Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + CREATIS http://www.creatis.insa-lyon.fr + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + =========================================================================*/ + +#ifndef VVTOOLFOO_H +#define VVTOOLFOO_H + +#include +#include + +#include "vvToolBase.h" +#include "ui_vvToolFoo.h" + +//------------------------------------------------------------------------------ +class vvToolFoo: + public QDialog, + public vvToolBase, + private Ui::vvToolFoo +{ + Q_OBJECT + public: + vvToolFoo(vvMainWindowBase* parent=0, Qt::WindowFlags f=0); + ~vvToolFoo(); + + static void Initialize(); + + protected: + Ui::vvToolFoo ui; + +}; // end class vvToolFoo +//------------------------------------------------------------------------------ + +#endif + diff --git a/vv/vvToolInputSelectorWidget.cxx b/vv/vvToolInputSelectorWidget.cxx index 0cb8c01..217b53b 100644 --- a/vv/vvToolInputSelectorWidget.cxx +++ b/vv/vvToolInputSelectorWidget.cxx @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvToolInputSelectorWidget.cxx,v $ Language: C++ - Date: $Date: 2010/01/29 13:54:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2010/02/24 11:42:42 $ + Version: $Revision: 1.2 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2010 @@ -48,7 +48,6 @@ vvToolInputSelectorWidget::vvToolInputSelectorWidget(QWidget * parent, Qt::Windo //------------------------------------------------------------------------------ void vvToolInputSelectorWidget::Initialize(std::vector l, int index) { - DD("Initialize"); DD(index); mInputSequenceBox->clear(); mSlicerManagerList = l; mCurrentIndex = index; @@ -70,8 +69,6 @@ void vvToolInputSelectorWidget::Initialize(std::vector l, int //------------------------------------------------------------------------------ void vvToolInputSelectorWidget::SetToolTip(QString s) { - // mLabelSelection->setToolTip(s); - //mInputSequenceBox->setToolTip(s); setToolTip(s); } //------------------------------------------------------------------------------ diff --git a/vv/vvToolInputSelectorWidget.h b/vv/vvToolInputSelectorWidget.h index 4940c44..0c02651 100644 --- a/vv/vvToolInputSelectorWidget.h +++ b/vv/vvToolInputSelectorWidget.h @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvToolInputSelectorWidget.h,v $ Language: C++ - Date: $Date: 2010/02/05 09:06:46 $ - Version: $Revision: 1.2 $ + Date: $Date: 2010/02/24 11:42:42 $ + Version: $Revision: 1.3 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2010 @@ -30,8 +30,8 @@ #include #include - #include "ui_vvToolInputSelectorWidget.h" +#include "vvImage.h" class vvSlicerManager; @@ -60,6 +60,7 @@ class vvToolInputSelectorWidget: public QWidget, private Ui::vvToolInputSelector Ui::vvToolInputSelectorWidget ui; std::vector mSlicerManagerList; int mCurrentIndex; + vvSlicerManager * mCurrentSliceManager; }; // end class vvToolInputSelectorWidget //------------------------------------------------------------------------------ diff --git a/vv/vvToolManager.cxx b/vv/vvToolManager.cxx index e66fa06..9ff504f 100644 --- a/vv/vvToolManager.cxx +++ b/vv/vvToolManager.cxx @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvToolManager.cxx,v $ Language: C++ - Date: $Date: 2010/02/03 10:54:08 $ - Version: $Revision: 1.2 $ + Date: $Date: 2010/02/24 11:42:42 $ + Version: $Revision: 1.3 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2008 @@ -26,9 +26,14 @@ =========================================================================*/ #include "vvToolManager.h" -#include "vvMainWindow.h" +#include "vvToolCreatorBase.h" +#include "vvMainWindowBase.h" +//------------------------------------------------------------------------------ +/// Unique static instance vvToolManager* vvToolManager::mSingleton=0; +//------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ vvToolManager * vvToolManager::GetInstance() { @@ -49,18 +54,10 @@ void vvToolManager::AddTool(vvToolCreatorBase * v) { //------------------------------------------------------------------------------ -void vvToolManager::Initialize(vvMainWindow * m) { +void vvToolManager::InsertToolsInMenu(vvMainWindowBase * m) { for(unsigned int i=0; imListOfTools.size(); i++) { - GetInstance()->mListOfTools[i]->Initialize(m); + GetInstance()->mListOfTools[i]->InsertToolInMenu(m); } } //------------------------------------------------------------------------------ - -//------------------------------------------------------------------------------ -void vvToolManager::UpdateEnabledTool() { - for(unsigned int i=0; imListOfTools.size(); i++) { - GetInstance()->mListOfTools[i]->UpdateEnabledTool(); - } -} -//------------------------------------------------------------------------------ diff --git a/vv/vvToolManager.h b/vv/vvToolManager.h index 8d8c1da..01f1e81 100644 --- a/vv/vvToolManager.h +++ b/vv/vvToolManager.h @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvToolManager.h,v $ Language: C++ - Date: $Date: 2010/02/03 10:54:08 $ - Version: $Revision: 1.2 $ + Date: $Date: 2010/02/24 11:42:42 $ + Version: $Revision: 1.3 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2008 @@ -28,11 +28,10 @@ #ifndef VVTOOLMANAGER_H #define VVTOOLMANAGER_H -#include "vvToolCreatorBase.h" #include "clitkCommon.h" class vvToolCreatorBase; -class vvMainWindow; +class vvMainWindowBase; //------------------------------------------------------------------------------ // Manage a list of ToolCreator. Each tool will be automagically @@ -40,15 +39,25 @@ class vvMainWindow; // MainWindow will call the 'Initialize' to insert the tool in the // menu bar. class vvToolManager { + public: - // Functions + + /// Get or build unique instance with this method static vvToolManager * GetInstance(); + + /// Add a tool creator in the list (called before main, via static member initialization) static void AddTool(vvToolCreatorBase * v); - static void Initialize(vvMainWindow * m); - static void UpdateEnabledTool(); - // Variables - std::vector mListOfTools; + + /// Called in MainWindow, insert all tools into the menu + static void InsertToolsInMenu(vvMainWindowBase * m); + +protected: + + /// Singleton object pointer static vvToolManager * mSingleton; + + /// list of all tool creators + std::vector mListOfTools; }; //------------------------------------------------------------------------------ diff --git a/vv/vvToolWidgetBase.cxx b/vv/vvToolWidgetBase.cxx new file mode 100644 index 0000000..c853c75 --- /dev/null +++ b/vv/vvToolWidgetBase.cxx @@ -0,0 +1,132 @@ +/*========================================================================= + + Program: vv + Module: $RCSfile: vvToolWidgetBase.cxx,v $ + Language: C++ + Date: $Date: 2010/02/24 11:43:37 $ + Version: $Revision: 1.1 $ + Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) + + Copyright (C) 2008 + Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + CREATIS-LRMN http://www.creatis.insa-lyon.fr + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + =========================================================================*/ + +#include "vvToolWidgetBase.h" +#include "vvMainWindowBase.h" +#include "vvSlicerManager.h" + +//------------------------------------------------------------------------------ +vvToolWidgetBase::vvToolWidgetBase(vvMainWindowBase * parent, Qt::WindowFlags f) + :QDialog(parent, f), + Ui::vvToolWidgetBase() { + + // Set Modality : dialog is not modal but stay always on top because + // parent is set at construction + mIsInitialized = false; + mFilter = 0; + mMainWindowBase = parent; + setModal(false); + setAttribute(Qt::WA_DeleteOnClose); + + // GUI Initialization + setupUi(this); + + // Connect signals & slots + connect(mMainWindowBase, SIGNAL(AnImageIsBeingClosed(vvSlicerManager*)), + this, SLOT(AnImageIsBeingClosed(vvSlicerManager*))); + connect(mToolInputSelectionWidget, SIGNAL(accepted()), this, SLOT(InputIsSelected())); + connect(mToolInputSelectionWidget, SIGNAL(rejected()), this, SLOT(close())); + connect(buttonBox, SIGNAL(accepted()), this, SLOT(apply())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(close())); + + // Disable main widget while input image is not selected + mToolWidget->setEnabled(false); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +vvToolWidgetBase::~vvToolWidgetBase() { + +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvToolWidgetBase::show() { + if (!mIsInitialized) { + InitializeInputs(); + } + QDialog::show(); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +bool vvToolWidgetBase::close() { + return QDialog::close(); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvToolWidgetBase::AnImageIsBeingClosed(vvSlicerManager * m) { + if (m == mCurrentSlicerManager) { + close(); + } +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvToolWidgetBase::InitializeInputs() { + if (mFilter) { + int j=0; + mToolInputSelectionWidget->SetToolTip(QString("%1").arg(mFilter->GetAvailableImageTypes().c_str())); + for(unsigned int i=0; iGetSlicerManagers().size(); i++) { + vvImage * s = mMainWindowBase->GetSlicerManagers()[i]->GetImage(); + if (mFilter->CheckImageType(s->GetNumberOfDimensions(), + s->GetNumberOfScalarComponents(), + s->GetScalarTypeAsString())) { + mSlicerManagersCompatible.push_back(mMainWindowBase->GetSlicerManagers()[i]); + if ((int)i == mMainWindowBase->GetSlicerManagerCurrentIndex()) mCurrentCompatibleIndex = j; + j++; + } + } + } + else { + mSlicerManagersCompatible = mMainWindowBase->GetSlicerManagers(); + mCurrentCompatibleIndex = mMainWindowBase->GetSlicerManagerCurrentIndex(); + } + mToolInputSelectionWidget->Initialize(mSlicerManagersCompatible, + mCurrentCompatibleIndex); + mIsInitialized = true; +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvToolWidgetBase::InputIsSelected() { + // Common + int index = mToolInputSelectionWidget->GetSelectedInputIndex(); + mCurrentSlicerManager = mSlicerManagersCompatible[index]; + mToolWidget->setEnabled(true); + if (!mCurrentSlicerManager) close(); + InputIsSelected(mCurrentSlicerManager); +} +//------------------------------------------------------------------------------ + diff --git a/vv/vvToolWidgetBase.h b/vv/vvToolWidgetBase.h new file mode 100644 index 0000000..225b5f2 --- /dev/null +++ b/vv/vvToolWidgetBase.h @@ -0,0 +1,71 @@ +/*========================================================================= + + Program: vv + Module: $RCSfile: vvToolWidgetBase.h,v $ + Language: C++ + Date: $Date: 2010/02/24 11:43:37 $ + Version: $Revision: 1.1 $ + Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) + + Copyright (C) 2010 + Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + CREATIS http://www.creatis.insa-lyon.fr + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + =========================================================================*/ + +#ifndef VVTOOLWIDGETBASE_H +#define VVTOOLWIDGETBASE_H + +#include +#include "ui_vvToolWidgetBase.h" +#include "clitkImageToImageGenericFilter.h" +class vvMainWindowBase; + +//------------------------------------------------------------------------------ +class vvToolWidgetBase: + public QDialog, + public Ui::vvToolWidgetBase +{ + Q_OBJECT + public: + + vvToolWidgetBase(vvMainWindowBase * parent=0, Qt::WindowFlags f=0); + ~vvToolWidgetBase(); + + virtual void InputIsSelected(vvSlicerManager *m) = 0; + +public slots: + virtual void apply() = 0; + void InputIsSelected(); + void AnImageIsBeingClosed(vvSlicerManager * m); + void show(); + virtual bool close(); + +protected: + void InitializeInputs(); + Ui::vvToolWidgetBase ui; + clitk::ImageToImageGenericFilterBase * mFilter; + vvMainWindowBase * mMainWindowBase; + std::vector mSlicerManagersCompatible; + vvSlicerManager * mCurrentSlicerManager; + int mCurrentCompatibleIndex; + vvImage * mCurrentImage; + bool mIsInitialized; + +}; // end class vvToolWidgetBase +//------------------------------------------------------------------------------ + +#endif + -- 2.45.1