From 61197e6756976dd45fff2b95e9f961bf3e3dac33 Mon Sep 17 00:00:00 2001 From: Simon Rit Date: Fri, 23 Mar 2012 10:33:03 +0100 Subject: [PATCH] Prompt transform backup when saving image in vv. --- common/vvImageWriter.cxx | 1 + common/vvImageWriter.h | 4 ++++ common/vvImageWriter.txx | 44 +++++++++++++++++++++++++++++++++++++--- vv/vvMainWindow.cxx | 21 +++++++++++++++++++ 4 files changed, 67 insertions(+), 3 deletions(-) diff --git a/common/vvImageWriter.cxx b/common/vvImageWriter.cxx index 18123f6..c2d2a91 100644 --- a/common/vvImageWriter.cxx +++ b/common/vvImageWriter.cxx @@ -30,6 +30,7 @@ vvImageWriter::vvImageWriter() mOutputFilename = ""; mLastError = ""; mUseAnObserver = false; + mSaveTransform = false; } //------------------------------------------------------------------------------ diff --git a/common/vvImageWriter.h b/common/vvImageWriter.h index 6281549..ae192b5 100644 --- a/common/vvImageWriter.h +++ b/common/vvImageWriter.h @@ -48,6 +48,9 @@ public: return mLastError; } + bool GetSaveTransform() { return mSaveTransform; } + void SetSaveTransform(bool b) { mSaveTransform = b; } + //==================================================================== // Main function void Update() { @@ -66,6 +69,7 @@ protected: std::string mLastError; bool mUseAnObserver; + bool mSaveTransform; //==================================================================== template diff --git a/common/vvImageWriter.txx b/common/vvImageWriter.txx index 35192f0..0640f0c 100644 --- a/common/vvImageWriter.txx +++ b/common/vvImageWriter.txx @@ -19,8 +19,8 @@ #define vvImageWriter_TXX #include +#include #include "vvToITK.h" -#include "clitkDD.h" //==================================================================== template @@ -52,12 +52,50 @@ void vvImageWriter::UpdateWithDim(std::string OutputPixelType) template void vvImageWriter::UpdateWithDimAndOutputPixelType() { - //Create the writer + // The ITK image typedef itk::Image< OutputPixelType, VImageDimension > OutputImageType; + typename OutputImageType::ConstPointer itkimg = vvImageToITK(mImage); + + //Create the writer typedef itk::ImageFileWriter WriterType; typename WriterType::Pointer writer = WriterType::New(); writer->SetFileName(mOutputFilename); - writer->SetInput(vvImageToITK(mImage)); + + //Change information if it must transformation must be saved + typedef itk::ChangeInformationImageFilter ChangeInfoType; + typename ChangeInfoType::Pointer info = ChangeInfoType::New(); + if(mSaveTransform) { + // Set pipeline + info->SetInput(itkimg); + writer->SetInput(info->GetOutput()); + + // Inverse vv matrix + itk::Matrix trans; + for(int i=0; i<4; i++) + for(int j=0; j<4; j++) + trans[i][j] = mImage->GetTransform()->GetMatrix()->GetElement(i,j); + trans = trans.GetInverse(); + + // Direction + typename ChangeInfoType::DirectionType direction; + for(unsigned int i=0; iSetOutputDirection(direction); + info->ChangeDirectionOn(); + + // Origin + typename ChangeInfoType::PointType origin = itkimg->GetOrigin(); + origin = direction * origin; + for(unsigned int i=0; iSetOutputOrigin(origin); + info->ChangeOriginOn(); + } + else + writer->SetInput(itkimg); + + if (mUseAnObserver) { writer->AddObserver(itk::ProgressEvent(), mObserver); } diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index 9dbd407..4c55a5c 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -2297,6 +2297,27 @@ void vvMainWindow::SaveAs() vvImageWriter::Pointer writer = vvImageWriter::New(); writer->SetOutputFileName(fileName.toStdString()); writer->SetInput(mSlicerManagers[index]->GetImage()); + + // Check on transform and prompt user + writer->SetSaveTransform(false); + bool bId = true; + for(int i=0; i<4; i++) + for(int j=0; j<4; j++) { + double elt = mSlicerManagers[index]->GetImage()->GetTransform()->GetMatrix()->GetElement(i,j); + if(i==j && elt!=1.) + bId = false; + if(i!=j && elt!=0.) + bId = false; + } + if( !bId ) { + QString warning = "The image has an associated linear transform. Do you want to save it along?"; + QMessageBox msgBox(QMessageBox::Warning, tr("Save transform"), warning, 0, this); + msgBox.addButton(tr("Yes"), QMessageBox::AcceptRole); + msgBox.addButton(tr("No"), QMessageBox::RejectRole); + if (msgBox.exec() == QMessageBox::AcceptRole) + writer->SetSaveTransform(true); + } + writer->Update(); QApplication::restoreOverrideCursor(); if (writer->GetLastError().size()) { -- 2.47.1