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