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-07-12 10:52:54 $
00007   Version:   $Revision: 1.25 $
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 size_t                  SizeValueType;
00062   typedef ptrdiff_t               IndexValueType;
00063   typedef ptrdiff_t               OffsetValueType;
00064 
00065 
00067   typedef std::vector<IndexValueType>  IndexType;
00068 
00070   typedef std::vector<SizeValueType>   SizeType;
00071 
00073   typedef Superclass::RegionType       RegionType;
00074 
00076   itkTypeMacro(ImageIORegion, Region);
00077 
00079   unsigned int GetImageDimension() const;
00080 
00084   unsigned int GetRegionDimension() const;
00085 
00087   virtual RegionType GetRegionType() const;
00088 
00091   ImageIORegion(unsigned int dimension);
00092 
00095   ImageIORegion();
00096 
00099   virtual ~ImageIORegion();
00100 
00103   ImageIORegion(const Self& region);
00104 
00107   void operator=(const Self& region);
00108 
00110   void SetIndex(const IndexType &index);
00111 
00113   const IndexType & GetIndex() const;
00114 
00117   void SetSize(const SizeType &size);
00118 
00120   const SizeType & GetSize() const;
00121 
00125   SizeValueType GetSize(unsigned long i) const;
00126   IndexValueType GetIndex(unsigned long i) const;
00127   void SetSize(const unsigned long i, SizeValueType size);
00128   void SetIndex(const unsigned long i, IndexValueType idx);
00130 
00132   bool operator==(const Self &region) const;
00133 
00135   bool operator!=(const Self &region) const;
00136 
00138   bool IsInside(const IndexType &index) const;
00139 
00141   bool IsInside(const Self &region) const;
00142 
00145   SizeValueType GetNumberOfPixels( void ) const;
00146 
00147 protected:
00152   virtual void PrintSelf(std::ostream& os, Indent indent) const;
00153 
00154 private:
00155   unsigned int      m_ImageDimension;
00156   IndexType         m_Index;
00157   SizeType          m_Size;
00158 };
00159 
00160 
00161 // Declare operator<<
00162 extern std::ostream & operator<<(std::ostream &os, const ImageIORegion &region); 
00163 
00168 template< unsigned int VDimension >
00169 class ImageIORegionAdaptor
00170 {
00171 public:
00172   typedef ImageRegion<VDimension>  ImageRegionType;
00173   typedef ImageIORegion            ImageIORegionType;
00174 
00175   typedef typename ImageRegionType::SizeType  ImageSizeType;
00176   typedef typename ImageRegionType::IndexType ImageIndexType;
00177 
00178   itkLegacyMacro(static void Convert( const ImageRegionType & outImageRegion, ImageIORegionType & inIORegion) );
00179 
00180   static void Convert( const ImageRegionType & inImageRegion, ImageIORegionType & outIORegion, const ImageIndexType &largestRegionIndex)
00181     {
00182     //
00183     // The ImageRegion and ImageIORegion objects may have different dimensions.
00184     // Here we only copy the common dimensions between the two. If the ImageRegion
00185     // has more dimensions than the ImageIORegion, then the defaults of the ImageRegion
00186     // will take care of the remaining codimension. If the ImageRegion has less dimensions
00187     // than the ImageIORegion, then the remaining IO dimensions are simply ignored.
00188     //
00189     const unsigned int ioDimension = outIORegion.GetImageDimension();
00190     const unsigned int imageDimension = VDimension;
00191 
00192     unsigned int minDimension = ( ioDimension > imageDimension ) ? imageDimension : ioDimension;
00193 
00194     ImageSizeType  size  = inImageRegion.GetSize();
00195     ImageIndexType index = inImageRegion.GetIndex();
00196     
00197     for( unsigned int i = 0; i < minDimension; i++ )
00198       {
00199       outIORegion.SetSize(  i, size[i] );
00200       outIORegion.SetIndex( i, index[i] - largestRegionIndex[i]);
00201       }
00202 
00203     //
00204     // Fill in the remaining codimension (if any) with default values
00205     //
00206     for( unsigned int k = minDimension; k < ioDimension; k++ )
00207       {
00208       outIORegion.SetSize(  k, 1 ); // Note that default size in IO is 1 not 0
00209       outIORegion.SetIndex( k, 0 );
00210       }
00211     }
00212 
00213   itkLegacyMacro(static void Convert( const ImageIORegionType & inIORegion, ImageRegionType & outImageRegion) );
00214   
00215 
00216   static void Convert( const ImageIORegionType & inIORegion, ImageRegionType & outImageRegion, const ImageIndexType &largestRegionIndex )
00217     {
00218     ImageSizeType  size;
00219     ImageIndexType index;
00220 
00221     size.Fill(1);  // initialize with default values
00222     index.Fill(0);
00223 
00224     //
00225     // The ImageRegion and ImageIORegion objects may have different dimensions.
00226     // Here we only copy the common dimensions between the two. If the ImageRegion
00227     // has more dimensions than the ImageIORegion, then the defaults of the ImageRegion
00228     // will take care of the remaining codimension. If the ImageRegion has less dimensions
00229     // than the ImageIORegion, then the remaining IO dimensions are simply ignored.
00230     //
00231     const unsigned int ioDimension = inIORegion.GetImageDimension();
00232     const unsigned int imageDimension = VDimension;
00233 
00234     unsigned int minDimension = ( ioDimension > imageDimension ) ? imageDimension : ioDimension;
00235 
00236     for(unsigned int i=0; i<minDimension; i++)
00237       {
00238       size[i]  = inIORegion.GetSize(i);
00239       index[i] = inIORegion.GetIndex(i) + largestRegionIndex[i];
00240       }
00241 
00242     outImageRegion.SetSize( size );
00243     outImageRegion.SetIndex( index );
00244     }
00245 };
00246 
00247 #if !defined(ITK_LEGACY_REMOVE)
00248 template< unsigned int VDimension >
00249 void ImageIORegionAdaptor<VDimension>::Convert( const ImageRegionType & inImageRegion, ImageIORegionType & outIORegion ) 
00250 {
00251   itkGenericLegacyBodyMacro(ImageIORegionAdaptor::Convert, 4.0);
00252   // the index argument is required
00253   ImageIndexType index;
00254   index.Fill(0);
00255   ImageIORegionAdaptor<VDimension>::Convert(inImageRegion, outIORegion, index);
00256 }
00257 
00258 template< unsigned int VDimension >
00259 void ImageIORegionAdaptor<VDimension>::Convert( const ImageIORegionType & inIORegion, ImageRegionType & outImageRegion )
00260 {
00261   itkGenericLegacyBodyMacro(ImageIORegionAdaptor::Convert, 4.0);
00262   // the index argument is required
00263   ImageIndexType index;
00264   index.Fill(0);
00265   ImageIORegionAdaptor<VDimension>::Convert(inIORegion, outImageRegion, index);
00266 }
00267 #endif
00268 
00269 } // end namespace itk
00270 
00271 #endif
00272 

Generated at Mon Jul 12 2010 18:36:35 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000