修改了底层节点的children返回问题

dev-VirtualTexture
yang.yongquan 2022-08-07 22:25:33 +08:00
parent b0a9ec3ae1
commit 82e2d51855
2 changed files with 13 additions and 8 deletions

View File

@ -46,10 +46,8 @@ bvhPtr BvhTree::subBvhTree(QVector4D initBound[], int l, int r) {
void BvhTree::traverseBvhTree(bvhPtr now, std::vector<GLuint>& children, std::vector<QVector4D>& bounds) { void BvhTree::traverseBvhTree(bvhPtr now, std::vector<GLuint>& children, std::vector<QVector4D>& bounds) {
if (now == NULL) return ; if (now == NULL) return ;
if(now.get()->getSon(0) || now.get()->getSon(1)) { children.push_back(now.get()->getLeftSon(0));
children.push_back(now.get()->getSon(0)); children.push_back(now.get()->getRightSon(1));
children.push_back(now.get()->getSon(1));
}
bounds.push_back(now.get()->bound); bounds.push_back(now.get()->bound);
traverseBvhTree(now.get()->child[0], children, bounds); traverseBvhTree(now.get()->child[0], children, bounds);
traverseBvhTree(now.get()->child[1], children, bounds); traverseBvhTree(now.get()->child[1], children, bounds);

View File

@ -22,11 +22,17 @@ struct BvhNode {
static bool y_compare(QVector4D a, QVector4D b) { static bool y_compare(QVector4D a, QVector4D b) {
return a.y() < b.y(); return a.y() < b.y();
} }
GLuint getSon(int k) { GLuint getLeftSon(int k) {
if (k >= 2) return 0; if (child[0] == NULL) {
if (child[k] == NULL) return INT_MAX;
}
return child[0].get()->lab;
}
GLuint getRightSon(int k) {
if (child[1] == NULL) {
return 0; return 0;
return child[k].get()->lab; }
return child[1].get()->lab;
} }
BvhNode() { BvhNode() {
child[0] = child[1] = NULL; child[0] = child[1] = NULL;
@ -55,6 +61,7 @@ public:
void traverseBvhTree(bvhPtr now, std::vector<GLuint>& children, std::vector<QVector4D>& bounds); void traverseBvhTree(bvhPtr now, std::vector<GLuint>& children, std::vector<QVector4D>& bounds);
// 获得 Bvh rootBvh部分的 children 数组,包围盒数组 vector 传输 // 获得 Bvh rootBvh部分的 children 数组,包围盒数组 vector 传输
void getBvhArray(std::vector<GLuint>& children, std::vector<QVector4D>& bounds); void getBvhArray(std::vector<GLuint>& children, std::vector<QVector4D>& bounds);
// 获得 BvhTree 中节点总数
GLuint getBvhNodeNum(); GLuint getBvhNodeNum();
}; };