Subversion Repositories gelsvn

Rev

Rev 299 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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