]> Creatis software - clitk.git/commitdiff
Copy pasted code from overlay to fusion for sequences. This yet another
authorSimon Rit <simon.rit@creatis.insa-lyon.fr>
Wed, 12 Jun 2013 08:28:37 +0000 (10:28 +0200)
committerSimon Rit <simon.rit@creatis.insa-lyon.fr>
Wed, 12 Jun 2013 08:28:37 +0000 (10:28 +0200)
illustration that fusion and overlay are essentially the same. This should
replace the function of Remi, SetFusionSequence. All this is to be done...

vv/vv.cxx
vv/vvMainWindow.cxx
vv/vvMainWindow.h
vv/vvReadState.cxx
vv/vvSlicerManager.cxx
vv/vvSlicerManager.h

index 7506aa94b81d792f1f0d359ffe49ca0185e5bae9..5df3415e0437ed44a77a9ebf15c6358bd8e620d2 100644 (file)
--- a/vv/vv.cxx
+++ b/vv/vv.cxx
@@ -81,6 +81,8 @@ void open_sequence(vvMainWindow &window,
     window.AddOverlayImage(n_image_loaded-1,sequence_filenames,vvImageReader::MERGEDWITHTIME);
   else if (open_mode==O_LANDMARKS)
     window.AddLandmarks(n_image_loaded-1,sequence_filenames);
+  else if (open_mode==O_FUSION)
+    window.AddFusionImage(n_image_loaded-1,sequence_filenames,vvImageReader::MERGEDWITHTIME);
   else {
     std::cerr << "Sequences are not managed for opening " << open_mode_names[open_mode] << std::endl;
     exit(1);
@@ -278,7 +280,7 @@ int main( int argc, char** argv )
         else if (open_mode==O_CONTOUR)
           window.AddDCStructContour(n_image_loaded-1,current.c_str());
         else if (open_mode==O_FUSION)
-          window.AddFusionImage(n_image_loaded-1,current.c_str());
+          window.AddFusionImage(n_image_loaded-1,image,vvImageReader::IMAGE);
         else if (open_mode==O_LANDMARKS)
           window.AddLandmarks(n_image_loaded-1,image);
         open_mode = O_BASE;
index d7d076a60d83038ee3b02a4dde80bf77d3d421b1..42107987512a3c78686455c9e0f266ebb253b4e3 100644 (file)
@@ -2146,9 +2146,15 @@ void vvMainWindow::SelectFusionImage()
 
     QString Extensions = EXTENSIONS;
     Extensions += ";;All Files (*)";
-    QString file = QFileDialog::getOpenFileName(this,tr("Load Fusion image"),mInputPathName,Extensions);
-    if (!file.isEmpty())
-      AddFusionImage(index,file);
+    QStringList files = QFileDialog::getOpenFileNames(this,tr("Load Fusion image"),mInputPathName,Extensions);
+    if (files.isEmpty())
+      return;
+
+    std::vector<std::string> vecFileNames;
+    for (int i = 0; i < files.size(); i++) {
+      vecFileNames.push_back(files[i].toStdString());
+    }
+    AddFusionImage(index,vecFileNames,vvImageReader::IMAGE);
 }
 //------------------------------------------------------------------------------
 
@@ -2163,77 +2169,78 @@ void vvMainWindow::ResetTransformationToIdentity()
 //------------------------------------------------------------------------------
 
 //------------------------------------------------------------------------------
-void vvMainWindow::AddFusionImage(int index, QString file)
+void vvMainWindow::AddFusionImage(int index, std::vector<std::string> fileNames, vvImageReader::LoadedImageType type)
 {
+  QString file(fileNames[0].c_str());
   if (QFile::exists(file))
   {
     mInputPathName = itksys::SystemTools::GetFilenamePath(file.toStdString()).c_str();
     itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(
       file.toStdString().c_str(), itk::ImageIOFactory::ReadMode);
-    reader->SetFileName(file.toStdString().c_str());
+    reader->SetFileName(fileNames[0].c_str());
     reader->ReadImageInformation();
     std::string component = reader->GetComponentTypeAsString(reader->GetComponentType());
-    if (reader) {
-      QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
-      vvProgressDialog progress("Opening fusion");
-      qApp->processEvents();
+    int dimension = reader->GetNumberOfDimensions();
+    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+    vvProgressDialog progress("Opening fusion");
+    qApp->processEvents();
 
-      std::string filename = itksys::SystemTools::GetFilenameWithoutExtension(file.toStdString()).c_str();
-      if (mSlicerManagers[index]->SetFusion(file.toStdString(),
-        reader->GetNumberOfDimensions(), component)) {
-          //create an item in the tree with good settings
-          QTreeWidgetItem *item = new QTreeWidgetItem();
-          item->setData(0,Qt::UserRole,file.toStdString().c_str());
-          item->setData(1,Qt::UserRole,tr("fusion"));
-          QFileInfo fileinfo(filename.c_str()); //Do not show the path
+    std::string filename = itksys::SystemTools::GetFilenameWithoutExtension(file.toStdString()).c_str();
+    if (mSlicerManagers[index]->SetFusion(fileNames,dimension, component,type)) {
+      //create an item in the tree with good settings
+      QTreeWidgetItem *item = new QTreeWidgetItem();
+      item->setData(0,Qt::UserRole,file.toStdString().c_str());
+      item->setData(1,Qt::UserRole,tr("fusion"));
+      QFileInfo fileinfo(file); //Do not show the path
           item->setData(COLUMN_IMAGE_NAME,Qt::DisplayRole,fileinfo.fileName());
           item->setToolTip(COLUMN_IMAGE_NAME, mSlicerManagers[index]->GetListOfAbsoluteFilePathInOneString("fusion").c_str());
           qApp->processEvents();
 
-          for (int j = 1; j <= 4; j++) {
-            item->setData(j,Qt::CheckStateRole,DataTree->topLevelItem(index)->data(j,Qt::CheckStateRole));
-          }
-
-          //Create the buttons for reload and close
-          qApp->processEvents();
-          QTreePushButton* cButton = new QTreePushButton;
-          cButton->setItem(item);
-          cButton->setColumn(COLUMN_CLOSE_IMAGE);
-          cButton->setToolTip(tr("close image"));
-          cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
-          connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
-            this,SLOT(CloseImage(QTreeWidgetItem*, int)));
-
-          QTreePushButton* rButton = new QTreePushButton;
-          rButton->setItem(item);
-          rButton->setColumn(COLUMN_RELOAD_IMAGE);
-          rButton->setToolTip(tr("reload image"));
-          rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
-          connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
-            this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
-
-          DataTree->topLevelItem(index)->setExpanded(1);
-          DataTree->topLevelItem(index)->addChild(item);
-          DataTree->setItemWidget(item, COLUMN_CLOSE_IMAGE, cButton);
-          DataTree->setItemWidget(item, COLUMN_RELOAD_IMAGE, rButton);
-
-          //set the id of the image
-          QString id = DataTree->topLevelItem(index)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString();
-          item->setData(COLUMN_IMAGE_NAME,Qt::UserRole,id.toStdString().c_str());
-          UpdateTree();
-          qApp->processEvents();
-          ImageInfoChanged();
-          QApplication::restoreOverrideCursor();
-      } else {
-        QApplication::restoreOverrideCursor();
-        QString error = "Cannot import the new image.\n";
-        error += mSlicerManagers[index]->GetLastError().c_str();
-        QMessageBox::information(this,tr("Problem reading image !"),error);
+      for (int j = 1; j <= 4; j++) {
+        item->setData(j,Qt::CheckStateRole,DataTree->topLevelItem(index)->data(j,Qt::CheckStateRole));
       }
+
+      //Create the buttons for reload and close
+      qApp->processEvents();
+      QTreePushButton* cButton = new QTreePushButton;
+      cButton->setItem(item);
+      cButton->setColumn(COLUMN_CLOSE_IMAGE);
+      cButton->setToolTip(tr("close image"));
+      cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
+      connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
+        this,SLOT(CloseImage(QTreeWidgetItem*, int)));
+
+      QTreePushButton* rButton = new QTreePushButton;
+      rButton->setItem(item);
+      rButton->setColumn(COLUMN_RELOAD_IMAGE);
+      rButton->setToolTip(tr("reload image"));
+      rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
+      connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
+        this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
+
+      DataTree->topLevelItem(index)->setExpanded(1);
+      DataTree->topLevelItem(index)->addChild(item);
+      DataTree->setItemWidget(item, COLUMN_CLOSE_IMAGE, cButton);
+      DataTree->setItemWidget(item, COLUMN_RELOAD_IMAGE, rButton);
+
+      //set the id of the image
+      QString id = DataTree->topLevelItem(index)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString();
+      item->setData(COLUMN_IMAGE_NAME,Qt::UserRole,id.toStdString().c_str());
+      UpdateTree();
+      qApp->processEvents();
+      ImageInfoChanged();
+      QApplication::restoreOverrideCursor();
+
+      // Update the display to update, e.g., the sliders
+      for(int i=0; i<4; i++)
+        DisplaySliders(index, i);
     } else {
+      QApplication::restoreOverrideCursor();
       QString error = "Cannot import the new image.\n";
+      error += mSlicerManagers[index]->GetLastError().c_str();
       QMessageBox::information(this,tr("Problem reading image !"),error);
     }
+    WindowLevelChanged();
   }
   else
     QMessageBox::information(this,tr("Problem reading Fusion !"),"File doesn't exist!");
index dd95c0a83fa273f65b6b6ecb4a83052f806424f6..e5e315509b1924c2392358cc36c6fe80c4e14fa4 100644 (file)
@@ -55,7 +55,7 @@ class vvMainWindow: public vvMainWindowBase,
   vvSlicerManager * AddImage(vvImage::Pointer image,std::string filename);
   void AddField(QString file,int index);
   void AddOverlayImage(int index, std::vector<std::string> fileNames, vvImageReader::LoadedImageType type);
-  void AddFusionImage(int index, QString filename);
+  void AddFusionImage(int index, std::vector<std::string> fileNames, vvImageReader::LoadedImageType type);
   void AddROI(int index, QString filename);
 
   //Process the sequence for fusion:
index 980bbf1ffeac7a832fc086265f68f14a05911dd0..6a248b2b82b23d456146fb79687c8212ddf1902b 100644 (file)
@@ -168,8 +168,12 @@ std::string vvReadState::ReadFusion(int index)
     if (m_XmlReader->isStartElement()) {
       if (value == "FileName") {
         file = m_XmlReader->readElementText().toStdString();
-        if (!m_XmlReader->hasError())
-          m_Window->AddFusionImage(index, file.c_str());
+        if (!m_XmlReader->hasError()) {
+          // TODO: manage sequence of images
+          std::vector<std::string> vec;
+          vec.push_back(file.c_str());
+          m_Window->AddFusionImage(index, vec, vvImageReader::IMAGE);
+        }
       }
       if (value == "FusionOpacity") {
         vali = m_XmlReader->readElementText().toInt();
index 5afe71bd9a2df0ce2f5265916ba47f787a2ad78d..89fd42b49fae4177e89ec0c2ee4590e38c9a6f54 100644 (file)
@@ -279,20 +279,18 @@ bool vvSlicerManager::SetOverlay(std::vector<std::string> filenames,int dim, std
 \r
 \r
 //----------------------------------------------------------------------------\r
-bool vvSlicerManager::SetFusion(std::string filename,int dim, std::string component)\r
+bool vvSlicerManager::SetFusion(std::vector<std::string> filenames,int dim, std::string component, vvImageReader::LoadedImageType type)\r
 {\r
-  mFusionName = filename;\r
+  mFusionName = filenames[0];\r
   mFusionComponent = component;\r
   if (dim > mImage->GetNumberOfDimensions()) {\r
-    mLastError = " Overlay dimension cannot be greater then reference image!";\r
+    mLastError = " Fusion dimension cannot be greater than reference image!";\r
     return false;\r
   }\r
   if (mFusionReader.IsNull())\r
     mFusionReader = vvImageReader::New();\r
-  std::vector<std::string> filenames;\r
-  filenames.push_back(filename);\r
   mFusionReader->SetInputFilenames(filenames);\r
-  mFusionReader->Update(mImage->GetNumberOfDimensions(),component.c_str(),mType);\r
+  mFusionReader->Update(type);\r
   if (mFusionReader->GetLastError().size() == 0) {\r
     for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
       mSlicers[i]->SetFusion(mFusionReader->GetOutput());\r
index 60f239219532764c57a2e971f717c691066ba88f..bbdd2a41dad6cfb36c24f8c5d8a143f69dd9e7f6 100644 (file)
@@ -77,7 +77,7 @@ class vvSlicerManager : public QObject {
   bool SetImages(std::vector<std::string> filenames, vvImageReader::LoadedImageType type, int n=0);
 
   bool SetOverlay(std::vector<std::string> filenames, int dim, std::string component, vvImageReader::LoadedImageType type);
-  bool SetFusion(std::string filename, int dim, std::string component);
+  bool SetFusion(std::vector<std::string> filenames,int dim, std::string component, vvImageReader::LoadedImageType type);
   bool SetFusionSequence(std::vector<std::string> filenames, int dim, std::string component, vvImageReader::LoadedImageType type);
   ///Set a VF by loading it from the disk
   bool SetVF(std::string filename);