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