Orfeo Toolbox  4.0
itkOffset.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 __itkOffset_h
19 #define __itkOffset_h
20 
21 #include "itkSize.h"
22 
23 #include <memory>
24 
25 namespace itk
26 {
27 namespace Functor
28 {
29 template< unsigned int VOffsetDimension >
31 }
32 
54 template< unsigned int VOffsetDimension = 2 >
55 class Offset
56 {
57 public:
59  typedef Offset Self;
60 
62  itkStaticConstMacro(Dimension, unsigned int, VOffsetDimension);
63 
65  static unsigned int GetOffsetDimension() { return VOffsetDimension; }
66 
70 
73 
75  const Self
76  operator+(const Self & offset) const
77  {
78  Self result;
79 
80  for ( unsigned int i = 0; i < VOffsetDimension; i++ )
81  { result[i] = m_Offset[i] + offset[i]; }
82  return result;
83  }
84 
86  const Self
87  operator+(const Size< VOffsetDimension > & size) const
88  {
89  Self result;
90 
91  for ( unsigned int i = 0; i < VOffsetDimension; i++ )
92  { result[i] = m_Offset[i] + size[i]; }
93  return result;
94  }
95 
97  const Self &
99  {
100  for ( unsigned int i = 0; i < VOffsetDimension; i++ )
101  { m_Offset[i] += size[i]; }
102  return *this;
103  }
104 
106  const Self &
108  {
109  for ( unsigned int i = 0; i < VOffsetDimension; i++ )
110  { m_Offset[i] -= size[i]; }
111  return *this;
112  }
113 
115  const Self
116  operator-(const Self & vec)
117  {
118  Self result;
119 
120  for ( unsigned int i = 0; i < VOffsetDimension; i++ )
121  { result[i] = m_Offset[i] - vec.m_Offset[i]; }
122  return result;
123  }
124 
126  const Self &
127  operator+=(const Self & vec)
128  {
129  for ( unsigned int i = 0; i < VOffsetDimension; i++ )
130  { m_Offset[i] += vec.m_Offset[i]; }
131  return *this;
132  }
133 
135  const Self &
136  operator-=(const Self & vec)
137  {
138  for ( unsigned int i = 0; i < VOffsetDimension; i++ )
139  { m_Offset[i] -= vec.m_Offset[i]; }
140  return *this;
141  }
142 
144  bool
145  operator==(const Self & vec) const
146  {
147  bool same = 1;
148 
149  for ( unsigned int i = 0; i < VOffsetDimension && same; i++ )
150  { same = ( m_Offset[i] == vec.m_Offset[i] ); }
151  return same;
152  }
153 
155  bool
156  operator!=(const Self & vec) const
157  {
158  bool same = 1;
159 
160  for ( unsigned int i = 0; i < VOffsetDimension && same; i++ )
161  { same = ( m_Offset[i] == vec.m_Offset[i] ); }
162  return !same;
163  }
164 
167  OffsetValueType & operator[](unsigned int dim)
168  { return m_Offset[dim]; }
169 
173  OffsetValueType operator[](unsigned int dim) const
174  { return m_Offset[dim]; }
175 
178  const OffsetValueType * GetOffset() const { return m_Offset; }
179 
184  void SetOffset(const OffsetValueType val[VOffsetDimension])
185  {
186  std::copy(val,
187  val+VOffsetDimension,
188  m_Offset);
189  }
190 
194  static Self GetBasisOffset(unsigned int dim);
195 
198  void Fill(OffsetValueType value)
199  { for ( unsigned int i = 0; i < VOffsetDimension; ++i ) { m_Offset[i] = value; } }
200 
206  OffsetValueType m_Offset[VOffsetDimension];
207 
208 // force gccxml to find the constructors found before the internal upgrade to
209 // gcc 4.2
210 #if defined( CABLE_CONFIGURATION )
211  Offset(); //purposely not implemented
212  Offset(const Self &); //purposely not implemented
213  void operator=(const Self &); //purposely not implemented
214 
215 #endif
216 };
217 
218 namespace Functor
219 {
228 template< unsigned int VOffsetDimension >
229 class OffsetLexicographicCompare
230 {
231 public:
233  Offset< VOffsetDimension > const & r) const
234  {
235  for ( unsigned int i = 0; i < VOffsetDimension; ++i )
236  {
237  if ( l.m_Offset[i] < r.m_Offset[i] )
238  {
239  return true;
240  }
241  else if ( l.m_Offset[i] > r.m_Offset[i] )
242  {
243  return false;
244  }
245  }
246  return false;
247  }
248 };
249 }
250 
251 template< unsigned int VOffsetDimension >
252 Offset< VOffsetDimension >
254 ::GetBasisOffset(unsigned int dim)
255 {
256  Self ind;
257 
258  memset(ind.m_Offset, 0, sizeof( OffsetValueType ) * VOffsetDimension);
259  ind.m_Offset[dim] = 1;
260  return ind;
261 }
262 
263 template< unsigned int VOffsetDimension >
264 std::ostream & operator<<(std::ostream & os, const Offset< VOffsetDimension > & ind)
265 {
266  os << "[";
267  unsigned int dimlim = VOffsetDimension - 1;
268  for ( unsigned int i = 0; i < dimlim; ++i )
269  {
270  os << ind[i] << ", ";
271  }
272  if ( VOffsetDimension >= 1 )
273  {
274  os << ind[VOffsetDimension - 1];
275  }
276  os << "]";
277  return os;
278 }
279 } // end namespace itk
280 
281 #endif

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