]> Creatis software - clitk.git/blob - vv/vvToolROIManager.cxx
Prevent segfault on close ; remove actors when close
[clitk.git] / vv / vvToolROIManager.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 "vvToolROIManager.h"
21 #include "vvImageReader.h"
22 #include "vvROIActor.h"
23 #include "vvSlicer.h"
24 #include "vvROIActor.h"
25 #include "vvMeshReader.h"
26 #include "vvStructSelector.h"
27
28 // Qt
29 #include <QFileDialog>
30 #include <QMessageBox>
31 #include <QColorDialog>
32 #include <QAbstractEventDispatcher>
33  
34 // vtk
35 #include <vtkLookupTable.h>
36 #include <vtkRenderWindow.h>
37
38 //------------------------------------------------------------------------------
39 // Create the tool and automagically (I like this word) insert it in
40 // the main window menu.
41 ADD_TOOL(vvToolROIManager);
42 //------------------------------------------------------------------------------
43
44 //------------------------------------------------------------------------------
45 vvToolROIManager::vvToolROIManager(vvMainWindowBase * parent, Qt::WindowFlags f):
46   QWidget(parent->GetTab()), 
47   vvToolBase<vvToolROIManager>(parent),
48   Ui::vvToolROIManager()
49 {
50   // Store parent
51   mMainWindow = parent;
52   
53   // Assume the initial tab ROI index is 2
54   mIndexFirstTab = 2;
55
56   // Get the ROI Tab
57   QWidget * tab = qFindChild<QWidget*>(parent->GetTab(), "ROItab");
58   
59   // Set it as current
60   parent->GetTab()->setCurrentIndex(mIndexFirstTab);
61   
62   // Check if widget already used
63   if (tab->layout()->isEmpty()) {
64     tab->layout()->addWidget(this);
65   }
66   else {
67     close();
68     return;
69   }
70   
71   // Build the UI
72   Ui_vvToolROIManager::setupUi(this);
73   setAttribute(Qt::WA_DeleteOnClose);
74   mTree->clear();
75   mTree->header()->resizeSection(0, 30);
76   
77   // Temporary disable "Load dicom" button
78   frame_4->hide();
79
80   // Set default LUT
81   mDefaultLUTColor = vtkSmartPointer<vtkLookupTable>::New();
82   for(int i=0; i<mDefaultLUTColor->GetNumberOfTableValues(); i++) {
83     double r = (rand()/(RAND_MAX+1.0));
84     double v = (rand()/(RAND_MAX+1.0));
85     double b = (rand()/(RAND_MAX+1.0));
86     mDefaultLUTColor->SetTableValue(i, r, v, b);
87   }
88 #include "vvDefaultLut.h"
89
90   // Initialization
91   mNumberOfVisibleROI = 0;
92   mNumberOfVisibleContourROI = 0;
93
94   // Select the current image as the target
95   int i = parent->GetSlicerManagerCurrentIndex();
96   InputIsSelected(parent->GetSlicerManagers()[i]);
97
98   // Connect event from mainwindow to this widget
99   connect(parent, SIGNAL(AnImageIsBeingClosed(vvSlicerManager *)), 
100           this, SLOT(AnImageIsBeingClosed(vvSlicerManager *)));
101   connect(parent, SIGNAL(SelectedImageHasChanged(vvSlicerManager *)), 
102           this, SLOT(SelectedImageHasChanged(vvSlicerManager *)));
103   connect(mOpenBinaryButton, SIGNAL(clicked()), this, SLOT(OpenBinaryImage()));
104   connect(mOpenDicomButton, SIGNAL(clicked()), this, SLOT(OpenDicomImage()));
105   connect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItemChangedInTree()));
106   connect(mCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleROIToggled(bool)));
107   connect(mOpacitySlider, SIGNAL(valueChanged(int)), this, SLOT(OpacityChanged(int)));
108   connect(mChangeColorButton, SIGNAL(clicked()), this, SLOT(ChangeColor()));
109   connect(mContourCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleContourROIToggled(bool)));  
110   connect(mChangeContourColorButton, SIGNAL(clicked()), this, SLOT(ChangeContourColor()));
111   connect(mContourWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeContourWidth(int)));
112   connect(mDepthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeDepth(int)));
113   connect(mReloadButton, SIGNAL(clicked()), this, SLOT(ReloadCurrentROI()));
114   connect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int)));
115   connect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool)));
116   connect(mCloseButton, SIGNAL(clicked()), this, SLOT(close()));
117 }
118 //------------------------------------------------------------------------------
119
120
121 //------------------------------------------------------------------------------
122 vvToolROIManager::~vvToolROIManager()
123 {
124 }
125 //------------------------------------------------------------------------------
126
127
128 //------------------------------------------------------------------------------
129 // STATIC
130 void vvToolROIManager::Initialize() {
131   SetToolName("ROIManager");
132   SetToolMenuName("Display ROI (binary image)");
133   SetToolIconFilename(":/common/icons/tool-roi.png");
134   SetToolTip("Display ROI from a binary image.");
135   SetToolExperimental(true);
136 }
137 //------------------------------------------------------------------------------
138
139
140 //------------------------------------------------------------------------------
141 void vvToolROIManager::InputIsSelected(vvSlicerManager *m)
142 {
143   mSlicerManager = m;
144
145   // Initialization
146   mSlicerManager = m;
147   mCurrentImage = mSlicerManager->GetImage();
148
149   // Refuse if 4D
150   if (mCurrentImage->GetNumberOfDimensions() != 3) {
151     QMessageBox::information(this,tr("Sorry only 3D yet"), tr("Sorry only 3D yet"));
152     close();
153     return;
154   }
155
156   // Change gui
157   mLabelInputInfo->setText(QString("%1").arg(m->GetFileName().c_str()));
158
159   // Auto display browser to select new contours 
160   OpenBinaryImage();
161 }
162 //------------------------------------------------------------------------------
163
164
165 //------------------------------------------------------------------------------
166 void vvToolROIManager::AnImageIsBeingClosed(vvSlicerManager * m)
167 {
168   if (m == mSlicerManager) { 
169     close();
170     return;
171   }
172 }
173 //------------------------------------------------------------------------------
174
175
176 //------------------------------------------------------------------------------
177 void vvToolROIManager::close()
178 {
179   // Update to delete actors
180   UpdateAllContours();
181   QWidget::close();
182 }
183 //------------------------------------------------------------------------------
184
185
186 //------------------------------------------------------------------------------
187 void vvToolROIManager::SelectedImageHasChanged(vvSlicerManager * m) {
188   if (m != mSlicerManager) hide(); 
189   else {
190     show();
191   }
192 }
193 //------------------------------------------------------------------------------
194
195
196 //------------------------------------------------------------------------------
197 void vvToolROIManager::OpenBinaryImage() 
198 {
199   // Open images
200   QString Extensions = "Images files ( *.mha *.mhd *.hdr *.his)";
201   Extensions += ";;All Files (*)";
202   QStringList filename =
203     QFileDialog::getOpenFileNames(this,tr("Open binary image"),
204                                   mMainWindowBase->GetInputPathName(),Extensions);
205   if (filename.size() == 0) return;
206   
207   // For each selected file, open the image
208   for(int i=0; i<filename.size(); i++) {
209     // Open Image
210     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
211     vvImageReader::Pointer reader = vvImageReader::New();
212     std::vector<std::string> filenames;
213     filenames.push_back(filename[i].toStdString());
214     reader->SetInputFilenames(filenames);
215     reader->Update(vvImageReader::IMAGE);
216     QApplication::restoreOverrideCursor();
217
218     if (reader->GetLastError().size() != 0) {
219       std::cerr << "Error while reading " << filename[i].toStdString() << std::endl;
220       QString error = "Cannot open file \n";
221       error += reader->GetLastError().c_str();
222       QMessageBox::information(this,tr("Reading problem"),error);
223       return;
224     }
225     vvImage::Pointer binaryImage = reader->GetOutput();
226     AddImage(binaryImage, filename[i].toStdString(), mBackgroundValueSpinBox->value(),
227              (!mBGModeCheckBox->isChecked()));
228     mOpenedBinaryImage.push_back(binaryImage);
229   }
230
231   // Update the contours
232   UpdateAllContours(); 
233 }
234 //------------------------------------------------------------------------------
235
236
237 //------------------------------------------------------------------------------
238 void vvToolROIManager::OpenDicomImage() 
239 {
240   DD("OpenDicomImage");
241   QString Extensions = "Dicom Files ( *.dcm RS*)";
242   Extensions += ";;All Files (*)";
243   QString file = QFileDialog::getOpenFileName(this,tr("Merge Images"), 
244                                               mMainWindow->GetInputPathName(), 
245                                               Extensions);
246   if (file.isNull()) return;
247
248   //  AddDCStructContour(index, file);
249   vvMeshReader reader;
250   reader.SetFilename(file.toStdString());
251   vvStructSelector selector;
252   selector.SetStructures(reader.GetROINames());
253   // selector.EnablePropagationCheckBox(); FIXME Disable
254
255   // FIXME : change text -> allow to save binary image
256
257   if (selector.exec()) {
258     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
259     reader.SetSelectedItems(selector.getSelectedItems());
260     reader.SetImage(mSlicerManager->GetImage());
261     reader.Update();
262
263     // std::vector<vvMesh::Pointer> contours=reader.GetOutput();
264     // for (std::vector<vvMesh::Pointer>::iterator i=contours.begin();
265     //      i!=contours.end(); i++)
266     //   AddContour(index,*i,selector.PropagationEnabled());
267     QApplication::restoreOverrideCursor();
268   }
269
270
271
272 }
273 //------------------------------------------------------------------------------
274
275
276 //------------------------------------------------------------------------------
277 void vvToolROIManager::AddImage(vvImage * binaryImage, std::string filename, 
278                                 double BG, bool modeBG) 
279 {
280   // Check Dimension
281   int dim = mCurrentImage->GetNumberOfDimensions();
282   int bin_dim = binaryImage->GetNumberOfDimensions();
283   if (dim < bin_dim) {
284     std::ostringstream os;
285     os << "Error. Loaded binary image is " << bin_dim
286        << "D while selected image is " << dim << "D" << std::endl;
287     QMessageBox::information(this,tr("Reading problem"),os.str().c_str());
288     return;
289   }
290   
291   // Compute roi index
292   int n = mROIList.size();
293   
294   // Compute the name of the new ROI
295   std::ostringstream oss;
296   oss << vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(filename));
297   std::string name = oss.str();
298   
299   // Set color
300   std::vector<double> color;
301   color.push_back(1);
302   color.push_back(0);
303   color.push_back(0);
304
305   // Create ROI
306   clitk::DicomRT_ROI::Pointer roi = clitk::DicomRT_ROI::New();
307   roi->SetFromBinaryImage(binaryImage, n, name, color, filename);
308
309   // Add a new roi to the list
310   mROIList.push_back(roi);
311  
312   // Set BG or FG mode
313   if (modeBG) 
314     roi->SetBackgroundValueLabelImage(BG);
315   else 
316     roi->SetForegroundValueLabelImage(BG);
317   
318   // Change color
319   if (n<mDefaultLUTColor->GetNumberOfTableValues ()) {
320     double * color = mDefaultLUTColor->GetTableValue(n % mDefaultLUTColor->GetNumberOfTableValues ());
321     roi->SetDisplayColor(color[0], color[1], color[2]);
322   }
323   
324   // Add a new roi actor
325   QSharedPointer<vvROIActor> actor = QSharedPointer<vvROIActor>(new vvROIActor);
326   actor->SetBGMode(modeBG);
327   actor->SetROI(roi);
328   actor->SetSlicerManager(mSlicerManager);
329   actor->Initialize(n+1); // depth is n+1 to start at 1
330   mROIActorsList.push_back(actor);
331   
332   // CheckBox for "All"
333   if (actor->IsVisible()) mNumberOfVisibleROI++;
334   if (actor->IsContourVisible()) mNumberOfVisibleContourROI++;
335   
336   // Add ROI in tree
337   mTreeWidgetList.push_back(QSharedPointer<QTreeWidgetItem>(new QTreeWidgetItem(mTree)));
338   QTreeWidgetItem * w = mTreeWidgetList.back().data();
339   w->setText(0, QString("%1").arg(roi->GetROINumber()));
340   w->setText(1, QString("%1").arg(roi->GetName().c_str()));
341   w->setText(3, QString("%1").arg(actor->GetDepth()));  
342   QBrush brush(QColor(roi->GetDisplayColor()[0]*255, 
343                       roi->GetDisplayColor()[1]*255, 
344                       roi->GetDisplayColor()[2]*255));
345   brush.setStyle(Qt::SolidPattern);
346   w->setBackground(2, brush);
347   mMapROIToTreeWidget[roi] = w;
348   mMapTreeWidgetToROI[w] = roi;
349   mTree->resizeColumnToContents(0);
350   mTree->resizeColumnToContents(1);
351
352   // Update 
353   UpdateAllROIStatus(); 
354 }
355 //------------------------------------------------------------------------------
356
357
358 //------------------------------------------------------------------------------
359 void vvToolROIManager::UpdateAllContours() 
360 {
361   // Render loaded ROIs (the first is sufficient)
362   for(unsigned int i=0; i<mROIList.size(); i++) {
363     mROIActorsList[i]->Update();
364   }
365   for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
366     mSlicerManager->GetSlicer(i)->Render();
367   }  
368 }
369 //------------------------------------------------------------------------------
370
371
372 //------------------------------------------------------------------------------
373 void vvToolROIManager::UpdateAllROIStatus() {
374   int nbVisible = 0;
375   int nb = mROIList.size();
376   for(int i=0; i<nb; i++) {
377     if (mROIActorsList[i]->IsVisible()) {
378       nbVisible++;
379     }
380   }
381
382   // change the states
383   disconnect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int)));  
384   disconnect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool)));
385   if (nbVisible == nb) mCheckBoxShowAll->setCheckState(Qt::Checked);
386   else {
387     if (nbVisible == 0) mCheckBoxShowAll->setCheckState(Qt::Unchecked);
388     else mCheckBoxShowAll->setCheckState(Qt::PartiallyChecked);
389   }
390   connect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool)));
391   connect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int)));
392 }
393 //------------------------------------------------------------------------------
394
395
396 //------------------------------------------------------------------------------
397 void vvToolROIManager::SelectedItemChangedInTree() {
398   
399   // Search which roi is selected
400   QList<QTreeWidgetItem *> l = mTree->selectedItems();
401   if (l.size() == 0) {
402     //    mCurrentROIActor = 0;
403     mCurrentROI = NULL;
404     mGroupBoxROI->setEnabled(false);
405     return;
406   }
407   QTreeWidgetItem * w = l[0];
408   if (mMapTreeWidgetToROI.find(w) == mMapTreeWidgetToROI.end()) {
409     //    mCurrentROIActor = 0;
410     mCurrentROI = NULL;
411     mGroupBoxROI->setEnabled(false);
412     return;
413   }
414   if (w == NULL) return;
415   clitk::DicomRT_ROI * roi = mMapTreeWidgetToROI[w];
416   if (roi == NULL) return; // sometimes it is called while there is no roi anymore
417   // Get selected roi actor
418   int n = roi->GetROINumber();
419   QSharedPointer<vvROIActor> actor = mROIActorsList[n];
420   mCurrentROI = roi;
421   mCurrentROIActor = actor;
422
423   // Warning -> avoid unuseful Render here by disconnect slider 
424   // Update GUI
425   disconnect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItemChangedInTree()));
426   disconnect(mCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleROIToggled(bool)));
427   disconnect(mOpacitySlider, SIGNAL(valueChanged(int)), this, SLOT(OpacityChanged(int)));
428   disconnect(mChangeColorButton, SIGNAL(clicked()), this, SLOT(ChangeColor()));
429   disconnect(mContourCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleContourROIToggled(bool)));  
430   disconnect(mChangeContourColorButton, SIGNAL(clicked()), this, SLOT(ChangeContourColor()));
431   disconnect(mContourWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeContourWidth(int)));
432   disconnect(mDepthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeDepth(int)));
433
434   mGroupBoxROI->setEnabled(true);
435   mROInameLabel->setText(roi->GetName().c_str());
436   mCheckBoxShow->setChecked(actor->IsVisible());
437   mContourCheckBoxShow->setChecked(actor->IsContourVisible());
438   mContourWidthSpinBox->setValue(actor->GetContourWidth());
439   mDepthSpinBox->setValue(actor->GetDepth());
440   w->setText(3, QString("%1").arg(actor->GetDepth()));
441   mOpacitySlider->setValue((int)lrint(actor->GetOpacity()*100));
442   mOpacitySpinBox->setValue((int)lrint(actor->GetOpacity()*100));
443
444   connect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItemChangedInTree()));
445   connect(mCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleROIToggled(bool)));
446   connect(mOpacitySlider, SIGNAL(valueChanged(int)), this, SLOT(OpacityChanged(int)));
447   connect(mChangeColorButton, SIGNAL(clicked()), this, SLOT(ChangeColor()));
448   connect(mContourCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleContourROIToggled(bool)));  
449   connect(mChangeContourColorButton, SIGNAL(clicked()), this, SLOT(ChangeContourColor()));
450   connect(mContourWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeContourWidth(int)));
451   connect(mDepthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeDepth(int)));
452
453   
454   // Set the current color to the selected ROI name
455   mROInameLabel->setAutoFillBackground(true);// # This is important!!
456   mROInameLabel->setStyleSheet("QLabel { background-color : red; color : blue; }");
457   QColor color = QColor(mCurrentROI->GetDisplayColor()[0]*255,
458                         mCurrentROI->GetDisplayColor()[1]*255,
459                         mCurrentROI->GetDisplayColor()[2]*255);
460   QString values = QString("%1, %2, %3").arg(color.red()).arg(color.green()).arg(color.blue());
461   mROInameLabel->setStyleSheet("QLabel { background-color: rgb("+values+"); }");
462
463   // is this needed ?
464   //  actor->Update(); 
465   // Final rendering
466   // mCurrentSlicerManager->Render();
467 }
468 //------------------------------------------------------------------------------
469
470
471 //------------------------------------------------------------------------------
472 void vvToolROIManager::VisibleROIToggled(bool b) {
473   if (mCurrentROIActor == NULL) return;
474   if (b == mCurrentROIActor->IsVisible()) return; // nothing to do
475   mCurrentROIActor->SetVisible(b);
476   UpdateAllROIStatus();
477   mSlicerManager->Render(); 
478 }
479 //------------------------------------------------------------------------------
480
481
482 //------------------------------------------------------------------------------
483 void vvToolROIManager::VisibleContourROIToggled(bool b) {
484   if (mCurrentROIActor == NULL) return;
485   if (mCurrentROIActor->IsContourVisible() == b) return; // nothing to do
486   mCurrentROIActor->SetContourVisible(b);
487   mCurrentROIActor->UpdateColor();
488   mSlicerManager->Render(); 
489 }
490 //------------------------------------------------------------------------------
491
492
493 //------------------------------------------------------------------------------
494 void vvToolROIManager::OpacityChanged(int v) {
495   if (mCurrentROIActor == NULL) return;
496   mCurrentROIActor->SetOpacity((double)v/100.0);
497   mCurrentROIActor->UpdateColor();
498   mSlicerManager->Render(); 
499 }
500 //------------------------------------------------------------------------------
501
502
503 //------------------------------------------------------------------------------
504 void vvToolROIManager::AllVisibleROIToggled(int b) {
505   bool status = false;
506   if ((mCheckBoxShowAll->checkState() == Qt::Checked) ||
507       (mCheckBoxShowAll->checkState() == Qt::PartiallyChecked))  status = true;
508
509   for(uint i=0; i<mROIList.size(); i++) {
510     mROIActorsList[i]->SetVisible(status);
511   }
512   if (status) mCheckBoxShowAll->setCheckState(Qt::Checked);
513   else  mCheckBoxShowAll->setCheckState(Qt::Unchecked);
514   mCheckBoxShow->setChecked(status);
515   mSlicerManager->Render(); 
516 }
517 //------------------------------------------------------------------------------
518
519
520 //------------------------------------------------------------------------------
521 void vvToolROIManager::AllVisibleContourROIToggled(bool b) {
522   bool status = false;
523   if ((mContourCheckBoxShowAll->checkState() == Qt::Checked) ||
524       (mContourCheckBoxShowAll->checkState() == Qt::PartiallyChecked))  status = true;
525   // Update current 
526   for(uint i=0; i<mROIActorsList.size(); i++) {
527     mROIActorsList[i]->SetContourVisible(status);
528   }
529   // Update current selection
530   if (status) mContourCheckBoxShowAll->setCheckState(Qt::Checked);
531   else  mContourCheckBoxShowAll->setCheckState(Qt::Unchecked);
532   mContourCheckBoxShow->setChecked(status);
533   mSlicerManager->Render(); 
534 }
535 //------------------------------------------------------------------------------
536
537
538 //------------------------------------------------------------------------------
539 void vvToolROIManager::ChangeColor() {
540   QColor color;
541   color.setRgbF(mCurrentROIActor->GetROI()->GetDisplayColor()[0],
542                 mCurrentROIActor->GetROI()->GetDisplayColor()[1],
543                 mCurrentROIActor->GetROI()->GetDisplayColor()[2]);
544   QColor c = QColorDialog::getColor(color, this, "Choose the ROI color");
545   mCurrentROIActor->GetROI()->SetDisplayColor(c.redF(), c.greenF(), c.blueF());
546   mCurrentROIActor->UpdateColor();
547
548   QTreeWidgetItem * w = mMapROIToTreeWidget[mCurrentROI];
549   QBrush brush(QColor(mCurrentROI->GetDisplayColor()[0]*255,
550                       mCurrentROI->GetDisplayColor()[1]*255,
551                       mCurrentROI->GetDisplayColor()[2]*255));
552   brush.setStyle(Qt::SolidPattern);
553   w->setBackground(2, brush);
554   // Render
555   mSlicerManager->Render();
556 }
557 //------------------------------------------------------------------------------
558
559
560 //------------------------------------------------------------------------------
561 void vvToolROIManager::ChangeContourColor() {
562   QColor color;
563   color.setRgbF(mCurrentROIActor->GetContourColor()[0], 
564                 mCurrentROIActor->GetContourColor()[1], 
565                 mCurrentROIActor->GetContourColor()[2]);
566   QColor c = QColorDialog::getColor(color, this, "Choose the contour color");
567   mCurrentROIActor->SetContourColor(c.redF(), c.greenF(), c.blueF());
568   mCurrentROIActor->UpdateColor();
569   mSlicerManager->Render();
570 }
571 //------------------------------------------------------------------------------
572
573
574 //------------------------------------------------------------------------------
575 void vvToolROIManager::ChangeContourWidth(int n) {
576   mCurrentROIActor->SetContourWidth(n);
577   mCurrentROIActor->UpdateColor();
578   mSlicerManager->Render();
579 }
580 //------------------------------------------------------------------------------
581
582
583 //------------------------------------------------------------------------------
584 void vvToolROIManager::ChangeDepth(int n) {
585   mCurrentROIActor->SetDepth(n);
586   mCurrentROIActor->UpdateImage();
587   mSlicerManager->Render();
588   QList<QTreeWidgetItem *> l = mTree->selectedItems();
589   QTreeWidgetItem * w = l[0];
590   w->setText(3, QString("%1").arg(mCurrentROIActor->GetDepth()));
591 }
592 //------------------------------------------------------------------------------
593
594
595 //------------------------------------------------------------------------------
596 void vvToolROIManager::ReloadCurrentROI() {
597
598   // Remove all contours/overlay first
599   bool visible = mCurrentROIActor->IsVisible();
600   bool cvisible = mCurrentROIActor->IsContourVisible();
601   mCurrentROIActor->SetVisible(false);
602   mCurrentROIActor->SetContourVisible(false);
603   mSlicerManager->Render();
604   
605   // Reload image
606   vvImageReader::Pointer reader = vvImageReader::New();
607   reader->SetInputFilename(mCurrentROI->GetFilename());
608   reader->Update(vvImageReader::IMAGE);
609   if (reader->GetLastError() != "") {
610     QMessageBox::information(mMainWindowBase, tr("Sorry, error. Could not reload"), 
611                              reader->GetLastError().c_str());
612     return;
613   }
614
615   mCurrentROI->GetImage()->Reset();//GetFirstVTKImageData()->ReleaseData();
616   mCurrentROI->SetImage(reader->GetOutput());
617   
618   // Update visu
619   mCurrentROIActor->UpdateImage();
620   mCurrentROIActor->SetVisible(visible);
621   mCurrentROIActor->SetContourVisible(cvisible);
622   mSlicerManager->Render();    
623 }
624 //------------------------------------------------------------------------------