Skip to content

Commit

Permalink
support for libeigen vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Schier committed Jul 26, 2017
1 parent bb6694e commit e5ece12
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 18 additions & 4 deletions bvh_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <atomic>
#include <thread>
#include <limits>
#include <vector>

#include "primitives.h"

Expand Down Expand Up @@ -70,8 +71,8 @@ class BVHTree {
node.last = last;
node.left = NAI;
node.right = NAI;
node.aabb.min = Vec3fType(inf);
node.aabb.max = Vec3fType(-inf);
node.aabb.min = Vec3fType(inf, inf, inf);
node.aabb.max = Vec3fType(-inf, -inf, -inf);
return node_id;
}

Expand Down Expand Up @@ -174,7 +175,7 @@ BVHTree<IdxType, Vec3fType>::bsplit(typename Node::ID node_id,
float min = node.aabb.min[d];
float max = node.aabb.max[d];
for (Bin & bin : bins) {
bin = {0, {Vec3fType(inf), Vec3fType(-inf)}};
bin = {0, {Vec3fType(inf, inf, inf), Vec3fType(-inf, -inf, -inf)}};
}
for (std::size_t i = node.first; i < node.last; ++i) {
AABB const & aabb = aabbs[indices[i]];
Expand Down Expand Up @@ -214,7 +215,7 @@ BVHTree<IdxType, Vec3fType>::bsplit(typename Node::ID node_id,
float min = node.aabb.min[d];
float max = node.aabb.max[d];
for (Bin & bin : bins) {
bin = {0, {Vec3fType(inf), Vec3fType(-inf)}};
bin = {0, {Vec3fType(inf, inf, inf), Vec3fType(-inf, -inf, -inf)}};
}
for (std::size_t i = node.first; i < node.last; ++i) {
AABB const & aabb = aabbs[indices[i]];
Expand Down Expand Up @@ -426,7 +427,11 @@ BVHTree<IdxType, Vec3fType>::closest_point(Vec3fType vertex, typename Node::ID n

for (std::size_t i = node.first; i < node.last; ++i) {
Vec3fType closest_tri = acc::closest_point(vertex, tris[i]);
#ifdef USE_LIBEIGEN
float dist_tri = (closest_tri - vertex).squaredNorm();
#else
float dist_tri = (closest_tri - vertex).square_norm();
#endif
if (dist_tri < dist) {
closest = closest_tri;
dist = dist_tri;
Expand All @@ -449,8 +454,13 @@ BVHTree<IdxType, Vec3fType>::closest_point(Vec3fType vertex, float max_dist) con
if (node.left != NAI && node.right != NAI) {
Vec3fType closest_left = acc::closest_point(vertex, nodes[node.left].aabb);
Vec3fType closest_right = acc::closest_point(vertex, nodes[node.right].aabb);
#ifdef USE_LIBEIGEN
float dmin_left = (closest_left - vertex).squaredNorm();
float dmin_right = (closest_right - vertex).squaredNorm();
#else
float dmin_left = (closest_left - vertex).square_norm();
float dmin_right = (closest_right - vertex).square_norm();
#endif
bool left = dmin_left < dist;
bool right = dmin_right < dist;
if (left && right) {
Expand All @@ -472,7 +482,11 @@ BVHTree<IdxType, Vec3fType>::closest_point(Vec3fType vertex, float max_dist) con
}
} else {
Vec3fType closest_leaf = closest_point(vertex, node_id);
#ifdef USE_LIBEIGEN
float dist_leaf = (closest_leaf - vertex).squaredNorm();
#else
float dist_leaf = (closest_leaf - vertex).square_norm();
#endif
if (dist_leaf < dist) {
dist = dist_leaf;
closest = closest_leaf;
Expand Down
2 changes: 2 additions & 0 deletions primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

#include <limits>

#ifndef USE_LIBEIGEN
#include <math/vector.h>
#endif

#include "defines.h"

Expand Down

0 comments on commit e5ece12

Please sign in to comment.