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 cpPlugins::Interface::Image* image =
32 this->GetInput< cpPlugins::Interface::Image >( "Input" );
34 return( "MarchingCubes: Input data is not a valid image." );
35 vtkImageData* vtk_image = image->GetVTK< vtkImageData >( );
36 if( vtk_image == NULL )
37 return( "MarchingCubes: Input does not have a valid VTK conversion." );
39 std::vector< double > values =
40 this->m_Parameters->GetRealList( "Thresholds" );
41 vtkPolyData* pd = NULL;
42 if( vtk_image->GetDataDimension( ) == 2 )
44 vtkMarchingSquares* ms = this->_CreateVTK< vtkMarchingSquares >( );
45 ms->SetInputData( vtk_image );
46 for( unsigned int i = 0; i < values.size( ); ++i )
47 ms->SetValue( i, values[ i ] );
49 pd = ms->GetOutput( );
51 else if( vtk_image->GetDataDimension( ) == 3 )
53 vtkMarchingCubes* mc = this->_CreateVTK< vtkMarchingCubes >( );
54 mc->ComputeNormalsOff( );
55 mc->SetInputData( vtk_image );
56 for( unsigned int i = 0; i < values.size( ); ++i )
57 mc->SetValue( i, values[ i ] );
59 pd = mc->GetOutput( );
62 return( "MarchingCubes: Input data does not have a valid dimension." );
65 cpPlugins::Interface::Mesh* out =
66 this->GetOutput< cpPlugins::Interface::Mesh >( "Output" );