Subversion Repositories gelsvn

Rev

Rev 595 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
595 jab 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
 
443 jab 12
#ifndef __GEOMETRY_AABOX__H
13
#define __GEOMETRY_AABOX__H
290 jrf 14
 
15
#include <iostream>
16
#include <vector>
17
#include "Triangle.h"
18
 
291 jrf 19
namespace Geometry
20
{
21
  const float DIST_THRESH = 5.0e-4f;
290 jrf 22
 
291 jrf 23
  class AABox
24
  {
290 jrf 25
	CGLA::Vec3f pmin, pmax, interior_point;
291 jrf 26
  public:
290 jrf 27
 
28
	AABox() {}
29
 
30
	AABox(const CGLA::Vec3f& _pmin, const CGLA::Vec3f& _pmax,
291 jrf 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)
290 jrf 37
		{
291 jrf 38
			pmax[i] += DIST_THRESH/2.0f;
39
			pmin[i] -= DIST_THRESH/2.0f;
290 jrf 40
		}
291 jrf 41
	  assert(pmin.all_le(interior_point));
42
	  assert(pmax.all_ge(interior_point));
43
	}
290 jrf 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,
291 jrf 56
							   std::vector<Triangle>& lvec,
57
							   std::vector<Triangle>& rvec);
290 jrf 58
 
291 jrf 59
  };
60
}
290 jrf 61
 
62
#endif