1 #include <ImageSources/RandomImageSource.h>
2 #include <cpPlugins/DataObjects/Image.h>
4 #include <itkRandomImageSource.h>
6 // -------------------------------------------------------------------------
7 cpPluginsImageSources::RandomImageSource::
11 this->_ConfigureOutput< cpPlugins::DataObjects::Image >( "Output" );
13 this->m_Parameters.ConfigureAsUintList( "Size" );
14 this->m_Parameters.ConfigureAsRealList( "Spacing" );
16 std::vector< std::string > pixels;
17 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_char
18 pixels.push_back( "char" );
19 pixels.push_back( "uchar" );
20 #endif // cpPlugins_CONFIG_INTEGER_TYPES_char
21 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_short
22 pixels.push_back( "short" );
23 pixels.push_back( "ushort" );
24 #endif // cpPlugins_CONFIG_INTEGER_TYPES_short
25 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_int
26 pixels.push_back( "int" );
27 pixels.push_back( "uint" );
28 #endif // cpPlugins_CONFIG_INTEGER_TYPES_int
29 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_long
30 pixels.push_back( "long" );
31 pixels.push_back( "ulong" );
32 #endif // cpPlugins_CONFIG_INTEGER_TYPES_long
33 #ifdef cpPlugins_CONFIG_REAL_TYPES_float
34 pixels.push_back( "float" );
35 #endif // cpPlugins_CONFIG_REAL_TYPES_float
36 #ifdef cpPlugins_CONFIG_REAL_TYPES_double
37 pixels.push_back( "double" );
38 #endif // cpPlugins_CONFIG_REAL_TYPES_double
39 this->m_Parameters.ConfigureAsChoices( "PixelType", pixels );
41 std::vector< std::string > dims;
42 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_1
43 dims.push_back( "1" );
44 #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_1
45 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_2
46 dims.push_back( "2" );
47 #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_2
48 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_3
49 dims.push_back( "3" );
50 #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_3
51 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_4
52 dims.push_back( "4" );
53 #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_4
54 this->m_Parameters.ConfigureAsChoices( "Dimension", dims );
57 // -------------------------------------------------------------------------
58 cpPluginsImageSources::RandomImageSource::
63 // -------------------------------------------------------------------------
64 void cpPluginsImageSources::RandomImageSource::
68 auto pixel = this->m_Parameters.GetSelectedChoice( "PixelType" );
69 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_char
70 if( pixel == "char" ) success = this->_GD0< char >( );
71 if( pixel == "uchar" ) success = this->_GD0< unsigned char >( );
72 #endif // cpPlugins_CONFIG_INTEGER_TYPES_char
73 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_short
74 if( pixel == "short" ) success = this->_GD0< short >( );
75 if( pixel == "ushort" ) success = this->_GD0< unsigned short >( );
76 #endif // cpPlugins_CONFIG_INTEGER_TYPES_short
77 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_int
78 if( pixel == "int" ) success = this->_GD0< int >( );
79 if( pixel == "uint" ) success = this->_GD0< unsigned int >( );
80 #endif // cpPlugins_CONFIG_INTEGER_TYPES_int
81 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_long
82 if( pixel == "long" ) success = this->_GD0< long >( );
83 if( pixel == "ulong" ) success = this->_GD0< unsigned long >( );
84 #endif // cpPlugins_CONFIG_INTEGER_TYPES_long
85 #ifdef cpPlugins_CONFIG_REAL_TYPES_float
86 if( pixel == "float" ) success = this->_GD0< float >( );
87 #endif // cpPlugins_CONFIG_REAL_TYPES_float
88 #ifdef cpPlugins_CONFIG_REAL_TYPES_double
89 if( pixel == "double" ) success = this->_GD0< double >( );
90 #endif // cpPlugins_CONFIG_REAL_TYPES_double
92 this->_Error( "Invalid pixel type." );
95 // -------------------------------------------------------------------------
96 template< class _TPixel >
97 bool cpPluginsImageSources::RandomImageSource::
100 bool success = false;
101 auto dim = this->m_Parameters.GetSelectedChoice( "Dimension" );
102 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_1
103 if( dim == "1" ) success = this->_GD1< _TPixel, 1 >( );
104 #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_1
105 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_2
106 if( dim == "2" ) success = this->_GD1< _TPixel, 2 >( );
107 #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_2
108 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_3
109 if( dim == "3" ) success = this->_GD1< _TPixel, 3 >( );
110 #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_3
111 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_4
112 if( dim == "4" ) success = this->_GD1< _TPixel, 4 >( );
113 #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_4
115 this->_Error( "Invalid dimension." );
119 // -------------------------------------------------------------------------
120 template< class _TPixel, unsigned int _VDim >
121 bool cpPluginsImageSources::RandomImageSource::
124 typedef itk::Image< _TPixel, _VDim > _TImage;
125 typedef itk::RandomImageSource< _TImage > _TFilter;
127 auto size = this->m_Parameters.GetUintList( "Size" );
128 auto spacing = this->m_Parameters.GetRealList( "Spacing" );
129 if( size.size( ) < _VDim )
130 this->_Error( "Invalid size." );
131 if( spacing.size( ) < _VDim )
132 this->_Error( "Invalid spacing." );
134 typename _TImage::SizeType out_size;
135 typename _TImage::SpacingType out_spac;
136 for( unsigned int i = 0; i < _VDim; ++i )
138 out_size[ i ] = size[ i ];
139 out_spac[ i ] = spacing[ i ];
143 _TFilter* filter = this->_CreateITK< _TFilter >( );
144 filter->SetSize( out_size );
145 filter->SetSpacing( out_spac );
147 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );