1 #include <cpPlugins/Plugins/MarchingCubes.h>
2 #include <cpPlugins/Interface/Image.h>
3 #include <cpPlugins/Interface/Mesh.h>
5 #include <vtkImageData.h>
6 #include <vtkMarchingCubes.h>
7 #include <vtkMarchingSquares.h>
9 // -------------------------------------------------------------------------
10 cpPlugins::Plugins::MarchingCubes::
15 this->m_ClassName = "cpPlugins::MarchingCubes";
17 this->SetNumberOfInputs( 1 );
18 this->SetNumberOfOutputs( 1 );
19 this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 );
21 using namespace cpPlugins::Interface;
22 this->m_DefaultParameters.Configure( Parameters::RealList, "Thresholds" );
23 this->m_Parameters = this->m_DefaultParameters;
26 // -------------------------------------------------------------------------
27 cpPlugins::Plugins::MarchingCubes::
30 if( this->m_Algorithm != NULL )
31 this->m_Algorithm->Delete( );
34 // -------------------------------------------------------------------------
35 std::string cpPlugins::Plugins::MarchingCubes::
39 cpPlugins::Interface::Image* input =
40 dynamic_cast< cpPlugins::Interface::Image* >(
41 this->m_Inputs[ 0 ].GetPointer( )
44 return( "MarchingCubes: Input data is not a valid image." );
45 vtkImageData* vtk_input =
46 dynamic_cast< vtkImageData* >( input->GetVTKDataObject( ) );
47 if( vtk_input == NULL )
48 return( "MarchingCubes: Input does not have a valid conversion to VTK." );
50 if( this->m_Algorithm != NULL )
51 this->m_Algorithm->Delete( );
53 std::vector< double > values;
54 this->m_Parameters.GetValueAsRealList( values, "Thresholds" );
55 if( vtk_input->GetDataDimension( ) == 2 )
57 vtkMarchingSquares* ms = vtkMarchingSquares::New( );
58 ms->SetInputData( vtk_input );
59 for( unsigned int i = 0; i < values.size( ); ++i )
60 ms->SetValue( i, values[ i ] );
61 this->m_Algorithm = ms;
63 else if( vtk_input->GetDataDimension( ) == 3 )
65 vtkMarchingCubes* mc = vtkMarchingCubes::New( );
66 mc->SetInputData( vtk_input );
67 for( unsigned int i = 0; i < values.size( ); ++i )
68 mc->SetValue( i, values[ i ] );
69 this->m_Algorithm = mc;
72 return( "MarchingCubes: Input data does not have a valid dimension." );
75 this->m_Algorithm->Update( );
76 this->m_Outputs[ 0 ]->SetVTKDataObject( this->m_Algorithm->GetOutput( ) );