]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.cxx
...
[cpPlugins.git] / lib / cpPlugins / Plugins / BasicFilters / MarchingCubes.cxx
1 #include "MarchingCubes.h"
2 #include <cpPlugins/Interface/Image.h>
3 #include <cpPlugins/Interface/Mesh.h>
4
5 #include <vtkImageData.h>
6 #include <vtkMarchingCubes.h>
7 #include <vtkMarchingSquares.h>
8
9 // -------------------------------------------------------------------------
10 cpPlugins::BasicFilters::MarchingCubes::
11 MarchingCubes( )
12   : Superclass( )
13 {
14   this->_AddInput( "Input" );
15   this->_AddOutput< cpPlugins::Interface::Mesh >( "Output" );
16
17   this->m_Parameters->ConfigureAsRealList( "Thresholds" );
18 }
19
20 // -------------------------------------------------------------------------
21 cpPlugins::BasicFilters::MarchingCubes::
22 ~MarchingCubes( )
23 {
24 }
25
26 // -------------------------------------------------------------------------
27 std::string cpPlugins::BasicFilters::MarchingCubes::
28 _GenerateData( )
29 {
30   // Get input
31   auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" );
32   if( image == NULL )
33     return( "MarchingCubes: Input data is not a valid image." );
34   vtkImageData* vtk_image = image->GetVTK< vtkImageData >( );
35   if( vtk_image == NULL )
36     return( "MarchingCubes: Input does not have a valid VTK conversion." );
37
38   std::vector< double > values =
39     this->m_Parameters->GetRealList( "Thresholds" );
40   vtkPolyData* pd = NULL;
41   if( vtk_image->GetDataDimension( ) == 2 )
42   {
43     vtkMarchingSquares* ms = this->_CreateVTK< vtkMarchingSquares >( );
44     ms->SetInputData( vtk_image );
45     for( unsigned int i = 0; i < values.size( ); ++i )
46       ms->SetValue( i, values[ i ] );
47     ms->Update( );
48     pd = ms->GetOutput( );
49   }
50   else if( vtk_image->GetDataDimension( ) == 3 )
51   {
52     vtkMarchingCubes* mc = this->_CreateVTK< vtkMarchingCubes >( );
53     mc->ComputeNormalsOff( );
54     mc->SetInputData( vtk_image );
55     for( unsigned int i = 0; i < values.size( ); ++i )
56       mc->SetValue( i, values[ i ] );
57     mc->Update( );
58     pd = mc->GetOutput( );
59   }
60   else
61     return( "MarchingCubes: Input data does not have a valid dimension." );
62
63   // Execute filter
64   auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" );
65   out->SetVTK( pd );
66   return( "" );
67 }
68
69 // eof - $RCSfile$