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: 2003/09/10 14:29:26 $ 00007 Version: $Revision: 1.17 $ 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) 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 } 00067 00069 const Self & 00070 operator+=(const Self &vec) 00071 { 00072 for (unsigned int i=0; i < VDimension; i++) 00073 { m_Size[i] += vec.m_Size[i]; } 00074 return *this; 00075 } 00076 00078 const Self 00079 operator-(const Self &vec) 00080 { 00081 Self result; 00082 for (unsigned int i=0; i < VDimension; i++) 00083 { result[i] = m_Size[i] - vec.m_Size[i]; } 00084 return result; 00085 } 00086 00088 const Self & 00089 operator-=(const Self &vec) 00090 { 00091 for (unsigned int i=0; i < VDimension; i++) 00092 { m_Size[i] -= vec.m_Size[i]; } 00093 return *this; 00094 } 00095 00097 const Self 00098 operator*(const Self &vec) 00099 { 00100 Self result; 00101 for (unsigned int i=0; i < VDimension; i++) 00102 { result[i] = m_Size[i] * vec.m_Size[i]; } 00103 return result; 00104 } 00105 00107 const Self & 00108 operator*=(const Self &vec) 00109 { 00110 for (unsigned int i=0; i < VDimension; i++) 00111 { m_Size[i] *= vec.m_Size[i]; } 00112 return *this; 00113 } 00114 00116 bool 00117 operator==(const Self &vec) const 00118 { 00119 bool same=1; 00120 for (unsigned int i=0; i < VDimension && same; i++) 00121 { same = (m_Size[i] == vec.m_Size[i]); } 00122 return same; 00123 } 00124 00126 bool 00127 operator!=(const Self &vec) const 00128 { 00129 bool same=1; 00130 for (unsigned int i=0; i < VDimension && same; i++) 00131 { same = (m_Size[i] == vec.m_Size[i]); } 00132 return !same; 00133 } 00134 00137 SizeValueType & operator[](unsigned int dim) 00138 { return m_Size[dim]; } 00139 00143 SizeValueType operator[](unsigned int dim) const 00144 { return m_Size[dim]; } 00145 00148 const SizeValueType *GetSize() const { return m_Size; }; 00149 00153 void SetSize(const SizeValueType val[VDimension]) 00154 { memcpy(m_Size, val, sizeof(SizeValueType)*VDimension); } 00155 00162 void SetElement(unsigned long element, SizeValueType val ) 00163 { m_Size[ element ] = val; } 00164 00171 SizeValueType GetElement( unsigned long element ) const 00172 { return m_Size[ element ]; } 00173 00176 void Fill(SizeValueType value) 00177 { for(unsigned int i=0;i < VDimension; ++i) m_Size[i] = value; } 00178 00189 SizeValueType m_Size[VDimension]; 00190 00191 }; 00192 00193 00194 template<unsigned int VDimension> 00195 std::ostream & operator<<(std::ostream &os, const Size<VDimension> &size) 00196 { 00197 os << "["; 00198 for (unsigned int i=0; i+1 < VDimension; ++i) 00199 { 00200 os << size[i] << ", "; 00201 } 00202 if (VDimension >= 1) 00203 { 00204 os << size[VDimension-1]; 00205 } 00206 os << "]"; 00207 return os; 00208 } 00209 00210 } // end namespace itk 00211 00212 #endif

Generated at Sun Apr 1 02:44:41 2007 for ITK by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2000