-
Notifications
You must be signed in to change notification settings - Fork 7
/
kdTree.h
80 lines (62 loc) · 1.42 KB
/
kdTree.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef KDTREE_H
#define KDTREE_H
#include <vector>
#include "all.h"
//#include "AABB.h"
namespace HYF
{
const int KD_MAX_THREADS = 6;
class Triangle;
class IntersectResult
{
public:
IntersectResult() :
intersectPoint(0,0,0),
normalVec(0,0,0),
distance(1000000000000.0),
isInObj(false){};
~IntersectResult(){};
vector3 intersectPoint, normalVec;
bool isInObj;
double distance;
const Material* ma;
Primitive* primi;
};
const double INF = 1000000000000.0;
class TriangleBox {
public:
vector3 minPos, maxPos;
TriangleBox();
~TriangleBox() {}
void Update(Triangle* tri); // 更新
bool Cantain(vector3 O);
double CalnArea();
double Collide(vector3 ray_O, vector3 ray_V);
};
class TriangleNode {
public:
Triangle** tris; //每个节点中多个面片
int size, plane; //
double split; //分割点
TriangleBox box; //盒子
TriangleNode* leftNode; //左节点
TriangleNode* rightNode;//右节点
TriangleNode();
~TriangleNode();
};
class TriangleTree {
TriangleNode* root;
void DeleteTree(TriangleNode* node);
void SortTriangle(Triangle** tris, int l, int r, int coord, bool minCoord);
void DivideNode(TriangleNode* node);
IntersectResult TravelTree(TriangleNode* node, vector3 ray_O, vector3 ray_V);
public:
TriangleTree();
~TriangleTree();
TriangleNode* GetRoot() { return root; }
void BuildTree();
IntersectResult Collide(Ray ray);//光线和kdtree相交的结果
int intersect(Ray ray,IntersectResult& result);
};
}
#endif