Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkImageToImageFilterDetail.h

Go to the documentation of this file.
00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkImageToImageFilterDetail.h,v $ 00005 Language: C++ 00006 Date: $Date: 2003/09/10 14:29:13 $ 00007 Version: $Revision: 1.6 $ 00008 00009 Copyright (c) Insight Software Consortium. All rights reserved. 00010 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. 00011 00012 Portions of this code are covered under the VTK copyright. 00013 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. 00014 00015 This software is distributed WITHOUT ANY WARRANTY; without even 00016 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00017 PURPOSE. See the above copyright notices for more information. 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 // Source dimension is greater than the destination dimension, copy the 00206 // first part of the source into the destination 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 // copy what we can 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 // Source dimension is less than the destination dimension, copy source 00247 // into the first part of the destination and set zeros elsewhere. 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 // copy what we can 00255 for (dim=0; dim < D2; ++dim) 00256 { 00257 destIndex[dim] = srcIndex[dim]; 00258 destSize[dim] = srcSize[dim]; 00259 } 00260 // fill in the rest of the dimensions with zero/one 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 ImageToImageFilterDefaultCopyRegion<D1, D2>( 00316 BinaryUnsignedIntDispatch<D1, D2>::ComparisonType(), 00317 destRegion, srcRegion); 00318 } 00319 }; 00320 00321 00324 template<unsigned int D1, unsigned int D2> 00325 std::ostream & operator<<(std::ostream &os, const ImageRegionCopier<D1, D2> & 00326 copier) 00327 { 00328 os << "ImageRegionCopier: " 00329 << typeid(ImageRegionCopier<D1, D2>).name() << std::endl; 00330 return os; 00331 } 00332 00334 template<unsigned int D1, unsigned int D2> 00335 bool operator!=(const ImageRegionCopier<D1, D2> &c1, 00336 const ImageRegionCopier<D1, D2> &c2) 00337 { 00338 return &c1 != &c2; 00339 } 00340 00341 } // end of namespace ImageToImageFilterDetail 00342 00343 } // end namespace itk 00344 00345 //#ifndef ITK_MANUAL_INSTANTIATION 00346 //#include "itkImageToImageFilterDetail.txx" 00347 //#endif 00348 00349 #endif

Generated at Sat Mar 31 02:22:48 2007 for ITK by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2000