Orfeo Toolbox  3.16
itkOffset.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkOffset.h,v $
5  Language: C++
6  Date: $Date: 2009-02-06 20:53:15 $
7  Version: $Revision: 1.19 $
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 __itkOffset_h
18 #define __itkOffset_h
19 
20 #include "itkMacro.h"
21 #include "itkSize.h"
22 
23 #include <memory>
24 
25 #include "itkExceptionObject.h"
26 
27 #if defined(_MSC_VER)
28 
29 // local variable may be used without having been initialized
30 #pragma warning ( disable : 4701 )
31 #endif
32 namespace itk
33 {
34 
35 namespace Functor
36 {
37 template<unsigned int VOffsetDimension> class OffsetLexicographicCompare;
38 }
39 
40 
58 template<unsigned int VOffsetDimension=2>
59 class Offset {
60 public:
62  typedef Offset Self;
63 
65  static unsigned int GetOffsetDimension() { return VOffsetDimension; }
66 
69  typedef long OffsetValueType;
70 
73 
75  const Self
76  operator+(const Self &offset) const
77  {
78  Self result;
79  for (unsigned int i=0; i < VOffsetDimension; i++)
80  { result[i] = m_Offset[i] + offset[i]; }
81  return result;
82  }
83 
85  const Self
86  operator+(const Size<VOffsetDimension> &size) const
87  {
88  Self result;
89  for (unsigned int i=0; i < VOffsetDimension; i++)
90  { result[i] = m_Offset[i] + size[i]; }
91  return result;
92  }
93 
95  const Self &
97  {
98  for (unsigned int i=0; i < VOffsetDimension; i++)
99  { m_Offset[i] += size[i]; }
100  return *this;
101  }
102 
104  const Self &
106  {
107  for (unsigned int i=0; i < VOffsetDimension; i++)
108  { m_Offset[i] -= size[i]; }
109  return *this;
110  }
111 
113  const Self
114  operator-(const Self &vec)
115  {
116  Self result;
117  for (unsigned int i=0; i < VOffsetDimension; i++)
118  { result[i] = m_Offset[i] - vec.m_Offset[i]; }
119  return result;
120  }
121 
123  const Self &
124  operator+=(const Self &vec)
125  {
126  for (unsigned int i=0; i < VOffsetDimension; i++)
127  { m_Offset[i] += vec.m_Offset[i]; }
128  return *this;
129  }
130 
132  const Self &
133  operator-=(const Self &vec)
134  {
135  for (unsigned int i=0; i < VOffsetDimension; i++)
136  { m_Offset[i] -= vec.m_Offset[i]; }
137  return *this;
138  }
139 
141  bool
142  operator==(const Self &vec) const
143  {
144  bool same=1;
145  for (unsigned int i=0; i < VOffsetDimension && same; i++)
146  { same = (m_Offset[i] == vec.m_Offset[i]); }
147  return same;
148  }
149 
151  bool
152  operator!=(const Self &vec) const
153  {
154  bool same=1;
155  for (unsigned int i=0; i < VOffsetDimension && same; i++)
156  { same = (m_Offset[i] == vec.m_Offset[i]); }
157  return !same;
158  }
159 
162  OffsetValueType & operator[](unsigned int dim)
163  { return m_Offset[dim]; }
164 
168  OffsetValueType operator[](unsigned int dim) const
169  { return m_Offset[dim]; }
170 
173  const OffsetValueType *GetOffset() const { return m_Offset; };
174 
179  void SetOffset(const OffsetValueType val[VOffsetDimension])
180  { memcpy(m_Offset, val, sizeof(OffsetValueType)*VOffsetDimension); }
181 
185  static Self GetBasisOffset(unsigned int dim);
186 
189  void Fill(OffsetValueType value)
190  { for(unsigned int i=0;i < VOffsetDimension; ++i) m_Offset[i] = value; }
191 
197  OffsetValueType m_Offset[VOffsetDimension];
198 
199 
200 // force gccxml to find the constructors found before the internal upgrade to gcc 4.2
201 #if defined(CABLE_CONFIGURATION)
202  Offset(); //purposely not implemented
203  Offset(const Self&); //purposely not implemented
204  void operator=(const Self&); //purposely not implemented
205 #endif
206 
207 };
208 
209 
210 namespace Functor
211 {
219 template<unsigned int VOffsetDimension>
220 class OffsetLexicographicCompare
221 {
222 public:
224  Offset<VOffsetDimension> const& r) const
225  {
226  for(unsigned int i=0; i < VOffsetDimension; ++i)
227  {
228  if(l.m_Offset[i] < r.m_Offset[i])
229  {
230  return true;
231  }
232  else if(l.m_Offset[i] > r.m_Offset[i])
233  {
234  return false;
235  }
236  }
237  return false;
238  }
239 };
240 }
241 
242 template<unsigned int VOffsetDimension>
243 Offset<VOffsetDimension>
245 ::GetBasisOffset(unsigned int dim)
246 {
247  Self ind;
248 
249  memset(ind.m_Offset, 0, sizeof(OffsetValueType)*VOffsetDimension);
250  ind.m_Offset[dim] = 1;
251  return ind;
252 }
253 
254 template<unsigned int VOffsetDimension>
255 std::ostream & operator<<(std::ostream &os, const Offset<VOffsetDimension> &ind)
256 {
257  os << "[";
258  unsigned int dimlim = VOffsetDimension - 1;
259  for (unsigned int i=0; i < dimlim; ++i)
260  {
261  os << ind[i] << ", ";
262  }
263  if (VOffsetDimension >= 1)
264  {
265  os << ind[VOffsetDimension-1];
266  }
267  os << "]";
268  return os;
269 }
270 
271 } // end namespace itk
272 
273 #endif

Generated at Sat May 18 2013 23:57:40 for Orfeo Toolbox with doxygen 1.8.3.1