GenGeo  1.1
vector3.h
Go to the documentation of this file.
1 
2 // //
3 // Copyright (c) 2007-2014 by The University of Queensland //
4 // Centre for Geoscience Computing //
5 // http://earth.uq.edu.au/centre-geoscience-computing //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.opensource.org/licenses/osl-3.0.php //
10 // //
12 
13 #ifndef __VECTOR3_H
14 #define __VECTOR3_H
15 
16 #define DO_INLINE_VECTOR3 1
17 
18 #if DO_INLINE_VECTOR3 >= 1
19 #define VECTOR3_INLINE inline
20 #else
21 #define VECTOR3_INLINE
22 #endif
23 
24 #include <iostream>
25 #include <math.h>
26 #include <string>
27 
28 //#include "Foundation/Error.h"
29 
30 using std::ostream;
31 using std::istream;
32 using std::string;
33 
34 //class Matrix3;
35 
36 /*
37 class VecErr:public MError
38 {
39  public:
40  VecErr(const string&);
41  virtual ~VecErr(){};
42 };
43 */
44 
45 struct VDMulVadd;
46 struct VDMul;
47 
48 class Vector3
49 {
50 protected:
51  double data[3];
52 
53 public:
54  static const Vector3 ZERO;
55  // constructors
57  VECTOR3_INLINE explicit Vector3(double s);
58  VECTOR3_INLINE Vector3(double,double,double);
60 
61  // vec-vec operators
63  VECTOR3_INLINE Vector3& operator=(double s);
68 //wangyc added !
69 // VECTOR3_INLINE Vector3 operator*(const Matrix3 &m) const;
70  VECTOR3_INLINE double operator*(const Vector3&) const;
72 
73  // vec-dbl ops
74  VECTOR3_INLINE Vector3 operator*(double) const;
76  VECTOR3_INLINE Vector3 operator/(double) const;
77  VECTOR3_INLINE Vector3 operator-(double) const;
78  VECTOR3_INLINE Vector3 operator+(double) const;
81 
82 // wangyc added !
84  VECTOR3_INLINE double norm() const;
85  VECTOR3_INLINE double wnorm(double,double,double) const;
86  VECTOR3_INLINE double norm2() const;
87  VECTOR3_INLINE double wnorm2(double,double,double) const;
88  VECTOR3_INLINE Vector3 unit() const;
89 // VECTOR3_INLINE Vector3 unit_s() const; //safe version (throw exceptions)
90  VECTOR3_INLINE double max() const;
91  VECTOR3_INLINE double min() const;
92 
93  VECTOR3_INLINE Vector3 rotate(const Vector3 &axis, const Vector3 &axisPt) const;
94 
95  VECTOR3_INLINE bool operator==(const Vector3&) const;
96  VECTOR3_INLINE bool operator!=(const Vector3&) const;
97 
98  VECTOR3_INLINE friend Vector3 cmax(const Vector3&,const Vector3&);
99  VECTOR3_INLINE friend Vector3 cmin(const Vector3&,const Vector3&);
100 
101  VECTOR3_INLINE friend Vector3 cross(const Vector3&,const Vector3&);
102  VECTOR3_INLINE friend double dot(const Vector3&,const Vector3&);
103  VECTOR3_INLINE friend Vector3 operator*(double,const Vector3&);
104 
105  //n+1-ary operators
106  VECTOR3_INLINE void mul_add_and_assign(const Vector3*,const Vector3*,const double&);
107  VECTOR3_INLINE void mul_and_assign(const Vector3*,const double&);
108 
109  VECTOR3_INLINE Vector3(const VDMulVadd&);
110  VECTOR3_INLINE Vector3& operator=(const VDMulVadd&);
111 
112  VECTOR3_INLINE Vector3(const VDMul&);
113  VECTOR3_INLINE Vector3& operator=(const VDMul&);
114 
115  //access stuff
116  VECTOR3_INLINE void set_x(double x) {data[0] = x;}
117  VECTOR3_INLINE void set_y(double y) {data[1] = y;}
118  VECTOR3_INLINE void set_z(double z) {data[2] = z;}
119 // void set_xyz(double x, double y, double z)
120 // { data[0] = x; data[1] = y; data[2] = z;}
121 
122  VECTOR3_INLINE double& X() {return data[0];};
123  VECTOR3_INLINE double& Y() {return data[1];};
124  VECTOR3_INLINE double& Z() {return data[2];};
125  VECTOR3_INLINE double x() const {return data[0];};
126  VECTOR3_INLINE double y() const {return data[1];};
127  VECTOR3_INLINE double z() const {return data[2];};
128  VECTOR3_INLINE const double &operator[](int i) const {return data[i];}
129  VECTOR3_INLINE double& operator[](int i) {return data[i];}
130 
131  // in/output
132  VECTOR3_INLINE friend ostream& operator << (ostream&,const Vector3&);
133  VECTOR3_INLINE friend istream& operator >> (istream&,Vector3&);
134 
135  // comparison -> enable to use of Vector3 as key in STL map and set
136  bool operator<(const Vector3&) const;
137 
138 // friend class Matrix3;
139 };
140 
143 
144 #if DO_INLINE_VECTOR3 >= 1
145 #include "vector3.hh"
146 #endif
147 
148 #endif // __VECTOR3_H