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() {}
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)
00084 {
00085 JoinType out;
00086
00087
00088 this->FirstCopier(out, 0, A);
00089
00090
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)
00118 {
00119 FirstCopier(CopierDispatch<Dimension1>(), out, idx, A);
00120 }
00121
00123 void FirstCopier(CopierDispatchBase,
00124 JoinType& out, unsigned int idx, const TPixel1& A)
00125 {
00126 for (unsigned int i=0; i < Dimension1; i++, idx++)
00127 { out[idx] = static_cast<JoinValueType>(A[i]); }
00128 }
00130
00132 void FirstCopier(CopierDispatch<1>,
00133 JoinType& out, unsigned int idx, const TPixel1& A)
00134 { out[idx] = static_cast<JoinValueType>(A); }
00135
00141 void SecondCopier(JoinType& out, unsigned int idx, const TPixel2& B)
00142 {
00143 SecondCopier(CopierDispatch<Dimension2>(), out, idx, B);
00144 }
00145
00147 void SecondCopier(CopierDispatchBase,
00148 JoinType& out, unsigned int idx, const TPixel2& B)
00149 {
00150 for (unsigned int i=0; i < Dimension2; i++, idx++)
00151 { out[idx] = static_cast<JoinValueType>(B[i]); }
00152 }
00154
00156 void SecondCopier(CopierDispatch<1>,
00157 JoinType& out, unsigned int idx, const TPixel2& B)
00158 {
00159 out[idx] = static_cast<JoinValueType>(B);
00160 }
00161 };
00163
00164 template <typename TImage1, typename TImage2>
00165 struct MakeJoin
00166 {
00167 typedef JoinFunctor<typename TImage1::PixelType,
00168 typename TImage2::PixelType> FunctorType;
00169 typedef Image<typename FunctorType::JoinType,
00170 ::itk::GetImageDimension<TImage1>::ImageDimension> ImageType;
00171 };
00172
00173 }
00174
00198 template <class TInputImage1, class TInputImage2>
00199 class ITK_EXPORT JoinImageFilter:
00200 public BinaryFunctorImageFilter<TInputImage1,
00201 TInputImage2,
00202 ITK_TYPENAME
00203 Functor::MakeJoin<TInputImage1,
00204 TInputImage2>::ImageType,
00205 ITK_TYPENAME
00206 Functor::MakeJoin<TInputImage1,
00207 TInputImage2>::FunctorType>
00208 {
00209 public:
00211 itkStaticConstMacro(OutputImageDimension, unsigned int,
00212 TInputImage1::ImageDimension);
00213
00215 typedef JoinImageFilter Self;
00216
00218 typedef typename Functor::MakeJoin<TInputImage1,
00219 TInputImage2>::FunctorType FunctorType;
00220 typedef typename Functor::MakeJoin<TInputImage1,
00221 TInputImage2>::ImageType OutputImageType;
00222 typedef typename FunctorType::JoinType OutputImagePixelType;
00223
00225 typedef BinaryFunctorImageFilter<TInputImage1,TInputImage2, OutputImageType,
00226 FunctorType > Superclass;
00227 typedef SmartPointer<Self> Pointer;
00228 typedef SmartPointer<const Self> ConstPointer;
00229
00231 itkNewMacro(Self);
00232
00234 itkTypeMacro(JoinImageFilter, BinaryFunctorImageFilter);
00235
00236 #ifdef ITK_USE_CONCEPT_CHECKING
00237
00238 itkConceptMacro(Input1HasPixelTraitsCheck,
00239 (Concept::HasPixelTraits<typename TInputImage1::PixelType>));
00240 itkConceptMacro(Input2HasPixelTraitsCheck,
00241 (Concept::HasPixelTraits<typename TInputImage2::PixelType>));
00242 itkConceptMacro(Input1Input2HasJoinTraitsCheck,
00243 (Concept::HasJoinTraits<typename PixelTraits<typename TInputImage1::PixelType>::ValueType,
00244 typename PixelTraits<typename TInputImage2::PixelType>::ValueType>));
00245
00247 #endif
00248
00249 protected:
00250 JoinImageFilter() {}
00251 virtual ~JoinImageFilter() {}
00252
00253 private:
00254 JoinImageFilter(const Self&);
00255 void operator=(const Self&);
00256
00257 };
00258
00259
00260 }
00261
00262 #endif
00263