]> Creatis software - cpPlugins.git/blobdiff - plugins/ImageMeshFilters/MarchingCubes.cxx
Code cleaning
[cpPlugins.git] / plugins / ImageMeshFilters / MarchingCubes.cxx
diff --git a/plugins/ImageMeshFilters/MarchingCubes.cxx b/plugins/ImageMeshFilters/MarchingCubes.cxx
new file mode 100644 (file)
index 0000000..81efbe0
--- /dev/null
@@ -0,0 +1,64 @@
+#include <plugins/ImageMeshFilters/MarchingCubes.h>
+#include <cpPlugins/Image.h>
+#include <cpPlugins/Mesh.h>
+
+#include <vtkImageData.h>
+#include <vtkMarchingCubes.h>
+#include <vtkMarchingSquares.h>
+
+// -------------------------------------------------------------------------
+cpPluginsImageMeshFilters::MarchingCubes::
+MarchingCubes( )
+  : Superclass( )
+{
+  this->_AddInput( "Input" );
+  this->_AddOutput< cpPlugins::Mesh >( "Output" );
+  this->m_Parameters.ConfigureAsRealList( "Thresholds" );
+}
+
+// -------------------------------------------------------------------------
+cpPluginsImageMeshFilters::MarchingCubes::
+~MarchingCubes( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsImageMeshFilters::MarchingCubes::
+_GenerateData( )
+{
+  // Get input
+  auto image = this->GetInput( "Input" );
+  vtkImageData* vtk_image = image->GetVTK< vtkImageData >( );
+  if( vtk_image == NULL )
+    this->_Error( "Input does not have a valid VTK conversion." );
+
+  std::vector< double > values =
+    this->m_Parameters.GetRealList( "Thresholds" );
+  vtkPolyData* pd = NULL;
+  if( vtk_image->GetDataDimension( ) == 2 )
+  {
+    vtkMarchingSquares* ms = this->_CreateVTK< vtkMarchingSquares >( );
+    ms->SetInputData( vtk_image );
+    for( unsigned int i = 0; i < values.size( ); ++i )
+      ms->SetValue( i, values[ i ] );
+    ms->Update( );
+    pd = ms->GetOutput( );
+  }
+  else if( vtk_image->GetDataDimension( ) == 3 )
+  {
+    vtkMarchingCubes* mc = this->_CreateVTK< vtkMarchingCubes >( );
+    mc->ComputeNormalsOff( );
+    mc->SetInputData( vtk_image );
+    for( unsigned int i = 0; i < values.size( ); ++i )
+      mc->SetValue( i, values[ i ] );
+    mc->Update( );
+    pd = mc->GetOutput( );
+  }
+  else
+    this->_Error( "Input data does not have a valid dimension." );
+
+  // Connect output
+  this->GetOutput( "Output" )->SetVTK( pd );
+}
+
+// eof - $RCSfile$