1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
5 #ifndef __CPEXTENSIONS__ALGORITHMS__GAUSSIANDENSITYIMAGEFILTER__H__
6 #define __CPEXTENSIONS__ALGORITHMS__GAUSSIANDENSITYIMAGEFILTER__H__
8 #include <itkImageToImageFilter.h>
9 #include <itkImageScanlineConstIterator.h>
10 #include <itkImageScanlineIterator.h>
11 #include <itkProgressReporter.h>
13 namespace cpExtensions
19 template< class _TInputImage, class _TEstimator >
20 class GaussianDensityImageFilter
21 : public itk::ImageToImageFilter< _TInputImage, itk::Image< typename _TEstimator::TScalar, _TInputImage::ImageDimension > >
24 typedef typename _TEstimator::TScalar TScalar;
25 typedef itk::Image< TScalar, _TInputImage::ImageDimension > TOutputImage;
26 typedef GaussianDensityImageFilter Self;
27 typedef itk::ImageToImageFilter< _TInputImage, TOutputImage > Superclass;
28 typedef itk::SmartPointer< Self > Pointer;
29 typedef itk::SmartPointer< const Self > ConstPointer;
31 typedef _TInputImage TInputImage;
32 typedef _TEstimator TEstimator;
33 typedef typename TOutputImage::RegionType TRegion;
37 itkTypeMacro( GaussianDensityImageFilter, itkImageToImageFilter );
39 itkGetConstObjectMacro( Estimator, TEstimator );
40 itkSetConstObjectMacro( Estimator, TEstimator );
43 GaussianDensityImageFilter( )
47 virtual ~GaussianDensityImageFilter( )
51 virtual void ThreadedGenerateData(
52 const TRegion& region,
53 itk::ThreadIdType threadId
56 const typename TRegion::SizeType& regionSize = region.GetSize( );
57 if( regionSize[ 0 ] == 0 )
59 const TInputImage* in = this->GetInput( );
60 TOutputImage* out = this->GetOutput( 0 );
62 const size_t nLines = region.GetNumberOfPixels( ) / regionSize[ 0 ];
63 itk::ProgressReporter progress( this, threadId, nLines );
65 // Define the iterators
66 itk::ImageScanlineConstIterator< TInputImage > inIt( in, region );
67 itk::ImageScanlineIterator< TOutputImage > outIt( out, region );
71 while( !inIt.IsAtEnd( ) )
73 while( !inIt.IsAtEndOfLine( ) )
75 if( this->m_Estimator.IsNotNull( ) )
76 outIt.Set( this->m_Estimator->Density( inIt.Get( ) ) );
83 progress.CompletedPixel( );
89 // Purposely not implemented.
90 GaussianDensityImageFilter( const Self& );
91 void operator=( const Self& );
94 typename TEstimator::ConstPointer m_Estimator;
101 #endif // __CPEXTENSIONS__ALGORITHMS__GAUSSIANDENSITYIMAGEFILTER__H__