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

itkImageIORegion.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkImageIORegion.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-02-24 15:36:27 $
00007   Version:   $Revision: 1.23 $
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      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkImageIORegion_h
00018 #define __itkImageIORegion_h
00019 
00020 #include <algorithm>
00021 #include "itkRegion.h"
00022 #include "itkObjectFactory.h"
00023 #include "itkImageRegion.h"
00024 #include "itkIndex.h"
00025 #include "itkSize.h"
00026 
00027 namespace itk
00028 {
00029 
00053 class ITK_EXPORT ImageIORegion: public Region
00054 {
00055 public:
00057   typedef ImageIORegion Self;
00058   typedef Region        Superclass;
00059 
00061   typedef unsigned long           SizeValueType;
00062   typedef long                    IndexValueType;
00063 
00064 
00066   typedef std::vector<IndexValueType>  IndexType;
00067 
00069   typedef std::vector<SizeValueType>   SizeType;
00070 
00072   typedef Superclass::RegionType       RegionType;
00073 
00075   itkTypeMacro(ImageIORegion, Region);
00076 
00078   unsigned int GetImageDimension() const;
00079 
00083   unsigned int GetRegionDimension() const;
00084 
00086   virtual RegionType GetRegionType() const;
00087 
00090   ImageIORegion(unsigned int dimension);
00091 
00094   ImageIORegion();
00095 
00098   virtual ~ImageIORegion();
00099 
00102   ImageIORegion(const Self& region);
00103 
00106   void operator=(const Self& region);
00107 
00109   void SetIndex(const IndexType &index);
00110 
00112   const IndexType & GetIndex() const;
00113 
00116   void SetSize(const SizeType &size);
00117 
00119   const SizeType & GetSize() const;
00120 
00124   SizeValueType GetSize(unsigned long i) const;
00125   IndexValueType GetIndex(unsigned long i) const;
00126   void SetSize(const unsigned long i, SizeValueType size);
00127   void SetIndex(const unsigned long i, IndexValueType idx);
00129 
00131   bool operator==(const Self &region) const;
00132 
00134   bool operator!=(const Self &region) const;
00135 
00137   bool IsInside(const IndexType &index) const;
00138 
00140   bool IsInside(const Self &region) const;
00141 
00142 
00143 protected:
00148   virtual void PrintSelf(std::ostream& os, Indent indent) const;
00149 
00150 private:
00151   unsigned int      m_ImageDimension;
00152   IndexType         m_Index;
00153   SizeType          m_Size;
00154 };
00155 
00156 
00157 // Declare operator<<
00158 extern std::ostream & operator<<(std::ostream &os, const ImageIORegion &region); 
00159 
00164 template< unsigned int VDimension >
00165 class ImageIORegionAdaptor
00166 {
00167 public:
00168   typedef ImageRegion<VDimension>  ImageRegionType;
00169   typedef ImageIORegion            ImageIORegionType;
00170 
00171   typedef typename ImageRegionType::SizeType  ImageSizeType;
00172   typedef typename ImageRegionType::IndexType ImageIndexType;
00173 
00174   itkLegacyMacro(static void Convert( const ImageRegionType & outImageRegion, ImageIORegionType & inIORegion) );
00175 
00176   static void Convert( const ImageRegionType & inImageRegion, ImageIORegionType & outIORegion, const ImageIndexType &largestRegionIndex)
00177     {
00178     //
00179     // The ImageRegion and ImageIORegion objects may have different dimensions.
00180     // Here we only copy the common dimensions between the two. If the ImageRegion
00181     // has more dimensions than the ImageIORegion, then the defaults of the ImageRegion
00182     // will take care of the remaining codimension. If the ImageRegion has less dimensions
00183     // than the ImageIORegion, then the remaining IO dimensions are simply ignored.
00184     //
00185     const unsigned int ioDimension = outIORegion.GetImageDimension();
00186     const unsigned int imageDimension = VDimension;
00187 
00188     unsigned int minDimension = ( ioDimension > imageDimension ) ? imageDimension : ioDimension;
00189 
00190     ImageSizeType  size  = inImageRegion.GetSize();
00191     ImageIndexType index = inImageRegion.GetIndex();
00192     
00193     for( unsigned int i = 0; i < minDimension; i++ )
00194       {
00195       outIORegion.SetSize(  i, size[i] );
00196       outIORegion.SetIndex( i, index[i] - largestRegionIndex[i]);
00197       }
00198 
00199     //
00200     // Fill in the remaining codimension (if any) with default values
00201     //
00202     for( unsigned int k = minDimension; k < ioDimension; k++ )
00203       {
00204       outIORegion.SetSize(  k, 1 ); // Note that default size in IO is 1 not 0
00205       outIORegion.SetIndex( k, 0 );
00206       }
00207     }
00208 
00209   itkLegacyMacro(static void Convert( const ImageIORegionType & inIORegion, ImageRegionType & outImageRegion) );
00210   
00211 
00212   static void Convert( const ImageIORegionType & inIORegion, ImageRegionType & outImageRegion, const ImageIndexType &largestRegionIndex )
00213     {
00214     ImageSizeType  size;
00215     ImageIndexType index;
00216 
00217     size.Fill(1);  // initialize with default values
00218     index.Fill(0);
00219 
00220     //
00221     // The ImageRegion and ImageIORegion objects may have different dimensions.
00222     // Here we only copy the common dimensions between the two. If the ImageRegion
00223     // has more dimensions than the ImageIORegion, then the defaults of the ImageRegion
00224     // will take care of the remaining codimension. If the ImageRegion has less dimensions
00225     // than the ImageIORegion, then the remaining IO dimensions are simply ignored.
00226     //
00227     const unsigned int ioDimension = inIORegion.GetImageDimension();
00228     const unsigned int imageDimension = VDimension;
00229 
00230     unsigned int minDimension = ( ioDimension > imageDimension ) ? imageDimension : ioDimension;
00231 
00232     for(unsigned int i=0; i<minDimension; i++)
00233       {
00234       size[i]  = inIORegion.GetSize(i);
00235       index[i] = inIORegion.GetIndex(i) + largestRegionIndex[i];
00236       }
00237 
00238     outImageRegion.SetSize( size );
00239     outImageRegion.SetIndex( index );
00240     }
00241 };
00242 
00243 #if !defined(ITK_LEGACY_REMOVE)
00244 template< unsigned int VDimension >
00245 void ImageIORegionAdaptor<VDimension>::Convert( const ImageRegionType & inImageRegion, ImageIORegionType & outIORegion ) 
00246 {
00247   itkGenericLegacyBodyMacro(ImageIORegionAdaptor::Convert, 4.0);
00248   // the index argument is required
00249   ImageIndexType index;
00250   index.Fill(0);
00251   ImageIORegionAdaptor<VDimension>::Convert(inImageRegion, outIORegion, index);
00252 }
00253 
00254 template< unsigned int VDimension >
00255 void ImageIORegionAdaptor<VDimension>::Convert( const ImageIORegionType & inIORegion, ImageRegionType & outImageRegion )
00256 {
00257   itkGenericLegacyBodyMacro(ImageIORegionAdaptor::Convert, 4.0);
00258   // the index argument is required
00259   ImageIndexType index;
00260   index.Fill(0);
00261   ImageIORegionAdaptor<VDimension>::Convert(inIORegion, outImageRegion, index);
00262 }
00263 #endif
00264 
00265 } // end namespace itk
00266 
00267 #endif
00268 

Generated at Thu May 28 10:16:24 2009 for ITK by doxygen 1.5.5 written by Dimitri van Heesch, © 1997-2000