From fa4dfd213b8e8a4e0a7db18e0930eb99611d5732 Mon Sep 17 00:00:00 2001 From: Jackson Campolattaro Date: Tue, 16 Jun 2020 17:35:54 -0400 Subject: [PATCH] Change how child nodes are stored and perform benchmark --- Octree/include/CGAL/Octree/IO.h | 2 +- Octree/include/CGAL/Octree/Octree_node.h | 29 ++++++++++++------------ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Octree/include/CGAL/Octree/IO.h b/Octree/include/CGAL/Octree/IO.h index 71df5bdd4e8..cdb841a5904 100644 --- a/Octree/include/CGAL/Octree/IO.h +++ b/Octree/include/CGAL/Octree/IO.h @@ -24,7 +24,7 @@ void writeToStream(ostream &os, const CGAL::Octree_node &nod // Print out this node's children if (!node.is_leaf()) { for (int i = 0; i < 8; ++i) { - writeToStream(os, node.children()[i], depth + 1); + writeToStream(os, (*node.children())[i], depth + 1); } } } diff --git a/Octree/include/CGAL/Octree/Octree_node.h b/Octree/include/CGAL/Octree/Octree_node.h index e9722793f69..954ebc6bfe0 100644 --- a/Octree/include/CGAL/Octree/Octree_node.h +++ b/Octree/include/CGAL/Octree/Octree_node.h @@ -109,21 +109,21 @@ namespace CGAL { typedef typename PointRange::const_iterator InputIterator; typedef typename std::list IterList; + typedef std::array ChildList; + private: // members : - // TODO: Replace with pointer to fixed size array, or std::optional> ? - Node *m_children; /* pointer the the 8 possible child nodes. Leaf if NULL */ + //Node *m_children; /* pointer the the 8 possible child nodes. Leaf if NULL */ + std::shared_ptr m_children; Node *m_parent; /* pointer the the single parent node. Root if NULL */ - IntPoint m_location; /* integer location of current node (x,y,z) on the current depth grid */ - uint8_t m_depth; /* current depth inside the octree */ IterList m_points; /* list of iterators of the input pwn contained in the node */ public: // functions : Octree_node() : - m_children(NULL), + //m_children(NULL), m_parent(NULL), m_location(IntPoint(0, 0, 0)), m_depth(0) {} @@ -135,36 +135,37 @@ namespace CGAL { void unsplit() { if (m_children != NULL) { for (int i = 0; i < 8; i++) - m_children[i].unsplit(); + (*m_children)[i].unsplit(); - delete[] m_children; - m_children = NULL; + //delete m_children; + m_children.reset(); } } void split() { - m_children = new Node[8]; + ChildList children; for (int child_id = 0; child_id < 8; child_id++) { - m_children[child_id].set_parent(this); - m_children[child_id].depth() = m_depth + 1; + children[child_id].set_parent(this); + children[child_id].depth() = m_depth + 1; for (int j = 0; j < 3; j++) { - m_children[child_id].location()[j] = 2 * m_location[j] + ((child_id >> j) & 1); + children[child_id].location()[j] = 2 * m_location[j] + ((child_id >> j) & 1); } } + m_children = std::make_shared(children); } bool is_leaf() const { return (m_children == NULL); } Node *children() { return m_children; } - const Node *children() const { return m_children; } + std::shared_ptr children() const { return m_children; } Node *child(const unsigned int index) const { if (m_children == NULL || index > 7) return NULL; else - return &(m_children[index]); + return &((*m_children)[index]); } Node *parent() { return m_parent; }