OpenMEEG
vect3.h
Go to the documentation of this file.
1 /*
2 Project Name : OpenMEEG
3 
4 © INRIA and ENPC (contributors: Geoffray ADDE, Maureen CLERC, Alexandre
5 GRAMFORT, Renaud KERIVEN, Jan KYBIC, Perrine LANDREAU, Théodore PAPADOPOULO,
6 Emmanuel OLIVI
7 Maureen.Clerc.AT.inria.fr, keriven.AT.certis.enpc.fr,
8 kybic.AT.fel.cvut.cz, papadop.AT.inria.fr)
9 
10 The OpenMEEG software is a C++ package for solving the forward/inverse
11 problems of electroencephalography and magnetoencephalography.
12 
13 This software is governed by the CeCILL-B license under French law and
14 abiding by the rules of distribution of free software. You can use,
15 modify and/ or redistribute the software under the terms of the CeCILL-B
16 license as circulated by CEA, CNRS and INRIA at the following URL
17 "http://www.cecill.info".
18 
19 As a counterpart to the access to the source code and rights to copy,
20 modify and redistribute granted by the license, users are provided only
21 with a limited warranty and the software's authors, the holders of the
22 economic rights, and the successive licensors have only limited
23 liability.
24 
25 In this respect, the user's attention is drawn to the risks associated
26 with loading, using, modifying and/or developing or reproducing the
27 software by the user in light of its specific status of free software,
28 that may mean that it is complicated to manipulate, and that also
29 therefore means that it is reserved for developers and experienced
30 professionals having in-depth computer knowledge. Users are therefore
31 encouraged to load and test the software's suitability as regards their
32 requirements in conditions enabling the security of their systems and/or
33 data to be ensured and, more generally, to use and operate it in the
34 same conditions as regards security.
35 
36 The fact that you are presently reading this means that you have had
37 knowledge of the CeCILL-B license and that you accept its terms.
38 */
39 
40 #pragma once
41 
42 #if WIN32
43 #define _USE_MATH_DEFINES
44 #define _CRT_SECURE_NO_DEPRECATE 1
45 #endif
46 #include <cstdlib>
47 #include <cmath>
48 #include <iostream>
49 #include <om_common.h>
50 #include <vector>
51 
52 #include <OpenMEEG_Export.h>
53 
54 namespace OpenMEEG {
55 
62  class OPENMEEG_EXPORT Vect3 {
63 
64  double m[3];
65 
66  public:
67 
68  inline Vect3() { }
69  inline Vect3(const double& xx, const double& yy, const double& zz) { m[0] = xx; m[1] = yy; m[2] = zz; }
70  inline Vect3(const double& a) { std::fill(&m[0], &m[3], a); }
71  inline ~Vect3() { }
72 
73  Vect3& operator=(const Vect3& v) {
74  std::copy(&v.m[0], &v.m[3], &m[0]);
75  return *this;
76  }
77 
78  Vect3(const Vect3& v) {
79  m[0] = v.x();
80  m[1] = v.y();
81  m[2] = v.z();
82  }
83 
84  inline double& x() { return m[0]; }
85  inline const double& x() const { return m[0]; }
86 
87  inline double& y() { return m[1]; }
88  inline const double& y() const { return m[1]; }
89 
90  inline double& z() { return m[2]; }
91  inline const double& z() const { return m[2]; }
92 
93  inline double operator*(const Vect3& v) const { return m[0]*v.x()+m[1]*v.y()+m[2]*v.z(); }
94  inline double operator<(const Vect3& v) const { return ((m[0] != v.x())?(m[0] < v.x()):((m[1] != v.y())? (m[1] < v.y()):(m[2] < v.z()))); }
95 
96  inline double norm() const { return sqrt(norm2()); }
97  inline double norm2() const { return m[0]*m[0]+m[1]*m[1]+m[2]*m[2]; }
98 
99  inline bool operator==(const Vect3& v ) const { return (m[0]==v.x() && m[1]==v.y() && m[2]==v.z()); }
100  inline bool operator!=(const Vect3& v ) const { return (m[0]!=v.x() || m[1]!=v.y() || m[2]!=v.z()); }
101 
102  inline void operator+=(const Vect3& v) { m[0] += v.x(); m[1] += v.y(); m[2] += v.z(); }
103  inline void operator-=(const Vect3& v) { m[0] -= v.x(); m[1] -= v.y(); m[2] -= v.z(); }
104  inline void operator*=(const double& d) { m[0] *= d; m[1] *= d; m[2] *= d; }
105  inline void operator/=(const double& d) { operator*=(1.0/d); }
106 
107  inline void multadd(const double& d, const Vect3& v) {m[0] += d*v.x(); m[1] += d*v.y(); m[2] += d*v.z();}
108 
109  inline Vect3 operator+(const Vect3& v) const { return Vect3(m[0]+v.x(), m[1]+v.y(), m[2]+v.z()); }
110  inline Vect3 operator-(const Vect3& v) const { return Vect3(m[0]-v.x(), m[1]-v.y(), m[2]-v.z()); }
111  inline Vect3 operator^(const Vect3& v) const { return Vect3(m[1]*v.z()-m[2]*v.y(), m[2]*v.x()-m[0]*v.z(), m[0]*v.y()-m[1]*v.x()); }
112  inline Vect3 operator*(const double& d) const { return Vect3(d*m[0], d*m[1], d*m[2]); }
113  inline Vect3 operator/(const double& d) const { return Vect3(m[0]/d, m[1]/d, m[2]/d); }
114 
115  inline double operator() (const int i) const {
116  om_assert(i>=0 && i<3);
117  return m[i];
118  }
119 
120  inline double& operator()(const int i) {
121  om_assert(i>=0 && i<3);
122  return m[i];
123  }
124 
125  inline Vect3 operator-() { return Vect3(-m[0], -m[1], -m[2]); }
126 
127  inline double det(const Vect3& y2, const Vect3& y3) const {
128  return (*this)*(y2^y3); // y1.det(y2, y3):= y1/(y2^y3)
129  }
130 
131  inline double solangl(const Vect3& v1, const Vect3& v2, const Vect3& v3) const {
132  // De Munck : Good sign directly
133  const Vect3 Y1 = v1 - *this;
134  const Vect3 Y2 = v2 - *this;
135  const Vect3 Y3 = v3 - *this;
136  const double y1 = Y1.norm();
137  const double y2 = Y2.norm();
138  const double y3 = Y3.norm();
139  const double d = Y1*(Y2^Y3);
140  return 2.*atan2(d, (y1*y2*y3+y1*(Y2*Y3)+y2*(Y3*Y1)+y3*(Y1*Y2)));
141  }
142 
143  inline void normalize() {
144  *this /= (*this).norm();
145  }
146 
147  friend std::ostream& operator<<(std::ostream& os, const Vect3& v);
148  friend std::istream& operator>>(std::istream& is, Vect3& v);
149  };
150 
151  inline Vect3 operator*(const double& d, const Vect3& v) { return v*d; }
152 
153  inline std::istream& operator>>(std::istream& is, Vect3& v) {
154  return is >> v.x() >> v.y() >> v.z();
155  }
156 
157  inline std::ostream& operator<<(std::ostream& os, const Vect3& v) {
158  return os << v.x() << ' ' << v.y() << ' ' << v.z() ;
159  }
160 
161  typedef Vect3 Normal;
162  typedef std::vector<Normal> Normals;
163 }
double m[3]
Coordinates of the vector.
Definition: vect3.h:64
std::vector< Normal > Normals
Definition: vect3.h:162
Vect3(const Vect3 &v)
Definition: vect3.h:78
void multadd(const double &d, const Vect3 &v)
Definition: vect3.h:107
bool operator==(const Vect3 &v) const
Definition: vect3.h:99
Vect3 & operator=(const Vect3 &v)
Definition: vect3.h:73
Vect3 operator-(const Vect3 &v) const
Definition: vect3.h:110
std::istream & operator>>(std::istream &is, Conductivity< REP > &m)
bool operator!=(const Vect3 &v) const
Definition: vect3.h:100
Vect3 operator/(const double &d) const
Definition: vect3.h:113
Vect3 operator-()
Definition: vect3.h:125
double & operator()(const int i)
Definition: vect3.h:120
std::ostream & operator<<(std::ostream &os, const Conductivity< REP > &m)
const double & z() const
Definition: vect3.h:91
Vect3 operator*(const double &d, const Vect3 &v)
Definition: vect3.h:151
void operator/=(const double &d)
Definition: vect3.h:105
const double & x() const
Definition: vect3.h:85
double det(const Vect3 &y2, const Vect3 &y3) const
Definition: vect3.h:127
double norm2() const
Definition: vect3.h:97
void operator-=(const Vect3 &v)
Definition: vect3.h:103
double norm() const
Definition: vect3.h:96
const double & y() const
Definition: vect3.h:88
Vect3(const double &a)
Definition: vect3.h:70
Vect3 operator+(const Vect3 &v) const
Definition: vect3.h:109
void operator*=(const double &d)
Definition: vect3.h:104
double & x()
Definition: vect3.h:84
Vect3 operator*(const double &d) const
Definition: vect3.h:112
double & z()
Definition: vect3.h:90
double operator<(const Vect3 &v) const
Definition: vect3.h:94
Vect3.
Definition: vect3.h:62
double operator*(const Vect3 &v) const
Definition: vect3.h:93
Vect3 Normal
Definition: vect3.h:161
double solangl(const Vect3 &v1, const Vect3 &v2, const Vect3 &v3) const
Definition: vect3.h:131
Vect3 operator^(const Vect3 &v) const
Definition: vect3.h:111
void normalize()
Definition: vect3.h:143
void operator+=(const Vect3 &v)
Definition: vect3.h:102
Vect3(const double &xx, const double &yy, const double &zz)
Definition: vect3.h:69
double & y()
Definition: vect3.h:87