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: 2009-02-05 19:04:57 $
00007   Version:   $Revision: 1.9 $
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 {
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   // Source dimension is greater than the destination dimension, copy the
00211   // first part of the source into the destination
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   // copy what we can
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   // Source dimension is less than the destination dimension, copy source
00253   // into the first part of the destination and set zeros elsewhere.
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   // copy what we can
00262   for (dim=0; dim < D2; ++dim)
00263     {
00264     destIndex[dim] = srcIndex[dim];
00265     destSize[dim] = srcSize[dim];
00266     }
00267   // fill in the rest of the dimensions with zero/one
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 } // end of namespace ImageToImageFilterDetail
00352     
00353 } // end namespace itk
00354 
00355 //#ifndef ITK_MANUAL_INSTANTIATION
00356 //#include "itkImageToImageFilterDetail.txx"
00357 //#endif
00358 
00359 #endif
00360 

Generated at Fri Apr 16 18:43:16 2010 for ITK by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2000