00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00077 this->FirstCopier(out, 0, A);
00078
00079
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 };
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 }
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&);
00228 void operator=(const Self&);
00229
00230 };
00231
00232
00233 }
00234
00235 #endif