7 #include <boost/filesystem.hpp> 9 #include <fwCore/base.hpp> 11 #include <itkImageFileReader.h> 12 #include <itkImageIOFactory.h> 14 #include <fwData/Image.hpp> 16 #include <fwTools/IntrinsicTypes.hpp> 17 #include <fwTools/Dispatcher.hpp> 18 #include <fwTools/TypeInfoKeyTypeMapping.hpp> 20 #include <fwDataIO/reader/registry/macros.hpp> 22 #include "inr2itk/itkInrImageIOFactory.hpp" 24 #include "fwItkIO/itk.hpp" 25 #include "fwItkIO/ImageReader.hpp" 26 #include "fwItkIO/helper/ProgressItkToFw.hpp" 44 ImageReader::~ImageReader()
55 ::fwData::Image::sptr m_dataImage;
56 std::string m_filename;
57 ::fwItkIO::ImageReader::sptr m_fwReader;
60 template<
class PIXELTYPE>
63 OSLM_INFO(
"::fwItkIO::ImageReader::ITKLoaderFunctor with PIXELTYPE "<<
64 ::fwTools::DynamicType::string<PIXELTYPE>() );
71 typename itk::ImageIOBase::Pointer imageIORead = itk::ImageIOFactory::CreateImageIO(
72 param.m_filename.c_str(), itk::ImageIOFactory::ReadMode);
75 Progressor progress(imageIORead, param.m_fwReader, param.m_filename);
78 typedef itk::Image< PIXELTYPE, 3 > ImageType;
79 typedef itk::ImageFileReader< ImageType > ReaderType;
80 typename ReaderType::Pointer reader = ReaderType::New();
81 reader->SetFileName( param.m_filename.c_str() );
83 reader->SetImageIO( imageIORead );
86 typename ImageType::Pointer itkimage = reader->GetOutput();
87 ::fwItkIO::dataImageFactory< ImageType>( itkimage, param.m_dataImage );
91 static const std::type_info& getImageType(
const std::string &imageFileName )
93 itk::ImageIOBase::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(
94 imageFileName.c_str(), itk::ImageIOFactory::ReadMode);
99 errMsg =
"no ImageIOFactory found to read header of file : ";
100 errMsg.append( imageFileName );
102 throw( std::ios_base::failure( errMsg ) );
105 imageIO->SetFileName( imageFileName.c_str() );
106 imageIO->ReadImageInformation();
107 return imageIO->GetComponentTypeInfo();
113 void ImageReader::read()
115 ::boost::filesystem::path file = getFile();
116 OSLM_ASSERT(
"File: "<<file<<
" doesn't exist", ::boost::filesystem::exists( file ) );
117 assert( !m_object.expired() );
118 assert( m_object.lock() );
120 const std::type_info& ti = ITKLoaderFunctor::getImageType( file.string() );
123 param.m_filename = file.string();
124 param.m_dataImage = this->getConcreteObject();
125 param.m_fwReader = this->getSptr();
129 assert( m_object.lock() );
#define OSLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
#define SLM_TRACE_FUNC()
Trace contextual function signature.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
#define OSLM_INFO(message)
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
The namespace fwItkIO contains reader, writer and helper for itk image.
Contains the representation of the data objects used in the framework.