Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkJoinImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkJoinImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-04-01 14:36:26 $
00007   Version:   $Revision: 1.18 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkJoinImageFilter_h
00018 #define __itkJoinImageFilter_h
00019 
00020 #include "itkBinaryFunctorImageFilter.h"
00021 #include "itkPixelTraits.h"
00022 
00023 namespace itk
00024 {
00025   
00026 namespace Functor {  
00045 template <class TPixel1, class TPixel2>
00046 class JoinFunctor
00047 {
00048 public:
00049   JoinFunctor() {}
00050   ~JoinFunctor() {}
00052 
00054   typedef JoinFunctor Self;
00055 
00057   typedef typename PixelTraits<TPixel1>::ValueType               ValueType1;
00058   typedef typename PixelTraits<TPixel2>::ValueType               ValueType2;
00059   typedef typename JoinTraits<ValueType1, ValueType2>::ValueType JoinValueType;
00060 
00062   itkStaticConstMacro(Dimension1, unsigned int,
00063                       PixelTraits<TPixel1>::Dimension);
00064   itkStaticConstMacro(Dimension2, unsigned int,
00065                       PixelTraits<TPixel2>::Dimension);
00066   itkStaticConstMacro(JoinDimension, unsigned int,
00067                       Dimension1 + Dimension2);
00069 
00071   typedef Vector<JoinValueType, itkGetStaticConstMacro(JoinDimension)> JoinType;
00072 
00073   bool operator!=( const JoinFunctor & ) const
00074     {
00075     return false;
00076     }
00077   bool operator==( const JoinFunctor & other ) const
00078     {
00079     return !(*this != other);
00080     }
00081 
00083   inline JoinType operator() ( const TPixel1 & A, const TPixel2 & B) const
00084     {
00085     JoinType out;
00086 
00087     // Copy A into the output, casting as necessary
00088     this->FirstCopier(out, 0, A);
00089 
00090     // Copy B into the output, starting where A left off,casting as necessary
00091     this->SecondCopier(out, Dimension1, B);
00092 
00093     return out;
00094     }
00095 
00096 private:
00103   struct CopierDispatchBase {};
00104   template<unsigned int VDimension>
00105   struct CopierDispatch : public CopierDispatchBase {};
00106 
00117   void FirstCopier(JoinType& out, unsigned int idx, const TPixel1& A) const
00118     {
00119     FirstCopier(CopierDispatch<Dimension1>(), out, idx, A);
00120     }
00121 
00123   void FirstCopier(CopierDispatchBase,
00124                    JoinType& out, unsigned int idx, const TPixel1& A) const
00125     {
00126     for (unsigned int i=0; i < Dimension1; i++, idx++)
00127       {
00128       out[idx] = static_cast<JoinValueType>(A[i]);
00129       }
00130     }
00132 
00134   void FirstCopier(CopierDispatch<1>,
00135                    JoinType& out, unsigned int idx, const TPixel1& A) const
00136     { out[idx] = static_cast<JoinValueType>(A); }
00137 
00143   void SecondCopier(JoinType& out, unsigned int idx, const TPixel2& B) const
00144     {
00145     SecondCopier(CopierDispatch<Dimension2>(), out, idx, B);
00146     }
00147 
00149   void SecondCopier(CopierDispatchBase,
00150                     JoinType& out, unsigned int idx, const TPixel2& B) const
00151     {
00152     for (unsigned int i=0; i < Dimension2; i++, idx++)
00153       {
00154       out[idx] = static_cast<JoinValueType>(B[i]);
00155       }
00156     }
00158 
00160   void SecondCopier(CopierDispatch<1>,
00161                     JoinType& out, unsigned int idx, const TPixel2& B) const
00162     {
00163     out[idx] = static_cast<JoinValueType>(B);
00164     }
00165 }; //class JoinFunction
00167 
00168 template <typename TImage1, typename TImage2>
00169 struct MakeJoin
00170 {
00171   typedef JoinFunctor<typename TImage1::PixelType,
00172                       typename TImage2::PixelType> FunctorType;
00173   typedef Image<typename FunctorType::JoinType,
00174                 ::itk::GetImageDimension<TImage1>::ImageDimension> ImageType;
00175 };
00176 
00177 } //namespace functor
00178   
00202 template <class TInputImage1, class TInputImage2>
00203 class ITK_EXPORT JoinImageFilter:
00204   public BinaryFunctorImageFilter<TInputImage1,
00205                                   TInputImage2,
00206                                   ITK_TYPENAME
00207                                   Functor::MakeJoin<TInputImage1,
00208                                                     TInputImage2>::ImageType,
00209                                   ITK_TYPENAME
00210                                   Functor::MakeJoin<TInputImage1,
00211                                                     TInputImage2>::FunctorType>
00212 {
00213 public:
00215   itkStaticConstMacro(OutputImageDimension, unsigned int,
00216                       TInputImage1::ImageDimension);
00217 
00219   typedef JoinImageFilter  Self;
00220 
00222   typedef typename Functor::MakeJoin<TInputImage1,
00223                                      TInputImage2>::FunctorType FunctorType;
00224   typedef typename Functor::MakeJoin<TInputImage1,
00225                                      TInputImage2>::ImageType OutputImageType;
00226   typedef typename FunctorType::JoinType OutputImagePixelType;  
00227 
00229   typedef BinaryFunctorImageFilter<TInputImage1,TInputImage2, OutputImageType,
00230                                    FunctorType > Superclass; 
00231   typedef SmartPointer<Self>                     Pointer;
00232   typedef SmartPointer<const Self>               ConstPointer;
00233 
00235   itkNewMacro(Self);
00236 
00238   itkTypeMacro(JoinImageFilter, BinaryFunctorImageFilter);
00239 
00240 #ifdef ITK_USE_CONCEPT_CHECKING
00241 
00242   itkConceptMacro(Input1HasPixelTraitsCheck,
00243     (Concept::HasPixelTraits<typename TInputImage1::PixelType>));
00244   itkConceptMacro(Input2HasPixelTraitsCheck,
00245     (Concept::HasPixelTraits<typename TInputImage2::PixelType>));
00246   itkConceptMacro(Input1Input2HasJoinTraitsCheck,
00247     (Concept::HasJoinTraits<typename PixelTraits<typename TInputImage1::PixelType>::ValueType,
00248                             typename PixelTraits<typename TInputImage2::PixelType>::ValueType>));
00249 
00251 #endif
00252 
00253 protected:
00254   JoinImageFilter() {}
00255   virtual ~JoinImageFilter() {}
00256 
00257 private:
00258   JoinImageFilter(const Self&); //purposely not implemented
00259   void operator=(const Self&); //purposely not implemented
00260 
00261 };
00262 
00263   
00264 } // end namespace itk
00265   
00266 #endif
00267 

Generated at Mon Jul 12 2010 18:53:34 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000