1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
20 #include "vvToolStructureSetManager.h"
21 #include "vvImageReader.h"
22 #include "vvStructureSetActor.h"
24 #include "vvROIActor.h"
27 #include <QFileDialog>
28 #include <QMessageBox>
29 #include <QColorDialog>
30 #include <QAbstractEventDispatcher>
33 #include <vtkLookupTable.h>
34 #include <vtkRenderWindow.h>
36 //------------------------------------------------------------------------------
37 // Create the tool and automagically (I like this word) insert it in
38 // the main window menu.
39 ADD_TOOL(vvToolStructureSetManager);
40 //------------------------------------------------------------------------------
42 int vvToolStructureSetManager::m_NumberOfTool = 0;
43 std::vector<vvSlicerManager*> vvToolStructureSetManager::mListOfInputs;
44 std::map<vvSlicerManager*, vvToolStructureSetManager*> vvToolStructureSetManager::mListOfOpenTool;
46 //------------------------------------------------------------------------------
47 vvToolStructureSetManager::vvToolStructureSetManager(vvMainWindowBase * parent,
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()
56 Ui_vvToolStructureSetManager::setupUi(mToolWidget);
58 // this->setFixedWidth(120);
60 mCurrentStructureSetActor = 0;
61 connect(mCloseButton, SIGNAL(clicked()), this, SLOT(close()));
62 mCloseButton->setVisible(false);
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;
81 #include "vvDefaultLut.h"
84 if (current == NULL) {
85 MustOpenDialogWhenCreated = true;
86 AddInputSelector("Select image");
89 MustOpenDialogWhenCreated = false;
90 mMainButtonBox->setEnabled(true);
91 mCurrentSlicerManager = current;
92 mCurrentImage = mCurrentSlicerManager->GetImage();
93 mToolWidget->setEnabled(true);
94 InputIsSelected(mCurrentSlicerManager);
97 //------------------------------------------------------------------------------
100 //------------------------------------------------------------------------------
101 vvToolStructureSetManager::~vvToolStructureSetManager()
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();
111 //std::cout << "vvToolStructureSetManager::~vvToolStructureSetManager()" << std::endl;
113 //------------------------------------------------------------------------------
116 //------------------------------------------------------------------------------
118 void vvToolStructureSetManager::Initialize() {
119 SetToolName("ROIManager_OLD");
120 SetToolMenuName("Display ROI (binary image)");
121 SetToolIconFilename(":/common/icons/tool-roi.png");
122 SetToolTip("Display ROI from a binary image.");
123 SetToolExperimental(true);
125 //------------------------------------------------------------------------------
128 //------------------------------------------------------------------------------
129 void vvToolStructureSetManager::InputIsSelected(vvSlicerManager *m)
131 //std::cout << "vvToolStructureSetManager::InputIsSelected()" << std::endl;
133 //int mTabNumber = parent->GetTab()->addTab(this, "");
134 // this->setFixedWidth(120);
135 //this->setPreferedHeight(441);
137 if (mCurrentImage->GetNumberOfDimensions() != 3) {
138 QMessageBox::information(this,tr("Sorry only 3D yet"), tr("Sorry only 3D yet"));
143 HideInputSelector(); // splitter
144 mToolInputSelectionWidget->hide();
145 mLabelInputInfo->setText(QString("%1").arg(m->GetFileName().c_str()));
148 // if (!isWindow()) {
149 mListOfInputs.push_back(mCurrentSlicerManager);
150 mListOfOpenTool[mCurrentSlicerManager] = this;
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(mDepthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeDepth(int)));
163 connect(mReloadButton, SIGNAL(clicked()), this, SLOT(ReloadCurrentROI()));
164 connect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int)));
165 connect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool)));
167 // Browse to load image
168 if (MustOpenDialogWhenCreated)
171 //------------------------------------------------------------------------------
174 //------------------------------------------------------------------------------
175 void vvToolStructureSetManager::Open(int type) {
177 case 0: OpenBinaryImage(); return; // Open binary image;
178 case 1: DD("TODO"); return; // Open DICOM RT
179 case 2: DD("TODO"); return; // Open mesh
180 default: std::cerr << "Error ????" << std::endl; exit(0);
183 //------------------------------------------------------------------------------
186 //------------------------------------------------------------------------------
187 void vvToolStructureSetManager::AddRoiInTreeWidget(clitk::DicomRT_ROI * roi, QTreeWidget * ww) {
188 mTreeWidgetList.push_back(QSharedPointer<QTreeWidgetItem>(new QTreeWidgetItem(ww)));
189 QTreeWidgetItem * w = mTreeWidgetList.back().data();
190 w->setText(0, QString("%1").arg(roi->GetROINumber()));
191 w->setText(1, QString("%1").arg(roi->GetName().c_str()));
192 vvROIActor * actor = mStructureSetActorsList[0]->GetROIActor(roi->GetROINumber());
193 w->setText(3, QString("%1").arg(actor->GetDepth()));
194 QBrush brush(QColor(roi->GetDisplayColor()[0]*255, roi->GetDisplayColor()[1]*255, roi->GetDisplayColor()[2]*255));
195 brush.setStyle(Qt::SolidPattern);
196 w->setBackground(2, brush);
197 mMapROIToTreeWidget[roi] = w;
198 mMapTreeWidgetToROI[w] = roi;
199 mTree->resizeColumnToContents(0);
200 mTree->resizeColumnToContents(1);
202 //------------------------------------------------------------------------------
205 //------------------------------------------------------------------------------
206 void vvToolStructureSetManager::UpdateStructureSetInTreeWidget(int index, clitk::DicomRT_StructureSet * s) {
209 const std::vector<clitk::DicomRT_ROI::Pointer> & rois = s->GetListOfROI();
210 for(unsigned int i=0; i<rois.size(); i++) {
211 if (mMapROIToTreeWidget.find(rois[i]) == mMapROIToTreeWidget.end())
212 AddRoiInTreeWidget(rois[i], mTree); // replace mTree with ss if several SS
215 clitk::DicomRT_StructureSet::ROIConstIteratorType iter;
216 for(iter = s->GetROIs().begin(); iter != s->GetROIs().end(); iter++) {
217 clitk::DicomRT_ROI::Pointer roi = iter->second;
218 if (mMapROIToTreeWidget.find(roi) == mMapROIToTreeWidget.end())
219 AddRoiInTreeWidget(roi, mTree); // replace mTree with ss if several SS
222 //------------------------------------------------------------------------------
225 //------------------------------------------------------------------------------
226 int vvToolStructureSetManager::AddStructureSet(clitk::DicomRT_StructureSet * mStructureSet) {
227 // Create actor for this SS
229 QSharedPointer<vvStructureSetActor> mStructureSetActor(new vvStructureSetActor);
231 mStructureSetActor->SetStructureSet(mStructureSet);
232 mStructureSetActor->SetSlicerManager(mCurrentSlicerManager);
233 // Insert in lists and get index
234 mStructureSetsList.push_back(mStructureSet);
235 mStructureSetActorsList.push_back(mStructureSetActor);
236 int index = mStructureSetsList.size()-1;
240 //------------------------------------------------------------------------------
243 //------------------------------------------------------------------------------
244 void vvToolStructureSetManager::OpenBinaryImage()
247 if (mCurrentStructureSet == NULL) {
248 if (mStructureSetsList.size() == 0) { // Create a default SS
249 clitk::DicomRT_StructureSet::Pointer mStructureSet = clitk::DicomRT_StructureSet::New();
250 index = AddStructureSet(mStructureSet);
252 else { // Get first SS
256 index = mCurrentStructureSetIndex;
258 mCurrentStructureSet = mStructureSetsList[index];
259 mCurrentStructureSetActor = mStructureSetActorsList[index].data();
260 mCurrentStructureSetIndex = index;
262 QString Extensions = "Images files ( *.mha *.mhd *.hdr *.his)";
263 Extensions += ";;All Files (*)";
264 QStringList filename =
265 QFileDialog::getOpenFileNames(this,tr("Open binary image"),
266 mMainWindowBase->GetInputPathName(),Extensions);
267 if (filename.size() == 0) return;
268 mLoadedROIIndex.clear();
269 for(int i=0; i<filename.size(); i++) {
271 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
272 vvImageReader::Pointer reader = vvImageReader::New();
273 std::vector<std::string> filenames;
274 filenames.push_back(filename[i].toStdString());
275 reader->SetInputFilenames(filenames);
276 reader->Update(vvImageReader::IMAGE);
277 QApplication::restoreOverrideCursor();
279 if (reader->GetLastError().size() != 0) {
280 std::cerr << "Error while reading " << filename[i].toStdString() << std::endl;
281 QString error = "Cannot open file \n";
282 error += reader->GetLastError().c_str();
283 QMessageBox::information(this,tr("Reading problem"),error);
286 vvImage::Pointer binaryImage = reader->GetOutput();
287 AddImage(binaryImage, filename[i].toStdString(), mBackgroundValueSpinBox->value());
288 mOpenedBinaryImage.push_back(binaryImage);
293 //------------------------------------------------------------------------------
296 //------------------------------------------------------------------------------
297 void vvToolStructureSetManager::UpdateImage()
299 // Update the TreeWidget
300 UpdateStructureSetInTreeWidget(mCurrentStructureSetIndex, mCurrentStructureSet);
301 // Render loaded ROIs (the first is sufficient)
302 for(unsigned int i=0; i<mLoadedROIIndex.size(); i++) {
303 mCurrentStructureSetActor->GetROIActor(mLoadedROIIndex[i])->Update();
305 for(int i=0; i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
306 mCurrentSlicerManager->GetSlicer(i)->Render();
309 //------------------------------------------------------------------------------
312 //------------------------------------------------------------------------------
313 void vvToolStructureSetManager::AddImage(vvImage * binaryImage, std::string filename,
314 double BG, bool m_modeBG)
316 // Check current structure set
318 if (mCurrentStructureSet == NULL) {
319 if (mStructureSetsList.size() == 0) { // Create a default SS
320 clitk::DicomRT_StructureSet::Pointer mStructureSet = clitk::DicomRT_StructureSet::New();
321 index = AddStructureSet(mStructureSet);
323 else { // Get first SS
327 index = mCurrentStructureSetIndex;
329 mCurrentStructureSet = mStructureSetsList[index];
330 mCurrentStructureSetActor = mStructureSetActorsList[index].data();
331 mCurrentStructureSetIndex = index;
334 int dim = mCurrentImage->GetNumberOfDimensions();
335 int bin_dim = binaryImage->GetNumberOfDimensions();
336 if (dim < bin_dim) { ////////// TO CHANGE FOR 3D/4D
337 std::ostringstream os;
338 os << "Error. Loaded binary image is " << bin_dim
339 << "D while selected image is " << dim << "D" << std::endl;
340 QMessageBox::information(this,tr("Reading problem"),os.str().c_str());
344 // Add a new roi to the structure
345 int n = mCurrentStructureSet->AddBinaryImageAsNewROI(binaryImage, filename);
346 mLoadedROIIndex.push_back(n);
348 mCurrentStructureSet->GetROIFromROINumber(n)->SetBackgroundValueLabelImage(BG);
350 mCurrentStructureSet->GetROIFromROINumber(n)->SetForegroundValueLabelImage(BG);
353 if (n<mDefaultLUTColor->GetNumberOfTableValues ()) {
354 double * color = mDefaultLUTColor->GetTableValue(n % mDefaultLUTColor->GetNumberOfTableValues ());
355 mCurrentStructureSet->GetROIFromROINumber(n)->SetDisplayColor(color[0], color[1], color[2]);
358 // Add a new roi actor
359 mCurrentStructureSetActor->CreateNewROIActor(n, m_modeBG);
361 // CheckBox for "All"
362 if (mCurrentStructureSetActor->GetROIActor(n)->IsVisible())
363 mNumberOfVisibleROI++;
364 if (mCurrentStructureSetActor->GetROIActor(n)->IsContourVisible())
365 mNumberOfVisibleContourROI++;
366 UpdateAllROIStatus();
368 //------------------------------------------------------------------------------
371 //------------------------------------------------------------------------------
372 void vvToolStructureSetManager::apply()
376 //------------------------------------------------------------------------------
379 //------------------------------------------------------------------------------
380 bool vvToolStructureSetManager::close()
382 //std::cout << "vvToolStructureSetManager::close()" << std::endl;
384 return vvToolWidgetBase::close();
386 //------------------------------------------------------------------------------
389 //------------------------------------------------------------------------------
390 void vvToolStructureSetManager::closeEvent(QCloseEvent *event)
392 //std::cout << "vvToolStructureSetManager::closeEvent()" << std::endl;
394 std::vector<vvSlicerManager*>::iterator iter = std::find(mListOfInputs.begin(), mListOfInputs.end(), mCurrentSlicerManager);
395 if (iter != mListOfInputs.end()) mListOfInputs.erase(iter);
397 // DD("how delete mListOfOpenTool ???");
398 mListOfOpenTool.erase(mCurrentSlicerManager);
400 mCheckBoxShowAll->setCheckState(Qt::Unchecked);
401 mContourCheckBoxShowAll->setCheckState(Qt::Unchecked);
402 if (mCurrentSlicerManager != 0)
403 mCurrentSlicerManager->Render();
406 if (m_NumberOfTool == 1) {
407 mMainWindow->GetTab()->removeTab(mTabNumber);
413 //------------------------------------------------------------------------------
416 //------------------------------------------------------------------------------
417 // CURRENT ROI INTERACTION
418 //------------------------------------------------------------------------------
421 //------------------------------------------------------------------------------
422 void vvToolStructureSetManager::SelectedItemChangedInTree() {
424 // Search which roi is selected
425 QList<QTreeWidgetItem *> l = mTree->selectedItems();
427 mCurrentROIActor = NULL;
429 mGroupBoxROI->setEnabled(false);
432 QTreeWidgetItem * w = l[0];
433 //std::cout << "selected item -> " << w->text(1).toStdString() << std::endl;
434 //std::cout << "m_NumberOfTool -> " << m_NumberOfTool << std::endl;
435 if (mMapTreeWidgetToROI.find(w) == mMapTreeWidgetToROI.end()) {
436 mCurrentROIActor = NULL;
438 mGroupBoxROI->setEnabled(false);
441 clitk::DicomRT_ROI * roi = mMapTreeWidgetToROI[w];
442 // Get selected roi actor
443 vvROIActor * actor = mStructureSetActorsList[mCurrentStructureSetIndex]->GetROIActor(roi->GetROINumber());
445 mCurrentROIActor = actor;
447 // Warning -> avoid unuseful Render here by disconnect slider
449 disconnect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItemChangedInTree()));
450 disconnect(mCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleROIToggled(bool)));
451 disconnect(mOpacitySlider, SIGNAL(valueChanged(int)), this, SLOT(OpacityChanged(int)));
452 disconnect(mChangeColorButton, SIGNAL(clicked()), this, SLOT(ChangeColor()));
453 disconnect(mContourCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleContourROIToggled(bool)));
454 disconnect(mChangeContourColorButton, SIGNAL(clicked()), this, SLOT(ChangeContourColor()));
455 disconnect(mContourWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeContourWidth(int)));
456 disconnect(mDepthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeDepth(int)));
458 mGroupBoxROI->setEnabled(true);
459 mROInameLabel->setText(roi->GetName().c_str());
460 mCheckBoxShow->setChecked(actor->IsVisible());
461 mContourCheckBoxShow->setChecked(actor->IsContourVisible());
462 mContourWidthSpinBox->setValue(actor->GetContourWidth());
463 mDepthSpinBox->setValue(actor->GetDepth());
464 w->setText(3, QString("%1").arg(actor->GetDepth()));
465 mOpacitySlider->setValue((int)lrint(actor->GetOpacity()*100));
466 mOpacitySpinBox->setValue((int)lrint(actor->GetOpacity()*100));
468 connect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItemChangedInTree()));
469 connect(mCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleROIToggled(bool)));
470 connect(mOpacitySlider, SIGNAL(valueChanged(int)), this, SLOT(OpacityChanged(int)));
471 connect(mChangeColorButton, SIGNAL(clicked()), this, SLOT(ChangeColor()));
472 connect(mContourCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleContourROIToggled(bool)));
473 connect(mChangeContourColorButton, SIGNAL(clicked()), this, SLOT(ChangeContourColor()));
474 connect(mContourWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeContourWidth(int)));
475 connect(mDepthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeDepth(int)));
480 // mCurrentSlicerManager->Render();
482 //------------------------------------------------------------------------------
485 //------------------------------------------------------------------------------
486 void vvToolStructureSetManager::UpdateAllROIStatus() {
488 int nb = mCurrentStructureSetActor->GetROIList().size();
489 for(int i=0; i<nb; i++) {
490 if (mCurrentStructureSetActor->GetROIList()[i]->IsVisible()) {
495 disconnect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int)));
496 disconnect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool)));
497 if (nbVisible == nb) mCheckBoxShowAll->setCheckState(Qt::Checked);
499 if (nbVisible == 0) mCheckBoxShowAll->setCheckState(Qt::Unchecked);
500 else mCheckBoxShowAll->setCheckState(Qt::PartiallyChecked);
502 connect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool)));
503 connect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int)));
505 //------------------------------------------------------------------------------
507 //------------------------------------------------------------------------------
508 void vvToolStructureSetManager::VisibleROIToggled(bool b) {
509 if (mCurrentROIActor == NULL) return;
510 if (b == mCurrentROIActor->IsVisible()) return; // nothing to do
511 mCurrentROIActor->SetVisible(b);
512 UpdateAllROIStatus();
513 mCurrentSlicerManager->Render();
515 //------------------------------------------------------------------------------
518 //------------------------------------------------------------------------------
519 void vvToolStructureSetManager::VisibleContourROIToggled(bool b) {
520 if (mCurrentROIActor == NULL) return;
521 if (mCurrentROIActor->IsContourVisible() == b) return; // nothing to do
522 mCurrentROIActor->SetContourVisible(b);
523 mCurrentROIActor->UpdateColor();
524 mCurrentSlicerManager->Render();
526 //------------------------------------------------------------------------------
529 //------------------------------------------------------------------------------
530 void vvToolStructureSetManager::OpacityChanged(int v) {
531 if (mCurrentROIActor == NULL) return;
532 mCurrentROIActor->SetOpacity((double)v/100.0);
533 mCurrentROIActor->UpdateColor();
534 mCurrentSlicerManager->Render();
536 //------------------------------------------------------------------------------
539 //------------------------------------------------------------------------------
540 void vvToolStructureSetManager::AllVisibleROIToggled(int b) {
542 if ((mCheckBoxShowAll->checkState() == Qt::Checked) ||
543 (mCheckBoxShowAll->checkState() == Qt::PartiallyChecked)) status = true;
545 for(int i=0; i<mCurrentStructureSetActor->GetNumberOfROIs(); i++) {
546 mCurrentStructureSetActor->GetROIList()[i]->SetVisible(status);
548 if (status) mCheckBoxShowAll->setCheckState(Qt::Checked);
549 else mCheckBoxShowAll->setCheckState(Qt::Unchecked);
550 mCheckBoxShow->setChecked(status);
551 mCurrentSlicerManager->Render();
553 //------------------------------------------------------------------------------
556 //------------------------------------------------------------------------------
557 void vvToolStructureSetManager::AllVisibleContourROIToggled(bool b) {
559 if ((mContourCheckBoxShowAll->checkState() == Qt::Checked) ||
560 (mContourCheckBoxShowAll->checkState() == Qt::PartiallyChecked)) status = true;
562 for(int i=0; i<mCurrentStructureSetActor->GetNumberOfROIs(); i++) {
563 mCurrentStructureSetActor->GetROIList()[i]->SetContourVisible(status);
565 // Update current selection
566 if (status) mContourCheckBoxShowAll->setCheckState(Qt::Checked);
567 else mContourCheckBoxShowAll->setCheckState(Qt::Unchecked);
568 mContourCheckBoxShow->setChecked(status);
569 mCurrentSlicerManager->Render();
571 //------------------------------------------------------------------------------
574 //------------------------------------------------------------------------------
575 void vvToolStructureSetManager::ChangeColor() {
577 color.setRgbF(mCurrentROIActor->GetROI()->GetDisplayColor()[0],
578 mCurrentROIActor->GetROI()->GetDisplayColor()[1],
579 mCurrentROIActor->GetROI()->GetDisplayColor()[2]);
580 QColor c = QColorDialog::getColor(color, this, "Choose the ROI color");
581 mCurrentROIActor->GetROI()->SetDisplayColor(c.redF(), c.greenF(), c.blueF());
582 mCurrentROIActor->UpdateColor();
584 QTreeWidgetItem * w = mMapROIToTreeWidget[mCurrentROI];
585 QBrush brush(QColor(mCurrentROI->GetDisplayColor()[0]*255,
586 mCurrentROI->GetDisplayColor()[1]*255,
587 mCurrentROI->GetDisplayColor()[2]*255));
588 brush.setStyle(Qt::SolidPattern);
589 w->setBackground(2, brush);
591 mCurrentSlicerManager->Render();
593 //------------------------------------------------------------------------------
596 //------------------------------------------------------------------------------
597 void vvToolStructureSetManager::ChangeContourColor() {
599 color.setRgbF(mCurrentROIActor->GetContourColor()[0],
600 mCurrentROIActor->GetContourColor()[1],
601 mCurrentROIActor->GetContourColor()[2]);
602 QColor c = QColorDialog::getColor(color, this, "Choose the contour color");
603 mCurrentROIActor->SetContourColor(c.redF(), c.greenF(), c.blueF());
604 mCurrentROIActor->UpdateColor();
605 mCurrentSlicerManager->Render();
607 //------------------------------------------------------------------------------
610 //------------------------------------------------------------------------------
611 void vvToolStructureSetManager::ChangeContourWidth(int n) {
612 mCurrentROIActor->SetContourWidth(n);
613 mCurrentROIActor->UpdateColor();
614 mCurrentSlicerManager->Render();
616 //------------------------------------------------------------------------------
619 //------------------------------------------------------------------------------
620 void vvToolStructureSetManager::ChangeDepth(int n) {
621 mCurrentROIActor->SetDepth(n);
622 mCurrentROIActor->UpdateImage();
623 mCurrentSlicerManager->Render();
624 QList<QTreeWidgetItem *> l = mTree->selectedItems();
625 QTreeWidgetItem * w = l[0];
626 w->setText(3, QString("%1").arg(mCurrentROIActor->GetDepth()));
628 //------------------------------------------------------------------------------
631 //------------------------------------------------------------------------------
632 void vvToolStructureSetManager::ReloadCurrentROI() {
634 vvImageReader::Pointer reader = vvImageReader::New();
635 reader->SetInputFilename(mCurrentROI->GetFilename());
636 reader->Update(vvImageReader::IMAGE);
637 if (reader->GetLastError() != "") {
638 QMessageBox::information(mMainWindowBase, tr("Sorry, error. Could not reload"), reader->GetLastError().c_str());
641 mCurrentROI->GetImage()->GetFirstVTKImageData()->ReleaseData();
642 mCurrentROI->SetImage(reader->GetOutput());
645 mCurrentROIActor->UpdateImage();
646 mCurrentSlicerManager->Render();
648 //------------------------------------------------------------------------------
651 //------------------------------------------------------------------------------
652 void vvToolStructureSetManager::CheckInputList(std::vector<vvSlicerManager*> & l, int & index)
654 for(unsigned int i=0; i<l.size(); i++) {
655 std::vector<vvSlicerManager*>::iterator iter = std::find(mListOfInputs.begin(), mListOfInputs.end(), l[i]);
656 if (iter != mListOfInputs.end()) {
657 for(unsigned int j=i;j<l.size(); j++) l[j] = l[j+1];
659 if (index == (int)i) index = 0;
664 //------------------------------------------------------------------------------
667 //------------------------------------------------------------------------------
669 vvToolStructureSetManager * vvToolStructureSetManager::AddImage(vvSlicerManager * m, std::string name, vvImage::Pointer image, double BG, bool m_modeBG)
671 // If the tool is open for this vvSlicerManager, use it and return
672 if (mListOfOpenTool[m]) {
673 vvToolStructureSetManager * tool = mListOfOpenTool[m];
674 tool->AddImage(image, name, BG, m_modeBG);
679 // If the tool is not open, create it
680 vvToolStructureSetManager * tool = new vvToolStructureSetManager
681 (CREATOR(vvToolStructureSetManager)->GetMainWindow(), Qt::Dialog, m);
682 tool->AddImage(image, name, BG, m_modeBG);
687 //------------------------------------------------------------------------------