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 cpPlugins::Plugins::ImageSeriesReader::
18 this->SetNumberOfOutputs( 1 );
19 this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
21 this->m_DefaultParameters[ "FileNames" ] =
22 TParameter( "string", "file_name1;file_name2;file_name3;..." );
23 this->m_DefaultParameters[ "PixelType" ] = TParameter( "type", "uchar" );
24 this->m_DefaultParameters[ "ImageDimension" ] = TParameter( "int", "3" );
25 this->m_DefaultParameters[ "IsColorImage" ] = TParameter( "bool", "0" );
28 // -------------------------------------------------------------------------
29 cpPlugins::Plugins::ImageSeriesReader::
34 // -------------------------------------------------------------------------
35 std::string cpPlugins::Plugins::ImageSeriesReader::
38 return( "cpPlugins::Plugins::ImageSeriesReader" );
41 // -------------------------------------------------------------------------
42 std::string cpPlugins::Plugins::ImageSeriesReader::
45 TParameters::const_iterator dIt;
47 // Get image dimension
48 dIt = this->m_Parameters.find( "ImageDimension" );
49 if( dIt == this->m_Parameters.end( ) )
50 dIt = this->m_DefaultParameters.find( "ImageDimension" );
52 std::string r = "cpPlugins::Plugins::ImageSeriesReader: itk::Image dimension not supported.";
53 if( dIt->second.second == "2" ) r = this->_GD0< 2 >( );
54 else if( dIt->second.second == "3" ) r = this->_GD0< 3 >( );
55 else if( dIt->second.second == "4" ) r = this->_GD0< 4 >( );
60 // -------------------------------------------------------------------------
61 template< unsigned int D >
62 std::string cpPlugins::Plugins::ImageSeriesReader::
65 TParameters::const_iterator tIt, cIt;
67 // Get image pixel type
68 tIt = this->m_Parameters.find( "PixelType" );
69 if( tIt == this->m_Parameters.end( ) )
70 tIt = this->m_DefaultParameters.find( "PixelType" );
71 cIt = this->m_Parameters.find( "IsColorImage" );
72 if( cIt == this->m_Parameters.end( ) )
73 cIt = this->m_DefaultParameters.find( "IsColorImage" );
75 std::string r = "cpPlugins::Plugins::ImageSeriesReader: itk::Image pixel type not supported";
76 if( cIt->second.second == "0" )
78 if( tIt->second.second == "char" )
79 r = this->_GD1< char, D >( );
80 else if( tIt->second.second == "short" )
81 r = this->_GD1< short, D >( );
82 else if( tIt->second.second == "int" )
83 r = this->_GD1< int, D >( );
84 else if( tIt->second.second == "long" )
85 r = this->_GD1< long, D >( );
86 else if( tIt->second.second == "uchar" )
87 r = this->_GD1< unsigned char, D >( );
88 else if( tIt->second.second == "ushort" )
89 r = this->_GD1< unsigned short, D >( );
90 else if( tIt->second.second == "uint" )
91 r = this->_GD1< unsigned int, D >( );
92 else if( tIt->second.second == "ulong" )
93 r = this->_GD1< unsigned long, D >( );
94 else if( tIt->second.second == "float" )
95 r = this->_GD1< float, D >( );
96 else if( tIt->second.second == "double" )
97 r = this->_GD1< double, D >( );
99 else if( cIt->second.second == "1" )
101 if( tIt->second.second == "char" )
102 r = this->_GD1< itk::RGBPixel< char >, D >( );
103 else if( tIt->second.second == "short" )
104 r = this->_GD1< itk::RGBPixel< short >, D >( );
105 else if( tIt->second.second == "int" )
106 r = this->_GD1< itk::RGBPixel< int >, D >( );
107 else if( tIt->second.second == "long" )
108 r = this->_GD1< itk::RGBPixel< long >, D >( );
109 else if( tIt->second.second == "uchar" )
110 r = this->_GD1< itk::RGBPixel< unsigned char >, D >( );
111 else if( tIt->second.second == "ushort" )
112 r = this->_GD1< itk::RGBPixel< unsigned short >, D >( );
113 else if( tIt->second.second == "uint" )
114 r = this->_GD1< itk::RGBPixel< unsigned int >, D >( );
115 else if( tIt->second.second == "ulong" )
116 r = this->_GD1< itk::RGBPixel< unsigned long >, D >( );
117 else if( tIt->second.second == "float" )
118 r = this->_GD1< itk::RGBPixel< float >, D >( );
119 else if( tIt->second.second == "double" )
120 r = this->_GD1< itk::RGBPixel< double >, D >( );
125 // -------------------------------------------------------------------------
126 template< class P, unsigned int D >
127 std::string cpPlugins::Plugins::ImageSeriesReader::
130 TParameters::const_iterator fIt;
133 std::set< std::string > filenames;
134 fIt = this->m_Parameters.find( "FileNames" );
135 if( fIt == this->m_Parameters.end( ) )
136 fIt = this->m_DefaultParameters.find( "FileName" );
137 std::istringstream filenames_stream( fIt->second.second );
138 std::string filename;
139 while( std::getline( filenames_stream, filename, ';' ) )
140 filenames.insert( filename );
143 typedef itk::Image< P, D > _TImage;
144 typedef itk::ImageSeriesReader< _TImage > _TReader;
147 dynamic_cast< _TReader* >( this->m_Reader.GetPointer( ) );
150 this->m_Reader = _TReader::New( );
151 reader = dynamic_cast< _TReader* >( this->m_Reader.GetPointer( ) );
154 std::set< std::string >::const_iterator fnIt = filenames.begin( );
155 for( ; fnIt != filenames.end( ); ++fnIt )
156 reader->AddFileName( *fnIt );
161 catch( itk::ExceptionObject& err )
163 return( err.GetDescription( ) );
166 this->_SetOutput( 0, reader->GetOutput( ) );