itkImageToImageFilterDetail.h
Go to the documentation of this file.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 {
00039
00048 struct DispatchBase {};
00049
00057 template <bool>
00058 struct BooleanDispatch {};
00059
00068 template <int>
00069 struct IntDispatch : public DispatchBase {};
00070
00085 template <unsigned int>
00086 struct UnsignedIntDispatch : public DispatchBase {};
00088
00096 template <bool B1, bool B2>
00097 struct BinaryBooleanDispatch
00098 {
00099
00102 typedef BooleanDispatch<B1> FirstType;
00103 typedef BooleanDispatch<B2> SecondType;
00104 };
00105
00112 template <int D1, int D2>
00113 struct BinaryIntDispatch
00114 {
00115
00118 typedef IntDispatch<D1> FirstType;
00119 typedef IntDispatch<D2> SecondType;
00120 };
00121
00133 template <unsigned int D1, unsigned int D2>
00134 struct BinaryUnsignedIntDispatch : public DispatchBase
00135 {
00136
00139 typedef UnsignedIntDispatch<D1> FirstType;
00140 typedef UnsignedIntDispatch<D2> SecondType;
00141
00157 typedef IntDispatch<(D1 > D2) - (D1 < D2)> ComparisonType;
00158 typedef IntDispatch<0> FirstEqualsSecondType;
00159 typedef IntDispatch<1> FirstGreaterThanSecondType;
00160 typedef IntDispatch<-1> FirstLessThanSecondType;
00161 };
00162
00179 template <unsigned int D1, unsigned int D2>
00180 void ImageToImageFilterDefaultCopyRegion(const typename
00181 BinaryUnsignedIntDispatch<D1, D2>::FirstEqualsSecondType &,
00182 ImageRegion<D1> &destRegion,
00183 const ImageRegion<D2> &srcRegion)
00184 {
00185 destRegion = srcRegion;
00186 }
00187
00204 template <unsigned int D1, unsigned int D2>
00205 void ImageToImageFilterDefaultCopyRegion(const typename
00206 BinaryUnsignedIntDispatch<D1, D2>::FirstLessThanSecondType &,
00207 ImageRegion<D1> &destRegion,
00208 const ImageRegion<D2> &srcRegion)
00209 {
00210
00211
00212 unsigned int dim;
00213 Index<D1> destIndex;
00214 Size<D1> destSize;
00215 const Index<D2> &srcIndex = srcRegion.GetIndex();
00216 const Size<D2> &srcSize = srcRegion.GetSize();
00218
00219
00220 for (dim=0; dim < D1; ++dim)
00221 {
00222 destIndex[dim] = srcIndex[dim];
00223 destSize[dim] = srcSize[dim];
00224 }
00225
00226 destRegion.SetIndex(destIndex);
00227 destRegion.SetSize(destSize);
00228 }
00229
00246 template <unsigned int D1, unsigned int D2>
00247 void ImageToImageFilterDefaultCopyRegion(const typename
00248 BinaryUnsignedIntDispatch<D1, D2>::FirstGreaterThanSecondType &,
00249 ImageRegion<D1> &destRegion,
00250 const ImageRegion<D2> &srcRegion)
00251 {
00252
00253
00254 unsigned int dim;
00255 Index<D1> destIndex;
00256 Size<D1> destSize;
00257 const Index<D2> &srcIndex = srcRegion.GetIndex();
00258 const Size<D2> &srcSize = srcRegion.GetSize();
00260
00261
00262 for (dim=0; dim < D2; ++dim)
00263 {
00264 destIndex[dim] = srcIndex[dim];
00265 destSize[dim] = srcSize[dim];
00266 }
00267
00268 for (; dim < D1; ++dim)
00269 {
00270 destIndex[dim] = 0;
00271 destSize[dim] = 1;
00272 }
00273
00274 destRegion.SetIndex(destIndex);
00275 destRegion.SetSize(destSize);
00276 }
00277
00278
00315 template <unsigned int D1, unsigned int D2>
00316 class ITK_EXPORT ImageRegionCopier
00317 {
00318 public:
00319 virtual void operator() (ImageRegion<D1> &destRegion,
00320 const ImageRegion<D2> &srcRegion) const
00321 {
00322 typedef typename BinaryUnsignedIntDispatch<D1, D2>::ComparisonType ComparisonType;
00323 ImageToImageFilterDefaultCopyRegion<D1, D2>(
00324 ComparisonType(),
00325 destRegion, srcRegion);
00326 }
00327 virtual ~ImageRegionCopier() {}
00328 };
00329
00330
00333 template<unsigned int D1, unsigned int D2>
00334 std::ostream & operator<<(std::ostream &os, const ImageRegionCopier<D1, D2> &
00335 copier)
00336 {
00337 os << "ImageRegionCopier: "
00338 << typeid(ImageRegionCopier<D1, D2>).name() << std::endl;
00339 return os;
00340 }
00342
00344 template<unsigned int D1, unsigned int D2>
00345 bool operator!=(const ImageRegionCopier<D1, D2> &c1,
00346 const ImageRegionCopier<D1, D2> &c2)
00347 {
00348 return &c1 != &c2;
00349 }
00350
00351 }
00352
00353 }
00354
00355
00356
00357
00358
00359 #endif
00360