]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.cxx
Parameters are now part of the pipeline update process
[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->SetNumberOfInputs( 1 );
15   this->SetNumberOfOutputs( 1 );
16   this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 );
17
18   this->m_Parameters->ConfigureAsRealList( "Thresholds" );
19 }
20
21 // -------------------------------------------------------------------------
22 cpPlugins::BasicFilters::MarchingCubes::
23 ~MarchingCubes( )
24 {
25 }
26
27 // -------------------------------------------------------------------------
28 std::string cpPlugins::BasicFilters::MarchingCubes::
29 _GenerateData( )
30 {
31   // Get input
32   cpPlugins::Interface::Image* image =
33     this->GetInput< cpPlugins::Interface::Image >( 0 );
34   if( image == NULL )
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." );
39
40   std::vector< double > values;
41   this->m_Parameters->GetRealList( values, "Thresholds" );
42   vtkPolyData* pd = NULL;
43   if( vtk_image->GetDataDimension( ) == 2 )
44   {
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 ] );
49     ms->Update( );
50     pd = ms->GetOutput( );
51   }
52   else if( vtk_image->GetDataDimension( ) == 3 )
53   {
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 ] );
59     mc->Update( );
60     pd = mc->GetOutput( );
61   }
62   else
63     return( "MarchingCubes: Input data does not have a valid dimension." );
64
65   // Execute filter
66   cpPlugins::Interface::Mesh* out =
67     this->GetOutput< cpPlugins::Interface::Mesh >( 0 );
68   out->SetVTK( pd );
69   return( "" );
70 }
71
72 // eof - $RCSfile$