// ------------------------------------------------------------------------- // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) // ------------------------------------------------------------------------- #ifndef __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__HXX__ #define __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__HXX__ #include #include #include #include // ------------------------------------------------------------------------- template< class _TInput, class _TOutput, class _TFilter > cpExtensions::Algorithms::ImageFunctionFilter< _TInput, _TOutput, _TFilter >:: ImageFunctionFilter( ) : Superclass( ) { } // ------------------------------------------------------------------------- template< class _TInput, class _TOutput, class _TFilter > cpExtensions::Algorithms::ImageFunctionFilter< _TInput, _TOutput, _TFilter >:: ~ImageFunctionFilter( ) { } // ------------------------------------------------------------------------- template< class _TInput, class _TOutput, class _TFilter > void cpExtensions::Algorithms::ImageFunctionFilter< _TInput, _TOutput, _TFilter >:: BeforeThreadedGenerateData( ) { if( this->m_Function.IsNull( ) ) itkExceptionMacro( << "Please set a valid itk::ImageFunction" ); this->m_Function->SetInputImage( this->GetInput( ) ); } // ------------------------------------------------------------------------- template< class _TInput, class _TOutput, class _TFilter > void cpExtensions::Algorithms::ImageFunctionFilter< _TInput, _TOutput, _TFilter >:: ThreadedGenerateData( const TRegion& region, itk::ThreadIdType threadId ) { const typename TRegion::SizeType& regionSize = region.GetSize( ); if( regionSize[ 0 ] == 0 ) return; const _TInput* in = this->GetInput( ); _TOutput* out = this->GetOutput( 0 ); itk::ProgressReporter pr( this, threadId, region.GetNumberOfPixels( ) ); // Define the iterators itk::ImageRegionConstIteratorWithIndex< TInput > iIt( in, region ); itk::ImageRegionIteratorWithIndex< TOutput > oIt( out, region ); iIt.GoToBegin( ); oIt.GoToBegin( ); for( ; !iIt.IsAtEnd( ) && !oIt.IsAtEnd( ); ++iIt, ++oIt ) { oIt.Set( this->m_Function->EvaluateAtIndex( iIt.GetIndex( ) ) ); pr.CompletedPixel( ); } // rof } #endif // __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__HXX__ // eof - $RCSfile$