#define vvImageWriter_TXX
#include <itkImageFileWriter.h>
+#include <itkChangeInformationImageFilter.h>
#include "vvToITK.h"
-#include "clitkDD.h"
//====================================================================
template<unsigned int VImageDimension>
template<class OutputPixelType, unsigned int VImageDimension>
void vvImageWriter::UpdateWithDimAndOutputPixelType()
{
- //Create the writer
+ // The ITK image
typedef itk::Image< OutputPixelType, VImageDimension > OutputImageType;
+ typename OutputImageType::ConstPointer itkimg = vvImageToITK<OutputImageType>(mImage);
+
+ //Create the writer
typedef itk::ImageFileWriter<OutputImageType> WriterType;
typename WriterType::Pointer writer = WriterType::New();
writer->SetFileName(mOutputFilename);
- writer->SetInput(vvImageToITK<OutputImageType>(mImage));
+
+ //Change information if it must transformation must be saved
+ typedef itk::ChangeInformationImageFilter<OutputImageType> ChangeInfoType;
+ typename ChangeInfoType::Pointer info = ChangeInfoType::New();
+ if(mSaveTransform) {
+ // Set pipeline
+ info->SetInput(itkimg);
+ writer->SetInput(info->GetOutput());
+
+ // Inverse vv matrix
+ itk::Matrix<double, 4, 4> 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; i<VImageDimension; i++)
+ for(unsigned int j=0; j<VImageDimension; j++)
+ direction[i][j] = trans[i][j];
+ info->SetOutputDirection(direction);
+ info->ChangeDirectionOn();
+
+ // Origin
+ typename ChangeInfoType::PointType origin = itkimg->GetOrigin();
+ origin = direction * origin;
+ for(unsigned int i=0; i<VImageDimension; i++)
+ origin[i] += trans[i][3];
+ info->SetOutputOrigin(origin);
+ info->ChangeOriginOn();
+ }
+ else
+ writer->SetInput(itkimg);
+
+
if (mUseAnObserver) {
writer->AddObserver(itk::ProgressEvent(), mObserver);
}
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()) {