]> Creatis software - cpPlugins.git/blobdiff - plugins/ImageMeshFilters/RasterMeshFilter.cxx
Raster filter updated. LUT image visualization strange bug :-(
[cpPlugins.git] / plugins / ImageMeshFilters / RasterMeshFilter.cxx
index f2ac07ffc53dc0858133c35bc2c93aca6a89ff44..4124cb1232db6b88ab851a75bedcbc062460f401 100644 (file)
@@ -1,15 +1,12 @@
 #include <plugins/ImageMeshFilters/RasterMeshFilter.h>
 #include <cpPlugins/DataObjects/BoundingBox.h>
 #include <cpPlugins/DataObjects/Mesh.h>
-
-#include <vtkImageData.h>
-#include <vtkImageStencil.h>
-#include <vtkLinearExtrusionFilter.h>
-#include <vtkPolyDataToImageStencil.h>
-#include <vtkStripper.h>
+#include <cpPlugins_ImageIterators.h>
 
 #include <itkTriangleMeshToBinaryImageFilter.h>
+#include <cpExtensions/Algorithms/RasterContourFilter.h>
 #include <itkTriangleMeshToBinaryImageFilter.hxx>
+#include <cpExtensions/Algorithms/RasterContourFilter.hxx>
 
 // -------------------------------------------------------------------------
 cpPluginsImageMeshFilters::RasterMeshFilter::
@@ -72,125 +69,24 @@ template< class _TMesh >
 void cpPluginsImageMeshFilters::RasterMeshFilter::
 _GD0_2D( _TMesh* mesh )
 {
+  typedef unsigned char _TPixel;
   typedef itk::ImageBase< 2 > _TImageBase;
-  typedef itk::Image< unsigned char, 2 > _TImage;
-  typedef cpPlugins::DataObjects::BoundingBox _TBB;
-  typedef typename _TImage::PointType _TPoint;
+  typedef itk::Image< _TPixel, 2 > _TImage;
+  typedef cpExtensions::Algorithms::RasterContourFilter< _TImage > _TFilter;
 
-  static const unsigned int PAD = 10;
-
-  _TImage::Pointer white = this->GetOutputData< _TImage >( "Output" );
-  if( white.IsNull( ) )
-    white = _TImage::New( );
-
-  // Get configuration values
-  typename _TImage::SpacingType spac;
-  typename _TImage::SizeType size;
-  typename _TImage::PointType origin;
-  typename _TImage::DirectionType direction;
-  typename _TImage::IndexType index;
-
-  auto in_bb = this->GetInput< _TBB >( "Template" );
   auto in_im = this->GetInputData< _TImageBase >( "Template" );
-  if( in_im != NULL )
-  {
-    spac = in_im->GetSpacing( );
-    size = in_im->GetLargestPossibleRegion( ).GetSize( );
-    origin = in_im->GetOrigin( );
-    direction = in_im->GetDirection( );
-    index = in_im->GetLargestPossibleRegion( ).GetIndex( );
-  }
-  else
-  {
-    _TPoint minBB, maxBB;
-    if( in_bb != NULL )
-    {
-      minBB = in_bb->GetMinimum< _TPoint >( );
-      maxBB = in_bb->GetMaximum< _TPoint >( );
-    }
-    else
-    {
-      double bounds[ 6 ];
-      mesh->GetBounds( bounds );
-      minBB[ 0 ] = bounds[ 0 ];
-      minBB[ 1 ] = bounds[ 1 ];
-      maxBB[ 0 ] = bounds[ 2 ];
-      maxBB[ 1 ] = bounds[ 3 ];
-
-    } // fi
-
-    double lx = double( maxBB[ 0 ] - minBB[ 0 ] );
-    double ly = double( maxBB[ 1 ] - minBB[ 1 ] );
-    double lm = ( lx < ly )? lx: ly;
-
-    // Compute spacing
-    spac.Fill( lm / double( this->m_Parameters.GetUint( "MinimumSize" ) ) );
-
-    // Compute size
-    size[ 0 ] = ( unsigned long )( std::ceil( lx / spac[ 0 ] ) );
-    size[ 1 ] = ( unsigned long )( std::ceil( ly / spac[ 1 ] ) );
-
-    // ... add some padding pixels
-    size[ 0 ] += PAD;
-    size[ 1 ] += PAD;
-
-    // Set origin
-    origin = minBB;
-    origin[ 0 ] -= double( PAD >> 1 ) * spac[ 0 ];
-    origin[ 1 ] -= double( PAD >> 1 ) * spac[ 1 ];
-
-    // Remaining values
-    direction.SetIdentity( );
-    index.Fill( 0 );
-
-  } // fi
-
-  // Configure output image
-  _TImage::RegionType region;
-  region.SetSize( size );
-  region.SetIndex( index );
-  white->SetSpacing( spac );
-  white->SetRegions( region );
-  white->SetOrigin( origin );
-  white->SetDirection( direction );
-  white->Allocate( );
-  white->FillBuffer( this->m_Parameters.GetUint( "InsideValue" ) );
-  if( this->m_WhiteImage.IsNull( ) )
-    this->m_WhiteImage = TImage::New( );
-  this->m_WhiteImage->SetITK( white );
-  vtkImageData* white_vtk = this->m_WhiteImage->GetVTK< vtkImageData >( );
-
-  // Configure mini-pipeline
-  if( this->m_Stripper.GetPointer( ) == NULL )
-    this->m_Stripper = vtkSmartPointer< vtkStripper >::New( );
-  this->m_Stripper->SetInputData( mesh );
-  this->m_Stripper->Update( );
-
-  if( this->m_Extruder.GetPointer( ) == NULL )
-    this->m_Extruder = vtkSmartPointer< vtkLinearExtrusionFilter >::New( );
-  this->m_Extruder->SetInputConnection( this->m_Stripper->GetOutputPort( ) );
-  this->m_Extruder->SetScaleFactor( double( 1 ) );
-  this->m_Extruder->SetExtrusionTypeToNormalExtrusion( );
-  this->m_Extruder->SetVector( 0, 0, 1 );
-  this->m_Extruder->Update( );
-
-  if( this->m_PolyDataToStencil.GetPointer( ) == NULL )
-    this->m_PolyDataToStencil =
-      vtkSmartPointer< vtkPolyDataToImageStencil >::New( );
-  this->m_PolyDataToStencil->SetTolerance( 0 );
-  this->m_PolyDataToStencil->SetInputConnection( this->m_Extruder->GetOutputPort( ) );
-  this->m_PolyDataToStencil->SetOutputOrigin( white_vtk->GetOrigin( ) );
-  this->m_PolyDataToStencil->SetOutputSpacing( white_vtk->GetSpacing( ) );
-  this->m_PolyDataToStencil->SetOutputWholeExtent( white_vtk->GetExtent( ) );
-  this->m_PolyDataToStencil->Update( );
-
-  this->m_ImageStencil = this->_CreateVTK< vtkImageStencil >( );
-  this->m_ImageStencil->SetInputData( white_vtk );
-  this->m_ImageStencil->SetStencilConnection( this->m_PolyDataToStencil->GetOutputPort( ) );
-  this->m_ImageStencil->ReverseStencilOff( );
-  this->m_ImageStencil->SetBackgroundValue( this->m_Parameters.GetUint( "OutsideValue" ) );
-  this->m_ImageStencil->Update( );
-  this->GetOutput( "Output" )->SetVTK( this->m_ImageStencil->GetOutput( ) );
+  if( in_im == NULL )
+    this->_Error( "A template is needed for 2D raster (this is temporal)." );
+  _TPixel inside = _TPixel( this->m_Parameters.GetUint( "InsideValue" ) );
+  _TPixel outside = _TPixel( this->m_Parameters.GetUint( "OutsideValue" ) );
+
+  auto filter = this->_CreateITK< _TFilter >( );
+  filter->AddPoints( mesh->GetPoints( ) );
+  filter->SetTemplate( in_im );
+  filter->SetInsideValue( inside );
+  filter->SetOutsideValue( outside );
+  filter->Update( );
+  this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
 }
 
 // -------------------------------------------------------------------------
@@ -208,11 +104,6 @@ _GD0_3D( _TMesh* mesh )
   static const unsigned int PAD = 10;
 
   _TFilter* filter = this->_CreateITK< _TFilter >( );
-  this->m_WhiteImage = NULL;
-  this->m_Stripper = NULL;
-  this->m_Extruder = NULL;
-  this->m_PolyDataToStencil = NULL;
-  this->m_ImageStencil = NULL;
 
   // Get configuration values
   typename _TImage::SpacingType spac;