]> Creatis software - clitk.git/blob - vv/vvToolStructureSetManager.cxx
Attempt to remove some leaks. DicomRT_Contour, DicomRT_ROI and DicomRT_StructureSet...
[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   m_NumberOfTool--;
103
104   for(unsigned int i=0; i< mStructureSetActorsList.size(); i++)
105     delete mStructureSetActorsList[i];
106
107   for (std::map<clitk::DicomRT_ROI::Pointer, QTreeWidgetItem *>::iterator it = mMapROIToTreeWidget.begin();
108        it!=mMapROIToTreeWidget.end(); it++)
109     delete it->second;
110 }
111 //------------------------------------------------------------------------------
112
113
114 //------------------------------------------------------------------------------
115 // STATIC
116 void vvToolStructureSetManager::Initialize() {
117   SetToolName("ROIManager");
118   SetToolMenuName("Display ROI (binary image)");
119   SetToolIconFilename(":/common/icons/tool-roi.png");
120   SetToolTip("Display ROI from a binary image.");
121   SetToolExperimental(false);
122 }
123 //------------------------------------------------------------------------------
124
125
126 //------------------------------------------------------------------------------
127 void vvToolStructureSetManager::InputIsSelected(vvSlicerManager *m)
128 {
129   //int mTabNumber = parent->GetTab()->addTab(this, "");
130   //  this->setFixedWidth(120);
131   //this->setPreferedHeight(441);  
132   // Refuse if 4D
133   if (mCurrentImage->GetNumberOfDimensions() != 3) {
134     QMessageBox::information(this,tr("Sorry only 3D yet"), tr("Sorry only 3D yet"));
135     close();
136   }
137   // Hide selector
138   HideInputSelector(); // splitter
139   mToolInputSelectionWidget->hide();
140   mLabelInputInfo->setText(QString("%1").arg(m->GetFileName().c_str()));
141
142   // add to instance
143   // if (!isWindow()) {
144   mListOfInputs.push_back(mCurrentSlicerManager);
145   mListOfOpenTool[mCurrentSlicerManager] = this;
146   // }
147
148   // Connect open menus
149   connect(mOpenBinaryButton, SIGNAL(clicked()), this, SLOT(OpenBinaryImage()));
150   connect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItemChangedInTree()));
151   connect(mCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleROIToggled(bool)));
152   connect(mOpacitySlider, SIGNAL(valueChanged(int)), this, SLOT(OpacityChanged(int)));
153   connect(mChangeColorButton, SIGNAL(clicked()), this, SLOT(ChangeColor()));
154   connect(mContourCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleContourROIToggled(bool)));  
155   connect(mChangeContourColorButton, SIGNAL(clicked()), this, SLOT(ChangeContourColor()));
156   connect(mContourWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeContourWidth(int)));
157   connect(mReloadButton, SIGNAL(clicked()), this, SLOT(ReloadCurrentROI()));
158   connect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int)));
159   connect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool)));
160
161   // Browse to load image
162   if (MustOpenDialogWhenCreated)
163     OpenBinaryImage();
164 }
165 //------------------------------------------------------------------------------
166
167
168 //------------------------------------------------------------------------------
169 void vvToolStructureSetManager::Open(int type) {
170   switch (type) {
171   case 0: OpenBinaryImage(); return; // Open binary image;
172   case 1: DD("TODO"); return; // Open DICOM RT
173   case 2: DD("TODO"); return; // Open mesh
174   default: std::cerr << "Error ????" << std::endl; exit(0);
175   }
176 }
177 //------------------------------------------------------------------------------
178
179
180 //------------------------------------------------------------------------------
181 void vvToolStructureSetManager::AddRoiInTreeWidget(clitk::DicomRT_ROI * roi, QTreeWidget * ww) {
182   QTreeWidgetItem * w = new QTreeWidgetItem(ww);
183   w->setText(0, QString("%1").arg(roi->GetROINumber()));
184   w->setText(1, QString("%1").arg(roi->GetName().c_str()));
185   QBrush brush(QColor(roi->GetDisplayColor()[0]*255, roi->GetDisplayColor()[1]*255, roi->GetDisplayColor()[2]*255));
186   brush.setStyle(Qt::SolidPattern);
187   w->setBackground(2, brush);
188   mMapROIToTreeWidget[roi] = w;
189   mMapTreeWidgetToROI[w] = roi;
190   mTree->resizeColumnToContents(0);
191   mTree->resizeColumnToContents(1);
192 }
193 //------------------------------------------------------------------------------
194
195
196 //------------------------------------------------------------------------------
197 void vvToolStructureSetManager::UpdateStructureSetInTreeWidget(int index, clitk::DicomRT_StructureSet * s) {
198   // Insert ROI
199   const std::vector<clitk::DicomRT_ROI::Pointer> & rois = s->GetListOfROI();
200   for(unsigned int i=0; i<rois.size(); i++) {
201     if (mMapROIToTreeWidget.find(rois[i]) == mMapROIToTreeWidget.end())
202       AddRoiInTreeWidget(rois[i], mTree); // replace mTree with ss if several SS
203   }
204 }
205 //------------------------------------------------------------------------------
206
207
208 //------------------------------------------------------------------------------
209 int vvToolStructureSetManager::AddStructureSet(clitk::DicomRT_StructureSet * mStructureSet) {
210   // Create actor for this SS
211
212   vvStructureSetActor * mStructureSetActor =  new vvStructureSetActor;
213   
214   mStructureSetActor->SetStructureSet(mStructureSet);
215   mStructureSetActor->SetSlicerManager(mCurrentSlicerManager);
216   // Insert in lists and get index
217   mStructureSetsList.push_back(mStructureSet);
218   mStructureSetActorsList.push_back(mStructureSetActor);
219   int index = mStructureSetsList.size()-1;
220   // Return index
221   return index;
222 }
223 //------------------------------------------------------------------------------
224
225
226 //------------------------------------------------------------------------------
227 void vvToolStructureSetManager::OpenBinaryImage() 
228 {
229   int index;
230   if (mCurrentStructureSet == NULL) {
231     if (mStructureSetsList.size() == 0) { // Create a default SS
232       clitk::DicomRT_StructureSet::Pointer mStructureSet = clitk::DicomRT_StructureSet::New();
233       index = AddStructureSet(mStructureSet);
234     }
235     else { // Get first SS
236       index = 0;
237     }
238   } else {
239     index = mCurrentStructureSetIndex;
240   }
241   mCurrentStructureSet = mStructureSetsList[index];
242   mCurrentStructureSetActor = mStructureSetActorsList[index];
243   mCurrentStructureSetIndex = index;
244   // Open images
245   QString Extensions = "Images files ( *.mhd *.hdr *.his)";
246   Extensions += ";;All Files (*)";
247   QStringList filename =
248     QFileDialog::getOpenFileNames(this,tr("Open binary image"),
249                                   mMainWindowBase->GetInputPathName(),Extensions);
250   if (filename.size() == 0) return;
251   mLoadedROIIndex.clear();
252   for(int i=0; i<filename.size(); i++) {
253     // Open Image
254     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
255     vvImageReader mReader;
256     std::vector<std::string> filenames;
257     filenames.push_back(filename[i].toStdString());
258     mReader.SetInputFilenames(filenames);
259     mReader.Update(IMAGE);
260     QApplication::restoreOverrideCursor();
261
262     if (mReader.GetLastError().size() != 0) {
263       std::cerr << "Error while reading " << filename[i].toStdString() << std::endl;
264       QString error = "Cannot open file \n";
265       error += mReader.GetLastError().c_str();
266       QMessageBox::information(this,tr("Reading problem"),error);
267       return;
268     }
269     vvImage::Pointer binaryImage = mReader.GetOutput();
270     AddImage(binaryImage, filename[i].toStdString(), mBackgroundValueSpinBox->value());
271     mOpenedBinaryImage.push_back(binaryImage);
272   }
273   UpdateImage();
274 }
275 //------------------------------------------------------------------------------
276
277
278 //------------------------------------------------------------------------------
279 void vvToolStructureSetManager::UpdateImage() 
280 {
281   // Update the TreeWidget
282   UpdateStructureSetInTreeWidget(mCurrentStructureSetIndex, mCurrentStructureSet);
283   // Render loaded ROIs (the first is sufficient)
284   for(unsigned int i=0; i<mLoadedROIIndex.size(); i++) {
285     mCurrentStructureSetActor->GetROIActor(mLoadedROIIndex[i])->Update();
286   }
287   for(int i=0; i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
288     mCurrentSlicerManager->GetSlicer(i)->Render();
289   }  
290 }
291 //------------------------------------------------------------------------------
292
293
294 //------------------------------------------------------------------------------
295 void vvToolStructureSetManager::AddImage(vvImage * binaryImage, std::string filename, 
296                                          double BG, bool m_modeBG) 
297 {
298   // Check current structure set
299   int index;
300   if (mCurrentStructureSet == NULL) {
301     if (mStructureSetsList.size() == 0) { // Create a default SS
302       clitk::DicomRT_StructureSet::Pointer mStructureSet = clitk::DicomRT_StructureSet::New();
303       index = AddStructureSet(mStructureSet);
304     }
305     else { // Get first SS
306       index = 0;
307     }
308   } else {
309     index = mCurrentStructureSetIndex;
310   }
311   mCurrentStructureSet = mStructureSetsList[index];
312   mCurrentStructureSetActor = mStructureSetActorsList[index];
313   mCurrentStructureSetIndex = index;
314
315   // Check Dimension
316   int dim = mCurrentImage->GetNumberOfDimensions();
317   int bin_dim = binaryImage->GetNumberOfDimensions();
318   if (dim < bin_dim) {  ////////// TO CHANGE FOR 3D/4D
319     std::ostringstream os;
320     os << "Error. Loaded binary image is " << bin_dim
321        << "D while selected image is " << dim << "D" << std::endl;
322     QMessageBox::information(this,tr("Reading problem"),os.str().c_str());
323     return;
324   }
325   
326   // Add a new roi to the structure
327   int n = mCurrentStructureSet->AddBinaryImageAsNewROI(binaryImage, filename);
328   mLoadedROIIndex.push_back(n);
329   if (m_modeBG) 
330     mCurrentStructureSet->GetROI(n)->SetBackgroundValueLabelImage(BG);
331   else 
332     mCurrentStructureSet->GetROI(n)->SetForegroundValueLabelImage(BG);
333   
334   // Change color
335   if (n<mDefaultLUTColor->GetNumberOfTableValues ()) {
336     double * color = mDefaultLUTColor->GetTableValue(n % mDefaultLUTColor->GetNumberOfTableValues ());
337     mCurrentStructureSet->GetROI(n)->SetDisplayColor(color[0], color[1], color[2]);
338   }
339   
340   // Add a new roi actor
341   mCurrentStructureSetActor->CreateNewROIActor(n, m_modeBG);
342   
343   // CheckBox for "All"
344   if (mCurrentStructureSetActor->GetROIActor(n)->IsVisible())
345     mNumberOfVisibleROI++;
346   if (mCurrentStructureSetActor->GetROIActor(n)->IsContourVisible())
347     mNumberOfVisibleContourROI++;
348   UpdateAllROIStatus();
349 }
350 //------------------------------------------------------------------------------
351
352
353 //------------------------------------------------------------------------------
354 void vvToolStructureSetManager::apply() 
355 {
356   close();
357 }
358 //------------------------------------------------------------------------------
359
360
361 //------------------------------------------------------------------------------
362 bool vvToolStructureSetManager::close()
363 {
364   return vvToolWidgetBase::close();
365 }
366 //------------------------------------------------------------------------------
367
368
369 //------------------------------------------------------------------------------
370 void vvToolStructureSetManager::closeEvent(QCloseEvent *event) 
371 {
372   std::vector<vvSlicerManager*>::iterator iter = std::find(mListOfInputs.begin(), mListOfInputs.end(), mCurrentSlicerManager);
373   if (iter != mListOfInputs.end()) mListOfInputs.erase(iter);
374   
375   //  DD("how delete mListOfOpenTool ???");
376   mListOfOpenTool.erase(mCurrentSlicerManager);
377
378   mCheckBoxShowAll->setCheckState(Qt::Unchecked);
379   mContourCheckBoxShowAll->setCheckState(Qt::Unchecked);
380   if (mCurrentSlicerManager != 0) mCurrentSlicerManager->Render();
381   if (mCurrentStructureSetActor) {
382     for(int i=0; i<mCurrentStructureSetActor->GetNumberOfROIs(); i++) {
383       mCurrentStructureSetActor->GetROIList()[i]->SetVisible(false);
384       mCurrentStructureSetActor->GetROIList()[i]->SetContourVisible(false);
385       delete mCurrentStructureSetActor->GetROIList()[i];
386     }
387   }
388
389   if (!isWindow()) {
390     if (m_NumberOfTool == 1) {
391       mMainWindow->GetTab()->removeTab(mTabNumber);
392     }
393   } 
394
395   event->accept();
396 }
397 //------------------------------------------------------------------------------
398
399
400 //------------------------------------------------------------------------------
401 // CURRENT ROI INTERACTION
402 //------------------------------------------------------------------------------
403
404
405 //------------------------------------------------------------------------------
406 void vvToolStructureSetManager::SelectedItemChangedInTree() {
407   // Search which roi is selected
408   QList<QTreeWidgetItem *> l = mTree->selectedItems();
409   if (l.size() == 0) {
410     mCurrentROIActor = NULL;
411     mCurrentROI = NULL;
412     mGroupBoxROI->setEnabled(false);
413     return;
414   }
415   QTreeWidgetItem * w = l[0];
416   if (mMapTreeWidgetToROI.find(w) == mMapTreeWidgetToROI.end()) {
417     mCurrentROIActor = NULL;
418     mCurrentROI = NULL;
419     mGroupBoxROI->setEnabled(false);
420     return;
421   }
422   clitk::DicomRT_ROI * roi = mMapTreeWidgetToROI[w];
423   // Get selected roi actor
424   vvROIActor * actor = mStructureSetActorsList[mCurrentStructureSetIndex]->GetROIActor(roi->GetROINumber());
425   mCurrentROI = roi;
426   mCurrentROIActor = actor;
427
428   // Update GUI
429   mGroupBoxROI->setEnabled(true);
430   mROInameLabel->setText(roi->GetName().c_str());
431   mCheckBoxShow->setChecked(actor->IsVisible());
432   mContourCheckBoxShow->setChecked(actor->IsContourVisible());
433   mContourWidthSpinBox->setValue(actor->GetContourWidth());
434   
435   // Warning -> avoir unuseful Render here by disconnect slider 
436   disconnect(mOpacitySlider, SIGNAL(valueChanged(int)), 
437              this, SLOT(OpacityChanged(int)));
438   mOpacitySlider->setValue((int)lrint(actor->GetOpacity()*100));
439   mOpacitySpinBox->setValue((int)lrint(actor->GetOpacity()*100));
440   connect(mOpacitySlider, SIGNAL(valueChanged(int)), 
441           this, SLOT(OpacityChanged(int)));
442   actor->Update(); 
443
444   // Final rendering
445   mCurrentSlicerManager->Render();
446 }
447 //------------------------------------------------------------------------------
448
449
450 //------------------------------------------------------------------------------
451 void vvToolStructureSetManager::UpdateAllROIStatus() {
452   int nbVisible = 0;
453   int nb = mCurrentStructureSetActor->GetROIList().size();
454   for(int i=0; i<nb; i++) {
455     if (mCurrentStructureSetActor->GetROIList()[i]->IsVisible()) {
456       nbVisible++;
457     }
458   }
459
460   disconnect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int)));  
461   disconnect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool)));
462   if (nbVisible == nb) mCheckBoxShowAll->setCheckState(Qt::Checked);
463   else {
464     if (nbVisible == 0) mCheckBoxShowAll->setCheckState(Qt::Unchecked);
465     else mCheckBoxShowAll->setCheckState(Qt::PartiallyChecked);
466   }
467   connect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool)));
468   connect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int)));
469 }
470 //------------------------------------------------------------------------------
471
472 //------------------------------------------------------------------------------
473 void vvToolStructureSetManager::VisibleROIToggled(bool b) {
474   if (mCurrentROIActor == NULL) return;
475   if (b == mCurrentROIActor->IsVisible()) return; // nothing to do
476   mCurrentROIActor->SetVisible(b);
477   UpdateAllROIStatus();
478   mCurrentSlicerManager->Render(); 
479 }
480 //------------------------------------------------------------------------------
481
482
483 //------------------------------------------------------------------------------
484 void vvToolStructureSetManager::VisibleContourROIToggled(bool b) {
485   if (mCurrentROIActor == NULL) return;
486   if (mCurrentROIActor->IsContourVisible() == b) return; // nothing to do
487   mCurrentROIActor->SetContourVisible(b);
488   mCurrentROIActor->UpdateColor();
489   mCurrentSlicerManager->Render(); 
490 }
491 //------------------------------------------------------------------------------
492
493
494 //------------------------------------------------------------------------------
495 void vvToolStructureSetManager::OpacityChanged(int v) {
496   if (mCurrentROIActor == NULL) return;
497   mCurrentROIActor->SetOpacity((double)v/100.0);
498   mCurrentROIActor->UpdateColor();
499   mCurrentSlicerManager->Render(); 
500 }
501 //------------------------------------------------------------------------------
502
503
504 //------------------------------------------------------------------------------
505 void vvToolStructureSetManager::AllVisibleROIToggled(int b) {
506   bool status = false;
507   if ((mCheckBoxShowAll->checkState() == Qt::Checked) ||
508       (mCheckBoxShowAll->checkState() == Qt::PartiallyChecked))  status = true;
509
510   for(int i=0; i<mCurrentStructureSetActor->GetNumberOfROIs(); i++) {
511     mCurrentStructureSetActor->GetROIList()[i]->SetVisible(status);
512   }
513   if (status) mCheckBoxShowAll->setCheckState(Qt::Checked);
514   else  mCheckBoxShowAll->setCheckState(Qt::Unchecked);
515   mCheckBoxShow->setChecked(status);
516   mCurrentSlicerManager->Render(); 
517 }
518 //------------------------------------------------------------------------------
519
520
521 //------------------------------------------------------------------------------
522 void vvToolStructureSetManager::AllVisibleContourROIToggled(bool b) {
523   bool status = false;
524   if ((mContourCheckBoxShowAll->checkState() == Qt::Checked) ||
525       (mContourCheckBoxShowAll->checkState() == Qt::PartiallyChecked))  status = true;
526   // Update current 
527   for(int i=0; i<mCurrentStructureSetActor->GetNumberOfROIs(); i++) {
528     mCurrentStructureSetActor->GetROIList()[i]->SetContourVisible(status);
529   }
530   // Update current selection
531   if (status) mContourCheckBoxShowAll->setCheckState(Qt::Checked);
532   else  mContourCheckBoxShowAll->setCheckState(Qt::Unchecked);
533   mContourCheckBoxShow->setChecked(status);
534   mCurrentSlicerManager->Render(); 
535 }
536 //------------------------------------------------------------------------------
537
538
539 //------------------------------------------------------------------------------
540 void vvToolStructureSetManager::ChangeColor() {
541   QColor color;
542   color.setRgbF(mCurrentROIActor->GetROI()->GetDisplayColor()[0],
543                 mCurrentROIActor->GetROI()->GetDisplayColor()[1],
544                 mCurrentROIActor->GetROI()->GetDisplayColor()[2]);
545   QColor c = QColorDialog::getColor(color, this, "Choose the ROI color");
546   mCurrentROIActor->GetROI()->SetDisplayColor(c.redF(), c.greenF(), c.blueF());
547   mCurrentROIActor->UpdateColor();
548
549   QTreeWidgetItem * w = mMapROIToTreeWidget[mCurrentROI];
550   QBrush brush(QColor(mCurrentROI->GetDisplayColor()[0]*255,
551                       mCurrentROI->GetDisplayColor()[1]*255,
552                       mCurrentROI->GetDisplayColor()[2]*255));
553   brush.setStyle(Qt::SolidPattern);
554   w->setBackground(2, brush);
555   // Render
556   mCurrentSlicerManager->Render();
557 }
558 //------------------------------------------------------------------------------
559
560
561 //------------------------------------------------------------------------------
562 void vvToolStructureSetManager::ChangeContourColor() {
563   QColor color;
564   color.setRgbF(mCurrentROIActor->GetContourColor()[0], 
565                 mCurrentROIActor->GetContourColor()[1], 
566                 mCurrentROIActor->GetContourColor()[2]);
567   QColor c = QColorDialog::getColor(color, this, "Choose the contour color");
568   mCurrentROIActor->SetContourColor(c.redF(), c.greenF(), c.blueF());
569   mCurrentROIActor->UpdateColor();
570   mCurrentSlicerManager->Render();
571 }
572 //------------------------------------------------------------------------------
573
574
575 //------------------------------------------------------------------------------
576 void vvToolStructureSetManager::ChangeContourWidth(int n) {
577   mCurrentROIActor->SetContourWidth(n);
578   mCurrentROIActor->UpdateColor();
579   mCurrentSlicerManager->Render();
580 }
581 //------------------------------------------------------------------------------
582
583
584 //------------------------------------------------------------------------------
585 void vvToolStructureSetManager::ReloadCurrentROI() {
586   // Reload image
587   vvImageReader mReader;
588   mReader.SetInputFilename(mCurrentROI->GetFilename());
589   mReader.Update(IMAGE);
590   if (mReader.GetLastError() != "") {
591     QMessageBox::information(mMainWindowBase, tr("Sorry, error. Could not reload"), mReader.GetLastError().c_str());
592     return;
593   }
594   mCurrentROI->GetImage()->GetFirstVTKImageData()->ReleaseData();
595   mCurrentROI->SetImage(mReader.GetOutput());
596   
597   // Update visu"
598   mCurrentROIActor->UpdateImage();
599   mCurrentSlicerManager->Render();    
600 }
601 //------------------------------------------------------------------------------
602
603
604 //------------------------------------------------------------------------------
605 void vvToolStructureSetManager::CheckInputList(std::vector<vvSlicerManager*> & l, int & index) 
606 {
607   for(unsigned int i=0; i<l.size(); i++) {
608     std::vector<vvSlicerManager*>::iterator iter = std::find(mListOfInputs.begin(), mListOfInputs.end(), l[i]);
609     if (iter != mListOfInputs.end()) {
610       for(unsigned int j=i;j<l.size(); j++) l[j] = l[j+1];
611       l.pop_back();
612       if (index == (int)i) index = 0;
613       i--;
614     }
615   }
616 }
617 //------------------------------------------------------------------------------
618
619
620 //------------------------------------------------------------------------------
621 // STATIC
622 vvToolStructureSetManager * vvToolStructureSetManager::AddImage(vvSlicerManager * m, std::string name, vvImage::Pointer image, double BG, bool m_modeBG)
623 {
624   // If the tool is open for this vvSlicerManager, use it and return
625   if (mListOfOpenTool[m]) {
626     vvToolStructureSetManager * tool = mListOfOpenTool[m];
627     tool->AddImage(image, name, BG, m_modeBG);
628     tool->UpdateImage();
629     return tool;
630   }
631
632   // If the tool is not open, create it
633   vvToolStructureSetManager * tool = new vvToolStructureSetManager
634     (CREATOR(vvToolStructureSetManager)->GetMainWindow(), Qt::Dialog, m);
635   tool->AddImage(image, name, BG, m_modeBG);
636   tool->UpdateImage();
637   tool->show();
638   return tool;
639 }
640 //------------------------------------------------------------------------------