ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkSquareImageFilter.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 __itkSquareImageFilter_h
00019 #define __itkSquareImageFilter_h
00020 
00021 #include "itkUnaryFunctorImageFilter.h"
00022 
00023 namespace itk
00024 {
00036 namespace Functor
00037 {
00038 template< class TInput, class TOutput >
00039 class Square
00040 {
00041 public:
00042   typedef typename NumericTraits< TInput >::RealType RealType;
00043   Square() {}
00044   ~Square() {}
00045   bool operator!=(const Square &) const
00046   {
00047     return false;
00048   }
00049 
00050   bool operator==(const Square & other) const
00051   {
00052     return !( *this != other );
00053   }
00054 
00055   inline TOutput operator()(const TInput & A) const
00056   {
00057     const RealType ra = static_cast< RealType >( A );
00058 
00059     return static_cast< TOutput >( ra * ra );
00060   }
00061 };
00062 }
00063 template< class TInputImage, class TOutputImage >
00064 class ITK_EXPORT SquareImageFilter:
00065   public
00066   UnaryFunctorImageFilter< TInputImage, TOutputImage,
00067                            Functor::Square< typename TInputImage::PixelType,
00068                                             typename TOutputImage::PixelType >   >
00069 {
00070 public:
00072   typedef SquareImageFilter Self;
00073   typedef UnaryFunctorImageFilter<
00074     TInputImage, TOutputImage,
00075     Functor::Square< typename TInputImage::PixelType,
00076                      typename TOutputImage::PixelType > >  Superclass;
00077 
00078   typedef SmartPointer< Self >       Pointer;
00079   typedef SmartPointer< const Self > ConstPointer;
00080 
00082   itkNewMacro(Self);
00083 
00085   itkTypeMacro(SquareImageFilter,
00086                UnaryFunctorImageFilter);
00087 
00088 #ifdef ITK_USE_CONCEPT_CHECKING
00089 
00090   itkConceptMacro( InputHasNumericTraitsCheck,
00091                    ( Concept::HasNumericTraits< typename TInputImage::PixelType > ) );
00092   itkConceptMacro( RealTypeMultiplyOperatorCheck,
00093                    ( Concept::MultiplyOperator< typename NumericTraits< typename TInputImage::PixelType >::RealType > ) );
00094 
00096 #endif
00097 protected:
00098   SquareImageFilter() {}
00099   virtual ~SquareImageFilter() {}
00100 private:
00101   SquareImageFilter(const Self &); //purposely not implemented
00102   void operator=(const Self &);    //purposely not implemented
00103 };
00104 } // end namespace itk
00106 
00107 #endif
00108