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.3 2008/05/23 07:25:27 sasha 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 m_x_range[2];
153 
155  double m_y_range[2];
156 
158  double m_z_range[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 U3dBox::getXMin () const
168 {
169  return m_x_range[0];
170 }
171 
172 inline double U3dBox::getXMax () const
173 {
174  return m_x_range[1];
175 }
176 
177 inline double U3dBox::getYMin () const
178 {
179  return m_y_range[0];
180 }
181 
182 inline double U3dBox::getYMax () const
183 {
184  return m_y_range[1];
185 }
186 
187 inline double U3dBox::getZMin () const
188 {
189  return m_z_range[0];
190 }
191 
192 inline double U3dBox::getZMax () const
193 {
194  return m_z_range[1];
195 }
196 
197 inline void U3dBox::setCoords(const double& xmin,
198  const double& xmax,
199  const double& ymin,
200  const double& ymax,
201  const double& zmin,
202  const double& zmax)
203 {
204  m_x_range[0] = xmin;
205  m_x_range[1] = xmax;
206  m_y_range[0] = ymin;
207  m_y_range[1] = ymax;
208  m_z_range[0] = zmin;
209  m_z_range[1] = zmax;
210 }
211 
212 inline int U3dBox::setXMin (double xMin)
213 {
214  if (xMin >= m_x_range[1])
215  return false;
216  m_x_range[0] = xMin;
217  return true;
218 }
219 
220 inline int U3dBox::setXMax (double xMax)
221 {
222  if (xMax <= m_x_range[0])
223  return false;
224  m_x_range[1] = xMax;
225  return true;
226 }
227 
228 inline int U3dBox::setYMin (double yMin)
229 {
230  if (yMin >= m_y_range[1])
231  return false;
232  m_y_range[0] = yMin;
233  return true;
234 }
235 
236 inline int U3dBox::setYMax (double yMax)
237 {
238  if (yMax <= m_y_range[0])
239  return false;
240  m_y_range[1] = yMax;
241  return true;
242 }
243 
244 inline int U3dBox::setZMin (double zMin)
245 {
246  if (zMin >= m_z_range[1])
247  return false;
248  m_z_range[0] = zMin;
249  return true;
250 }
251 
252 inline int U3dBox::setZMax (double zMax)
253 {
254  if (zMax <= m_z_range[0])
255  return false;
256  m_z_range[1] = zMax;
257  return true;
258 }
259 
260 
261 inline double U3dBox::getXSize () const
262 {
263  return m_x_range[1] - m_x_range[0];
264 }
265 
266 inline double U3dBox::getYSize () const
267 {
268  return m_y_range[1] - m_y_range[0];
269 }
270 
271 inline double U3dBox::getZSize () const
272 {
273  return m_z_range[1] - m_z_range[0];
274 }
275 
276 
277 U3dBox combineBox(U3dBox box1, U3dBox box2);
278 
279 #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)
int setYMin(double)
Definition: u3d_box.hpp:228
double m_x_range[2]
Definition: u3d_box.hpp:147
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 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 m_y_range[2]
Definition: u3d_box.hpp:155
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()
bool checkOverlay(const U3dBox &box) const
double m_z_range[2]
Definition: u3d_box.hpp:158