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: 2009-07-12 23:19:57 $
00007   Version:   $Revision: 1.35 $
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 #include "vnl/vnl_math.h"
00029 
00030 namespace itk
00031 {
00032 // Forward declaration of ImageBase so it can be declared a friend
00033 // (needed for PrintSelf mechanism)
00034 template <unsigned int VImageDimension> class ImageBase;
00035 
00036 
00054 template <unsigned int VImageDimension>
00055 class ITK_EXPORT ImageRegion: public Region
00056 {
00057 public:
00059   typedef ImageRegion             Self;
00060   typedef Region                  Superclass;
00061 
00063   itkTypeMacro(ImageRegion, Region);
00064 
00066   itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
00067 
00070   itkStaticConstMacro(SliceDimension, unsigned int,
00071                       (ImageDimension - (ImageDimension > 1)));
00072 
00074   static unsigned int GetImageDimension()
00075     { return ImageDimension; }
00076 
00078   typedef Index< itkGetStaticConstMacro( ImageDimension) >  IndexType;
00079   typedef typename IndexType::IndexValueType                IndexValueType;
00080   typedef IndexValueType                          IndexValueArrayType[ ImageDimension];
00081   typedef typename IndexType::OffsetType          OffsetType;
00082   typedef typename OffsetType::OffsetValueType    OffsetValueType;
00083 
00085   typedef Size< itkGetStaticConstMacro( ImageDimension ) >  SizeType;
00086   typedef typename SizeType::SizeValueType                  SizeValueType;
00087 
00089   typedef ImageRegion<itkGetStaticConstMacro(SliceDimension)> SliceRegion;
00090 
00092   virtual typename Superclass::RegionType GetRegionType() const
00093     {return Superclass::ITK_STRUCTURED_REGION;}
00094 
00097   ImageRegion();
00098 
00101   virtual ~ImageRegion();
00102 
00105   ImageRegion(const Self& region): Region(region), m_Index( region.m_Index ), m_Size( region.m_Size ) {}
00106 
00109   ImageRegion(const IndexType &index, const SizeType &size)
00110     { m_Index = index; m_Size = size; };
00111 
00115   ImageRegion(const SizeType &size)
00116     { m_Size = size; m_Index.Fill(0); }
00117 
00120   void operator=(const Self& region)
00121     { m_Index = region.m_Index;  m_Size = region.m_Size; };
00122 
00124   void SetIndex(const IndexType &index)
00125     { m_Index = index; };
00126 
00128   const IndexType& GetIndex() const
00129     { return m_Index; };
00130 
00133   void SetSize(const SizeType &size)
00134     { m_Size = size; };
00135 
00137   const SizeType& GetSize() const
00138     { return m_Size; }
00139 
00141   void SetSize(unsigned long i, SizeValueType sze)
00142     { m_Size[i] = sze; }
00143   SizeValueType GetSize(unsigned long i) const
00144     { return m_Size[i]; }
00146 
00148   void SetIndex(unsigned long i, IndexValueType sze)
00149     { m_Index[i] = sze; }
00150   IndexValueType GetIndex(unsigned long i) const
00151     { return m_Index[i]; }
00153 
00155   bool
00156   operator==(const Self &region) const
00157     {
00158     bool same = 1;
00159     same = (m_Index == region.m_Index);
00160     same = same && (m_Size == region.m_Size);
00161     return same;
00162     }
00164 
00166   bool
00167   operator!=(const Self &region) const
00168     {
00169     bool same = 1;
00170     same = (m_Index == region.m_Index);
00171     same = same && (m_Size == region.m_Size);
00172     return !same;
00173     }
00175 
00176 
00178   bool
00179   IsInside(const IndexType &index) const
00180     {
00181     for(unsigned int i=0; i<ImageDimension; i++)
00182       {
00183       if( index[i] < m_Index[i] )
00184         {
00185         return false;
00186         }
00187       if( index[i] >= (m_Index[i] + static_cast<long>(m_Size[i])) )
00188         {
00189         return false;
00190         }
00191       }
00192     return true;
00193     }
00195 
00201   template <typename TCoordRepType>
00202   bool
00203   IsInside(const ContinuousIndex<TCoordRepType,VImageDimension> &index) const
00204     {
00205     for(unsigned int i=0; i<ImageDimension; i++)
00206       {
00207 #ifdef ITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY
00208       if( itk::Math::RoundHalfIntegerUp(index[i]) < static_cast<int>( m_Index[i] ) )
00209 #else
00210       if( index[i] < static_cast<TCoordRepType>( m_Index[i] ) )
00211 #endif
00212         {
00213         return false;
00214         }
00215       // bound is the last valid pixel location
00216 #ifdef ITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY
00217       const TCoordRepType bound = static_cast<TCoordRepType>(
00218          m_Index[i] + m_Size[i] - 0.5);
00219 #else
00220       const TCoordRepType bound = static_cast<TCoordRepType>(
00221          m_Index[i] + static_cast<long>(m_Size[i]) - 1);
00222 #endif
00223 
00224 
00225       if( index[i] > bound )
00226         {
00227         return false;
00228         }
00229       }
00230     return true;
00231     }
00232 
00234   bool
00235   IsInside(const Self &region) const
00236     {
00237     IndexType beginCorner = region.GetIndex();
00238     if( ! this->IsInside( beginCorner ) )
00239       {
00240       return false;
00241       }
00242     IndexType endCorner;
00243     SizeType  size = region.GetSize();
00244     for(unsigned int i=0; i<ImageDimension; i++)
00245       {
00246       endCorner[i] = beginCorner[i] + size[i] - 1;
00247       }
00248     if( ! this->IsInside( endCorner ) )
00249       {
00250       return false;
00251       }
00252     return true;
00253     }
00255 
00258   SizeValueType GetNumberOfPixels() const;
00259 
00263   void PadByRadius(IndexValueType radius);
00264   void PadByRadius(const IndexValueArrayType radius);
00265   void PadByRadius(const SizeType &radius);
00267 
00272   bool Crop(const Self& region);
00273 
00277   SliceRegion Slice(const unsigned long dim) const;
00278 
00279 protected:
00284   virtual void PrintSelf(std::ostream& os, Indent indent) const;
00285 
00286 private:
00287   IndexType           m_Index;
00288   SizeType            m_Size;
00289 
00291   friend class ImageBase<VImageDimension>;
00292 };
00293 
00294 
00295 template<unsigned int VImageDimension>
00296 std::ostream & operator<<(std::ostream &os, const ImageRegion<VImageDimension> &region);
00297 
00298 } // end namespace itk
00299 
00300 // Define instantiation macro for this template.
00301 #define ITK_TEMPLATE_ImageRegion(_, EXPORT, x, y) namespace itk { \
00302   _(1(class EXPORT ImageRegion< ITK_TEMPLATE_1 x >)) \
00303   _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00304                                       const ImageRegion< ITK_TEMPLATE_1 x >&))) \
00305   namespace Templates { typedef ImageRegion< ITK_TEMPLATE_1 x > ImageRegion##y; } \
00306   }
00307 
00308 #if ITK_TEMPLATE_EXPLICIT
00309 # include "Templates/itkImageRegion+-.h"
00310 #endif
00311 
00312 #if ITK_TEMPLATE_TXX
00313 # include "itkImageRegion.txx"
00314 #endif
00315 
00316 #endif
00317 

Generated at Tue Sep 15 03:23:31 2009 for ITK by doxygen 1.5.8 written by Dimitri van Heesch, © 1997-2000