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: 2002/05/01 16:43:34 $
00007   Version:   $Revision: 1.4 $
00008 
00009   Copyright (c) 2002 Insight 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
00261     for (; dim < D1; ++dim)
00262       {
00263       destIndex[dim] = 0;
00264       destSize[dim] = 0;
00265       }
00266     
00267     destRegion.SetIndex(destIndex);
00268     destRegion.SetSize(destSize);
00269   }
00270 
00271 
00314   template <unsigned int D1, unsigned int D2>
00315     class ITK_EXPORT ImageRegionCopier 
00316   {
00317   public:
00318     virtual void operator() (ImageRegion<D1> &destRegion,
00319                             const ImageRegion<D2> &srcRegion) const
00320     {
00321       ImageToImageFilterDefaultCopyRegion<D1, D2>(
00322                       BinaryUnsignedIntDispatch<D1, D2>::ComparisonType(),
00323                       destRegion, srcRegion);
00324     }
00325   };
00326 
00327 
00330   template<unsigned int D1, unsigned int D2>
00331   std::ostream & operator<<(std::ostream &os, const ImageRegionCopier<D1, D2> &
00332                             copier)
00333   {
00334     os << "ImageRegionCopier: "
00335        << typeid(ImageRegionCopier<D1, D2>).name() << std::endl;
00336     return os;
00337   }
00338 
00340   template<unsigned int D1, unsigned int D2>
00341   bool operator!=(const ImageRegionCopier<D1, D2> &c1,
00342                   const ImageRegionCopier<D1, D2> &c2)
00343   {
00344     return &c1 != &c2;
00345   }
00346   
00347 } // end of namespace ImageToImageFilterDetail
00348     
00349 } // end namespace itk
00350 
00351 //#ifndef ITK_MANUAL_INSTANTIATION
00352 //#include "itkImageToImageFilterDetail.txx"
00353 //#endif
00354 
00355 #endif

Generated at Wed Mar 12 01:13:02 2003 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000