#include #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; pixels.push_back( "char" ); pixels.push_back( "short" ); pixels.push_back( "int" ); pixels.push_back( "long" ); pixels.push_back( "uchar" ); pixels.push_back( "ushort" ); pixels.push_back( "uint" ); pixels.push_back( "ulong" ); pixels.push_back( "float" ); pixels.push_back( "double" ); this->m_Parameters.ConfigureAsChoices( "PixelType", pixels ); this->m_Parameters.SetSelectedChoice( "PixelType", "uchar" ); std::vector< std::string > dims; dims.push_back( "1" ); dims.push_back( "2" ); dims.push_back( "3" ); dims.push_back( "4" ); this->m_Parameters.ConfigureAsChoices( "Dimension", dims ); this->m_Parameters.SetSelectedChoice( "Dimension", "2" ); } // ------------------------------------------------------------------------- cpPluginsImageSources::RandomImageSource:: ~RandomImageSource( ) { } // ------------------------------------------------------------------------- void cpPluginsImageSources::RandomImageSource:: _GenerateData( ) { auto pixel = this->m_Parameters.GetSelectedChoice( "PixelType" ); if ( pixel == "char" ) this->_GD0< char >( ); else if( pixel == "short" ) this->_GD0< short >( ); else if( pixel == "int" ) this->_GD0< int >( ); else if( pixel == "long" ) this->_GD0< long >( ); else if( pixel == "uchar" ) this->_GD0< unsigned char >( ); else if( pixel == "ushort" ) this->_GD0< unsigned short >( ); else if( pixel == "uint" ) this->_GD0< unsigned int >( ); else if( pixel == "ulong" ) this->_GD0< unsigned long >( ); else if( pixel == "float" ) this->_GD0< float >( ); else if( pixel == "double" ) this->_GD0< double >( ); else this->_Error( "Invalid pixel type." ); } // ------------------------------------------------------------------------- template< class _TPixel > void cpPluginsImageSources::RandomImageSource:: _GD0( ) { auto dim = this->m_Parameters.GetSelectedChoice( "Dimension" ); if ( dim == "1" ) this->_GD1< _TPixel, 1 >( ); else if( dim == "2" ) this->_GD1< _TPixel, 2 >( ); else if( dim == "3" ) this->_GD1< _TPixel, 3 >( ); else if( dim == "4" ) this->_GD1< _TPixel, 4 >( ); else this->_Error( "Invalid dimension." ); } // ------------------------------------------------------------------------- template< class _TPixel, unsigned int _VDim > void 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( ) ); } // eof - $RCSfile$