Revert "traversals are now templated by OrthtreeTraits"

This reverts commit 3c55548967.
This commit is contained in:
Sven Oesau 2024-02-02 15:08:32 +01:00
parent d9756dd971
commit 47bbc08d8e
4 changed files with 55 additions and 53 deletions

View File

@ -15,7 +15,7 @@ using Octree = CGAL::Orthtree<OTraits>;
void dump_as_polylines(const Octree& ot) void dump_as_polylines(const Octree& ot)
{ {
std::ofstream out("octree.polylines.txt"); std::ofstream out("octree.polylines.txt");
for (Octree::Node_index node : ot.traverse(CGAL::Orthtrees::Leaves_traversal<OTraits>(ot))) for (Octree::Node_index node : ot.traverse(CGAL::Orthtrees::Leaves_traversal<Octree>(ot)))
{ {
if (!ot.is_leaf(node)) if (!ot.is_leaf(node))
continue; continue;

View File

@ -12,7 +12,7 @@ using Point = Kernel::Point_3;
using Point_set = CGAL::Point_set_3<Point>; using Point_set = CGAL::Point_set_3<Point>;
using Point_map = Point_set::Point_map; using Point_map = Point_set::Point_map;
using Octree = CGAL::Octree<Kernel, Point_set, Point_map>; using Octree = CGAL::Octree<Kernel, Point_set, Point_map>;
using Preorder_traversal = CGAL::Orthtrees::Preorder_traversal<typename Octree::Traits>; using Preorder_traversal = CGAL::Orthtrees::Preorder_traversal<Octree>;
int main(int argc, char **argv) { int main(int argc, char **argv) {

View File

@ -330,7 +330,7 @@ public:
// Collect all the leaf nodes // Collect all the leaf nodes
std::queue<Node_index> leaf_nodes; std::queue<Node_index> leaf_nodes;
for (Node_index leaf: traverse(Orthtrees::Leaves_traversal<Traits>(*this))) { for (Node_index leaf: traverse(Orthtrees::Leaves_traversal<Self>(*this))) {
leaf_nodes.push(leaf); leaf_nodes.push(leaf);
} }
@ -391,7 +391,8 @@ public:
const Traits& traits() const { return m_traits; } const Traits& traits() const { return m_traits; }
/*! /*!
\brief provides access to the root node, and by extension the rest of the tree. \brief provides access to the root node, and by
extension the rest of the tree.
*/ */
Node_index root() const { return 0; } Node_index root() const { return 0; }
@ -440,6 +441,35 @@ public:
return traverse(Traversal{*this, std::forward<Args>(args)...}); return traverse(Traversal{*this, std::forward<Args>(args)...});
} }
// TODO shall we document it?
FT
compute_cartesian_coordinate(std::uint32_t gc, std::size_t depth, int ci) const
{
CGAL_assertion(depth <= m_side_per_depth.size());
// an odd coordinate will be first compute at the current depth,
// while an even coordinate has already been computed at a previous depth.
// So while the coordinate is even, we decrease the depth to end up of the first
// non-even coordinate to compute it (with particular case for bbox limits).
// Note that is depth becomes too large, we might end up with incorrect coordinates
// due to rounding errors.
if (gc == (1u << depth)) return (m_bbox.max)()[ci]; // gc == 2^node_depth
if (gc == 0) return (m_bbox.min)()[ci];
if (gc % 2 !=0)
{
FT size = depth < m_side_per_depth.size()
? m_side_per_depth[depth][ci]
: m_side_per_depth[depth-1][ci]/FT(2);
return (m_bbox.min)()[ci] + int(gc) * size;
}
std::size_t nd = depth;
do{
--nd;
gc = gc >> 1;
}
while((gc&1)==0); // while even, shift
return (m_bbox.min)()[ci] + int(gc) * m_side_per_depth[nd][ci];
}
/*! /*!
\brief constructs the bounding box of a node. \brief constructs the bounding box of a node.
@ -1083,33 +1113,6 @@ public:
private: // functions : private: // functions :
FT compute_cartesian_coordinate(std::uint32_t gc, std::size_t depth, int ci) const
{
CGAL_assertion(depth <= m_side_per_depth.size());
// an odd coordinate will be first compute at the current depth,
// while an even coordinate has already been computed at a previous depth.
// So while the coordinate is even, we decrease the depth to end up of the first
// non-even coordinate to compute it (with particular case for bbox limits).
// Note that is depth becomes too large, we might end up with incorrect coordinates
// due to rounding errors.
if (gc == (1u << depth)) return (m_bbox.max)()[ci]; // gc == 2^node_depth
if (gc == 0) return (m_bbox.min)()[ci];
if (gc % 2 != 0)
{
FT size = depth < m_side_per_depth.size()
? m_side_per_depth[depth][ci]
: m_side_per_depth[depth - 1][ci] / FT(2);
return (m_bbox.min)()[ci] + int(gc) * size;
}
std::size_t nd = depth;
do {
--nd;
gc = gc >> 1;
} while ((gc & 1) == 0); // while even, shift
return (m_bbox.min)()[ci] + int(gc) * m_side_per_depth[nd][ci];
}
Node_index recursive_descendant(Node_index node, std::size_t i) { return child(node, i); } Node_index recursive_descendant(Node_index node, std::size_t i) { return child(node, i); }
template <typename... Indices> template <typename... Indices>
@ -1208,7 +1211,7 @@ public:
friend std::ostream& operator<<(std::ostream& os, const Self& orthtree) { friend std::ostream& operator<<(std::ostream& os, const Self& orthtree) {
// Iterate over all nodes // Iterate over all nodes
for (auto n: orthtree.traverse(Orthtrees::Preorder_traversal<Traits>(orthtree))) { for (auto n: orthtree.traverse(Orthtrees::Preorder_traversal<Self>(orthtree))) {
// Show the depth // Show the depth
for (std::size_t i = 0; i < orthtree.depth(n); ++i) for (std::size_t i = 0; i < orthtree.depth(n); ++i)
os << ". "; os << ". ";

View File

@ -14,7 +14,6 @@
#include <CGAL/license/Orthtree.h> #include <CGAL/license/Orthtree.h>
#include <CGAL/Orthtree.h>
#include <iostream> #include <iostream>
#include <boost/range/iterator_range.hpp> #include <boost/range/iterator_range.hpp>
#include <CGAL/Orthtree/Traversal_iterator.h> #include <CGAL/Orthtree/Traversal_iterator.h>
@ -29,23 +28,23 @@ namespace Orthtrees {
\ingroup PkgOrthtreeTraversal \ingroup PkgOrthtreeTraversal
\brief A class used for performing a preorder traversal. \brief A class used for performing a preorder traversal.
\tparam GeomTraits must be a model of `OrthtreeTraits` \tparam Tree an instance of `Orthtree`
A preorder traversal starts from the root towards the leaves. A preorder traversal starts from the root towards the leaves.
\cgalModels{OrthtreeTraversal} \cgalModels{OrthtreeTraversal}
*/ */
template <typename GeomTraits> template <typename Tree>
struct Preorder_traversal { struct Preorder_traversal {
private: private:
const CGAL::Orthtree<GeomTraits>& m_orthtree; const Tree& m_orthtree;
public: public:
using Node_index = typename GeomTraits::Node_index; using Node_index = typename Tree::Node_index;
Preorder_traversal(const CGAL::Orthtree<GeomTraits>& orthtree) : m_orthtree(orthtree) {} Preorder_traversal(const Tree& orthtree) : m_orthtree(orthtree) {}
Node_index first_index() const { Node_index first_index() const {
return m_orthtree.root(); return m_orthtree.root();
@ -73,23 +72,23 @@ public:
\ingroup PkgOrthtreeTraversal \ingroup PkgOrthtreeTraversal
\brief A class used for performing a postorder traversal. \brief A class used for performing a postorder traversal.
\tparam GeomTraits must be a model of `OrthtreeTraits` \tparam Tree an instance of `Orthtree`
A postorder traversal starts from the leaves towards the root. A postorder traversal starts from the leaves towards the root.
\cgalModels{OrthtreeTraversal} \cgalModels{OrthtreeTraversal}
*/ */
template <typename GeomTraits> template <typename Tree>
struct Postorder_traversal { struct Postorder_traversal {
private: private:
const CGAL::Orthtree<GeomTraits>& m_orthtree; const Tree& m_orthtree;
public: public:
using Node_index = typename GeomTraits::Node_index; using Node_index = typename Tree::Node_index;
Postorder_traversal(const CGAL::Orthtree<GeomTraits>& orthtree) : m_orthtree(orthtree) {} Postorder_traversal(const Tree& orthtree) : m_orthtree(orthtree) {}
Node_index first_index() const { Node_index first_index() const {
return m_orthtree.deepest_first_child(m_orthtree.root()); return m_orthtree.deepest_first_child(m_orthtree.root());
@ -104,23 +103,23 @@ public:
\ingroup PkgOrthtreeTraversal \ingroup PkgOrthtreeTraversal
\brief A class used for performing a traversal on leaves only. \brief A class used for performing a traversal on leaves only.
\tparam GeomTraits must be a model of `OrthtreeTraits` \tparam Tree an instance of `Orthtree`
All non-leaf nodes are ignored. All non-leaf nodes are ignored.
\cgalModels{OrthtreeTraversal} \cgalModels{OrthtreeTraversal}
*/ */
template <typename GeomTraits> template <typename Tree>
struct Leaves_traversal { struct Leaves_traversal {
private: private:
const CGAL::Orthtree<GeomTraits>& m_orthtree; const Tree& m_orthtree;
public: public:
using Node_index = typename GeomTraits::Node_index; using Node_index = typename Tree::Node_index;
Leaves_traversal(const CGAL::Orthtree<GeomTraits>& orthtree) : m_orthtree(orthtree) {} Leaves_traversal(const Tree& orthtree) : m_orthtree(orthtree) {}
Node_index first_index() const { Node_index first_index() const {
return m_orthtree.deepest_first_child(m_orthtree.root()); return m_orthtree.deepest_first_child(m_orthtree.root());
@ -142,7 +141,7 @@ public:
\ingroup PkgOrthtreeTraversal \ingroup PkgOrthtreeTraversal
\brief A class used for performing a traversal of a specific depth level. \brief A class used for performing a traversal of a specific depth level.
\tparam GeomTraits must be a model of `OrthtreeTraits` \tparam Tree an instance of `Orthtree`
All tree nodes at another depth are ignored. If the selected depth is All tree nodes at another depth are ignored. If the selected depth is
All tree nodes at another depth are ignored. If the selected depth is All tree nodes at another depth are ignored. If the selected depth is
@ -150,21 +149,21 @@ public:
\cgalModels{OrthtreeTraversal} \cgalModels{OrthtreeTraversal}
*/ */
template <typename GeomTraits> template <typename Tree>
struct Level_traversal { struct Level_traversal {
private: private:
const CGAL::Orthtree<GeomTraits>& m_orthtree; const Tree& m_orthtree;
const std::size_t m_depth; const std::size_t m_depth;
public: public:
using Node_index = typename GeomTraits::Node_index; using Node_index = typename Tree::Node_index;
/*! /*!
constructs a `depth`-level traversal. constructs a `depth`-level traversal.
*/ */
Level_traversal(const CGAL::Orthtree<GeomTraits>& orthtree, std::size_t depth) : m_orthtree(orthtree), m_depth(depth) {} Level_traversal(const Tree& orthtree, std::size_t depth) : m_orthtree(orthtree), m_depth(depth) {}
Node_index first_index() const { Node_index first_index() const {
// assumes the tree has at least one child at m_depth // assumes the tree has at least one child at m_depth