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