VR-Forces 5.0.1 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
point.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2003 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 /*******************************************************************************
6 ** $RCSfile: point.h,v $ $Revision: 1.27 $ $State: Exp $
7 *******************************************************************************/
8 
9 #ifndef point_H_
10 #define point_H_
11 
12 #ifndef NO_VRLINK
13 #include <vlutil/vlConfig.h>
14 #include <vlutil/vlString.h>
15 #include <vlutil/vlUtil.h>
16 #include <matrix/vlVector.h>
17 #endif
18 
19 #include <stdio.h>
20 #include <iostream>
22 
23 class Dt4dPoint;
24 class DtPoint;
25 
26 typedef DtPoint DtVertex;
27 
28 // DtPoint represents points in 3-space.
29 // DtPoint may rely on vrlink (for things like DtString and DtVector).
30 // This class has no virtual functions, in order to minimize its run-time
31 // size. (A terrain database can have millions of DtPoints, so the
32 // vtable ptr can matter).
33 
35 {
36 
37 public:
38 // friend std::ostream& operator<<(std::ostream& os, const DtPoint& point);
39 // friend std::istream& operator>>(std::istream& is, DtPoint& point);
40 
41 
42  DtPoint(
43  const double& x = 0.0,
44  const double& y = 0.0,
45  const double& z = 0.0);
46 
47  enum DtPointIndex {
48  DtPX = 0,
49  DtPY = 1,
50  DtPZ = 2,
51  DtMAXPointIndex
52  };
53 
54  DtPoint(const DtPoint& orig);
55  DtPoint(const DtVector& orig);
56  DtPoint(const Dt4dPoint& orig);
57 
58  virtual ~DtPoint();
59 
60  DtPoint& operator=(const DtPoint& rhs);
61  DtPoint& operator=(const DtVector& rhs);
62  DtPoint& operator=(const Dt4dPoint& rhs);
63 
64  const double& operator[](const int& index) const;
65  double& operator[](const int& index);
66 
67  const double& operator[](const DtPointIndex& index) const;
68  double& operator[](const DtPointIndex& index);
69 
70  bool operator==(const DtPoint& rhs) const;
71  bool operator!=(const DtPoint& rhs) const;
72 
73  DtPoint operator*(const double& rhs) const;
74  DtPoint& operator*=(const double& rhs);
75 
76  DtPoint operator/(const double& rhs) const;
77  DtPoint& operator/=(const double& rhs);
78 
79  DtPoint operator+(const DtPoint& rhs) const;
80  DtPoint& operator+=(const DtPoint& rhs);
81 
82  DtPoint operator+(const DtVector& rhs) const;
83  DtPoint& operator+=(const DtVector& rhs);
84 
85  DtPoint operator-(const DtPoint& rhs) const;
86  DtPoint& operator-=(const DtPoint& rhs);
87 
88  DtPoint operator-(const DtVector& rhs) const;
89  DtPoint& operator-=(const DtVector& rhs);
90 
91  // compares two points and returns true if the distance between them
92  // is within the tolerance value.
93  bool approxEq(const DtPoint& p, const double& tolerance) const;
94 
95  void get(double& x, double& y, double& z) const;
96  const double& x() const;
97  const double& y() const;
98  const double& z() const;
99 
100  void set( const double& x, const double& y, const double& z);
101  void setX(const double& x);
102  void setY(const double& y);
103  void setZ(const double& z);
104 
105  // Distance from this point to end point.
106  double distanceTo(const DtPoint & end) const;
107  double distanceSquaredTo(const DtPoint & end) const;
108 
109  // Distance from this point to end point. Ignores Z values.
110  double xyDistanceTo(const DtPoint & end) const;
111  double xyDistanceSquaredTo(const DtPoint & end) const;
112 
113  // Distance from this point to line defined by points A and B. Ignores Z.
114  double xyDistanceToLine(const DtPoint& pointA, const DtPoint& pointB) const;
115  double xyDistanceToLineSquared(const DtPoint& pointA, const DtPoint& pointB) const;
116 
117  // Assuming that this point is the end point of a vector
118  // starting at (0,0,0), This function normalizes that
119  // vector and sets this point to the normalized end point.
120  void normalize();
121 
122  // Distance from this point to the origin (0,0,0) point.
123  double magnitudeSquared() const;
124 
125  DtVector difference(const DtPoint& p) const;
126 
127 #ifndef NO_VRLINK
128  DtString string() const;
129 #endif
130 
131  bool readFrom(FILE* fp);
132  bool writeTo(FILE* fp);
133 
134  void dump(const char* label) const;
135 
136 protected:
137  double myRep[3];
138 };
139 
140 DT_DLL_geometry std::ostream& operator<<(std::ostream& os, const DtPoint& point);
141 DT_DLL_geometry std::istream& operator>>(std::istream& is, DtPoint& point);
142 
143 inline DtPoint::DtPoint(const double& x, const double& y, const double& z)
144 {
145  myRep[DtPX] = x;
146  myRep[DtPY] = y;
147  myRep[DtPZ] = z;
148 }
149 
151 {
152 }
153 
154 inline const double& DtPoint::operator[](const int& index) const
155 {
156  return myRep[index];
157 }
158 
159 inline double& DtPoint::operator[](const int& index)
160 {
161  return myRep[index];
162 }
163 
164 inline const double& DtPoint::operator[](const DtPointIndex& index) const
165 {
166  return myRep[index];
167 }
168 
169 inline double& DtPoint::operator[](const DtPointIndex& index)
170 {
171  return myRep[index];
172 }
173 
174 inline void DtPoint::set( const double& x, const double& y, const double& z)
175 {
176  myRep[DtPX] = x;
177  myRep[DtPY] = y;
178  myRep[DtPZ] = z;
179 }
180 
181 inline void DtPoint::get(double& x, double& y, double& z) const
182 {
183  x = myRep[DtPX];
184  y = myRep[DtPY];
185  z = myRep[DtPZ];
186 }
187 
188 inline const double& DtPoint::x() const
189 {
190  return myRep[DtPX];
191 }
192 
193 inline void DtPoint::setX(const double& x)
194 {
195  myRep[DtPX] = x;
196 }
197 
198 inline const double& DtPoint::y() const
199 {
200  return myRep[DtPY];
201 }
202 
203 inline void DtPoint::setY(const double& y)
204 {
205  myRep[DtPY] = y;
206 }
207 
208 inline const double& DtPoint::z() const
209 {
210  return myRep[DtPZ];
211 }
212 
213 inline void DtPoint::setZ(const double& z)
214 {
215  myRep[DtPZ] = z;
216 }
217 
218 #endif
const double & x() const
Definition: point.h:188
const double & operator[](const int &index) const
Definition: point.h:154
void get(double &x, double &y, double &z) const
Definition: point.h:181
DT_DLL_terrainCS bool operator==(const DtDegMinSec &lhs, const DtDegMinSec &rhs)
DT_DLL_features std::ostream & operator<<(std::ostream &, const DtFeatureTransform &)
std::ostream output.
DtPoint DtVertex
Definition: point.h:24
#define DT_DLL_geometry
Definition: geometryDefines.h:23
DtPointIndex
Definition: point.h:47
virtual ~DtPoint()
Definition: point.h:150
void setY(const double &y)
Definition: point.h:203
Definition: point.h:49
void set(const double &x, const double &y, const double &z)
Definition: point.h:174
const double & y() const
Definition: point.h:198
void setZ(const double &z)
Definition: point.h:213
Definition: point.h:48
double myRep[3]
Definition: point.h:137
void setX(const double &x)
Definition: point.h:193
DT_DLL_terrainCS bool operator!=(const DtDegMinSec &lhs, const DtDegMinSec &rhs)
Definition: point.h:50
const double & z() const
Definition: point.h:208
DT_DLL_features std::istream & operator>>(std::istream &, DtQuery &)
iostream input iteration
DtPoint(const double &x=0.0, const double &y=0.0, const double &z=0.0)
Definition: point.h:143
Definition: point.h:34

Document ID: Generated on Mon Jun 20 00:38:30 EDT 2022 from SVN revision 244029
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)