688 |
khor |
1 |
/* ----------------------------------------------------------------------- *
|
|
|
2 |
* This file is part of GEL, http://www.imm.dtu.dk/GEL
|
|
|
3 |
* Copyright (C) the authors and DTU Informatics
|
|
|
4 |
* For license and list of authors, see ../../doc/intro.pdf
|
|
|
5 |
* ----------------------------------------------------------------------- */
|
|
|
6 |
|
|
|
7 |
/**
|
|
|
8 |
* @file AABox.h
|
|
|
9 |
* @brief Axis aligned bounding box class.
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
#ifndef __GEOMETRY_AABOX__H
|
|
|
13 |
#define __GEOMETRY_AABOX__H
|
|
|
14 |
|
|
|
15 |
#include <iostream>
|
|
|
16 |
#include <vector>
|
|
|
17 |
#include "Triangle.h"
|
|
|
18 |
|
|
|
19 |
namespace Geometry
|
|
|
20 |
{
|
|
|
21 |
const float DIST_THRESH = 5.0e-4f;
|
|
|
22 |
|
|
|
23 |
class AABox
|
|
|
24 |
{
|
|
|
25 |
CGLA::Vec3f pmin, pmax, interior_point;
|
|
|
26 |
public:
|
|
|
27 |
|
|
|
28 |
AABox() {}
|
|
|
29 |
|
|
|
30 |
AABox(const CGLA::Vec3f& _pmin, const CGLA::Vec3f& _pmax,
|
|
|
31 |
const CGLA::Vec3f& _interior_point):
|
|
|
32 |
|
|
|
33 |
pmin(_pmin), pmax(_pmax), interior_point(_interior_point)
|
|
|
34 |
{
|
|
|
35 |
for(int i=0;i<3;++i)
|
|
|
36 |
if((pmax[i]-pmin[i]) < DIST_THRESH)
|
|
|
37 |
{
|
|
|
38 |
pmax[i] += DIST_THRESH/2.0f;
|
|
|
39 |
pmin[i] -= DIST_THRESH/2.0f;
|
|
|
40 |
}
|
|
|
41 |
assert(pmin.all_le(interior_point));
|
|
|
42 |
assert(pmax.all_ge(interior_point));
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
const CGLA::Vec3f& get_pmin() const {return pmin;}
|
|
|
46 |
|
|
|
47 |
const CGLA::Vec3f& get_pmax() const {return pmax;}
|
|
|
48 |
|
|
|
49 |
bool intersect(const CGLA::Vec3f&, const CGLA::Vec3f&) const;
|
|
|
50 |
|
|
|
51 |
void minmax_sq_dist(const CGLA::Vec3f& p, float& dmin, float& dmax) const;
|
|
|
52 |
|
|
|
53 |
static AABox box_triangle(const Triangle&);
|
|
|
54 |
|
|
|
55 |
static AABox box_and_split(const std::vector<Triangle>& invec,
|
|
|
56 |
std::vector<Triangle>& lvec,
|
|
|
57 |
std::vector<Triangle>& rvec);
|
|
|
58 |
|
|
|
59 |
};
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
#endif
|