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-05-13 15:27:49 $
00007   Version:   $Revision: 1.32 $
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                       (VImageDimension - (VImageDimension > 1)));
00072 
00074   static unsigned int GetImageDimension()
00075     { return VImageDimension; }
00076 
00078   typedef Index<VImageDimension>                  IndexType;
00079   typedef typename IndexType::IndexValueType      IndexValueType;
00080 
00082   typedef Size<VImageDimension>                   SizeType;
00083   typedef typename SizeType::SizeValueType        SizeValueType;
00084 
00086   typedef ImageRegion<itkGetStaticConstMacro(SliceDimension)> SliceRegion;
00087 
00089   virtual typename Superclass::RegionType GetRegionType() const
00090     {return Superclass::ITK_STRUCTURED_REGION;}
00091 
00094   ImageRegion();
00095 
00098   virtual ~ImageRegion();
00099 
00102   ImageRegion(const Self& region): Region(region), m_Index( region.m_Index ), m_Size( region.m_Size ) {}
00103 
00106   ImageRegion(const IndexType &index, const SizeType &size)
00107     { m_Index = index; m_Size = size; };
00108 
00112   ImageRegion(const SizeType &size)
00113     { m_Size = size; m_Index.Fill(0); }
00114 
00117   void operator=(const Self& region)
00118     { m_Index = region.m_Index;  m_Size = region.m_Size; };
00119 
00121   void SetIndex(const IndexType &index)
00122     { m_Index = index; };
00123 
00125   const IndexType& GetIndex() const
00126     { return m_Index; };
00127 
00130   void SetSize(const SizeType &size)
00131     { m_Size = size; };
00132 
00134   const SizeType& GetSize() const
00135     { return m_Size; }
00136 
00138   void SetSize(unsigned long i, SizeValueType sze)
00139     { m_Size[i] = sze; }
00140   SizeValueType GetSize(unsigned long i) const
00141     { return m_Size[i]; }
00143 
00145   void SetIndex(unsigned long i, IndexValueType sze)
00146     { m_Index[i] = sze; }
00147   IndexValueType GetIndex(unsigned long i) const
00148     { return m_Index[i]; }
00150 
00152   bool
00153   operator==(const Self &region) const
00154     {
00155     bool same = 1;
00156     same = (m_Index == region.m_Index);
00157     same = same && (m_Size == region.m_Size);
00158     return same;
00159     }
00161 
00163   bool
00164   operator!=(const Self &region) const
00165     {
00166     bool same = 1;
00167     same = (m_Index == region.m_Index);
00168     same = same && (m_Size == region.m_Size);
00169     return !same;
00170     }
00172 
00173 
00175   bool
00176   IsInside(const IndexType &index) const
00177     {
00178     for(unsigned int i=0; i<ImageDimension; i++)
00179       {
00180       if( index[i] < m_Index[i] )
00181         {
00182         return false;
00183         }
00184       if( index[i] >= (m_Index[i] + static_cast<long>(m_Size[i])) )
00185         {
00186         return false;
00187         }
00188       }
00189     return true;
00190     }
00192 
00198   template <typename TCoordRepType>
00199   bool
00200   IsInside(const ContinuousIndex<TCoordRepType,VImageDimension> &index) const
00201     {
00202     for(unsigned int i=0; i<ImageDimension; i++)
00203       {
00204 #ifdef ITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY
00205       if( itk::Math::RoundHalfIntegerUp(index[i]) < static_cast<int>( m_Index[i] ) )
00206 #else
00207       if( index[i] < static_cast<TCoordRepType>( m_Index[i] ) )
00208 #endif
00209         {
00210         return false;
00211         }
00212       // bound is the last valid pixel location
00213 #ifdef ITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY
00214       const TCoordRepType bound = static_cast<TCoordRepType>(
00215          m_Index[i] + m_Size[i] - 0.5);
00216 #else
00217       const TCoordRepType bound = static_cast<TCoordRepType>(
00218          m_Index[i] + static_cast<long>(m_Size[i]) - 1);
00219 #endif
00220 
00221 
00222       if( index[i] > bound )
00223         {
00224         return false;
00225         }
00226       }
00227     return true;
00228     }
00229 
00231   bool
00232   IsInside(const Self &region) const
00233     {
00234     IndexType beginCorner = region.GetIndex();
00235     if( ! this->IsInside( beginCorner ) )
00236       {
00237       return false;
00238       }
00239     IndexType endCorner;
00240     SizeType  size = region.GetSize();
00241     for(unsigned int i=0; i<ImageDimension; i++)
00242       {
00243       endCorner[i] = beginCorner[i] + size[i] - 1;
00244       }
00245     if( ! this->IsInside( endCorner ) )
00246       {
00247       return false;
00248       }
00249     return true;
00250     }
00252 
00255   unsigned long GetNumberOfPixels() const;
00256 
00260   void PadByRadius(unsigned long radius);
00261   void PadByRadius(const unsigned long radius[VImageDimension]);
00262   void PadByRadius(const SizeType &radius);
00264 
00269   bool Crop(const Self& region);
00270 
00274   SliceRegion Slice(const unsigned long dim) const;
00275 
00276 protected:
00281   virtual void PrintSelf(std::ostream& os, Indent indent) const;
00282 
00283 private:
00284   IndexType           m_Index;
00285   SizeType            m_Size;
00286 
00288   friend class ImageBase<VImageDimension>;
00289 };
00290 
00291 
00292 template<unsigned int VImageDimension>
00293 std::ostream & operator<<(std::ostream &os, const ImageRegion<VImageDimension> &region);
00294 
00295 } // end namespace itk
00296 
00297 // Define instantiation macro for this template.
00298 #define ITK_TEMPLATE_ImageRegion(_, EXPORT, x, y) namespace itk { \
00299   _(1(class EXPORT ImageRegion< ITK_TEMPLATE_1 x >)) \
00300   _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00301                                       const ImageRegion< ITK_TEMPLATE_1 x >&))) \
00302   namespace Templates { typedef ImageRegion< ITK_TEMPLATE_1 x > ImageRegion##y; } \
00303   }
00304 
00305 #if ITK_TEMPLATE_EXPLICIT
00306 # include "Templates/itkImageRegion+-.h"
00307 #endif
00308 
00309 #if ITK_TEMPLATE_TXX
00310 # include "itkImageRegion.txx"
00311 #endif
00312 
00313 #endif
00314 

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