diff --git a/include/itkStreamingStatisticsImageFilter.h b/include/itkStreamingStatisticsImageFilter.h index d6c09ff..c9a606d 100644 --- a/include/itkStreamingStatisticsImageFilter.h +++ b/include/itkStreamingStatisticsImageFilter.h @@ -15,8 +15,8 @@ * limitations under the License. * *=========================================================================*/ -#ifndef itkStatisticsImageFilter_h -#define itkStatisticsImageFilter_h +#ifndef itkStreamingStatisticsImageFilter_h +#define itkStreamingStatisticsImageFilter_h #include "itkImageToImageFilter.h" #include "itkNumericTraits.h" @@ -25,10 +25,10 @@ namespace itk { -/** \class StatisticsImageFilter +/** \class StreamingStatisticsImageFilter * \brief Compute min. max, variance and mean of an Image. * - * StatisticsImageFilter computes the minimum, maximum, sum, mean, variance + * StreamingStatisticsImageFilter computes the minimum, maximum, sum, mean, variance * sigma of an image. The filter needs all of its input image. It * behaves as a filter with an input and output. Thus it can be inserted * in a pipline with other filters and the statistics will only be @@ -38,26 +38,26 @@ namespace itk * threaded. It computes statistics in each thread then combines them in * its AfterThreadedGenerate method. * - * \ingroup MathematicalStatisticsImageFilters + * \ingroup MathematicalStreamingStatisticsImageFilters * * \ingroup StreamingSinc */ template< typename TInputImage > -class StatisticsImageFilter: - public ImageToImageFilter< TInputImage, TInputImage > +class StreamingStatisticsImageFilter: + public ImageSinc< TInputImage > { public: /** Standard Self typedef */ - typedef StatisticsImageFilter Self; - typedef ImageToImageFilter< TInputImage, TInputImage > Superclass; - typedef SmartPointer< Self > Pointer; - typedef SmartPointer< const Self > ConstPointer; + typedef StreamingStatisticsImageFilter Self; + typedef ImageSinc< TInputImage > Superclass; + typedef SmartPointer< Self > Pointer; + typedef SmartPointer< const Self > ConstPointer; /** Method for creation through the object factory. */ itkNewMacro(Self); /** Runtime information support. */ - itkTypeMacro(StatisticsImageFilter, ImageToImageFilter); + itkTypeMacro(StreamingStatisticsImageFilter, ImageSinc); /** Image related typedefs. */ typedef typename TInputImage::Pointer InputImagePointer; @@ -137,35 +137,23 @@ class StatisticsImageFilter: #endif protected: - StatisticsImageFilter(); - ~StatisticsImageFilter(){} + StreamingStatisticsImageFilter(); + ~StreamingStatisticsImageFilter(){} void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; - /** Pass the input through unmodified. Do this by Grafting in the - * AllocateOutputs method. - */ - void AllocateOutputs() ITK_OVERRIDE; - /** Initialize some accumulators before the threads run. */ - void BeforeThreadedGenerateData() ITK_OVERRIDE; + void BeforeStreamedGenerateData() ITK_OVERRIDE; /** Do final mean and variance computation from data accumulated in threads. */ - void AfterThreadedGenerateData() ITK_OVERRIDE; + void AfterStreamedGenerateData() ITK_OVERRIDE; /** Multi-thread version GenerateData. */ - void ThreadedGenerateData(const RegionType & - outputRegionForThread, - ThreadIdType threadId) ITK_OVERRIDE; - - // Override since the filter needs all the data for the algorithm - void GenerateInputRequestedRegion() ITK_OVERRIDE; + void ThreadedStreamedGenerateData(const RegionType &inputRegion, ThreadIdType threadId) ITK_OVERRIDE; - // Override since the filter produces all of its output - void EnlargeOutputRequestedRegion(DataObject *data) ITK_OVERRIDE; private: - StatisticsImageFilter(const Self &); //purposely not implemented + StreamingStatisticsImageFilter(const Self &); //purposely not implemented void operator=(const Self &); //purposely not implemented Array< RealType > m_ThreadSum; @@ -177,7 +165,7 @@ class StatisticsImageFilter: } // end namespace itk #ifndef ITK_MANUAL_INSTANTIATION -#include "itkStatisticsImageFilter.hxx" +#include "itkStreamingStatisticsImageFilter.hxx" #endif #endif diff --git a/include/itkStreamingStatisticsImageFilter.hxx b/include/itkStreamingStatisticsImageFilter.hxx index 0453b46..ea7067c 100644 --- a/include/itkStreamingStatisticsImageFilter.hxx +++ b/include/itkStreamingStatisticsImageFilter.hxx @@ -15,9 +15,9 @@ * limitations under the License. * *=========================================================================*/ -#ifndef itkStatisticsImageFilter_hxx -#define itkStatisticsImageFilter_hxx -#include "itkStatisticsImageFilter.h" +#ifndef itkStreamingStatisticsImageFilter_hxx +#define itkStreamingStatisticsImageFilter_hxx +#include "itkStreamingStatisticsImageFilter.h" #include "itkImageScanlineIterator.h" @@ -26,8 +26,8 @@ namespace itk { template< typename TInputImage > -StatisticsImageFilter< TInputImage > -::StatisticsImageFilter():m_ThreadSum(1), m_SumOfSquares(1), m_Count(1), m_ThreadMin(1), m_ThreadMax(1) +StreamingStatisticsImageFilter< TInputImage > +::StreamingStatisticsImageFilter():m_ThreadSum(1), m_SumOfSquares(1), m_Count(1), m_ThreadMin(1), m_ThreadMax(1) { // first output is a copy of the image, DataObject created by // superclass @@ -59,7 +59,7 @@ StatisticsImageFilter< TInputImage > template< typename TInputImage > DataObject::Pointer -StatisticsImageFilter< TInputImage > +StreamingStatisticsImageFilter< TInputImage > ::MakeOutput(DataObjectPointerArraySizeType output) { switch ( output ) @@ -87,96 +87,96 @@ StatisticsImageFilter< TInputImage > } template< typename TInputImage > -typename StatisticsImageFilter< TInputImage >::PixelObjectType * -StatisticsImageFilter< TInputImage > +typename StreamingStatisticsImageFilter< TInputImage >::PixelObjectType * +StreamingStatisticsImageFilter< TInputImage > ::GetMinimumOutput() { return static_cast< PixelObjectType * >( this->ProcessObject::GetOutput(1) ); } template< typename TInputImage > -const typename StatisticsImageFilter< TInputImage >::PixelObjectType * -StatisticsImageFilter< TInputImage > +const typename StreamingStatisticsImageFilter< TInputImage >::PixelObjectType * +StreamingStatisticsImageFilter< TInputImage > ::GetMinimumOutput() const { return static_cast< const PixelObjectType * >( this->ProcessObject::GetOutput(1) ); } template< typename TInputImage > -typename StatisticsImageFilter< TInputImage >::PixelObjectType * -StatisticsImageFilter< TInputImage > +typename StreamingStatisticsImageFilter< TInputImage >::PixelObjectType * +StreamingStatisticsImageFilter< TInputImage > ::GetMaximumOutput() { return static_cast< PixelObjectType * >( this->ProcessObject::GetOutput(2) ); } template< typename TInputImage > -const typename StatisticsImageFilter< TInputImage >::PixelObjectType * -StatisticsImageFilter< TInputImage > +const typename StreamingStatisticsImageFilter< TInputImage >::PixelObjectType * +StreamingStatisticsImageFilter< TInputImage > ::GetMaximumOutput() const { return static_cast< const PixelObjectType * >( this->ProcessObject::GetOutput(2) ); } template< typename TInputImage > -typename StatisticsImageFilter< TInputImage >::RealObjectType * -StatisticsImageFilter< TInputImage > +typename StreamingStatisticsImageFilter< TInputImage >::RealObjectType * +StreamingStatisticsImageFilter< TInputImage > ::GetMeanOutput() { return static_cast< RealObjectType * >( this->ProcessObject::GetOutput(3) ); } template< typename TInputImage > -const typename StatisticsImageFilter< TInputImage >::RealObjectType * -StatisticsImageFilter< TInputImage > +const typename StreamingStatisticsImageFilter< TInputImage >::RealObjectType * +StreamingStatisticsImageFilter< TInputImage > ::GetMeanOutput() const { return static_cast< const RealObjectType * >( this->ProcessObject::GetOutput(3) ); } template< typename TInputImage > -typename StatisticsImageFilter< TInputImage >::RealObjectType * -StatisticsImageFilter< TInputImage > +typename StreamingStatisticsImageFilter< TInputImage >::RealObjectType * +StreamingStatisticsImageFilter< TInputImage > ::GetSigmaOutput() { return static_cast< RealObjectType * >( this->ProcessObject::GetOutput(4) ); } template< typename TInputImage > -const typename StatisticsImageFilter< TInputImage >::RealObjectType * -StatisticsImageFilter< TInputImage > +const typename StreamingStatisticsImageFilter< TInputImage >::RealObjectType * +StreamingStatisticsImageFilter< TInputImage > ::GetSigmaOutput() const { return static_cast< const RealObjectType * >( this->ProcessObject::GetOutput(4) ); } template< typename TInputImage > -typename StatisticsImageFilter< TInputImage >::RealObjectType * -StatisticsImageFilter< TInputImage > +typename StreamingStatisticsImageFilter< TInputImage >::RealObjectType * +StreamingStatisticsImageFilter< TInputImage > ::GetVarianceOutput() { return static_cast< RealObjectType * >( this->ProcessObject::GetOutput(5) ); } template< typename TInputImage > -const typename StatisticsImageFilter< TInputImage >::RealObjectType * -StatisticsImageFilter< TInputImage > +const typename StreamingStatisticsImageFilter< TInputImage >::RealObjectType * +StreamingStatisticsImageFilter< TInputImage > ::GetVarianceOutput() const { return static_cast< const RealObjectType * >( this->ProcessObject::GetOutput(5) ); } template< typename TInputImage > -typename StatisticsImageFilter< TInputImage >::RealObjectType * -StatisticsImageFilter< TInputImage > +typename StreamingStatisticsImageFilter< TInputImage >::RealObjectType * +StreamingStatisticsImageFilter< TInputImage > ::GetSumOutput() { return static_cast< RealObjectType * >( this->ProcessObject::GetOutput(6) ); } template< typename TInputImage > -const typename StatisticsImageFilter< TInputImage >::RealObjectType * -StatisticsImageFilter< TInputImage > +const typename StreamingStatisticsImageFilter< TInputImage >::RealObjectType * +StreamingStatisticsImageFilter< TInputImage > ::GetSumOutput() const { return static_cast< const RealObjectType * >( this->ProcessObject::GetOutput(6) ); @@ -184,45 +184,8 @@ StatisticsImageFilter< TInputImage > template< typename TInputImage > void -StatisticsImageFilter< TInputImage > -::GenerateInputRequestedRegion() -{ - Superclass::GenerateInputRequestedRegion(); - if ( this->GetInput() ) - { - InputImagePointer image = - const_cast< typename Superclass::InputImageType * >( this->GetInput() ); - image->SetRequestedRegionToLargestPossibleRegion(); - } -} - -template< typename TInputImage > -void -StatisticsImageFilter< TInputImage > -::EnlargeOutputRequestedRegion(DataObject *data) -{ - Superclass::EnlargeOutputRequestedRegion(data); - data->SetRequestedRegionToLargestPossibleRegion(); -} - -template< typename TInputImage > -void -StatisticsImageFilter< TInputImage > -::AllocateOutputs() -{ - // Pass the input through as the output - InputImagePointer image = - const_cast< TInputImage * >( this->GetInput() ); - - this->GraftOutput(image); - - // Nothing that needs to be allocated for the remaining outputs -} - -template< typename TInputImage > -void -StatisticsImageFilter< TInputImage > -::BeforeThreadedGenerateData() +StreamingStatisticsImageFilter< TInputImage > +::BeforeStreamedGenerateData() { ThreadIdType numberOfThreads = this->GetNumberOfThreads(); @@ -243,8 +206,8 @@ StatisticsImageFilter< TInputImage > template< typename TInputImage > void -StatisticsImageFilter< TInputImage > -::AfterThreadedGenerateData() +StreamingStatisticsImageFilter< TInputImage > +::AfterStreamedGenerateData() { ThreadIdType i; SizeValueType count; @@ -300,11 +263,10 @@ StatisticsImageFilter< TInputImage > template< typename TInputImage > void -StatisticsImageFilter< TInputImage > -::ThreadedGenerateData(const RegionType & outputRegionForThread, - ThreadIdType threadId) +StreamingStatisticsImageFilter< TInputImage > +::ThreadedStreamedGenerateData(const RegionType & inputRegion, ThreadIdType threadId) { - const SizeValueType size0 = outputRegionForThread.GetSize(0); + const SizeValueType size0 =inputRegion.GetSize(0); if( size0 == 0) { return; @@ -318,10 +280,10 @@ StatisticsImageFilter< TInputImage > PixelType min = NumericTraits< PixelType >::max(); PixelType max = NumericTraits< PixelType >::NonpositiveMin(); - ImageScanlineConstIterator< TInputImage > it (this->GetInput(), outputRegionForThread); + ImageScanlineConstIterator< TInputImage > it (this->GetInput(), inputRegion); // support progress methods/callbacks - const size_t numberOfLinesToProcess = outputRegionForThread.GetNumberOfPixels() / size0; + const size_t numberOfLinesToProcess =inputRegion.GetNumberOfPixels() / size0; ProgressReporter progress( this, threadId, numberOfLinesToProcess ); // do the work @@ -358,7 +320,7 @@ StatisticsImageFilter< TInputImage > template< typename TImage > void -StatisticsImageFilter< TImage > +StreamingStatisticsImageFilter< TImage > ::PrintSelf(std::ostream & os, Indent indent) const { Superclass::PrintSelf(os, indent);