gVirtualXRay  2.0.10
VirtualX-RayImagingLibraryonGPU
Vec3.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 __Vec3_h
36 #define __Vec3_h
37 
38 
69 //******************************************************************************
70 // Include
71 //******************************************************************************
72 #ifndef __gVirtualXRayConfig_h
74 #endif
75 
76 #include <iostream>
77 
78 
79 //******************************************************************************
80 // namespace
81 //******************************************************************************
82 namespace gVirtualXRay {
83 
84 
85 //******************************************************************************
86 // class declaration
87 //******************************************************************************
88 template<typename T> class Vec3;
89 
90 
91 //******************************************************************************
92 // Function declaration
93 //******************************************************************************
94 template<typename T> std::ostream& operator<<(std::ostream& anOutputStream,
95  const Vec3<T>& aVector);
96 
97 
98 //==============================================================================
103 //==============================================================================
104 template<typename T> class Vec3
105 //------------------------------------------------------------------------------
106 {
107 //******************************************************************************
108 public:
109  //--------------------------------------------------------------------------
111 
116  //--------------------------------------------------------------------------
117  Vec3(const T& aX = 0, const T& aY = 0, const T& aZ = 0);
118 
119 
120  //--------------------------------------------------------------------------
122 
125  //--------------------------------------------------------------------------
126  void setX(const T& aValue);
127 
128 
129  //--------------------------------------------------------------------------
131 
134  //--------------------------------------------------------------------------
135  void setY(const T& aValue);
136 
137 
138  //--------------------------------------------------------------------------
140 
143  //--------------------------------------------------------------------------
144  void setZ(const T& aValue);
145 
146 
147  //--------------------------------------------------------------------------
149 
152  //--------------------------------------------------------------------------
153  T getX() const;
154 
155 
156  //--------------------------------------------------------------------------
158 
161  //--------------------------------------------------------------------------
162  T getY() const;
163 
164 
165  //--------------------------------------------------------------------------
167 
170  //--------------------------------------------------------------------------
171  T getZ() const;
172 
173 
174  //--------------------------------------------------------------------------
176 
179  //--------------------------------------------------------------------------
180  double length() const;
181 
182 
183  //--------------------------------------------------------------------------
185 
188  //--------------------------------------------------------------------------
189  Vec3 normal() const;
190 
191 
192  //--------------------------------------------------------------------------
194  //--------------------------------------------------------------------------
195  void normalize();
196 
197 
198  //--------------------------------------------------------------------------
200  //--------------------------------------------------------------------------
201  void normalise();
202 
203 
204  //--------------------------------------------------------------------------
206 
210  //--------------------------------------------------------------------------
211  double dotProduct(const Vec3& aVector) const;
212 
213 
214  //--------------------------------------------------------------------------
217 
221  //--------------------------------------------------------------------------
222  Vec3 crossProduct(const Vec3& aVector) const;
223 
224 
225  //--------------------------------------------------------------------------
228 
232  //--------------------------------------------------------------------------
233  double distance(const Vec3& aVector) const;
234 
235 
236  //--------------------------------------------------------------------------
239 
243  //--------------------------------------------------------------------------
244  //double operator*(const Vec3& aVector) const;
245 
246 
247  //--------------------------------------------------------------------------
249 
253  //--------------------------------------------------------------------------
254  Vec3<T> elementWiseProduct(const Vec3& aVector) const;
255 
256 
257  //--------------------------------------------------------------------------
259 
263  //--------------------------------------------------------------------------
264  Vec3 operator+(const Vec3& aVector) const;
265 
266 
267  //--------------------------------------------------------------------------
269 
273  //--------------------------------------------------------------------------
274  Vec3& operator+=(const Vec3& aVector);
275 
276 
277  //--------------------------------------------------------------------------
279 
283  //--------------------------------------------------------------------------
284  Vec3 operator-(const Vec3& aVector) const;
285 
286 
287  //--------------------------------------------------------------------------
289 
293  //--------------------------------------------------------------------------
294  Vec3& operator-=(const Vec3& aVector);
295 
296 
297  //--------------------------------------------------------------------------
299 
303  //--------------------------------------------------------------------------
304  Vec3 operator*(const double& aValue) const;
305 
306 
307  //--------------------------------------------------------------------------
310 
314  //--------------------------------------------------------------------------
315  Vec3& operator*=(const double& aValue);
316 
317 
318  //--------------------------------------------------------------------------
320 
324  //--------------------------------------------------------------------------
325  Vec3 operator*(const float& aValue) const;
326 
327 
328  //--------------------------------------------------------------------------
331 
335  //--------------------------------------------------------------------------
336  Vec3& operator*=(const float& aValue);
337 
338 
339  //--------------------------------------------------------------------------
341 
345  //--------------------------------------------------------------------------
346  Vec3 operator/(const double& aValue) const;
347 
348 
349  //--------------------------------------------------------------------------
351 
355  //--------------------------------------------------------------------------
356  Vec3& operator/=(const double& aValue);
357 
358 
359  //--------------------------------------------------------------------------
361 
365  //--------------------------------------------------------------------------
366  Vec3 operator/(const float& aValue) const;
367 
368 
369  //--------------------------------------------------------------------------
371 
375  //--------------------------------------------------------------------------
376  Vec3& operator/=(const float& aValue);
377 
378 
379  //--------------------------------------------------------------------------
382 
386  //--------------------------------------------------------------------------
387  Vec3 operator^(const Vec3& aVector) const;
388 
389 
390  //--------------------------------------------------------------------------
392 
395  //--------------------------------------------------------------------------
396  Vec3 operator-() const;
397 
398 
399  //--------------------------------------------------------------------------
401 
406  //--------------------------------------------------------------------------
407  bool operator==(const Vec3& aVector) const;
408 
409 
410  //--------------------------------------------------------------------------
412 
417  //--------------------------------------------------------------------------
418  bool operator!=(const Vec3& aVector) const;
419 
420 
421  T& operator()(unsigned int i);
422  const T& operator()(unsigned int i) const;
423 
424  T& operator[](unsigned int i);
425  const T& operator[](unsigned int i) const;
426 
427 
428 //******************************************************************************
429 protected:
430  //**************************************************************************
431  T m_x;
432  T m_y;
433  T m_z;
434 };
435 
436 
437 //------------------------------------------------------------------------------
439 
444 //------------------------------------------------------------------------------
445 template<typename T> Vec3<T> operator*(const double& aValue,
446  const Vec3<T>& aVector);
447 
448 
449 } // namespace gVirtualXRay
450 
451 
452 //******************************************************************************
453 #include "Vec3.inl"
454 
455 
456 #endif // __Vec3_h
T m_z
the position along the z-axi
Definition: Vec3.h:433
void setY(const T &aValue)
Set the position along the y-axis.
Definition: Vec3.inl:99
bool operator!=(const Vec3 &aVector) const
Operator !=.
Definition: Vec3.inl:371
T & operator[](unsigned int i)
Definition: Vec3.inl:430
double distance(const Vec3 &aVector) const
Definition: Vec3.inl:209
Vec3 operator-() const
Operator - to get the opposite vector.
Definition: Vec3.inl:350
Vec3 & operator+=(const Vec3 &aVector)
Operator +=.
Definition: Vec3.inl:230
T m_x
the position along the x-axis
Definition: Vec3.h:431
double length() const
Get the length of the vector.
Definition: Vec3.inl:139
void normalise()
Normalise the current vector so that its length is 1.
Definition: Vec3.inl:166
Vec3 is a template class to handle a 3D vector.
Definition: Vec3.h:88
T getX() const
Accessor on the position along the x-axis.
Definition: Vec3.inl:115
T getZ() const
Accessor on the position along the z-axis.
Definition: Vec3.inl:131
Vec3 normal() const
Get the unit vector corresponding to the normed current vector.
Definition: Vec3.inl:147
Vec3< T > elementWiseProduct(const Vec3 &aVector) const
Element-wise product.
Definition: Vec3.inl:201
Vec3 operator/(const double &aValue) const
Operator / to divide each component of the vector by a given value.
Definition: Vec3.inl:302
Vec3 & operator*=(const double &aValue)
Definition: Vec3.inl:270
T m_y
the position along the y-axi
Definition: Vec3.h:432
void setX(const T &aValue)
Set the position along the x-axis.
Definition: Vec3.inl:91
Vec3 crossProduct(const Vec3 &aVector) const
Definition: Vec3.inl:182
Template class to handle 3D vectors.
T getY() const
Accessor on the position along the y-axis.
Definition: Vec3.inl:123
Vec3 operator^(const Vec3 &aVector) const
Definition: Vec3.inl:342
Vec3 & operator-=(const Vec3 &aVector)
Operator -=.
Definition: Vec3.inl:250
Vec3 operator+(const Vec3 &aVector) const
Operator +.
Definition: Vec3.inl:222
void normalize()
Normalize the current vector so that its length is 1.
Definition: Vec3.inl:155
std::ostream & operator<<(std::ostream &anOutputSream, const gVirtualXRay::AtomicElement &anElement)
operator <<
bool operator==(const Vec3 &aVector) const
Operator ==.
Definition: Vec3.inl:358
T & operator()(unsigned int i)
Definition: Vec3.inl:384
Vec3 operator*(const double &aValue) const
Operator * to multiply each component of the vector by a given value.
Definition: Vec3.inl:262
double dotProduct(const Vec3 &aVector) const
Get the dot product between the current vector and a given vector.
Definition: Vec3.inl:174
Image< T > operator*(const T &aValue, const Image< T > &anImage)
Definition: Image.inl:5104
Vec3 & operator/=(const double &aValue)
Operator -=.
Definition: Vec3.inl:310
void setZ(const T &aValue)
Set the position along the z-axis.
Definition: Vec3.inl:107
Vec3(const T &aX=0, const T &aY=0, const T &aZ=0)
Default Constructor.
Definition: Vec3.inl:82