From ae6ab552bec1c4f23aec29e774204d942f4df342 Mon Sep 17 00:00:00 2001 From: Simon Rit Date: Wed, 12 Jun 2013 10:28:37 +0200 Subject: [PATCH] Copy pasted code from overlay to fusion for sequences. This yet another 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 | 4 +- vv/vvMainWindow.cxx | 119 ++++++++++++++++++++++------------------- vv/vvMainWindow.h | 2 +- vv/vvReadState.cxx | 8 ++- vv/vvSlicerManager.cxx | 10 ++-- vv/vvSlicerManager.h | 2 +- 6 files changed, 78 insertions(+), 67 deletions(-) diff --git a/vv/vv.cxx b/vv/vv.cxx index 7506aa9..5df3415 100644 --- 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; diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index d7d076a..4210798 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -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 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 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!"); diff --git a/vv/vvMainWindow.h b/vv/vvMainWindow.h index dd95c0a..e5e3155 100644 --- a/vv/vvMainWindow.h +++ b/vv/vvMainWindow.h @@ -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 fileNames, vvImageReader::LoadedImageType type); - void AddFusionImage(int index, QString filename); + void AddFusionImage(int index, std::vector fileNames, vvImageReader::LoadedImageType type); void AddROI(int index, QString filename); //Process the sequence for fusion: diff --git a/vv/vvReadState.cxx b/vv/vvReadState.cxx index 980bbf1..6a248b2 100644 --- a/vv/vvReadState.cxx +++ b/vv/vvReadState.cxx @@ -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 vec; + vec.push_back(file.c_str()); + m_Window->AddFusionImage(index, vec, vvImageReader::IMAGE); + } } if (value == "FusionOpacity") { vali = m_XmlReader->readElementText().toInt(); diff --git a/vv/vvSlicerManager.cxx b/vv/vvSlicerManager.cxx index 5afe71b..89fd42b 100644 --- a/vv/vvSlicerManager.cxx +++ b/vv/vvSlicerManager.cxx @@ -279,20 +279,18 @@ bool vvSlicerManager::SetOverlay(std::vector filenames,int dim, std //---------------------------------------------------------------------------- -bool vvSlicerManager::SetFusion(std::string filename,int dim, std::string component) +bool vvSlicerManager::SetFusion(std::vector filenames,int dim, std::string component, vvImageReader::LoadedImageType type) { - mFusionName = filename; + mFusionName = filenames[0]; mFusionComponent = component; if (dim > mImage->GetNumberOfDimensions()) { - mLastError = " Overlay dimension cannot be greater then reference image!"; + mLastError = " Fusion dimension cannot be greater than reference image!"; return false; } if (mFusionReader.IsNull()) mFusionReader = vvImageReader::New(); - std::vector filenames; - filenames.push_back(filename); mFusionReader->SetInputFilenames(filenames); - mFusionReader->Update(mImage->GetNumberOfDimensions(),component.c_str(),mType); + mFusionReader->Update(type); if (mFusionReader->GetLastError().size() == 0) { for ( unsigned int i = 0; i < mSlicers.size(); i++) { mSlicers[i]->SetFusion(mFusionReader->GetOutput()); diff --git a/vv/vvSlicerManager.h b/vv/vvSlicerManager.h index 60f2392..bbdd2a4 100644 --- a/vv/vvSlicerManager.h +++ b/vv/vvSlicerManager.h @@ -77,7 +77,7 @@ class vvSlicerManager : public QObject { bool SetImages(std::vector filenames, vvImageReader::LoadedImageType type, int n=0); bool SetOverlay(std::vector filenames, int dim, std::string component, vvImageReader::LoadedImageType type); - bool SetFusion(std::string filename, int dim, std::string component); + bool SetFusion(std::vector filenames,int dim, std::string component, vvImageReader::LoadedImageType type); bool SetFusionSequence(std::vector filenames, int dim, std::string component, vvImageReader::LoadedImageType type); ///Set a VF by loading it from the disk bool SetVF(std::string filename); -- 2.47.1