]> Creatis software - clitk.git/commitdiff
- now work in 3D with
authordsarrut <dsarrut>
Thu, 27 May 2010 09:31:48 +0000 (09:31 +0000)
committerdsarrut <dsarrut>
Thu, 27 May 2010 09:31:48 +0000 (09:31 +0000)
vv/vvROIActor.cxx
vv/vvROIActor.h
vv/vvStructureSetActor.cxx
vv/vvStructureSetActor.h
vv/vvToolStructureSetManager.cxx
vv/vvToolStructureSetManager.h

index 2ffde5d62946e2e9e6de6c8bb87f4d8562a93c7b..382edf9f788452d88d7ac2f39cc5b5fcaa4ce422 100644 (file)
   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
   ======================================================================-====*/
 
+// vv
 #include "vvROIActor.h"
 #include "vvImageContour.h"
 #include "vvSlicerManager.h"
 #include "vvBinaryImageOverlayActor.h"
+
+// vtk
 #include <vtkImageActor.h>
 #include <vtkCamera.h>
 #include <vtkRenderer.h>
-//#include <vtkRenderWindow.h>
 #include <vtkMarchingSquares.h>
 #include <vtkImageClip.h>
 #include <vtkImageData.h>
@@ -39,7 +41,7 @@ vvROIActor::vvROIActor()
   mIsContourVisible = false;
   mOpacity = 0.7;
   mIsSelected = false;
-  mContourWidth = 2;
+  mContourWidth = 1;
   mContourColor.resize(3);
 }
 //------------------------------------------------------------------------------
@@ -74,6 +76,23 @@ void vvROIActor::SetSlicerManager(vvSlicerManager * s) {
 //------------------------------------------------------------------------------
 
 
+//------------------------------------------------------------------------------
+void vvROIActor::UpdateImage()
+{
+  for(unsigned int i= 0; i<mOverlayActors.size(); i++) {
+    mOverlayActors[i]->HideActors();
+    delete mOverlayActors[i];
+  }
+  for(unsigned int i= 0; i<mImageContour.size(); i++) {
+    mImageContour[i]->HideActors();
+    delete mImageContour[i];
+  }
+  Initialize();
+  Update(); // No Render
+}
+//------------------------------------------------------------------------------
+
+
 //------------------------------------------------------------------------------
 void vvROIActor::SetVisible(bool b)
 {
@@ -85,7 +104,7 @@ void vvROIActor::SetVisible(bool b)
     for(unsigned int i= 0; i<mOverlayActors.size(); i++)
       mOverlayActors[i]->ShowActors();
   }
-  Update();
+  Update(); // No Render
 }
 //------------------------------------------------------------------------------
 
