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: 2002/09/13 17:34:23 $
00007   Version:   $Revision: 1.10 $
00008 
00009   Copyright (c) 2002 Insight 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() {}
00051 
00053   typedef JoinFunctor Self;
00054   
00056   typedef typename PixelTraits<TPixel1>::ValueType ValueType1;
00057   typedef typename PixelTraits<TPixel2>::ValueType ValueType2;
00058   typedef typename JoinTraits<ValueType1, ValueType2>::ValueType JoinValueType;
00059 
00061   itkStaticConstMacro(Dimension1, unsigned int,
00062                       PixelTraits<TPixel1>::Dimension);
00063   itkStaticConstMacro(Dimension2, unsigned int,
00064                       PixelTraits<TPixel2>::Dimension);
00065   itkStaticConstMacro(JoinDimension, unsigned int,
00066                       Dimension1 + Dimension2);
00067 
00069   typedef Vector<JoinValueType, itkGetStaticConstMacro(JoinDimension)> JoinType;
00070 
00072   inline JoinType operator()( const TPixel1 & A, const TPixel2 & B)
00073     {
00074     JoinType out;
00075 
00076     // Copy A into the output, casting as necessary
00077     this->FirstCopier(out, 0, A);
00078 
00079     // Copy B into the output, starting where A left off,casting as necessary
00080     this->SecondCopier(out, Dimension1, B);
00081 
00082     return out;
00083     }
00084 
00085 private:
00092   struct CopierDispatchBase {};
00093   template<unsigned int VDimension>
00094   struct CopierDispatch : public CopierDispatchBase {};
00095 
00106   void FirstCopier(JoinType& out, unsigned int idx, const TPixel1& A)
00107     {
00108     FirstCopier(CopierDispatch<Dimension1>(), out, idx, A);
00109     }
00110 
00112   void FirstCopier(CopierDispatchBase,
00113                    JoinType& out, unsigned int idx, const TPixel1& A)
00114     {
00115       for (unsigned int i=0; i < Dimension1; i++, idx++)
00116       { out[idx] = static_cast<JoinValueType>(A[i]); }
00117     }
00118 
00120   void FirstCopier(CopierDispatch<1>,
00121                    JoinType& out, unsigned int idx, const TPixel1& A)
00122     { out[idx] = static_cast<JoinValueType>(A); }
00123 
00129   void SecondCopier(JoinType& out, unsigned int idx, const TPixel2& B)
00130     {
00131     SecondCopier(CopierDispatch<Dimension2>(), out, idx, B);
00132     }
00133 
00135   void SecondCopier(CopierDispatchBase,
00136                     JoinType& out, unsigned int idx, const TPixel2& B)
00137     {
00138     for (unsigned int i=0; i < Dimension2; i++, idx++)
00139       { out[idx] = static_cast<JoinValueType>(B[i]); }
00140     }
00141 
00143   void SecondCopier(CopierDispatch<1>,
00144                     JoinType& out, unsigned int idx, const TPixel2& B)
00145     {
00146     out[idx] = static_cast<JoinValueType>(B);
00147     }
00148 }; //class JoinFunction
00149 
00150 template <typename TImage1, typename TImage2>
00151 struct MakeJoin
00152 {
00153   typedef JoinFunctor<typename TImage1::PixelType,
00154                       typename TImage2::PixelType> FunctorType;
00155   typedef Image<typename FunctorType::JoinType,
00156                 ::itk::GetImageDimension<TImage1>::ImageDimension> ImageType;
00157 };
00158 
00159 } //namespace functor
00160   
00184 template <class TInputImage1, class TInputImage2>
00185 class ITK_EXPORT JoinImageFilter:
00186   public BinaryFunctorImageFilter<TInputImage1,
00187                                   TInputImage2,
00188                                   ITK_TYPENAME
00189                                   Functor::MakeJoin<TInputImage1,
00190                                                     TInputImage2>::ImageType,
00191                                   ITK_TYPENAME
00192                                   Functor::MakeJoin<TInputImage1,
00193                                                     TInputImage2>::FunctorType>
00194 {
00195 public:
00197   itkStaticConstMacro(OutputImageDimension, unsigned int,
00198                       TInputImage1::ImageDimension);
00199 
00201   typedef JoinImageFilter  Self;
00202 
00204   typedef typename Functor::MakeJoin<TInputImage1,
00205                                      TInputImage2>::FunctorType FunctorType;
00206   typedef typename Functor::MakeJoin<TInputImage1,
00207                                      TInputImage2>::ImageType OutputImageType;
00208   typedef typename FunctorType::JoinType OutputImagePixelType;  
00209   
00211   typedef BinaryFunctorImageFilter<TInputImage1,TInputImage2, OutputImageType,
00212                                    FunctorType > Superclass; 
00213   typedef SmartPointer<Self>   Pointer;
00214   typedef SmartPointer<const Self>  ConstPointer;
00215 
00217   itkNewMacro(Self);
00218 
00220   itkTypeMacro(JoinImageFilter, BinaryFunctorImageFilter);
00221 
00222 protected:
00223   JoinImageFilter() {}
00224   virtual ~JoinImageFilter() {}
00225 
00226 private:
00227   JoinImageFilter(const Self&); //purposely not implemented
00228   void operator=(const Self&); //purposely not implemented
00229 
00230 };
00231 
00232   
00233 } // end namespace itk
00234   
00235 #endif

Generated at Fri May 21 01:14:58 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000