1 #include <cpPlugins/Plugins/ImageReader.h>
3 #include <itkImageFileReader.h>
5 #define ITK_MANUAL_INSTANTIATION
7 #include <itkRGBPixel.h>
9 // -------------------------------------------------------------------------
10 cpPlugins::Plugins::ImageReader::
14 this->SetNumberOfOutputs( 1 );
16 this->m_DefaultParameters[ "FileName" ] =
17 TParameter( "string", "no_file_name" );
18 this->m_DefaultParameters[ "PixelType" ] = TParameter( "type", "uchar" );
19 this->m_DefaultParameters[ "ImageDimension" ] = TParameter( "int", "2" );
20 this->m_DefaultParameters[ "IsColorImage" ] = TParameter( "bool", "0" );
23 // -------------------------------------------------------------------------
24 cpPlugins::Plugins::ImageReader::
29 // -------------------------------------------------------------------------
30 std::string cpPlugins::Plugins::ImageReader::
33 return( "cpPlugins::Plugins::ImageReader" );
36 // -------------------------------------------------------------------------
37 std::string cpPlugins::Plugins::ImageReader::
40 TParameters::const_iterator dIt;
42 // Get image dimension
43 dIt = this->m_Parameters.find( "ImageDimension" );
44 if( dIt == this->m_Parameters.end( ) )
45 dIt = this->m_DefaultParameters.find( "ImageDimension" );
47 std::string ret = "itk::Image dimension not supported.";
48 if ( dIt->second.second == "1" ) ret = this->_GenerateData0< 1 >( );
49 else if( dIt->second.second == "2" ) ret = this->_GenerateData0< 2 >( );
50 else if( dIt->second.second == "3" ) ret = this->_GenerateData0< 3 >( );
51 else if( dIt->second.second == "4" ) ret = this->_GenerateData0< 4 >( );
56 // -------------------------------------------------------------------------
57 template< unsigned int D >
58 std::string cpPlugins::Plugins::ImageReader::
61 TParameters::const_iterator tIt, cIt;
63 // Get image pixelType
64 tIt = this->m_Parameters.find( "PixelType" );
65 if( tIt == this->m_Parameters.end( ) )
66 tIt = this->m_DefaultParameters.find( "PixelType" );
67 cIt = this->m_Parameters.find( "IsColorImage" );
68 if( cIt == this->m_Parameters.end( ) )
69 cIt = this->m_DefaultParameters.find( "IsColorImage" );
71 std::string ret = "itk::Image pixel type not supported";
72 if( cIt->second.second == "0" )
74 if( tIt->second.second == "char" )
75 ret = this->_GenerateData1< char, D >( );
76 else if( tIt->second.second == "short" )
77 ret = this->_GenerateData1< short, D >( );
78 else if( tIt->second.second == "int" )
79 ret = this->_GenerateData1< int, D >( );
80 else if( tIt->second.second == "long" )
81 ret = this->_GenerateData1< long, D >( );
82 else if( tIt->second.second == "uchar" )
83 ret = this->_GenerateData1< unsigned char, D >( );
84 else if( tIt->second.second == "ushort" )
85 ret = this->_GenerateData1< unsigned short, D >( );
86 else if( tIt->second.second == "uint" )
87 ret = this->_GenerateData1< unsigned int, D >( );
88 else if( tIt->second.second == "ulong" )
89 ret = this->_GenerateData1< unsigned long, D >( );
90 else if( tIt->second.second == "float" )
91 ret = this->_GenerateData1< float, D >( );
92 else if( tIt->second.second == "double" )
93 ret = this->_GenerateData1< double, D >( );
95 else if( cIt->second.second == "1" )
97 if( tIt->second.second == "char" )
98 ret = this->_GenerateData1< itk::RGBPixel< char >, D >( );
99 else if( tIt->second.second == "short" )
100 ret = this->_GenerateData1< itk::RGBPixel< short >, D >( );
101 else if( tIt->second.second == "int" )
102 ret = this->_GenerateData1< itk::RGBPixel< int >, D >( );
103 else if( tIt->second.second == "long" )
104 ret = this->_GenerateData1< itk::RGBPixel< long >, D >( );
105 else if( tIt->second.second == "uchar" )
106 ret = this->_GenerateData1< itk::RGBPixel< unsigned char >, D >( );
107 else if( tIt->second.second == "ushort" )
108 ret = this->_GenerateData1< itk::RGBPixel< unsigned short >, D >( );
109 else if( tIt->second.second == "uint" )
110 ret = this->_GenerateData1< itk::RGBPixel< unsigned int >, D >( );
111 else if( tIt->second.second == "ulong" )
112 ret = this->_GenerateData1< itk::RGBPixel< unsigned long >, D >( );
113 else if( tIt->second.second == "float" )
114 ret = this->_GenerateData1< itk::RGBPixel< float >, D >( );
115 else if( tIt->second.second == "double" )
116 ret = this->_GenerateData1< itk::RGBPixel< double >, D >( );
121 // -------------------------------------------------------------------------
122 template< class P, unsigned int D >
123 std::string cpPlugins::Plugins::ImageReader::
126 TParameters::const_iterator fIt;
128 // Get image pixelType
129 fIt = this->m_Parameters.find( "FileName" );
130 if( fIt == this->m_Parameters.end( ) )
131 fIt = this->m_DefaultParameters.find( "FileName" );
133 typedef itk::Image< P, D > _TImage;
134 typedef itk::ImageFileReader< _TImage > _TImageReader;
136 _TImageReader* reader =
137 dynamic_cast< _TImageReader* >( this->m_Reader.GetPointer( ) );
140 this->m_Reader = _TImageReader::New( );
141 reader = dynamic_cast< _TImageReader* >( this->m_Reader.GetPointer( ) );
144 reader->SetFileName( fIt->second.second );
149 catch( itk::ExceptionObject& err )
151 return( err.GetDescription( ) );
154 this->_SetOutput( 0, reader->GetOutput( ) );