Subversion Repositories gelsvn

Rev

Rev 443 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 443 Rev 595
-
 
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
 
1
#ifndef __GEOMETRY_AABOX__H
12
#ifndef __GEOMETRY_AABOX__H
2
#define __GEOMETRY_AABOX__H
13
#define __GEOMETRY_AABOX__H
3
 
14
 
4
#include <iostream>
15
#include <iostream>
5
#include <vector>
16
#include <vector>
6
#include "Triangle.h"
17
#include "Triangle.h"
7
 
18
 
8
namespace Geometry
19
namespace Geometry
9
{
20
{
10
  const float DIST_THRESH = 5.0e-4f;
21
  const float DIST_THRESH = 5.0e-4f;
11
 
22
 
12
  class AABox
23
  class AABox
13
  {
24
  {
14
	CGLA::Vec3f pmin, pmax, interior_point;
25
	CGLA::Vec3f pmin, pmax, interior_point;
15
  public:
26
  public:
16
 
27
 
17
	AABox() {}
28
	AABox() {}
18
 
29
 
19
	AABox(const CGLA::Vec3f& _pmin, const CGLA::Vec3f& _pmax,
30
	AABox(const CGLA::Vec3f& _pmin, const CGLA::Vec3f& _pmax,
20
		  const CGLA::Vec3f& _interior_point):
31
		  const CGLA::Vec3f& _interior_point):
21
 
32
 
22
	pmin(_pmin), pmax(_pmax), interior_point(_interior_point)
33
	pmin(_pmin), pmax(_pmax), interior_point(_interior_point)
23
	{
34
	{
24
      for(int i=0;i<3;++i)
35
      for(int i=0;i<3;++i)
25
		if((pmax[i]-pmin[i]) < DIST_THRESH)
36
		if((pmax[i]-pmin[i]) < DIST_THRESH)
26
		{
37
		{
27
			pmax[i] += DIST_THRESH/2.0f;
38
			pmax[i] += DIST_THRESH/2.0f;
28
			pmin[i] -= DIST_THRESH/2.0f;
39
			pmin[i] -= DIST_THRESH/2.0f;
29
		}
40
		}
30
	  assert(pmin.all_le(interior_point));
41
	  assert(pmin.all_le(interior_point));
31
	  assert(pmax.all_ge(interior_point));
42
	  assert(pmax.all_ge(interior_point));
32
	}
43
	}
33
 
44
 
34
	const CGLA::Vec3f& get_pmin() const {return pmin;}
45
	const CGLA::Vec3f& get_pmin() const {return pmin;}
35
 
46
 
36
	const CGLA::Vec3f& get_pmax() const {return pmax;}
47
	const CGLA::Vec3f& get_pmax() const {return pmax;}
37
 
48
 
38
	bool intersect(const CGLA::Vec3f&, const CGLA::Vec3f&) const;
49
	bool intersect(const CGLA::Vec3f&, const CGLA::Vec3f&) const;
39
 
50
 
40
	void minmax_sq_dist(const CGLA::Vec3f& p, float& dmin, float& dmax) const;
51
	void minmax_sq_dist(const CGLA::Vec3f& p, float& dmin, float& dmax) const;
41
 
52
 
42
	static AABox box_triangle(const Triangle&);
53
	static AABox box_triangle(const Triangle&);
43
 
54
 
44
	static AABox box_and_split(const std::vector<Triangle>& invec,
55
	static AABox box_and_split(const std::vector<Triangle>& invec,
45
							   std::vector<Triangle>& lvec,
56
							   std::vector<Triangle>& lvec,
46
							   std::vector<Triangle>& rvec);
57
							   std::vector<Triangle>& rvec);
47
														 
58
														 
48
  };
59
  };
49
}
60
}
50
 
61
 
51
#endif
62
#endif
52
 
63