00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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)
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)
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)
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
00202 #if defined(CABLE_CONFIGURATION)
00203 Size();
00204 Size(const Self&);
00205 void operator=(const Self&);
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 }
00228
00229 #endif
00230