ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkSumOfSquaresImageFunction.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 __itkSumOfSquaresImageFunction_h
00019 #define __itkSumOfSquaresImageFunction_h
00020 
00021 #include "itkImageFunction.h"
00022 #include "itkNumericTraits.h"
00023 #include "itkNeighborhood.h"
00024 
00025 namespace itk
00026 {
00043 template< class TInputImage, class TCoordRep = float >
00044 class ITK_EXPORT SumOfSquaresImageFunction:
00045   public ImageFunction< TInputImage, typename NumericTraits< typename TInputImage::PixelType >::RealType,
00046                         TCoordRep >
00047 {
00048 public:
00049 
00051   typedef SumOfSquaresImageFunction Self;
00052   typedef ImageFunction< TInputImage, typename NumericTraits< typename TInputImage::PixelType >::RealType,
00053                          TCoordRep >                     Superclass;
00054 
00055   typedef SmartPointer< Self >       Pointer;
00056   typedef SmartPointer< const Self > ConstPointer;
00057 
00059   itkTypeMacro(SumOfSquaresImageFunction, ImageFunction);
00060 
00062   itkNewMacro(Self);
00063 
00065   typedef TInputImage InputImageType;
00066 
00068   typedef typename Superclass::OutputType OutputType;
00069 
00071   typedef typename Superclass::IndexType IndexType;
00072 
00074   typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
00075 
00077   typedef typename Superclass::PointType PointType;
00078 
00080   itkStaticConstMacro(ImageDimension, unsigned int,
00081                       InputImageType::ImageDimension);
00082 
00084   typedef typename NumericTraits< typename InputImageType::PixelType >::RealType
00085   RealType;
00086 
00088   virtual RealType EvaluateAtIndex(const IndexType & index) const;
00089 
00091   virtual RealType Evaluate(const PointType & point) const
00092   {
00093     IndexType index;
00094 
00095     this->ConvertPointToNearestIndex(point, index);
00096     return this->EvaluateAtIndex(index);
00097   }
00098 
00099   virtual RealType EvaluateAtContinuousIndex(
00100     const ContinuousIndexType & cindex) const
00101   {
00102     IndexType index;
00103 
00104     this->ConvertContinuousIndexToNearestIndex(cindex, index);
00105     return this->EvaluateAtIndex(index);
00106   }
00107 
00110   itkGetConstReferenceMacro(NeighborhoodRadius, unsigned int);
00111 
00112   void SetNeighborhoodRadius(unsigned int radius)
00113   {
00114     m_NeighborhoodRadius = radius;
00115 
00116     m_NeighborhoodSize = 1;
00117     long twoRPlus1 = 2 * m_NeighborhoodRadius + 1;
00118     for ( unsigned int i = 0; i < ImageDimension; i++ )
00119       {
00120       m_NeighborhoodSize *= twoRPlus1;
00121       }
00122   }
00123 
00124   itkGetConstReferenceMacro(NeighborhoodSize, unsigned int);
00125 protected:
00126   SumOfSquaresImageFunction();
00127   ~SumOfSquaresImageFunction(){}
00128   void PrintSelf(std::ostream & os, Indent indent) const;
00129 
00130 private:
00131   SumOfSquaresImageFunction(const Self &); //purposely not implemented
00132   void operator=(const Self &);            //purposely not implemented
00133 
00134   unsigned int m_NeighborhoodRadius;
00135   unsigned int m_NeighborhoodSize;
00136 };
00137 } // end namespace itk
00138 
00139 // Define instantiation macro for this template.
00140 #define ITK_TEMPLATE_SumOfSquaresImageFunction(_, EXPORT, TypeX, TypeY)     \
00141   namespace itk                                                             \
00142   {                                                                         \
00143   _( 2 ( class EXPORT SumOfSquaresImageFunction< ITK_TEMPLATE_2 TypeX > ) ) \
00144   namespace Templates                                                       \
00145   {                                                                         \
00146   typedef SumOfSquaresImageFunction< ITK_TEMPLATE_2 TypeX >                 \
00147   SumOfSquaresImageFunction##TypeY;                                       \
00148   }                                                                         \
00149   }
00150 
00151 #if ITK_TEMPLATE_EXPLICIT
00152 #include "Templates/itkSumOfSquaresImageFunction+-.h"
00153 #endif
00154 
00155 #if ITK_TEMPLATE_TXX
00156 #include "itkSumOfSquaresImageFunction.hxx"
00157 #endif
00158 
00159 #endif
00160