00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __itkImageToImageFilterDetail_h
00021 #define __itkImageToImageFilterDetail_h
00022
00023 #include "itkImageRegion.h"
00024 #include "itkSmartPointer.h"
00025
00026 namespace itk
00027 {
00028
00037 namespace ImageToImageFilterDetail
00038 {
00047 struct DispatchBase {};
00048
00056 template <bool>
00057 struct BooleanDispatch {};
00058
00067 template <int>
00068 struct IntDispatch : public DispatchBase {};
00069
00084 template <unsigned int>
00085 struct UnsignedIntDispatch : public DispatchBase {};
00086
00094 template <bool B1, bool B2>
00095 struct BinaryBooleanDispatch
00096 {
00099 typedef BooleanDispatch<B1> FirstType;
00100 typedef BooleanDispatch<B2> SecondType;
00101 };
00102
00109 template <int D1, int D2>
00110 struct BinaryIntDispatch
00111 {
00114 typedef IntDispatch<D1> FirstType;
00115 typedef IntDispatch<D2> SecondType;
00116 };
00117
00129 template <unsigned int D1, unsigned int D2>
00130 struct BinaryUnsignedIntDispatch : public DispatchBase
00131 {
00134 typedef UnsignedIntDispatch<D1> FirstType;
00135 typedef UnsignedIntDispatch<D2> SecondType;
00136
00152 typedef IntDispatch<(D1 > D2) - (D1 < D2)> ComparisonType;
00153 typedef IntDispatch<0> FirstEqualsSecondType;
00154 typedef IntDispatch<1> FirstGreaterThanSecondType;
00155 typedef IntDispatch<-1> FirstLessThanSecondType;
00156 };
00157
00174 template <unsigned int D1, unsigned int D2>
00175 void ImageToImageFilterDefaultCopyRegion(const typename
00176 BinaryUnsignedIntDispatch<D1, D2>::FirstEqualsSecondType &,
00177 ImageRegion<D1> &destRegion,
00178 const ImageRegion<D2> &srcRegion)
00179 {
00180 destRegion = srcRegion;
00181 }
00182
00199 template <unsigned int D1, unsigned int D2>
00200 void ImageToImageFilterDefaultCopyRegion(const typename
00201 BinaryUnsignedIntDispatch<D1, D2>::FirstLessThanSecondType &,
00202 ImageRegion<D1> &destRegion,
00203 const ImageRegion<D2> &srcRegion)
00204 {
00205
00206
00207 unsigned int dim;
00208 Index<D1> destIndex;
00209 Size<D1> destSize;
00210 const Index<D2> &srcIndex = srcRegion.GetIndex();
00211 const Size<D2> &srcSize = srcRegion.GetSize();
00212
00213
00214 for (dim=0; dim < D1; ++dim)
00215 {
00216 destIndex[dim] = srcIndex[dim];
00217 destSize[dim] = srcSize[dim];
00218 }
00219
00220 destRegion.SetIndex(destIndex);
00221 destRegion.SetSize(destSize);
00222 }
00223
00240 template <unsigned int D1, unsigned int D2>
00241 void ImageToImageFilterDefaultCopyRegion(const typename
00242 BinaryUnsignedIntDispatch<D1, D2>::FirstGreaterThanSecondType &,
00243 ImageRegion<D1> &destRegion,
00244 const ImageRegion<D2> &srcRegion)
00245 {
00246
00247
00248 unsigned int dim;
00249 Index<D1> destIndex;
00250 Size<D1> destSize;
00251 const Index<D2> &srcIndex = srcRegion.GetIndex();
00252 const Size<D2> &srcSize = srcRegion.GetSize();
00253
00254
00255 for (dim=0; dim < D2; ++dim)
00256 {
00257 destIndex[dim] = srcIndex[dim];
00258 destSize[dim] = srcSize[dim];
00259 }
00260
00261 for (; dim < D1; ++dim)
00262 {
00263 destIndex[dim] = 0;
00264 destSize[dim] = 1;
00265 }
00266
00267 destRegion.SetIndex(destIndex);
00268 destRegion.SetSize(destSize);
00269 }
00270
00271
00308 template <unsigned int D1, unsigned int D2>
00309 class ITK_EXPORT ImageRegionCopier
00310 {
00311 public:
00312 virtual void operator() (ImageRegion<D1> &destRegion,
00313 const ImageRegion<D2> &srcRegion) const
00314 {
00315 typedef typename BinaryUnsignedIntDispatch<D1, D2>::ComparisonType ComparisonType;
00316 ImageToImageFilterDefaultCopyRegion<D1, D2>(
00317 ComparisonType(),
00318 destRegion, srcRegion);
00319 }
00320 virtual ~ImageRegionCopier() {}
00321 };
00322
00323
00326 template<unsigned int D1, unsigned int D2>
00327 std::ostream & operator<<(std::ostream &os, const ImageRegionCopier<D1, D2> &
00328 copier)
00329 {
00330 os << "ImageRegionCopier: "
00331 << typeid(ImageRegionCopier<D1, D2>).name() << std::endl;
00332 return os;
00333 }
00334
00336 template<unsigned int D1, unsigned int D2>
00337 bool operator!=(const ImageRegionCopier<D1, D2> &c1,
00338 const ImageRegionCopier<D1, D2> &c2)
00339 {
00340 return &c1 != &c2;
00341 }
00342
00343 }
00344
00345 }
00346
00347
00348
00349
00350
00351 #endif