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";
16 this->m_ClassCategory = "ImageToMeshFilter";
18 this->SetNumberOfInputs( 1 );
19 this->SetNumberOfOutputs( 1 );
20 this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 );
22 using namespace cpPlugins::Interface;
23 this->m_DefaultParameters.Configure( Parameters::RealList, "Thresholds" );
24 this->m_Parameters = this->m_DefaultParameters;
27 // -------------------------------------------------------------------------
28 cpPlugins::Plugins::MarchingCubes::
31 if( this->m_Algorithm != NULL )
32 this->m_Algorithm->Delete( );
35 // -------------------------------------------------------------------------
36 std::string cpPlugins::Plugins::MarchingCubes::
40 cpPlugins::Interface::Image* image =
41 this->_Input< cpPlugins::Interface::Image >( 0 );
43 return( "MarchingCubes: Input data is not a valid image." );
44 vtkImageData* vtk_image = image->GetVTKImageData( );
45 if( vtk_image == NULL )
46 return( "MarchingCubes: Input does not have a valid VTK conversion." );
48 if( this->m_Algorithm != NULL )
49 this->m_Algorithm->Delete( );
51 std::vector< double > values;
52 this->m_Parameters.GetValueAsRealList( values, "Thresholds" );
53 if( vtk_image->GetDataDimension( ) == 2 )
55 vtkMarchingSquares* ms = vtkMarchingSquares::New( );
56 ms->SetInputData( vtk_image );
57 for( unsigned int i = 0; i < values.size( ); ++i )
58 ms->SetValue( i, values[ i ] );
59 this->m_Algorithm = ms;
61 else if( vtk_image->GetDataDimension( ) == 3 )
63 vtkMarchingCubes* mc = vtkMarchingCubes::New( );
64 mc->SetInputData( vtk_image );
65 for( unsigned int i = 0; i < values.size( ); ++i )
66 mc->SetValue( i, values[ i ] );
67 this->m_Algorithm = mc;
70 return( "MarchingCubes: Input data does not have a valid dimension." );
73 this->m_Algorithm->Update( );
74 cpPlugins::Interface::Mesh* out =
75 this->_Output< cpPlugins::Interface::Mesh >( 0 );
76 out->SetVTKMesh( this->m_Algorithm->GetOutput( ) );