]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.cxx
Widget integration (step 2/6). WARNING: IT DOES NOT COMPILE YETgit shortlog !
[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     m_Algorithm( NULL )
14 {
15   this->m_ClassName = "cpPlugins::BasicFilters::MarchingCubes";
16   this->m_ClassCategory = "ImageToMeshFilter";
17
18   this->SetNumberOfInputs( 1 );
19   this->SetNumberOfOutputs( 1 );
20   this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 );
21
22   using namespace cpPlugins::Interface;
23   this->m_DefaultParameters.Configure( Parameters::RealList, "Thresholds" );
24   this->m_Parameters = this->m_DefaultParameters;
25 }
26
27 // -------------------------------------------------------------------------
28 cpPlugins::BasicFilters::MarchingCubes::
29 ~MarchingCubes( )
30 {
31   if( this->m_Algorithm != NULL )
32     this->m_Algorithm->Delete( );
33 }
34
35 // -------------------------------------------------------------------------
36 std::string cpPlugins::BasicFilters::MarchingCubes::
37 _GenerateData( )
38 {
39   // Get input
40   cpPlugins::Interface::Image* image =
41     this->GetInput< cpPlugins::Interface::Image >( 0 );
42   if( image == NULL )
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." );
47
48   if( this->m_Algorithm != NULL )
49     this->m_Algorithm->Delete( );
50
51   std::vector< double > values;
52   this->m_Parameters.GetValueAsRealList( values, "Thresholds" );
53   if( vtk_image->GetDataDimension( ) == 2 )
54   {
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;
60   }
61   else if( vtk_image->GetDataDimension( ) == 3 )
62   {
63     vtkMarchingCubes* mc = vtkMarchingCubes::New( );
64     mc->ComputeNormalsOff( );
65     mc->SetInputData( vtk_image );
66     for( unsigned int i = 0; i < values.size( ); ++i )
67       mc->SetValue( i, values[ i ] );
68     this->m_Algorithm = mc;
69   }
70   else
71     return( "MarchingCubes: Input data does not have a valid dimension." );
72
73   // Execute filter
74   this->m_Algorithm->Update( );
75   cpPlugins::Interface::Mesh* out =
76     this->GetOutput< cpPlugins::Interface::Mesh >( 0 );
77   out->SetVTKMesh( this->m_Algorithm->GetOutput( ) );
78   return( "" );
79 }
80
81 // eof - $RCSfile$