]> Creatis software - clitk.git/commitdiff
Managed opening sequence of overlay images. Parser is ready for
authorSimon Rit <simon.rit@creatis.insa-lyon.fr>
Tue, 4 Sep 2012 11:13:07 +0000 (13:13 +0200)
committerSimon Rit <simon.rit@creatis.insa-lyon.fr>
Tue, 4 Sep 2012 11:13:07 +0000 (13:13 +0200)
fusion/vf/contour

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

index 9c3f666be3904a8de0350748bfd96c363917519b..1d43584bd3a64b125a71f80e46f151b87314de7f 100644 (file)
--- a/vv/vv.cxx
+++ b/vv/vv.cxx
@@ -110,8 +110,11 @@ int main( int argc, char** argv )
   window.show();
 
   std::vector<std::string> sequence_filenames;
-  enum {P_NORMAL,P_SEQUENCE,P_WINDOW,P_LEVEL};
-  int parse_mode=P_NORMAL;
+  enum {P_NORMAL,P_SEQUENCE,P_WINDOW,P_LEVEL} parse_mode;
+  parse_mode=P_NORMAL;
+  enum {O_BASE,O_OVERLAY,O_FUSION,O_VF,O_CONTOUR} open_mode;
+  std::string open_mode_names[] = {"base", "overlay", "fusion", "vf", "contour"};
+  open_mode=O_BASE;
   int n_image_loaded=0;
   std::string win(""), lev("");
 
@@ -121,7 +124,14 @@ int main( int argc, char** argv )
       std::string current = argv[i];
       if (!current.compare(0,2,"--")) { //We are parsing an option
         if (parse_mode == P_SEQUENCE) {//First finish the current sequence
-          window.LoadImages(sequence_filenames, vvImageReader::MERGEDWITHTIME);
+          if(open_mode==O_BASE)
+            window.LoadImages(sequence_filenames, vvImageReader::MERGEDWITHTIME);
+          else if (open_mode==O_OVERLAY)
+            window.AddOverlayImage(n_image_loaded-1,sequence_filenames);
+          else{
+            std::cerr << "Sequences are not managed for opening " << open_mode_names[open_mode] << std::endl;
+            exit(1);
+          }
           sequence_filenames.clear();
           parse_mode=P_NORMAL;
         }
@@ -148,26 +158,18 @@ int main( int argc, char** argv )
         }
         if (current=="--vf") {
           if (!n_image_loaded) load_image_first_error();
-          window.AddField(argv[i+1],n_image_loaded-1);
-          i++; //skip vf name
+          open_mode = O_VF;
         } else if (current=="--overlay") {
           if (!n_image_loaded) load_image_first_error();
-          window.AddOverlayImage(n_image_loaded-1,argv[i+1]);
-          i++; //skip overlay name
-        } /*else if (current=="--roi") {
-          if (!n_image_loaded) load_image_first_error();
-          window.AddROI(n_image_loaded-1,argv[i+1]);
-          i++; //skip roi name
-        }*/ else if (current=="--contour") {
+          open_mode = O_OVERLAY;
+        } else if (current=="--contour") {
           if (!n_image_loaded) load_image_first_error();
-          window.AddDCStructContour(n_image_loaded-1,argv[i+1]);
-          i++; //skip roi name
+          open_mode = O_CONTOUR;
         } else if (current=="--fusion") {
           if (!n_image_loaded) load_image_first_error();
-          window.AddFusionImage(n_image_loaded-1,argv[i+1]);
-          i++; //skip fusion name
+          open_mode = O_FUSION;
         } else if (current == "--sequence") {
-          n_image_loaded++; //count only one for the sequence
+          if(open_mode==O_BASE) n_image_loaded++; //count only one for the whole sequence
           parse_mode=P_SEQUENCE;
         } else if (current == "--window") {
           parse_mode=P_WINDOW;
@@ -220,12 +222,30 @@ int main( int argc, char** argv )
       } else {
         std::vector<std::string> image;
         image.push_back(current);
-        window.LoadImages(image, vvImageReader::IMAGE);
-        n_image_loaded++;
+        if(open_mode==O_BASE) {
+          window.LoadImages(image, vvImageReader::IMAGE);
+          n_image_loaded++;
+        }
+        else if (open_mode==O_VF)
+          window.AddField(current.c_str(), n_image_loaded-1);
+        else if (open_mode==O_OVERLAY)
+          window.AddOverlayImage(n_image_loaded-1,image);
+        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());
+        open_mode = O_BASE;
       }
     }
     if (parse_mode == P_SEQUENCE) { //Finish any current sequence
-      window.LoadImages(sequence_filenames, vvImageReader::MERGEDWITHTIME);
+      if(open_mode==O_BASE)
+        window.LoadImages(sequence_filenames, vvImageReader::MERGEDWITHTIME);
+      else if (open_mode==O_OVERLAY)
+        window.AddOverlayImage(n_image_loaded-1,sequence_filenames);
+      else{
+        std::cerr << "Sequences are not managed for opening " << open_mode_names[open_mode] << std::endl;
+        exit(1);
+      }
       sequence_filenames.clear();
       parse_mode=P_NORMAL;
     }
