ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkBinaryMagnitudeImageFilter.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 __itkBinaryMagnitudeImageFilter_h
00019 #define __itkBinaryMagnitudeImageFilter_h
00020 
00021 #include "itkBinaryFunctorImageFilter.h"
00022 
00023 namespace itk
00024 {
00025 namespace Functor
00026 {
00032 template< class TInput1, class TInput2, class TOutput >
00033 class Modulus2
00034 {
00035 public:
00036   Modulus2() {}
00037   ~Modulus2() {}
00038   bool operator!=(const Modulus2 &) const
00039   {
00040     return false;
00041   }
00043 
00044   bool operator==(const Modulus2 & other) const
00045   {
00046     return !( *this != other );
00047   }
00048 
00049   inline TOutput operator()(const TInput1 & A,
00050                             const TInput2 & B) const
00051   {
00052     const double dA = static_cast< double >( A );
00053     const double dB = static_cast< double >( B );
00054 
00055     return static_cast< TOutput >( vcl_sqrt(dA * dA + dB * dB) );
00056   }
00057 };
00058 }
00084 template< class TInputImage1, class TInputImage2, class TOutputImage >
00085 class ITK_EXPORT BinaryMagnitudeImageFilter:
00086   public
00087   BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
00088                             Functor::Modulus2<
00089                               typename TInputImage1::PixelType,
00090                               typename TInputImage2::PixelType,
00091                               typename TOutputImage::PixelType >   >
00092 {
00093 public:
00095   typedef BinaryMagnitudeImageFilter Self;
00096   typedef BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
00097                                     Functor::Modulus2<
00098                                       typename TInputImage1::PixelType,
00099                                       typename TInputImage2::PixelType,
00100                                       typename TOutputImage::PixelType >
00101                                     >                                   Superclass;
00102   typedef SmartPointer< Self >       Pointer;
00103   typedef SmartPointer< const Self > ConstPointer;
00104 
00106   itkNewMacro(Self);
00107 
00109   itkTypeMacro(BinaryMagnitudeImageFilter,
00110                BinaryFunctorImageFilter);
00111 
00112 #ifdef ITK_USE_CONCEPT_CHECKING
00113 
00114   itkConceptMacro( Input1ConvertibleToDoubleCheck,
00115                    ( Concept::Convertible< typename TInputImage1::PixelType, double > ) );
00116   itkConceptMacro( Input2ConvertibleToDoubleCheck,
00117                    ( Concept::Convertible< typename TInputImage2::PixelType, double > ) );
00118   itkConceptMacro( DoubleConvertibleToOutputCheck,
00119                    ( Concept::Convertible< double, typename TOutputImage::PixelType > ) );
00120 
00122 #endif
00123 protected:
00124   BinaryMagnitudeImageFilter() {}
00125   virtual ~BinaryMagnitudeImageFilter() {}
00126 private:
00127   BinaryMagnitudeImageFilter(const Self &); //purposely not implemented
00128   void operator=(const Self &);             //purposely not implemented
00129 };
00130 } // end namespace itk
00132 
00133 #endif
00134