Update face graph traits to use functors

This commit is contained in:
JacksonCampolattaro 2023-09-01 16:43:26 +02:00
parent 599a10cf0e
commit e9ca3cc561
1 changed files with 55 additions and 57 deletions

View File

@ -15,6 +15,8 @@
#include <CGAL/license/Orthtree.h> #include <CGAL/license/Orthtree.h>
#include <CGAL/Orthtree_traits_3_base.h>
#include <CGAL/Dimension.h> #include <CGAL/Dimension.h>
#include <CGAL/Bbox_3.h> #include <CGAL/Bbox_3.h>
@ -23,25 +25,28 @@ namespace CGAL
template <class PolygonMesh, class VPM> template <class PolygonMesh, class VPM>
struct Orthtree_traits_face_graph struct Orthtree_traits_face_graph
{ : public Orthtree_traits_3_base<typename Kernel_traits<typename boost::property_traits<VPM>::value_type>::type> {
Orthtree_traits_face_graph(const PolygonMesh& pm, VPM vpm) Orthtree_traits_face_graph(const PolygonMesh& pm, VPM vpm)
: m_pm(pm) : m_pm(pm), m_vpm(vpm) {}
, m_vpm(vpm)
{}
using Self = Orthtree_traits_face_graph<PolygonMesh, VPM>;
using Tree = Orthtree<Self>;
using Point_d = typename Self::Point_d;
using Dimension = typename Self::Dimension;
using Bbox_d = typename Self::Bbox_d;
using FT = typename Self::FT;
using Sphere_d = typename Self::Sphere_d; // SL: why?
using Array = typename Self::Array; // SL: why?
using Cartesian_const_iterator_d = typename Self::Cartesian_const_iterator_d;
using Point_d = typename boost::property_traits<VPM>::value_type;
using Geom_traits = typename Kernel_traits<Point_d>::type;
using Dimension = Dimension_tag<3>;
using Bbox_d = Bbox_3;
using FT = typename Geom_traits::FT;
using Sphere_d = typename Geom_traits::Sphere_3; // SL: why?
using Array = std::array<FT, 3>; // SL: why?
using Cartesian_const_iterator_d = typename Geom_traits::Cartesian_const_iterator_3;
// SL: these could be considered as built-in data and if the typedefs are not present, the tree have none // SL: these could be considered as built-in data and if the typedefs are not present, the tree have none
using Node_data_element = typename boost::graph_traits<PolygonMesh>::face_descriptor; using Node_data_element = typename boost::graph_traits<PolygonMesh>::face_descriptor;
using Node_data = std::vector<Node_data_element>; using Node_data = std::vector<Node_data_element>;
using Geom_traits = typename Kernel_traits<Point_d>::type;
struct Construct_bbox_d { struct Construct_bbox_d {
Bbox_d operator()(const Array& min, Bbox_d operator()(const Array& min,
const Array& max) const { const Array& max) const {
@ -59,64 +64,57 @@ struct Orthtree_traits_face_graph
Construct_point_d_from_array construct_point_d_from_array_object() const { return Construct_point_d_from_array(); } Construct_point_d_from_array construct_point_d_from_array_object() const { return Construct_point_d_from_array(); }
Construct_bbox_d construct_bbox_d_object() const { return Construct_bbox_d(); } Construct_bbox_d construct_bbox_d_object() const { return Construct_bbox_d(); }
// SL: why in each traits? because it's dimension dependant? auto root_node_bbox_object() const {
enum Adjacency { return [&]() -> std::pair<Array, Array> {
LEFT,
RIGHT,
DOWN,
UP,
BACK,
FRONT
};
std::pair<Array, Array> root_node_bbox() const Array min={0.0,0}, max={0.0,0};
{ if (faces(m_pm).begin()!=faces(m_pm).end())
Array min={0.0,0}, max={0.0,0};
if (faces(m_pm).begin()!=faces(m_pm).end())
{
const Point_d& p = get(m_vpm, *vertices(m_pm).begin());
min={p.x(), p.y(), p.z()};
max=min;
for (auto v : vertices(m_pm))
{ {
const Point_d& p_v = get(m_vpm, v); const Point_d& p = get(m_vpm, *vertices(m_pm).begin());
for (int i=0; i<3; ++i) min={p.x(), p.y(), p.z()};
max=min;
for (auto v : vertices(m_pm))
{ {
if (p_v[i]<min[i]) min[i]=p_v[i]; const Point_d& p_v = get(m_vpm, v);
if (p_v[i]>max[i]) max[i]=p_v[i]; for (int i=0; i<3; ++i)
{
if (p_v[i]<min[i]) min[i]=p_v[i];
if (p_v[i]>max[i]) max[i]=p_v[i];
}
} }
} }
}
return {min, max}; return {min, max};
};
} }
// SL: not clear to me what it should do from the doc // SL: not clear to me what it should do from the doc
Node_data root_node_contents() auto root_node_contents_object() {
{ return [&]() -> Node_data {
return {faces(m_pm).begin(), faces(m_pm).end()}; return {faces(m_pm).begin(), faces(m_pm).end()};
};
} }
template<class NodeIndex, class Tree> auto distribute_node_contents_object(){
void distribute_node_contents(NodeIndex n, Tree &tree, const Point_d &center) return [&](typename Tree::Node_index n, Tree &tree, const Point_d &center) -> void {
{ Node_data& ndata = tree.data(n);
Node_data& ndata = tree.data(n); for (int i=0; i<8; ++i)
for (int i=0; i<8; ++i)
{
NodeIndex child = tree.child(n, i);
Node_data& child_data = tree.data(child);
Bbox_d bbox = tree.bbox(child);
for (Node_data_element f : ndata)
{ {
typename boost::graph_traits<PolygonMesh>::halfedge_descriptor typename Tree::Node_index child = tree.child(n, i);
h = halfedge(f, m_pm); Node_data& child_data = tree.data(child);
typename Geom_traits::Triangle_3 t(get(m_vpm, source(h, m_pm)), Bbox_d bbox = tree.bbox(child);
get(m_vpm, target(h, m_pm)), for (Node_data_element f : ndata)
get(m_vpm, target(next(h, m_pm), m_pm))); {
if(do_intersect(t, bbox)) typename boost::graph_traits<PolygonMesh>::halfedge_descriptor
child_data.push_back(f); h = halfedge(f, m_pm);
typename Geom_traits::Triangle_3 t(get(m_vpm, source(h, m_pm)),
get(m_vpm, target(h, m_pm)),
get(m_vpm, target(next(h, m_pm), m_pm)));
if(do_intersect(t, bbox))
child_data.push_back(f);
}
} }
} };
} }
//SL: I find convenient to put it here //SL: I find convenient to put it here