27std::ostream & operator << (std::ostream & str,
const Pos & pos);
28std::istream & operator >> (std::istream & is,
Pos & pos);
31DLLEXPORT RVector3 center(
const R3Vector & vPos);
32DLLEXPORT R3Vector normalise(
const R3Vector & vPos);
34DLLEXPORT
double jacobianDetXY(
const RVector3 & p1,
const RVector3 & p2,
const RVector3 & p3);
35DLLEXPORT
double angle(
const RVector3 & p1,
const RVector3 & p2,
const RVector3 & p3);
37DLLEXPORT
bool xVari(
const R3Vector & electrodeList);
38DLLEXPORT
bool yVari(
const R3Vector & electrodeList);
39DLLEXPORT
bool zVari(
const R3Vector & electrodeList);
42DLLEXPORT RVector
x(
const R3Vector & rv);
44DLLEXPORT RVector
y(
const R3Vector & rv);
46DLLEXPORT RVector
z(
const R3Vector & rv);
48DLLEXPORT RVector absR3(
const R3Vector & vPos);
50DLLEXPORT
void swapXY(R3Vector & rv);
51DLLEXPORT
void swapXZ(R3Vector & rv);
52DLLEXPORT
void swapYZ(R3Vector & rv);
54DLLEXPORT std::vector < RVector3 > loadRVector3(
const std::string & fileName);
55DLLEXPORT
void saveRVector3(
const std::vector < RVector3 > l,
const std::string & fileName);
59DLLEXPORT RVector
toArray(
const R3Vector & vec);
62DLLEXPORT RMatrix
toMatrix(
const R3Vector & vec);
86 Pos() : valid_(true) { assign(0.0, 0.0, 0.0); }
89 Pos(
bool valid) : valid_(valid) { assign(0.0, 0.0, 0.0); }
91 Pos(
double x,
double y) : valid_(true) { assign(
x,
y, 0.0); }
92 Pos(
double x,
double y,
double z) : valid_(true) { assign(x, y, z); }
94 Pos(
const Pos & pos) { copy_(pos); }
98 if (
this != & pos){ copy_(pos); }
return *
this; }
101 Pos & operator = (
const Vector < double > & v){
107 throwLengthError(WHERE_AM_I +
" v.size() < 2 " + str(v.size()));
113 inline double & operator [] (Index i) {
return mat_[i]; }
115 inline const double & operator [] (Index i)
const {
return mat_[i]; }
117 #define DEFINE_UNARY_MOD_OPERATOR__(OP) \
118 inline Pos & operator OP##= (const double & b){ mat_[0] OP##= b; mat_[1] OP##= b; mat_[2] OP##= b; return *this; }\
119 inline Pos & operator OP##= (const Pos & b){ mat_[0] OP##= b[0]; mat_[1] OP##= b[1]; mat_[2] OP##= b[2]; return *this; }\
121 DEFINE_UNARY_MOD_OPERATOR__(+)
122 DEFINE_UNARY_MOD_OPERATOR__(-)
123 DEFINE_UNARY_MOD_OPERATOR__(/)
124 DEFINE_UNARY_MOD_OPERATOR__(*)
126 #undef DEFINE_UNARY_MOD_OPERATOR__
128 Pos operator - ()
const {
return Pos(-mat_[0], -mat_[1], -mat_[2]); }
130 inline void setValid(
bool valid) { valid_ = valid; }
131 inline bool valid()
const {
return valid_; }
133 inline void assign(
const double & x,
const double & y,
const double & z) {
134 mat_[0] =
x; mat_[1] =
y; mat_[2] =
z;
138 inline const double &
x()
const {
return mat_[0]; }
139 inline const double &
y()
const {
return mat_[1]; }
140 inline const double &
z()
const {
return mat_[2]; }
141 inline void setX(
double x) { mat_[0] =
x; }
142 inline void setY(
double y) { mat_[1] =
y; }
143 inline void setZ(
double z) { mat_[2] =
z; }
146 inline void setVal(
const double & val, Index i) {
150 throwRangeError(WHERE_AM_I, i, 0, 3);
155 inline const double &
getVal(Index i)
const {
159 throwRangeError(WHERE_AM_I, i, 0, 3);
166 mat_[0] = rint(mat_[0] / tol) * tol;
167 mat_[1] = rint(mat_[1] / tol) * tol;
168 mat_[2] = rint(mat_[2] / tol) * tol;
174 return ((mat_[0] - p[0]) * (mat_[0] - p[0]) +
175 (mat_[1] - p[1]) * (mat_[1] - p[1]) +
176 (mat_[2] - p[2]) * (mat_[2] - p[2]));
187 return mat_[0] * mat_[0] + mat_[1] * mat_[1] + mat_[2] * mat_[2];
196 double angle(
const Pos & p)
const;
199 double angle(
const RVector3 & p1,
const RVector3 & p3)
const;
201 inline double dot(
const Pos & p)
const {
202 return mat_[0] * p[0] + mat_[1] * p[1] + mat_[2] * p[2];
205 inline double sum()
const {
206 return mat_[0] + mat_[1] + mat_[2];
209 Pos norm(
const Pos & p1,
const Pos & p2)
const;
220 double t = this->
abs();
221 if (t > TOLERANCE) *
this /= t;
228 Pos cross(
const Pos & p)
const;
230 Pos normXY(
const Pos & p)
const;
232 template <
class Matrix >
Pos & transform(
const Matrix & wm){
233 double x = mat_[0],
y = mat_[1],
z = mat_[2];
235 mat_[0] =
x * wm[0][0] +
y * wm[0][1] +
z * wm[0][2];
236 mat_[1] =
x * wm[1][0] +
y * wm[1][1] +
z * wm[1][2];
237 mat_[2] =
x * wm[2][0] +
y * wm[2][1] +
z * wm[2][2];
241 inline Pos & rotateX(
double phi){
242 double mat[3][3] ={{ 1.0, 0.0, 0.0},
243 { 0.0, std::cos(phi), -std::sin(phi)},
244 { 0.0, std::sin(phi), std::cos(phi)} };
245 return this->transform(mat);
247 inline Pos & rotateY(
double phi){
248 double mat[3][3] = {{std::cos(phi), 0.0, std::sin(phi)},
250 {-std::sin(phi), 0.0, std::cos(phi)}};
252 return this->transform(mat);
254 inline Pos & rotateZ(
double phi){
255 double mat[3][3] = {{std::cos(phi), -std::sin(phi), 0.0},
256 {std::sin(phi), std::cos(phi), 0.0},
258 return this->transform(mat);
261 inline Pos & rotate(
const RVector3 & r){
262 return this->rotateX(r[0]).rotateY(r[1]).rotateZ(r[2]);
264 inline Pos & rotate(
double phiX,
double phiY,
double phiZ){
265 return this->rotateX(phiX).rotateY(phiY).rotateZ(phiZ);
268 inline Pos & scale(
const RVector3 & s){
return (*
this) *= s;}
270 inline Pos & translate(
const RVector3 & t){
return (*
this) += t;}
272 inline Pos & translate(
double x,
double y=0.0,
double z=0.0){
273 mat_[0] +=
x; mat_[1] +=
y; mat_[2] +=
z;
return *
this; }
276 RVector vec()
const {
285 return GIMLI::hash(mat_[0], mat_[1], mat_[2], valid_);
290 ASSERT_RANGE(i, 0, 3);
291 ASSERT_RANGE(j, 0, 3);
293 double tmp = mat_[i];
300 inline void copy_(
const Pos & pos) {
301 valid_ = pos.valid(); assign(pos[0], pos[1], pos[2]);
319inline bool operator == (
const RVector3 & a ,
const RVector3 & b){
320 if (a.valid() != b.valid())
return false;
321 if (a.distSquared(b) < TOLERANCE)
return true;
else return false;
323inline bool operator != (
const RVector3 & a ,
const RVector3 & b){
326inline bool operator < (
const RVector3 & a ,
const RVector3 & b){
327 return a.distSquared() < b.distSquared();
329inline bool operator <= (
const RVector3 & a ,
const RVector3 & b){
330 return a.distSquared() <= b.distSquared();
332inline bool operator > (
const RVector3 & a ,
const RVector3 & b){
333 return a.distSquared() > b.distSquared();
335inline bool operator >= (
const RVector3 & a ,
const RVector3 & b){
336 return a.distSquared() >= b.distSquared();
338inline RVector3 RINT(
const RVector3 & a) {
339 std::cout << WHERE_AM_I << std::endl;
343#define DEFINE_POS_BIN_OPERATOR__(OP) \
344inline Pos operator OP (const Pos & a, const Pos & b){ \
345 Pos tmp(a); return tmp OP##= b; } \
346inline Pos operator OP (const Pos & a, const double & b){ \
347 Pos tmp(a); return tmp OP##= b; } \
348inline Pos operator OP (const double & a, const Pos & b){ \
349 Pos tmp(a, a, a); return tmp OP##= b; } \
352DEFINE_POS_BIN_OPERATOR__(+)
353DEFINE_POS_BIN_OPERATOR__(*)
354DEFINE_POS_BIN_OPERATOR__(/)
355DEFINE_POS_BIN_OPERATOR__(-)
358inline std::ostream & operator << (std::ostream & str, const
Pos & pos){
360 str << pos[0] <<
"\t" << pos[1] <<
"\t" << pos[2];
362 str <<
" pos is not valid";
367inline std::istream & operator >> (std::istream & is,
Pos & pos){
374 if (abs(a[0] - b[0]) < TOLERANCE) {
375 if (abs(a[1] - b[1]) < TOLERANCE) {
380 }
else return a[0] < b[0];
385 if (abs(a[0] - b[0]) < TOLERANCE) {
386 if (abs(a[1] - b[1]) < TOLERANCE) {
391 }
else return a[0] < b[0];
394inline bool posLesserX(
const RVector3 & a,
const RVector3 & b){
395 if (abs(a[0] - b[0]) < TOLERANCE) {
396 if (abs(a[1] - b[1]) < TOLERANCE) {
401 }
else return a[0] < b[0];
408 template<>
struct hash<
GIMLI::Pos> {
409 GIMLI::Index operator()(
const GIMLI::Pos & p)
const noexcept {
413 template<>
struct hash<
GIMLI::PosVector > {
414 GIMLI::Index operator()(
const GIMLI::PosVector & p)
const noexcept {
Simple row-based dense matrix based on Vector.
Definition matrix.h:324
3 dimensional vector
Definition pos.h:73
const double & getVal(Index i) const
Definition pos.h:155
Pos & normalise()
Definition pos.h:226
double distSquared() const
Definition pos.h:186
Pos(bool valid)
Definition pos.h:89
void setVal(const double &val, Index i)
Definition pos.h:146
double distance(const Pos &p) const
Definition pos.h:183
double distSquared(const Pos &p) const
Definition pos.h:173
double abs() const
Definition pos.h:190
void swap(Index i, Index j)
Definition pos.h:289
Pos norm() const
Definition pos.h:212
double length() const
Definition pos.h:193
Pos & normalize()
Definition pos.h:219
double dist(const Pos &p) const
Definition pos.h:180
Pos & round(double tol)
Definition pos.h:165
GIMLi main namespace for the Geophyiscal Inversion and Modelling Library.
Definition baseentity.h:24
RMatrix toMatrix(const R3Vector &vec)
Definition pos.cpp:149
RVector y(const R3Vector &rv)
Definition pos.cpp:114
RVector x(const R3Vector &rv)
Definition pos.cpp:107
RVector toArray(const R3Vector &vec)
Definition pos.cpp:139
RVector z(const R3Vector &rv)
Definition pos.cpp:120
bool posLesserXrY(const RVector3 &a, const RVector3 &b)
Definition pos.h:373
bool operator<(const PolynomialElement< ValueType > &a, const PolynomialElement< ValueType > &b)
Definition polynomial.h:48
R3Vector stdVectorRVector3ToR3Vector(const std::vector< Pos > &rv)
Definition pos.cpp:157
std::vector< Pos > R3VectorTostdVectorRVector3(const R3Vector &rv)
Definition pos.cpp:163
bool posLesserXYrZ(const RVector3 &a, const RVector3 &b)
Definition pos.h:384