1 #include <cpPlugins/Plugins/ImageReader.h>
2 #include <cpPlugins/Interface/Image.h>
4 #include <itkImageFileReader.h>
6 #define ITK_MANUAL_INSTANTIATION
8 #include <itkRGBPixel.h>
10 // -------------------------------------------------------------------------
11 cpPlugins::Plugins::ImageReader::
15 this->SetNumberOfOutputs( 1 );
16 this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
18 this->m_DefaultParameters[ "FileName" ] =
19 TParameter( "string", "no_file_name" );
20 this->m_DefaultParameters[ "PixelType" ] = TParameter( "type", "uchar" );
21 this->m_DefaultParameters[ "ImageDimension" ] = TParameter( "int", "2" );
22 this->m_DefaultParameters[ "IsColorImage" ] = TParameter( "bool", "0" );
25 // -------------------------------------------------------------------------
26 cpPlugins::Plugins::ImageReader::
31 // -------------------------------------------------------------------------
32 std::string cpPlugins::Plugins::ImageReader::
35 return( "cpPlugins::Plugins::ImageReader" );
38 // -------------------------------------------------------------------------
39 std::string cpPlugins::Plugins::ImageReader::
42 TParameters::const_iterator dIt;
44 // Get image dimension
45 dIt = this->m_Parameters.find( "ImageDimension" );
46 if( dIt == this->m_Parameters.end( ) )
47 dIt = this->m_DefaultParameters.find( "ImageDimension" );
49 std::string r = "itk::Image dimension not supported.";
50 if ( dIt->second.second == "1" ) r = this->_GD0< 1 >( );
51 else if( dIt->second.second == "2" ) r = this->_GD0< 2 >( );
52 else if( dIt->second.second == "3" ) r = this->_GD0< 3 >( );
53 else if( dIt->second.second == "4" ) r = this->_GD0< 4 >( );
58 // -------------------------------------------------------------------------
59 template< unsigned int D >
60 std::string cpPlugins::Plugins::ImageReader::
63 TParameters::const_iterator tIt, cIt;
65 // Get image pixel type
66 tIt = this->m_Parameters.find( "PixelType" );
67 if( tIt == this->m_Parameters.end( ) )
68 tIt = this->m_DefaultParameters.find( "PixelType" );
69 cIt = this->m_Parameters.find( "IsColorImage" );
70 if( cIt == this->m_Parameters.end( ) )
71 cIt = this->m_DefaultParameters.find( "IsColorImage" );
73 std::string r = "itk::Image pixel type not supported";
74 if( cIt->second.second == "0" )
76 if( tIt->second.second == "char" )
77 r = this->_GD1< char, D >( );
78 else if( tIt->second.second == "short" )
79 r = this->_GD1< short, D >( );
80 else if( tIt->second.second == "int" )
81 r = this->_GD1< int, D >( );
82 else if( tIt->second.second == "long" )
83 r = this->_GD1< long, D >( );
84 else if( tIt->second.second == "uchar" )
85 r = this->_GD1< unsigned char, D >( );
86 else if( tIt->second.second == "ushort" )
87 r = this->_GD1< unsigned short, D >( );
88 else if( tIt->second.second == "uint" )
89 r = this->_GD1< unsigned int, D >( );
90 else if( tIt->second.second == "ulong" )
91 r = this->_GD1< unsigned long, D >( );
92 else if( tIt->second.second == "float" )
93 r = this->_GD1< float, D >( );
94 else if( tIt->second.second == "double" )
95 r = this->_GD1< double, D >( );
97 else if( cIt->second.second == "1" )
99 if( tIt->second.second == "char" )
100 r = this->_GD1< itk::RGBPixel< char >, D >( );
101 else if( tIt->second.second == "short" )
102 r = this->_GD1< itk::RGBPixel< short >, D >( );
103 else if( tIt->second.second == "int" )
104 r = this->_GD1< itk::RGBPixel< int >, D >( );
105 else if( tIt->second.second == "long" )
106 r = this->_GD1< itk::RGBPixel< long >, D >( );
107 else if( tIt->second.second == "uchar" )
108 r = this->_GD1< itk::RGBPixel< unsigned char >, D >( );
109 else if( tIt->second.second == "ushort" )
110 r = this->_GD1< itk::RGBPixel< unsigned short >, D >( );
111 else if( tIt->second.second == "uint" )
112 r = this->_GD1< itk::RGBPixel< unsigned int >, D >( );
113 else if( tIt->second.second == "ulong" )
114 r = this->_GD1< itk::RGBPixel< unsigned long >, D >( );
115 else if( tIt->second.second == "float" )
116 r = this->_GD1< itk::RGBPixel< float >, D >( );
117 else if( tIt->second.second == "double" )
118 r = this->_GD1< itk::RGBPixel< double >, D >( );
123 // -------------------------------------------------------------------------
124 template< class P, unsigned int D >
125 std::string cpPlugins::Plugins::ImageReader::
128 TParameters::const_iterator fIt;
131 fIt = this->m_Parameters.find( "FileName" );
132 if( fIt == this->m_Parameters.end( ) )
133 fIt = this->m_DefaultParameters.find( "FileName" );
135 typedef itk::Image< P, D > _TImage;
136 typedef itk::ImageFileReader< _TImage > _TImageReader;
138 _TImageReader* reader =
139 dynamic_cast< _TImageReader* >( this->m_Reader.GetPointer( ) );
142 this->m_Reader = _TImageReader::New( );
143 reader = dynamic_cast< _TImageReader* >( this->m_Reader.GetPointer( ) );
146 reader->SetFileName( fIt->second.second );
151 catch( itk::ExceptionObject& err )
153 return( err.GetDescription( ) );
156 this->_SetOutput( 0, reader->GetOutput( ) );