Skip to content

Commit

Permalink
Add boost iterator over nodes as member class of octree
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonCampolattaro committed Jun 29, 2020
1 parent 52afe2e commit f39ee93
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
36 changes: 32 additions & 4 deletions Octree/include/CGAL/Octree.h
Expand Up @@ -40,6 +40,7 @@
*/
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <iostream>
#include <fstream>
#include <ostream>
Expand All @@ -63,15 +64,41 @@ namespace CGAL {
// Define the Node based on this kernel
typedef Octree_node<Kernel, PointRange> Node;

// Some other useful types
typedef typename Kernel::FT FT;
typedef typename Kernel::Vector_3 Vector;
typedef typename Kernel::Iso_cuboid_3 Iso_cuboid;

// New Types :
typedef typename PointRange::iterator Range_iterator;
typedef typename std::iterator_traits<Range_iterator>::value_type Range_type;
// TODO: Kernel can be deduced from the point map

public: // Classes

class const_iterator :
public boost::iterator_facade<const_iterator, Node const, boost::forward_traversal_tag> {

public:

const_iterator() : m_node(0) {};

const_iterator(Node *p, std::function<const Node *(const Node *)> next) : m_node(p), m_next(next) {};

private:
friend class boost::iterator_core_access;

void increment() {
// TODO: This will use a node traversal function
std::cout << "Incrementing" << std::endl;
}

Node const &dereference() const { return *m_node; }

private:

Node const *m_node;

std::function<const Node *(const Node *)> m_next;

};

private: // data members :
Node m_root; /* root node of the octree */
Expand All @@ -87,6 +114,7 @@ namespace CGAL {
std::vector<size_t> m_unit_per_depth; /* number of unit node (smallest) inside one node for each depth for one axis */

public: // functions :

Octree(
PointRange &pwn,
PointMap &point_map,
Expand Down Expand Up @@ -210,7 +238,6 @@ namespace CGAL {
return rhs.m_root == m_root;
}


private: // functions :

Point compute_barycenter_position(Node &node) const {
Expand Down Expand Up @@ -263,6 +290,7 @@ namespace CGAL {
Point center = compute_barycenter_position(node);
reassign_points(node, node.points_begin(), node.points_end(), center);
}

}; // end class Octree

} // namespace CGAL
Expand Down
2 changes: 2 additions & 0 deletions Octree/test/Octree/test_tree_walk.cpp
Expand Up @@ -7,6 +7,8 @@
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Point_set_3.h>

#include <CGAL/Octree/Octree_node_range.h>

typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_3 Point;
typedef CGAL::Point_set_3<Point> Point_set;
Expand Down

0 comments on commit f39ee93

Please sign in to comment.