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