]> Creatis software - clitk.git/commitdiff
Add remove one selected ROI button
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Tue, 12 Jan 2016 10:10:02 +0000 (11:10 +0100)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Tue, 12 Jan 2016 10:10:02 +0000 (11:10 +0100)
Correct Select All Contour button (ROI) behavior

common/clitkDicomRT_ROI.cxx
common/clitkDicomRT_ROI.h
vv/qt_ui/vvToolROIManager.ui
vv/vvROIActor.cxx
vv/vvToolROIManager.cxx
vv/vvToolROIManager.h

index 7bec8c51f47b1be17104b0fb16da56c22f3e9317..2e914d6314abd0b035878a37a2da3a9785cdce81 100644 (file)
@@ -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
 {
index 31d9db4d44849c2586fdbd30ab1be190cdd2fe53..80cbacc03c2ed00c13a3605cd30df9adba5244ca 100644 (file)
@@ -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<double> & GetDisplayColor() const;
index f4848dba1b53f0ae5688b3455835f86b2af38c8a..8e0d3c23864336aa29dad45e1faea6145b0861fc 100644 (file)
               </sizepolicy>
              </property>
              <property name="text">
-              <string>        </string>
+              <string/>
              </property>
             </widget>
            </item>
              </property>
             </spacer>
            </item>
+           <item>
+            <widget class="QPushButton" name="mRemoveButton">
+             <property name="text">
+              <string>1</string>
+             </property>
+             <property name="icon">
+              <iconset resource="../vvIcons.qrc">
+               <normaloff>:/common/icons/standardbutton-cancel-16.png</normaloff>:/common/icons/standardbutton-cancel-16.png</iconset>
+             </property>
+            </widget>
+           </item>
            <item>
             <widget class="QLabel" name="mROInameLabel_3">
              <property name="sizePolicy">
           <bool>false</bool>
          </property>
          <property name="text">
-          <string/>
+          <string>All</string>
          </property>
          <property name="icon">
           <iconset resource="../vvIcons.qrc">
-           <normaloff>:/common/icons/exit.png</normaloff>:/common/icons/exit.png</iconset>
+           <normaloff>:/common/icons/standardbutton-cancel-16.png</normaloff>:/common/icons/standardbutton-cancel-16.png</iconset>
          </property>
         </widget>
        </item>
index 8561a25636eb8b81a419f0c66d82b7bc7c3ca552..9755e78fba73c28eb69fed3d5a120e79a64a25f8 100644 (file)
@@ -69,8 +69,8 @@ void vvROIActor::RemoveActors()
   }  
   
   Update(true);
-  mImageContour.clear();
-  mOverlayActors.clear();
+  //mImageContour.clear();
+  //mOverlayActors.clear();
 }
 //------------------------------------------------------------------------------
 
index c092976fba89b7755d8d5547c769228cf1ed2ce0..7a2324b2eecb2d28acd726afbe58a2cd7876a15a 100644 (file)
@@ -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<QTreeWidgetItem *> 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; i<mCurrentSlicerManager->GetNumberOfSlicers(); 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<QTreeWidgetItem>(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<vvROIActor> 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; i<nb; i++) {
     if (mROIActorsList[i]->IsVisible()) {
       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) ||
index c69dc363cff92e5cafeb13d49822bb6838a486b9..1c5fa20a5ed2c94630dbc3572512edc249d2284e 100644 (file)
@@ -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<vtkLookupTable> mDefaultLUTColor;