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>
77 template <
typename BV>
79 const BV& bv,
unsigned int* primitive_indices,
int 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>
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;
int split_axis
The axis based on which the split decision is made. For most BV, the axis is aligned with one of the ...
void set(Vector3< S > *vertices_, Triangle *tri_indices_, BVHModelType type_)
Set the geometry data needed by the split rule.
void computeSplitValue_mean(const BV &bv, Vector3< S > *vertices, Triangle *triangles, unsigned int *primitive_indices, int num_primitives, BVHModelType type, const Vector3< S > &split_vector, S &split_value)
BVHModelType
BVH model type.
virtual ~BVSplitter()
Default deconstructor.
void computeRule_median(const BV &bv, unsigned int *primitive_indices, int num_primitives)
Split algorithm 3: Split the node according to the median of the data contained.
void clear()
Clear the geometry data set before.
SplitMethodType
Three types of split algorithms are provided in FCL as default.
void computeSplitValue_bvcenter(const BV &bv, S &split_value)
void computeRule_bvcenter(const BV &bv, unsigned int *primitive_indices, int num_primitives)
Split algorithm 1: Split the node from center.
bool apply(const Vector3< S > &q) const
Apply the split rule on a given point.
Vector3< S > * vertices
The mesh vertices or points handled by the splitter.
Eigen::Matrix< S, 3, 1 > Vector3
Triangle * tri_indices
The triangles handled by the splitter.
static bool run(const BVSplitter< OBB< S >> &splitter, const Vector3< S > &q)
Triangle with 3 indices for points.
Vector3< S > split_vector
void computeSplitVector(const BV &bv, Vector3< S > &split_vector)
static bool run(const BVSplitter< kIOS< S >> &splitter, const Vector3< S > &q)
OBB< S > obb
OBB related with kIOS.
static void run(BVSplitter< OBB< S >> &splitter, const OBB< S > &bv, unsigned int *, int)
static void run(BVSplitter< BV > &splitter, const BV &bv, unsigned int *, int)
static void run(BVSplitter< kIOS< S >> &splitter, const kIOS< S > &bv, unsigned int *, int)
BVSplitter(SplitMethodType method)
void computeRule(const BV &bv, unsigned int *primitive_indices, int num_primitives)
Compute the split rule according to a subset of geometry and the corresponding BV node...
static void run(BVSplitter< kIOS< S >> &splitter, const kIOS< S > &bv, unsigned int *primitive_indices, int num_primitives)
BVHModelType type
Whether the geometry is mesh or point cloud.
static void run(BVSplitter< OBB< S >> &splitter, const OBB< S > &bv, unsigned int *primitive_indices, int num_primitives)
void computeSplitValue_median(const BV &bv, Vector3< S > *vertices, Triangle *triangles, unsigned int *primitive_indices, int num_primitives, BVHModelType type, const Vector3< S > &split_vector, S &split_value)
static bool run(const BVSplitter< BV > &splitter, const Vector3< S > &q)
Matrix3< S > axis
Orientation of OBB. The axes of the rotation matrix are the principle directions of the box...
A class describing the split rule that splits each BV node.
S split_value
The split threshold, different primitives are splitted according whether their projection on the spli...
static void run(const kIOS< S > &bv, Vector3< S > &split_vector)
SplitMethodType split_method
The split algorithm used.
static void run(const BV &bv, Vector3< S > &split_vector)
A class describing the kIOS collision structure, which is a set of spheres.
static void run(BVSplitter< BV > &splitter, const BV &bv, unsigned int *primitive_indices, int num_primitives)
void computeRule_mean(const BV &bv, unsigned int *primitive_indices, int num_primitives)
Split algorithm 2: Split the node according to the mean of the data contained.
Oriented bounding box class.