@@ -94,18 +113,16 @@ void vvROIActor::SetVisible(bool b)
 void vvROIActor::SetContourVisible(bool b) {
   mIsContourVisible = b;
   if (!b) { // remove actor
-    for(unsigned int i= 0; i<mOverlayActors.size(); i++) {
-      //      mOverlayActors[i]->HideActors();
+    for(unsigned int i= 0; i<mImageContour.size(); i++) {
       mImageContour[i]->HideActors();
     }
   }
   else {
-    for(unsigned int i= 0; i<mOverlayActors.size(); i++) {
-      // mOverlayActors[i]->ShowActors();
+    for(unsigned int i= 0; i<mImageContour.size(); i++) {
       mImageContour[i]->ShowActors();
     }
   }
-  Update();
+  Update(); // No Render
 }
 //------------------------------------------------------------------------------
 
@@ -133,10 +150,9 @@ void vvROIActor::Initialize() {
       mImageContour.push_back(new vvImageContour);
       mImageContour[i]->SetSlicer(mSlicerManager->GetSlicer(i));
       mImageContour[i]->SetImage(mROI->GetImage());
-      //mImageContour[i]->setColor(1.0, 0.0, 0.0);
-      mContourColor[0] = 1.0-mROI->GetDisplayColor()[0];
-      mContourColor[1] = 1.0-mROI->GetDisplayColor()[1];
-      mContourColor[2] = 1.0-mROI->GetDisplayColor()[2];
+      mContourColor[0] = mROI->GetDisplayColor()[0];
+      mContourColor[1] = mROI->GetDisplayColor()[1];
+      mContourColor[2] = mROI->GetDisplayColor()[2];
       mImageContour[i]->SetColor(mContourColor[0], mContourColor[1], mContourColor[2]);
       mImageContour[i]->SetLineWidth(mContourWidth);
       mImageContour[i]->SetPreserveMemoryModeEnabled(true);
@@ -175,51 +191,22 @@ void vvROIActor::Update()
 void vvROIActor::UpdateSlice(int slicer, int slices)
 {
   if (!mROI->GetImage())  return;
-
-  if (!mIsVisible) return;
-
+  if ((!mIsVisible) && (!mIsContourVisible)) return; 
   if (!mSlicerManager) {
     std::cerr << "Error. No mSlicerManager ?" << std::endl;
     exit(0);
   }
 
-  // CONTOUR HERE 
-  //  DD("vvROIActor::UpdateSlice");
-  //DD(mROI->GetName());
-  //DD(mIsSelected);
-  //DD(mROI->GetBackgroundValueLabelImage());
-  if (mIsSelected) {
-    mImageContour[slicer]->Update(1.0);//mROI->GetBackgroundValueLabelImage()); 
-    //    mImageContour[slicer]->showActors();
-  }
   if (mIsContourVisible) {
-    mImageContour[slicer]->SetLineWidth(mContourWidth);
     mImageContour[slicer]->Update(mROI->GetBackgroundValueLabelImage()+1); 
-    //    mImageContour[slicer]->showActors();
   }
 
   // Refresh overlays
   mOverlayActors[slicer]->UpdateSlice(slicer, slices);
-
-  // Do not used the following line : TOO SLOW.
-  // mSlicerManager->GetSlicer(slicer)->GetRenderWindow()->Render();
 }
 //------------------------------------------------------------------------------
 
 
-//------------------------------------------------------------------------------
-// void vvROIActor::UpdateOpacity(double d) {
-//   if (d == mOpacity) return;
-//   mOpacity = d;
-//   for(unsigned int i=0; i<mOverlayActors.size(); i++) {
-//     mOverlayActors[i]->SetOpacity(d);
-//     mOverlayActors[i]->UpdateColor();
-//   }
-//   mSlicerManager->Render();
-// }
-//------------------------------------------------------------------------------
-
-
 //------------------------------------------------------------------------------
 void vvROIActor::SetOpacity(double d)
 {
@@ -256,7 +243,8 @@ void vvROIActor::UpdateColor() {
   for(unsigned int i=0; i<mImageContour.size(); i++) {
     mImageContour[i]->SetLineWidth(mContourWidth);
     mImageContour[i]->SetColor(mContourColor[0], mContourColor[1], mContourColor[2]);
-    mImageContour[i]->Update(mROI->GetBackgroundValueLabelImage()+1);
+    if (mIsContourVisible)
+      mImageContour[i]->Update(mROI->GetBackgroundValueLabelImage()+1);
   }
 }
 //------------------------------------------------------------------------------
@@ -273,6 +261,7 @@ double vvROIActor::GetOpacity()
 //------------------------------------------------------------------------------
 void vvROIActor::SetSelected(bool b)
 {
+  DD(" Not used yet");
   mIsSelected = b;
   if (b) {
     for(int i=0; i<mSlicerManager->NumberOfSlicers(); i++) {
index a7cbd5c03d62d7872c8244f3e302757f73ca4895..f6a7b2f4d773d11b784f3e176818222beaf0b78b 100644 (file)
@@ -54,6 +54,7 @@ class vvROIActor: public QObject {
 public slots:
   void UpdateSlice(int slicer, int slices);
   void UpdateColor();
+  void UpdateImage();
 
  protected:
   clitk::DicomRT_ROI * mROI;
index ce0060d4e72bf10fe9d462ce98d534774eecfe32..09fc245758ae8d26de3e84140c424f5df31feb73 100644 (file)
@@ -34,6 +34,22 @@ vvStructureSetActor::~vvStructureSetActor()
 //------------------------------------------------------------------------------
 
 
+//------------------------------------------------------------------------------
+int vvStructureSetActor::GetNumberOfROIs() 
+{ 
+  return mROIActors.size(); 
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+std::vector<vvROIActor*> & vvStructureSetActor::GetROIList() 
+{ 
+  return mROIActors; 
+}
+//------------------------------------------------------------------------------
+
+
 //------------------------------------------------------------------------------
 void vvStructureSetActor::SetStructureSet(clitk::DicomRT_StructureSet * s)
 {
@@ -72,15 +88,21 @@ void vvStructureSetActor::CreateNewROIActor(int n)
     exit(0);
   }
 
+  // If already exist : delete it
+  int old = -1;
+  if (mMapROIIndex.find(n) != mMapROIIndex.end()) {
+    delete mROIActors[mMapROIIndex[n]];
+    old = mMapROIIndex[n];
+  }
+
   // Add ROI Actors
   vvROIActor * actor = new vvROIActor;
-  mROIActors.push_back(actor);
+  if (old == -1) mROIActors.push_back(actor);
+  else mROIActors[old] = actor;
   actor->SetROI(roi);
   actor->SetSlicerManager(mSlicerManager);
   actor->Initialize();
   mMapROIIndex[n] = mROIActors.size()-1;
-
-  //  actor->Update();
 }
 //------------------------------------------------------------------------------
 
index 9a6f95a082cc59e6ec03e818690adbfca4887cf6..19b98da2bc88da907e391e371991af1b8f5c7969 100644 (file)
@@ -36,8 +36,8 @@ class vvStructureSetActor: public QObject {
   void SetSlicerManager(vvSlicerManager * s);
   void CreateNewROIActor(int n);
   vvROIActor* GetROIActor(int n);
-  int GetNumberOfROIs() { return mROIActors.size(); }
-  std::vector<vvROIActor*> & GetROIList() { return mROIActors; }
+  int GetNumberOfROIs();
+  std::vector<vvROIActor*> & GetROIList();
   
  protected:
   clitk::DicomRT_StructureSet * mStructureSet;
index f311abcd2e51f8b5b447a9396ecd4fa52076a698..a698e3c5e4ca95a80ea07c5eab6dc38ff66654c2 100644 (file)
   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
   ======================================================================-====*/
 
+// vv
 #include "vvToolStructureSetManager.h"
 #include "vvImageReader.h"
 #include "vvStructureSetActor.h"
 #include "vvSlicer.h"
 #include "vvROIActor.h"
 
+// Qt
 #include <QFileDialog>
 #include <QMessageBox>
 #include <QColorDialog>
 
+// vtk
 #include <vtkLookupTable.h>
 #include <vtkRenderWindow.h>
 
@@ -37,18 +40,42 @@ ADD_TOOL(vvToolStructureSetManager);
 
 //------------------------------------------------------------------------------
 vvToolStructureSetManager::vvToolStructureSetManager(vvMainWindowBase * parent, Qt::WindowFlags f)
-  :vvToolWidgetBase(parent, f),
+  :vvToolWidgetBase(parent, f),//, true),
    vvToolBase<vvToolStructureSetManager>(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<vvToolStructureSetManager>::GetInstance()->mToolIconFilename));
+  DD(this->width());
+  */
+  // ---------------
+
   mTree->clear();
   mCurrentStructureSet = NULL;
   mCurrentStructureSetIndex = -1;
   mGroupBoxROI->setEnabled(false);
   mCurrentROIActor = NULL;
   mIsAllVisibleEnabled = false;
+  mNumberOfVisibleROI = 0;
+  mNumberOfVisibleContourROI = 0;
   mDefaultLUTColor = vtkLookupTable::New();
   for(unsigned int i=0; i<mDefaultLUTColor->GetNumberOfTableValues(); i++) {
     double r = (rand()/(RAND_MAX+1.0));
@@ -68,7 +95,6 @@ vvToolStructureSetManager::vvToolStructureSetManager(vvMainWindowBase * parent,
 //------------------------------------------------------------------------------
 vvToolStructureSetManager::~vvToolStructureSetManager()
 {
-  DD("vvToolStructureSetManager DESTRUCTOR");
 }
 //------------------------------------------------------------------------------
 
@@ -87,19 +113,17 @@ void vvToolStructureSetManager::Initialize() {
 //------------------------------------------------------------------------------
 void vvToolStructureSetManager::InputIsSelected(vvSlicerManager *m)
 {
-  // Hide the input selector
-  QList<int> s;
-  s.push_back(0);
-  s.push_back(1);
-  splitter->setSizes(s);
+  // 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();
   // Connect open menus
-  //  connect(mOpenComboBox, SIGNAL(activated(int)), this, SLOT(open(int)));
   connect(mOpenBinaryButton, SIGNAL(clicked()), this, SLOT(OpenBinaryImage()));
-  DD(mCurrentImage->GetNumberOfDimensions());
-
-  // Seems that the following is not needed to refresh ...
-  //  connect(m, SIGNAL(LeftButtonReleaseSignal(int)), SLOT(LeftButtonReleaseEvent(int)));
-
   connect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItemChangedInTree()));
   connect(mCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleROIToggled(bool)));
   connect(mOpacitySlider, SIGNAL(valueChanged(int)), this, SLOT(OpacityChanged(int)));
@@ -107,25 +131,9 @@ void vvToolStructureSetManager::InputIsSelected(vvSlicerManager *m)
   connect(mContourCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleContourROIToggled(bool)));  
   connect(mChangeContourColorButton, SIGNAL(clicked()), this, SLOT(ChangeContourColor()));
   connect(mContourWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeContourWidth(int)));
-
-  connect(mCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleROIToggled(bool)));
-  connect(mOpacitySliderAll, SIGNAL(valueChanged(int)), this, SLOT(AllOpacityChanged(int)));
-  connect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool)));  
-}
-//------------------------------------------------------------------------------
-
-
-//------------------------------------------------------------------------------
-void vvToolStructureSetManager::LeftButtonReleaseEvent(int slicer)
-{
-  DD("vvToolStructureSetManager::UpdateSlice");
-  //DD(slicer);
-  //DD(view);
-  //DD(slices);
-  for(int i=0; i<mCurrentSlicerManager->NumberOfSlicers(); i++) {
-    if (i != slicer);
-    mCurrentSlicerManager->GetSlicer(i)->GetRenderWindow()->Render();
-  }
+  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)));
 }
 //------------------------------------------------------------------------------
 
