#include #include #include #include #include #include // ------------------------------------------------------------------------- cpPlugins::Plugins::MarchingCubes:: MarchingCubes( ) : Superclass( ), m_Algorithm( NULL ) { this->m_ClassName = "cpPlugins::MarchingCubes"; this->SetNumberOfInputs( 1 ); this->SetNumberOfOutputs( 1 ); this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 ); using namespace cpPlugins::Interface; this->m_DefaultParameters.Configure( Parameters::RealList, "Thresholds" ); this->m_Parameters = this->m_DefaultParameters; } // ------------------------------------------------------------------------- cpPlugins::Plugins::MarchingCubes:: ~MarchingCubes( ) { if( this->m_Algorithm != NULL ) this->m_Algorithm->Delete( ); } // ------------------------------------------------------------------------- std::string cpPlugins::Plugins::MarchingCubes:: _GenerateData( ) { // Get input cpPlugins::Interface::Image* input = dynamic_cast< cpPlugins::Interface::Image* >( this->m_Inputs[ 0 ].GetPointer( ) ); if( input == NULL ) return( "MarchingCubes: Input data is not a valid image." ); vtkImageData* vtk_input = dynamic_cast< vtkImageData* >( input->GetVTKDataObject( ) ); if( vtk_input == NULL ) return( "MarchingCubes: Input does not have a valid conversion to VTK." ); if( this->m_Algorithm != NULL ) this->m_Algorithm->Delete( ); std::vector< double > values; this->m_Parameters.GetValueAsRealList( values, "Thresholds" ); if( vtk_input->GetDataDimension( ) == 2 ) { vtkMarchingSquares* ms = vtkMarchingSquares::New( ); ms->SetInputData( vtk_input ); for( unsigned int i = 0; i < values.size( ); ++i ) ms->SetValue( i, values[ i ] ); this->m_Algorithm = ms; } else if( vtk_input->GetDataDimension( ) == 3 ) { vtkMarchingCubes* mc = vtkMarchingCubes::New( ); mc->SetInputData( vtk_input ); for( unsigned int i = 0; i < values.size( ); ++i ) mc->SetValue( i, values[ i ] ); this->m_Algorithm = mc; } else return( "MarchingCubes: Input data does not have a valid dimension." ); // Execute filter this->m_Algorithm->Update( ); this->m_Outputs[ 0 ]->SetVTKDataObject( this->m_Algorithm->GetOutput( ) ); return( "" ); } // eof - $RCSfile$