1717#include < atomic>
1818#include < thread>
1919#include < limits>
20+ #include < vector>
2021
2122#include " primitives.h"
2223
@@ -70,8 +71,8 @@ class BVHTree {
7071 node.last = last;
7172 node.left = NAI;
7273 node.right = NAI;
73- node.aabb .min = Vec3fType (inf);
74- node.aabb .max = Vec3fType (-inf);
74+ node.aabb .min = Vec3fType (inf, inf, inf );
75+ node.aabb .max = Vec3fType (-inf, -inf, -inf );
7576 return node_id;
7677 }
7778
@@ -174,7 +175,7 @@ BVHTree<IdxType, Vec3fType>::bsplit(typename Node::ID node_id,
174175 float min = node.aabb .min [d];
175176 float max = node.aabb .max [d];
176177 for (Bin & bin : bins) {
177- bin = {0 , {Vec3fType (inf), Vec3fType (-inf)}};
178+ bin = {0 , {Vec3fType (inf, inf, inf ), Vec3fType (-inf, -inf, -inf)}};
178179 }
179180 for (std::size_t i = node.first ; i < node.last ; ++i) {
180181 AABB const & aabb = aabbs[indices[i]];
@@ -214,7 +215,7 @@ BVHTree<IdxType, Vec3fType>::bsplit(typename Node::ID node_id,
214215 float min = node.aabb .min [d];
215216 float max = node.aabb .max [d];
216217 for (Bin & bin : bins) {
217- bin = {0 , {Vec3fType (inf), Vec3fType (-inf)}};
218+ bin = {0 , {Vec3fType (inf, inf, inf ), Vec3fType (-inf, -inf, -inf)}};
218219 }
219220 for (std::size_t i = node.first ; i < node.last ; ++i) {
220221 AABB const & aabb = aabbs[indices[i]];
@@ -426,7 +427,11 @@ BVHTree<IdxType, Vec3fType>::closest_point(Vec3fType vertex, typename Node::ID n
426427
427428 for (std::size_t i = node.first ; i < node.last ; ++i) {
428429 Vec3fType closest_tri = acc::closest_point (vertex, tris[i]);
430+ #ifdef USE_LIBEIGEN
431+ float dist_tri = (closest_tri - vertex).squaredNorm ();
432+ #else
429433 float dist_tri = (closest_tri - vertex).square_norm ();
434+ #endif
430435 if (dist_tri < dist) {
431436 closest = closest_tri;
432437 dist = dist_tri;
@@ -449,8 +454,13 @@ BVHTree<IdxType, Vec3fType>::closest_point(Vec3fType vertex, float max_dist) con
449454 if (node.left != NAI && node.right != NAI) {
450455 Vec3fType closest_left = acc::closest_point (vertex, nodes[node.left ].aabb );
451456 Vec3fType closest_right = acc::closest_point (vertex, nodes[node.right ].aabb );
457+ #ifdef USE_LIBEIGEN
458+ float dmin_left = (closest_left - vertex).squaredNorm ();
459+ float dmin_right = (closest_right - vertex).squaredNorm ();
460+ #else
452461 float dmin_left = (closest_left - vertex).square_norm ();
453462 float dmin_right = (closest_right - vertex).square_norm ();
463+ #endif
454464 bool left = dmin_left < dist;
455465 bool right = dmin_right < dist;
456466 if (left && right) {
@@ -472,7 +482,11 @@ BVHTree<IdxType, Vec3fType>::closest_point(Vec3fType vertex, float max_dist) con
472482 }
473483 } else {
474484 Vec3fType closest_leaf = closest_point (vertex, node_id);
485+ #ifdef USE_LIBEIGEN
486+ float dist_leaf = (closest_leaf - vertex).squaredNorm ();
487+ #else
475488 float dist_leaf = (closest_leaf - vertex).square_norm ();
489+ #endif
476490 if (dist_leaf < dist) {
477491 dist = dist_leaf;
478492 closest = closest_leaf;
0 commit comments