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 std::string cpPlugins::Plugins::ImageReader::
14 return( "cpPlugins::Plugins::ImageReader" );
17 // -------------------------------------------------------------------------
18 cpPlugins::Plugins::ImageReader::
22 this->SetNumberOfOutputs( 1 );
23 this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
25 using namespace cpPlugins::Interface;
26 this->m_DefaultParameters.Configure( Parameters::String, "FileName" );
27 this->m_DefaultParameters.Configure( Parameters::String, "PixelType" );
28 this->m_DefaultParameters.Configure( Parameters::Uint, "Dimension" );
29 this->m_DefaultParameters.Configure( Parameters::Uint, "IsColorImage" );
30 this->m_DefaultParameters.SetValueAsString( "PixelType", "uchar" );
31 this->m_DefaultParameters.SetValueAsUint( "Dimension", 3 );
32 this->m_DefaultParameters.SetValueAsUint( "IsColorImage", 0 );
33 this->m_Parameters = this->m_DefaultParameters;
36 // -------------------------------------------------------------------------
37 cpPlugins::Plugins::ImageReader::
42 // -------------------------------------------------------------------------
43 std::string cpPlugins::Plugins::ImageReader::
46 using namespace cpPlugins::Interface;
47 Parameters::TUint dim = this->m_Parameters.GetValueAsUint( "Dimension" );
48 std::string r = "cpPlugins::Plugins::ImageReader: itk::Image dimension not supported.";
49 if ( dim == 1 ) r = this->_GD0< 1 >( );
50 else if( dim == 2 ) r = this->_GD0< 2 >( );
51 else if( dim == 3 ) r = this->_GD0< 3 >( );
52 else if( dim == 4 ) r = this->_GD0< 4 >( );
57 // -------------------------------------------------------------------------
58 template< unsigned int D >
59 std::string cpPlugins::Plugins::ImageReader::
62 using namespace cpPlugins::Interface;
63 Parameters::TString pt = this->m_Parameters.GetValueAsString( "PixelType" );
64 Parameters::TUint ci = this->m_Parameters.GetValueAsUint( "IsColorImage" );
66 std::string r = "cpPlugins::Plugins::ImageReader: itk::Image pixel type not supported";
70 r = this->_GD1< char, D >( );
71 else if( pt == "short" )
72 r = this->_GD1< short, D >( );
73 else if( pt == "int" )
74 r = this->_GD1< int, D >( );
75 else if( pt == "long" )
76 r = this->_GD1< long, D >( );
77 else if( pt == "uchar" )
78 r = this->_GD1< unsigned char, D >( );
79 else if( pt == "ushort" )
80 r = this->_GD1< unsigned short, D >( );
81 else if( pt == "uint" )
82 r = this->_GD1< unsigned int, D >( );
83 else if( pt == "ulong" )
84 r = this->_GD1< unsigned long, D >( );
85 else if( pt == "float" )
86 r = this->_GD1< float, D >( );
87 else if( pt == "double" )
88 r = this->_GD1< double, D >( );
93 r = this->_GD1< itk::RGBPixel< char >, D >( );
94 else if( pt == "short" )
95 r = this->_GD1< itk::RGBPixel< short >, D >( );
96 else if( pt == "int" )
97 r = this->_GD1< itk::RGBPixel< int >, D >( );
98 else if( pt == "long" )
99 r = this->_GD1< itk::RGBPixel< long >, D >( );
100 else if( pt == "uchar" )
101 r = this->_GD1< itk::RGBPixel< unsigned char >, D >( );
102 else if( pt == "ushort" )
103 r = this->_GD1< itk::RGBPixel< unsigned short >, D >( );
104 else if( pt == "uint" )
105 r = this->_GD1< itk::RGBPixel< unsigned int >, D >( );
106 else if( pt == "ulong" )
107 r = this->_GD1< itk::RGBPixel< unsigned long >, D >( );
108 else if( pt == "float" )
109 r = this->_GD1< itk::RGBPixel< float >, D >( );
110 else if( pt == "double" )
111 r = this->_GD1< itk::RGBPixel< double >, D >( );
116 // -------------------------------------------------------------------------
117 template< class P, unsigned int D >
118 std::string cpPlugins::Plugins::ImageReader::
122 using namespace cpPlugins::Interface;
123 Parameters::TString fname =
124 this->m_Parameters.GetValueAsString( "FileName" );
126 typedef itk::Image< P, D > _TImage;
127 typedef itk::ImageFileReader< _TImage > _TReader;
130 dynamic_cast< _TReader* >( this->m_RealProcessObject.GetPointer( ) );
133 this->m_RealProcessObject = _TReader::New( );
135 dynamic_cast< _TReader* >( this->m_RealProcessObject.GetPointer( ) );
138 reader->SetFileName( fname );
143 catch( itk::ExceptionObject& err )
145 return( err.GetDescription( ) );
148 this->_SetOutput( 0, reader->GetOutput( ) );