gVirtualXRay  2.0.10
VirtualX-RayImagingLibraryonGPU
Vec2.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (c) 2017, Dr Franck P. Vidal (franck.p.vidal@fpvidal.net),
4 http://www.fpvidal.net/
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation and/or
15 other materials provided with the distribution.
16 
17 3. Neither the name of the Bangor University nor the names of its contributors
18 may be used to endorse or promote products derived from this software without
19 specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32 */
33 
34 
35 #ifndef __Vec2_h
36 #define __Vec2_h
37 
38 
66 //******************************************************************************
67 // Include
68 //******************************************************************************
69 #ifndef __gVirtualXRayConfig_h
71 #endif
72 
73 
74 //******************************************************************************
75 // namespace
76 //******************************************************************************
77 namespace gVirtualXRay {
78 
79 
80 //******************************************************************************
81 // class declaration
82 //******************************************************************************
83 template<typename T> class Vec2;
84 
85 
86 //******************************************************************************
87 // function declaration
88 //******************************************************************************
89 template <typename T> std::ostream& operator<<(std::ostream& anOutputStream,
90  const Vec2<T>& aVector);
91 
92 
93 //==============================================================================
98 //==============================================================================
99 template<typename T> class Vec2
100 //------------------------------------------------------------------------------
101 {
102 //******************************************************************************
103 public:
104  //---------------------------------------------------------------------------
106 
110  //---------------------------------------------------------------------------
111  Vec2(const T& aX = 0.0f, const T& aY = 0.0f);
112 
113 
114  //---------------------------------------------------------------------------
116 
119  //---------------------------------------------------------------------------
120  void setX(const T& aValue);
121 
122 
123  //---------------------------------------------------------------------------
125 
128  //---------------------------------------------------------------------------
129  void setY(const T& aValue);
130 
131 
132  //---------------------------------------------------------------------------
134 
137  //---------------------------------------------------------------------------
138  T getX() const;
139 
140 
141  //---------------------------------------------------------------------------
143 
146  //---------------------------------------------------------------------------
147  T getY() const;
148 
149 
150  //---------------------------------------------------------------------------
152 
155  //---------------------------------------------------------------------------
156  double length() const;
157 
158 
159  //---------------------------------------------------------------------------
161 
164  //---------------------------------------------------------------------------
165  Vec2 normal() const;
166 
167 
168  //---------------------------------------------------------------------------
170  //---------------------------------------------------------------------------
171  void normalize();
172 
173 
174  //---------------------------------------------------------------------------
176  //---------------------------------------------------------------------------
177  void normalise();
178 
179 
180  //---------------------------------------------------------------------------
182 
186  //---------------------------------------------------------------------------
187  double dotProduct(const Vec2& aVector) const;
188 
189 
190  //---------------------------------------------------------------------------
193 
197  //---------------------------------------------------------------------------
198  double distance(const Vec2& aVector) const;
199 
200 
201  //---------------------------------------------------------------------------
203 
207  //---------------------------------------------------------------------------
208  const Vec2 operator+(const Vec2& aVector) const;
209 
210 
211  //---------------------------------------------------------------------------
213 
217  //---------------------------------------------------------------------------
218  Vec2& operator+=(const Vec2& aVector);
219 
220 
221  //---------------------------------------------------------------------------
223 
227  //---------------------------------------------------------------------------
228  const Vec2 operator-(const Vec2& aVector) const;
229 
230 
231  //---------------------------------------------------------------------------
233 
237  //---------------------------------------------------------------------------
238  Vec2& operator-=(const Vec2& aVector);
239 
240 
241  //---------------------------------------------------------------------------
243 
247  //---------------------------------------------------------------------------
248  const Vec2 operator*(const double& aValue) const;
249 
250 
251  //---------------------------------------------------------------------------
254 
258  //---------------------------------------------------------------------------
259  Vec2& operator*=(const double& aValue);
260 
261 
262  //---------------------------------------------------------------------------
264 
268  //---------------------------------------------------------------------------
269  const Vec2 operator*(const float& aValue) const;
270 
271 
272  //---------------------------------------------------------------------------
275 
279  //---------------------------------------------------------------------------
280  Vec2& operator*=(const float& aValue);
281 
282 
283  //---------------------------------------------------------------------------
285 
289  //---------------------------------------------------------------------------
290  const Vec2 operator/(const double& aValue) const;
291 
292 
293  //---------------------------------------------------------------------------
296 
300  //---------------------------------------------------------------------------
301  Vec2& operator/=(const double& aValue);
302 
303 
304  //---------------------------------------------------------------------------
306 
310  //---------------------------------------------------------------------------
311  const Vec2 operator/(const float& aValue) const;
312 
313 
314  //---------------------------------------------------------------------------
317 
321  //---------------------------------------------------------------------------
322  Vec2& operator/=(const float& aValue);
323 
324 
325  //---------------------------------------------------------------------------
327 
330  //---------------------------------------------------------------------------
331  const Vec2 operator-() const;
332 
333 
334  T& operator()(unsigned int i);
335 
336 
337  const T& operator()(unsigned int i) const;
338 
339 
340  T& operator[](unsigned int i);
341 
342 
343  const T& operator[](unsigned int i) const;
344 
345 
346 //******************************************************************************
347 protected:
348  //**************************************************************************
349  T m_x;
350  T m_y;
351 };
352 
353 
354 } // namespace gVirtualXRay
355 
356 
357 //******************************************************************************
358 #include "Vec2.inl"
359 
360 
361 #endif // __Vec2_h
Template class to handle 2D vectors.
void setX(const T &aValue)
Set the position along the x-axis.
Definition: Vec2.inl:78
Vec2 is a template class to handle a 2D vector.
Definition: Vec2.h:83
void setY(const T &aValue)
Set the position along the y-axis.
Definition: Vec2.inl:86
const Vec2 operator-() const
Operator - to get the opposite vector.
Definition: Vec2.inl:278
Vec2 & operator-=(const Vec2 &aVector)
Operator -=.
Definition: Vec2.inl:191
T m_x
the position along the x-axis
Definition: Vec2.h:349
void normalize()
Normalize the current vector so that its length is 1.
Definition: Vec2.inl:126
const Vec2 operator+(const Vec2 &aVector) const
Operator +.
Definition: Vec2.inl:164
const Vec2 operator*(const double &aValue) const
Operator * to multiply each component of the vector by a given value.
Definition: Vec2.inl:202
const Vec2 operator/(const double &aValue) const
Operator / to divide each component of the vector by a given value.
Definition: Vec2.inl:240
Vec2 & operator*=(const double &aValue)
Definition: Vec2.inl:210
T getX() const
Accessor on the position along the x-axis.
Definition: Vec2.inl:94
void normalise()
Normalise the current vector so that its length is 1.
Definition: Vec2.inl:136
T & operator()(unsigned int i)
Definition: Vec2.inl:286
double length() const
Get the length of the vector.
Definition: Vec2.inl:110
T m_y
the position along the y-axi
Definition: Vec2.h:350
double dotProduct(const Vec2 &aVector) const
Get the dot product between the current vector and a given vector.
Definition: Vec2.inl:144
Vec2 & operator+=(const Vec2 &aVector)
Operator +=.
Definition: Vec2.inl:172
std::ostream & operator<<(std::ostream &anOutputSream, const gVirtualXRay::AtomicElement &anElement)
operator <<
double distance(const Vec2 &aVector) const
Definition: Vec2.inl:152
Vec2(const T &aX=0.0f, const T &aY=0.0f)
Default Constructor.
Definition: Vec2.inl:69
T & operator[](unsigned int i)
Definition: Vec2.inl:324
Vec2 normal() const
Get the unit vector corresponding to the normed current vector.
Definition: Vec2.inl:118
T getY() const
Accessor on the position along the y-axis.
Definition: Vec2.inl:102
Vec2 & operator/=(const double &aValue)
Definition: Vec2.inl:248