1 #include <cpPlugins/Plugins/ImageReader.h>
3 // TODO: interesting... #define ITK_MANUAL_INSTANTIATION
5 #include <itkImageFileReader.h>
6 #include <itkRGBPixel.h>
8 // -------------------------------------------------------------------------
9 cpPlugins::Plugins::ImageReader::
13 this->SetNumberOfOutputs( 1 );
15 this->m_DefaultParameters[ "FileName" ] =
16 TParameter( "string", "no_file_name" );
17 this->m_DefaultParameters[ "PixelType" ] = TParameter( "type", "uchar" );
18 this->m_DefaultParameters[ "ImageDimension" ] = TParameter( "int", "2" );
19 this->m_DefaultParameters[ "IsColorImage" ] = TParameter( "bool", "0" );
22 // -------------------------------------------------------------------------
23 cpPlugins::Plugins::ImageReader::
28 // -------------------------------------------------------------------------
29 std::string cpPlugins::Plugins::ImageReader::
32 return( "cpPlugins::Plugins::ImageReader" );
35 // -------------------------------------------------------------------------
36 std::string cpPlugins::Plugins::ImageReader::
39 TParameters::const_iterator dIt;
41 // Get image dimension
42 dIt = this->m_Parameters.find( "ImageDimension" );
43 if( dIt == this->m_Parameters.end( ) )
44 dIt = this->m_DefaultParameters.find( "ImageDimension" );
46 std::string ret = "itk::Image dimension not supported.";
47 if ( dIt->second.second == "1" ) ret = this->_GenerateData0< 1 >( );
48 else if( dIt->second.second == "2" ) ret = this->_GenerateData0< 2 >( );
49 else if( dIt->second.second == "3" ) ret = this->_GenerateData0< 3 >( );
50 else if( dIt->second.second == "4" ) ret = this->_GenerateData0< 4 >( );
55 // -------------------------------------------------------------------------
56 template< unsigned int D >
57 std::string cpPlugins::Plugins::ImageReader::
60 TParameters::const_iterator tIt, cIt;
62 // Get image pixelType
63 tIt = this->m_Parameters.find( "PixelType" );
64 if( tIt == this->m_Parameters.end( ) )
65 tIt = this->m_DefaultParameters.find( "PixelType" );
66 cIt = this->m_Parameters.find( "IsColorImage" );
67 if( cIt == this->m_Parameters.end( ) )
68 cIt = this->m_DefaultParameters.find( "IsColorImage" );
70 std::string ret = "itk::Image pixel type not supported";
71 if( cIt->second.second == "0" )
73 if( tIt->second.second == "char" )
74 ret = this->_GenerateData1< char, D >( );
75 else if( tIt->second.second == "short" )
76 ret = this->_GenerateData1< short, D >( );
77 else if( tIt->second.second == "int" )
78 ret = this->_GenerateData1< int, D >( );
79 else if( tIt->second.second == "long" )
80 ret = this->_GenerateData1< long, D >( );
81 else if( tIt->second.second == "uchar" )
82 ret = this->_GenerateData1< unsigned char, D >( );
83 else if( tIt->second.second == "ushort" )
84 ret = this->_GenerateData1< unsigned short, D >( );
85 else if( tIt->second.second == "uint" )
86 ret = this->_GenerateData1< unsigned int, D >( );
87 else if( tIt->second.second == "ulong" )
88 ret = this->_GenerateData1< unsigned long, D >( );
89 else if( tIt->second.second == "float" )
90 ret = this->_GenerateData1< float, D >( );
91 else if( tIt->second.second == "double" )
92 ret = this->_GenerateData1< double, D >( );
94 else if( cIt->second.second == "1" )
96 if( tIt->second.second == "char" )
97 ret = this->_GenerateData1< itk::RGBPixel< char >, D >( );
98 else if( tIt->second.second == "short" )
99 ret = this->_GenerateData1< itk::RGBPixel< short >, D >( );
100 else if( tIt->second.second == "int" )
101 ret = this->_GenerateData1< itk::RGBPixel< int >, D >( );
102 else if( tIt->second.second == "long" )
103 ret = this->_GenerateData1< itk::RGBPixel< long >, D >( );
104 else if( tIt->second.second == "uchar" )
105 ret = this->_GenerateData1< itk::RGBPixel< unsigned char >, D >( );
106 else if( tIt->second.second == "ushort" )
107 ret = this->_GenerateData1< itk::RGBPixel< unsigned short >, D >( );
108 else if( tIt->second.second == "uint" )
109 ret = this->_GenerateData1< itk::RGBPixel< unsigned int >, D >( );
110 else if( tIt->second.second == "ulong" )
111 ret = this->_GenerateData1< itk::RGBPixel< unsigned long >, D >( );
112 else if( tIt->second.second == "float" )
113 ret = this->_GenerateData1< itk::RGBPixel< float >, D >( );
114 else if( tIt->second.second == "double" )
115 ret = this->_GenerateData1< itk::RGBPixel< double >, D >( );
120 // -------------------------------------------------------------------------
121 template< class P, unsigned int D >
122 std::string cpPlugins::Plugins::ImageReader::
125 TParameters::const_iterator fIt;
127 // Get image pixelType
128 fIt = this->m_Parameters.find( "FileName" );
129 if( fIt == this->m_Parameters.end( ) )
130 fIt = this->m_DefaultParameters.find( "FileName" );
132 typedef itk::Image< P, D > _TImage;
133 typedef itk::ImageFileReader< _TImage > _TImageReader;
135 _TImageReader* reader =
136 dynamic_cast< _TImageReader* >( this->m_Reader.GetPointer( ) );
139 this->m_Reader = _TImageReader::New( );
140 reader = dynamic_cast< _TImageReader* >( this->m_Reader.GetPointer( ) );
143 reader->SetFileName( fIt->second.second );
148 catch( itk::ExceptionObject& err )
150 return( err.GetDescription( ) );
153 this->_SetOutput( 0, reader->GetOutput( ) );