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/02/26 20:25:53 $
00007   Version:   $Revision: 1.6 $
00008 
00009   Copyright (c) 2002 Insight 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 
00058   typedef std::vector<long>  IndexType;
00059 
00061   typedef std::vector<long>  SizeType;
00062   
00064   virtual Superclass::RegionType GetRegionType() const
00065     {return Superclass::ITK_STRUCTURED_REGION;}
00066 
00069   ImageIORegion(unsigned int dimension)
00070     {
00071       m_ImageDimension = dimension;
00072       m_Index.resize(m_ImageDimension);
00073       m_Size.resize(m_ImageDimension);
00074       std::fill(m_Index.begin(), m_Index.end(), 0);
00075       std::fill(m_Size.begin(), m_Size.end(), 0);
00076     }
00077   
00080   ImageIORegion()
00081     {
00082       m_ImageDimension = 2;
00083       m_Index.resize(2);
00084       m_Size.resize(2);
00085       std::fill(m_Index.begin(), m_Index.end(), 0);
00086       std::fill(m_Size.begin(), m_Size.end(), 0);
00087     }
00088   
00091   virtual ~ImageIORegion(){};
00092 
00095   ImageIORegion(const Self& region): Region()
00096     { 
00097       m_Index =region.m_Index; 
00098       m_Size = region.m_Size; 
00099       m_ImageDimension = region.m_ImageDimension;
00100     }
00101   
00104   void operator=(const Self& region) 
00105     { 
00106       m_Index = region.m_Index;  
00107       m_Size = region.m_Size;
00108       m_ImageDimension = region.m_ImageDimension;
00109     };
00110 
00112   void SetIndex(const IndexType &index) 
00113     { m_Index = index; };
00114 
00116   const IndexType& GetIndex() const
00117     { return m_Index; };
00118   
00121   void SetSize(const SizeType &size)
00122     { m_Size = size; };
00123 
00125   const SizeType& GetSize() const
00126     { return m_Size;}
00127 
00129   void SetSize(const unsigned long i, long size)
00130     {m_Size[i] = size;}
00131   void SetIndex(const unsigned long i, long idx)
00132     {m_Index[i] = idx;}
00133 
00135   bool
00136   operator==(const Self &region) const
00137     {
00138       bool same = 1;
00139       same = (m_Index == region.m_Index);
00140       same = same && (m_Size == region.m_Size);
00141       same = same && (m_ImageDimension == region.m_ImageDimension);
00142       return same;
00143     }
00144 
00146   bool
00147   operator!=(const Self &region) const
00148     {
00149       bool same = 1;
00150       same = (m_Index == region.m_Index);
00151       same = same && (m_Size == region.m_Size);
00152       same = same && (m_ImageDimension == region.m_ImageDimension);
00153       return !same;
00154     }
00155   
00157   bool
00158   IsInside(const IndexType &index) const
00159     {
00160       for(unsigned int i=0; i<m_ImageDimension; i++)
00161         {
00162         if( index[i] < m_Index[i] ) 
00163           {
00164           return false;
00165           }
00166         if( index[i] >= m_Index[i] + m_Size[i] ) 
00167           {
00168           return false;
00169           }
00170         }
00171       return true;
00172     }
00173  
00176   unsigned long GetNumberOfPixels() const;
00177 
00178 protected:
00179 
00180 private:
00181   unsigned int m_ImageDimension;
00182   std::vector<long> m_Index;
00183   std::vector<long> m_Size;
00184 };
00185 
00186 
00187 inline std::ostream & operator<<(std::ostream &os, const ImageIORegion &region)
00188 {
00189   os << "Dimension: " << region.GetImageDimension() << std::endl;
00190   os << "Index: ";
00191   for(ImageIORegion::IndexType::const_iterator i = region.GetIndex().begin();
00192       i != region.GetIndex().end(); ++i)
00193     {
00194     os << *i << " ";
00195     }
00196   os << std::endl;
00197   os << "Index: ";
00198   for(ImageIORegion::SizeType::const_iterator k = region.GetSize().begin();
00199       k != region.GetSize().end(); ++k)
00200     {
00201     os << *k << " ";
00202     }
00203   os << std::endl;
00204   return os;
00205 }
00206 
00207 } // end namespace itk
00208 
00209 #endif
00210 

Generated at Fri May 21 01:14:53 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000