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->SetNumberOfInputs( 1 );
15 this->SetNumberOfOutputs( 1 );
16 this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 );
18 using namespace cpPlugins::Interface;
19 this->m_DefaultParameters.Configure( Parameters::RealList, "Thresholds" );
20 this->m_Parameters = this->m_DefaultParameters;
23 // -------------------------------------------------------------------------
24 cpPlugins::BasicFilters::MarchingCubes::
29 // -------------------------------------------------------------------------
30 std::string cpPlugins::BasicFilters::MarchingCubes::
34 cpPlugins::Interface::Image* image =
35 this->GetInput< cpPlugins::Interface::Image >( 0 );
37 return( "MarchingCubes: Input data is not a valid image." );
38 vtkImageData* vtk_image = image->GetVTK< vtkImageData >( );
39 if( vtk_image == NULL )
40 return( "MarchingCubes: Input does not have a valid VTK conversion." );
42 std::vector< double > values;
43 this->m_Parameters.GetValueAsRealList( values, "Thresholds" );
44 vtkPolyData* pd = NULL;
45 if( vtk_image->GetDataDimension( ) == 2 )
47 vtkMarchingSquares* ms = this->_CreateVTK< vtkMarchingSquares >( );
48 ms->SetInputData( vtk_image );
49 for( unsigned int i = 0; i < values.size( ); ++i )
50 ms->SetValue( i, values[ i ] );
52 pd = ms->GetOutput( );
54 else if( vtk_image->GetDataDimension( ) == 3 )
56 vtkMarchingCubes* mc = this->_CreateVTK< vtkMarchingCubes >( );
57 mc->ComputeNormalsOff( );
58 mc->SetInputData( vtk_image );
59 for( unsigned int i = 0; i < values.size( ); ++i )
60 mc->SetValue( i, values[ i ] );
62 pd = mc->GetOutput( );
65 return( "MarchingCubes: Input data does not have a valid dimension." );
68 cpPlugins::Interface::Mesh* out =
69 this->GetOutput< cpPlugins::Interface::Mesh >( 0 );