UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
u3d_point.hpp
1 /* u3d_point.hpp */
2 /* $Id: u3d_point.hpp,v 1.4 2008/05/20 08:38:22 sasha Exp $ */
3 #ifndef __u3d_point_hpp
4 #define __u3d_point_hpp
5 
6 #include <vector>
7 #include <cmath>
8 
9 
10 #define U3D_EPSILON 1.e-6
11 #define EQUAL_REALS(a,b) ( (fabs((a)-(b)) < U3D_EPSILON ? true : false) )
12 
13 
14 
16 class U3dPoint
17 {
18 public:
19 
21  U3dPoint ();
22 
23  virtual ~U3dPoint(){};
24 
26  U3dPoint (const U3dPoint& p);
27 
29  U3dPoint (double x, double y, double z);
30 
31  /* Create point with given point coordinates. */
32  //U3dPoint (U3dVertex vertex);
33 
35  U3dPoint& operator= (const U3dPoint& p);
36 
38  bool operator==(const U3dPoint&) const;
39 
41  bool operator!=(const U3dPoint&) const;
42 
43  // Point and Vector Operations (always valid)
44  U3dPoint operator+(U3dPoint) const; // +translate
45  U3dPoint operator-(U3dPoint) const; // -translate
46  //U3dPoint& operator+=(U3dVector); // inc translate
47  //U3dPoint& operator-=(U3dVector); // dec translate
48 
49  // Scalar Multiplication
50  friend U3dPoint operator*(int, U3dPoint);
51  friend U3dPoint operator*(U3dPoint, int);
52  friend U3dPoint operator*(double, U3dPoint);
53  friend U3dPoint operator*(U3dPoint, double);
54 
55  // Scalar Division
56  friend U3dPoint operator/(U3dPoint, int);
57  friend U3dPoint operator/(U3dPoint, double);
58 
60  double getX () const;
61 
63  double getY () const;
64 
66  double getZ () const;
67 
68  /* Check the point is inside given box. */
69  //virtual bool isInside (const U3dBox& mbox) const;
70 
72  void setXYZ (double x, double y, double z);
73 
75  void setX (double x);
76 
78  void setY (double y);
79 
81  void setZ (double z);
82 
83  //U3dVertex getVertex();
84 
85 protected:
86 
88  double m_X, m_Y, m_Z;
89 
90 };
91 
92 
93 /* INLINE implementation */
94 
96  : m_X(0.0), m_Y(0.0), m_Z(0.0)
97 {
98  /* dummy */
99 }
100 
101 inline U3dPoint::U3dPoint (const U3dPoint& p)
102  : m_X(p.getX()), m_Y(p.getY()), m_Z(p.getZ())
103 {
104  /* dummy */
105 }
106 
107 inline U3dPoint::U3dPoint (double x, double y, double z)
108  : m_X(x), m_Y(y), m_Z(z)
109 {
110  /* dummy */
111 }
112 /*
113  inline U3dPoint::U3dPoint (U3dVertex vertex)
114  : m_X(vertex.x), m_Y(vertex.y), m_Z(vertex.z)
115  {
116 
117  }*/
118 
119 inline U3dPoint&
121 {
122  m_X = p.getX();
123  m_Y = p.getY();
124  m_Z = p.getZ();
125  return *this;
126 }
127 
128 inline double
130 {
131  return m_X;
132 }
133 
134 inline double
136 {
137  return m_Y;
138 }
139 
140 inline double
142 {
143  return m_Z;
144 }
145 
146 inline void
147 U3dPoint::setXYZ (double x, double y, double z)
148 {
149  m_X = x;
150  m_Y = y;
151  m_Z = z;
152 }
153 
154 inline void
155 U3dPoint::setX (double x)
156 {
157  m_X = x;
158 }
159 
160 inline void
161 U3dPoint::setY (double y)
162 {
163  m_Y = y;
164 }
165 
166 inline void
167 U3dPoint::setZ (double z)
168 {
169  m_Z = z;
170 }
171 
172 typedef std::vector<U3dPoint> U3dPoints;
173 typedef std::vector<U3dPoint*> U3dPointsAr;
174 typedef std::vector<U3dPointsAr> U3dPointsMatrix;
175 
176 
177 /*=========================== GLOBAL FUNCTIONS ========================*/
178 
180 inline double pDistance(U3dPoint p0, U3dPoint p1)
181 {
182  return sqrt ( (p0.getX()-p1.getX())*(p0.getX()-p1.getX()) +
183  (p0.getY()-p1.getY())*(p0.getY()-p1.getY()) +
184  (p0.getZ()-p1.getZ())*(p0.getZ()-p1.getZ()) );
185 };
186 
188 int getNeighbour(U3dPoint p, U3dPointsAr p_ar);
189 
190 
191 #endif /* u3d_point.hpp */
void setXYZ(double x, double y, double z)
Definition: u3d_point.hpp:147
void setY(double y)
Definition: u3d_point.hpp:161
double m_X
Definition: u3d_point.hpp:88
void setX(double x)
Definition: u3d_point.hpp:155
double getZ() const
Definition: u3d_point.hpp:141
double getY() const
Definition: u3d_point.hpp:135
U3dPoint & operator=(const U3dPoint &p)
Definition: u3d_point.hpp:120
Definition: u3d_point.hpp:16
bool operator!=(const U3dPoint &) const
void setZ(double z)
Definition: u3d_point.hpp:167
U3dPoint()
Definition: u3d_point.hpp:95
double getX() const
Definition: u3d_point.hpp:129
bool operator==(const U3dPoint &) const