]> Creatis software - clitk.git/commitdiff
Avoid to open more than one overlay/fusion/vf per image with command line
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Mon, 7 Mar 2016 08:42:17 +0000 (09:42 +0100)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Mon, 7 Mar 2016 08:42:17 +0000 (09:42 +0100)
vv/vv.cxx
vv/vvMainWindow.cxx
vv/vvMainWindow.h

index 6a367f7da07ccac1973ffff458bde573cbe75616..a5a0215fb1d3cc31aa8b0b66137ce67d6d22b0e6 100644 (file)
--- a/vv/vv.cxx
+++ b/vv/vv.cxx
@@ -77,11 +77,11 @@ void open_sequence(vvMainWindow &window,
   const std::string open_mode_names[] = {"base", "overlay", "fusion", "vf", "contour", "fusionSequence"};
   if(open_mode==O_BASE)
     window.LoadImages(sequence_filenames, vvImageReader::MERGEDWITHTIME);
-  else if (open_mode==O_OVERLAY)
+  else if (open_mode==O_OVERLAY && window.CheckAddedImage(n_image_loaded-1, "overlay"))
     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)
+  else if (open_mode==O_FUSION && window.CheckAddedImage(n_image_loaded-1, "fusion") && window.CheckAddedImage(n_image_loaded-1, "fusionSequence"))
     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;
@@ -273,13 +273,13 @@ int main( int argc, char** argv )
             first_of_wl_set = n_image_loaded-1;
           }
         }
-        else if (open_mode==O_VF)
+        else if (open_mode==O_VF && window.CheckAddedImage(n_image_loaded-1, "vector"))
           window.AddField(current.c_str(), n_image_loaded-1);
-        else if (open_mode==O_OVERLAY)
+        else if (open_mode==O_OVERLAY && window.CheckAddedImage(n_image_loaded-1, "overlay"))
           window.AddOverlayImage(n_image_loaded-1,image,vvImageReader::IMAGE);
         else if (open_mode==O_CONTOUR)
           window.AddDCStructContour(n_image_loaded-1,current.c_str());
-        else if (open_mode==O_FUSION)
+        else if (open_mode==O_FUSION && window.CheckAddedImage(n_image_loaded-1, "fusion") && window.CheckAddedImage(n_image_loaded-1, "fusionSequence"))
           window.AddFusionImage(n_image_loaded-1,image,vvImageReader::IMAGE);
         else if (open_mode==O_LANDMARKS)
           window.AddLandmarks(n_image_loaded-1,image);
