X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FPlugins%2FMarchingCubes.cxx;h=8187b42d0cdb51d743523ae28f9c7452a254f5b9;hb=54e12e973942f6ddfe6c606acf2fd93480ca6165;hp=32040333bd7737760253e0facb5eded80ed9d81e;hpb=2d96cce7bcab0bdcd9e93e44ed413c47388151d9;p=cpPlugins.git diff --git a/lib/cpPlugins/Plugins/MarchingCubes.cxx b/lib/cpPlugins/Plugins/MarchingCubes.cxx index 3204033..8187b42 100644 --- a/lib/cpPlugins/Plugins/MarchingCubes.cxx +++ b/lib/cpPlugins/Plugins/MarchingCubes.cxx @@ -2,172 +2,78 @@ #include #include -#include - -#define ITK_MANUAL_INSTANTIATION -#include -#include +#include +#include +#include // ------------------------------------------------------------------------- cpPlugins::Plugins::MarchingCubes:: MarchingCubes( ) - : Superclass( ) + : Superclass( ), + m_Algorithm( NULL ) { + this->m_ClassName = "cpPlugins::MarchingCubes"; + this->SetNumberOfInputs( 1 ); this->SetNumberOfOutputs( 1 ); this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 ); - /* TODO - this->m_DefaultParameters[ "FileName" ] = - TParameter( "string", "no_file_name" ); - this->m_DefaultParameters[ "PixelType" ] = TParameter( "type", "uchar" ); - this->m_DefaultParameters[ "ImageDimension" ] = TParameter( "int", "2" ); - this->m_DefaultParameters[ "IsColorImage" ] = TParameter( "bool", "0" ); - */ + using namespace cpPlugins::Interface; + this->m_DefaultParameters.Configure( Parameters::RealList, "Thresholds" ); + this->m_Parameters = this->m_DefaultParameters; } // ------------------------------------------------------------------------- cpPlugins::Plugins::MarchingCubes:: ~MarchingCubes( ) { -} - -// ------------------------------------------------------------------------- -std::string cpPlugins::Plugins::MarchingCubes:: -GetClassName( ) const -{ - return( "cpPlugins::Plugins::MarchingCubes" ); + if( this->m_Algorithm != NULL ) + this->m_Algorithm->Delete( ); } // ------------------------------------------------------------------------- std::string cpPlugins::Plugins::MarchingCubes:: _GenerateData( ) { - return( "" ); - /* TODO - TParameters::const_iterator dIt; - - // Get image dimension - dIt = this->m_Parameters.find( "ImageDimension" ); - if( dIt == this->m_Parameters.end( ) ) - dIt = this->m_DefaultParameters.find( "ImageDimension" ); - - std::string r = "cpPlugins::Plugins::MarchingCubes: itk::Image dimension not supported."; - if ( dIt->second.second == "1" ) r = this->_GD0< 1 >( ); - else if( dIt->second.second == "2" ) r = this->_GD0< 2 >( ); - else if( dIt->second.second == "3" ) r = this->_GD0< 3 >( ); - else if( dIt->second.second == "4" ) r = this->_GD0< 4 >( ); - - return( r ); - */ -} - -// ------------------------------------------------------------------------- -template< unsigned int D > -std::string cpPlugins::Plugins::MarchingCubes:: -_GD0( ) -{ - return( "" ); - /* TODO - TParameters::const_iterator tIt, cIt; - - // Get image pixel type - tIt = this->m_Parameters.find( "PixelType" ); - if( tIt == this->m_Parameters.end( ) ) - tIt = this->m_DefaultParameters.find( "PixelType" ); - cIt = this->m_Parameters.find( "IsColorImage" ); - if( cIt == this->m_Parameters.end( ) ) - cIt = this->m_DefaultParameters.find( "IsColorImage" ); - - std::string r = "cpPlugins::Plugins::MarchingCubes: itk::Image pixel type not supported"; - if( cIt->second.second == "0" ) + // Get input + cpPlugins::Interface::Image* image = + this->_Input< cpPlugins::Interface::Image >( 0 ); + if( image == NULL ) + return( "MarchingCubes: Input data is not a valid image." ); + vtkImageData* vtk_image = image->GetVTKImageData( ); + if( vtk_image == NULL ) + return( "MarchingCubes: Input does not have a valid VTK conversion." ); + + if( this->m_Algorithm != NULL ) + this->m_Algorithm->Delete( ); + + std::vector< double > values; + this->m_Parameters.GetValueAsRealList( values, "Thresholds" ); + if( vtk_image->GetDataDimension( ) == 2 ) { - if( tIt->second.second == "char" ) - r = this->_GD1< char, D >( ); - else if( tIt->second.second == "short" ) - r = this->_GD1< short, D >( ); - else if( tIt->second.second == "int" ) - r = this->_GD1< int, D >( ); - else if( tIt->second.second == "long" ) - r = this->_GD1< long, D >( ); - else if( tIt->second.second == "uchar" ) - r = this->_GD1< unsigned char, D >( ); - else if( tIt->second.second == "ushort" ) - r = this->_GD1< unsigned short, D >( ); - else if( tIt->second.second == "uint" ) - r = this->_GD1< unsigned int, D >( ); - else if( tIt->second.second == "ulong" ) - r = this->_GD1< unsigned long, D >( ); - else if( tIt->second.second == "float" ) - r = this->_GD1< float, D >( ); - else if( tIt->second.second == "double" ) - r = this->_GD1< double, D >( ); + vtkMarchingSquares* ms = vtkMarchingSquares::New( ); + ms->SetInputData( vtk_image ); + for( unsigned int i = 0; i < values.size( ); ++i ) + ms->SetValue( i, values[ i ] ); + this->m_Algorithm = ms; } - else if( cIt->second.second == "1" ) - { - if( tIt->second.second == "char" ) - r = this->_GD1< itk::RGBPixel< char >, D >( ); - else if( tIt->second.second == "short" ) - r = this->_GD1< itk::RGBPixel< short >, D >( ); - else if( tIt->second.second == "int" ) - r = this->_GD1< itk::RGBPixel< int >, D >( ); - else if( tIt->second.second == "long" ) - r = this->_GD1< itk::RGBPixel< long >, D >( ); - else if( tIt->second.second == "uchar" ) - r = this->_GD1< itk::RGBPixel< unsigned char >, D >( ); - else if( tIt->second.second == "ushort" ) - r = this->_GD1< itk::RGBPixel< unsigned short >, D >( ); - else if( tIt->second.second == "uint" ) - r = this->_GD1< itk::RGBPixel< unsigned int >, D >( ); - else if( tIt->second.second == "ulong" ) - r = this->_GD1< itk::RGBPixel< unsigned long >, D >( ); - else if( tIt->second.second == "float" ) - r = this->_GD1< itk::RGBPixel< float >, D >( ); - else if( tIt->second.second == "double" ) - r = this->_GD1< itk::RGBPixel< double >, D >( ); - } // fi - return( r ); -*/ -} - -// ------------------------------------------------------------------------- -template< class P, unsigned int D > -std::string cpPlugins::Plugins::MarchingCubes:: -_GD1( ) -{ - return( "" ); - /* TODO - TParameters::const_iterator fIt; - - // Get filename - fIt = this->m_Parameters.find( "FileName" ); - if( fIt == this->m_Parameters.end( ) ) - fIt = this->m_DefaultParameters.find( "FileName" ); - - typedef itk::Image< P, D > _TImage; - typedef itk::ImageFileReader< _TImage > _TReader; - - _TReader* reader = - dynamic_cast< _TReader* >( this->m_Reader.GetPointer( ) ); - if( reader == NULL ) + else if( vtk_image->GetDataDimension( ) == 3 ) { - this->m_Reader = _TReader::New( ); - reader = dynamic_cast< _TReader* >( this->m_Reader.GetPointer( ) ); - - } // fi - reader->SetFileName( fIt->second.second ); - try - { - reader->Update( ); + vtkMarchingCubes* mc = vtkMarchingCubes::New( ); + mc->SetInputData( vtk_image ); + for( unsigned int i = 0; i < values.size( ); ++i ) + mc->SetValue( i, values[ i ] ); + this->m_Algorithm = mc; } - catch( itk::ExceptionObject& err ) - { - return( err.GetDescription( ) ); - - } // yrt - this->_SetOutput( 0, reader->GetOutput( ) ); + else + return( "MarchingCubes: Input data does not have a valid dimension." ); + + // Execute filter + this->m_Algorithm->Update( ); + cpPlugins::Interface::Mesh* out = + this->_Output< cpPlugins::Interface::Mesh >( 0 ); + out->SetVTKMesh( this->m_Algorithm->GetOutput( ) ); return( "" ); -*/ } // eof - $RCSfile$