+
+
+//------------------------------------------------------------------------------
+bool vvToolStructureSetManager::close()
+{
+ return vvToolWidgetBase::close();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolStructureSetManager::closeEvent(QCloseEvent *event)
+{
+ // DD("vvToolStructureSetManager::closeEvent()");
+ std::vector<vvSlicerManager*>::iterator iter = std::find(mListOfInputs.begin(), mListOfInputs.end(), mCurrentSlicerManager);
+ if (iter != mListOfInputs.end()) mListOfInputs.erase(iter);
+
+ // DD("how delete mListOfOpenTool ???");
+ mListOfOpenTool.erase(mCurrentSlicerManager);
+
+ mCheckBoxShowAll->setCheckState(Qt::Unchecked);
+ mContourCheckBoxShowAll->setCheckState(Qt::Unchecked);
+ if (mCurrentSlicerManager != 0) mCurrentSlicerManager->Render();
+ if (mCurrentStructureSetActor) {
+ for(int i=0; i<mCurrentStructureSetActor->GetNumberOfROIs(); i++) {
+ // DD(i);
+ mCurrentStructureSetActor->GetROIList()[i]->SetVisible(false);
+ mCurrentStructureSetActor->GetROIList()[i]->SetContourVisible(false);
+ delete mCurrentStructureSetActor->GetROIList()[i];
+ }
+ }
+
+ if (!isWindow()) {
+ if (m_NumberOfTool == 1) {
+ mMainWindow->GetTab()->removeTab(mTabNumber);
+ }
+ }
+
+ event->accept();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+// CURRENT ROI INTERACTION
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolStructureSetManager::SelectedItemChangedInTree() {
+ // Search which roi is selected
+ QList<QTreeWidgetItem *> l = mTree->selectedItems();
+ if (l.size() == 0) {
+ mCurrentROIActor = NULL;
+ mCurrentROI = NULL;
+ mGroupBoxROI->setEnabled(false);
+ return;
+ }
+ QTreeWidgetItem * w = l[0];
+ if (mMapTreeWidgetToROI.find(w) == mMapTreeWidgetToROI.end()) {
+ mCurrentROIActor = NULL;
+ mCurrentROI = NULL;
+ mGroupBoxROI->setEnabled(false);
+ return;
+ }
+ clitk::DicomRT_ROI * roi = mMapTreeWidgetToROI[w];
+ // Get selected roi actor
+ vvROIActor * actor = mStructureSetActorsList[mCurrentStructureSetIndex]->GetROIActor(roi->GetROINumber());
+ mCurrentROI = roi;
+ mCurrentROIActor = actor;
+
+ // Update GUI
+ mGroupBoxROI->setEnabled(true);
+ mROInameLabel->setText(roi->GetName().c_str());
+ mCheckBoxShow->setChecked(actor->IsVisible());
+ mContourCheckBoxShow->setChecked(actor->IsContourVisible());
+ mContourWidthSpinBox->setValue(actor->GetContourWidth());
+
+ // Warning -> avoir unuseful Render here by disconnect slider
+ disconnect(mOpacitySlider, SIGNAL(valueChanged(int)),
+ this, SLOT(OpacityChanged(int)));
+ mOpacitySlider->setValue((int)lrint(actor->GetOpacity()*100));
+ mOpacitySpinBox->setValue((int)lrint(actor->GetOpacity()*100));
+ connect(mOpacitySlider, SIGNAL(valueChanged(int)),
+ this, SLOT(OpacityChanged(int)));
+ actor->Update();
+
+ // Final rendering
+ mCurrentSlicerManager->Render();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolStructureSetManager::UpdateAllROIStatus() {
+ int nbVisible = 0;
+ int nb = mCurrentStructureSetActor->GetROIList().size();
+ for(int i=0; i<nb; i++) {
+ if (mCurrentStructureSetActor->GetROIList()[i]->IsVisible()) {
+ nbVisible++;
+ }
+ }
+
+ disconnect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int)));
+ disconnect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool)));
+ if (nbVisible == nb) mCheckBoxShowAll->setCheckState(Qt::Checked);
+ else {
+ if (nbVisible == 0) mCheckBoxShowAll->setCheckState(Qt::Unchecked);
+ else mCheckBoxShowAll->setCheckState(Qt::PartiallyChecked);
+ }
+ connect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool)));
+ connect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int)));
+}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+void vvToolStructureSetManager::VisibleROIToggled(bool b) {
+ if (mCurrentROIActor == NULL) return;
+ if (b == mCurrentROIActor->IsVisible()) return; // nothing to do
+ mCurrentROIActor->SetVisible(b);
+ UpdateAllROIStatus();
+ mCurrentSlicerManager->Render();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolStructureSetManager::VisibleContourROIToggled(bool b) {
+ if (mCurrentROIActor == NULL) return;
+ if (mCurrentROIActor->IsContourVisible() == b) return; // nothing to do
+ mCurrentROIActor->SetContourVisible(b);
+ mCurrentROIActor->UpdateColor();
+ mCurrentSlicerManager->Render();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolStructureSetManager::OpacityChanged(int v) {
+ if (mCurrentROIActor == NULL) return;
+ mCurrentROIActor->SetOpacity((double)v/100.0);
+ mCurrentROIActor->UpdateColor();
+ mCurrentSlicerManager->Render();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolStructureSetManager::AllVisibleROIToggled(int b) {
+ bool status = false;
+ if ((mCheckBoxShowAll->checkState() == Qt::Checked) ||
+ (mCheckBoxShowAll->checkState() == Qt::PartiallyChecked)) status = true;
+
+ for(int i=0; i<mCurrentStructureSetActor->GetNumberOfROIs(); i++) {
+ mCurrentStructureSetActor->GetROIList()[i]->SetVisible(status);
+ }
+ if (status) mCheckBoxShowAll->setCheckState(Qt::Checked);
+ else mCheckBoxShowAll->setCheckState(Qt::Unchecked);
+ mCheckBoxShow->setChecked(status);
+ mCurrentSlicerManager->Render();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolStructureSetManager::AllVisibleContourROIToggled(bool b) {
+ bool status = false;
+ if ((mContourCheckBoxShowAll->checkState() == Qt::Checked) ||
+ (mContourCheckBoxShowAll->checkState() == Qt::PartiallyChecked)) status = true;
+ // Update current
+ for(int i=0; i<mCurrentStructureSetActor->GetNumberOfROIs(); i++) {
+ mCurrentStructureSetActor->GetROIList()[i]->SetContourVisible(status);
+ }
+ // Update current selection
+ if (status) mContourCheckBoxShowAll->setCheckState(Qt::Checked);
+ else mContourCheckBoxShowAll->setCheckState(Qt::Unchecked);
+ mContourCheckBoxShow->setChecked(status);
+ mCurrentSlicerManager->Render();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolStructureSetManager::ChangeColor() {
+ QColor color;
+ color.setRgbF(mCurrentROIActor->GetROI()->GetDisplayColor()[0],
+ mCurrentROIActor->GetROI()->GetDisplayColor()[1],
+ mCurrentROIActor->GetROI()->GetDisplayColor()[2]);
+ QColor c = QColorDialog::getColor(color, this, "Choose the ROI color");
+ mCurrentROIActor->GetROI()->SetDisplayColor(c.redF(), c.greenF(), c.blueF());
+ mCurrentROIActor->UpdateColor();
+
+ QTreeWidgetItem * w = mMapROIToTreeWidget[mCurrentROI];
+ QBrush brush(QColor(mCurrentROI->GetDisplayColor()[0]*255,
+ mCurrentROI->GetDisplayColor()[1]*255,
+ mCurrentROI->GetDisplayColor()[2]*255));
+ brush.setStyle(Qt::SolidPattern);
+ w->setBackground(2, brush);
+ // Render
+ mCurrentSlicerManager->Render();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolStructureSetManager::ChangeContourColor() {
+ QColor color;
+ color.setRgbF(mCurrentROIActor->GetContourColor()[0],
+ mCurrentROIActor->GetContourColor()[1],
+ mCurrentROIActor->GetContourColor()[2]);
+ QColor c = QColorDialog::getColor(color, this, "Choose the contour color");
+ mCurrentROIActor->SetContourColor(c.redF(), c.greenF(), c.blueF());
+ mCurrentROIActor->UpdateColor();
+ mCurrentSlicerManager->Render();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolStructureSetManager::ChangeContourWidth(int n) {
+ mCurrentROIActor->SetContourWidth(n);
+ mCurrentROIActor->UpdateColor();
+ mCurrentSlicerManager->Render();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolStructureSetManager::ReloadCurrentROI() {
+ // Reload image
+ vvImageReader * mReader = new vvImageReader;
+ mReader->SetInputFilename(mCurrentROI->GetFilename());
+ mReader->Update(IMAGE);
+ if (mReader->GetLastError() != "") {
+ QMessageBox::information(mMainWindowBase, tr("Sorry, error. Could not reload"), mReader->GetLastError().c_str());
+ return;
+ }
+ // delete mCurrentROI->GetImage();
+ // DD(mCurrentROI->GetImage()->GetFirstVTKImageData()->GetDataReleased());
+// DD(mCurrentROI->GetImage()->GetFirstVTKImageData()->GetReferenceCount());
+ mCurrentROI->GetImage()->GetFirstVTKImageData()->ReleaseData();
+ // DD(mCurrentROI->GetImage()->GetFirstVTKImageData()->GetDataReleased());
+ mCurrentROI->SetImage(mReader->GetOutput());
+
+ // Update visu"
+ mCurrentROIActor->UpdateImage();
+ mCurrentSlicerManager->Render();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolStructureSetManager::CheckInputList(std::vector<vvSlicerManager*> & l, int & index)
+{
+ DD("TODO CheckInputList");
+
+ for(unsigned int i=0; i<l.size(); i++) {
+ std::vector<vvSlicerManager*>::iterator iter = std::find(mListOfInputs.begin(), mListOfInputs.end(), l[i]);
+ if (iter != mListOfInputs.end()) {
+ for(unsigned int j=i;j<l.size(); j++) l[j] = l[j+1];
+ l.pop_back();
+ if (index == (int)i) index = 0;
+ i--;
+ }
+ }
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+// STATIC
+vvToolStructureSetManager * vvToolStructureSetManager::AddImage(vvSlicerManager * m, vvImage::Pointer image, double BG, bool m_modeBG)
+{
+ // DD("static AddImage");
+ //DD(mListOfInputs.size());
+
+ if (mListOfOpenTool[m]) {
+ DD("found");
+ vvToolStructureSetManager * tool = mListOfOpenTool[m];
+ tool->AddImage(image, "bidon.mhd", BG, m_modeBG);
+ tool->UpdateImage();
+ // tool->show();
+ return tool;
+ }
+ else {
+ DD("not found");
+ }
+
+ std::vector<vvSlicerManager*>::iterator iter =
+ std::find(mListOfInputs.begin(), mListOfInputs.end(), m);
+ if (iter != mListOfInputs.end()) {
+ DD("found");
+ DD("TODO");
+
+ }
+ else {
+ DD("not found");
+
+ // mMainWindowBase instead of NULL, should be static ?
+
+ vvToolStructureSetManager * tool = new vvToolStructureSetManager
+ (CREATOR(vvToolStructureSetManager)->GetMainWindow(), Qt::Dialog, m);
+
+ // WARNING : load list of image and selec -> to change to force mCurrentSlicerManager
+
+ // tool->InputIsSelected();
+ tool->AddImage(image, "bidon.mhd", BG, m_modeBG);
+ tool->UpdateImage();
+ tool->show();
+ return tool;
+ }
+ return NULL;
+}
+//------------------------------------------------------------------------------