Subversion Repositories gelsvn

Rev

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

Rev 321 Rev 393
1
#include "BoundingNode.h"
1
#include "BoundingNode.h"
2
#include "BoundingINode.h"
2
#include "BoundingINode.h"
3
#include "BoundingLNode.h"
3
#include "BoundingLNode.h"
4
 
4
 
5
 
5
 
6
using namespace std;
6
using namespace std;
7
using namespace CGLA;
7
using namespace CGLA;
8
 
8
 
9
namespace Geometry
9
namespace Geometry
10
{
10
{
11
 
11
 
12
template<class BoxType>
12
template<class BoxType>
13
void BoundingNode<BoxType>::sq_distance(const Vec3f& p, 
13
void BoundingNode<BoxType>::sq_distance(const Vec3f& p, 
14
										float& dmin, float& dmax,
14
										float& dmin, float& dmax,
15
										float& s) const
15
										float& s) const
16
{
16
{
17
  BoxType::minmax_sq_dist(p, dmin, dmax);
17
  BoxType::minmax_sq_dist(p, dmin, dmax);
18
	s = 0;
18
	s = 0;
19
}
19
}
20
 
20
 
21
template<class BoxType>
21
template<class BoxType>
22
BoundingNode<BoxType>* 
22
BoundingNode<BoxType>* 
23
BoundingNode<BoxType>::build(std::vector<Triangle>& triangles)
23
BoundingNode<BoxType>::build(std::vector<Triangle>& triangles)
24
{
24
{
25
	int N = triangles.size();
25
	int N = triangles.size();
26
	if(N==1)
26
	if(N==1)
27
		{
27
		{
28
			const Triangle& t = triangles[0];
28
			const Triangle& t = triangles[0];
29
#if USE_LEAF_BOXES
29
#if USE_LEAF_BOXES
30
			return new BoundingLNode<BoxType>(BoxType::box_triangle(t), t);
30
			return new BoundingLNode<BoxType>(BoxType::box_triangle(t), t);
31
#else
31
#else
32
			return new BoundingLNode<BoxType>(t);
32
			return new BoundingLNode<BoxType>(t);
33
#endif
33
#endif
34
 
34
 
35
		}
35
		}
36
	else
36
	else
37
		{
37
		{
38
			std::vector<Triangle> triangles_left;
38
			std::vector<Triangle> triangles_left;
39
			std::vector<Triangle> triangles_right;
39
			std::vector<Triangle> triangles_right;
40
 
40
 
41
			BoxType box = 
41
			BoxType box = 
42
				BoxType::box_and_split(triangles, triangles_left, triangles_right);
42
				BoxType::box_and_split(triangles, triangles_left, triangles_right);
43
 
43
 
44
			BoundingNode* left  = build(triangles_left);
44
			BoundingNode* left  = build(triangles_left);
45
			BoundingNode* right = build(triangles_right);
45
			BoundingNode* right = build(triangles_right);
46
 
46
 
47
			BoundingNode<BoxType>* bn = new BoundingINode<BoxType>(box, left, right);
47
			BoundingNode<BoxType>* bn = new BoundingINode<BoxType>(box, left, right);
48
			return bn;
48
			return bn;
49
		}
49
		}
50
}
50
}
51
 
51
 
52
template class BoundingNode<AABox>;
52
template class BoundingNode<AABox>;
53
/*
53
/*
54
template BoundingNode<AABox>* 
54
template BoundingNode<AABox>* 
55
BoundingNode<AABox>::build(std::vector<Triangle>& triangles);
55
BoundingNode<AABox>::build(std::vector<Triangle>& triangles);
56
*/
56
*/
57
template class BoundingNode<OBox>;
57
template class BoundingNode<OBox>;
58
/*template BoundingNode<OBox>* 
58
/*template BoundingNode<OBox>* 
59
BoundingNode<OBox>::build(std::vector<Triangle>& triangles);
59
BoundingNode<OBox>::build(std::vector<Triangle>& triangles);
60
*/
60
*/
61
}
61
}
62
 
62