Add placeholder nearest_k_neighbours with testing

This commit is contained in:
Jackson Campolattaro 2020-07-13 10:55:32 -04:00
parent 29394deb7c
commit 736bcb04fb
3 changed files with 43 additions and 6 deletions

View File

@ -330,6 +330,12 @@ public:
return *node_for_point;
}
template <typename Point_output_iterator>
void nearest_k_neighbours(const Point &p, std::size_t k, Point_output_iterator output) {
*output++ = p;
}
/// @}
/// \name Operators

View File

@ -19,10 +19,35 @@ ostream &operator<<(ostream &os, const CGAL::Octree::Octree<PointRange, PointMap
// Create a range of nodes
auto nodes = octree.template walk<CGAL::Octree::Walker::Preorder>();
// Iterate over the range and print each node
// for (auto &n : nodes) {
//
// for (int i = 0; i < n.depth() - 1; ++i)
// os << " │ ";
//
// if (!n.is_root()) {
//
// if (n.index() == 7)
// os << " └─";
// else
// os << " ├─";
// }
//
// os << n << std::endl;
//
// if (!n.is_leaf()) {
//
// for (int i = 0; i < n.depth(); ++i)
// os << " │ ";
//
// os << " ┬ " << std::endl;
// }
// }
// Iterate over the range and print each node
for (auto &n : nodes) {
for (int i = 0; i < n.depth(); ++i)
for (int i = 0; i < n.depth() - 1; ++i)
os << ". ";
os << n << std::endl;

View File

@ -22,7 +22,7 @@ typedef CGAL::Octree::Octree
<Point_set, typename Point_set::Point_map>
Octree;
void naive_vs_accelerated(std::size_t dataset_size) {
void naive_vs_octree(std::size_t dataset_size) {
// Create a dataset
Point_set points;
@ -63,9 +63,15 @@ void naive_vs_accelerated(std::size_t dataset_size) {
// Do the same using the octree
Point octree_nearest = *generator;
auto point_map = points.point_map();
Octree octree(points, point_map);
octree.refine(10, 1);
auto octree_start_time = high_resolution_clock::now();
{
// 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.begin();
}
duration<float> octree_elapsed_time = high_resolution_clock::now() - octree_start_time;
@ -87,10 +93,10 @@ void naive_vs_accelerated(std::size_t dataset_size) {
int main(void) {
naive_vs_accelerated(100);
naive_vs_accelerated(1000);
naive_vs_accelerated(10000);
naive_vs_accelerated(100000);
naive_vs_octree(100);
naive_vs_octree(1000);
naive_vs_octree(10000);
naive_vs_octree(100000);
return EXIT_SUCCESS;
}