ESyS-Particle
4.0.1
|
00001 00002 // // 00003 // Copyright (c) 2003-2011 by The University of Queensland // 00004 // Earth Systems Science Computational Centre (ESSCC) // 00005 // http://www.uq.edu.au/esscc // 00006 // // 00007 // Primary Business: Brisbane, Queensland, Australia // 00008 // Licensed under the Open Software License version 3.0 // 00009 // http://www.opensource.org/licenses/osl-3.0.php // 00010 // // 00012 00013 #ifndef __VEC3_H 00014 #define __VEC3_H 00015 00016 #define DO_INLINE_VEC3 1 00017 00018 #if DO_INLINE_VEC3 >= 1 00019 #define VEC3_INLINE inline 00020 #else 00021 #define VEC3_INLINE 00022 #endif 00023 00024 #include <iostream> 00025 #include <math.h> 00026 #include <string> 00027 00028 #include "Foundation/Error.h" 00029 00030 using std::ostream; 00031 using std::istream; 00032 using std::string; 00033 00034 class Matrix3; 00035 00036 class VecErr:public MError 00037 { 00038 public: 00039 VecErr(const string&); 00040 virtual ~VecErr(){}; 00041 }; 00042 00043 struct VDMulVadd; 00044 struct VDMul; 00045 00046 class Vec3 00047 { 00048 protected: 00049 double data[3]; 00050 00051 public: 00052 static const Vec3 ZERO; 00053 // constructors 00054 VEC3_INLINE Vec3(); 00055 VEC3_INLINE explicit Vec3(double s); 00056 VEC3_INLINE Vec3(double,double,double); 00057 VEC3_INLINE Vec3(const Vec3&); 00058 00059 // vec-vec operators 00060 VEC3_INLINE Vec3& operator=(const Vec3&); 00061 VEC3_INLINE Vec3& operator=(double s); 00062 VEC3_INLINE Vec3& operator-=(const Vec3&); 00063 VEC3_INLINE Vec3& operator+=(const Vec3&); 00064 VEC3_INLINE Vec3 operator+(const Vec3&) const; 00065 VEC3_INLINE Vec3 operator-(const Vec3&) const; 00066 //wangyc added ! 00067 VEC3_INLINE Vec3 operator*(const Matrix3 &m) const; 00068 VEC3_INLINE double operator*(const Vec3&) const; 00069 VEC3_INLINE Vec3 operator-() const; 00070 00071 // vec-dbl ops 00072 VEC3_INLINE Vec3 operator*(double) const; 00073 VEC3_INLINE Vec3& operator*=(double); 00074 VEC3_INLINE Vec3 operator/(double) const; 00075 VEC3_INLINE Vec3 operator-(double) const; 00076 VEC3_INLINE Vec3 operator+(double) const; 00077 VEC3_INLINE Vec3& operator+=(double); 00078 VEC3_INLINE Vec3& operator-=(double); 00079 00080 // wangyc added ! 00081 VEC3_INLINE Vec3& operator/=(double); 00082 VEC3_INLINE double norm() const; 00083 VEC3_INLINE double norm2() const; 00084 VEC3_INLINE Vec3 unit() const; 00085 VEC3_INLINE Vec3 unit_s() const; //safe version (throw exceptions) 00086 VEC3_INLINE double max() const; 00087 VEC3_INLINE double min() const; 00088 00089 VEC3_INLINE Vec3 rotate(const Vec3 &axis, const Vec3 &axisPt) const; 00090 00091 VEC3_INLINE bool operator==(const Vec3&) const; 00092 VEC3_INLINE bool operator!=(const Vec3&) const; 00093 00094 VEC3_INLINE friend Vec3 cmax(const Vec3&,const Vec3&); 00095 VEC3_INLINE friend Vec3 cmin(const Vec3&,const Vec3&); 00096 00097 VEC3_INLINE friend Vec3 cross(const Vec3&,const Vec3&); 00098 VEC3_INLINE friend double dot(const Vec3&,const Vec3&); 00099 VEC3_INLINE friend Vec3 operator*(double,const Vec3&); 00100 00101 //n+1-ary operators 00102 VEC3_INLINE void mul_add_and_assign(const Vec3*,const Vec3*,const double&); 00103 VEC3_INLINE void mul_and_assign(const Vec3*,const double&); 00104 00105 VEC3_INLINE Vec3(const VDMulVadd&); 00106 VEC3_INLINE Vec3& operator=(const VDMulVadd&); 00107 00108 VEC3_INLINE Vec3(const VDMul&); 00109 VEC3_INLINE Vec3& operator=(const VDMul&); 00110 00111 //access stuff 00112 // wangyc added ! 00113 VEC3_INLINE void set_x(double x) {data[0] = x;} 00114 VEC3_INLINE void set_y(double y) {data[1] = y;} 00115 VEC3_INLINE void set_z(double z) {data[2] = z;} 00116 // void set_xyz(double x, double y, double z) 00117 // { data[0] = x; data[1] = y; data[2] = z;} 00118 00119 VEC3_INLINE double& X() {return data[0];}; 00120 VEC3_INLINE double& Y() {return data[1];}; 00121 VEC3_INLINE double& Z() {return data[2];}; 00122 VEC3_INLINE double X() const {return data[0];}; 00123 VEC3_INLINE double Y() const {return data[1];}; 00124 VEC3_INLINE double Z() const {return data[2];}; 00125 VEC3_INLINE const double &operator[](int i) const {return data[i];} 00126 VEC3_INLINE double& operator[](int i) {return data[i];} 00127 00128 // in/output 00129 VEC3_INLINE friend ostream& operator << (ostream&,const Vec3&); 00130 VEC3_INLINE friend istream& operator >> (istream&,Vec3&); 00131 00132 // comparison -> enable to use of Vec3 as key in STL map and set 00133 bool operator<(const Vec3&) const; 00134 00135 friend class Matrix3; 00136 }; 00137 00138 VEC3_INLINE Vec3 comp_max(const Vec3&,const Vec3&); 00139 VEC3_INLINE Vec3 comp_min(const Vec3&,const Vec3&); 00140 00141 #if DO_INLINE_VEC3 >= 1 00142 #include "Foundation/vec3.hpp" 00143 #endif 00144 00145 #endif // __VEC3_H