1 #ifndef __CPEXTENSIONS__ALGORITHMS__SPATIALOBJECTMASKIMAGEFILTER__HXX__
2 #define __CPEXTENSIONS__ALGORITHMS__SPATIALOBJECTMASKIMAGEFILTER__HXX__
4 #include <itkImageScanlineIterator.h>
5 #include <itkProgressReporter.h>
7 // -------------------------------------------------------------------------
8 template< class I, class O >
9 cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
10 SpatialObjectMaskImageFilter( )
13 this->SetNumberOfRequiredInputs( 1 );
17 // -------------------------------------------------------------------------
18 template< class I, class O >
19 cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
20 ~SpatialObjectMaskImageFilter( )
24 // -------------------------------------------------------------------------
25 template< class I, class O >
26 void cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
27 GenerateOutputInformation( )
30 dynamic_cast< const I* >( this->itk::ProcessObject::GetInput( 0 ) );
31 for( unsigned int idx = 0; idx < this->GetNumberOfOutputs( ); ++idx )
33 itk::DataObject* out = this->GetOutput( idx );
35 out->CopyInformation( in );
40 // -------------------------------------------------------------------------
41 template< class I, class O >
42 void cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
43 ThreadedGenerateData( const TRegion& region, itk::ThreadIdType threadId )
45 if( this->m_SpatialObject.IsNull( ) )
47 itkGenericExceptionMacro( << "No itk::SpatialObject given." );
54 dynamic_cast< const I* >( this->itk::ProcessObject::GetInput( 0 ) );
55 O* out = this->GetOutput( 0 );
56 const auto size0 = region.GetSize( 0 );
59 const auto nLines = region.GetNumberOfPixels( ) / size0;
62 itk::ImageScanlineConstIterator< I > iIt( in, region );
63 itk::ImageScanlineIterator< O > oIt( out, region );
64 itk::ProgressReporter progress( this, threadId, nLines );
67 typename TSpatialObject::PointType pnt;
68 while( !iIt.IsAtEnd( ) )
70 while( !iIt.IsAtEndOfLine( ) )
72 auto idx = iIt.GetIndex( );
73 in->TransformIndexToPhysicalPoint( idx, pnt );
74 if( this->m_SpatialObject->IsInside( pnt ) )
75 oIt.Set( TOutPixel( iIt.Get( ) ) );
77 oIt.Set( this->m_OutsideValue );
84 progress.CompletedPixel( );
89 #endif // __CPEXTENSIONS__ALGORITHMS__SPATIALOBJECTMASKIMAGEFILTER__HXX__