From e8442e0c58e660d1c62f159968aa3a74a638aaf4 Mon Sep 17 00:00:00 2001 From: tbaudier Date: Mon, 7 Mar 2016 09:42:17 +0100 Subject: [PATCH] Avoid to open more than one overlay/fusion/vf per image with command line --- vv/vv.cxx | 10 ++-- vv/vvMainWindow.cxx | 138 ++++++++++++++++++++------------------------ vv/vvMainWindow.h | 1 + 3 files changed, 69 insertions(+), 80 deletions(-) diff --git a/vv/vv.cxx b/vv/vv.cxx index 6a367f7..a5a0215 100644 --- 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); diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index 474ddde..9d29824 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -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 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 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 vecFileNames; - for (int i = 0; i < files.size(); i++) { - vecFileNames.push_back(files[i].toStdString()); - } - AddFusionImage(index,vecFileNames,vvImageReader::IMAGE); + std::vector 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 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 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 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); } //------------------------------------------------------------------------------ diff --git a/vv/vvMainWindow.h b/vv/vvMainWindow.h index b093554..9253fa0 100644 --- a/vv/vvMainWindow.h +++ b/vv/vvMainWindow.h @@ -54,6 +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); + bool CheckAddedImage(int index, QString imageType); void AddOverlayImage(int index, std::vector fileNames, vvImageReader::LoadedImageType type); void AddFusionImage(int index, std::vector fileNames, vvImageReader::LoadedImageType type); void AddROI(int index, QString filename); -- 2.47.1