]> Creatis software - clitk.git/blob - vv/vvToolStructureSetManager.cxx
Memory leak hunt: vvBinaryImageOverlayActor vvImageContour vVImageReader are now...
[clitk.git] / vv / vvToolStructureSetManager.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17   ======================================================================-====*/
18
19 // vv
20 #include "vvToolStructureSetManager.h"
21 #include "vvImageReader.h"
22 #include "vvStructureSetActor.h"
23 #include "vvSlicer.h"
24 #include "vvROIActor.h"
25
26 // Qt
27 #include <QFileDialog>
28 #include <QMessageBox>
29 #include <QColorDialog>
30
31 // vtk
32 #include <vtkLookupTable.h>
33 #include <vtkRenderWindow.h>
34
35 //------------------------------------------------------------------------------
36 // Create the tool and automagically (I like this word) insert it in
37 // the main window menu.
38 ADD_TOOL(vvToolStructureSetManager);
39 //------------------------------------------------------------------------------
40
41 int vvToolStructureSetManager::m_NumberOfTool = 0;
42 std::vector<vvSlicerManager*> vvToolStructureSetManager::mListOfInputs;
43 std::map<vvSlicerManager*, vvToolStructureSetManager*> vvToolStructureSetManager::mListOfOpenTool;
44
45 //------------------------------------------------------------------------------
46 vvToolStructureSetManager::vvToolStructureSetManager(vvMainWindowBase * parent, 
47                                                      Qt::WindowFlags f, 
48                                                      vvSlicerManager * current):
49   vvToolWidgetBase(parent, f), 
50   // if Qt::Widget -> No dialog in this case (in tab) ; PB = "invisible widget on menu" !
51   // if "f" normal widget
52   vvToolBase<vvToolStructureSetManager>(parent),
53   Ui::vvToolStructureSetManager()
54 {
55   Ui_vvToolStructureSetManager::setupUi(mToolWidget);
56
57   //  this->setFixedWidth(120);
58   m_NumberOfTool++;
59   mCurrentStructureSetActor = 0;
60   connect(mCloseButton, SIGNAL(clicked()), this, SLOT(close()));
61   mCloseButton->setVisible(false);
62   mTree->clear();
63   mTree->header()->resizeSection(0, 30);
64   mMainWindowBase->GetTab()->setTabIcon(mTabNumber, GetToolIcon());
65   mCurrentStructureSet = NULL;
66   mCurrentStructureSetIndex = -1;
67   mGroupBoxROI->setEnabled(false);
68   mCurrentROIActor = NULL;
69   mIsAllVisibleEnabled = false;
70   mNumberOfVisibleROI = 0;
71   mNumberOfVisibleContourROI = 0;
72   mDefaultLUTColor = vtkSmartPointer<vtkLookupTable>::New();
73   for(int i=0; i<mDefaultLUTColor->GetNumberOfTableValues(); i++) {
74     double r = (rand()/(RAND_MAX+1.0));
75     double v = (rand()/(RAND_MAX+1.0));
76     double b = (rand()/(RAND_MAX+1.0));
77     mDefaultLUTColor->SetTableValue(i, r, v, b);
78     //    std::cout << "mDefaultLUTColor->SetTableValue(" << i << ", " << r << ", " << v << ", " << b << ");" << std::endl;
79   }
80 #include "vvDefaultLut.h"
81
82   // Add input selector
83   if (current == NULL) {
84     MustOpenDialogWhenCreated = true;
85     AddInputSelector("Select image");
86   }
87   else {
88     MustOpenDialogWhenCreated = false;
89     mMainButtonBox->setEnabled(true);
90     mCurrentSlicerManager = current;
91     mCurrentImage = mCurrentSlicerManager->GetImage();
92     mToolWidget->setEnabled(true);
93     InputIsSelected(mCurrentSlicerManager);
94   }
95 }
96 //------------------------------------------------------------------------------
97
98
99 //------------------------------------------------------------------------------
100 vvToolStructureSetManager::~vvToolStructureSetManager()
101 {
102   disconnect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItemChangedInTree()));
103   m_NumberOfTool--;
104 }
105 //------------------------------------------------------------------------------
106
107
108 //------------------------------------------------------------------------------
109 // STATIC
110 void vvToolStructureSetManager::Initialize() {
111   SetToolName("ROIManager");
112   SetToolMenuName("Display ROI (binary image)");
113   SetToolIconFilename(":/common/icons/tool-roi.png");
114   SetToolTip("Display ROI from a binary image.");
115   SetToolExperimental(false);
116 }
117 //------------------------------------------------------------------------------
118
119
120 //------------------------------------------------------------------------------
121 void vvToolStructureSetManager::InputIsSelected(vvSlicerManager *m)
122 {
123   //int mTabNumber = parent->GetTab()->addTab(this, "");
124   //  this->setFixedWidth(120);
125   //this->setPreferedHeight(441);  
126   // Refuse if 4D
127   if (mCurrentImage->GetNumberOfDimensions() != 3) {
128     QMessageBox::information(this,tr("Sorry only 3D yet"), tr("Sorry only 3D yet"));
129     close();
130   }
131   // Hide selector
132   HideInputSelector(); // splitter
133   mToolInputSelectionWidget->hide();
134   mLabelInputInfo->setText(QString("%1").arg(m->GetFileName().c_str()));
135
136   // add to instance
137   // if (!isWindow()) {
138   mListOfInputs.push_back(mCurrentSlicerManager);
139   mListOfOpenTool[mCurrentSlicerManager] = this;
140   // }
141
142   // Connect open menus
143   connect(mOpenBinaryButton, SIGNAL(clicked()), this, SLOT(OpenBinaryImage()));
144   connect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItemChangedInTree()));
145   connect(mCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleROIToggled(bool)));
146   connect(mOpacitySlider, SIGNAL(valueChanged(int)), this, SLOT(OpacityChanged(int)));
147   connect(mChangeColorButton, SIGNAL(clicked()), this, SLOT(ChangeColor()));
148   connect(mContourCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleContourROIToggled(bool)));  
149   connect(mChangeContourColorButton, SIGNAL(clicked()), this, SLOT(ChangeContourColor()));
150   connect(mContourWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeContourWidth(int)));
151   connect(mReloadButton, SIGNAL(clicked()), this, SLOT(ReloadCurrentROI()));
152   connect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int)));
153   connect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool)));
154
155   // Browse to load image
156   if (MustOpenDialogWhenCreated)
157     OpenBinaryImage();
158 }
159 //------------------------------------------------------------------------------
160
161
162 //------------------------------------------------------------------------------
163 void vvToolStructureSetManager::Open(int type) {
164   switch (type) {
165   case 0: OpenBinaryImage(); return; // Open binary image;
166   case 1: DD("TODO"); return; // Open DICOM RT
167   case 2: DD("TODO"); return; // Open mesh
168   default: std::cerr << "Error ????" << std::endl; exit(0);
169   }
170 }
171 //------------------------------------------------------------------------------
172
173
174 //------------------------------------------------------------------------------
175 void vvToolStructureSetManager::AddRoiInTreeWidget(clitk::DicomRT_ROI * roi, QTreeWidget * ww) {
176   mTreeWidgetList.push_back(QSharedPointer<QTreeWidgetItem>(new QTreeWidgetItem(ww)));
177   QTreeWidgetItem * w = mTreeWidgetList.back().data();
178   w->setText(0, QString("%1").arg(roi->GetROINumber()));
179   w->setText(1, QString("%1").arg(roi->GetName().c_str()));
180   QBrush brush(QColor(roi->GetDisplayColor()[0]*255, roi->GetDisplayColor()[1]*255, roi->GetDisplayColor()[2]*255));
181   brush.setStyle(Qt::SolidPattern);
182   w->setBackground(2, brush);
183   mMapROIToTreeWidget[roi] = w;
184   mMapTreeWidgetToROI[w] = roi;
185   mTree->resizeColumnToContents(0);
186   mTree->resizeColumnToContents(1);
187 }
188 //------------------------------------------------------------------------------
189
190
191 //------------------------------------------------------------------------------
192 void vvToolStructureSetManager::UpdateStructureSetInTreeWidget(int index, clitk::DicomRT_StructureSet * s) {
193   // Insert ROI
194   const std::vector<clitk::DicomRT_ROI::Pointer> & rois = s->GetListOfROI();
195   for(unsigned int i=0; i<rois.size(); i++) {
196     if (mMapROIToTreeWidget.find(rois[i]) == mMapROIToTreeWidget.end())
197       AddRoiInTreeWidget(rois[i], mTree); // replace mTree with ss if several SS
198   }
199 }
200 //------------------------------------------------------------------------------
201
202
203 //------------------------------------------------------------------------------
204 int vvToolStructureSetManager::AddStructureSet(clitk::DicomRT_StructureSet * mStructureSet) {
205   // Create actor for this SS
206
207   QSharedPointer<vvStructureSetActor> mStructureSetActor(new vvStructureSetActor);
208   
209   mStructureSetActor->SetStructureSet(mStructureSet);
210   mStructureSetActor->SetSlicerManager(mCurrentSlicerManager);
211   // Insert in lists and get index
212   mStructureSetsList.push_back(mStructureSet);
213   mStructureSetActorsList.push_back(mStructureSetActor);
214   int index = mStructureSetsList.size()-1;
215   // Return index
216   return index;
217 }
218 //------------------------------------------------------------------------------
219
220
221 //------------------------------------------------------------------------------
222 void vvToolStructureSetManager::OpenBinaryImage() 
223 {
224   int index;
225   if (mCurrentStructureSet == NULL) {
226     if (mStructureSetsList.size() == 0) { // Create a default SS
227       clitk::DicomRT_StructureSet::Pointer mStructureSet = clitk::DicomRT_StructureSet::New();
228       index = AddStructureSet(mStructureSet);
229     }
230     else { // Get first SS
231       index = 0;
232     }
233   } else {
234     index = mCurrentStructureSetIndex;
235   }
236   mCurrentStructureSet = mStructureSetsList[index];
237   mCurrentStructureSetActor = mStructureSetActorsList[index].data();
238   mCurrentStructureSetIndex = index;
239   // Open images
240   QString Extensions = "Images files ( *.mhd *.hdr *.his)";
241   Extensions += ";;All Files (*)";
242   QStringList filename =
243     QFileDialog::getOpenFileNames(this,tr("Open binary image"),
244                                   mMainWindowBase->GetInputPathName(),Extensions);
245   if (filename.size() == 0) return;
246   mLoadedROIIndex.clear();
247   for(int i=0; i<filename.size(); i++) {
248     // Open Image
249     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
250     vvImageReader::Pointer reader = vvImageReader::New();
251     std::vector<std::string> filenames;
252     filenames.push_back(filename[i].toStdString());
253     reader->SetInputFilenames(filenames);
254     reader->Update(IMAGE);
255     QApplication::restoreOverrideCursor();
256
257     if (reader->GetLastError().size() != 0) {
258       std::cerr << "Error while reading " << filename[i].toStdString() << std::endl;
259       QString error = "Cannot open file \n";
260       error += reader->GetLastError().c_str();
261       QMessageBox::information(this,tr("Reading problem"),error);
262       return;
263     }
264     vvImage::Pointer binaryImage = reader->GetOutput();
265     AddImage(binaryImage, filename[i].toStdString(), mBackgroundValueSpinBox->value());
266     mOpenedBinaryImage.push_back(binaryImage);
267   }
268   UpdateImage();
269 }
270 //------------------------------------------------------------------------------
271
272
273 //------------------------------------------------------------------------------
274 void vvToolStructureSetManager::UpdateImage() 
275 {
276   // Update the TreeWidget
277   UpdateStructureSetInTreeWidget(mCurrentStructureSetIndex, mCurrentStructureSet);
278   // Render loaded ROIs (the first is sufficient)
279   for(unsigned int i=0; i<mLoadedROIIndex.size(); i++) {
280     mCurrentStructureSetActor->GetROIActor(mLoadedROIIndex[i])->Update();
281   }
282   for(int i=0; i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
283     mCurrentSlicerManager->GetSlicer(i)->Render();
284   }  
285 }
286 //------------------------------------------------------------------------------
287
288
289 //------------------------------------------------------------------------------
290 void vvToolStructureSetManager::AddImage(vvImage * binaryImage, std::string filename, 
291                                          double BG, bool m_modeBG) 
292 {
293   // Check current structure set
294   int index;
295   if (mCurrentStructureSet == NULL) {
296     if (mStructureSetsList.size() == 0) { // Create a default SS
297       clitk::DicomRT_StructureSet::Pointer mStructureSet = clitk::DicomRT_StructureSet::New();
298       index = AddStructureSet(mStructureSet);
299     }
300     else { // Get first SS
301       index = 0;
302     }
303   } else {
304     index = mCurrentStructureSetIndex;
305   }
306   mCurrentStructureSet = mStructureSetsList[index];
307   mCurrentStructureSetActor = mStructureSetActorsList[index].data();
308   mCurrentStructureSetIndex = index;
309
310   // Check Dimension
311   int dim = mCurrentImage->GetNumberOfDimensions();
312   int bin_dim = binaryImage->GetNumberOfDimensions();
313   if (dim < bin_dim) {  ////////// TO CHANGE FOR 3D/4D
314     std::ostringstream os;
315     os << "Error. Loaded binary image is " << bin_dim
316        << "D while selected image is " << dim << "D" << std::endl;
317     QMessageBox::information(this,tr("Reading problem"),os.str().c_str());
318     return;
319   }
320   
321   // Add a new roi to the structure
322   int n = mCurrentStructureSet->AddBinaryImageAsNewROI(binaryImage, filename);
323   mLoadedROIIndex.push_back(n);
324   if (m_modeBG) 
325     mCurrentStructureSet->GetROI(n)->SetBackgroundValueLabelImage(BG);
326   else 
327     mCurrentStructureSet->GetROI(n)->SetForegroundValueLabelImage(BG);
328   
329   // Change color
330   if (n<mDefaultLUTColor->GetNumberOfTableValues ()) {
331     double * color = mDefaultLUTColor->GetTableValue(n % mDefaultLUTColor->GetNumberOfTableValues ());
332     mCurrentStructureSet->GetROI(n)->SetDisplayColor(color[0], color[1], color[2]);
333   }
334   
335   // Add a new roi actor
336   mCurrentStructureSetActor->CreateNewROIActor(n, m_modeBG);
337   
338   // CheckBox for "All"
339   if (mCurrentStructureSetActor->GetROIActor(n)->IsVisible())
340     mNumberOfVisibleROI++;
341   if (mCurrentStructureSetActor->GetROIActor(n)->IsContourVisible())
342     mNumberOfVisibleContourROI++;
343   UpdateAllROIStatus();
344 }
345 //------------------------------------------------------------------------------
346
347
348 //------------------------------------------------------------------------------
349 void vvToolStructureSetManager::apply() 
350 {
351   close();
352 }
353 //------------------------------------------------------------------------------
354
355
356 //------------------------------------------------------------------------------
357 bool vvToolStructureSetManager::close()
358 {
359   return vvToolWidgetBase::close();
360 }
361 //------------------------------------------------------------------------------
362
363
364 //------------------------------------------------------------------------------
365 void vvToolStructureSetManager::closeEvent(QCloseEvent *event) 
366 {
367   std::vector<vvSlicerManager*>::iterator iter = std::find(mListOfInputs.begin(), mListOfInputs.end(), mCurrentSlicerManager);
368   if (iter != mListOfInputs.end()) mListOfInputs.erase(iter);
369   
370   //  DD("how delete mListOfOpenTool ???");
371   mListOfOpenTool.erase(mCurrentSlicerManager);
372
373   mCheckBoxShowAll->setCheckState(Qt::Unchecked);
374   mContourCheckBoxShowAll->setCheckState(Qt::Unchecked);
375   if (mCurrentSlicerManager != 0) mCurrentSlicerManager->Render();
376   if (mCurrentStructureSetActor) {
377     for(int i=0; i<mCurrentStructureSetActor->GetNumberOfROIs(); i++) {
378       mCurrentStructureSetActor->GetROIList()[i]->SetVisible(false);
379       mCurrentStructureSetActor->GetROIList()[i]->SetContourVisible(false);
380       delete mCurrentStructureSetActor->GetROIList()[i];
381     }
382   }
383
384   if (!isWindow()) {
385     if (m_NumberOfTool == 1) {
386       mMainWindow->GetTab()->removeTab(mTabNumber);
387     }
388   } 
389
390   event->accept();
391 }
392 //------------------------------------------------------------------------------
393
394
395 //------------------------------------------------------------------------------
396 // CURRENT ROI INTERACTION
397 //------------------------------------------------------------------------------
398
399
400 //------------------------------------------------------------------------------
401 void vvToolStructureSetManager::SelectedItemChangedInTree() {
402   // Search which roi is selected
403   QList<QTreeWidgetItem *> l = mTree->selectedItems();
404   if (l.size() == 0) {
405     mCurrentROIActor = NULL;
406     mCurrentROI = NULL;
407     mGroupBoxROI->setEnabled(false);
408     return;
409   }
410   QTreeWidgetItem * w = l[0];
411   if (mMapTreeWidgetToROI.find(w) == mMapTreeWidgetToROI.end()) {
412     mCurrentROIActor = NULL;
413     mCurrentROI = NULL;
414     mGroupBoxROI->setEnabled(false);
415     return;
416   }
417   clitk::DicomRT_ROI * roi = mMapTreeWidgetToROI[w];
418   // Get selected roi actor
419   vvROIActor * actor = mStructureSetActorsList[mCurrentStructureSetIndex]->GetROIActor(roi->GetROINumber());
420   mCurrentROI = roi;
421   mCurrentROIActor = actor;
422
423   // Update GUI
424   mGroupBoxROI->setEnabled(true);
425   mROInameLabel->setText(roi->GetName().c_str());
426   mCheckBoxShow->setChecked(actor->IsVisible());
427   mContourCheckBoxShow->setChecked(actor->IsContourVisible());
428   mContourWidthSpinBox->setValue(actor->GetContourWidth());
429   
430   // Warning -> avoir unuseful Render here by disconnect slider 
431   disconnect(mOpacitySlider, SIGNAL(valueChanged(int)), 
432              this, SLOT(OpacityChanged(int)));
433   mOpacitySlider->setValue((int)lrint(actor->GetOpacity()*100));
434   mOpacitySpinBox->setValue((int)lrint(actor->GetOpacity()*100));
435   connect(mOpacitySlider, SIGNAL(valueChanged(int)), 
436           this, SLOT(OpacityChanged(int)));
437   actor->Update(); 
438
439   // Final rendering
440   mCurrentSlicerManager->Render();
441 }
442 //------------------------------------------------------------------------------
443
444
445 //------------------------------------------------------------------------------
446 void vvToolStructureSetManager::UpdateAllROIStatus() {
447   int nbVisible = 0;
448   int nb = mCurrentStructureSetActor->GetROIList().size();
449   for(int i=0; i<nb; i++) {
450     if (mCurrentStructureSetActor->GetROIList()[i]->IsVisible()) {
451       nbVisible++;
452     }
453   }
454
455   disconnect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int)));  
456   disconnect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool)));
457   if (nbVisible == nb) mCheckBoxShowAll->setCheckState(Qt::Checked);
458   else {
459     if (nbVisible == 0) mCheckBoxShowAll->setCheckState(Qt::Unchecked);
460     else mCheckBoxShowAll->setCheckState(Qt::PartiallyChecked);
461   }
462   connect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool)));
463   connect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int)));
464 }
465 //------------------------------------------------------------------------------
466
467 //------------------------------------------------------------------------------
468 void vvToolStructureSetManager::VisibleROIToggled(bool b) {
469   if (mCurrentROIActor == NULL) return;
470   if (b == mCurrentROIActor->IsVisible()) return; // nothing to do
471   mCurrentROIActor->SetVisible(b);
472   UpdateAllROIStatus();
473   mCurrentSlicerManager->Render(); 
474 }
475 //------------------------------------------------------------------------------
476
477
478 //------------------------------------------------------------------------------
479 void vvToolStructureSetManager::VisibleContourROIToggled(bool b) {
480   if (mCurrentROIActor == NULL) return;
481   if (mCurrentROIActor->IsContourVisible() == b) return; // nothing to do
482   mCurrentROIActor->SetContourVisible(b);
483   mCurrentROIActor->UpdateColor();
484   mCurrentSlicerManager->Render(); 
485 }
486 //------------------------------------------------------------------------------
487
488
489 //------------------------------------------------------------------------------
490 void vvToolStructureSetManager::OpacityChanged(int v) {
491   if (mCurrentROIActor == NULL) return;
492   mCurrentROIActor->SetOpacity((double)v/100.0);
493   mCurrentROIActor->UpdateColor();
494   mCurrentSlicerManager->Render(); 
495 }
496 //------------------------------------------------------------------------------
497
498
499 //------------------------------------------------------------------------------
500 void vvToolStructureSetManager::AllVisibleROIToggled(int b) {
501   bool status = false;
502   if ((mCheckBoxShowAll->checkState() == Qt::Checked) ||
503       (mCheckBoxShowAll->checkState() == Qt::PartiallyChecked))  status = true;
504
505   for(int i=0; i<mCurrentStructureSetActor->GetNumberOfROIs(); i++) {
506     mCurrentStructureSetActor->GetROIList()[i]->SetVisible(status);
507   }
508   if (status) mCheckBoxShowAll->setCheckState(Qt::Checked);
509   else  mCheckBoxShowAll->setCheckState(Qt::Unchecked);
510   mCheckBoxShow->setChecked(status);
511   mCurrentSlicerManager->Render(); 
512 }
513 //------------------------------------------------------------------------------
514
515
516 //------------------------------------------------------------------------------
517 void vvToolStructureSetManager::AllVisibleContourROIToggled(bool b) {
518   bool status = false;
519   if ((mContourCheckBoxShowAll->checkState() == Qt::Checked) ||
520       (mContourCheckBoxShowAll->checkState() == Qt::PartiallyChecked))  status = true;
521   // Update current 
522   for(int i=0; i<mCurrentStructureSetActor->GetNumberOfROIs(); i++) {
523     mCurrentStructureSetActor->GetROIList()[i]->SetContourVisible(status);
524   }
525   // Update current selection
526   if (status) mContourCheckBoxShowAll->setCheckState(Qt::Checked);
527   else  mContourCheckBoxShowAll->setCheckState(Qt::Unchecked);
528   mContourCheckBoxShow->setChecked(status);
529   mCurrentSlicerManager->Render(); 
530 }
531 //------------------------------------------------------------------------------
532
533
534 //------------------------------------------------------------------------------
535 void vvToolStructureSetManager::ChangeColor() {
536   QColor color;
537   color.setRgbF(mCurrentROIActor->GetROI()->GetDisplayColor()[0],
538                 mCurrentROIActor->GetROI()->GetDisplayColor()[1],
539                 mCurrentROIActor->GetROI()->GetDisplayColor()[2]);
540   QColor c = QColorDialog::getColor(color, this, "Choose the ROI color");
541   mCurrentROIActor->GetROI()->SetDisplayColor(c.redF(), c.greenF(), c.blueF());
542   mCurrentROIActor->UpdateColor();
543
544   QTreeWidgetItem * w = mMapROIToTreeWidget[mCurrentROI];
545   QBrush brush(QColor(mCurrentROI->GetDisplayColor()[0]*255,
546                       mCurrentROI->GetDisplayColor()[1]*255,
547                       mCurrentROI->GetDisplayColor()[2]*255));
548   brush.setStyle(Qt::SolidPattern);
549   w->setBackground(2, brush);
550   // Render
551   mCurrentSlicerManager->Render();
552 }
553 //------------------------------------------------------------------------------
554
555
556 //------------------------------------------------------------------------------
557 void vvToolStructureSetManager::ChangeContourColor() {
558   QColor color;
559   color.setRgbF(mCurrentROIActor->GetContourColor()[0], 
560                 mCurrentROIActor->GetContourColor()[1], 
561                 mCurrentROIActor->GetContourColor()[2]);
562   QColor c = QColorDialog::getColor(color, this, "Choose the contour color");
563   mCurrentROIActor->SetContourColor(c.redF(), c.greenF(), c.blueF());
564   mCurrentROIActor->UpdateColor();
565   mCurrentSlicerManager->Render();
566 }
567 //------------------------------------------------------------------------------
568
569
570 //------------------------------------------------------------------------------
571 void vvToolStructureSetManager::ChangeContourWidth(int n) {
572   mCurrentROIActor->SetContourWidth(n);
573   mCurrentROIActor->UpdateColor();
574   mCurrentSlicerManager->Render();
575 }
576 //------------------------------------------------------------------------------
577
578
579 //------------------------------------------------------------------------------
580 void vvToolStructureSetManager::ReloadCurrentROI() {
581   // Reload image
582   vvImageReader::Pointer reader = vvImageReader::New();
583   reader->SetInputFilename(mCurrentROI->GetFilename());
584   reader->Update(IMAGE);
585   if (reader->GetLastError() != "") {
586     QMessageBox::information(mMainWindowBase, tr("Sorry, error. Could not reload"), reader->GetLastError().c_str());
587     return;
588   }
589   mCurrentROI->GetImage()->GetFirstVTKImageData()->ReleaseData();
590   mCurrentROI->SetImage(reader->GetOutput());
591   
592   // Update visu"
593   mCurrentROIActor->UpdateImage();
594   mCurrentSlicerManager->Render();    
595 }
596 //------------------------------------------------------------------------------
597
598
599 //------------------------------------------------------------------------------
600 void vvToolStructureSetManager::CheckInputList(std::vector<vvSlicerManager*> & l, int & index) 
601 {
602   for(unsigned int i=0; i<l.size(); i++) {
603     std::vector<vvSlicerManager*>::iterator iter = std::find(mListOfInputs.begin(), mListOfInputs.end(), l[i]);
604     if (iter != mListOfInputs.end()) {
605       for(unsigned int j=i;j<l.size(); j++) l[j] = l[j+1];
606       l.pop_back();
607       if (index == (int)i) index = 0;
608       i--;
609     }
610   }
611 }
612 //------------------------------------------------------------------------------
613
614
615 //------------------------------------------------------------------------------
616 // STATIC
617 vvToolStructureSetManager * vvToolStructureSetManager::AddImage(vvSlicerManager * m, std::string name, vvImage::Pointer image, double BG, bool m_modeBG)
618 {
619   // If the tool is open for this vvSlicerManager, use it and return
620   if (mListOfOpenTool[m]) {
621     vvToolStructureSetManager * tool = mListOfOpenTool[m];
622     tool->AddImage(image, name, BG, m_modeBG);
623     tool->UpdateImage();
624     return tool;
625   }
626
627   // If the tool is not open, create it
628   vvToolStructureSetManager * tool = new vvToolStructureSetManager
629     (CREATOR(vvToolStructureSetManager)->GetMainWindow(), Qt::Dialog, m);
630   tool->AddImage(image, name, BG, m_modeBG);
631   tool->UpdateImage();
632   tool->show();
633   return tool;
634 }
635 //------------------------------------------------------------------------------