ArchitectureColoredPainting/ArchitectureColoredPainting/BvhTree.h

68 lines
1.5 KiB
C
Raw Normal View History

#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();
}
GLuint getLeftSon(int k) {
if (child[0] == NULL) {
return INT_MAX;
}
return child[0].get()->lab;
}
GLuint getRightSon(int k) {
if (child[1] == NULL) {
return 0;
}
return child[1].get()->lab;
}
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);
// <20><><EFBFBD><EFBFBD> BvhTree <20>нڵ<D0BD><DAB5><EFBFBD><EFBFBD><EFBFBD>
GLuint getBvhNodeNum();
};