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

itkImageRegion.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkImageRegion.h,v $
00005   Language:  C++
00006   Date:      $Date: 2006-04-20 14:54:09 $
00007   Version:   $Revision: 1.28 $
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 __itkImageRegion_h
00021 #define __itkImageRegion_h
00022 
00023 #include "itkRegion.h"
00024 
00025 #include "itkIndex.h"
00026 #include "itkSize.h"
00027 #include "itkContinuousIndex.h"
00028 
00029 namespace itk
00030 {
00031 // Forward declaration of ImageBase so it can be declared a friend
00032 // (needed for PrintSelf mechanism)  
00033 template <unsigned int VImageDimension> class ImageBase;
00034 
00035   
00053 template <unsigned int VImageDimension>
00054 class ITK_EXPORT ImageRegion: public Region
00055 {
00056 public:
00058   typedef ImageRegion              Self;
00059   typedef Region  Superclass;
00060 
00062   itkTypeMacro(ImageRegion, Region);
00063 
00065   itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
00066 
00069   itkStaticConstMacro(SliceDimension, unsigned int,
00070                       (VImageDimension - (VImageDimension > 1)));
00071 
00073   static unsigned int GetImageDimension() 
00074     { return VImageDimension; }
00075 
00077   typedef Index<VImageDimension>  IndexType;
00078   typedef typename IndexType::IndexValueType IndexValueType;
00079 
00081   typedef Size<VImageDimension>  SizeType;
00082   typedef typename SizeType::SizeValueType SizeValueType;
00083 
00085   typedef ImageRegion<itkGetStaticConstMacro(SliceDimension)> SliceRegion;
00086 
00088   virtual typename Superclass::RegionType GetRegionType() const
00089     {return Superclass::ITK_STRUCTURED_REGION;}
00090 
00093   ImageRegion();
00094 
00097   virtual ~ImageRegion();
00098 
00101   ImageRegion(const Self& region): Region(region), m_Index( region.m_Index ), m_Size( region.m_Size ) {}
00102 
00105   ImageRegion(const IndexType &index, const SizeType &size)
00106     { m_Index = index; m_Size = size; };
00107 
00111   ImageRegion(const SizeType &size)
00112     { m_Size = size; m_Index.Fill(0); } ;
00113 
00116   void operator=(const Self& region) 
00117     { m_Index = region.m_Index;  m_Size = region.m_Size; };
00118 
00120   void SetIndex(const IndexType &index) 
00121     { m_Index = index; };
00122 
00124   const IndexType& GetIndex() const
00125     { return m_Index; };
00126 
00129   void SetSize(const SizeType &size)
00130     { m_Size = size; };
00131 
00133   const SizeType& GetSize() const
00134     { return m_Size; }
00135 
00137   void SetSize(unsigned long i, SizeValueType sze) 
00138     { m_Size[i] = sze; }
00139   SizeValueType GetSize(unsigned long i) const
00140     { return m_Size[i]; }
00142 
00144   void SetIndex(unsigned long i, IndexValueType sze) 
00145     { m_Index[i] = sze; }
00146   IndexValueType GetIndex(unsigned long i) const
00147     { return m_Index[i]; }
00149 
00151   bool
00152   operator==(const Self &region) const
00153     {
00154       bool same = 1;
00155       same = (m_Index == region.m_Index);
00156       same = same && (m_Size == region.m_Size);
00157       return same;
00158     }
00160 
00162   bool
00163   operator!=(const Self &region) const
00164     {
00165       bool same = 1;
00166       same = (m_Index == region.m_Index);
00167       same = same && (m_Size == region.m_Size);
00168       return !same;
00169     }
00171 
00172   
00174   bool
00175   IsInside(const IndexType &index) const
00176     {
00177       for(unsigned int i=0; i<ImageDimension; i++)
00178         {
00179         if( index[i] < m_Index[i] ) 
00180           {
00181           return false;
00182           }
00183         if( index[i] >= m_Index[i] + static_cast<long>(m_Size[i]) ) 
00184           {
00185           return false;
00186           }
00187         }
00188       return true;
00189     }
00191 
00193   template <typename TCoordRepType>
00194   bool
00195   IsInside(const ContinuousIndex<TCoordRepType,VImageDimension> &index) const
00196     {
00197       for(unsigned int i=0; i<ImageDimension; i++)
00198         {
00199         if( index[i] < static_cast<TCoordRepType>( m_Index[i] ) ) 
00200           {
00201           return false;
00202           }
00203         // bound is the last valid pixel location
00204         const TCoordRepType bound = static_cast<TCoordRepType>(
00205                               m_Index[i] + static_cast<long>(m_Size[i]) - 1);
00207 
00208         if( index[i] > bound )
00209           {
00210           return false;
00211           }
00212         }
00213       return true;
00214     }
00215  
00216 
00218   bool
00219   IsInside(const Self &region) const
00220     {
00221       IndexType beginCorner = region.GetIndex();
00222       if( ! this->IsInside( beginCorner ) )
00223         {
00224         return false;
00225         }
00226       IndexType endCorner;
00227       SizeType  size = region.GetSize();
00228       for(unsigned int i=0; i<ImageDimension; i++) 
00229         {
00230         endCorner[i] = beginCorner[i] + size[i] - 1;
00231         }
00232       if( ! this->IsInside( endCorner ) )
00233         {
00234         return false;
00235         }
00236       return true;
00237     }
00239 
00242   unsigned long GetNumberOfPixels() const;
00243 
00247   void PadByRadius(unsigned long radius);
00248   void PadByRadius(const unsigned long radius[VImageDimension]);
00249   void PadByRadius(const SizeType &radius);
00251 
00256   bool Crop(const Self& region);
00257 
00261   SliceRegion Slice(const unsigned long dim) const;
00262 
00263 protected:
00268   virtual void PrintSelf(std::ostream& os, Indent indent) const;
00269 
00270 private:
00271   IndexType           m_Index;
00272   SizeType            m_Size;
00273 
00275   friend class ImageBase<VImageDimension>;
00276 };
00277 
00278 
00279 template<unsigned int VImageDimension>
00280 std::ostream & operator<<(std::ostream &os, const ImageRegion<VImageDimension> &region);
00281 
00282 } // end namespace itk
00283 
00284 // Define instantiation macro for this template.
00285 #define ITK_TEMPLATE_ImageRegion(_, EXPORT, x, y) namespace itk { \
00286   _(1(class EXPORT ImageRegion< ITK_TEMPLATE_1 x >)) \
00287   _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00288                                       const ImageRegion< ITK_TEMPLATE_1 x >&))) \
00289   namespace Templates { typedef ImageRegion< ITK_TEMPLATE_1 x > ImageRegion##y; } \
00290   }
00291 
00292 #if ITK_TEMPLATE_EXPLICIT
00293 # include "Templates/itkImageRegion+-.h"
00294 #endif
00295 
00296 #if ITK_TEMPLATE_TXX
00297 # include "itkImageRegion.txx"
00298 #endif
00299 
00300 #endif
00301 
00302 

Generated at Mon Apr 14 12:57:40 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000