1 #include <plugins/ImageSources/RandomImageSource.h>
2 #include <cpPlugins/DataObjects/Image.h>
4 #include <itkRandomImageSource.h>
5 #include <itkRandomImageSource.hxx>
7 // -------------------------------------------------------------------------
8 cpPluginsImageSources::RandomImageSource::
12 this->_ConfigureOutput< cpPlugins::DataObjects::Image >( "Output" );
14 this->m_Parameters.ConfigureAsUintList( "Size" );
15 this->m_Parameters.ConfigureAsRealList( "Spacing" );
17 std::vector< std::string > pixels;
18 pixels.push_back( "char" );
19 pixels.push_back( "short" );
20 pixels.push_back( "int" );
21 pixels.push_back( "long" );
22 pixels.push_back( "uchar" );
23 pixels.push_back( "ushort" );
24 pixels.push_back( "uint" );
25 pixels.push_back( "ulong" );
26 pixels.push_back( "float" );
27 pixels.push_back( "double" );
28 this->m_Parameters.ConfigureAsChoices( "PixelType", pixels );
29 this->m_Parameters.SetSelectedChoice( "PixelType", "uchar" );
31 std::vector< std::string > dims;
32 dims.push_back( "1" );
33 dims.push_back( "2" );
34 dims.push_back( "3" );
35 dims.push_back( "4" );
36 this->m_Parameters.ConfigureAsChoices( "Dimension", dims );
37 this->m_Parameters.SetSelectedChoice( "Dimension", "2" );
40 // -------------------------------------------------------------------------
41 cpPluginsImageSources::RandomImageSource::
46 // -------------------------------------------------------------------------
47 void cpPluginsImageSources::RandomImageSource::
50 auto pixel = this->m_Parameters.GetSelectedChoice( "PixelType" );
51 if ( pixel == "char" ) this->_GD0< char >( );
52 else if( pixel == "short" ) this->_GD0< short >( );
53 else if( pixel == "int" ) this->_GD0< int >( );
54 else if( pixel == "long" ) this->_GD0< long >( );
55 else if( pixel == "uchar" ) this->_GD0< unsigned char >( );
56 else if( pixel == "ushort" ) this->_GD0< unsigned short >( );
57 else if( pixel == "uint" ) this->_GD0< unsigned int >( );
58 else if( pixel == "ulong" ) this->_GD0< unsigned long >( );
59 else if( pixel == "float" ) this->_GD0< float >( );
60 else if( pixel == "double" ) this->_GD0< double >( );
61 else this->_Error( "Invalid pixel type." );
64 // -------------------------------------------------------------------------
65 template< class _TPixel >
66 void cpPluginsImageSources::RandomImageSource::
69 auto dim = this->m_Parameters.GetSelectedChoice( "Dimension" );
70 if ( dim == "1" ) this->_GD1< _TPixel, 1 >( );
71 else if( dim == "2" ) this->_GD1< _TPixel, 2 >( );
72 else if( dim == "3" ) this->_GD1< _TPixel, 3 >( );
73 else if( dim == "4" ) this->_GD1< _TPixel, 4 >( );
74 else this->_Error( "Invalid dimension." );
77 // -------------------------------------------------------------------------
78 template< class _TPixel, unsigned int _VDim >
79 void cpPluginsImageSources::RandomImageSource::
82 typedef itk::Image< _TPixel, _VDim > _TImage;
83 typedef itk::RandomImageSource< _TImage > _TFilter;
85 auto size = this->m_Parameters.GetUintList( "Size" );
86 auto spacing = this->m_Parameters.GetRealList( "Spacing" );
87 if( size.size( ) < _VDim )
88 this->_Error( "Invalid size." );
89 if( spacing.size( ) < _VDim )
90 this->_Error( "Invalid spacing." );
92 typename _TImage::SizeType out_size;
93 typename _TImage::SpacingType out_spac;
94 for( unsigned int i = 0; i < _VDim; ++i )
96 out_size[ i ] = size[ i ];
97 out_spac[ i ] = spacing[ i ];
101 _TFilter* filter = this->_CreateITK< _TFilter >( );
102 filter->SetSize( out_size );
103 filter->SetSpacing( out_spac );
105 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );