From 82e2d518559863c5c5591f9dd2ced58476a33ddb Mon Sep 17 00:00:00 2001 From: "yang.yongquan" <3395816735@qq.com> Date: Sun, 7 Aug 2022 22:25:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E5=BA=95=E5=B1=82?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E7=9A=84children=E8=BF=94=E5=9B=9E=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ArchitectureColoredPainting/BvhTree.cpp | 6 ++---- ArchitectureColoredPainting/BvhTree.h | 15 +++++++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) 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(); };