UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
u3d_box.hpp
1 /* u3d_box.hpp */
2 /* $Id: u3d_box.hpp,v 1.13 2008/03/31 07:58:19 guser1 Exp $ */
3 #ifndef __u3d_box_hpp
4 #define __u3d_box_hpp
5 
6 #include "u3d_point.hpp"
7 #include "u3d_triangle.hpp"
8 
9 
10 class U3dPoint;
11 
12 enum U3D_BOX_STATE {
13  INVALID = 0,
14  ACCEPTABLE
15 };
16 
17 enum BOX_TRI_INT {
18  NO_INTERSECT,
19  INTERSECT,
20  INSIDE
21 };
22 
24 class U3dBox
25 {
26 public:
27 
29  U3dBox();
30 
32  U3dBox (double x_size, double y_size, double z_size);
33 
35  U3dBox (const U3dPoint& p1, const U3dPoint& p2);
36 
38  U3dBox (const U3dPoint& p, double x_size, double y_size, double z_size);
39 
41  U3dBox (const U3dBox& box);
42 
43  U3D_BOX_STATE validate(double xmin,
44  double xmax,
45  double ymin,
46  double ymax,
47  double zmin,
48  double zmax) const;
49 
51  bool checkOverlay(const U3dBox& box) const;
52 
54  BOX_TRI_INT intersectWithTriangle(const U3dTriangle& triangle, const U3dPoint& p1,
55  const U3dPoint& p2, const U3dPoint& p3);
56 
59 
60  /* Returns array of intersection points of triangle with box */
61  //int getIntersectWithTriangle(U3dPoint p1, U3dPoint p2, U3dPoint p3, U3dVertexAr* isectAr);
62 
64  bool checkInside (const U3dPoint& p) const;
66  bool checkDefinitelyInside (const U3dPoint& p) const;
68  bool checkInsideEps (const U3dPoint& p) const;
69 
70 
72  double getXMin () const;
73 
75  double getXMax () const;
76 
78  double getYMin () const;
79 
81  double getYMax () const;
82 
84  double getZMin () const;
85 
87  double getZMax () const;
88 
90  void setCoords(const double& xmin,
91  const double& xmax,
92  const double& ymin,
93  const double& ymax,
94  const double& zmin,
95  const double& zmax);
96 
98  int setXMin (double);
99 
101  int setXMax (double);
102 
104  int setYMin (double);
105 
107  int setYMax (double);
108 
110  int setZMin (double);
111 
113  int setZMax (double);
114 
116  double getXSize () const;
117 
119  double getYSize () const;
120 
122  double getZSize () const;
123 
125  double getDiag() const;
126 
129 
132 
135 
136  /* Get coordinates of center of the box */
137  //U3dVertex getCenter();
138 
142  int operator== (const U3dBox& rbox) const;
143 
147  int operator!= (const U3dBox& rbox) const {return !operator==(rbox); };
148 
149 protected:
150 
152  double fXRange[2];
153 
155  double fYRange[2];
156 
158  double fZRange[2];
159 
160 private:
161  int triBoxOverlap(U3dPoint boxcenter, double boxhalfsize[3], U3dPoint triverts[3]);
162  int planeBoxOverlap(U3dPoint normal,double d, double maxbox[3]);
163 };
164 
165 /* INLINE implementation */
166 
167 inline double
168 U3dBox::getXMin () const
169 {
170  return fXRange[0];
171 }
172 
173 inline double
174 U3dBox::getXMax () const
175 {
176  return fXRange[1];
177 }
178 
179 inline double
180 U3dBox::getYMin () const
181 {
182  return fYRange[0];
183 }
184 
185 inline double
186 U3dBox::getYMax () const
187 {
188  return fYRange[1];
189 }
190 
191 inline double
192 U3dBox::getZMin () const
193 {
194  return fZRange[0];
195 }
196 
197 inline double
198 U3dBox::getZMax () const
199 {
200  return fZRange[1];
201 }
202 
203 inline void
204 U3dBox::setCoords(const double& xmin,
205  const double& xmax,
206  const double& ymin,
207  const double& ymax,
208  const double& zmin,
209  const double& zmax)
210 {
211  fXRange[0] = xmin;
212  fXRange[1] = xmax;
213  fYRange[0] = ymin;
214  fYRange[1] = ymax;
215  fZRange[0] = zmin;
216  fZRange[1] = zmax;
217 }
218 
219 inline int U3dBox::setXMin (double xMin)
220 {
221  if (xMin >= fXRange[1])
222  return false;
223  fXRange[0] = xMin;
224  return true;
225 }
226 
227 inline int U3dBox::setXMax (double xMax)
228 {
229  if (xMax <= fXRange[0])
230  return false;
231  fXRange[1] = xMax;
232  return true;
233 }
234 
235 inline int U3dBox::setYMin (double yMin)
236 {
237  if (yMin >= fYRange[1])
238  return false;
239  fYRange[0] = yMin;
240  return true;
241 }
242 
243 inline int U3dBox::setYMax (double yMax)
244 {
245  if (yMax <= fYRange[0])
246  return false;
247  fYRange[1] = yMax;
248  return true;
249 }
250 
251 inline int U3dBox::setZMin (double zMin)
252 {
253  if (zMin >= fZRange[1])
254  return false;
255  fZRange[0] = zMin;
256  return true;
257 }
258 
259 inline int U3dBox::setZMax (double zMax)
260 {
261  if (zMax <= fZRange[0])
262  return false;
263  fZRange[1] = zMax;
264  return true;
265 }
266 
267 
268 inline double
269 U3dBox::getXSize () const
270 {
271  return fXRange[1] - fXRange[0];
272 }
273 
274 inline double
275 U3dBox::getYSize () const
276 {
277  return fYRange[1] - fYRange[0];
278 }
279 
280 inline double
281 U3dBox::getZSize () const
282 {
283  return fZRange[1] - fZRange[0];
284 }
285 
286 
287 U3dBox combineBox(U3dBox box1, U3dBox box2);
288 
289 #endif /* u3d_box.hpp */
int operator!=(const U3dBox &rbox) const
Definition: u3d_box.hpp:147
int setZMin(double)
Definition: u3d_box.hpp:244
int setXMin(double)
Definition: u3d_box.hpp:212
bool intersectWithSegment(U3dPoint pA, U3dPoint pB)
double fZRange[2]
Definition: u3d_box.hpp:158
int setYMin(double)
Definition: u3d_box.hpp:228
double getYMax() const
Definition: u3d_box.hpp:182
U3dPoint getLimitPoint()
Definition: u3d_box.hpp:24
bool checkDefinitelyInside(const U3dPoint &p) const
int setYMax(double)
Definition: u3d_box.hpp:236
Definition: u3d_triangle.hpp:18
double getXMax() const
Definition: u3d_box.hpp:172
double getXMin() const
Definition: u3d_box.hpp:167
int setXMax(double)
Definition: u3d_box.hpp:220
bool checkInsideEps(const U3dPoint &p) const
bool checkInside(const U3dPoint &p) const
Definition: u3d_point.hpp:16
U3dPoint getCenter()
double getYMin() const
Definition: u3d_box.hpp:177
double fXRange[2]
Definition: u3d_box.hpp:147
double getXSize() const
Definition: u3d_box.hpp:261
double getZSize() const
Definition: u3d_box.hpp:271
int operator==(const U3dBox &rbox) const
double getYSize() const
Definition: u3d_box.hpp:266
double getZMax() const
Definition: u3d_box.hpp:192
double getZMin() const
Definition: u3d_box.hpp:187
void setCoords(const double &xmin, const double &xmax, const double &ymin, const double &ymax, const double &zmin, const double &zmax)
Definition: u3d_box.hpp:197
double getDiag() const
BOX_TRI_INT intersectWithTriangle(const U3dTriangle &triangle, const U3dPoint &p1, const U3dPoint &p2, const U3dPoint &p3)
int setZMax(double)
Definition: u3d_box.hpp:252
U3dPoint getInitPoint()
double fYRange[2]
Definition: u3d_box.hpp:155
bool checkOverlay(const U3dBox &box) const