Subversion Repositories gelsvn

Rev

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

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