Orfeo Toolbox  3.16
itkSize.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkSize.h,v $
5  Language: C++
6  Date: $Date: 2009-03-03 15:09:26 $
7  Version: $Revision: 1.24 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkSize_h
18 #define __itkSize_h
19 
20 #include "itkMacro.h"
21 #include <cstring>
22 
23 namespace itk
24 {
25 
46 template<unsigned int VDimension=2>
47 class Size {
48 public:
50  typedef Size Self;
51 
54  typedef unsigned long SizeValueType;
55 
57  static unsigned int GetSizeDimension(void) { return VDimension; }
58 
60  const Self
61  operator+(const Self &vec) const
62  {
63  Self result;
64  for (unsigned int i=0; i < VDimension; i++)
65  { result[i] = m_Size[i] + vec.m_Size[i]; }
66  return result;
67  }
68 
70  const Self &
71  operator+=(const Self &vec)
72  {
73  for (unsigned int i=0; i < VDimension; i++)
74  { m_Size[i] += vec.m_Size[i]; }
75  return *this;
76  }
77 
79  const Self
80  operator-(const Self &vec) const
81  {
82  Self result;
83  for (unsigned int i=0; i < VDimension; i++)
84  { result[i] = m_Size[i] - vec.m_Size[i]; }
85  return result;
86  }
87 
89  const Self &
90  operator-=(const Self &vec)
91  {
92  for (unsigned int i=0; i < VDimension; i++)
93  { m_Size[i] -= vec.m_Size[i]; }
94  return *this;
95  }
96 
98  const Self
99  operator*(const Self &vec) const
100  {
101  Self result;
102  for (unsigned int i=0; i < VDimension; i++)
103  { result[i] = m_Size[i] * vec.m_Size[i]; }
104  return result;
105  }
106 
108  const Self &
109  operator*=(const Self &vec)
110  {
111  for (unsigned int i=0; i < VDimension; i++)
112  { m_Size[i] *= vec.m_Size[i]; }
113  return *this;
114  }
115 
117  bool
118  operator==(const Self &vec) const
119  {
120  bool same=1;
121  for (unsigned int i=0; i < VDimension && same; i++)
122  { same = (m_Size[i] == vec.m_Size[i]); }
123  return same;
124  }
125 
127  bool
128  operator!=(const Self &vec) const
129  {
130  bool same=1;
131  for (unsigned int i=0; i < VDimension && same; i++)
132  { same = (m_Size[i] == vec.m_Size[i]); }
133  return !same;
134  }
135 
138  SizeValueType & operator[](unsigned int dim)
139  { return m_Size[dim]; }
140 
144  SizeValueType operator[](unsigned int dim) const
145  { return m_Size[dim]; }
146 
149  const SizeValueType *GetSize() const { return m_Size; }
150 
154  void SetSize(const SizeValueType val[VDimension])
155  { memcpy(m_Size, val, sizeof(SizeValueType)*VDimension); }
156 
163  void SetElement(unsigned long element, SizeValueType val )
164  { m_Size[ element ] = val; }
165 
172  SizeValueType GetElement( unsigned long element ) const
173  { return m_Size[ element ]; }
174 
177  void Fill(SizeValueType value)
178  { for(unsigned int i=0;i < VDimension; ++i) m_Size[i] = value; }
179 
190  SizeValueType m_Size[VDimension];
191 
192 
193 // force gccxml to find the constructors found before the internal upgrade to gcc 4.2
194 #if defined(CABLE_CONFIGURATION)
195  Size(); //purposely not implemented
196  Size(const Self&); //purposely not implemented
197  void operator=(const Self&); //purposely not implemented
198 #endif
199 
200 };
201 
202 
203 template<unsigned int VDimension>
204 std::ostream & operator<<(std::ostream &os, const Size<VDimension> &size)
205 {
206  os << "[";
207  for (unsigned int i=0; i+1 < VDimension; ++i)
208  {
209  os << size[i] << ", ";
210  }
211  if (VDimension >= 1)
212  {
213  os << size[VDimension-1];
214  }
215  os << "]";
216  return os;
217 }
218 
219 } // end namespace itk
220 
221 #endif

Generated at Sun May 19 2013 00:08:09 for Orfeo Toolbox with doxygen 1.8.3.1