Skip to content

Commit

Permalink
Replace neighbour (British spelling) with neighbor (American spelling…
Browse files Browse the repository at this point in the history
…) for consistency
  • Loading branch information
JacksonCampolattaro committed Jul 21, 2020
1 parent 3d84a2a commit 17666cd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
10 changes: 5 additions & 5 deletions Octree/benchmark/Octree/bench.cpp
Expand Up @@ -57,7 +57,7 @@ std::chrono::duration<double> benchmark_refine(Point_set points) {
return elapsed;
}

std::chrono::duration<double> benchmark_nearest_neighbour(Point_set points) {
std::chrono::duration<double> benchmark_nearest_neighbor(Point_set points) {

std::cout << "Benchmarking search" << std::endl;

Expand All @@ -70,11 +70,11 @@ std::chrono::duration<double> benchmark_nearest_neighbour(Point_set points) {
for (int i = 0; i < NUM_NEAREST_SEARCHES; ++i) {

auto search_point = point_map[std::rand() % points.number_of_points()];
std::vector<Point> octree_nearest_neighbours;
std::vector<Point> octree_nearest_neighbors;

auto start = std::chrono::high_resolution_clock::now();

octree.nearest_k_neighbours(search_point, 16, std::back_inserter(octree_nearest_neighbours));
octree.nearest_k_neighbors(search_point, 16, std::back_inserter(octree_nearest_neighbors));

auto end = std::chrono::high_resolution_clock::now();

Expand Down Expand Up @@ -126,8 +126,8 @@ int main(void) {
file << "~~~~~~~~~~~~~~~~~~~~~~~" << std::endl;
file << "Tree construction time: "
<< std::chrono::duration_cast<std::chrono::microseconds>(benchmark_refine(points)).count() << " us" << std::endl;
file << "Nearest K neighbours search time: "
<< std::chrono::duration_cast<std::chrono::nanoseconds>(benchmark_nearest_neighbour(points)).count() << " ns" << std::endl;
file << "Nearest K neighbors search time: "
<< std::chrono::duration_cast<std::chrono::nanoseconds>(benchmark_nearest_neighbor(points)).count() << " ns" << std::endl;
file << std::endl;

// Leave room for notes
Expand Down
14 changes: 7 additions & 7 deletions Octree/include/CGAL/Octree.h
Expand Up @@ -385,7 +385,7 @@ class Octree {
* \param output the output iterator to add the found points to (in order of increasing distance)
*/
template<typename Point_output_iterator>
void nearest_k_neighbours_in_radius(const Point &search_point, FT search_radius_squared, std::size_t k,
void nearest_k_neighbors_in_radius(const Point &search_point, FT search_radius_squared, std::size_t k,
Point_output_iterator output) const {

// Create an empty list of points
Expand All @@ -394,7 +394,7 @@ class Octree {

// Invoking the recursive function adds those points to the vector (passed by reference)
auto search_bounds = Sphere(search_point, search_radius_squared);
nearest_k_neighbours_recursive(search_bounds, m_root, points_list);
nearest_k_neighbors_recursive(search_bounds, m_root, points_list);

// Add all the points found to the output
for (auto &item : points_list)
Expand All @@ -404,7 +404,7 @@ class Octree {
/*!
* \brief Find the K points in a tree that are nearest to the search point
*
* This function is equivalent to invoking nearest_k_neighbours_in_radius for an infinite radius.
* This function is equivalent to invoking nearest_k_neighbors_in_radius for an infinite radius.
* For a tree with K or fewer points, all points in the tree will be returned.
*
* \tparam Point_output_iterator an output iterator type that will accept points
Expand All @@ -413,9 +413,9 @@ class Octree {
* \param output the output iterator to add the found points to (in order of increasing distance)
*/
template<typename Point_output_iterator>
void nearest_k_neighbours(const Point &search_point, std::size_t k, Point_output_iterator output) const {
void nearest_k_neighbors(const Point &search_point, std::size_t k, Point_output_iterator output) const {

return nearest_k_neighbours_in_radius(search_point, std::numeric_limits<FT>::max(), k, output);
return nearest_k_neighbors_in_radius(search_point, std::numeric_limits<FT>::max(), k, output);
}

/// @}
Expand Down Expand Up @@ -528,7 +528,7 @@ class Octree {
FT distance;
};

void nearest_k_neighbours_recursive(Sphere &search_bounds, const Node &node,
void nearest_k_neighbors_recursive(Sphere &search_bounds, const Node &node,
std::vector<Point_with_distance> &results, FT epsilon = 0) const {

// Check whether the node has children
Expand Down Expand Up @@ -605,7 +605,7 @@ class Octree {
if (do_intersect(child_node, search_bounds)) {

// Recursively invoke this function
nearest_k_neighbours_recursive(search_bounds, child_node, results);
nearest_k_neighbors_recursive(search_bounds, child_node, results);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Octree/test/Octree/CMakeLists.txt
Expand Up @@ -13,7 +13,7 @@ create_single_source_cgal_program("test_octree_equality.cpp")
create_single_source_cgal_program("test_octree_refine.cpp")
create_single_source_cgal_program("test_octree_locate.cpp")
create_single_source_cgal_program("test_octree_bbox.cpp")
create_single_source_cgal_program("test_octree_nearest_neighbour.cpp")
create_single_source_cgal_program("test_octree_nearest_neighbor.cpp")

create_single_source_cgal_program("test_node.cpp")
create_single_source_cgal_program("test_node_index.cpp")
Expand Down
Expand Up @@ -75,7 +75,7 @@ void naive_vs_octree(std::size_t dataset_size) {
{
// TODO: Write a nearest-neighbor implementation and use it here
std::vector<Point> k_neighbors;
octree.nearest_k_neighbours(random_point, 1, std::back_inserter(k_neighbors));
octree.nearest_k_neighbors(random_point, 1, std::back_inserter(k_neighbors));
octree_nearest = *k_neighbors.begin();
}
duration<float> octree_elapsed_time = high_resolution_clock::now() - octree_start_time;
Expand Down Expand Up @@ -109,38 +109,40 @@ void kdtree_vs_octree(std::size_t dataset_size, std::size_t K) {
Point random_point = *(generator++);

// Use the naive algorithm to find the nearest point in the dataset
std::vector<Point> kd_tree_nearest_neighbours;
std::vector<Point> kd_tree_nearest_neighbors;
Kd_tree kd_tree(points.points().begin(), points.points().end());
kd_tree.build();
auto kd_tree_start_time = high_resolution_clock::now();
Kd_tree_search search(kd_tree, random_point, K);
duration<float> kd_tree_elapsed_time = high_resolution_clock::now() - kd_tree_start_time;
for (auto p : search)
kd_tree_nearest_neighbours.push_back(p.first);
kd_tree_nearest_neighbors.push_back(p.first);

std::cout << "Kd_tree --> "
<< kd_tree_nearest_neighbours.size() << " points "
<< "in " << kd_tree_elapsed_time.count() << "s ";
<< kd_tree_nearest_neighbors.size() << " points "
<< "in " << kd_tree_elapsed_time.count() << "s "
<< std::endl;

// Do the same using the octree
std::vector<Point> octree_nearest_neighbours;
std::vector<Point> octree_nearest_neighbors;
auto point_map = points.point_map();
Octree octree(points, point_map);
octree.refine(10, 20);
auto octree_start_time = high_resolution_clock::now();
octree.nearest_k_neighbours(random_point, K, std::back_inserter(octree_nearest_neighbours));
octree.nearest_k_neighbors(random_point, K, std::back_inserter(octree_nearest_neighbors));
duration<float> octree_elapsed_time = high_resolution_clock::now() - octree_start_time;

std::cout << "Octree --> "
<< octree_nearest_neighbours.size() << " points "
<< "in " << octree_elapsed_time.count() << "s ";
<< octree_nearest_neighbors.size() << " points "
<< "in " << octree_elapsed_time.count() << "s "
<< std::endl;

// Check that the octree produces the right number of results
assert(octree_nearest_neighbours.size() == K);
assert(octree_nearest_neighbors.size() == K);

// Check that they produce the same answer
for (int j = 0; j < K; ++j)
assert(octree_nearest_neighbours[j] == kd_tree_nearest_neighbours[j]);
assert(octree_nearest_neighbors[j] == kd_tree_nearest_neighbors[j]);

}

Expand Down

0 comments on commit 17666cd

Please sign in to comment.