From 2ab0d177ced19e88c51b479f9d73d8171eb71aa8 Mon Sep 17 00:00:00 2001 From: Simon Rit Date: Tue, 4 Sep 2012 13:13:07 +0200 Subject: [PATCH 1/1] Managed opening sequence of overlay images. Parser is ready for fusion/vf/contour --- vv/vv.cxx | 60 ++++++++++++++++++++++++++++-------------- vv/vvMainWindow.cxx | 19 ++++++++----- vv/vvMainWindow.h | 2 +- vv/vvReadState.cxx | 8 ++++-- vv/vvSlicerManager.cxx | 6 ++--- vv/vvSlicerManager.h | 2 +- 6 files changed, 63 insertions(+), 34 deletions(-) diff --git a/vv/vv.cxx b/vv/vv.cxx index 9c3f666..1d43584 100644 --- a/vv/vv.cxx +++ b/vv/vv.cxx @@ -110,8 +110,11 @@ int main( int argc, char** argv ) window.show(); std::vector 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 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; } diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index 4e70cd4..d42d11c 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -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 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 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()); diff --git a/vv/vvMainWindow.h b/vv/vvMainWindow.h index c77a59a..fa29b0c 100644 --- a/vv/vvMainWindow.h +++ b/vv/vvMainWindow.h @@ -54,7 +54,7 @@ class vvMainWindow: public vvMainWindowBase, void LoadImages(std::vector 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 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 diff --git a/vv/vvReadState.cxx b/vv/vvReadState.cxx index 7383ecd..434f799 100644 --- a/vv/vvReadState.cxx +++ b/vv/vvReadState.cxx @@ -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 vec; + vec.push_back(file.c_str()); + m_Window->AddOverlayImage(index, vec); + } } if (value == "OverlayColorWindow") { vald = m_XmlReader->readElementText().toDouble(); diff --git a/vv/vvSlicerManager.cxx b/vv/vvSlicerManager.cxx index 1c64221..9a51c4b 100644 --- a/vv/vvSlicerManager.cxx +++ b/vv/vvSlicerManager.cxx @@ -242,9 +242,9 @@ bool vvSlicerManager::SetImages(std::vector filenames, vvImageReade //---------------------------------------------------------------------------- -bool vvSlicerManager::SetOverlay(std::string filename,int dim, std::string component) +bool vvSlicerManager::SetOverlay(std::vector 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 filenames; - filenames.push_back(filename); mOverlayReader->SetInputFilenames(filenames); mOverlayReader->Update(mImage->GetNumberOfDimensions(),component.c_str(),mType); if (mOverlayReader->GetLastError().size() == 0) { diff --git a/vv/vvSlicerManager.h b/vv/vvSlicerManager.h index 50a31ba..c5ce55c 100644 --- a/vv/vvSlicerManager.h +++ b/vv/vvSlicerManager.h @@ -64,7 +64,7 @@ class vvSlicerManager : public QObject { void SetImage(vvImage::Pointer image); bool SetImages(std::vector filenames, vvImageReader::LoadedImageType type, int n=0); - bool SetOverlay(std::string filename, int dim, std::string component); + bool SetOverlay(std::vector 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); -- 2.45.2