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 this->m_Parameters->ConfigureAsRealList( "Thresholds" );
21 // -------------------------------------------------------------------------
22 cpPlugins::BasicFilters::MarchingCubes::
27 // -------------------------------------------------------------------------
28 std::string cpPlugins::BasicFilters::MarchingCubes::
32 cpPlugins::Interface::Image* image =
33 this->GetInput< cpPlugins::Interface::Image >( 0 );
35 return( "MarchingCubes: Input data is not a valid image." );
36 vtkImageData* vtk_image = image->GetVTK< vtkImageData >( );
37 if( vtk_image == NULL )
38 return( "MarchingCubes: Input does not have a valid VTK conversion." );
40 std::vector< double > values;
41 this->m_Parameters->GetRealList( values, "Thresholds" );
42 vtkPolyData* pd = NULL;
43 if( vtk_image->GetDataDimension( ) == 2 )
45 vtkMarchingSquares* ms = this->_CreateVTK< vtkMarchingSquares >( );
46 ms->SetInputData( vtk_image );
47 for( unsigned int i = 0; i < values.size( ); ++i )
48 ms->SetValue( i, values[ i ] );
50 pd = ms->GetOutput( );
52 else if( vtk_image->GetDataDimension( ) == 3 )
54 vtkMarchingCubes* mc = this->_CreateVTK< vtkMarchingCubes >( );
55 mc->ComputeNormalsOff( );
56 mc->SetInputData( vtk_image );
57 for( unsigned int i = 0; i < values.size( ); ++i )
58 mc->SetValue( i, values[ i ] );
60 pd = mc->GetOutput( );
63 return( "MarchingCubes: Input data does not have a valid dimension." );
66 cpPlugins::Interface::Mesh* out =
67 this->GetOutput< cpPlugins::Interface::Mesh >( 0 );