]> Creatis software - clitk.git/commitdiff
Add callbacks, now works.
authorDavid Sarrut <david.sarrut@gmail.com>
Mon, 20 Feb 2012 15:59:22 +0000 (16:59 +0100)
committerDavid Sarrut <david.sarrut@gmail.com>
Mon, 20 Feb 2012 15:59:22 +0000 (16:59 +0100)
vv/vvToolROIManager.cxx
vv/vvToolROIManager.h

index b681fc79298078be55c8e392ef957576b43b3847..87419389e89ba735ef10f13ac5ec8df4759fa79b 100644 (file)
@@ -85,6 +85,18 @@ vvToolROIManager::vvToolROIManager(vvMainWindowBase * parent, Qt::WindowFlags f)
           this, SLOT(AnImageIsBeingClosed(vvSlicerManager *)));
   connect(parent, SIGNAL(SelectedImageHasChanged(vvSlicerManager *)), 
           this, SLOT(SelectedImageHasChanged(vvSlicerManager *)));
+  connect(mOpenBinaryButton, SIGNAL(clicked()), this, SLOT(OpenBinaryImage()));
+  connect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItemChangedInTree()));
+  connect(mCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleROIToggled(bool)));
+  connect(mOpacitySlider, SIGNAL(valueChanged(int)), this, SLOT(OpacityChanged(int)));
+  connect(mChangeColorButton, SIGNAL(clicked()), this, SLOT(ChangeColor()));
+  connect(mContourCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleContourROIToggled(bool)));  
+  connect(mChangeContourColorButton, SIGNAL(clicked()), this, SLOT(ChangeContourColor()));
+  connect(mContourWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeContourWidth(int)));
+  connect(mDepthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeDepth(int)));
+  connect(mReloadButton, SIGNAL(clicked()), this, SLOT(ReloadCurrentROI()));
+  connect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int)));
+  connect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool)));
 
   // mMainWindowBase->GetTab()->setTabIcon(mTabNumber, GetToolIcon());
 }
@@ -319,3 +331,213 @@ void vvToolROIManager::UpdateAllROIStatus() {
 }
 //------------------------------------------------------------------------------
 
