RSMesh 1.0.0
一个曲面重构的系统,输入为点云,输出为obj,stl等主流格式的网格文件,使用的方法为径向基函数插值,采取了并行优化、Intel-MKL等优化措施,支持百万级别的点云
载入中...
搜索中...
未找到
bbox3d.cpp
1//
2// Created by RainSure on 2023/10/26.
3//
4
5#include "geometry/bbox3d.h"
6#include "common/eigen_utility.h"
7#include <limits>
8
9namespace rsmesh {
10 namespace geometry {
16 bbox3d::bbox3d() : min_(std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity()),
17 max_(-std::numeric_limits<double>::infinity(), -std::numeric_limits<double>::infinity(), -std::numeric_limits<double>::infinity()){}
18
24 bbox3d::bbox3d(const point3d &min, const point3d &max) : min_(min), max_(max){
25 }
31 bool bbox3d::operator==(const bbox3d &rhs) const {
32 return min_ == rhs.min_ and max_ == rhs.max_;
33 }
34
40 return min_ + size() / 2.0;
41 }
42
48 bool bbox3d::contains(const point3d &p) const {
49 return
50 p[0] >= min_[0] and p[0] <= max_[0] and
51 p[1] >= min_[1] and p[1] <= max_[1] and
52 p[2] >= min_[2] and p[2] <= max_[2];
53 }
54
60 bbox3d bbox3d::convex_hull(const bbox3d& other) const {
61 return {min_.cwiseMin(other.min_), max_.cwiseMax(other.max_)};
62 }
63
64 const point3d &bbox3d::max() const {
65 return max_;
66 }
67
68 const point3d &bbox3d::min() const {
69 return min_;
70 }
71
72 vector3d bbox3d::size() const {
73 return max_ - min_;
74 }
75
76 bbox3d bbox3d::transform(const linear_transformation3d &t) const {
77 auto c = center();
78 vector3d v1 = point3d(min_[0], max_[1], max_[2]) - c;
79 vector3d v2 = point3d(max_[0], min_[1], max_[2]) - c;
80 vector3d v3 = point3d(max_[0], max_[1], min_[2]) - c;
81
82 c = transform_point(t, c);
83 v1 = transform_vector(t, v1);
84 v2 = transform_vector(t, v2);
85 v3 = transform_vector(t, v3);
86
87 vectors3d vertices(8, 3);
88 vertices.row(0) = -v1 - v2 - v3; // min, min, min
89 vertices.row(1) = -v1; // max, min, min
90 vertices.row(2) = v3; // max, max, min
91 vertices.row(3) = -v2; // min, max, min
92 vertices.row(4) = v1; // min, max, max
93 vertices.row(5) = -v3; // min, min, max
94 vertices.row(6) = v2; // max, min, max
95 vertices.row(7) = v1 + v2 + v3; // max, max, max
96
97 auto min = c + vertices.colwise().minCoeff();
98 auto max = c + vertices.colwise().maxCoeff();
99
100 return {min, max};
101 }
102
103 bbox3d bbox3d::union_hull(const bbox3d &other) const {
104 return {
105 min().cwiseMin(other.min()),
106 max().cwiseMax(other.max())
107 };
108 }
109 // 以下代码无用了,替换为了更简洁的模板写法
110// bbox3d bbox3d::from_points(const points3d &points) {
111// return from_points(common::row_begin(points), common::row_end(points));
112// }
113
114 } // rsmesh
115} // geometry
bool contains(const point3d &p) const
Definition bbox3d.cpp:48
bbox3d()
bbox3d类的默认构造函数
Definition bbox3d.cpp:16
bool operator==(const bbox3d &rhs) const
重载了==运算符,用于判断两个bbox3d是否相等
Definition bbox3d.cpp:31
bbox3d convex_hull(const bbox3d &other) const
Definition bbox3d.cpp:60
point3d center() const
返回包围盒的中心点
Definition bbox3d.cpp:39
Eigen::Matrix< double, Eigen::Dynamic, 3, Eigen::RowMajor > vectors3d
3维向量的集合
Definition point3d.h:44
point3d transform_point(const linear_transformation3d &lhs, const point3d &p)
对一个三维点进行线性变换
Definition point3d.h:75
vector3d transform_vector(const linear_transformation3d &lhs, const vector3d &v)
对一个三维向量进行线性变换
Definition point3d.h:87
vector3d point3d
3维点
Definition point3d.h:39
Eigen::Matrix< double, 3, 3, Eigen::RowMajor > linear_transformation3d
线性变换矩阵
Definition point3d.h:53
Eigen::RowVector3d vector3d
3维向量
Definition point3d.h:30
本系统的主命名空间,包含了common, examples, fmm, geometry, numeric, point_cloud等子命名空间