Orfeo Toolbox  4.0
itkSize.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkSize_h
19 #define __itkSize_h
20 
21 #include "itkMacro.h"
22 #include "itkIntTypes.h"
23 
24 namespace itk
25 {
51 template< unsigned int VDimension = 2 >
52 class Size
53 {
54 public:
56  typedef Size Self;
57 
61 
63  itkStaticConstMacro(Dimension, unsigned int, VDimension);
64 
66  static unsigned int GetSizeDimension(void) { return VDimension; }
67 
69  const Self
70  operator+(const Self & vec) const
71  {
72  Self result;
73 
74  for ( unsigned int i = 0; i < VDimension; i++ )
75  { result[i] = m_Size[i] + vec.m_Size[i]; }
76  return result;
77  }
78 
80  const Self &
81  operator+=(const Self & vec)
82  {
83  for ( unsigned int i = 0; i < VDimension; i++ )
84  { m_Size[i] += vec.m_Size[i]; }
85  return *this;
86  }
87 
89  const Self
90  operator-(const Self & vec) const
91  {
92  Self result;
93 
94  for ( unsigned int i = 0; i < VDimension; i++ )
95  { result[i] = m_Size[i] - vec.m_Size[i]; }
96  return result;
97  }
98 
100  const Self &
101  operator-=(const Self & vec)
102  {
103  for ( unsigned int i = 0; i < VDimension; i++ )
104  { m_Size[i] -= vec.m_Size[i]; }
105  return *this;
106  }
107 
109  const Self
110  operator*(const Self & vec) const
111  {
112  Self result;
113 
114  for ( unsigned int i = 0; i < VDimension; i++ )
115  { result[i] = m_Size[i] * vec.m_Size[i]; }
116  return result;
117  }
118 
120  const Self &
121  operator*=(const Self & vec)
122  {
123  for ( unsigned int i = 0; i < VDimension; i++ )
124  { m_Size[i] *= vec.m_Size[i]; }
125  return *this;
126  }
127 
129  bool
130  operator==(const Self & vec) const
131  {
132  bool same = 1;
133 
134  for ( unsigned int i = 0; i < VDimension && same; i++ )
135  { same = ( m_Size[i] == vec.m_Size[i] ); }
136  return same;
137  }
138 
140  bool
141  operator!=(const Self & vec) const
142  {
143  bool same = 1;
144 
145  for ( unsigned int i = 0; i < VDimension && same; i++ )
146  { same = ( m_Size[i] == vec.m_Size[i] ); }
147  return !same;
148  }
149 
152  SizeValueType & operator[](unsigned int dim)
153  { return m_Size[dim]; }
154 
158  SizeValueType operator[](unsigned int dim) const
159  { return m_Size[dim]; }
160 
163  const SizeValueType * GetSize() const { return m_Size; }
164 
168  void SetSize(const SizeValueType val[VDimension])
169  {
170  std::copy(val,
171  val+VDimension,
172  m_Size);
173  }
174 
181  void SetElement(unsigned long element, SizeValueType val)
182  { m_Size[element] = val; }
183 
190  SizeValueType GetElement(unsigned long element) const
191  { return m_Size[element]; }
192 
195  void Fill(SizeValueType value)
196  { for ( unsigned int i = 0; i < VDimension; ++i ) { m_Size[i] = value; } }
197 
208  SizeValueType m_Size[VDimension];
209 
210 // force gccxml to find the constructors found before the internal upgrade to
211 // gcc 4.2
212 #if defined( CABLE_CONFIGURATION )
213  Size(); //purposely not implemented
214  Size(const Self &); //purposely not implemented
215  void operator=(const Self &); //purposely not implemented
216 
217 #endif
218 };
219 
220 template< unsigned int VDimension >
221 std::ostream & operator<<(std::ostream & os, const Size< VDimension > & size)
222 {
223  os << "[";
224  for ( unsigned int i = 0; i + 1 < VDimension; ++i )
225  {
226  os << size[i] << ", ";
227  }
228  if ( VDimension >= 1 )
229  {
230  os << size[VDimension - 1];
231  }
232  os << "]";
233  return os;
234 }
235 } // end namespace itk
236 
237 #endif

Generated at Sat Mar 8 2014 15:33:37 for Orfeo Toolbox with doxygen 1.8.3.1