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-12-18 19:56:48 $
00007   Version:   $Revision: 1.37 $
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<IndexValueType>(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( Math::RoundHalfIntegerUp<IndexValueType>(index[i]) < static_cast<IndexValueType>( 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<IndexValueType>(m_Size[i]) - 1);
00222 #endif
00223 
00224 
00225       if( index[i] > bound )
00226         {
00227         return false;
00228         }
00229       }
00230     return true;
00231     }
00232 
00237   bool
00238   IsInside(const Self &region) const
00239     {
00240     IndexType beginCorner = region.GetIndex();
00241     if( ! this->IsInside( beginCorner ) )
00242       {
00243       return false;
00244       }
00245     IndexType endCorner;
00246     SizeType  size = region.GetSize();
00247     for(unsigned int i=0; i<ImageDimension; i++)
00248       {
00249       endCorner[i] = beginCorner[i] + size[i] - 1;
00250       }
00251     if( ! this->IsInside( endCorner ) )
00252       {
00253       return false;
00254       }
00255     return true;
00256     }
00258 
00261   SizeValueType GetNumberOfPixels() const;
00262 
00266   void PadByRadius(IndexValueType radius);
00267   void PadByRadius(const IndexValueArrayType radius);
00268   void PadByRadius(const SizeType &radius);
00270 
00275   bool Crop(const Self& region);
00276 
00280   SliceRegion Slice(const unsigned long dim) const;
00281 
00282 protected:
00287   virtual void PrintSelf(std::ostream& os, Indent indent) const;
00288 
00289 private:
00290   IndexType           m_Index;
00291   SizeType            m_Size;
00292 
00294   friend class ImageBase<VImageDimension>;
00295 };
00296 
00297 
00298 template<unsigned int VImageDimension>
00299 std::ostream & operator<<(std::ostream &os, const ImageRegion<VImageDimension> &region);
00300 
00301 } // end namespace itk
00302 
00303 // Define instantiation macro for this template.
00304 #define ITK_TEMPLATE_ImageRegion(_, EXPORT, x, y) namespace itk { \
00305   _(1(class EXPORT ImageRegion< ITK_TEMPLATE_1 x >)) \
00306   _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00307                                       const ImageRegion< ITK_TEMPLATE_1 x >&))) \
00308   namespace Templates { typedef ImageRegion< ITK_TEMPLATE_1 x > ImageRegion##y; } \
00309   }
00310 
00311 #if ITK_TEMPLATE_EXPLICIT
00312 # include "Templates/itkImageRegion+-.h"
00313 #endif
00314 
00315 #if ITK_TEMPLATE_TXX
00316 # include "itkImageRegion.txx"
00317 #endif
00318 
00319 #endif
00320 

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