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