Dandelion 1.1.2
A light-weight 3D builder for educational usage
载入中...
搜索中...
未找到
bvh.h
浏览该文件的文档.
1#ifndef DANDELION_UTILS_BVH_H
2#define DANDELION_UTILS_BVH_H
3
4#include <vector>
5#include <memory>
6#include <algorithm>
7
8#include "../src/platform/gl.hpp"
9#include "./ray.h"
10#include "aabb.h"
11
12/*!
13 * \file utils/bvh.h
14 */
15
16/*!
17 * \ingroup utils
18 * \~chinese
19 * \brief 表示的是BVH建立的树中的节点
20 */
21struct BVHNode
22{
23 /*! \~english Initialization of the BVHNode */
24 BVHNode();
25 /*! \~english Aligned-axis bounding box */
26 AABB aabb;
27 /*! \~english left node of the BVHNode */
28 BVHNode* left;
29 /*! \~english right node of the BVHNode */
30 BVHNode* right;
31 /*! \~english face index of current node, initialized to 0
32 * will only >0 in leaf nodes(the number of faces it covers <= 1)
33 */
34 size_t face_idx;
35};
36
37/*!
38 * \ingroup utils
39 * \~chinese
40 * \brief 用于在BVH划分左右子树时作为参与排序的节点
41 */
43{
44 /*! \~english face index of the sorted node */
45 size_t index;
46 /*! \~english centroid of the current AABB */
47 Eigen::Vector3f centroid;
48};
49
50class BVH
51{
52public:
53
54 /*!
55 * \~chinese
56 * \brief BVH加速结构的构造函数
57 *
58 * 传入当前mesh的类型
59 *
60 * \param mesh_type mesh的类型
61 */
62 BVH(const GL::Mesh& mesh);
63
64 /*! \~chinese 建立整个object的bvh的函数调用接口 */
65 void build();
66
67 /*! \~chinese 删除建立的整个bvh */
68 void recursively_delete(BVHNode* node);
69
70 /*! \~chinese 统计当前bvh的节点总数 */
71 size_t count_nodes(BVHNode* node);
72 /*!
73 * \~chinese
74 * \brief BVH加速求交的函数调用接口
75 *
76 * \param ray 求交的射线
77 * \param mesh 当前的mesh
78 * \param obj_model 当前mesh所在object的model矩阵
79 */
80 std::optional<Intersection>
81 intersect(const Ray& ray, const GL::Mesh& mesh, const Eigen::Matrix4f obj_model);
82
83 /*!
84 * \~chinese
85 * \brief 获取BVH求交的结果
86 * \param node 求交的节点
87 * \param ray 求交的射线
88 */
89 std::optional<Intersection> ray_node_intersect(BVHNode* node, const Ray& ray) const;
90
91 /*! \~chinese 整个bvh的根节点 */
93
94 /*! \~chinese 建立整个object的bvh的函数具体实现,边界条件为覆盖的面片数<=1 */
95 BVHNode* recursively_build(std::vector<size_t> faces_idx);
96
97 /*! \~chinese 当前bvh所在object的mesh */
98 const GL::Mesh& mesh;
99 /*! \~chinese 当前mesh的所有图元索引 */
100 std::vector<size_t> primitives;
101 /*! \~chinese 当前bvh所在object的model矩阵 */
102 Eigen::Matrix4f model;
103};
104
105#endif // DANDELION_UTILS_BVH_H
BVH中的Aligned-axis bounding box
定义 aabb.h:22
std::vector< size_t > primitives
定义 bvh.h:100
BVHNode * root
定义 bvh.h:92
Eigen::Matrix4f model
定义 bvh.h:102
BVH(const GL::Mesh &mesh)
BVH加速结构的构造函数
定义 bvh.cpp:22
BVHNode * recursively_build(std::vector< size_t > faces_idx)
定义 bvh.cpp:62
void recursively_delete(BVHNode *node)
定义 bvh.cpp:42
std::optional< Intersection > intersect(const Ray &ray, const GL::Mesh &mesh, const Eigen::Matrix4f obj_model)
BVH加速求交的函数调用接口
定义 bvh.cpp:130
size_t count_nodes(BVHNode *node)
定义 bvh.cpp:53
const GL::Mesh & mesh
定义 bvh.h:98
void build()
定义 bvh.cpp:27
std::optional< Intersection > ray_node_intersect(BVHNode *node, const Ray &ray) const
获取BVH求交的结果
定义 bvh.cpp:145
提供生成射线、判定相交的工具函数。
表示的是BVH建立的树中的节点
定义 bvh.h:22
用于场景预览渲染的 Mesh 类。
定义 gl.hpp:268
定义 ray.h:24
用于在BVH划分左右子树时作为参与排序的节点
定义 bvh.h:43