38 #ifndef FCL_BV_SPLITTER_INL_H
39 #define FCL_BV_SPLITTER_INL_H
52 template <
typename BV>
54 : split_method(method)
60 template <
typename BV>
67 template <
typename BV>
72 tri_indices = tri_indices_;
77 template <
typename BV>
79 const BV& bv,
unsigned int* primitive_indices,
int num_primitives)
84 computeRule_mean(bv, primitive_indices, num_primitives);
87 computeRule_median(bv, primitive_indices, num_primitives);
90 computeRule_bvcenter(bv, primitive_indices, num_primitives);
93 std::cerr <<
"Split method not supported\n";
98 template <
typename S,
typename BV>
109 template <
typename BV>
116 template <
typename S,
typename BV>
128 if(bv.width() >= bv.height() && bv.width() >= bv.depth())
130 else if(bv.height() >= bv.width() && bv.height() >= bv.depth())
139 template <
typename BV>
141 const BV& bv,
unsigned int* primitive_indices,
int num_primitives)
144 *
this, bv, primitive_indices, num_primitives);
148 template <
typename S,
typename BV>
154 unsigned int* primitive_indices,
159 if(bv.width() >= bv.height() && bv.width() >= bv.depth())
161 else if(bv.height() >= bv.width() && bv.height() >= bv.depth())
169 for(
int i = 0; i < num_primitives; ++i)
181 for(
int i = 0; i < num_primitives; ++i)
192 template <
typename BV>
194 const BV& bv,
unsigned int* primitive_indices,
int num_primitives)
197 *
this, bv, primitive_indices, num_primitives);
201 template <
typename S,
typename BV>
207 unsigned int* primitive_indices,
212 if(bv.width() >= bv.height() && bv.width() >= bv.depth())
214 else if(bv.height() >= bv.width() && bv.height() >= bv.depth())
218 std::vector<S> proj(num_primitives);
222 for(
int i = 0; i < num_primitives; ++i)
232 for(
int i = 0; i < num_primitives; ++i)
236 std::sort(proj.begin(), proj.end());
238 if(num_primitives % 2 == 1)
240 splitter.
split_value = proj[(num_primitives - 1) / 2];
244 splitter.
split_value = (proj[num_primitives / 2] + proj[num_primitives / 2 - 1]) / 2;
250 template <
typename BV>
252 const BV& bv,
unsigned int* primitive_indices,
int num_primitives)
255 *
this, bv, primitive_indices, num_primitives);
259 template <
typename S>
268 computeSplitVector<S, OBB<S>>(bv, splitter.split_vector);
269 computeSplitValue_bvcenter<S, OBB<S>>(bv, splitter.split_value);
274 template <
typename S>
280 unsigned int* primitive_indices,
283 computeSplitVector<S, OBB<S>>(bv, splitter.split_vector);
284 computeSplitValue_mean<S, OBB<S>>(
285 bv, splitter.vertices, splitter.tri_indices, primitive_indices,
286 num_primitives, splitter.type, splitter.split_vector, splitter.split_value);
291 template <
typename S>
297 unsigned int* primitive_indices,
300 computeSplitVector<S, OBB<S>>(bv, splitter.split_vector);
301 computeSplitValue_median<S, OBB<S>>(
302 bv, splitter.vertices, splitter.tri_indices, primitive_indices,
303 num_primitives, splitter.type, splitter.split_vector, splitter.split_value);
308 template <
typename S>
317 computeSplitVector<S, RSS<S>>(bv, splitter.split_vector);
318 computeSplitValue_bvcenter<S, RSS<S>>(bv, splitter.split_value);
323 template <
typename S>
329 unsigned int* primitive_indices,
332 computeSplitVector<S, RSS<S>>(bv, splitter.split_vector);
333 computeSplitValue_mean<S, RSS<S>>(
334 bv, splitter.vertices, splitter.tri_indices, primitive_indices,
335 num_primitives, splitter.type, splitter.split_vector, splitter.split_value);
340 template <
typename S>
346 unsigned int* primitive_indices,
349 computeSplitVector<S, RSS<S>>(bv, splitter.split_vector);
350 computeSplitValue_median<S, RSS<S>>(
351 bv, splitter.vertices, splitter.tri_indices, primitive_indices,
352 num_primitives, splitter.type, splitter.split_vector, splitter.split_value);
357 template <
typename S>
366 computeSplitVector<S, kIOS<S>>(bv, splitter.split_vector);
367 computeSplitValue_bvcenter<S, kIOS<S>>(bv, splitter.split_value);
372 template <
typename S>
378 unsigned int* primitive_indices,
381 computeSplitVector<S, kIOS<S>>(bv, splitter.split_vector);
382 computeSplitValue_mean<S, kIOS<S>>(
383 bv, splitter.vertices, splitter.tri_indices, primitive_indices,
384 num_primitives, splitter.type, splitter.split_vector, splitter.split_value);
389 template <
typename S>
395 unsigned int* primitive_indices,
398 computeSplitVector<S, kIOS<S>>(bv, splitter.split_vector);
399 computeSplitValue_median<S, kIOS<S>>(
400 bv, splitter.vertices, splitter.tri_indices, primitive_indices,
401 num_primitives, splitter.type, splitter.split_vector, splitter.split_value);
406 template <
typename S>
415 computeSplitVector<S, OBBRSS<S>>(bv, splitter.split_vector);
416 computeSplitValue_bvcenter<S, OBBRSS<S>>(bv, splitter.split_value);
421 template <
typename S>
427 unsigned int* primitive_indices,
430 computeSplitVector<S, OBBRSS<S>>(bv, splitter.split_vector);
431 computeSplitValue_mean<S, OBBRSS<S>>(
432 bv, splitter.vertices, splitter.tri_indices, primitive_indices,
433 num_primitives, splitter.type, splitter.split_vector, splitter.split_value);
438 template <
typename S>
444 unsigned int* primitive_indices,
447 computeSplitVector<S, OBBRSS<S>>(bv, splitter.split_vector);
448 computeSplitValue_median<S, OBBRSS<S>>(
449 bv, splitter.vertices, splitter.tri_indices, primitive_indices,
450 num_primitives, splitter.type, splitter.split_vector, splitter.split_value);
455 template <
typename S>
462 return splitter.split_vector.dot(q) > splitter.split_value;
467 template <
typename S>
474 return splitter.split_vector.dot(q) > splitter.split_value;
479 template <
typename S>
486 return splitter.split_vector.dot(q) > splitter.split_value;
491 template <
typename S>
498 return splitter.split_vector.dot(q) > splitter.split_value;
503 template <
typename BV>
507 tri_indices =
nullptr;
512 template <
typename S,
typename BV>
517 split_vector = bv.axis.col(0);
522 template <
typename S,
typename BV>
529 template <
typename S>
534 split_vector = bv.
obb.
axis.col(0);
539 template <
typename S>
544 split_vector = bv.
obb.
axis.col(0);
549 template <
typename S,
typename BV>
553 split_value = center[0];
557 template <
typename S,
typename BV>
562 unsigned int* primitive_indices,
573 S c[3] = {0.0, 0.0, 0.0};
575 for(
int i = 0; i < num_primitives; ++i)
577 const Triangle& t = triangles[primitive_indices[i]];
582 c[0] += (p1[0] + p2[0] + p3[0]);
583 c[1] += (p1[1] + p2[1] + p3[1]);
584 c[2] += (p1[2] + p2[2] + p3[2]);
586 split_value = (c[0] * split_vector[0] + c[1] * split_vector[1] + c[2] * split_vector[2]) / (3 * num_primitives);
590 for(
int i = 0; i < num_primitives; ++i)
592 const Vector3<S>& p = vertices[primitive_indices[i]];
594 sum += v.dot(split_vector);
597 split_value = sum / num_primitives;
602 template <
typename S,
typename BV>
607 unsigned int* primitive_indices,
615 std::vector<S> proj(num_primitives);
619 for(
int i = 0; i < num_primitives; ++i)
621 const Triangle& t = triangles[primitive_indices[i]];
626 p1[1] + p2[1] + p3[1],
627 p1[2] + p2[2] + p3[2]);
629 proj[i] = centroid3.dot(split_vector) / 3;
634 for(
int i = 0; i < num_primitives; ++i)
636 const Vector3<S>& p = vertices[primitive_indices[i]];
638 proj[i] = v.dot(split_vector);
642 std::sort(proj.begin(), proj.end());
644 if(num_primitives % 2 == 1)
646 split_value = proj[(num_primitives - 1) / 2];
650 split_value = (proj[num_primitives / 2] + proj[num_primitives / 2 - 1]) / 2;