1 #include <cpPlugins/Plugins/ImageSeriesReader.h>
2 #include <cpPlugins/Interface/Image.h>
7 #include <itkImageSeriesReader.h>
9 #define ITK_MANUAL_INSTANTIATION
11 #include <itkRGBPixel.h>
13 // -------------------------------------------------------------------------
14 std::string cpPlugins::Plugins::ImageSeriesReader::
17 return( "cpPlugins::Plugins::ImageSeriesReader" );
20 // -------------------------------------------------------------------------
21 cpPlugins::Plugins::ImageSeriesReader::
25 this->SetNumberOfOutputs( 1 );
26 this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
28 using namespace cpPlugins::Interface;
29 this->m_DefaultParameters.Configure( Parameters::StringList, "FileNames" );
30 this->m_DefaultParameters.Configure( Parameters::String, "PixelType" );
31 this->m_DefaultParameters.Configure( Parameters::Uint, "Dimension" );
32 this->m_DefaultParameters.Configure( Parameters::Uint, "IsColorImage" );
33 this->m_DefaultParameters.SetValueAsString( "PixelType", "uchar" );
34 this->m_DefaultParameters.SetValueAsUint( "Dimension", 3 );
35 this->m_DefaultParameters.SetValueAsUint( "IsColorImage", 0 );
36 this->m_Parameters = this->m_DefaultParameters;
39 // -------------------------------------------------------------------------
40 cpPlugins::Plugins::ImageSeriesReader::
45 // -------------------------------------------------------------------------
46 std::string cpPlugins::Plugins::ImageSeriesReader::
49 using namespace cpPlugins::Interface;
50 Parameters::TUint dim = this->m_Parameters.GetValueAsUint( "Dimension" );
52 std::string r = "cpPlugins::Plugins::ImageSeriesReader: itk::Image dimension not supported.";
53 if ( dim == 2 ) r = this->_GD0< 2 >( );
54 else if( dim == 3 ) r = this->_GD0< 3 >( );
55 else if( dim == 4 ) r = this->_GD0< 4 >( );
60 // -------------------------------------------------------------------------
61 template< unsigned int D >
62 std::string cpPlugins::Plugins::ImageSeriesReader::
65 using namespace cpPlugins::Interface;
66 Parameters::TString pt = this->m_Parameters.GetValueAsString( "PixelType" );
67 Parameters::TUint ci = this->m_Parameters.GetValueAsUint( "IsColorImage" );
69 std::string r = "cpPlugins::Plugins::ImageSeriesReader: itk::Image pixel type not supported";
73 r = this->_GD1< char, D >( );
74 else if( pt == "short" )
75 r = this->_GD1< short, D >( );
76 else if( pt == "int" )
77 r = this->_GD1< int, D >( );
78 else if( pt == "long" )
79 r = this->_GD1< long, D >( );
80 else if( pt == "uchar" )
81 r = this->_GD1< unsigned char, D >( );
82 else if( pt == "ushort" )
83 r = this->_GD1< unsigned short, D >( );
84 else if( pt == "uint" )
85 r = this->_GD1< unsigned int, D >( );
86 else if( pt == "ulong" )
87 r = this->_GD1< unsigned long, D >( );
88 else if( pt == "float" )
89 r = this->_GD1< float, D >( );
90 else if( pt == "double" )
91 r = this->_GD1< double, D >( );
96 r = this->_GD1< itk::RGBPixel< char >, D >( );
97 else if( pt == "short" )
98 r = this->_GD1< itk::RGBPixel< short >, D >( );
99 else if( pt == "int" )
100 r = this->_GD1< itk::RGBPixel< int >, D >( );
101 else if( pt == "long" )
102 r = this->_GD1< itk::RGBPixel< long >, D >( );
103 else if( pt == "uchar" )
104 r = this->_GD1< itk::RGBPixel< unsigned char >, D >( );
105 else if( pt == "ushort" )
106 r = this->_GD1< itk::RGBPixel< unsigned short >, D >( );
107 else if( pt == "uint" )
108 r = this->_GD1< itk::RGBPixel< unsigned int >, D >( );
109 else if( pt == "ulong" )
110 r = this->_GD1< itk::RGBPixel< unsigned long >, D >( );
111 else if( pt == "float" )
112 r = this->_GD1< itk::RGBPixel< float >, D >( );
113 else if( pt == "double" )
114 r = this->_GD1< itk::RGBPixel< double >, D >( );
119 // -------------------------------------------------------------------------
120 template< class P, unsigned int D >
121 std::string cpPlugins::Plugins::ImageSeriesReader::
124 using namespace cpPlugins::Interface;
125 std::vector< Parameters::TString > unordered_names;
126 this->m_Parameters.GetValueAsStringList( unordered_names, "FileNames" );
127 std::set< std::string > ordered_names;
128 for( unsigned int i = 0; i < unordered_names.size( ); ++i )
129 ordered_names.insert( unordered_names[ i ] );
132 typedef itk::Image< P, D > _TImage;
133 typedef itk::ImageSeriesReader< _TImage > _TReader;
136 dynamic_cast< _TReader* >( this->m_RealProcessObject.GetPointer( ) );
139 this->m_RealProcessObject = _TReader::New( );
141 dynamic_cast< _TReader* >( this->m_RealProcessObject.GetPointer( ) );
144 std::set< std::string >::const_iterator fnIt = ordered_names.begin( );
145 for( ; fnIt != ordered_names.end( ); ++fnIt )
146 reader->AddFileName( *fnIt );
151 catch( itk::ExceptionObject& err )
153 return( err.GetDescription( ) );
156 this->_SetOutput( 0, reader->GetOutput( ) );