Subversion Repositories gelsvn

Rev

Rev 291 | Rev 309 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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