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: 2003/09/10 14:29:34 $
00007   Version:   $Revision: 1.9 $
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 "itkRegion.h"
00021 #include "itkObjectFactory.h"
00022 
00023 namespace itk
00024 {
00025 
00043 class ITK_EXPORT ImageIORegion: public Region
00044 {
00045 public:
00047   typedef ImageIORegion Self;
00048   typedef Region        Superclass;
00049 
00051   itkTypeMacro(ImageIORegion, Region);
00052 
00054   unsigned int GetImageDimension() const
00055   { return m_ImageDimension; }
00056 
00060   unsigned int GetRegionDimension() const
00061   { 
00062     unsigned long dim=0;
00063     for (unsigned long i=0; i<m_ImageDimension; i++)
00064       {
00065       if ( m_Size[i] > 1 ) dim++;
00066       }
00067     return dim;
00068   }
00069 
00071   typedef std::vector<long>  IndexType;
00072 
00074   typedef std::vector<long>  SizeType;
00075   
00077   virtual Superclass::RegionType GetRegionType() const
00078   {return Superclass::ITK_STRUCTURED_REGION;}
00079 
00082   ImageIORegion(unsigned int dimension)
00083   {
00084     m_ImageDimension = dimension;
00085     m_Index.resize(m_ImageDimension);
00086     m_Size.resize(m_ImageDimension);
00087     std::fill(m_Index.begin(), m_Index.end(), 0);
00088     std::fill(m_Size.begin(), m_Size.end(), 0);
00089   }
00090   
00093   ImageIORegion()
00094   {
00095     m_ImageDimension = 2;
00096     m_Index.resize(2);
00097     m_Size.resize(2);
00098     std::fill(m_Index.begin(), m_Index.end(), 0);
00099     std::fill(m_Size.begin(), m_Size.end(), 0);
00100   }
00101   
00104   virtual ~ImageIORegion(){};
00105 
00108   ImageIORegion(const Self& region): Region()
00109   { 
00110     m_Index =region.m_Index; 
00111     m_Size = region.m_Size; 
00112     m_ImageDimension = region.m_ImageDimension;
00113   }
00114   
00117   void operator=(const Self& region) 
00118   { 
00119     m_Index = region.m_Index;  
00120     m_Size = region.m_Size;
00121     m_ImageDimension = region.m_ImageDimension;
00122   };
00123 
00125   void SetIndex(const IndexType &index) 
00126   { m_Index = index; };
00127 
00129   const IndexType& GetIndex() const
00130   { return m_Index; };
00131   
00134   void SetSize(const SizeType &size)
00135   { m_Size = size; };
00136 
00138   const SizeType& GetSize() const
00139   { return m_Size;}
00140 
00144   long GetSize(unsigned long i) const
00145   { return m_Size[i]; }
00146   long GetIndex(unsigned long i) const
00147   { return m_Index[i]; }
00148   void SetSize(const unsigned long i, long size)
00149   {m_Size[i] = size;}
00150   void SetIndex(const unsigned long i, long idx)
00151   {m_Index[i] = idx;}
00152 
00154   bool
00155   operator==(const Self &region) const
00156   {
00157     bool same = 1;
00158     same = (m_Index == region.m_Index);
00159     same = same && (m_Size == region.m_Size);
00160     same = same && (m_ImageDimension == region.m_ImageDimension);
00161     return same;
00162   }
00163 
00165   bool
00166   operator!=(const Self &region) const
00167   {
00168     bool same = 1;
00169     same = (m_Index == region.m_Index);
00170     same = same && (m_Size == region.m_Size);
00171     same = same && (m_ImageDimension == region.m_ImageDimension);
00172     return !same;
00173   }
00174   
00176   bool
00177   IsInside(const IndexType &index) const
00178   {
00179     for(unsigned int i=0; i<m_ImageDimension; i++)
00180       {
00181       if( index[i] < m_Index[i] ) 
00182         {
00183         return false;
00184         }
00185       if( index[i] >= m_Index[i] + m_Size[i] ) 
00186         {
00187         return false;
00188         }
00189       }
00190     return true;
00191   }
00192  
00195   unsigned long GetNumberOfPixels() const;
00196 
00197 protected:
00198 
00199 private:
00200   unsigned int m_ImageDimension;
00201   std::vector<long> m_Index;
00202   std::vector<long> m_Size;
00203 };
00204 
00205 
00206 inline std::ostream & operator<<(std::ostream &os, const ImageIORegion &region)
00207 {
00208   os << "Dimension: " << region.GetImageDimension() << std::endl;
00209   os << "Index: ";
00210   for(ImageIORegion::IndexType::const_iterator i = region.GetIndex().begin();
00211       i != region.GetIndex().end(); ++i)
00212     {
00213     os << *i << " ";
00214     }
00215   os << std::endl;
00216   os << "Index: ";
00217   for(ImageIORegion::SizeType::const_iterator k = region.GetSize().begin();
00218       k != region.GetSize().end(); ++k)
00219     {
00220     os << *k << " ";
00221     }
00222   os << std::endl;
00223   return os;
00224 }
00225 
00226 } // end namespace itk
00227 
00228 #endif
00229 

Generated at Tue Sep 16 11:32:01 2003 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000