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* image =
40 this->_Input< cpPlugins::Interface::Image >( 0 );
42 return( "MarchingCubes: Input data is not a valid image." );
43 vtkImageData* vtk_image = image->GetVTKImageData( );
44 if( vtk_image == NULL )
45 return( "MarchingCubes: Input does not have a valid VTK conversion." );
47 if( this->m_Algorithm != NULL )
48 this->m_Algorithm->Delete( );
50 std::vector< double > values;
51 this->m_Parameters.GetValueAsRealList( values, "Thresholds" );
52 if( vtk_image->GetDataDimension( ) == 2 )
54 vtkMarchingSquares* ms = vtkMarchingSquares::New( );
55 ms->SetInputData( vtk_image );
56 for( unsigned int i = 0; i < values.size( ); ++i )
57 ms->SetValue( i, values[ i ] );
58 this->m_Algorithm = ms;
60 else if( vtk_image->GetDataDimension( ) == 3 )
62 vtkMarchingCubes* mc = vtkMarchingCubes::New( );
63 mc->SetInputData( vtk_image );
64 for( unsigned int i = 0; i < values.size( ); ++i )
65 mc->SetValue( i, values[ i ] );
66 this->m_Algorithm = mc;
69 return( "MarchingCubes: Input data does not have a valid dimension." );
72 this->m_Algorithm->Update( );
73 cpPlugins::Interface::Mesh* out =
74 this->_Output< cpPlugins::Interface::Mesh >( 0 );
75 out->SetVTKMesh( this->m_Algorithm->GetOutput( ) );