42 template <
typename BV>
44 split_vector = bv.axes.col(0);
77 split_vector = bv.
obb.
axes.col(0);
82 split_vector = bv.
obb.
axes.col(0);
85 template <
typename BV>
87 Vec3s center = bv.center();
88 split_value = center[0];
91 template <
typename BV>
93 unsigned int* primitive_indices,
95 const Vec3s& split_vector,
100 for (
unsigned int i = 0; i < num_primitives; ++i) {
101 const Triangle&
t = triangles[primitive_indices[i]];
103 const Vec3s& p2 = vertices[
t[1]];
104 const Vec3s& p3 = vertices[
t[2]];
108 split_value =
c.dot(split_vector) / (3 * num_primitives);
111 for (
unsigned int i = 0; i < num_primitives; ++i) {
112 const Vec3s& p = vertices[primitive_indices[i]];
113 sum += p.dot(split_vector);
116 split_value = sum / num_primitives;
120 template <
typename BV>
122 unsigned int* primitive_indices,
124 const Vec3s& split_vector,
126 std::vector<CoalScalar> proj(num_primitives);
129 for (
unsigned int i = 0; i < num_primitives; ++i) {
130 const Triangle&
t = triangles[primitive_indices[i]];
132 const Vec3s& p2 = vertices[
t[1]];
133 const Vec3s& p3 = vertices[
t[2]];
134 Vec3s centroid3(
p1[0] + p2[0] + p3[0],
p1[1] + p2[1] + p3[1],
135 p1[2] + p2[2] + p3[2]);
137 proj[i] = centroid3.dot(split_vector) / 3;
140 for (
unsigned int i = 0; i < num_primitives; ++i) {
141 const Vec3s& p = vertices[primitive_indices[i]];
142 Vec3s v(p[0], p[1], p[2]);
143 proj[i] =
v.dot(split_vector);
147 std::sort(proj.begin(), proj.end());
149 if (num_primitives % 2 == 1) {
150 split_value = proj[(num_primitives - 1) / 2];
152 split_value = (proj[num_primitives / 2] + proj[num_primitives / 2 - 1]) / 2;
159 computeSplitVector<OBB>(bv, split_vector);
160 computeSplitValue_bvcenter<OBB>(bv, split_value);
165 unsigned int* primitive_indices,
166 unsigned int num_primitives) {
167 computeSplitVector<OBB>(bv, split_vector);
168 computeSplitValue_mean<OBB>(bv, vertices, tri_indices, primitive_indices,
169 num_primitives,
type, split_vector, split_value);
174 unsigned int* primitive_indices,
175 unsigned int num_primitives) {
176 computeSplitVector<OBB>(bv, split_vector);
177 computeSplitValue_median<OBB>(bv, vertices, tri_indices, primitive_indices,
178 num_primitives,
type, split_vector,
185 computeSplitVector<RSS>(bv, split_vector);
186 computeSplitValue_bvcenter<RSS>(bv, split_value);
191 unsigned int* primitive_indices,
192 unsigned int num_primitives) {
193 computeSplitVector<RSS>(bv, split_vector);
194 computeSplitValue_mean<RSS>(bv, vertices, tri_indices, primitive_indices,
195 num_primitives,
type, split_vector, split_value);
200 unsigned int* primitive_indices,
201 unsigned int num_primitives) {
202 computeSplitVector<RSS>(bv, split_vector);
203 computeSplitValue_median<RSS>(bv, vertices, tri_indices, primitive_indices,
204 num_primitives,
type, split_vector,
212 computeSplitValue_bvcenter<kIOS>(bv, split_value);
217 unsigned int* primitive_indices,
218 unsigned int num_primitives) {
220 computeSplitValue_mean<kIOS>(bv, vertices, tri_indices, primitive_indices,
221 num_primitives,
type, split_vector, split_value);
226 unsigned int* primitive_indices,
227 unsigned int num_primitives) {
229 computeSplitValue_median<kIOS>(bv, vertices, tri_indices, primitive_indices,
230 num_primitives,
type, split_vector,
238 computeSplitValue_bvcenter<OBBRSS>(bv, split_value);
243 unsigned int* primitive_indices,
244 unsigned int num_primitives) {
246 computeSplitValue_mean<OBBRSS>(bv, vertices, tri_indices, primitive_indices,
247 num_primitives,
type, split_vector,
253 unsigned int* primitive_indices,
254 unsigned int num_primitives) {
256 computeSplitValue_median<OBBRSS>(bv, vertices, tri_indices, primitive_indices,
257 num_primitives,
type, split_vector,
263 return split_vector.dot(
Vec3s(
q[0],
q[1],
q[2])) > split_value;
268 return split_vector.dot(
Vec3s(
q[0],
q[1],
q[2])) > split_value;
273 return split_vector.dot(
Vec3s(
q[0],
q[1],
q[2])) > split_value;
278 return split_vector.dot(
Vec3s(
q[0],
q[1],
q[2])) > split_value;