]> Creatis software - clitk.git/blobdiff - vv/vvToolStructureSetManager.cxx
Merge branch 'master' of /home/dsarrut/clitk3.server
[clitk.git] / vv / vvToolStructureSetManager.cxx
index c9e336884b65bb746c5808f3723ae05ba4c49368..f625e4cd46ef0945fa3c40df9036a2be50e547ee 100644 (file)
@@ -3,7 +3,7 @@
 
   Authors belong to:
   - University of LYON              http://www.universite-lyon.fr/
-  - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
+  - Léon Bérard cancer center       http://www.centreleonberard.fr
   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
 
   This software is distributed WITHOUT ANY WARRANTY; without even
@@ -14,7 +14,7 @@
 
   - BSD        See included LICENSE.txt file
   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-  ======================================================================-====*/
+  ===========================================================================**/
 
 // vv
 #include "vvToolStructureSetManager.h"
@@ -27,7 +27,8 @@
 #include <QFileDialog>
 #include <QMessageBox>
 #include <QColorDialog>
-
+#include <QAbstractEventDispatcher>
 // vtk
 #include <vtkLookupTable.h>
 #include <vtkRenderWindow.h>
@@ -41,7 +42,6 @@ ADD_TOOL(vvToolStructureSetManager);
 int vvToolStructureSetManager::m_NumberOfTool = 0;
 std::vector<vvSlicerManager*> vvToolStructureSetManager::mListOfInputs;
 std::map<vvSlicerManager*, vvToolStructureSetManager*> vvToolStructureSetManager::mListOfOpenTool;
