Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/embree/kernels/builders/priminfo.h
9912 views
1
// Copyright 2009-2021 Intel Corporation
2
// SPDX-License-Identifier: Apache-2.0
3
4
#pragma once
5
6
#include "primref.h"
7
8
namespace embree
9
{
10
// FIXME: maybe there's a better place for this util fct
11
__forceinline float areaProjectedTriangle(const Vec3fa& v0, const Vec3fa& v1, const Vec3fa& v2)
12
{
13
const Vec3fa e0 = v1-v0;
14
const Vec3fa e1 = v2-v0;
15
const Vec3fa d = cross(e0,e1);
16
return fabs(d.x) + fabs(d.y) + fabs(d.z);
17
}
18
19
//namespace isa
20
//{
21
template<typename BBox>
22
class CentGeom
23
{
24
public:
25
__forceinline CentGeom () {}
26
27
__forceinline CentGeom (EmptyTy)
28
: geomBounds(empty), centBounds(empty) {}
29
30
__forceinline CentGeom (const BBox& geomBounds, const BBox3fa& centBounds)
31
: geomBounds(geomBounds), centBounds(centBounds) {}
32
33
template<typename PrimRef>
34
__forceinline void extend_primref(const PrimRef& prim)
35
{
36
BBox bounds; Vec3fa center;
37
prim.binBoundsAndCenter(bounds,center);
38
geomBounds.extend(bounds);
39
centBounds.extend(center);
40
}
41
42
static void extend_ref (CentGeom& pinfo, const PrimRef& ref) {
43
pinfo.extend_primref(ref);
44
};
45
46
template<typename PrimRef>
47
__forceinline void extend_center2(const PrimRef& prim)
48
{
49
BBox3fa bounds = prim.bounds();
50
geomBounds.extend(bounds);
51
centBounds.extend(bounds.center2());
52
}
53
54
__forceinline void extend(const BBox& geomBounds_) {
55
geomBounds.extend(geomBounds_);
56
centBounds.extend(center2(geomBounds_));
57
}
58
59
__forceinline void merge(const CentGeom& other)
60
{
61
geomBounds.extend(other.geomBounds);
62
centBounds.extend(other.centBounds);
63
}
64
65
static __forceinline const CentGeom merge2(const CentGeom& a, const CentGeom& b) {
66
CentGeom r = a; r.merge(b); return r;
67
}
68
69
public:
70
BBox geomBounds; //!< geometry bounds of primitives
71
BBox3fa centBounds; //!< centroid bounds of primitives
72
};
73
74
typedef CentGeom<BBox3fa> CentGeomBBox3fa;
75
76
/*! stores bounding information for a set of primitives */
77
template<typename BBox>
78
class PrimInfoT : public CentGeom<BBox>
79
{
80
public:
81
using CentGeom<BBox>::geomBounds;
82
using CentGeom<BBox>::centBounds;
83
84
__forceinline PrimInfoT () {}
85
86
__forceinline PrimInfoT (EmptyTy)
87
: CentGeom<BBox>(empty), begin(0), end(0) {}
88
89
__forceinline PrimInfoT (size_t N)
90
: CentGeom<BBox>(empty), begin(0), end(N) {}
91
92
__forceinline PrimInfoT (size_t begin, size_t end, const CentGeomBBox3fa& centGeomBounds)
93
: CentGeom<BBox>(centGeomBounds), begin(begin), end(end) {}
94
95
template<typename PrimRef>
96
__forceinline void add_primref(const PrimRef& prim)
97
{
98
CentGeom<BBox>::extend_primref(prim);
99
end++;
100
}
101
102
template<typename PrimRef>
103
__forceinline void add_center2(const PrimRef& prim) {
104
CentGeom<BBox>::extend_center2(prim);
105
end++;
106
}
107
108
template<typename PrimRef>
109
__forceinline void add_center2(const PrimRef& prim, const size_t i) {
110
CentGeom<BBox>::extend_center2(prim);
111
end+=i;
112
}
113
114
/*__forceinline void add(const BBox& geomBounds_) {
115
CentGeom<BBox>::extend(geomBounds_);
116
end++;
117
}
118
119
__forceinline void add(const BBox& geomBounds_, const size_t i) {
120
CentGeom<BBox>::extend(geomBounds_);
121
end+=i;
122
}*/
123
124
__forceinline void merge(const PrimInfoT& other)
125
{
126
CentGeom<BBox>::merge(other);
127
begin += other.begin;
128
end += other.end;
129
}
130
131
static __forceinline const PrimInfoT merge(const PrimInfoT& a, const PrimInfoT& b) {
132
PrimInfoT r = a; r.merge(b); return r;
133
}
134
135
/*! returns the number of primitives */
136
__forceinline size_t size() const {
137
return end-begin;
138
}
139
140
__forceinline float halfArea() {
141
return expectedApproxHalfArea(geomBounds);
142
}
143
144
__forceinline float leafSAH() const {
145
return expectedApproxHalfArea(geomBounds)*float(size());
146
//return halfArea(geomBounds)*blocks(num);
147
}
148
149
__forceinline float leafSAH(size_t block_shift) const {
150
return expectedApproxHalfArea(geomBounds)*float((size()+(size_t(1)<<block_shift)-1) >> block_shift);
151
//return halfArea(geomBounds)*float((num+3) >> 2);
152
//return halfArea(geomBounds)*blocks(num);
153
}
154
155
/*! stream output */
156
friend embree_ostream operator<<(embree_ostream cout, const PrimInfoT& pinfo) {
157
return cout << "PrimInfo { begin = " << pinfo.begin << ", end = " << pinfo.end << ", geomBounds = " << pinfo.geomBounds << ", centBounds = " << pinfo.centBounds << "}";
158
}
159
160
public:
161
size_t begin,end; //!< number of primitives
162
};
163
164
typedef PrimInfoT<BBox3fa> PrimInfo;
165
//typedef PrimInfoT<LBBox3fa> PrimInfoMB;
166
//}
167
}
168
169