ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkMovingHistogramImageFilterBase.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkMovingHistogramImageFilterBase_h
00019 #define __itkMovingHistogramImageFilterBase_h
00020 
00021 #include "itkKernelImageFilter.h"
00022 #include <list>
00023 #include <map>
00024 #include <set>
00025 
00026 namespace itk
00027 {
00089 template< class TInputImage, class TOutputImage, class TKernel >
00090 class ITK_EXPORT MovingHistogramImageFilterBase:
00091   public KernelImageFilter< TInputImage, TOutputImage, TKernel >
00092 {
00093 public:
00095   typedef MovingHistogramImageFilterBase                          Self;
00096   typedef KernelImageFilter< TInputImage, TOutputImage, TKernel > Superclass;
00097   typedef SmartPointer< Self >                                    Pointer;
00098   typedef SmartPointer< const Self >                              ConstPointer;
00099 
00101   itkNewMacro(Self);
00102 
00104   itkTypeMacro(MovingHistogramImageFilterBase,
00105                KernelImageFilter);
00106 
00108   typedef TInputImage                                InputImageType;
00109   typedef TOutputImage                               OutputImageType;
00110   typedef typename TInputImage::RegionType           RegionType;
00111   typedef typename TInputImage::SizeType             SizeType;
00112   typedef typename TInputImage::IndexType            IndexType;
00113   typedef typename TInputImage::PixelType            PixelType;
00114   typedef typename TInputImage::OffsetType           OffsetType;
00115   typedef typename Superclass::OutputImageRegionType OutputImageRegionType;
00116   typedef typename TOutputImage::PixelType           OutputPixelType;
00117 
00119   itkStaticConstMacro(ImageDimension, unsigned int,
00120                       TInputImage::ImageDimension);
00121 
00123   typedef TKernel KernelType;
00124 
00126   typedef typename KernelType::ConstIterator KernelIteratorType;
00127 
00129   typedef typename KernelType::SizeType RadiusType;
00130 
00131   typedef typename std::list< OffsetType > OffsetListType;
00132 
00133   typedef typename std::map< OffsetType, OffsetListType, typename OffsetType::LexicographicCompare > OffsetMapType;
00134 
00136   void SetKernel(const KernelType & kernel);
00137 
00138   itkGetConstMacro(PixelsPerTranslation, SizeValueType);
00139 
00140 protected:
00141   MovingHistogramImageFilterBase();
00142   ~MovingHistogramImageFilterBase() {}
00143 
00144   void PrintSelf(std::ostream & os, Indent indent) const;
00145 
00146   void GetDirAndOffset(const IndexType LineStart,
00147                        const IndexType PrevLineStart,
00148                        OffsetType & LineOffset,
00149                        OffsetType & Changes,
00150                        int & LineDirection);
00151 
00152   // store the added and removed pixel offset in a list
00153   OffsetMapType m_AddedOffsets;
00154   OffsetMapType m_RemovedOffsets;
00155 
00156   // store the offset of the kernel to initialize the histogram
00157   OffsetListType m_KernelOffsets;
00158 
00159   FixedArray< int, itkGetStaticConstMacro(ImageDimension) > m_Axes;
00160 
00161   SizeValueType m_PixelsPerTranslation;
00162 private:
00163   MovingHistogramImageFilterBase(const Self &); //purposely not implemented
00164   void operator=(const Self &);                 //purposely not implemented
00165 
00166   class DirectionCost
00167   {
00168 public:
00169     DirectionCost(int dimension, int count)
00170     {
00171       m_Dimension = dimension;
00172       m_Count = count;
00173     }
00174 
00179     inline bool operator<(const DirectionCost & dc) const
00180     {
00181       if ( m_Count > dc.m_Count )
00182             { return true; }
00183       else if ( m_Count < dc.m_Count )
00184             { return false; }
00185       else //if (m_Count == dc.m_Count)
00186             { return m_Dimension > dc.m_Dimension; }
00187     }
00189 
00190     int m_Dimension;
00191     int m_Count;
00192   };
00193 }; // end of class
00194 } // end namespace itk
00195 
00196 #ifndef ITK_MANUAL_INSTANTIATION
00197 #include "itkMovingHistogramImageFilterBase.hxx"
00198 #endif
00199 
00200 #endif
00201