X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=common%2FvvImageReader.txx;h=2d7d5b573f3c9a2985bfef023c21f4a542c53537;hb=b2a7c12437798214cca01b68d61f5b16eb1036a5;hp=46385bebb58b13b8af00f261b368d30e67926413;hpb=573d80d0f7a17607d2ee883c21c940c0ba020282;p=clitk.git diff --git a/common/vvImageReader.txx b/common/vvImageReader.txx index 46385be..2d7d5b5 100644 --- a/common/vvImageReader.txx +++ b/common/vvImageReader.txx @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -33,7 +34,7 @@ template void vvImageReader::UpdateWithDim(std::string InputPixelType) { - if (mType == VECTORFIELD) + if (mType == VECTORFIELD || mType == VECTORFIELDWITHTIME) UpdateWithDimAndInputPixelType,VImageDimension>(); else if (InputPixelType == "short") UpdateWithDimAndInputPixelType(); @@ -66,6 +67,8 @@ void vvImageReader::UpdateWithDim(std::string InputPixelType) template void vvImageReader::UpdateWithDimAndInputPixelType() { + itk::AnalyzeImageIO *analyzeImageIO = NULL; + 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(); @@ -114,14 +118,17 @@ void vvImageReader::UpdateWithDimAndInputPixelType() filter->SetExtractionRegion(extractedRegion); filter->SetInput(reader->GetOutput()); filter->ReleaseDataFlagOn(); +#if ITK_VERSION_MAJOR == 4 + filter->SetDirectionCollapseToSubmatrix(); +#endif 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; @@ -132,7 +139,12 @@ void vvImageReader::UpdateWithDimAndInputPixelType() try { if (mType == IMAGEWITHTIME) - mImage=vvImageFromITK(reader->GetOutput(),true); + { + std::cerr << "We should never come here:" << std::endl + << " Calling vvImageReader with multiple images and IMAGEWITHTIME is undefined." << std::endl + << " You are probably looking for MERGEDWITHTIME Type." << std::endl; + return; + } else mImage=vvImageFromITK(reader->GetOutput()); } catch ( itk::ExceptionObject & err ) { @@ -150,7 +162,7 @@ void vvImageReader::UpdateWithDimAndInputPixelType() reader->ReleaseDataFlagOn(); try { - if (mType == IMAGEWITHTIME) + if (mType == IMAGEWITHTIME || mType == VECTORFIELDWITHTIME) mImage=vvImageFromITK(reader->GetOutput(),true); else mImage=vvImageFromITK(reader->GetOutput()); @@ -162,6 +174,22 @@ 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; i<16 && m[i]==mImage->GetTransform()->GetMatrix()->GetElement(i%4, i/4); 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(); } } }