index 474ddde737f80d28e939fdf91bcbd0713d3bbff9..9d29824c3abc473bdf860008032c581dd97643df 100644 (file)
@@ -1989,28 +1989,37 @@ void vvMainWindow::SelectOverlayImage()
 { 
   int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
 
+  if (!(CheckAddedImage(index, "overlay")))
+    return;
+
+  QString Extensions = EXTENSIONS;
+  Extensions += ";;All Files (*)";
+  QStringList files = QFileDialog::getOpenFileNames(this,tr("Load Overlay 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());
+  }
+
+  AddOverlayImage(index,vecFileNames,vvImageReader::IMAGE);
+}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+bool vvMainWindow::CheckAddedImage(int index, QString imageType)
+{ 
   //check if one overlay image is added
   for (int child = 0; child < DataTree->topLevelItem(index)->childCount(); child++)
-    if (DataTree->topLevelItem(index)->child(child)->data(1,Qt::UserRole).toString() == "overlay") {
+    if (DataTree->topLevelItem(index)->child(child)->data(1,Qt::UserRole).toString().compare(imageType) == 0) {
       QString error = "Cannot add more than one compared image\n";
       error += "Please remove first ";
       error += DataTree->topLevelItem(index)->child(child)->data(COLUMN_IMAGE_NAME,Qt::DisplayRole).toString();
       QMessageBox::information(this,tr("Problem adding compared image !"),error);
-      return;
+      return false;
     }
-
-    QString Extensions = EXTENSIONS;
-    Extensions += ";;All Files (*)";
-    QStringList files = QFileDialog::getOpenFileNames(this,tr("Load Overlay 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());
-    }
-
-    AddOverlayImage(index,vecFileNames,vvImageReader::IMAGE);
+    return true;
 }
 //------------------------------------------------------------------------------
 
@@ -2130,28 +2139,20 @@ void vvMainWindow::SelectFusionImage()
 { 
   int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
 
-  //check if one fusion image is added
-  for (int child = 0; child < DataTree->topLevelItem(index)->childCount(); child++)
-    if ( (DataTree->topLevelItem(index)->child(child)->data(1,Qt::UserRole).toString() == "fusion") ||
-      (DataTree->topLevelItem(index)->child(child)->data(1,Qt::UserRole).toString() == "fusionSequence") ) {
-        QString error = "Cannot add more than one fusion image\n";
-        error += "Please remove first ";
-        error += DataTree->topLevelItem(index)->child(child)->data(COLUMN_IMAGE_NAME,Qt::DisplayRole).toString();
-        QMessageBox::information(this,tr("Problem adding fusion image !"),error);
-        return;
-    }
+  if (!(CheckAddedImage(index, "fusion")) || !(CheckAddedImage(index, "fusionSequence")))
+    return;
 
-    QString Extensions = EXTENSIONS;
-    Extensions += ";;All Files (*)";
-    QStringList files = QFileDialog::getOpenFileNames(this,tr("Load Fusion image"),mInputPathName,Extensions);
-    if (files.isEmpty())
-      return;
+  QString Extensions = EXTENSIONS;
+  Extensions += ";;All Files (*)";
+  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);
+  std::vector<std::string> vecFileNames;
+  for (int i = 0; i < files.size(); i++) {
+    vecFileNames.push_back(files[i].toStdString());
+  }
+  AddFusionImage(index,vecFileNames,vvImageReader::IMAGE);
 }
 //------------------------------------------------------------------------------
 
@@ -2260,26 +2261,20 @@ void vvMainWindow::AddLandmarks(int index, std::vector<std::string> files)
 void vvMainWindow::OpenField()
 { 
   int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
-  //check if a vector field has already been added
-  for (int child = 0; child < DataTree->topLevelItem(index)->childCount(); child++)
-    if (DataTree->topLevelItem(index)->child(child)->data(1,Qt::UserRole).toString() == "vector") {
-      QString error = "Cannot add more than one vector field\n";
-      error += "Please remove first ";
-      error += DataTree->topLevelItem(index)->child(child)->data(COLUMN_IMAGE_NAME,Qt::DisplayRole).toString();
-      QMessageBox::information(this,tr("Problem adding vector field!"),error);
-      return;
-    }
+  
+  if (!(CheckAddedImage(index, "vector")))
+    return;
 
-    QString Extensions = "Images ( *.mhd *.mha *.vf *.nii *.nrrd *.nhdr)";
-    // Extensions += ";;Images ( *.mha)";
-    // Extensions += ";;VF Images ( *.vf)";
-    // Extensions += ";;nii Images ( *.nii)";
-    // Extensions += ";;nrrd Images ( *.nrrd)";
-    // Extensions += ";;nhdr Images ( *.nhdr)";
-    Extensions += ";;All Files (*)";
-    QString file = QFileDialog::getOpenFileName(this,tr("Load deformation field"),mInputPathName,Extensions);
-    if (!file.isEmpty())
-      AddField(file,index);
+  QString Extensions = "Images ( *.mhd *.mha *.vf *.nii *.nrrd *.nhdr)";
+  // Extensions += ";;Images ( *.mha)";
+  // Extensions += ";;VF Images ( *.vf)";
+  // Extensions += ";;nii Images ( *.nii)";
+  // Extensions += ";;nrrd Images ( *.nrrd)";
+  // Extensions += ";;nhdr Images ( *.nhdr)";
+  Extensions += ";;All Files (*)";
+  QString file = QFileDialog::getOpenFileName(this,tr("Load deformation field"),mInputPathName,Extensions);
+  if (!file.isEmpty())
+    AddField(file,index);
 }
 //------------------------------------------------------------------------------
 
@@ -2446,30 +2441,23 @@ void vvMainWindow::SelectFusionSequence()
 { 
   //get the index of the slicer manager of the main sequence (CT)
   int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
-  //check if one overlay image is already associated
-  for (int child = 0; child < DataTree->topLevelItem(index)->childCount(); child++)
-    if ( (DataTree->topLevelItem(index)->child(child)->data(1,Qt::UserRole).toString() == "fusion") ||
-      (DataTree->topLevelItem(index)->child(child)->data(1,Qt::UserRole).toString() == "fusionSequence") ) {
-        QString error = "Cannot add more than one compared image\n";
-        error += "Please remove first ";
-        error += DataTree->topLevelItem(index)->child(child)->data(COLUMN_IMAGE_NAME,Qt::DisplayRole).toString();
-        QMessageBox::information(this,tr("Problem adding compared image !"),error);
-        return;
-    }
 
-    QString Extensions = EXTENSIONS;
-    Extensions += ";;All Files (*)";
-    QStringList files = QFileDialog::getOpenFileNames(this,tr("Load Overlay image sequence"),mInputPathName,Extensions);
-    if (files.isEmpty())
-      return;
+  if (!(CheckAddedImage(index, "fusion")) || !(CheckAddedImage(index, "fusionSequence")))
+    return;
 
-    std::vector<std::string> vecFileNames;
-    for (int i = 0; i < files.size(); i++) {
-      vecFileNames.push_back(files[i].toStdString());
-    }
+  QString Extensions = EXTENSIONS;
+  Extensions += ";;All Files (*)";
+  QStringList files = QFileDialog::getOpenFileNames(this,tr("Load Overlay image sequence"),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());
+  }
 
-    //associate the secondary sequence (US) to the main one
-    AddFusionSequence(index,vecFileNames,vvImageReader::MERGEDWITHTIME);
+  //associate the secondary sequence (US) to the main one
+  AddFusionSequence(index,vecFileNames,vvImageReader::MERGEDWITHTIME);
 }
 //------------------------------------------------------------------------------
 
index b093554d0a0b92018d352f1eb1236db1012b8be6..9253fa07a21a0f41853300b869d34c393fa5ed3f 100644 (file)
@@ -54,6 +54,7 @@ class vvMainWindow: public vvMainWindowBase,
   void LoadImages(std::vector<std::string> filenames, vvImageReader::LoadedImageType type);
   vvSlicerManager * AddImage(vvImage::Pointer image,std::string filename);
   void AddField(QString file,int index);
+  bool CheckAddedImage(int index, QString imageType);
   void AddOverlayImage(int index, std::vector<std::string> fileNames, vvImageReader::LoadedImageType type);
   void AddFusionImage(int index, std::vector<std::string> fileNames, vvImageReader::LoadedImageType type);
   void AddROI(int index, QString filename);