@@ -147,40 +155,17 @@ void vvToolStructureSetManager::AddRoiInTreeWidget(clitk::DicomRT_ROI * roi, QTr
   QTreeWidgetItem * w = new QTreeWidgetItem(ww);
   w->setText(0, QString("%1").arg(roi->GetROINumber()));
   w->setText(1, QString("%1").arg(roi->GetName().c_str()));
-  //  w->setText(1, QString("%1").arg(roi->GetName().c_str()));
   QBrush brush(QColor(roi->GetDisplayColor()[0]*255, roi->GetDisplayColor()[1]*255, roi->GetDisplayColor()[2]*255));
   brush.setStyle(Qt::SolidPattern);
-  //  for(int i=0; i<w->columnCount (); i++) {
   w->setBackground(2, brush);
-  //}
   mMapROIToTreeWidget[roi] = w;
   mMapTreeWidgetToROI[w] = roi;
-  // Connect ROI TreeWidget
-  // TODO
 }
 //------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------
 void vvToolStructureSetManager::UpdateStructureSetInTreeWidget(int index, clitk::DicomRT_StructureSet * s) {
-
-  /* ==> Please, keep this comment (if need several SS)
-     QTreeWidgetItem * ss;
-     if (mMapStructureSetIndexToTreeWidget.find(index) == mMapStructureSetIndexToTreeWidget.end()) {
-     // Main row item
-     ss = new QTreeWidgetItem(mTree);
-     //  ss->setFlags(Qt::ItemIsSelectable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsTristate);
-     ss->setText(0, QString("S%1").arg(index));
-     ss->setText(1, QString("%1").arg(s->GetLabel().c_str()));
-     // Insert in list
-     mMapStructureSetIndexToTreeWidget[index] = ss;
-    
-     // Connect Structure TreeWidget
-     // TODO
-     }
-     else ss = mMapStructureSetIndexToTreeWidget[index];
-  */
-
   // Insert ROI
   const std::vector<clitk::DicomRT_ROI*> & rois = s->GetListOfROI();
   for(unsigned int i=0; i<rois.size(); i++) {
@@ -193,17 +178,14 @@ void vvToolStructureSetManager::UpdateStructureSetInTreeWidget(int index, clitk:
 
 //------------------------------------------------------------------------------
 int vvToolStructureSetManager::AddStructureSet(clitk::DicomRT_StructureSet * mStructureSet) {
-
   // Create actor for this SS
   vvStructureSetActor * mStructureSetActor = new vvStructureSetActor;
   mStructureSetActor->SetStructureSet(mStructureSet);
   mStructureSetActor->SetSlicerManager(mCurrentSlicerManager);
-
   // Insert in lists and get index
   mStructureSetsList.push_back(mStructureSet);
   mStructureSetActorsList.push_back(mStructureSetActor);
   int index = mStructureSetsList.size()-1;
-
   // Return index
   return index;
 }
@@ -212,15 +194,11 @@ int vvToolStructureSetManager::AddStructureSet(clitk::DicomRT_StructureSet * mSt
 
 //------------------------------------------------------------------------------
 void vvToolStructureSetManager::OpenBinaryImage() {
-  //  DD("openBinaryImage");
-  // Select current StructureSet (or create)
   int index;
-  //  DD(mCurrentStructureSetIndex);
   if (mCurrentStructureSet == NULL) {
     if (mStructureSetsList.size() == 0) { // Create a default SS
       clitk::DicomRT_StructureSet * mStructureSet = new clitk::DicomRT_StructureSet;
       index = AddStructureSet(mStructureSet);
-      //DD(index);
     }
     else { // Get first SS
       index = 0;
@@ -228,14 +206,9 @@ void vvToolStructureSetManager::OpenBinaryImage() {
   } else {
     index = mCurrentStructureSetIndex;
   }
-  //  DD(index);
-  // TODO -> SET THIS SS AS CURRENT
   mCurrentStructureSet = mStructureSetsList[index];
   mCurrentStructureSetActor = mStructureSetActorsList[index];
   mCurrentStructureSetIndex = index;
-  //  DD(mCurrentStructureSetIndex);
-  //DD(mCurrentStructureSet->GetName());
-
   // Open images
   QString Extensions = "Images files ( *.mhd *.hdr *.his)";
   Extensions += ";;All Files (*)";
@@ -243,13 +216,9 @@ void vvToolStructureSetManager::OpenBinaryImage() {
     QFileDialog::getOpenFileNames(this,tr("Open binary image"),
                                  mMainWindowBase->GetInputPathName(),Extensions);
   if (filename.size() == 0) return;
-
   std::vector<int> mLoadedROIIndex;
   for(int i=0; i<filename.size(); i++) {
-    //DD(filename[i].toStdString());
-
     // Open Image
-    //init the progress events
     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
     vvImageReader * mReader = new vvImageReader;
     std::vector<std::string> filenames;
@@ -267,13 +236,10 @@ void vvToolStructureSetManager::OpenBinaryImage() {
       return;
     }
     vvImage::Pointer binaryImage = mReader->GetOutput();
-    //  delete mReader;
 
     // Check Dimension
     int dim = mCurrentImage->GetNumberOfDimensions();
-    //DD(dim);
     int bin_dim = binaryImage->GetNumberOfDimensions();
-    //DD(bin_dim);
     if (dim < bin_dim) {  ////////// TO CHANGE FOR 3D/4D
       std::ostringstream os;
       os << "Error. Loaded binary image is " << bin_dim
@@ -284,18 +250,12 @@ void vvToolStructureSetManager::OpenBinaryImage() {
 
     // Add a new roi to the structure
     int n = mCurrentStructureSet->AddBinaryImageAsNewROI(binaryImage, filename[i].toStdString());
-    //DD(n);
     mLoadedROIIndex.push_back(n);
-
     mCurrentStructureSet->GetROI(n)->SetBackgroundValueLabelImage(mBackgroundValueSpinBox->value());
 
-    // Change color NEED DEFAULT COLOR LIST
-    //DD(mDefaultLUTColor->GetNumberOfTableValues ());
+    // Change color
     if (n<mDefaultLUTColor->GetNumberOfTableValues ()) {
       double * color = mDefaultLUTColor->GetTableValue(n % mDefaultLUTColor->GetNumberOfTableValues ());
-      //DD(color[0]);
-      //DD(color[1]);
-      //DD(color[2]);
       mCurrentStructureSet->GetROI(n)->SetDisplayColor(color[0], color[1], color[2]);
     }
 
@@ -305,6 +265,9 @@ void vvToolStructureSetManager::OpenBinaryImage() {
     // CheckBox for "All"
     if (mCurrentStructureSetActor->GetROIActor(n)->IsVisible())
       mNumberOfVisibleROI++;
+    if (mCurrentStructureSetActor->GetROIActor(n)->IsContourVisible())
+      mNumberOfVisibleContourROI++;
+    UpdateAllROIStatus();
   } // end loop on n selected filenames
 
   // Update the TreeWidget
@@ -315,19 +278,37 @@ void vvToolStructureSetManager::OpenBinaryImage() {
   }
   for(int i=0; i<mCurrentSlicerManager->NumberOfSlicers(); i++) {
     mCurrentSlicerManager->GetSlicer(i)->Render();
-  }
-  
+  }  
 }
 //------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------
-void vvToolStructureSetManager::apply() {
+void vvToolStructureSetManager::apply() 
+{
   close();
 }
 //------------------------------------------------------------------------------
 
 
+//------------------------------------------------------------------------------
+bool vvToolStructureSetManager::close()
+{
+  mCheckBoxShowAll->setCheckState(Qt::Unchecked);
+  mContourCheckBoxShowAll->setCheckState(Qt::Unchecked);
+  if (mCurrentSlicerManager) mCurrentSlicerManager->Render();
+  if (mCurrentStructureSetActor) {
+    for(int i=0; i<mCurrentStructureSetActor->GetNumberOfROIs(); i++) {
+      mCurrentStructureSetActor->GetROIList()[i]->SetVisible(false);
+      mCurrentStructureSetActor->GetROIList()[i]->SetContourVisible(false);
+      delete mCurrentStructureSetActor->GetROIList()[i];
+    }
+  }
+  return vvToolWidgetBase::close();
+}
+//------------------------------------------------------------------------------
+
+
 //------------------------------------------------------------------------------
 // CURRENT ROI INTERACTION
 //------------------------------------------------------------------------------
@@ -337,23 +318,21 @@ void vvToolStructureSetManager::apply() {
 void vvToolStructureSetManager::SelectedItemChangedInTree() {
   // Search which roi is selected
   QList<QTreeWidgetItem *> l = mTree->selectedItems();
-  if (l.size() == 0) return;
+  if (l.size() == 0) {
+    mCurrentROIActor = NULL;
+    mCurrentROI = NULL;
+    mGroupBoxROI->setEnabled(false);
+    return;
+  }
   QTreeWidgetItem * w = l[0];
   if (mMapTreeWidgetToROI.find(w) == mMapTreeWidgetToROI.end()) {
     mCurrentROIActor = NULL;
     mCurrentROI = NULL;
     mGroupBoxROI->setEnabled(false);
-    return; // Search for SS (first)
+    return;
   }
   clitk::DicomRT_ROI * roi = mMapTreeWidgetToROI[w];
-  //  DD(roi->GetName());
-
   // Get selected roi actor
-  if (mCurrentROIActor != NULL) {
-    mCurrentROIActor->SetSelected(false);
-    mCurrentROIActor->Update();
-  }
-
   vvROIActor * actor = mStructureSetActorsList[mCurrentStructureSetIndex]->GetROIActor(roi->GetROINumber());
   mCurrentROI = roi;
   mCurrentROIActor = actor;
@@ -372,33 +351,51 @@ void vvToolStructureSetManager::SelectedItemChangedInTree() {
   mOpacitySpinBox->setValue((int)lrint(actor->GetOpacity()*100));
   connect(mOpacitySlider, SIGNAL(valueChanged(int)), 
          this, SLOT(OpacityChanged(int)));
+  actor->Update(); 
 
-  // Temporary disable selection
-  //  actor->SetSelected(true); // remove old selection  
-
-  // The following must not render !!
-  //  DD("before update");
-  actor->Update(); // To change in UpdateSelecte
-  //DD("after update");
-
+  // Final rendering
   mCurrentSlicerManager->Render();
 }
 //------------------------------------------------------------------------------
 
 
+//------------------------------------------------------------------------------
+void vvToolStructureSetManager::UpdateAllROIStatus() {
+  int nbVisible = 0;
+  int nb = mCurrentStructureSetActor->GetROIList().size();
+  for(int i=0; i<nb; i++) {
+    if (mCurrentStructureSetActor->GetROIList()[i]->IsVisible()) {
+      nbVisible++;
+    }
+  }
+
+  disconnect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int)));  
+  disconnect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool)));
+  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)));
+  connect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int)));
+}
+//------------------------------------------------------------------------------
+
 //------------------------------------------------------------------------------
 void vvToolStructureSetManager::VisibleROIToggled(bool b) {
+  if (mCurrentROIActor == NULL) return;
+  if (b == mCurrentROIActor->IsVisible()) return; // nothing to do
   mCurrentROIActor->SetVisible(b);
-  if (b) mNumberOfVisibleROI++;
-  else mNumberOfVisibleROI--;
-  //mNumberOfVisibleROI;
-  //  if (mNumberOfVisibleROI == mCurrentStructureSetIndex
+  UpdateAllROIStatus();
+  mCurrentSlicerManager->Render(); 
 }
 //------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------
 void vvToolStructureSetManager::VisibleContourROIToggled(bool b) {
+  if (mCurrentROIActor == NULL) return;
+  if (mCurrentROIActor->IsContourVisible() == b) return; // nothing to do
   mCurrentROIActor->SetContourVisible(b);
   mCurrentROIActor->UpdateColor();
   mCurrentSlicerManager->Render(); 
@@ -417,40 +414,36 @@ void vvToolStructureSetManager::OpacityChanged(int v) {
 
 
 //------------------------------------------------------------------------------
-void vvToolStructureSetManager::AllVisibleROIToggled(bool b) {
-  DD(b);
-  DD(mIsAllVisibleEnabled);
-  DD(mNumberOfVisibleROI);
-  if (b == mIsAllVisibleEnabled) return;
-  if (b) mCheckBoxShowAll->setCheckState(Qt::Checked);
-  else mCheckBoxShowAll->setCheckState(Qt::Unchecked);
-  mIsAllVisibleEnabled = b;
+void vvToolStructureSetManager::AllVisibleROIToggled(int b) {
+  bool status = false;
+  if ((mCheckBoxShowAll->checkState() == Qt::Checked) ||
+      (mCheckBoxShowAll->checkState() == Qt::PartiallyChecked))  status = true;
+
   for(int i=0; i<mCurrentStructureSetActor->GetNumberOfROIs(); i++) {
-    mCurrentStructureSetActor->GetROIList()[i]->SetVisible(b);
+    mCurrentStructureSetActor->GetROIList()[i]->SetVisible(status);
   }
-  // Update current selection
-  mCheckBoxShow->setChecked(b);
+  if (status) mCheckBoxShowAll->setCheckState(Qt::Checked);
+  else  mCheckBoxShowAll->setCheckState(Qt::Unchecked);
+  mCheckBoxShow->setChecked(status);
+  mCurrentSlicerManager->Render(); 
 }
 //------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------
 void vvToolStructureSetManager::AllVisibleContourROIToggled(bool b) {
-  /*mCurrentROIActor->SetContourVisible(b);
-    mCurrentROIActor->UpdateColor();
-    mCurrentSlicerManager->Render(); 
-  */
-}
-//------------------------------------------------------------------------------
-
-
-//------------------------------------------------------------------------------
-void vvToolStructureSetManager::AllOpacityChanged(int v) {
-  /*if (mCurrentROIActor == NULL) return;
-    mCurrentROIActor->SetOpacity((double)v/100.0);
-    mCurrentROIActor->UpdateColor();
-    mCurrentSlicerManager->Render(); 
-  */
+  bool status = false;
+  if ((mContourCheckBoxShowAll->checkState() == Qt::Checked) ||
+      (mContourCheckBoxShowAll->checkState() == Qt::PartiallyChecked))  status = true;
+  // Update current 
+  for(int i=0; i<mCurrentStructureSetActor->GetNumberOfROIs(); i++) {
+    mCurrentStructureSetActor->GetROIList()[i]->SetContourVisible(status);
+  }
+  // Update current selection
+  if (status) mContourCheckBoxShowAll->setCheckState(Qt::Checked);
+  else  mContourCheckBoxShowAll->setCheckState(Qt::Unchecked);
+  mContourCheckBoxShow->setChecked(status);
+  mCurrentSlicerManager->Render(); 
 }
 //------------------------------------------------------------------------------
 
@@ -470,10 +463,7 @@ void vvToolStructureSetManager::ChangeColor() {
                       mCurrentROI->GetDisplayColor()[1]*255,
                       mCurrentROI->GetDisplayColor()[2]*255));
   brush.setStyle(Qt::SolidPattern);
-  //  for(int i=0; i<w->columnCount (); i++) {
   w->setBackground(2, brush);
-  //}
-  
   // Render
   mCurrentSlicerManager->Render();
 }
@@ -504,9 +494,21 @@ void vvToolStructureSetManager::ChangeContourWidth(int n) {
 
 
 //------------------------------------------------------------------------------
-//void vvToolStructureSetManager::getActorFromROI() {
-//  mStructureSetActorsList[mCurrentStructureSetIndex]->GetROIActor(n);
-//}
+void vvToolStructureSetManager::ReloadCurrentROI() {
+  // Reload image
+  vvImageReader * mReader = new vvImageReader;
+  mReader->SetInputFilename(mCurrentROI->GetFilename());
+  mReader->Update(IMAGE);
+  if (mReader->GetLastError() != "") {
+    QMessageBox::information(mMainWindowBase, tr("Sorry, error. Could not reload"), mReader->GetLastError().c_str());
+    return;
+  }
+  mCurrentROI->SetImage(mReader->GetOutput());
+  
+  // Update visu"
+  mCurrentROIActor->UpdateImage();
+  mCurrentSlicerManager->Render();    
+}
 //------------------------------------------------------------------------------
 
 
index 0cd747345e302d85df99a1b0055040cfa4ba9e77..e77f127e09bdea58f68b8ed1c36c1b06e68df1c5 100644 (file)
@@ -49,7 +49,6 @@ class vvToolStructureSetManager:
 public slots:
   virtual void apply();
   void Open(int type);
-  void LeftButtonReleaseEvent(int slicer);
   void OpenBinaryImage();
   void SelectedItemChangedInTree();
   void VisibleROIToggled(bool b);
@@ -58,9 +57,9 @@ public slots:
   void ChangeColor();
   void ChangeContourColor();
   void ChangeContourWidth(int n);
-  void AllVisibleROIToggled(bool b);
+  void AllVisibleROIToggled(int b);
   void AllVisibleContourROIToggled(bool b);
-  void AllOpacityChanged(int v);
+  void ReloadCurrentROI();
 
  protected:
   Ui::vvToolStructureSetManager ui;
@@ -70,17 +69,19 @@ public slots:
   clitk::DicomRT_ROI * mCurrentROI;
   vvROIActor * mCurrentROIActor;
   vtkLookupTable * mDefaultLUTColor;
+  bool mIsAllVisibleEnabled;
+  int mNumberOfVisibleROI;
+  int mNumberOfVisibleContourROI;
+  std::vector<clitk::DicomRT_StructureSet*>        mStructureSetsList;
+  std::vector<vvStructureSetActor *>               mStructureSetActorsList;
+  std::map<int, QTreeWidgetItem *>                 mMapStructureSetIndexToTreeWidget;
+  std::map<clitk::DicomRT_ROI*, QTreeWidgetItem *> mMapROIToTreeWidget;
+  std::map<QTreeWidgetItem *, clitk::DicomRT_ROI*> mMapTreeWidgetToROI;
  
   void setCurrentSelectedROI(clitk::DicomRT_ROI * roi);
+  void UpdateAllROIStatus();
+  virtual bool close();
  
-  std::vector<clitk::DicomRT_StructureSet*> mStructureSetsList;
-  std::vector<vvStructureSetActor *> mStructureSetActorsList;
-  std::map<int, QTreeWidgetItem *> mMapStructureSetIndexToTreeWidget;
-  std::map<clitk::DicomRT_ROI*, QTreeWidgetItem *> mMapROIToTreeWidget;
-  std::map<QTreeWidgetItem *, clitk::DicomRT_ROI*> mMapTreeWidgetToROI;
-  bool mIsAllVisibleEnabled;
-  int mNumberOfVisibleROI;
-
 }; // end class vvToolStructureSetManager
 //------------------------------------------------------------------------------