diff --git a/ArchitectureColoredPainting/BvhTree.cpp b/ArchitectureColoredPainting/BvhTree.cpp index 13ad178..e537e29 100644 --- a/ArchitectureColoredPainting/BvhTree.cpp +++ b/ArchitectureColoredPainting/BvhTree.cpp @@ -46,10 +46,8 @@ bvhPtr BvhTree::subBvhTree(QVector4D initBound[], int l, int r) { void BvhTree::traverseBvhTree(bvhPtr now, std::vector& children, std::vector& bounds) { if (now == NULL) return ; - if(now.get()->getSon(0) || now.get()->getSon(1)) { - children.push_back(now.get()->getSon(0)); - children.push_back(now.get()->getSon(1)); - } + children.push_back(now.get()->getLeftSon(0)); + children.push_back(now.get()->getRightSon(1)); bounds.push_back(now.get()->bound); traverseBvhTree(now.get()->child[0], children, bounds); traverseBvhTree(now.get()->child[1], children, bounds); diff --git a/ArchitectureColoredPainting/BvhTree.h b/ArchitectureColoredPainting/BvhTree.h index 1ccc0c6..0292602 100644 --- a/ArchitectureColoredPainting/BvhTree.h +++ b/ArchitectureColoredPainting/BvhTree.h @@ -22,11 +22,17 @@ struct BvhNode { static bool y_compare(QVector4D a, QVector4D b) { return a.y() < b.y(); } - GLuint getSon(int k) { - if (k >= 2) return 0; - if (child[k] == NULL) + 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[k].get()->lab; + } + return child[1].get()->lab; } BvhNode() { child[0] = child[1] = NULL; @@ -55,6 +61,7 @@ public: void traverseBvhTree(bvhPtr now, std::vector& children, std::vector& bounds); // 获得 Bvh (rootBvh部分)的 children 数组,包围盒数组 vector 传输 void getBvhArray(std::vector& children, std::vector& bounds); + // 获得 BvhTree 中节点总数 GLuint getBvhNodeNum(); };