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