-bool vvToolStructureSetManager::mDestroyed = false;
 
 //------------------------------------------------------------------------------
 vvToolStructureSetManager::vvToolStructureSetManager(vvMainWindowBase * parent, 
@@ -100,9 +100,15 @@ vvToolStructureSetManager::vvToolStructureSetManager(vvMainWindowBase * parent,
 //------------------------------------------------------------------------------
 vvToolStructureSetManager::~vvToolStructureSetManager()
 {
-  //std::cout << "vvToolStructureSetManager::~vvToolStructureSetManager()" << std::endl;
   m_NumberOfTool--;
-  mDestroyed=true;
+  
+  // clearing the list at this point avoids
+  // segfaulting due to events being dispatched
+  // after object destruction
+  mTreeWidgetList.clear();
+  mTree->clearSelection();
+
+  //std::cout << "vvToolStructureSetManager::~vvToolStructureSetManager()" << std::endl;
 }
 //------------------------------------------------------------------------------
 
@@ -131,6 +137,7 @@ void vvToolStructureSetManager::InputIsSelected(vvSlicerManager *m)
   if (mCurrentImage->GetNumberOfDimensions() != 3) {
     QMessageBox::information(this,tr("Sorry only 3D yet"), tr("Sorry only 3D yet"));
     close();
+    return;
   }
   // Hide selector
   HideInputSelector(); // splitter
@@ -195,11 +202,19 @@ void vvToolStructureSetManager::AddRoiInTreeWidget(clitk::DicomRT_ROI * roi, QTr
 //------------------------------------------------------------------------------
 void vvToolStructureSetManager::UpdateStructureSetInTreeWidget(int index, clitk::DicomRT_StructureSet * s) {
   // Insert ROI
+  /*
   const std::vector<clitk::DicomRT_ROI::Pointer> & rois = s->GetListOfROI();
   for(unsigned int i=0; i<rois.size(); i++) {
     if (mMapROIToTreeWidget.find(rois[i]) == mMapROIToTreeWidget.end())
       AddRoiInTreeWidget(rois[i], mTree); // replace mTree with ss if several SS
   }
+  */
+  clitk::DicomRT_StructureSet::ROIConstIteratorType iter;
+  for(iter = s->GetROIs().begin(); iter != s->GetROIs().end(); iter++) {
+    clitk::DicomRT_ROI::Pointer roi = iter->second;
+    if (mMapROIToTreeWidget.find(roi) == mMapROIToTreeWidget.end())
+      AddRoiInTreeWidget(roi, mTree); // replace mTree with ss if several SS
+  }
 }
 //------------------------------------------------------------------------------
 
@@ -241,7 +256,7 @@ void vvToolStructureSetManager::OpenBinaryImage()
   mCurrentStructureSetActor = mStructureSetActorsList[index].data();
   mCurrentStructureSetIndex = index;
   // Open images
-  QString Extensions = "Images files ( *.mhd *.hdr *.his)";
+  QString Extensions = "Images files ( *.mha *.mhd *.hdr *.his)";
   Extensions += ";;All Files (*)";
   QStringList filename =
     QFileDialog::getOpenFileNames(this,tr("Open binary image"),
@@ -255,7 +270,7 @@ void vvToolStructureSetManager::OpenBinaryImage()
     std::vector<std::string> filenames;
     filenames.push_back(filename[i].toStdString());
     reader->SetInputFilenames(filenames);
-    reader->Update(IMAGE);
+    reader->Update(vvImageReader::IMAGE);
     QApplication::restoreOverrideCursor();
 
     if (reader->GetLastError().size() != 0) {
@@ -327,14 +342,14 @@ void vvToolStructureSetManager::AddImage(vvImage * binaryImage, std::string file
   int n = mCurrentStructureSet->AddBinaryImageAsNewROI(binaryImage, filename);
   mLoadedROIIndex.push_back(n);
   if (m_modeBG) 
-    mCurrentStructureSet->GetROI(n)->SetBackgroundValueLabelImage(BG);
+    mCurrentStructureSet->GetROIFromROINumber(n)->SetBackgroundValueLabelImage(BG);
   else 
-    mCurrentStructureSet->GetROI(n)->SetForegroundValueLabelImage(BG);
+    mCurrentStructureSet->GetROIFromROINumber(n)->SetForegroundValueLabelImage(BG);
   
   // Change color
   if (n<mDefaultLUTColor->GetNumberOfTableValues ()) {
     double * color = mDefaultLUTColor->GetTableValue(n % mDefaultLUTColor->GetNumberOfTableValues ());
-    mCurrentStructureSet->GetROI(n)->SetDisplayColor(color[0], color[1], color[2]);
+    mCurrentStructureSet->GetROIFromROINumber(n)->SetDisplayColor(color[0], color[1], color[2]);
   }
   
   // Add a new roi actor
@@ -362,6 +377,7 @@ void vvToolStructureSetManager::apply()
 bool vvToolStructureSetManager::close()
 {
   //std::cout << "vvToolStructureSetManager::close()" << std::endl;
+
   return vvToolWidgetBase::close();
 }
 //------------------------------------------------------------------------------
@@ -371,7 +387,6 @@ bool vvToolStructureSetManager::close()
 void vvToolStructureSetManager::closeEvent(QCloseEvent *event) 
 {
   //std::cout << "vvToolStructureSetManager::closeEvent()" << std::endl;
-  disconnect(mTree, SIGNAL(itemSelectionChanged()));
 
   std::vector<vvSlicerManager*>::iterator iter = std::find(mListOfInputs.begin(), mListOfInputs.end(), mCurrentSlicerManager);
   if (iter != mListOfInputs.end()) mListOfInputs.erase(iter);
@@ -403,16 +418,6 @@ void vvToolStructureSetManager::closeEvent(QCloseEvent *event)
 //------------------------------------------------------------------------------
 void vvToolStructureSetManager::SelectedItemChangedInTree() {
   
-  // ATTENTION:
-  //  RP - 05/04/2011
-  //  Horrible solution for the problem of triggering this event
-  // after the window has been closed and the object instance 
-  // has been destroyed. I couldn't find the place where the
-  // window is destroyed, though.
-  //
-  if (mDestroyed)
-    return;
-  
   // Search which roi is selected
   QList<QTreeWidgetItem *> l = mTree->selectedItems();
   if (l.size() == 0) {
@@ -597,7 +602,7 @@ void vvToolStructureSetManager::ReloadCurrentROI() {
   // Reload image
   vvImageReader::Pointer reader = vvImageReader::New();
   reader->SetInputFilename(mCurrentROI->GetFilename());
-  reader->Update(IMAGE);
+  reader->Update(vvImageReader::IMAGE);
   if (reader->GetLastError() != "") {
     QMessageBox::information(mMainWindowBase, tr("Sorry, error. Could not reload"), reader->GetLastError().c_str());
     return;