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 O* cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
12 return( this->GetOutput( 0 ) );
15 // -------------------------------------------------------------------------
16 template< class I, class O >
17 const O* cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
18 GetPositiveOutput( ) const
20 return( this->GetOutput( 0 ) );
23 // -------------------------------------------------------------------------
24 template< class I, class O >
25 O* cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
28 return( this->GetOutput( 1 ) );
31 // -------------------------------------------------------------------------
32 template< class I, class O >
33 const O* cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
34 GetNegativeOutput( ) const
36 return( this->GetOutput( 1 ) );
39 // -------------------------------------------------------------------------
40 template< class I, class O >
41 cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
42 SpatialObjectMaskImageFilter( )
45 this->SetNumberOfRequiredInputs( 1 );
46 this->SetNumberOfRequiredOutputs( 2 );
47 this->SetNthOutput( 0, O::New( ) );
48 this->SetNthOutput( 1, O::New( ) );
51 // -------------------------------------------------------------------------
52 template< class I, class O >
53 cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
54 ~SpatialObjectMaskImageFilter( )
58 // -------------------------------------------------------------------------
59 template< class I, class O >
60 void cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
61 GenerateOutputInformation( )
64 dynamic_cast< const I* >( this->itk::ProcessObject::GetInput( 0 ) );
65 for( unsigned int idx = 0; idx < this->GetNumberOfOutputs( ); ++idx )
67 itk::DataObject* out = this->GetOutput( idx );
69 out->CopyInformation( in );
74 // -------------------------------------------------------------------------
75 template< class I, class O >
76 void cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
77 ThreadedGenerateData( const TRegion& region, itk::ThreadIdType threadId )
79 if( this->m_SpatialObject.IsNull( ) )
81 itkGenericExceptionMacro( << "No itk::SpatialObject given." );
88 dynamic_cast< const I* >( this->itk::ProcessObject::GetInput( 0 ) );
89 O* pos_out = this->GetPositiveOutput( );
90 O* neg_out = this->GetNegativeOutput( );
91 const auto size0 = region.GetSize( 0 );
94 const auto nLines = region.GetNumberOfPixels( ) / size0;
97 itk::ImageScanlineConstIterator< I > iIt( in, region );
98 itk::ImageScanlineIterator< O > pos_oIt( pos_out, region );
99 itk::ImageScanlineIterator< O > neg_oIt( neg_out, region );
100 itk::ProgressReporter progress( this, threadId, nLines );
103 typename TSpatialObject::PointType pnt;
104 while( !iIt.IsAtEnd( ) )
106 while( !iIt.IsAtEndOfLine( ) )
108 auto idx = iIt.GetIndex( );
109 in->TransformIndexToPhysicalPoint( idx, pnt );
110 if( this->m_SpatialObject->IsInside( pnt ) )
112 pos_oIt.Set( TOutPixel( iIt.Get( ) ) );
113 neg_oIt.Set( this->m_OutsideValue );
117 neg_oIt.Set( TOutPixel( iIt.Get( ) ) );
118 pos_oIt.Set( this->m_OutsideValue );
129 progress.CompletedPixel( );
134 #endif // __CPEXTENSIONS__ALGORITHMS__SPATIALOBJECTMASKIMAGEFILTER__HXX__