mirror of https://github.com/CGAL/cgal
Revert "traversals are now templated by OrthtreeTraits"
This reverts commit 3c55548967.
This commit is contained in:
parent
d9756dd971
commit
47bbc08d8e
|
|
@ -15,7 +15,7 @@ using Octree = CGAL::Orthtree<OTraits>;
|
|||
void dump_as_polylines(const Octree& ot)
|
||||
{
|
||||
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))
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ using Point = Kernel::Point_3;
|
|||
using Point_set = CGAL::Point_set_3<Point>;
|
||||
using Point_map = 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) {
|
||||
|
||||
|
|
|
|||
|
|
@ -330,7 +330,7 @@ public:
|
|||
|
||||
// Collect all the 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);
|
||||
}
|
||||
|
||||
|
|
@ -391,7 +391,8 @@ public:
|
|||
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; }
|
||||
|
||||
|
|
@ -440,6 +441,35 @@ public:
|
|||
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.
|
||||
|
||||
|
|
@ -1083,33 +1113,6 @@ public:
|
|||
|
||||
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); }
|
||||
|
||||
template <typename... Indices>
|
||||
|
|
@ -1208,7 +1211,7 @@ public:
|
|||
|
||||
friend std::ostream& operator<<(std::ostream& os, const Self& orthtree) {
|
||||
// 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
|
||||
for (std::size_t i = 0; i < orthtree.depth(n); ++i)
|
||||
os << ". ";
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
#include <CGAL/license/Orthtree.h>
|
||||
|
||||
#include <CGAL/Orthtree.h>
|
||||
#include <iostream>
|
||||
#include <boost/range/iterator_range.hpp>
|
||||
#include <CGAL/Orthtree/Traversal_iterator.h>
|
||||
|
|
@ -29,23 +28,23 @@ namespace Orthtrees {
|
|||
\ingroup PkgOrthtreeTraversal
|
||||
\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.
|
||||
|
||||
\cgalModels{OrthtreeTraversal}
|
||||
*/
|
||||
template <typename GeomTraits>
|
||||
template <typename Tree>
|
||||
struct Preorder_traversal {
|
||||
private:
|
||||
|
||||
const CGAL::Orthtree<GeomTraits>& m_orthtree;
|
||||
const Tree& m_orthtree;
|
||||
|
||||
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 {
|
||||
return m_orthtree.root();
|
||||
|
|
@ -73,23 +72,23 @@ public:
|
|||
\ingroup PkgOrthtreeTraversal
|
||||
\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.
|
||||
|
||||
\cgalModels{OrthtreeTraversal}
|
||||
*/
|
||||
template <typename GeomTraits>
|
||||
template <typename Tree>
|
||||
struct Postorder_traversal {
|
||||
private:
|
||||
|
||||
const CGAL::Orthtree<GeomTraits>& m_orthtree;
|
||||
const Tree& m_orthtree;
|
||||
|
||||
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 {
|
||||
return m_orthtree.deepest_first_child(m_orthtree.root());
|
||||
|
|
@ -104,23 +103,23 @@ public:
|
|||
\ingroup PkgOrthtreeTraversal
|
||||
\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.
|
||||
|
||||
\cgalModels{OrthtreeTraversal}
|
||||
*/
|
||||
template <typename GeomTraits>
|
||||
template <typename Tree>
|
||||
struct Leaves_traversal {
|
||||
private:
|
||||
|
||||
const CGAL::Orthtree<GeomTraits>& m_orthtree;
|
||||
const Tree& m_orthtree;
|
||||
|
||||
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 {
|
||||
return m_orthtree.deepest_first_child(m_orthtree.root());
|
||||
|
|
@ -142,7 +141,7 @@ public:
|
|||
\ingroup PkgOrthtreeTraversal
|
||||
\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
|
||||
|
|
@ -150,21 +149,21 @@ public:
|
|||
|
||||
\cgalModels{OrthtreeTraversal}
|
||||
*/
|
||||
template <typename GeomTraits>
|
||||
template <typename Tree>
|
||||
struct Level_traversal {
|
||||
private:
|
||||
|
||||
const CGAL::Orthtree<GeomTraits>& m_orthtree;
|
||||
const Tree& m_orthtree;
|
||||
const std::size_t m_depth;
|
||||
|
||||
public:
|
||||
|
||||
using Node_index = typename GeomTraits::Node_index;
|
||||
using Node_index = typename Tree::Node_index;
|
||||
|
||||
/*!
|
||||
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 {
|
||||
// assumes the tree has at least one child at m_depth
|
||||
|
|
|
|||
Loading…
Reference in New Issue