From f66c3f22b18229b8a3540c4437886fac388ec8a3 Mon Sep 17 00:00:00 2001 From: dsarrut Date: Wed, 30 Jun 2010 06:16:33 +0000 Subject: [PATCH] display ROI --- vv/vvStructureSetActor.cxx | 3 +- vv/vvStructureSetActor.h | 2 +- vv/vvToolStructureSetManager.cxx | 284 +++++++++++++++++++++++-------- vv/vvToolStructureSetManager.h | 21 ++- 4 files changed, 236 insertions(+), 74 deletions(-) diff --git a/vv/vvStructureSetActor.cxx b/vv/vvStructureSetActor.cxx index 09fc245..b6f08f8 100644 --- a/vv/vvStructureSetActor.cxx +++ b/vv/vvStructureSetActor.cxx @@ -79,7 +79,7 @@ vvROIActor * vvStructureSetActor::GetROIActor(int n) //------------------------------------------------------------------------------ -void vvStructureSetActor::CreateNewROIActor(int n) +void vvStructureSetActor::CreateNewROIActor(int n, bool modeBG) { // Check clitk::DicomRT_ROI * roi = mStructureSet->GetROI(n); @@ -99,6 +99,7 @@ void vvStructureSetActor::CreateNewROIActor(int n) vvROIActor * actor = new vvROIActor; if (old == -1) mROIActors.push_back(actor); else mROIActors[old] = actor; + actor->SetBGMode(modeBG); actor->SetROI(roi); actor->SetSlicerManager(mSlicerManager); actor->Initialize(); diff --git a/vv/vvStructureSetActor.h b/vv/vvStructureSetActor.h index 19b98da..ce2434a 100644 --- a/vv/vvStructureSetActor.h +++ b/vv/vvStructureSetActor.h @@ -34,7 +34,7 @@ class vvStructureSetActor: public QObject { void SetStructureSet(clitk::DicomRT_StructureSet * s); void SetSlicerManager(vvSlicerManager * s); - void CreateNewROIActor(int n); + void CreateNewROIActor(int n, bool modeBG=true); vvROIActor* GetROIActor(int n); int GetNumberOfROIs(); std::vector & GetROIList(); diff --git a/vv/vvToolStructureSetManager.cxx b/vv/vvToolStructureSetManager.cxx index a698e3c..257f57e 100644 --- a/vv/vvToolStructureSetManager.cxx +++ b/vv/vvToolStructureSetManager.cxx @@ -38,37 +38,30 @@ ADD_TOOL(vvToolStructureSetManager); //------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ -vvToolStructureSetManager::vvToolStructureSetManager(vvMainWindowBase * parent, Qt::WindowFlags f) - :vvToolWidgetBase(parent, f),//, true), - vvToolBase(parent), - Ui::vvToolStructureSetManager() +int vvToolStructureSetManager::m_NumberOfTool = 0; +std::vector vvToolStructureSetManager::mListOfInputs; +std::map vvToolStructureSetManager::mListOfOpenTool; + +//------------------------------------------------------------------------------ +vvToolStructureSetManager::vvToolStructureSetManager(vvMainWindowBase * parent, + Qt::WindowFlags f, + vvSlicerManager * current): + vvToolWidgetBase(parent, f), + // if Qt::Widget -> No dialog in this case (in tab) ; PB = "invisible widget on menu" ! + // if "f" normal widget + vvToolBase(parent), + Ui::vvToolStructureSetManager() { - // Setup the UI - /* - QWidget * aw = new QWidget(parent, f); - QVBoxLayout * verticalLayout = new QVBoxLayout(aw); - verticalLayout->addWidget(mToolInputSelectionWidget); - verticalLayout->addWidget(mToolWidget); - aw->setLayout(verticalLayout); - */ Ui_vvToolStructureSetManager::setupUi(mToolWidget); - // ---------------- - // Essai TAB - /* - //int a = mMainWindowBase->GetTab()->addTab(mToolWidget, "Toto"); - int a = mMainWindowBase->GetTab()->addTab(aw, "Toto"); - - // essai avec mToolWidget ? ok mais frame à cacher ... - // Changer le construceur par defautl de widgetbase -> pas dialog, pas parent (cf doc) - mMainWindowBase->GetTab()->setCurrentIndex(a); - mMainWindowBase->GetTab()->setTabIcon(a, QIcon(vvToolCreator::GetInstance()->mToolIconFilename)); - DD(this->width()); - */ - // --------------- - + // this->setFixedWidth(120); + m_NumberOfTool++; + mCurrentStructureSetActor = 0; + connect(mCloseButton, SIGNAL(clicked()), this, SLOT(close())); + mCloseButton->setVisible(false); mTree->clear(); + mTree->header()->resizeSection(0, 30); + mMainWindowBase->GetTab()->setTabIcon(mTabNumber, GetToolIcon()); mCurrentStructureSet = NULL; mCurrentStructureSetIndex = -1; mGroupBoxROI->setEnabled(false); @@ -87,7 +80,18 @@ vvToolStructureSetManager::vvToolStructureSetManager(vvMainWindowBase * parent, #include "vvDefaultLut.h" // Add input selector - AddInputSelector("Select image"); + if (current == NULL) { + MustOpenDialogWhenCreated = true; + AddInputSelector("Select image"); + } + else { + MustOpenDialogWhenCreated = false; + buttonBox->setEnabled(true); + mCurrentSlicerManager = current; + mCurrentImage = mCurrentSlicerManager->GetImage(); + mToolWidget->setEnabled(true); + InputIsSelected(mCurrentSlicerManager); + } } //------------------------------------------------------------------------------ @@ -95,15 +99,17 @@ vvToolStructureSetManager::vvToolStructureSetManager(vvMainWindowBase * parent, //------------------------------------------------------------------------------ vvToolStructureSetManager::~vvToolStructureSetManager() { + m_NumberOfTool--; } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ +// STATIC void vvToolStructureSetManager::Initialize() { SetToolName("ROIManager"); SetToolMenuName("Display ROI"); - SetToolIconFilename(":/common/icons/ducky.png"); + SetToolIconFilename(":/common/icons/lung-overlay.png"); SetToolTip("Display ROI from label image."); SetToolExperimental(true); } @@ -113,15 +119,25 @@ void vvToolStructureSetManager::Initialize() { //------------------------------------------------------------------------------ void vvToolStructureSetManager::InputIsSelected(vvSlicerManager *m) { + //int mTabNumber = parent->GetTab()->addTab(this, ""); + // this->setFixedWidth(120); + //this->setPreferedHeight(441); // Refuse if 4D if (mCurrentImage->GetNumberOfDimensions() != 3) { QMessageBox::information(this,tr("Sorry only 3D yet"), tr("Sorry only 3D yet")); close(); - // return; } // Hide selector HideInputSelector(); // splitter - // mToolInputSelectionWidget->hide(); + mToolInputSelectionWidget->hide(); + mLabelInputInfo->setText(QString("%1").arg(m->GetFileName().c_str())); + + // add to instance + // if (!isWindow()) { + mListOfInputs.push_back(mCurrentSlicerManager); + mListOfOpenTool[mCurrentSlicerManager] = this; + // } + // Connect open menus connect(mOpenBinaryButton, SIGNAL(clicked()), this, SLOT(OpenBinaryImage())); connect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItemChangedInTree())); @@ -134,6 +150,10 @@ void vvToolStructureSetManager::InputIsSelected(vvSlicerManager *m) connect(mReloadButton, SIGNAL(clicked()), this, SLOT(ReloadCurrentROI())); connect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int))); connect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool))); + + // Browse to load image + if (MustOpenDialogWhenCreated) + OpenBinaryImage(); } //------------------------------------------------------------------------------ @@ -160,6 +180,8 @@ void vvToolStructureSetManager::AddRoiInTreeWidget(clitk::DicomRT_ROI * roi, QTr w->setBackground(2, brush); mMapROIToTreeWidget[roi] = w; mMapTreeWidgetToROI[w] = roi; + mTree->resizeColumnToContents(0); + mTree->resizeColumnToContents(1); } //------------------------------------------------------------------------------ @@ -193,7 +215,8 @@ int vvToolStructureSetManager::AddStructureSet(clitk::DicomRT_StructureSet * mSt //------------------------------------------------------------------------------ -void vvToolStructureSetManager::OpenBinaryImage() { +void vvToolStructureSetManager::OpenBinaryImage() +{ int index; if (mCurrentStructureSet == NULL) { if (mStructureSetsList.size() == 0) { // Create a default SS @@ -216,7 +239,7 @@ void vvToolStructureSetManager::OpenBinaryImage() { QFileDialog::getOpenFileNames(this,tr("Open binary image"), mMainWindowBase->GetInputPathName(),Extensions); if (filename.size() == 0) return; - std::vector mLoadedROIIndex; + mLoadedROIIndex.clear(); for(int i=0; iGetOutput(); + AddImage(binaryImage, filename[i].toStdString(), mBackgroundValueSpinBox->value()); + } + UpdateImage(); +} +//------------------------------------------------------------------------------ - // Check Dimension - int dim = mCurrentImage->GetNumberOfDimensions(); - int bin_dim = binaryImage->GetNumberOfDimensions(); - if (dim < bin_dim) { ////////// TO CHANGE FOR 3D/4D - std::ostringstream os; - os << "Error. Loaded binary image is " << bin_dim - << "D while selected image is " << dim << "D" << std::endl; - QMessageBox::information(this,tr("Reading problem"),os.str().c_str()); - return; - } - - // Add a new roi to the structure - int n = mCurrentStructureSet->AddBinaryImageAsNewROI(binaryImage, filename[i].toStdString()); - mLoadedROIIndex.push_back(n); - mCurrentStructureSet->GetROI(n)->SetBackgroundValueLabelImage(mBackgroundValueSpinBox->value()); - - // Change color - if (nGetNumberOfTableValues ()) { - double * color = mDefaultLUTColor->GetTableValue(n % mDefaultLUTColor->GetNumberOfTableValues ()); - mCurrentStructureSet->GetROI(n)->SetDisplayColor(color[0], color[1], color[2]); - } - - // Add a new roi actor - mCurrentStructureSetActor->CreateNewROIActor(n); - - // CheckBox for "All" - if (mCurrentStructureSetActor->GetROIActor(n)->IsVisible()) - mNumberOfVisibleROI++; - if (mCurrentStructureSetActor->GetROIActor(n)->IsContourVisible()) - mNumberOfVisibleContourROI++; - UpdateAllROIStatus(); - } // end loop on n selected filenames +//------------------------------------------------------------------------------ +void vvToolStructureSetManager::UpdateImage() +{ // Update the TreeWidget - UpdateStructureSetInTreeWidget(index, mCurrentStructureSet); + UpdateStructureSetInTreeWidget(mCurrentStructureSetIndex, mCurrentStructureSet); // Render loaded ROIs (the first is sufficient) for(unsigned int i=0; iGetROIActor(mLoadedROIIndex[i])->Update(); @@ -283,6 +282,64 @@ void vvToolStructureSetManager::OpenBinaryImage() { //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +void vvToolStructureSetManager::AddImage(vvImage::Pointer binaryImage, std::string filename, double BG, bool m_modeBG) +{ + // Check current structure set + int index; + if (mCurrentStructureSet == NULL) { + if (mStructureSetsList.size() == 0) { // Create a default SS + clitk::DicomRT_StructureSet * mStructureSet = new clitk::DicomRT_StructureSet; + index = AddStructureSet(mStructureSet); + } + else { // Get first SS + index = 0; + } + } else { + index = mCurrentStructureSetIndex; + } + mCurrentStructureSet = mStructureSetsList[index]; + mCurrentStructureSetActor = mStructureSetActorsList[index]; + mCurrentStructureSetIndex = index; + + // Check Dimension + int dim = mCurrentImage->GetNumberOfDimensions(); + int bin_dim = binaryImage->GetNumberOfDimensions(); + if (dim < bin_dim) { ////////// TO CHANGE FOR 3D/4D + std::ostringstream os; + os << "Error. Loaded binary image is " << bin_dim + << "D while selected image is " << dim << "D" << std::endl; + QMessageBox::information(this,tr("Reading problem"),os.str().c_str()); + return; + } + + // Add a new roi to the structure + int n = mCurrentStructureSet->AddBinaryImageAsNewROI(binaryImage, filename); + mLoadedROIIndex.push_back(n); + if (m_modeBG) + mCurrentStructureSet->GetROI(n)->SetBackgroundValueLabelImage(BG); + else + mCurrentStructureSet->GetROI(n)->SetForegroundValueLabelImage(BG); + + // Change color + if (nGetNumberOfTableValues ()) { + double * color = mDefaultLUTColor->GetTableValue(n % mDefaultLUTColor->GetNumberOfTableValues ()); + mCurrentStructureSet->GetROI(n)->SetDisplayColor(color[0], color[1], color[2]); + } + + // Add a new roi actor + mCurrentStructureSetActor->CreateNewROIActor(n, m_modeBG); + + // CheckBox for "All" + if (mCurrentStructureSetActor->GetROIActor(n)->IsVisible()) + mNumberOfVisibleROI++; + if (mCurrentStructureSetActor->GetROIActor(n)->IsContourVisible()) + mNumberOfVisibleContourROI++; + UpdateAllROIStatus(); +} +//------------------------------------------------------------------------------ + + //------------------------------------------------------------------------------ void vvToolStructureSetManager::apply() { @@ -294,17 +351,40 @@ void vvToolStructureSetManager::apply() //------------------------------------------------------------------------------ bool vvToolStructureSetManager::close() { + return vvToolWidgetBase::close(); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvToolStructureSetManager::closeEvent(QCloseEvent *event) +{ + // DD("vvToolStructureSetManager::closeEvent()"); + std::vector::iterator iter = std::find(mListOfInputs.begin(), mListOfInputs.end(), mCurrentSlicerManager); + if (iter != mListOfInputs.end()) mListOfInputs.erase(iter); + + // DD("how delete mListOfOpenTool ???"); + mListOfOpenTool.erase(mCurrentSlicerManager); + mCheckBoxShowAll->setCheckState(Qt::Unchecked); mContourCheckBoxShowAll->setCheckState(Qt::Unchecked); - if (mCurrentSlicerManager) mCurrentSlicerManager->Render(); + if (mCurrentSlicerManager != 0) mCurrentSlicerManager->Render(); if (mCurrentStructureSetActor) { for(int i=0; iGetNumberOfROIs(); i++) { + // DD(i); mCurrentStructureSetActor->GetROIList()[i]->SetVisible(false); mCurrentStructureSetActor->GetROIList()[i]->SetContourVisible(false); delete mCurrentStructureSetActor->GetROIList()[i]; } } - return vvToolWidgetBase::close(); + + if (!isWindow()) { + if (m_NumberOfTool == 1) { + mMainWindow->GetTab()->removeTab(mTabNumber); + } + } + + event->accept(); } //------------------------------------------------------------------------------ @@ -503,6 +583,11 @@ void vvToolStructureSetManager::ReloadCurrentROI() { QMessageBox::information(mMainWindowBase, tr("Sorry, error. Could not reload"), mReader->GetLastError().c_str()); return; } + // delete mCurrentROI->GetImage(); + // DD(mCurrentROI->GetImage()->GetFirstVTKImageData()->GetDataReleased()); +// DD(mCurrentROI->GetImage()->GetFirstVTKImageData()->GetReferenceCount()); + mCurrentROI->GetImage()->GetFirstVTKImageData()->ReleaseData(); + // DD(mCurrentROI->GetImage()->GetFirstVTKImageData()->GetDataReleased()); mCurrentROI->SetImage(mReader->GetOutput()); // Update visu" @@ -512,3 +597,66 @@ void vvToolStructureSetManager::ReloadCurrentROI() { //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +void vvToolStructureSetManager::CheckInputList(std::vector & l, int & index) +{ + DD("TODO CheckInputList"); + + for(unsigned int i=0; i::iterator iter = std::find(mListOfInputs.begin(), mListOfInputs.end(), l[i]); + if (iter != mListOfInputs.end()) { + for(unsigned int j=i;jAddImage(image, "bidon.mhd", BG, m_modeBG); + tool->UpdateImage(); + // tool->show(); + return tool; + } + else { + DD("not found"); + } + + std::vector::iterator iter = + std::find(mListOfInputs.begin(), mListOfInputs.end(), m); + if (iter != mListOfInputs.end()) { + DD("found"); + DD("TODO"); + + } + else { + DD("not found"); + + // mMainWindowBase instead of NULL, should be static ? + + vvToolStructureSetManager * tool = new vvToolStructureSetManager + (CREATOR(vvToolStructureSetManager)->GetMainWindow(), Qt::Dialog, m); + + // WARNING : load list of image and selec -> to change to force mCurrentSlicerManager + + // tool->InputIsSelected(); + tool->AddImage(image, "bidon.mhd", BG, m_modeBG); + tool->UpdateImage(); + tool->show(); + return tool; + } + return NULL; +} +//------------------------------------------------------------------------------ diff --git a/vv/vvToolStructureSetManager.h b/vv/vvToolStructureSetManager.h index e77f127..db01935 100644 --- a/vv/vvToolStructureSetManager.h +++ b/vv/vvToolStructureSetManager.h @@ -14,7 +14,7 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -======================================================================-====*/ + ======================================================================-====*/ #ifndef VVTOOLSTRUCTURESETMANAGER_H #define VVTOOLSTRUCTURESETMANAGER_H @@ -35,8 +35,8 @@ class vvToolStructureSetManager: private Ui::vvToolStructureSetManager { Q_OBJECT - public: - vvToolStructureSetManager(vvMainWindowBase* parent=0, Qt::WindowFlags f=0); + public: + vvToolStructureSetManager(vvMainWindowBase* parent=0, Qt::WindowFlags f=0, vvSlicerManager * c = NULL); ~vvToolStructureSetManager(); static void Initialize(); @@ -46,6 +46,10 @@ class vvToolStructureSetManager: void UpdateStructureSetInTreeWidget(int index, clitk::DicomRT_StructureSet * s); void AddRoiInTreeWidget(clitk::DicomRT_ROI * roi, QTreeWidget * w); + static vvToolStructureSetManager * AddImage(vvSlicerManager * m, vvImage::Pointer image, double BG, bool modeBG=true); + void AddImage(vvImage::Pointer image, std::string filename, double BG, bool modeBG=true); + void UpdateImage(); + public slots: virtual void apply(); void Open(int type); @@ -61,7 +65,7 @@ public slots: void AllVisibleContourROIToggled(bool b); void ReloadCurrentROI(); - protected: +protected: Ui::vvToolStructureSetManager ui; clitk::DicomRT_StructureSet * mCurrentStructureSet; vvStructureSetActor * mCurrentStructureSetActor; @@ -77,10 +81,19 @@ public slots: std::map mMapStructureSetIndexToTreeWidget; std::map mMapROIToTreeWidget; std::map mMapTreeWidgetToROI; + std::vector mLoadedROIIndex; void setCurrentSelectedROI(clitk::DicomRT_ROI * roi); void UpdateAllROIStatus(); virtual bool close(); + virtual void closeEvent(QCloseEvent *event); + + // Management of all instances + virtual void CheckInputList(std::vector & l, int & index); + static std::vector mListOfInputs; + static std::map mListOfOpenTool; + static int m_NumberOfTool; + bool MustOpenDialogWhenCreated; }; // end class vvToolStructureSetManager //------------------------------------------------------------------------------ -- 2.47.1