X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=common%2FvvImageReader.txx;h=3ef04c6e0487f9b6bcec51e294e4f3075a6032e0;hb=619c7d36de4ec76e9e68beb4a77c3e91e72d4c89;hp=3a38719c2d4a16eedaed620bccd77ebb3aa58510;hpb=8df51d54a1774008d30619248a3887b8afbe411b;p=clitk.git diff --git a/common/vvImageReader.txx b/common/vvImageReader.txx index 3a38719..3ef04c6 100644 --- a/common/vvImageReader.txx +++ b/common/vvImageReader.txx @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include @@ -34,8 +34,13 @@ template void vvImageReader::UpdateWithDim(std::string InputPixelType) { - if (mType == VECTORFIELD) - UpdateWithDimAndInputPixelType,VImageDimension>(); + if (mType == VECTORFIELD || mType == VECTORFIELDWITHTIME) + { + if (VImageDimension == 4) + UpdateWithDimAndInputVectorPixelType,VImageDimension>(); + else + UpdateWithDimAndInputVectorPixelType,VImageDimension>(); + } else if (InputPixelType == "short") UpdateWithDimAndInputPixelType(); else if (InputPixelType == "unsigned_short") @@ -67,8 +72,6 @@ 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 @@ -91,7 +94,6 @@ void vvImageReader::UpdateWithDimAndInputPixelType() mLastError = error.str(); return; } - analyzeImageIO = dynamic_cast( reader->GetImageIO() ); } } else if (mType == SLICED) { mImage=vvImage::New(); @@ -128,7 +130,6 @@ void vvImageReader::UpdateWithDimAndInputPixelType() << "(slice #" << mSlice << ") " << err << std::endl; return; } - analyzeImageIO = dynamic_cast( reader->GetImageIO() ); } else { if (mInputFilenames.size() > 1) { typedef itk::Image< InputPixelType, VImageDimension > InputImageType; @@ -162,10 +163,7 @@ void vvImageReader::UpdateWithDimAndInputPixelType() reader->ReleaseDataFlagOn(); try { - if (mType == IMAGEWITHTIME) - mImage=vvImageFromITK(reader->GetOutput(),true); - else - mImage=vvImageFromITK(reader->GetOutput()); + mImage = vvImageFromITK(reader->GetOutput(), mType == IMAGEWITHTIME || mType == VECTORFIELDWITHTIME); } catch ( itk::ExceptionObject & err ) { std::cerr << "Error while reading " << mInputFilenames[0].c_str() << " " << err << std::endl; @@ -174,27 +172,62 @@ void vvImageReader::UpdateWithDimAndInputPixelType() mLastError = error.str(); return; } - analyzeImageIO = dynamic_cast( reader->GetImageIO() ); } } +} +//---------------------------------------------------------------------------- + +//---------------------------------------------------------------------------- +template +void vvImageReader::UpdateWithDimAndInputVectorPixelType() +{ + typedef itk::Image< InputPixelType, VImageDimension > InputImageType; + typename InputImageType::Pointer input; - // 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(); + if (mInputFilenames.size() > 1) { + typedef itk::ImageSeriesReader ReaderType; + typename ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileNames(mInputFilenames); + reader->ReleaseDataFlagOn(); + try { + reader->Update(); + input = reader->GetOutput(); + } catch ( itk::ExceptionObject & err ) { + std::cerr << "Error while reading image series:" << err << std::endl; + std::stringstream error; + error << err; + mLastError = error.str(); + return; + } + } else { + typedef itk::ImageFileReader ReaderType; + typename ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(mInputFilenames[0]); + reader->ReleaseDataFlagOn(); + try { + reader->Update(); + input = reader->GetOutput(); + } catch ( itk::ExceptionObject & err ) { + std::cerr << "Error while reading " << mInputFilenames[0].c_str() + << " " << err << std::endl; + std::stringstream error; + error << err; + mLastError = error.str(); + return; } } + + typedef itk::Image< itk::Vector, VImageDimension > VectorImageType; + typedef itk::FlexibleVectorCastImageFilter CasterType; + typename VectorImageType::Pointer casted_input; + typename CasterType::Pointer caster = CasterType::New(); + caster->SetInput(input); + caster->Update(); + casted_input = caster->GetOutput(); + + mImage = vvImageFromITK >(casted_input, mType == IMAGEWITHTIME || mType == VECTORFIELDWITHTIME); } //---------------------------------------------------------------------------- - #endif /* end #define vvImageReader_TXX */