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