Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkSize.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkSize.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-03-03 15:09:26 $
00007   Version:   $Revision: 1.24 $
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 __itkSize_h
00018 #define __itkSize_h
00019 
00020 #include "itkMacro.h"
00021 
00022 namespace itk
00023 {
00024 
00045 template<unsigned int VDimension=2>
00046 class Size {
00047 public:
00049   typedef Size  Self;
00050 
00052   typedef   Size<VDimension>  SizeType;
00053   typedef   unsigned long     SizeValueType;
00054 
00056   static unsigned int GetSizeDimension(void) { return VDimension; }
00057 
00059   const Self
00060   operator+(const Self &vec) const
00061     {
00062     Self result;
00063     for (unsigned int i=0; i < VDimension; i++)
00064       { result[i] = m_Size[i] + vec.m_Size[i]; }
00065     return result;
00066     }
00068 
00070   const Self &
00071   operator+=(const Self &vec)
00072     {
00073     for (unsigned int i=0; i < VDimension; i++)
00074       { m_Size[i] += vec.m_Size[i]; }
00075     return *this;
00076     }
00078 
00080   const Self
00081   operator-(const Self &vec) const
00082     {
00083     Self result;
00084     for (unsigned int i=0; i < VDimension; i++)
00085       { result[i] = m_Size[i] - vec.m_Size[i]; }
00086     return result;
00087     }
00089 
00091   const Self &
00092   operator-=(const Self &vec)
00093     {
00094     for (unsigned int i=0; i < VDimension; i++)
00095       { m_Size[i] -= vec.m_Size[i]; }
00096     return *this;
00097     }
00099 
00101   const Self
00102   operator*(const Self &vec) const
00103     {
00104     Self result;
00105     for (unsigned int i=0; i < VDimension; i++)
00106       { result[i] = m_Size[i] * vec.m_Size[i]; }
00107     return result;
00108     }
00110 
00112   const Self &
00113   operator*=(const Self &vec)
00114     {
00115     for (unsigned int i=0; i < VDimension; i++)
00116       { m_Size[i] *= vec.m_Size[i]; }
00117     return *this;
00118     }
00120 
00122   bool
00123   operator==(const Self &vec) const
00124     {
00125     bool same=1;
00126     for (unsigned int i=0; i < VDimension && same; i++)
00127       { same = (m_Size[i] == vec.m_Size[i]); }
00128     return same;
00129     }
00131 
00133   bool
00134   operator!=(const Self &vec) const
00135     {
00136     bool same=1;
00137     for (unsigned int i=0; i < VDimension && same; i++)
00138       { same = (m_Size[i] == vec.m_Size[i]); }
00139     return !same;
00140     }
00142 
00145   SizeValueType & operator[](unsigned int dim)
00146     { return m_Size[dim]; }
00147 
00151   SizeValueType operator[](unsigned int dim) const
00152     { return m_Size[dim]; }
00153 
00156   const SizeValueType *GetSize() const { return m_Size; }
00157 
00161   void SetSize(const SizeValueType val[VDimension])
00162     { memcpy(m_Size, val, sizeof(SizeValueType)*VDimension); }
00163 
00170   void SetElement(unsigned long element, SizeValueType val )
00171     { m_Size[ element ] = val;  }
00172 
00179   SizeValueType GetElement( unsigned long element ) const
00180     { return m_Size[ element ]; }
00181 
00184   void Fill(SizeValueType value)
00185     { for(unsigned int i=0;i < VDimension; ++i) m_Size[i] = value; }
00186 
00197   SizeValueType m_Size[VDimension];
00199 
00200 
00201 // force gccxml to find the constructors found before the internal upgrade to gcc 4.2
00202 #if defined(CABLE_CONFIGURATION)
00203   Size(); //purposely not implemented
00204   Size(const Self&); //purposely not implemented
00205   void operator=(const Self&); //purposely not implemented
00206 #endif
00207 
00208 };
00209 
00210 
00211 template<unsigned int VDimension>
00212 std::ostream & operator<<(std::ostream &os, const Size<VDimension> &size)
00213 {
00214   os << "[";
00215   for (unsigned int i=0; i+1 < VDimension; ++i)
00216     {
00217     os << size[i] << ", ";
00218     }
00219   if (VDimension >= 1)
00220     {
00221     os << size[VDimension-1];
00222     }
00223   os << "]";
00224   return os;
00225 }
00226 
00227 } // end namespace itk
00228 
00229 #endif 
00230 

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