OpendTect  6.6
coord.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: A.H.Bril
8  Date: 21-6-1996
9  Contents: Positions: Coordinates
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "basicmod.h"
16 #include "geometry.h"
17 #include "undefval.h"
18 
19 
25 {
26 public:
27 
30 
32  : Geom::Point2D<OrdType>( p ) {}
33  Coord() : Geom::Point2D<OrdType>( 0, 0 ) {}
34  Coord( OrdType cx, OrdType cy )
35  : Geom::Point2D<OrdType>( cx, cy ) {}
36 
37  bool operator==( const Coord& crd ) const
38  { return mIsEqual(x,crd.x,mDefEps)
39  && mIsEqual(y,crd.y,mDefEps); }
40  bool operator!=( const Coord& crd ) const
41  { return ! (crd == *this); }
42  bool operator<(const Coord&crd) const
43  { return x<crd.x || (x==crd.x && y<crd.y); }
44  bool operator>(const Coord&crd) const
45  { return x>crd.x || (x==crd.x && y>crd.y); }
46 
47  DistType horDistTo(const Coord&) const;
48  DistType sqHorDistTo(const Coord&) const;
50  DistType angle(const Coord& from,const Coord& to) const;
51  DistType cosAngle(const Coord& from,const Coord& to) const;
53  //
54  Coord normalize() const;
55  OrdType dot(const Coord&) const;
56 
57  const char* toString() const;
58  const char* toPrettyString(int nrdec=2) const;
59  bool fromString(const char*);
60 
61  static const Coord& udf();
62  inline bool isUdf() const { return !isDefined(); }
63 };
64 
65 
66 
71 mExpClass(Basic) Coord3 : public Coord
72 {
73 public:
74 
75  Coord3() : z(0) {}
76  Coord3(const Coord& a, OrdType z_ )
77  : Coord(a), z(z_) {}
78  Coord3(const Coord3& xyz )
79  : Coord( xyz.x, xyz.y )
80  , z( xyz.z ) {}
81  Coord3( OrdType x_, OrdType y_, OrdType z_ )
82  : Coord(x_,y_), z(z_) {}
83 
84  OrdType& operator[]( int idx )
85  { return idx ? (idx==1 ? y : z) : x; }
86  OrdType operator[]( int idx ) const
87  { return idx ? (idx==1 ? y : z) : x; }
88 
89  inline Coord3 operator+(const Coord3&) const;
90  inline Coord3 operator-(const Coord3&) const;
91  inline Coord3 operator-() const;
92  inline Coord3 operator*(double) const;
93  inline Coord3 operator/(double) const;
94  inline Coord3 scaleBy( const Coord3& ) const;
95  inline Coord3 unScaleBy( const Coord3& ) const;
96 
97  inline Coord3& operator+=(const Coord3&);
98  inline Coord3& operator-=(const Coord3&);
99  inline Coord3& operator/=(double);
100  inline Coord3& operator*=(double);
101  inline Coord& coord() { return *this; }
102  inline const Coord& coord() const { return *this; }
103 
104  inline bool operator==(const Coord3&) const;
105  inline bool operator!=(const Coord3&) const;
106  bool isSameAs(const Coord3&, const Coord3&) const;
107 
108  DistType distTo(const Coord3&) const;
109  DistType sqDistTo(const Coord3&) const;
110 
111  inline DistType dot(const Coord3&) const;
112  inline Coord3 cross(const Coord3&) const;
113  DistType abs() const;
114  DistType sqAbs() const;
115  inline Coord3 normalize() const;
116 
117  static const Coord3& udf();
118  inline bool isDefined() const;
119  inline bool isUdf() const { return !isDefined(); }
120 
121  const char* toString() const;
122  bool fromString(const char*);
123 
125 
126 };
127 
128 
129 inline Coord3 operator*( double f, const Coord3& b )
130 { return Coord3(b.x*f, b.y*f, b.z*f ); }
131 
132 
133 namespace Values {
134 
139 template<>
141 {
142 public:
143  static Coord val() { return Coord::udf(); }
144  static bool hasUdf() { return true; }
145  static bool isUdf( Coord crd ) { return !crd.isDefined(); }
146  static void setUdf( Coord& crd ) { crd = Coord::udf(); }
147 };
148 
149 
154 template<>
156 {
157 public:
158  static Coord3 val() { return Coord3::udf(); }
159  static bool hasUdf() { return true; }
160  static bool isUdf( Coord3 crd ) { return !crd.isDefined(); }
161  static void setUdf( Coord3& crd ) { crd = Coord3::udf(); }
162 };
163 
164 } // namespace Values
165 
166 
167 inline bool Coord3::operator==( const Coord3& b ) const
168 {
169  const DistType dx = x-b.x; const DistType dy = y-b.y;
170  const DistType dz = z-b.z;
171  return mIsZero(dx,mDefEps) && mIsZero(dy,mDefEps) && mIsZero(dz,mDefEps);
172 }
173 
174 
175 inline bool Coord3::operator!=( const Coord3& b ) const
176 {
177  return !(b==*this);
178 }
179 
180 inline bool Coord3::isDefined() const
181 {
183 }
184 
185 
186 inline Coord3 Coord3::operator+( const Coord3& p ) const
187 {
188  return Coord3( x+p.x, y+p.y, z+p.z );
189 }
190 
191 
192 inline Coord3 Coord3::operator-( const Coord3& p ) const
193 {
194  return Coord3( x-p.x, y-p.y, z-p.z );
195 }
196 
197 
198 inline Coord3 Coord3::operator-() const
199 {
200  return Coord3( -x, -y, -z );
201 }
202 
203 
204 inline Coord3 Coord3::operator*( double factor ) const
205 { return Coord3( x*factor, y*factor, z*factor ); }
206 
207 
208 inline Coord3 Coord3::operator/( double denominator ) const
209 { return Coord3( x/denominator, y/denominator, z/denominator ); }
210 
211 
212 inline Coord3 Coord3::scaleBy( const Coord3& factor ) const
213 { return Coord3( x*factor.x, y*factor.y, z*factor.z ); }
214 
215 
216 inline Coord3 Coord3::unScaleBy( const Coord3& denominator ) const
217 { return Coord3( x/denominator.x, y/denominator.y, z/denominator.z ); }
218 
219 
220 inline Coord3& Coord3::operator+=( const Coord3& p )
221 {
222  x += p.x; y += p.y; z += p.z;
223  return *this;
224 }
225 
226 
227 inline Coord3& Coord3::operator-=( const Coord3& p )
228 {
229  x -= p.x; y -= p.y; z -= p.z;
230  return *this;
231 }
232 
233 
234 inline Coord3& Coord3::operator*=( double factor )
235 {
236  x *= factor; y *= factor; z *= factor;
237  return *this;
238 }
239 
240 
241 inline Coord3& Coord3::operator/=( double denominator )
242 {
243  x /= denominator; y /= denominator; z /= denominator;
244  return *this;
245 }
246 
247 
248 inline Coord::DistType Coord3::dot(const Coord3& b) const
249 { return x*b.x + y*b.y + z*b.z; }
250 
251 
252 inline Coord3 Coord3::cross(const Coord3& b) const
253 { return Coord3( y*b.z-z*b.y, z*b.x-x*b.z, x*b.y-y*b.x ); }
254 
255 
256 inline Coord3 Coord3::normalize() const
257 {
258  const DistType absval = abs();
259  if ( absval < 1e-10 )
260  return *this;
261 
262  return *this / absval;
263 }
264 
265 
Coord3::sqDistTo
DistType sqDistTo(const Coord3 &) const
Coord3
A cartesian coordinate in 3D space.
Definition: coord.h:72
Values::Undef< Coord3 >::isUdf
static bool isUdf(Coord3 crd)
Definition: coord.h:160
Coord::horDistTo
DistType horDistTo(const Coord &) const
Coord3::Coord3
Coord3(const Coord3 &xyz)
Definition: coord.h:78
Coord3::coord
const Coord & coord() const
Definition: coord.h:102
Coord::toPrettyString
const char * toPrettyString(int nrdec=2) const
Conv::to
T to(const F &fr)
Definition: convert.h:34
geometry.h
Coord3::Coord3
Coord3(OrdType x_, OrdType y_, OrdType z_)
Definition: coord.h:81
Coord3::udf
static const Coord3 & udf()
mIsEqual
#define mIsEqual(x, y, eps)
Definition: commondefs.h:67
Coord3::toString
const char * toString() const
Coord::OrdType
Pos::Ordinate_Type OrdType
Definition: coord.h:28
Coord3::z
OrdType z
Definition: coord.h:124
Coord::Coord
Coord(const Geom::Point2D< OrdType > &p)
Definition: coord.h:31
Values::Undef< Coord3 >::setUdf
static void setUdf(Coord3 &crd)
Definition: coord.h:161
mExpClass
#define mExpClass(module)
Definition: commondefs.h:177
mDefEps
#define mDefEps
Definition: commondefs.h:71
Coord3::Coord3
Coord3()
Definition: coord.h:75
Coord3::Coord3
Coord3(const Coord &a, OrdType z_)
Definition: coord.h:76
operator==
bool operator==(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:81
Coord::operator==
bool operator==(const Coord &crd) const
Definition: coord.h:37
Coord3::operator!=
bool operator!=(const Coord3 &) const
Definition: coord.h:175
undefval.h
Coord3::operator-=
Coord3 & operator-=(const Coord3 &)
Definition: coord.h:227
Pos::Distance_Type
double Distance_Type
Definition: commontypes.h:91
Coord3::operator+=
Coord3 & operator+=(const Coord3 &)
Definition: coord.h:220
Coord3::scaleBy
Coord3 scaleBy(const Coord3 &) const
Definition: coord.h:212
Coord
A cartesian coordinate in 2D space.
Definition: coord.h:25
Coord3::operator[]
OrdType operator[](int idx) const
Definition: coord.h:86
Coord::cosAngle
DistType cosAngle(const Coord &from, const Coord &to) const
saves the expensive acos() call
Coord3::operator==
bool operator==(const Coord3 &) const
Definition: coord.h:167
Values::isUdf
bool isUdf(const T &t)
Definition: undefval.h:245
Values::Undef< Coord3 >::val
static Coord3 val()
Definition: coord.h:158
Coord3::dot
DistType dot(const Coord3 &) const
Definition: coord.h:248
Coord3::isSameAs
bool isSameAs(const Coord3 &, const Coord3 &) const
Values::Undef< Coord >::val
static Coord val()
Definition: coord.h:143
Geom::Point2D::isDefined
bool isDefined() const
Definition: geometry.h:364
mIsZero
#define mIsZero(x, eps)
Definition: commondefs.h:66
operator!=
bool operator!=(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:90
mClass
#define mClass(module)
Definition: commondefs.h:181
Coord::DistType
Pos::Distance_Type DistType
Definition: coord.h:29
Values::Undef< Coord3 >
Undefined Coord3.
Definition: coord.h:156
Coord::sqHorDistTo
DistType sqHorDistTo(const Coord &) const
saves the expensive sqrt() call
Values::Undef< Coord >::isUdf
static bool isUdf(Coord crd)
Definition: coord.h:145
Coord3::isDefined
bool isDefined() const
Definition: coord.h:180
Coord::isUdf
bool isUdf() const
Definition: coord.h:62
Coord3::operator-
Coord3 operator-() const
Definition: coord.h:198
Coord::Coord
Coord()
Definition: coord.h:33
operator*
Coord3 operator*(double f, const Coord3 &b)
Definition: coord.h:129
Coord3::fromString
bool fromString(const char *)
Coord3::cross
Coord3 cross(const Coord3 &) const
Definition: coord.h:252
Coord3::normalize
Coord3 normalize() const
Definition: coord.h:256
Values::Undef< Coord >::setUdf
static void setUdf(Coord &crd)
Definition: coord.h:146
Coord::normalize
Coord normalize() const
Coord::dot
OrdType dot(const Coord &) const
Values::Undef< Coord >::hasUdf
static bool hasUdf()
Definition: coord.h:144
Geom
Definition: geometry.h:19
Geom::Point2D< Pos::Ordinate_Type >
operator-
int operator-(const DateInfo &di1, const DateInfo &di2)
Definition: dateinfo.h:128
Coord::operator!=
bool operator!=(const Coord &crd) const
Definition: coord.h:40
Coord3::isUdf
bool isUdf() const
Definition: coord.h:119
Coord3::operator*=
Coord3 & operator*=(double)
Definition: coord.h:234
Coord::angle
DistType angle(const Coord &from, const Coord &to) const
Coord::operator<
bool operator<(const Coord &crd) const
Definition: coord.h:42
Geom::Point2D::y
T y
Definition: geometry.h:68
Coord3::operator*
Coord3 operator*(double) const
Definition: coord.h:204
Geom::Point2D::x
T x
Definition: geometry.h:67
Coord::operator>
bool operator>(const Coord &crd) const
Definition: coord.h:44
Coord3::operator/=
Coord3 & operator/=(double)
Definition: coord.h:241
Coord3::distTo
DistType distTo(const Coord3 &) const
Coord::Coord
Coord(OrdType cx, OrdType cy)
Definition: coord.h:34
Pos::Ordinate_Type
double Ordinate_Type
Definition: commontypes.h:90
Values
Templatized undefined and initialisation (i.e. null) values.
Definition: color.h:113
Coord::udf
static const Coord & udf()
Coord3::sqAbs
DistType sqAbs() const
Coord::toString
const char * toString() const
Coord::fromString
bool fromString(const char *)
Coord3::operator+
Coord3 operator+(const Coord3 &) const
Definition: coord.h:186
Coord3::operator[]
OrdType & operator[](int idx)
Definition: coord.h:84
Values::Undef< Coord3 >::hasUdf
static bool hasUdf()
Definition: coord.h:159
Coord3::coord
Coord & coord()
Definition: coord.h:101
Coord3::operator/
Coord3 operator/(double) const
Definition: coord.h:208
Coord3::unScaleBy
Coord3 unScaleBy(const Coord3 &) const
Definition: coord.h:216
Coord3::abs
DistType abs() const
Values::Undef< Coord >
Undefined Coord.
Definition: coord.h:141

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B.V. 1995-2021