From 1c3533dee871b6d396c91c07f6c73a0dc46b2cd3 Mon Sep 17 00:00:00 2001 From: Simon Rit Date: Fri, 22 Apr 2011 17:00:20 +0200 Subject: [PATCH] Detect analyze unkown orientation and set identity instead of something else --- common/vvImageReader.txx | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/common/vvImageReader.txx b/common/vvImageReader.txx index 46385be..7607ab3 100644 --- a/common/vvImageReader.txx +++ b/common/vvImageReader.txx @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -66,6 +67,8 @@ void vvImageReader::UpdateWithDim(std::string InputPixelType) template void vvImageReader::UpdateWithDimAndInputPixelType() { + itk::AnalyzeImageIO *analyzeImageIO; + if (mType == MERGEDWITHTIME) // In this case we can load the images // one at the time to avoid excessive // memory use @@ -88,6 +91,7 @@ void vvImageReader::UpdateWithDimAndInputPixelType() mLastError = error.str(); return; } + analyzeImageIO = dynamic_cast( reader->GetImageIO() ); } } else if (mType == SLICED) { mImage=vvImage::New(); @@ -116,12 +120,12 @@ void vvImageReader::UpdateWithDimAndInputPixelType() filter->ReleaseDataFlagOn(); try { mImage->AddItkImage(filter->GetOutput()); - } - catch ( itk::ExceptionObject & err ) { + } catch ( itk::ExceptionObject & err ) { std::cerr << "Error while slicing " << mInputFilenames[0].c_str() << "(slice #" << mSlice << ") " << err << std::endl; return; } + analyzeImageIO = dynamic_cast( reader->GetImageIO() ); } else { if (mInputFilenames.size() > 1) { typedef itk::Image< InputPixelType, VImageDimension > InputImageType; @@ -162,6 +166,19 @@ void vvImageReader::UpdateWithDimAndInputPixelType() mLastError = error.str(); return; } + analyzeImageIO = dynamic_cast( reader->GetImageIO() ); + } + } + + // For unknown analyze orientations, we set identity + if(analyzeImageIO) { + const double m[16] = {1.,0.,0.,0.,0.,0.,1.,0.,0.,-1.,0.,0.,0.,0.,0.,1.}; + int i; + for(i=0; m[i]==mImage->GetTransform()->GetMatrix()->GetElement(i%4, i/4) && i<16; i++); + if(i==16) { + itkWarningMacro(<< "Analyze image file format detected with unknown orientation." + << "Forcing identity orientation, use other file format if not ok."); + mImage->GetTransform()->Identity(); } } } -- 2.45.1