1 #include "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::BasicFilters::MarchingCubes::
14 this->_AddInput( "Input" );
15 this->_AddOutput< cpPlugins::Interface::Mesh >( "Output" );
17 this->m_Parameters->ConfigureAsRealList( "Thresholds" );
20 // -------------------------------------------------------------------------
21 cpPlugins::BasicFilters::MarchingCubes::
26 // -------------------------------------------------------------------------
27 std::string cpPlugins::BasicFilters::MarchingCubes::
31 auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" );
32 vtkImageData* vtk_image = image->GetVTK< vtkImageData >( );
33 if( vtk_image == NULL )
34 return( "MarchingCubes: Input does not have a valid VTK conversion." );
36 std::vector< double > values =
37 this->m_Parameters->GetRealList( "Thresholds" );
38 vtkPolyData* pd = NULL;
39 if( vtk_image->GetDataDimension( ) == 2 )
41 vtkMarchingSquares* ms = this->_CreateVTK< vtkMarchingSquares >( );
42 ms->SetInputData( vtk_image );
43 for( unsigned int i = 0; i < values.size( ); ++i )
44 ms->SetValue( i, values[ i ] );
46 pd = ms->GetOutput( );
48 else if( vtk_image->GetDataDimension( ) == 3 )
50 vtkMarchingCubes* mc = this->_CreateVTK< vtkMarchingCubes >( );
51 mc->ComputeNormalsOff( );
52 mc->SetInputData( vtk_image );
53 for( unsigned int i = 0; i < values.size( ); ++i )
54 mc->SetValue( i, values[ i ] );
56 pd = mc->GetOutput( );
59 return( "MarchingCubes: Input data does not have a valid dimension." );
62 auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" );