Dandelion 1.1.2
A light-weight 3D builder for educational usage
载入中...
搜索中...
未找到
aabb.h
浏览该文件的文档.
1#ifndef DANDELION_UTILS_AABB_H
2#define DANDELION_UTILS_AABB_H
3
4#include <limits>
5#include <array>
6
7#include <Eigen/Core>
8#include <spdlog/spdlog.h>
9
10#include "ray.h"
11
12/*!
13 * \file utils/aabb.h
14 */
15
16/*!
17 * \ingroup utils
18 * \~chinese
19 * \brief BVH中的Aligned-axis bounding box
20 */
21class AABB
22{
23public:
24
25 /*! \~chinese x,y,z最小的点以及最大的点,两个点即能确定一个AABB */
26 Eigen::Vector3f p_min, p_max;
27
28 AABB();
29
30 AABB(const Eigen::Vector3f& p) : p_min(p), p_max(p) {}
31
32 AABB(const Eigen::Vector3f& p1, const Eigen::Vector3f& p2);
33
34 /*! \~chinese 返回p_max和p_min的距离,即AABB對角线的长度 */
35 Eigen::Vector3f diagonal() const;
36 /*! \~chinese 返回AABB的x,y,z中最长的一维 */
37 int max_extent() const;
38 /*! \~chinese 返回AABB的中心坐标 */
39 Eigen::Vector3f centroid();
40
41 /*
42 AABB intersect(const AABB& b);
43 bool inside(const Eigen::Vector3f& p, const AABB& b);
44 inline const Eigen::Vector3f& operator[](int i) const{
45 return (i==0) ? p_min : p_max;
46 }
47 */
48
49 /*!
50 * \~chinese
51 * \brief BVH加速求交的函数调用接口
52 *
53 * \param ray 求交的射线
54 * \param inv_dir (1/dir.x, 1/dir.y, 1/dir.z),乘法比除法快
55 * \param dir_is_neg 判断x,y,z方向是否为负,为负则交换t_min和t_max
56 */
57 bool
58 intersect(const Ray& ray, const Eigen::Vector3f& inv_dir, const std::array<int, 3>& dir_is_neg);
59};
60
61/*! \~chinese
62 * 将两个AABB融合,融合之后的AABB的p_min各维度取二者最小值,p_max各维度取二者最大值,返回融合之后的AABB
63 */
64AABB union_AABB(const AABB& b1, const AABB& b2);
65
66/*! \~chinese
67 * 将一个AABB和一个点融合,融合之后的AABB的p_min各维度取二者最小值,p_max各维度取二者最大值,返回融合之后的AABB
68 */
69AABB union_AABB(const AABB& b, const Eigen::Vector3f& p);
70
71/*!
72 * \~chinese
73 * \brief BVH加速求交的函数调用接口
74 *
75 * \param mesh 当前AABB所在的mesh
76 * \param face_idx 当前的面片所对应的index
77 */
78AABB get_aabb(const GL::Mesh& mesh, size_t face_idx);
79
80#endif // DANDELION_UTILS_AABB_H
AABB get_aabb(const GL::Mesh &mesh, size_t face_idx)
BVH加速求交的函数调用接口
定义 aabb.cpp:65
AABB union_AABB(const AABB &b1, const AABB &b2)
定义 aabb.cpp:76
BVH中的Aligned-axis bounding box
定义 aabb.h:22
int max_extent() const
定义 aabb.cpp:30
bool intersect(const Ray &ray, const Eigen::Vector3f &inv_dir, const std::array< int, 3 > &dir_is_neg)
BVH加速求交的函数调用接口
定义 aabb.cpp:48
Eigen::Vector3f p_min
定义 aabb.h:26
Eigen::Vector3f diagonal() const
定义 aabb.cpp:24
Eigen::Vector3f centroid()
定义 aabb.cpp:42
提供生成射线、判定相交的工具函数。
用于场景预览渲染的 Mesh 类。
定义 gl.hpp:268
定义 ray.h:24