From 197f1f1e151bf90f5555ec0dd7ebb9c8a5909a3c Mon Sep 17 00:00:00 2001 From: tbaudier Date: Tue, 12 Jan 2016 11:10:02 +0100 Subject: [PATCH] Add remove one selected ROI button Correct Select All Contour button (ROI) behavior --- common/clitkDicomRT_ROI.cxx | 8 ++++ common/clitkDicomRT_ROI.h | 1 + vv/qt_ui/vvToolROIManager.ui | 17 +++++++-- vv/vvROIActor.cxx | 4 +- vv/vvToolROIManager.cxx | 72 +++++++++++++++++++++++++++++++----- vv/vvToolROIManager.h | 4 +- 6 files changed, 91 insertions(+), 15 deletions(-) diff --git a/common/clitkDicomRT_ROI.cxx b/common/clitkDicomRT_ROI.cxx index 7bec8c5..2e914d6 100644 --- a/common/clitkDicomRT_ROI.cxx +++ b/common/clitkDicomRT_ROI.cxx @@ -73,6 +73,14 @@ int clitk::DicomRT_ROI::GetROINumber() const //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +void clitk::DicomRT_ROI::SetROINumber(int number) +{ + mNumber = number; +} +//-------------------------------------------------------------------- + + //-------------------------------------------------------------------- const std::string & clitk::DicomRT_ROI::GetName() const { diff --git a/common/clitkDicomRT_ROI.h b/common/clitkDicomRT_ROI.h index 31d9db4..80cbacc 100644 --- a/common/clitkDicomRT_ROI.h +++ b/common/clitkDicomRT_ROI.h @@ -47,6 +47,7 @@ public: std::string filename); int GetROINumber() const; + void SetROINumber(int); const std::string & GetName() const; const std::string & GetFilename() const; const std::vector & GetDisplayColor() const; diff --git a/vv/qt_ui/vvToolROIManager.ui b/vv/qt_ui/vvToolROIManager.ui index f4848db..8e0d3c2 100644 --- a/vv/qt_ui/vvToolROIManager.ui +++ b/vv/qt_ui/vvToolROIManager.ui @@ -528,7 +528,7 @@ - + @@ -545,6 +545,17 @@ + + + + 1 + + + + :/common/icons/standardbutton-cancel-16.png:/common/icons/standardbutton-cancel-16.png + + + @@ -690,11 +701,11 @@ false - + All - :/common/icons/exit.png:/common/icons/exit.png + :/common/icons/standardbutton-cancel-16.png:/common/icons/standardbutton-cancel-16.png diff --git a/vv/vvROIActor.cxx b/vv/vvROIActor.cxx index 8561a25..9755e78 100644 --- a/vv/vvROIActor.cxx +++ b/vv/vvROIActor.cxx @@ -69,8 +69,8 @@ void vvROIActor::RemoveActors() } Update(true); - mImageContour.clear(); - mOverlayActors.clear(); + //mImageContour.clear(); + //mOverlayActors.clear(); } //------------------------------------------------------------------------------ diff --git a/vv/vvToolROIManager.cxx b/vv/vvToolROIManager.cxx index c092976..7a2324b 100644 --- a/vv/vvToolROIManager.cxx +++ b/vv/vvToolROIManager.cxx @@ -48,6 +48,8 @@ ADD_TOOL(vvToolROIManager); //------------------------------------------------------------------------------ +int vvToolROIManager::nbTotalROI = 0; + //------------------------------------------------------------------------------ vvToolROIManager::vvToolROIManager(vvMainWindowBase * parent, Qt::WindowFlags f): QWidget(parent->GetTab()), @@ -213,8 +215,9 @@ void vvToolROIManager::InitializeNewTool(bool ReadStateFlag) connect(mDepthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeDepth(int))); 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))); + connect(mContourCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleContourROIToggled(int))); connect(mCloseButton, SIGNAL(clicked()), this, SLOT(close())); + connect(mRemoveButton, SIGNAL(clicked()), this, SLOT(RemoveROI())); } //------------------------------------------------------------------------------ @@ -245,6 +248,43 @@ void vvToolROIManager::AnImageIsBeingClosed(vvSlicerManager * m) } //------------------------------------------------------------------------------ +void vvToolROIManager::RemoveROI() +{ + + // Search the indice of the selected ROI + QList l = mTree->selectedItems(); + if (l.size() == 0) + return; + + QTreeWidgetItem * w = l[0]; + if (w == NULL) return; + if (w == 0) return; + if (mMapTreeWidgetToROI.find(w) == mMapTreeWidgetToROI.end()) { + return; + } + + clitk::DicomRT_ROI * roi = mMapTreeWidgetToROI[w]; + if (roi == NULL) return; + + // Get selected roi actor + int n = roi->GetROINumber(); + + disconnect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItemChangedInTree())); + mROIActorsList[n]->RemoveActors(); + mROIActorsList.erase(mROIActorsList.begin()+n); + mROIList.erase(mROIList.begin()+n); + mTreeWidgetList.erase(mTreeWidgetList.begin()+n); + + for (int i = n; i < mROIActorsList.size(); ++i) { + mROIList[i]->SetROINumber(i); + mTreeWidgetList[i].data()->setText(0, QString("%1").arg(mROIList[i]->GetROINumber())); + } + connect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItemChangedInTree())); + for(int i=0; iGetNumberOfSlicers(); i++) { + mCurrentSlicerManager->GetSlicer(i)->Render(); + } +} +//------------------------------------------------------------------------------ //------------------------------------------------------------------------------ void vvToolROIManager::close() @@ -257,6 +297,7 @@ void vvToolROIManager::close() disconnect(mChangeContourColorButton, SIGNAL(clicked()), this, SLOT(ChangeContourColor())); disconnect(mContourWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeContourWidth(int))); disconnect(mDepthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeDepth(int))); + disconnect(mRemoveButton, SIGNAL(clicked()), this, SLOT(RemoveROI())); // Remove actors for (unsigned int i = 0; i < mROIActorsList.size(); i++) { @@ -417,8 +458,9 @@ void vvToolROIManager::AddImage(vvImage * binaryImage, } // Compute roi index - int n = mROIList.size(); - + + int n = nbTotalROI; + ++nbTotalROI; // Compute the name of the new ROI // std::ostringstream oss; // oss << vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(filename)); @@ -432,7 +474,7 @@ void vvToolROIManager::AddImage(vvImage * binaryImage, // Create ROI clitk::DicomRT_ROI::Pointer roi = clitk::DicomRT_ROI::New(); - roi->SetFromBinaryImage(binaryImage, n, name, color, filename); + roi->SetFromBinaryImage(binaryImage, mROIList.size(), name, color, filename); // Add a new roi to the list mROIList.push_back(roi); @@ -460,7 +502,7 @@ void vvToolROIManager::AddImage(vvImage * binaryImage, // CheckBox for "All" if (actor->IsVisible()) mNumberOfVisibleROI++; if (actor->IsContourVisible()) mNumberOfVisibleContourROI++; - AllVisibleContourROIToggled(true); + AllVisibleContourROIToggled(1); // Add ROI in tree mTreeWidgetList.push_back(QSharedPointer(new QTreeWidgetItem(mTree))); @@ -481,7 +523,7 @@ void vvToolROIManager::AddImage(vvImage * binaryImage, // Update UpdateAllROIStatus(); - if (mCurrentImage->GetNumberOfDimensions() != 3) { + if (mCurrentImage->GetNumberOfDimensions() > 3) { //Modifications to avoid display bug with a 4D image QSharedPointer CurrentROIActorTemp; @@ -520,22 +562,31 @@ void vvToolROIManager::UpdateAllContours() void vvToolROIManager::UpdateAllROIStatus() { int nbVisible = 0; + int nbContourVisible = 0; int nb = mROIList.size(); for(int i=0; iIsVisible()) { nbVisible++; } + if (mROIActorsList[i]->IsContourVisible()) { + nbContourVisible++; + } } // change the states disconnect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int))); - disconnect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool))); + disconnect(mContourCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleContourROIToggled(int))); if (nbVisible == nb) mCheckBoxShowAll->setCheckState(Qt::Checked); else { if (nbVisible == 0) mCheckBoxShowAll->setCheckState(Qt::Unchecked); else mCheckBoxShowAll->setCheckState(Qt::PartiallyChecked); } - connect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool))); + if (nbContourVisible == nb) mContourCheckBoxShowAll->setCheckState(Qt::Checked); + else { + if (nbContourVisible == 0) mContourCheckBoxShowAll->setCheckState(Qt::Unchecked); + else mContourCheckBoxShowAll->setCheckState(Qt::PartiallyChecked); + } + connect(mContourCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleContourROIToggled(int))); connect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int))); } //------------------------------------------------------------------------------ @@ -581,6 +632,7 @@ void vvToolROIManager::SelectedItemChangedInTree() disconnect(mChangeContourColorButton, SIGNAL(clicked()), this, SLOT(ChangeContourColor())); disconnect(mContourWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeContourWidth(int))); disconnect(mDepthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeDepth(int))); + disconnect(mRemoveButton, SIGNAL(clicked()), this, SLOT(RemoveROI())); mROInameLabel->setText(roi->GetName().c_str()); mCheckBoxShow->setChecked(actor->IsVisible()); @@ -599,6 +651,7 @@ void vvToolROIManager::SelectedItemChangedInTree() connect(mChangeContourColorButton, SIGNAL(clicked()), this, SLOT(ChangeContourColor())); connect(mContourWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeContourWidth(int))); connect(mDepthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeDepth(int))); + connect(mRemoveButton, SIGNAL(clicked()), this, SLOT(RemoveROI())); // Set the current color to the selected ROI name @@ -643,6 +696,7 @@ void vvToolROIManager::VisibleContourROIToggled(bool b) if (mCurrentROIActor->IsContourVisible() == b) return; // nothing to do mCurrentROIActor->SetContourVisible(b); mCurrentROIActor->UpdateColor(); + UpdateAllROIStatus(); mCurrentSlicerManager->Render(); } //------------------------------------------------------------------------------ @@ -678,7 +732,7 @@ void vvToolROIManager::AllVisibleROIToggled(int b) //------------------------------------------------------------------------------ -void vvToolROIManager::AllVisibleContourROIToggled(bool b) +void vvToolROIManager::AllVisibleContourROIToggled(int b) { bool status = false; if ((mContourCheckBoxShowAll->checkState() == Qt::Checked) || diff --git a/vv/vvToolROIManager.h b/vv/vvToolROIManager.h index c69dc36..1c5fa20 100644 --- a/vv/vvToolROIManager.h +++ b/vv/vvToolROIManager.h @@ -64,9 +64,10 @@ class vvToolROIManager: void ChangeContourWidth(int n); void ChangeDepth(int n); void AllVisibleROIToggled(int b); - void AllVisibleContourROIToggled(bool b); + void AllVisibleContourROIToggled(int b); void ReloadCurrentROI(); void close(); + void RemoveROI(); vvSlicerManager * GetCurrentSlicerManager() { return mCurrentSlicerManager; } protected: @@ -79,6 +80,7 @@ protected: int mNumberOfVisibleROI; int mNumberOfVisibleContourROI; + static int nbTotalROI; vtkSmartPointer mDefaultLUTColor; -- 2.47.1