Skip to content

Commit

Permalink
major knn query speed optimization in under-populated regions of high…
Browse files Browse the repository at this point in the history
…ly populated trees.
  • Loading branch information
dictoon committed Aug 9, 2014
1 parent 3458bde commit 78480d8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/appleseed/foundation/math/knn/knn_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "foundation/math/knn/knn_tree.h"
#include "foundation/math/distance.h"
#include "foundation/math/fp.h"
#include "foundation/math/scalar.h"
#include "foundation/math/vector.h"
#include "foundation/platform/compiler.h"

Expand Down Expand Up @@ -307,17 +308,24 @@ inline void Query<T, N>::find_multiple_nearest_neighbors(
{
const size_t split_dim = node->get_split_dim();
const ValueType split_abs = node->get_split_abs();
const ValueType split_dist = query_point[split_dim] - split_abs;

const NodeType* RESTRICT child_node = nodes + node->get_child_node_index();

if (query_point[split_dim] >= split_abs)
if (split_dist > ValueType(0.0))
++child_node;

FOUNDATION_KNN_QUERY_STATS(++fetched_node_count);

// The child node contains too few points, keep the current node.
// The child node contains too few points.
if (child_node->get_point_count() < max_answer_size)
{
// Keep the child node anyway if its sibling is too far.
// Otherwise keep the current node.
if (square(split_dist) > query_max_square_distance)
node = child_node;
break;
}

// The child node contains enough points.
node = child_node;
Expand Down

0 comments on commit 78480d8

Please sign in to comment.