]> Creatis software - cpPlugins.git/blobdiff - plugins/cpPluginsImageMeshFilters/TriangleMeshToBinaryImageFilter.cxx
Bug smashed like a boss
[cpPlugins.git] / plugins / cpPluginsImageMeshFilters / TriangleMeshToBinaryImageFilter.cxx
index 11bb178f137ff6fd93985d5adebb4a6bff0734a9..c2442a690047f6d7b6c9fe43bf86e7b6a9682420 100644 (file)
@@ -1,4 +1,5 @@
 #include <cpPluginsImageMeshFilters/TriangleMeshToBinaryImageFilter.h>
+#include <cpPlugins/BoundingBox.h>
 #include <cpPlugins/Image.h>
 #include <cpPlugins/Mesh.h>
 
@@ -10,6 +11,7 @@ TriangleMeshToBinaryImageFilter( )
   : Superclass( )
 {
   this->_AddInput( "Input" );
+  this->_AddInput( "BoundingBox", false );
   this->_AddOutput< cpPlugins::Image >( "Output" );
 
   this->m_Parameters.ConfigureAsUint( "InsideValue" );
@@ -28,43 +30,55 @@ cpPluginsImageMeshFilters::TriangleMeshToBinaryImageFilter::
 }
 
 // -------------------------------------------------------------------------
-std::string cpPluginsImageMeshFilters::TriangleMeshToBinaryImageFilter::
+void cpPluginsImageMeshFilters::TriangleMeshToBinaryImageFilter::
 _GenerateData( )
 {
   typedef itk::Mesh< float, 3 >  _3F;
   typedef itk::Mesh< double, 3 > _3D;
 
-  auto _3f = this->GetInputData( "Input" )->GetITK< _3F >( );
-  auto _3d = this->GetInputData( "Input" )->GetITK< _3D >( );
-  if     ( _3f != NULL ) return( this->_GD0( _3f ) );
-  else if( _3d != NULL ) return( this->_GD0( _3d ) );
-  else
-    return( "TriangleMeshToBinaryImageFilter: No valid input itk mesh." );
+  auto _3f = this->GetInputData< _3F >( "Input" );
+  auto _3d = this->GetInputData< _3D >( "Input" );
+  if     ( _3f != NULL ) this->_GD0( _3f );
+  else if( _3d != NULL ) this->_GD0( _3d );
+  else this->_Error( "No valid input mesh." );
 }
 
 // -------------------------------------------------------------------------
 template< class _TMesh >
-std::string cpPluginsImageMeshFilters::TriangleMeshToBinaryImageFilter::
+void cpPluginsImageMeshFilters::TriangleMeshToBinaryImageFilter::
 _GD0( _TMesh* mesh )
 {
-  return( this->_GD1< _TMesh, unsigned char >( mesh ) );
+  this->_GD1< _TMesh, unsigned char >( mesh );
 }
 
 // -------------------------------------------------------------------------
 template< class _TMesh, class _TPixel >
-std::string cpPluginsImageMeshFilters::TriangleMeshToBinaryImageFilter::
+void cpPluginsImageMeshFilters::TriangleMeshToBinaryImageFilter::
 _GD1( _TMesh* mesh )
 {
+  typedef cpPlugins::BoundingBox _TBB;
   typedef itk::Image< _TPixel, _TMesh::PointDimension > _TImage;
   typedef itk::TriangleMeshToBinaryImageFilter< _TMesh, _TImage > _TFilter;
+  typedef typename _TImage::PointType _TPoint;
 
   static const unsigned int PAD = 10;
 
   _TFilter* filter = this->_CreateITK< _TFilter >( );
 
-  auto bb = mesh->GetBoundingBox( );
-  auto minBB = bb->GetMinimum( );
-  auto maxBB = bb->GetMaximum( );
+  auto in_bb = dynamic_cast< _TBB* >( this->GetInput( "BoundingBox" ) );
+  _TPoint minBB, maxBB;
+  if( in_bb == NULL )
+  {
+    auto bb = mesh->GetBoundingBox( );
+    minBB = bb->GetMinimum( );
+    maxBB = bb->GetMaximum( );
+  }
+  else
+  {
+    minBB = in_bb->GetMinimum< _TPoint >( );
+    maxBB = in_bb->GetMaximum< _TPoint >( );
+
+  } // fi
 
   double lx = double( maxBB[ 0 ] - minBB[ 0 ] );
   double ly = double( maxBB[ 1 ] - minBB[ 1 ] );
@@ -113,10 +127,7 @@ _GD1( _TMesh* mesh )
   filter->Update( );
 
   // Connect output
-  auto out = this->GetOutputData( "Output" );
-  out->SetITK( filter->GetOutput( ) );
-  return( "" );
-
+  this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
 }
 
 // eof - $RCSfile$