2022-08-07 18:46:39 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <QOpenGLTexture>
|
|
|
|
|
#include <QOpenGLContext>
|
|
|
|
|
#include <QTextCodec>
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <QVector4D>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#define bvhPtr std::tr1::shared_ptr<BvhNode>
|
|
|
|
|
|
|
|
|
|
// BvhTree <20>ڵ<EFBFBD>
|
|
|
|
|
struct BvhNode {
|
|
|
|
|
GLuint lab;
|
|
|
|
|
QVector4D bound;
|
|
|
|
|
bvhPtr child[2];
|
|
|
|
|
static bool x_compare(QVector4D a, QVector4D b) {
|
|
|
|
|
return a.x() < b.x();
|
|
|
|
|
}
|
|
|
|
|
static bool y_compare(QVector4D a, QVector4D b) {
|
|
|
|
|
return a.y() < b.y();
|
|
|
|
|
}
|
2022-08-07 22:25:33 +08:00
|
|
|
|
GLuint getLeftSon(int k) {
|
|
|
|
|
if (child[0] == NULL) {
|
|
|
|
|
return INT_MAX;
|
|
|
|
|
}
|
|
|
|
|
return child[0].get()->lab;
|
|
|
|
|
}
|
|
|
|
|
GLuint getRightSon(int k) {
|
|
|
|
|
if (child[1] == NULL) {
|
2022-08-07 18:46:39 +08:00
|
|
|
|
return 0;
|
2022-08-07 22:25:33 +08:00
|
|
|
|
}
|
|
|
|
|
return child[1].get()->lab;
|
2022-08-07 18:46:39 +08:00
|
|
|
|
}
|
|
|
|
|
BvhNode() {
|
|
|
|
|
child[0] = child[1] = NULL;
|
|
|
|
|
}
|
|
|
|
|
int maximumBound() {
|
|
|
|
|
return (std::fabs(bound.x() - bound.w()) < std::fabs(bound.y() - bound.z()));
|
|
|
|
|
}
|
|
|
|
|
~BvhNode() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class BvhTree
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
GLuint tot;
|
|
|
|
|
bvhPtr root;
|
|
|
|
|
static QVector4D calcBound(QVector4D initBound[], int l, int r);
|
|
|
|
|
static QVector4D Union(QVector4D a, QVector4D b);
|
|
|
|
|
public:
|
|
|
|
|
BvhTree() {
|
|
|
|
|
tot = 0;
|
|
|
|
|
root = NULL;
|
|
|
|
|
}
|
|
|
|
|
// <20><><EFBFBD>ݵײ<DDB5><D7B2><EFBFBD>Χ<EFBFBD><CEA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bvh<76><68>
|
|
|
|
|
void buildBvhTree(QVector4D initBound[], int len);
|
|
|
|
|
bvhPtr subBvhTree(QVector4D initBound[], int l, int r);
|
|
|
|
|
void traverseBvhTree(bvhPtr now, std::vector<GLuint>& children, std::vector<QVector4D>& bounds);
|
|
|
|
|
// <20><><EFBFBD><EFBFBD> Bvh <20><>rootBvh<76><68><EFBFBD>֣<EFBFBD><D6A3><EFBFBD> children <20><><EFBFBD>飬<EFBFBD><E9A3AC>Χ<EFBFBD><CEA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD> vector <20><><EFBFBD><EFBFBD>
|
|
|
|
|
void getBvhArray(std::vector<GLuint>& children, std::vector<QVector4D>& bounds);
|
2022-08-07 22:25:33 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD> BvhTree <20>нڵ<D0BD><DAB5><EFBFBD><EFBFBD><EFBFBD>
|
2022-08-07 18:46:39 +08:00
|
|
|
|
GLuint getBvhNodeNum();
|
|
|
|
|
};
|
|
|
|
|
|