index 4e70cd415ae45f378ab8a823a4c825f1cdacecde..d42d11ce44a958f1c84ea2077bcf935e4ce3d2a0 100644 (file)
@@ -1858,21 +1858,28 @@ void vvMainWindow::SelectOverlayImage()
 
   QString Extensions = EXTENSIONS;
   Extensions += ";;All Files (*)";
-  QString file = QFileDialog::getOpenFileName(this,tr("Load Overlay image"),mInputPathName,Extensions);
-  if (!file.isEmpty())
-    AddOverlayImage(index,file);
+  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);
 }
 //------------------------------------------------------------------------------
 
 //------------------------------------------------------------------------------
-void vvMainWindow::AddOverlayImage(int index, QString file)
+void vvMainWindow::AddOverlayImage(int index, std::vector<std::string> fileNames)
 {
+  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());
     int dimension = reader->GetNumberOfDimensions();
@@ -1881,7 +1888,7 @@ void vvMainWindow::AddOverlayImage(int index, QString file)
     qApp->processEvents();
 
     std::string filename = itksys::SystemTools::GetFilenameWithoutExtension(file.toStdString()).c_str();
-    if (mSlicerManagers[index]->SetOverlay(file.toStdString(),dimension, component)) {
+    if (mSlicerManagers[index]->SetOverlay(fileNames,dimension, component)) {
       //create an item in the tree with good settings
       QTreeWidgetItem *item = new QTreeWidgetItem();
       item->setData(0,Qt::UserRole,file.toStdString().c_str());
index c77a59a8a4948a482e6db31d46e816c52056cec7..fa29b0ce5fd288f36c599188ea7d4cae4e1d60ca 100644 (file)
@@ -54,7 +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);
-  void AddOverlayImage(int index, QString filename);
+  void AddOverlayImage(int index, std::vector<std::string> fileNames);
   void AddFusionImage(int index, QString filename);
   void AddROI(int index, QString filename);
   ///Adds a mesh to a SlicerManager, with optional warping by vector field
index 7383ecdcd30a1e311a00b431a135c5ac5efdcbc4..434f79939722ede476689baf28df07dc30c06e44 100644 (file)
@@ -191,8 +191,12 @@ std::string vvReadState::ReadOverlay(int index)
     if (m_XmlReader->isStartElement()) {
       if (value == "FileName") {
         file = m_XmlReader->readElementText().toStdString();
-        if (!m_XmlReader->hasError())
-          m_Window->AddOverlayImage(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->AddOverlayImage(index, vec);
+        }
       }
       if (value == "OverlayColorWindow") {
         vald = m_XmlReader->readElementText().toDouble();
index 1c642215b4b904a0e44797c973937ca4855a6989..9a51c4b0a427cc5bb950cae079c77853f0662287 100644 (file)
@@ -242,9 +242,9 @@ bool vvSlicerManager::SetImages(std::vector<std::string> filenames, vvImageReade
 
 
 //----------------------------------------------------------------------------
-bool vvSlicerManager::SetOverlay(std::string filename,int dim, std::string component)
+bool vvSlicerManager::SetOverlay(std::vector<std::string> filenames,int dim, std::string component)
 {
-  mOverlayName = filename;
+  mOverlayName = filenames[0];
   mOverlayComponent = component;
   if (dim > mImage->GetNumberOfDimensions()) {
     mLastError = " Overlay dimension cannot be greater then reference image!";
@@ -252,8 +252,6 @@ bool vvSlicerManager::SetOverlay(std::string filename,int dim, std::string compo
   }
   if (mOverlayReader.IsNull())
     mOverlayReader = vvImageReader::New();
-  std::vector<std::string> filenames;
-  filenames.push_back(filename);
   mOverlayReader->SetInputFilenames(filenames);
   mOverlayReader->Update(mImage->GetNumberOfDimensions(),component.c_str(),mType);
   if (mOverlayReader->GetLastError().size() == 0) {
index 50a31ba913eb31ba8b133a65acdb283f42633768..c5ce55cf952906cd097a98ae1032b3d62e76fff8 100644 (file)
@@ -64,7 +64,7 @@ class vvSlicerManager : public QObject {
   void SetImage(vvImage::Pointer image);
   bool SetImages(std::vector<std::string> filenames, vvImageReader::LoadedImageType type, int n=0);
 
-  bool SetOverlay(std::string filename, int dim, std::string component);
+  bool SetOverlay(std::vector<std::string> filenames, int dim, std::string component);
   bool SetFusion(std::string filename, int dim, std::string component);
   ///Set a VF by loading it from the disk
   bool SetVF(std::string filename);