Subversion Repositories gelsvn

Rev

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

Rev Author Line No. Line
290 jrf 1
#ifndef __BOUNDINGLNODE_H
2
#define __BOUNDINGLNODE_H
3
 
4
#include "BoundingNode.h"
5
 
6
#define USE_LEAF_BOXES 1
7
 
291 jrf 8
namespace Geometry
9
{
10
 
290 jrf 11
/// Leaf node of a bounding box tree. References triangle.
12
template<class BoxType>
13
class BoundingLNode: public BoundingNode<BoxType>
14
{
15
	Triangle tri;
16
 public:
17
 
18
#if USE_LEAF_BOXES
19
	BoundingLNode(const BoxType& box,
20
								const Triangle& _tri): BoundingNode<BoxType>(box), tri(_tri) {}
21
#else
22
	BoundingLNode(const Triangle& _tri): BoundingNode<BoxType>(BoxType()), tri(_tri) {}
23
#endif
24
 
25
	~BoundingLNode() {}
26
 
27
	bool intersect(const CGLA::Vec3f&,const CGLA::Vec3f&,float&) const;
28
	int intersect_cnt(const CGLA::Vec3f&,const CGLA::Vec3f&) const;
29
 
30
	void sq_distance(const CGLA::Vec3f&, float&, float&, float&) const;
31
 
32
	virtual bool is_leaf() const {return true;}
33
 
34
	const Triangle& get_tri() const {return tri;}
35
};
36
 
37
template<class BoxType>
38
inline bool BoundingLNode<BoxType>::intersect(const CGLA::Vec3f& p, 
39
																							const CGLA::Vec3f& dir,
40
																							float& tmin) const
41
{
42
#if USE_LEAF_BOXES
43
	if(BoxType::intersect(p,dir))
44
 		return tri.intersect(p,dir,tmin);
45
 	return false;
46
#else
47
	return tri.intersect(p,dir,tmin);
48
#endif
49
 
50
}
51
 
52
template<class BoxType>
53
inline int BoundingLNode<BoxType>::intersect_cnt(const CGLA::Vec3f& p, 
54
																								 const CGLA::Vec3f& dir) const
55
{
56
#if USE_LEAF_BOXES
291 jrf 57
	float tmin=1.0e33f;
290 jrf 58
	if(BoxType::intersect(p,dir) && 
59
		 tri.intersect(p,dir,tmin) &&
60
		 tmin > 0)
61
		return 1;
62
	return 0;
63
#else
64
	float tmin=1e33;
65
	if(tri.intersect(p,dir,tmin) &&
66
		 tmin > 0)
67
		return 1;
68
	return 0;
69
#endif
70
}
71
 
72
template<class BoxType>
73
inline void BoundingLNode<BoxType>::sq_distance(const CGLA::Vec3f& p, 
74
																								float& dmin, 
75
																								float& dmax, float& s) const
76
{
77
 	bool did_work = tri.signed_distance(p,dmax,s);
78
	if(!did_work) std::cout << dmax << std::endl;
79
	assert(did_work);
80
 	dmin = dmax; 
81
}
82
 
291 jrf 83
}
290 jrf 84
#endif