X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vv%2FvvImageReader.txx;h=e2e98bb2d125f5bdf76e23281c00e95a0856a116;hb=303649a25b6a2f05025953260a0290d726370d8b;hp=a893f0752a07dd39afd1b569a68021fe259c30cd;hpb=934a64f5b51382ad6bbc78d9c8734691e599cf09;p=clitk.git diff --git a/vv/vvImageReader.txx b/vv/vvImageReader.txx index a893f07..e2e98bb 100644 --- a/vv/vvImageReader.txx +++ b/vv/vvImageReader.txx @@ -1,159 +1,173 @@ /*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv -Program: vv -Language: C++ -Author : Pierre Seroul (pierre.seroul@gmail.com) + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr -Copyright (C) 2008 -Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr -CREATIS-LRMN http://www.creatis.insa-lyon.fr + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, version 3 of the License. + It is distributed under dual licence -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + ======================================================================-====*/ -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -=========================================================================*/ -#ifndef vvImageReader_TXX -#define vvImageReader_TXX -#include +#ifndef VVIMAGEREADER_TXX +#define VVIMAGEREADER_TXX +#include #include #include +#include + +#include #include "clitkCommon.h" -#include "itkImageToVTKImageFilter.h" +#include "clitkConfiguration.h" #include "vvFromITK.h" #include "vvConstants.h" +//---------------------------------------------------------------------------- template void vvImageReader::UpdateWithDim(std::string InputPixelType) { - if (mType == VECTORFIELD) - UpdateWithDimAndInputPixelType,VImageDimension>(); - else if (InputPixelType == "short") - UpdateWithDimAndInputPixelType(); - else if (InputPixelType == "unsigned_short") - UpdateWithDimAndInputPixelType(); - else if (InputPixelType == "char") - UpdateWithDimAndInputPixelType(); - else if (InputPixelType == "unsigned_char") - UpdateWithDimAndInputPixelType(); - else if (InputPixelType == "int") - UpdateWithDimAndInputPixelType(); - else if (InputPixelType == "double") - UpdateWithDimAndInputPixelType(); - else if (InputPixelType == "float") - UpdateWithDimAndInputPixelType(); - else - std::cerr << "Error, input pixel type : " << InputPixelType << " unknown !" << std::endl; + if (mType == VECTORFIELD) + UpdateWithDimAndInputPixelType,VImageDimension>(); + else if (InputPixelType == "short") + UpdateWithDimAndInputPixelType(); + else if (InputPixelType == "unsigned_short") + UpdateWithDimAndInputPixelType(); + else if (InputPixelType == "char") + UpdateWithDimAndInputPixelType(); + else if (InputPixelType == "unsigned_char") + UpdateWithDimAndInputPixelType(); + else if (InputPixelType == "int") + UpdateWithDimAndInputPixelType(); + else if (InputPixelType == "unsigned_int") + UpdateWithDimAndInputPixelType(); + else if (InputPixelType == "double") + UpdateWithDimAndInputPixelType(); + else if (InputPixelType == "float") + UpdateWithDimAndInputPixelType(); + else + std::cerr << "Error, input pixel type : " << InputPixelType << " unknown !" << std::endl; + + if (CLITK_EXPERIMENTAL && mLastError.size()==0) { + ReadNkiImageTransform(); + ReadMatImageTransform(); + } } -//==================================================================== +//---------------------------------------------------------------------------- + +//---------------------------------------------------------------------------- template void vvImageReader::UpdateWithDimAndInputPixelType() { - if (mType == MERGEDWITHTIME) // In this case we can load the images - // one at the time to avoid excessive - // memory use - { - typedef itk::Image< InputPixelType, VImageDimension-1 > InputImageType; - typedef itk::ImageFileReader ReaderType; - typename ReaderType::Pointer reader = ReaderType::New(); - typedef itk::ImageToVTKImageFilter ConnectorType; - typename ConnectorType::Pointer connector = ConnectorType::New(); - connector->SetInput(reader->GetOutput()); - mImage=vvImage::New(); - for (std::vector::const_iterator i=mInputFilenames.begin();i!=mInputFilenames.end();i++) - { - std::cout << (*i) << std::endl; - reader->SetFileName(*i); - try { - reader->Update(); - } - 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; - } - try { - connector->Update(); - } - catch ( itk::ExceptionObject & err ) { - std::cerr << "Error while setting vvImage from ITK (MERGEDWITHTIME)" - << " " << err << std::endl; - } - vtkImageData *image = vtkImageData::New(); - image->DeepCopy(connector->GetOutput()); - mImage->AddImage(image); - } + if (mType == MERGEDWITHTIME) // In this case we can load the images + // one at the time to avoid excessive + // memory use + { + mImage=vvImage::New(); + + for (std::vector::const_iterator i=mInputFilenames.begin(); i!=mInputFilenames.end(); i++) { + typedef itk::Image< InputPixelType, VImageDimension-1 > InputImageType; + typedef itk::ImageFileReader ReaderType; + typename ReaderType::Pointer reader = ReaderType::New(); + reader->ReleaseDataFlagOn(); + reader->SetFileName(*i); + try { + mImage->AddItkImage(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; + } } - else - { - if (mInputFilenames.size() > 1) - { - typedef itk::Image< InputPixelType, VImageDimension > InputImageType; - typedef itk::ImageSeriesReader ReaderType; - typename ReaderType::Pointer reader = ReaderType::New(); - for (std::vector::const_iterator i=mInputFilenames.begin();i!=mInputFilenames.end();i++) - std::cout << (*i) << std::endl; - reader->SetFileNames(mInputFilenames); - //if (mUseAnObserver) { - //reader->AddObserver(itk::ProgressEvent(), mObserver); - //} - try { - reader->Update(); - } - catch ( itk::ExceptionObject & err ) { - std::cerr << "Error while reading image series:" << err << std::endl; - std::stringstream error; - error << err; - mLastError = error.str(); - return; - } - if (mType == IMAGEWITHTIME) - mImage=vvImageFromITK(reader->GetOutput(),true); - else - mImage=vvImageFromITK(reader->GetOutput()); - } + } else if (mType == SLICED) { + mImage=vvImage::New(); + typedef itk::Image< InputPixelType, VImageDimension > InputImageType; + typedef itk::ImageFileReader ReaderType; + typename ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(mInputFilenames[0]); + reader->UpdateOutputInformation(); + + typedef itk::Image< InputPixelType, VImageDimension-1 > SlicedImageType; + typedef itk::ExtractImageFilter FilterType; + + typename InputImageType::RegionType inputRegion = reader->GetOutput()->GetLargestPossibleRegion(); + typename InputImageType::SizeType inputSize = inputRegion.GetSize(); + typename InputImageType::IndexType start = inputRegion.GetIndex(); + typename InputImageType::SizeType extractedRegionSize = inputSize; + typename InputImageType::RegionType extractedRegion; + extractedRegionSize[VImageDimension - 1] = 0; + extractedRegion.SetSize(extractedRegionSize); + start[VImageDimension - 1] = mSlice; + extractedRegion.SetIndex(start); + + typename FilterType::Pointer filter = FilterType::New(); + filter->SetExtractionRegion(extractedRegion); + filter->SetInput(reader->GetOutput()); + filter->ReleaseDataFlagOn(); + try { + mImage->AddItkImage(filter->GetOutput()); + } + catch ( itk::ExceptionObject & err ) { + std::cerr << "Error while slicing " << mInputFilenames[0].c_str() + << "(slice #" << mSlice << ") " << err << std::endl; + return; + } + } else { + if (mInputFilenames.size() > 1) { + typedef itk::Image< InputPixelType, VImageDimension > InputImageType; + typedef itk::ImageSeriesReader ReaderType; + typename ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileNames(mInputFilenames); + reader->ReleaseDataFlagOn(); + + try { + if (mType == IMAGEWITHTIME) + mImage=vvImageFromITK(reader->GetOutput(),true); + else + mImage=vvImageFromITK(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::Image< InputPixelType, VImageDimension > InputImageType; + typedef itk::ImageFileReader ReaderType; + typename ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(mInputFilenames[0]); + reader->ReleaseDataFlagOn(); + + try { + if (mType == IMAGEWITHTIME) + mImage=vvImageFromITK(reader->GetOutput(),true); else - { - typedef itk::Image< InputPixelType, VImageDimension > InputImageType; - typedef itk::ImageFileReader ReaderType; - typename ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(mInputFilenames[0]); - //if (mUseAnObserver) { - //reader->AddObserver(itk::ProgressEvent(), mObserver); - //} - try { - reader->Update(); - } - 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; - } - if (mType == IMAGEWITHTIME) - mImage=vvImageFromITK(reader->GetOutput(),true); - else - mImage=vvImageFromITK(reader->GetOutput()); - } + mImage=vvImageFromITK(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; + } } + } } -//==================================================================== +//---------------------------------------------------------------------------- #endif /* end #define vvImageReader_TXX */