Dandelion
2.0.0
A light-weight 3D builder for educational usage
Toggle main menu visibility
载入中...
搜索中...
未找到
bvh.h
浏览该文件的文档.
1
#pragma once
2
3
#include <vector>
4
5
#include "
../geometry/mesh.hpp
"
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
*/
18
struct
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
*/
39
struct
SortNode
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
47
class
BVH
48
{
49
public
:
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的根节点 */
89
BVHNode
*
root
;
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
aabb.h
AABB
BVH中的Aligned-axis bounding box
定义
aabb.h:21
BVH::primitives
std::vector< size_t > primitives
定义
bvh.h:97
BVH::BVH
BVH(const Mesh &mesh)
BVH加速结构的构造函数
定义
bvh.cpp:21
BVH::root
BVHNode * root
定义
bvh.h:89
BVH::model
Eigen::Matrix4f model
定义
bvh.h:99
BVH::mesh
const Mesh & mesh
定义
bvh.h:95
BVH::recursively_build
BVHNode * recursively_build(std::vector< size_t > faces_idx)
定义
bvh.cpp:61
BVH::recursively_delete
void recursively_delete(BVHNode *node)
定义
bvh.cpp:41
BVH::count_nodes
size_t count_nodes(BVHNode *node)
定义
bvh.cpp:52
BVH::intersect
std::optional< Intersection > intersect(const Ray &ray, const Mesh &mesh, const Eigen::Matrix4f obj_model)
BVH加速求交的函数调用接口
定义
bvh.cpp:130
BVH::build
void build()
定义
bvh.cpp:26
BVH::ray_node_intersect
std::optional< Intersection > ray_node_intersect(BVHNode *node, const Ray &ray) const
获取BVH求交的结果
定义
bvh.cpp:143
mesh.hpp
ray.h
提供生成射线、判定相交的工具函数。
BVHNode
表示的是BVH建立的树中的节点
定义
bvh.h:19
Mesh
用于同步渲染数据的三角形 Mesh 。
定义
mesh.hpp:28
Ray
定义
ray.h:24
SortNode
用于在BVH划分左右子树时作为参与排序的节点
定义
bvh.h:40
src
utils
bvh.h
制作者
1.18.0