+
+//------------------------------------------------------------------------------
+void vvToolROIManager::SelectedItemChangedInTree() {
+  
+  // Search which roi is selected
+  QList<QTreeWidgetItem *> l = mTree->selectedItems();
+  if (l.size() == 0) {
+    //    mCurrentROIActor = 0;
+    mCurrentROI = NULL;
+    mGroupBoxROI->setEnabled(false);
+    return;
+  }
+  QTreeWidgetItem * w = l[0];
+  //std::cout << "selected item -> " << w->text(1).toStdString() << std::endl;
+  //std::cout << "m_NumberOfTool -> " << m_NumberOfTool << std::endl;
+  if (mMapTreeWidgetToROI.find(w) == mMapTreeWidgetToROI.end()) {
+    //    mCurrentROIActor = 0;
+    mCurrentROI = NULL;
+    mGroupBoxROI->setEnabled(false);
+    return;
+  }
+  clitk::DicomRT_ROI * roi = mMapTreeWidgetToROI[w];
+  // Get selected roi actor
+  QSharedPointer<vvROIActor> actor = mROIActorsList[roi->GetROINumber()];
+  mCurrentROI = roi;
+  mCurrentROIActor = actor;
+
+  // Warning -> avoid unuseful Render here by disconnect slider 
+  // Update GUI
+  disconnect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItemChangedInTree()));
+  disconnect(mCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleROIToggled(bool)));
+  disconnect(mOpacitySlider, SIGNAL(valueChanged(int)), this, SLOT(OpacityChanged(int)));
+  disconnect(mChangeColorButton, SIGNAL(clicked()), this, SLOT(ChangeColor()));
+  disconnect(mContourCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleContourROIToggled(bool)));  
+  disconnect(mChangeContourColorButton, SIGNAL(clicked()), this, SLOT(ChangeContourColor()));
+  disconnect(mContourWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeContourWidth(int)));
+  disconnect(mDepthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeDepth(int)));
+
+  mGroupBoxROI->setEnabled(true);
+  mROInameLabel->setText(roi->GetName().c_str());
+  mCheckBoxShow->setChecked(actor->IsVisible());
+  mContourCheckBoxShow->setChecked(actor->IsContourVisible());
+  mContourWidthSpinBox->setValue(actor->GetContourWidth());
+  mDepthSpinBox->setValue(actor->GetDepth());
+  w->setText(3, QString("%1").arg(actor->GetDepth()));
+  mOpacitySlider->setValue((int)lrint(actor->GetOpacity()*100));
+  mOpacitySpinBox->setValue((int)lrint(actor->GetOpacity()*100));
+
+  connect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItemChangedInTree()));
+  connect(mCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleROIToggled(bool)));
+  connect(mOpacitySlider, SIGNAL(valueChanged(int)), this, SLOT(OpacityChanged(int)));
+  connect(mChangeColorButton, SIGNAL(clicked()), this, SLOT(ChangeColor()));
+  connect(mContourCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleContourROIToggled(bool)));  
+  connect(mChangeContourColorButton, SIGNAL(clicked()), this, SLOT(ChangeContourColor()));
+  connect(mContourWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeContourWidth(int)));
+  connect(mDepthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeDepth(int)));
+
+  // is this needed ?
+  //  actor->Update(); 
+  // Final rendering
+  // mCurrentSlicerManager->Render();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolROIManager::VisibleROIToggled(bool b) {
+  if (mCurrentROIActor == NULL) return;
+  if (b == mCurrentROIActor->IsVisible()) return; // nothing to do
+  mCurrentROIActor->SetVisible(b);
+  UpdateAllROIStatus();
+  mSlicerManager->Render(); 
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolROIManager::VisibleContourROIToggled(bool b) {
+  if (mCurrentROIActor == NULL) return;
+  if (mCurrentROIActor->IsContourVisible() == b) return; // nothing to do
+  mCurrentROIActor->SetContourVisible(b);
+  mCurrentROIActor->UpdateColor();
+  mSlicerManager->Render(); 
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolROIManager::OpacityChanged(int v) {
+  if (mCurrentROIActor == NULL) return;
+  mCurrentROIActor->SetOpacity((double)v/100.0);
+  mCurrentROIActor->UpdateColor();
+  mSlicerManager->Render(); 
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolROIManager::AllVisibleROIToggled(int b) {
+  bool status = false;
+  if ((mCheckBoxShowAll->checkState() == Qt::Checked) ||
+      (mCheckBoxShowAll->checkState() == Qt::PartiallyChecked))  status = true;
+
+  for(uint i=0; i<mROIList.size(); i++) {
+    mROIActorsList[i]->SetVisible(status);
+  }
+  if (status) mCheckBoxShowAll->setCheckState(Qt::Checked);
+  else  mCheckBoxShowAll->setCheckState(Qt::Unchecked);
+  mCheckBoxShow->setChecked(status);
+  mSlicerManager->Render(); 
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolROIManager::AllVisibleContourROIToggled(bool b) {
+  bool status = false;
+  if ((mContourCheckBoxShowAll->checkState() == Qt::Checked) ||
+      (mContourCheckBoxShowAll->checkState() == Qt::PartiallyChecked))  status = true;
+  // Update current 
+  for(uint i=0; i<mROIActorsList.size(); i++) {
+    mROIActorsList[i]->SetContourVisible(status);
+  }
+  // Update current selection
+  if (status) mContourCheckBoxShowAll->setCheckState(Qt::Checked);
+  else  mContourCheckBoxShowAll->setCheckState(Qt::Unchecked);
+  mContourCheckBoxShow->setChecked(status);
+  mSlicerManager->Render(); 
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolROIManager::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
+  mSlicerManager->Render();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolROIManager::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();
+  mSlicerManager->Render();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolROIManager::ChangeContourWidth(int n) {
+  mCurrentROIActor->SetContourWidth(n);
+  mCurrentROIActor->UpdateColor();
+  mSlicerManager->Render();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolROIManager::ChangeDepth(int n) {
+  mCurrentROIActor->SetDepth(n);
+  mCurrentROIActor->UpdateImage();
+  mSlicerManager->Render();
+  QList<QTreeWidgetItem *> l = mTree->selectedItems();
+  QTreeWidgetItem * w = l[0];
+  w->setText(3, QString("%1").arg(mCurrentROIActor->GetDepth()));
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolROIManager::ReloadCurrentROI() {
+  // Reload image
+  vvImageReader::Pointer reader = vvImageReader::New();
+  reader->SetInputFilename(mCurrentROI->GetFilename());
+  reader->Update(vvImageReader::IMAGE);
+  if (reader->GetLastError() != "") {
+    QMessageBox::information(mMainWindowBase, tr("Sorry, error. Could not reload"), 
+                             reader->GetLastError().c_str());
+    return;
+  }
+  mCurrentROI->GetImage()->GetFirstVTKImageData()->ReleaseData();
+  mCurrentROI->SetImage(reader->GetOutput());
+  
+  // Update visu"
+  mCurrentROIActor->UpdateImage();
+  mSlicerManager->Render();    
+}
+//------------------------------------------------------------------------------
+
+
index be3b987c311bae45a503d3c72b8d01957a4a91ba..14b9f42220a76c8234403ddd9eab6c8a11704556 100644 (file)
@@ -51,6 +51,17 @@ class vvToolROIManager:
   void AnImageIsBeingClosed(vvSlicerManager *);
   void SelectedImageHasChanged(vvSlicerManager *);
   void OpenBinaryImage();
+  void SelectedItemChangedInTree();
+  void VisibleROIToggled(bool b);
+  void VisibleContourROIToggled(bool b);
+  void OpacityChanged(int v);
+  void ChangeColor();
+  void ChangeContourColor();
+  void ChangeContourWidth(int n);
+  void ChangeDepth(int n);
+  void AllVisibleROIToggled(int b);
+  void AllVisibleContourROIToggled(bool b);
+  void ReloadCurrentROI();  
 
 protected:
   Ui::vvToolROIManager ui;
@@ -72,6 +83,9 @@ protected:
   std::map<clitk::DicomRT_ROI::Pointer, QTreeWidgetItem *> mMapROIToTreeWidget;
   std::map<QTreeWidgetItem *, clitk::DicomRT_ROI::Pointer> mMapTreeWidgetToROI;
   
+  // Data for current selected roi
+  clitk::DicomRT_ROI::Pointer mCurrentROI;
+  QSharedPointer<vvROIActor> mCurrentROIActor;  
  
 }; // end class vvToolROIManager
 //------------------------------------------------------------------------------