#include #include #include // ------------------------------------------------------------------------- cpPluginsImageSources::RandomImageSource:: RandomImageSource( ) : Superclass( ) { this->_ConfigureOutput< cpPlugins::DataObjects::Image >( "Output" ); this->m_Parameters.ConfigureAsUintList( "Size" ); this->m_Parameters.ConfigureAsRealList( "Spacing" ); std::vector< std::string > pixels; #ifdef cpPlugins_CONFIG_INTEGER_TYPES_char pixels.push_back( "char" ); pixels.push_back( "uchar" ); #endif // cpPlugins_CONFIG_INTEGER_TYPES_char #ifdef cpPlugins_CONFIG_INTEGER_TYPES_short pixels.push_back( "short" ); pixels.push_back( "ushort" ); #endif // cpPlugins_CONFIG_INTEGER_TYPES_short #ifdef cpPlugins_CONFIG_INTEGER_TYPES_int pixels.push_back( "int" ); pixels.push_back( "uint" ); #endif // cpPlugins_CONFIG_INTEGER_TYPES_int #ifdef cpPlugins_CONFIG_INTEGER_TYPES_long pixels.push_back( "long" ); pixels.push_back( "ulong" ); #endif // cpPlugins_CONFIG_INTEGER_TYPES_long #ifdef cpPlugins_CONFIG_REAL_TYPES_float pixels.push_back( "float" ); #endif // cpPlugins_CONFIG_REAL_TYPES_float #ifdef cpPlugins_CONFIG_REAL_TYPES_double pixels.push_back( "double" ); #endif // cpPlugins_CONFIG_REAL_TYPES_double this->m_Parameters.ConfigureAsChoices( "PixelType", pixels ); std::vector< std::string > dims; #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_1 dims.push_back( "1" ); #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_1 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_2 dims.push_back( "2" ); #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_2 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_3 dims.push_back( "3" ); #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_3 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_4 dims.push_back( "4" ); #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_4 this->m_Parameters.ConfigureAsChoices( "Dimension", dims ); } // ------------------------------------------------------------------------- cpPluginsImageSources::RandomImageSource:: ~RandomImageSource( ) { } // ------------------------------------------------------------------------- void cpPluginsImageSources::RandomImageSource:: _GenerateData( ) { bool success = false; auto pixel = this->m_Parameters.GetSelectedChoice( "PixelType" ); #ifdef cpPlugins_CONFIG_INTEGER_TYPES_char if( pixel == "char" ) success = this->_GD0< char >( ); if( pixel == "uchar" ) success = this->_GD0< unsigned char >( ); #endif // cpPlugins_CONFIG_INTEGER_TYPES_char #ifdef cpPlugins_CONFIG_INTEGER_TYPES_short if( pixel == "short" ) success = this->_GD0< short >( ); if( pixel == "ushort" ) success = this->_GD0< unsigned short >( ); #endif // cpPlugins_CONFIG_INTEGER_TYPES_short #ifdef cpPlugins_CONFIG_INTEGER_TYPES_int if( pixel == "int" ) success = this->_GD0< int >( ); if( pixel == "uint" ) success = this->_GD0< unsigned int >( ); #endif // cpPlugins_CONFIG_INTEGER_TYPES_int #ifdef cpPlugins_CONFIG_INTEGER_TYPES_long if( pixel == "long" ) success = this->_GD0< long >( ); if( pixel == "ulong" ) success = this->_GD0< unsigned long >( ); #endif // cpPlugins_CONFIG_INTEGER_TYPES_long #ifdef cpPlugins_CONFIG_REAL_TYPES_float if( pixel == "float" ) success = this->_GD0< float >( ); #endif // cpPlugins_CONFIG_REAL_TYPES_float #ifdef cpPlugins_CONFIG_REAL_TYPES_double if( pixel == "double" ) success = this->_GD0< double >( ); #endif // cpPlugins_CONFIG_REAL_TYPES_double if( !success ) this->_Error( "Invalid pixel type." ); } // ------------------------------------------------------------------------- template< class _TPixel > bool cpPluginsImageSources::RandomImageSource:: _GD0( ) { bool success = false; auto dim = this->m_Parameters.GetSelectedChoice( "Dimension" ); #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_1 if( dim == "1" ) success = this->_GD1< _TPixel, 1 >( ); #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_1 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_2 if( dim == "2" ) success = this->_GD1< _TPixel, 2 >( ); #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_2 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_3 if( dim == "3" ) success = this->_GD1< _TPixel, 3 >( ); #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_3 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_4 if( dim == "4" ) success = this->_GD1< _TPixel, 4 >( ); #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_4 if( !success ) this->_Error( "Invalid dimension." ); return( success ); } // ------------------------------------------------------------------------- template< class _TPixel, unsigned int _VDim > bool cpPluginsImageSources::RandomImageSource:: _GD1( ) { typedef itk::Image< _TPixel, _VDim > _TImage; typedef itk::RandomImageSource< _TImage > _TFilter; auto size = this->m_Parameters.GetUintList( "Size" ); auto spacing = this->m_Parameters.GetRealList( "Spacing" ); if( size.size( ) < _VDim ) this->_Error( "Invalid size." ); if( spacing.size( ) < _VDim ) this->_Error( "Invalid spacing." ); typename _TImage::SizeType out_size; typename _TImage::SpacingType out_spac; for( unsigned int i = 0; i < _VDim; ++i ) { out_size[ i ] = size[ i ]; out_spac[ i ] = spacing[ i ]; } // rof _TFilter* filter = this->_CreateITK< _TFilter >( ); filter->SetSize( out_size ); filter->SetSpacing( out_spac ); filter->Update( ); this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); return( true ); } // eof - $RCSfile$