]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Algorithms/SpatialObjectMaskImageFilter.hxx
...
[cpPlugins.git] / lib / cpExtensions / Algorithms / SpatialObjectMaskImageFilter.hxx
index 2df9c6f652848afef28af4b596abbb5c92911267..2c3cac73f33b2fdbd39d060dd5d5d036a0df1e11 100644 (file)
@@ -4,6 +4,38 @@
 #include <itkImageScanlineIterator.h>
 #include <itkProgressReporter.h>
 
+// -------------------------------------------------------------------------
+template< class I, class O >
+O* cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
+GetPositiveOutput( )
+{
+  return( this->GetOutput( 0 ) );
+}
+
+// -------------------------------------------------------------------------
+template< class I, class O >
+const O* cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
+GetPositiveOutput( ) const
+{
+  return( this->GetOutput( 0 ) );
+}
+
+// -------------------------------------------------------------------------
+template< class I, class O >
+O* cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
+GetNegativeOutput( )
+{
+  return( this->GetOutput( 1 ) );
+}
+
+// -------------------------------------------------------------------------
+template< class I, class O >
+const O* cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
+GetNegativeOutput( ) const
+{
+  return( this->GetOutput( 1 ) );
+}
+
 // -------------------------------------------------------------------------
 template< class I, class O >
 cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
@@ -11,7 +43,9 @@ SpatialObjectMaskImageFilter( )
   : Superclass( )
 {
   this->SetNumberOfRequiredInputs( 1 );
-  this->InPlaceOff( );
+  this->SetNumberOfRequiredOutputs( 2 );
+  this->SetNthOutput( 0, O::New( ) );
+  this->SetNthOutput( 1, O::New( ) );
 }
 
 // -------------------------------------------------------------------------
@@ -52,7 +86,8 @@ ThreadedGenerateData( const TRegion& region, itk::ThreadIdType threadId )
   // Get inputs
   const I* in =
     dynamic_cast< const I* >( this->itk::ProcessObject::GetInput( 0 ) );
-  O* out = this->GetOutput( 0 );
+  O* pos_out = this->GetPositiveOutput( );
+  O* neg_out = this->GetNegativeOutput( );
   const auto size0 = region.GetSize( 0 );
   if( size0 == 0 )
     return;
@@ -60,7 +95,8 @@ ThreadedGenerateData( const TRegion& region, itk::ThreadIdType threadId )
 
   // Create iterators
   itk::ImageScanlineConstIterator< I > iIt( in, region );
-  itk::ImageScanlineIterator< O > oIt( out, region );
+  itk::ImageScanlineIterator< O > pos_oIt( pos_out, region );
+  itk::ImageScanlineIterator< O > neg_oIt( neg_out, region );
   itk::ProgressReporter progress( this, threadId, nLines );
 
   // Main loop
@@ -72,15 +108,24 @@ ThreadedGenerateData( const TRegion& region, itk::ThreadIdType threadId )
       auto idx = iIt.GetIndex( );
       in->TransformIndexToPhysicalPoint( idx, pnt );
       if( this->m_SpatialObject->IsInside( pnt ) )
-        oIt.Set( TOutPixel( iIt.Get( ) ) );
+      {
+        pos_oIt.Set( TOutPixel( iIt.Get( ) ) );
+        neg_oIt.Set( this->m_OutsideValue );
+      }
       else
-        oIt.Set( this->m_OutsideValue );
+      {
+        neg_oIt.Set( TOutPixel( iIt.Get( ) ) );
+        pos_oIt.Set( this->m_OutsideValue );
+
+      } // fi
       ++iIt;
-      ++oIt;
+      ++pos_oIt;
+      ++neg_oIt;
 
     } // elihw
     iIt.NextLine( );
-    oIt.NextLine( );
+    pos_oIt.NextLine( );
+    neg_oIt.NextLine( );
     progress.CompletedPixel( );
 
   } // elihw