From a649221899b4fdafbdfb3dc7ceac1f2c9405cd40 Mon Sep 17 00:00:00 2001 From: Julian Stahl Date: Tue, 20 Sep 2022 23:32:59 +0200 Subject: [PATCH] Refactor domains to separate topology, geometry, function, gradient --- .../include/CGAL/Cartesian_grid_domain.h | 151 --------------- .../include/CGAL/Cartesian_topology_base.h | 129 ------------ Isosurfacing_3/include/CGAL/Implicit_domain.h | 169 ---------------- .../Isosurfacing_3/internal/Base_domain.h | 104 ++++++++++ .../internal/Cartesian_grid_geometry.h | 45 +++++ .../internal/Explicit_cartesian_grid_domain.h | 63 ++++++ .../Isosurfacing_3/internal/Grid_topology.h | 183 ++++++++++++++++++ .../internal/Implicit_cartesian_grid_domain.h | 72 +++++++ .../Implicit_function_with_geometry.h | 42 ++++ .../internal/Implicit_octree_domain.h | 67 +++++++ .../Isosurfacing_3/internal/Octree_geometry.h | 46 +++++ .../Isosurfacing_3/internal/Octree_topology.h | 133 +++++++++++++ .../include/CGAL/Isosurfacing_domains.h | 99 ++++++++++ Isosurfacing_3/include/CGAL/Octree_domain.h | 153 --------------- 14 files changed, 854 insertions(+), 602 deletions(-) delete mode 100644 Isosurfacing_3/include/CGAL/Cartesian_grid_domain.h delete mode 100644 Isosurfacing_3/include/CGAL/Cartesian_topology_base.h delete mode 100644 Isosurfacing_3/include/CGAL/Implicit_domain.h create mode 100644 Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Base_domain.h create mode 100644 Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Cartesian_grid_geometry.h create mode 100644 Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Explicit_cartesian_grid_domain.h create mode 100644 Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Grid_topology.h create mode 100644 Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Implicit_cartesian_grid_domain.h create mode 100644 Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Implicit_function_with_geometry.h create mode 100644 Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Implicit_octree_domain.h create mode 100644 Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Octree_geometry.h create mode 100644 Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Octree_topology.h create mode 100644 Isosurfacing_3/include/CGAL/Isosurfacing_domains.h delete mode 100644 Isosurfacing_3/include/CGAL/Octree_domain.h diff --git a/Isosurfacing_3/include/CGAL/Cartesian_grid_domain.h b/Isosurfacing_3/include/CGAL/Cartesian_grid_domain.h deleted file mode 100644 index ef776147282..00000000000 --- a/Isosurfacing_3/include/CGAL/Cartesian_grid_domain.h +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright (c) 2022 INRIA Sophia-Antipolis (France). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial -// -// Author(s) : Julian Stahl - -#ifndef CGAL_CARTESIAN_GRID_DOMAIN_H -#define CGAL_CARTESIAN_GRID_DOMAIN_H - -#include -#include -#include -#include -#include - -#ifdef CGAL_LINKED_WITH_TBB -#include -#endif // CGAL_LINKED_WITH_TBB - -namespace CGAL { -namespace Isosurfacing { - -template > -class Cartesian_grid_domain : public Cartesian_topology_base { -public: - typedef GeomTraits Geom_traits; - typedef typename Geom_traits::FT FT; - typedef typename Geom_traits::Point_3 Point; - typedef typename Geom_traits::Vector_3 Vector; - typedef typename Geom_traits::Vector_3 Grid_spacing; - typedef Cartesian_grid_3 Grid; - -public: - Cartesian_grid_domain(const Grid& grid, const Gradient& grad = Gradient()) : grid(&grid), grad(&grad) {} - - Point position(const Vertex_handle& v) const { - const Bbox_3& bbox = grid->get_bbox(); - const Vector& spacing = grid->get_spacing(); - - return Point(v[0] * spacing.x() + bbox.xmin(), v[1] * spacing.y() + bbox.ymin(), - v[2] * spacing.z() + bbox.zmin()); - } - - Vector gradient(const Point& p) const { - return grad->operator()(p); - } - - FT value(const Vertex_handle& v) const { - return grid->value(v[0], v[1], v[2]); - } - - template - void iterate_vertices(Functor& f, Sequential_tag tag = Sequential_tag()) const { - iterate_vertices_base(f, tag, grid->xdim(), grid->ydim(), grid->zdim()); - } - - template - void iterate_edges(Functor& f, Sequential_tag tag = Sequential_tag()) const { - iterate_edges_base(f, tag, grid->xdim(), grid->ydim(), grid->zdim()); - } - - template - void iterate_cells(Functor& f, Sequential_tag tag = Sequential_tag()) const { - iterate_cells_base(f, tag, grid->xdim(), grid->ydim(), grid->zdim()); - } - -#ifdef CGAL_LINKED_WITH_TBB - template - void iterate_vertices(Functor& f, Parallel_tag) const { - const std::size_t size_x = grid->xdim(); - const std::size_t size_y = grid->ydim(); - const std::size_t size_z = grid->zdim(); - - auto iterator = [&f, size_x, size_y, size_z](const tbb::blocked_range& r) { - for (std::size_t x = r.begin(); x != r.end(); x++) { - for (std::size_t y = 0; y < size_y - 1; y++) { - for (std::size_t z = 0; z < size_z - 1; z++) { - f({x, y, z}); - } - } - } - }; - - tbb::parallel_for(tbb::blocked_range(0, size_x - 1), iterator); - } - - template - void iterate_edges(Functor& f, Parallel_tag) const { - const std::size_t size_x = grid->xdim(); - const std::size_t size_y = grid->ydim(); - const std::size_t size_z = grid->zdim(); - - auto iterator = [&f, size_x, size_y, size_z](const tbb::blocked_range& r) { - for (std::size_t x = r.begin(); x != r.end(); x++) { - for (std::size_t y = 0; y < size_y - 1; y++) { - for (std::size_t z = 0; z < size_z - 1; z++) { - f({x, y, z, 0}); - f({x, y, z, 1}); - f({x, y, z, 2}); - } - } - } - }; - - tbb::parallel_for(tbb::blocked_range(0, size_x - 1), iterator); - } - - template - void iterate_cells(Functor& f, Parallel_tag) const { - const std::size_t size_x = grid->xdim(); - const std::size_t size_y = grid->ydim(); - const std::size_t size_z = grid->zdim(); - - //#pragma omp parallel for - // for (int x = 0; x < size_x - 1; x++) { - // for (std::size_t y = 0; y < size_y - 1; y++) { - // for (std::size_t z = 0; z < size_z - 1; z++) { - // f({(std::size_t)x, y, z}); - // } - // } - //} - - auto iterator = [&f, size_x, size_y, size_z](const tbb::blocked_range& r) { - for (std::size_t x = r.begin(); x != r.end(); x++) { - for (std::size_t y = 0; y < size_y - 1; y++) { - for (std::size_t z = 0; z < size_z - 1; z++) { - f({x, y, z}); - } - } - } - }; - - tbb::parallel_for(tbb::blocked_range(0, size_x - 1), iterator); - } -#endif // CGAL_LINKED_WITH_TBB - -private: - const Grid* grid; - - const Gradient* grad; -}; - -} // namespace Isosurfacing -} // namespace CGAL - -#endif // CGAL_CARTESIAN_GRID_DOMAIN_H diff --git a/Isosurfacing_3/include/CGAL/Cartesian_topology_base.h b/Isosurfacing_3/include/CGAL/Cartesian_topology_base.h deleted file mode 100644 index a244a7c8f17..00000000000 --- a/Isosurfacing_3/include/CGAL/Cartesian_topology_base.h +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (c) 2022 INRIA Sophia-Antipolis (France). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial -// -// Author(s) : Julian Stahl - -#ifndef CGAL_CARTESIAN_TOPOLOGY_BASE_H -#define CGAL_CARTESIAN_TOPOLOGY_BASE_H - -#include -#include -#include -#include - -#include - -namespace CGAL { -namespace Isosurfacing { - -class Cartesian_topology_base { -public: - typedef std::array Vertex_handle; - typedef std::array Edge_handle; - typedef std::array Cell_handle; - - static constexpr Cell_type CELL_TYPE = CUBICAL_CELL; - static constexpr std::size_t VERTICES_PER_CELL = 8; - static constexpr std::size_t EDGES_PER_CELL = 12; - - typedef std::array Edge_vertices; - typedef std::array Cells_incident_to_edge; - typedef std::array Cell_vertices; - typedef std::array Cell_edges; - -public: - Edge_vertices edge_vertices(const Edge_handle& e) const { - Edge_vertices ev; - ev[0] = {e[0], e[1], e[2]}; - ev[1] = {e[0], e[1], e[2]}; - ev[1][e[3]] += 1; - return ev; - } - - Cells_incident_to_edge cells_incident_to_edge(const Edge_handle& e) const { - const int local = internal::Cube_table::edge_store_index[e[3]]; - auto neighbors = internal::Cube_table::edge_to_voxel_neighbor[local]; - - Cells_incident_to_edge cite; - for (std::size_t i = 0; i < cite.size(); i++) { - for (std::size_t j = 0; j < cite[i].size(); j++) { - cite[i][j] = e[j] + neighbors[i][j]; - } - } - return cite; - } - - Cell_vertices cell_vertices(const Cell_handle& v) const { - Cell_vertices cv; - for (std::size_t i = 0; i < cv.size(); i++) { - for (std::size_t j = 0; j < v.size(); j++) { - cv[i][j] = v[j] + internal::Cube_table::local_vertex_position[i][j]; - } - } - return cv; - } - - Cell_edges cell_edges(const Cell_handle& v) const { - Cell_edges ce; - for (std::size_t i = 0; i < ce.size(); i++) { - for (std::size_t j = 0; j < v.size(); j++) { - ce[i][j] = v[j] + internal::Cube_table::global_edge_id[i][j]; - } - ce[i][3] = internal::Cube_table::global_edge_id[i][3]; - } - return ce; - } - -protected: - template - void iterate_vertices_base(Functor& f, Sequential_tag, const std::size_t size_x, const std::size_t size_y, - const std::size_t size_z) const { - - for (std::size_t x = 0; x < size_x; x++) { - for (std::size_t y = 0; y < size_y; y++) { - for (std::size_t z = 0; z < size_z; z++) { - f({x, y, z}); - } - } - } - } - - template - void iterate_edges_base(Functor& f, Sequential_tag, const std::size_t size_x, const std::size_t size_y, - const std::size_t size_z) const { - - for (std::size_t x = 0; x < size_x - 1; x++) { - for (std::size_t y = 0; y < size_y - 1; y++) { - for (std::size_t z = 0; z < size_z - 1; z++) { - f({x, y, z, 0}); - f({x, y, z, 1}); - f({x, y, z, 2}); - } - } - } - } - - template - void iterate_cells_base(Functor& f, Sequential_tag, const std::size_t size_x, const std::size_t size_y, - const std::size_t size_z) const { - - for (std::size_t x = 0; x < size_x - 1; x++) { - for (std::size_t y = 0; y < size_y - 1; y++) { - for (std::size_t z = 0; z < size_z - 1; z++) { - f({x, y, z}); - } - } - } - } -}; - -} // namespace Isosurfacing -} // namespace CGAL - -#endif // CGAL_CARTESIAN_TOPOLOGY_BASE_H diff --git a/Isosurfacing_3/include/CGAL/Implicit_domain.h b/Isosurfacing_3/include/CGAL/Implicit_domain.h deleted file mode 100644 index 87da797cb69..00000000000 --- a/Isosurfacing_3/include/CGAL/Implicit_domain.h +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright (c) 2022 INRIA Sophia-Antipolis (France). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial -// -// Author(s) : Julian Stahl - -#ifndef CGAL_IMPLICIT_DOMAIN_H -#define CGAL_IMPLICIT_DOMAIN_H - -#include -#include -#include -#include - -#ifdef CGAL_LINKED_WITH_TBB -#include -#endif // CGAL_LINKED_WITH_TBB - -namespace CGAL { -namespace Isosurfacing { - -template > -class Implicit_domain : public Cartesian_topology_base { -public: - typedef GeomTraits Geom_traits; - typedef typename Geom_traits::FT FT; - typedef typename Geom_traits::Point_3 Point; - typedef typename Geom_traits::Vector_3 Vector; - typedef typename Geom_traits::Vector_3 Grid_spacing; - -public: - Implicit_domain(const Bbox_3& bbox, const Grid_spacing& spacing, const Function& func, - const Gradient& grad = Gradient()) - : bbox(bbox), spacing(spacing), func(&func), grad(&grad) { - - sizes[0] = bbox.x_span() / spacing.x() + 1; - sizes[1] = bbox.y_span() / spacing.y() + 1; - sizes[2] = bbox.z_span() / spacing.z() + 1; - } - - Point position(const Vertex_handle& v) const { - return Point(v[0] * spacing.x() + bbox.xmin(), v[1] * spacing.y() + bbox.ymin(), - v[2] * spacing.z() + bbox.zmin()); - } - - Vector gradient(const Point& p) const { - return grad->operator()(p); - } - - FT value(const Vertex_handle& v) const { - return func->operator()(position(v)); - } - - template - void iterate_vertices(Functor& f, Sequential_tag tag = Sequential_tag()) const { - iterate_vertices_base(f, tag, sizes[0], sizes[1], sizes[2]); - } - - template - void iterate_edges(Functor& f, Sequential_tag tag = Sequential_tag()) const { - iterate_edges_base(f, tag, sizes[0], sizes[1], sizes[2]); - } - - template - void iterate_cells(Functor& f, Sequential_tag tag = Sequential_tag()) const { - iterate_cells_base(f, tag, sizes[0], sizes[1], sizes[2]); - } - -#ifdef CGAL_LINKED_WITH_TBB - template - void iterate_vertices(Functor& f, Parallel_tag) const { - const std::size_t size_x = sizes[0]; - const std::size_t size_y = sizes[1]; - const std::size_t size_z = sizes[2]; - - auto iterator = [&f, size_x, size_y, size_z](const tbb::blocked_range& r) { - for (std::size_t x = r.begin(); x != r.end(); x++) { - for (std::size_t y = 0; y < size_y; y++) { - for (std::size_t z = 0; z < size_z; z++) { - f({x, y, z}); - } - } - } - }; - - tbb::parallel_for(tbb::blocked_range(0, size_x), iterator); - } - - template - void iterate_edges(Functor& f, Parallel_tag) const { - const std::size_t size_x = sizes[0]; - const std::size_t size_y = sizes[1]; - const std::size_t size_z = sizes[2]; - - auto iterator = [&f, size_x, size_y, size_z](const tbb::blocked_range& r) { - for (std::size_t x = r.begin(); x != r.end(); x++) { - for (std::size_t y = 0; y < size_y - 1; y++) { - for (std::size_t z = 0; z < size_z - 1; z++) { - f({x, y, z, 0}); - f({x, y, z, 1}); - f({x, y, z, 2}); - } - } - } - }; - - tbb::parallel_for(tbb::blocked_range(0, size_x - 1), iterator); - } - - template - void iterate_cells(Functor& f, Parallel_tag) const { - const std::size_t size_x = sizes[0]; - const std::size_t size_y = sizes[1]; - const std::size_t size_z = sizes[2]; - - //#pragma omp parallel for - // for (int x = 0; x < size_x - 1; x++) { - // Cell_handle h; - // h[0] = x; - // for (std::size_t y = 0; y < size_y - 1; y++) { - // h[1] = y; - // for (std::size_t z = 0; z < size_z - 1; z++) { - // h[2] = z; - // f(h); - // } - // } - //} - - auto iterator = [&f, size_x, size_y, size_z](const tbb::blocked_range& r) { - for (std::size_t x = r.begin(); x != r.end(); x++) { - for (std::size_t y = 0; y < size_y - 1; y++) { - for (std::size_t z = 0; z < size_z - 1; z++) { - f({x, y, z}); - } - } - } - }; - - tbb::parallel_for(tbb::blocked_range(0, size_x - 1), iterator); - } -#endif // CGAL_LINKED_WITH_TBB - -private: - Bbox_3 bbox; - Grid_spacing spacing; - - const Function* func; - const Gradient* grad; - - std::array sizes; -}; - - -template -Implicit_domain create_implicit_domain(const Bbox_3& domain, - const typename GeomTraits::Vector_3& spacing, - const Function& func, const Gradient& grad) { - return Implicit_domain(domain, spacing, func, grad); -} - -} // namespace Isosurfacing -} // namespace CGAL - -#endif // CGAL_IMPLICIT_DOMAIN_H diff --git a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Base_domain.h b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Base_domain.h new file mode 100644 index 00000000000..5af83d6cf1c --- /dev/null +++ b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Base_domain.h @@ -0,0 +1,104 @@ +// Copyright (c) 2022 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Julian Stahl + +#ifndef CGAL_BASE_DOMAIN_H +#define CGAL_BASE_DOMAIN_H + +#include +#include + +namespace CGAL { +namespace Isosurfacing { + +template +class Base_domain { +public: + typedef GeomTraits Geom_traits; + typedef typename Geom_traits::FT FT; + typedef typename Geom_traits::Point_3 Point; + typedef typename Geom_traits::Vector_3 Vector; + + typedef Topology_ Topology; + typedef typename Topology::Vertex_descriptor Vertex_descriptor; + typedef typename Topology::Edge_descriptor Edge_descriptor; + typedef typename Topology::Cell_descriptor Cell_descriptor; + + static constexpr Cell_type CELL_TYPE = Topology::CELL_TYPE; + static constexpr std::size_t VERTICES_PER_CELL = Topology::VERTICES_PER_CELL; + static constexpr std::size_t EDGES_PER_CELL = Topology::EDGES_PER_CELL; + + typedef typename Topology::Vertices_incident_to_edge Vertices_incident_to_edge; + typedef typename Topology::Cells_incident_to_edge Cells_incident_to_edge; + typedef typename Topology::Cell_vertices Cell_vertices; + typedef typename Topology::Cell_edges Cell_edges; + + typedef Geometry_ Geometry; + typedef Function_ Function; + typedef Gradient_ Gradient; + +public: + Base_domain(const Topology& topo, const Geometry& geom, const Function& func, const Gradient& grad) + : topo(&topo), geom(&geom), func(&func), grad(&grad) {} + + Point position(const Vertex_descriptor& v) const { + return geom->operator()(v); + } + + FT value(const Vertex_descriptor& v) const { + return func->operator()(v); + } + + Vector gradient(const Point& p) const { + return grad->operator()(p); + } + + Vertices_incident_to_edge edge_vertices(const Edge_descriptor& e) const { + return topo->edge_vertices(e); + } + + Cells_incident_to_edge cells_incident_to_edge(const Edge_descriptor& e) const { + return topo->cells_incident_to_edge(e); + } + + Cell_vertices cell_vertices(const Cell_descriptor& c) const { + return topo->cell_vertices(c); + } + + Cell_edges cell_edges(const Cell_descriptor& c) const { + return topo->cell_edges(c); + } + + template + void iterate_vertices(Functor& f) const { + topo->iterate_vertices(f, Concurrency_tag()); + } + + template + void iterate_edges(Functor& f) const { + topo->iterate_edges(f, Concurrency_tag()); + } + + template + void iterate_cells(Functor& f) const { + topo->iterate_cells(f, Concurrency_tag()); + } + +private: + const Topology* topo; + const Geometry* geom; + const Function* func; + const Gradient* grad; +}; + +} // namespace Isosurfacing +} // namespace CGAL + +#endif // CGAL_BASE_DOMAIN_H diff --git a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Cartesian_grid_geometry.h b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Cartesian_grid_geometry.h new file mode 100644 index 00000000000..331442d7723 --- /dev/null +++ b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Cartesian_grid_geometry.h @@ -0,0 +1,45 @@ +// Copyright (c) 2022 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Julian Stahl + +#ifndef CGAL_CARTESIAN_GRID_GEOMETRY_H +#define CGAL_CARTESIAN_GRID_GEOMETRY_H + +#include +#include + +namespace CGAL { +namespace Isosurfacing { + +template +class Cartesian_grid_geometry { +public: + typedef GeomTraits Geom_traits; + typedef typename Geom_traits::Point_3 Point; + typedef typename Geom_traits::Vector_3 Vector; + + typedef typename Grid_topology::Vertex_descriptor Vertex_descriptor; + +public: + Cartesian_grid_geometry(const Vector& offset, const Vector& spacing) : offset(offset), spacing(spacing) {} + + Point operator()(const Vertex_descriptor& v) const { + return Point(v[0] * spacing[0], v[1] * spacing[1], v[2] * spacing[2]) + offset; + } + +private: + Vector offset; + Vector spacing; +}; + +} // namespace Isosurfacing +} // namespace CGAL + +#endif // CGAL_CARTESIAN_GRID_GEOMETRY_H diff --git a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Explicit_cartesian_grid_domain.h b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Explicit_cartesian_grid_domain.h new file mode 100644 index 00000000000..ec8e8049104 --- /dev/null +++ b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Explicit_cartesian_grid_domain.h @@ -0,0 +1,63 @@ +// Copyright (c) 2022 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Julian Stahl + +#ifndef CGAL_EXPLICIT_CARTESIAN_GRID_DOMAIN_H +#define CGAL_EXPLICIT_CARTESIAN_GRID_DOMAIN_H + +#include +#include +#include +#include +#include +#include + +namespace CGAL { +namespace Isosurfacing { + +template +class Explicit_cartesian_grid_domain_with_gradient + : public Base_domain, Cartesian_grid_3, + Gradient_> { +public: + typedef GeomTraits Geom_traits; + + typedef Grid_topology Topology; + typedef Cartesian_grid_geometry Geometry; + typedef Cartesian_grid_3 Function; + typedef Gradient_ Gradient; + +public: + Explicit_cartesian_grid_domain_with_gradient(const std::size_t size_i, const std::size_t size_j, + const std::size_t size_k, const Vector& offset, const Vector& spacing, + const Function& grid, const Gradient& grad) + : topo(size_i, size_j, size_k), geom(offset, spacing), Base_domain(topo, geom, grid, grad) {} + +private: + Topology topo; + Geometry geom; +}; + +template +class Explicit_cartesian_grid_domain + : public Explicit_cartesian_grid_domain_with_gradient> { +public: + Explicit_cartesian_grid_domain(const std::size_t size_i, const std::size_t size_j, const std::size_t size_k, + const Vector& offset, const Vector& spacing, const Function& grid) + : Explicit_cartesian_grid_domain_with_gradient(size_i, size_j, size_k, offset, spacing, grid, grad) {} + +private: + Gradient grad; +}; + +} // namespace Isosurfacing +} // namespace CGAL + +#endif // CGAL_EXPLICIT_CARTESIAN_GRID_DOMAIN_H diff --git a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Grid_topology.h b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Grid_topology.h new file mode 100644 index 00000000000..9dbeeab2a97 --- /dev/null +++ b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Grid_topology.h @@ -0,0 +1,183 @@ +// Copyright (c) 2022 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Julian Stahl + +#ifndef CGAL_GRID_TOPOLOGY_H +#define CGAL_GRID_TOPOLOGY_H + +#include +#include +#include +#include + +#include + +#ifdef CGAL_LINKED_WITH_TBB +#include +#endif // CGAL_LINKED_WITH_TBB + +namespace CGAL { +namespace Isosurfacing { + +class Grid_topology { +public: + typedef std::array Vertex_descriptor; + typedef std::array Edge_descriptor; + typedef std::array Cell_descriptor; + + static constexpr Cell_type CELL_TYPE = CUBICAL_CELL; + static constexpr std::size_t VERTICES_PER_CELL = 8; + static constexpr std::size_t EDGES_PER_CELL = 12; + + typedef std::array Vertices_incident_to_edge; + typedef std::array Cells_incident_to_edge; + typedef std::array Cell_vertices; + typedef std::array Cell_edges; + +public: + Grid_topology(const std::size_t size_i, const std::size_t size_j, const std::size_t size_k) + : size_i(size_i), size_j(size_j), size_k(size_k) {} + + Vertices_incident_to_edge edge_vertices(const Edge_descriptor& e) const { + Vertices_incident_to_edge ev; + ev[0] = {e[0], e[1], e[2]}; + ev[1] = {e[0], e[1], e[2]}; + ev[1][e[3]] += 1; + return ev; + } + + Cells_incident_to_edge cells_incident_to_edge(const Edge_descriptor& e) const { + const int local = internal::Cube_table::edge_store_index[e[3]]; + auto neighbors = internal::Cube_table::edge_to_voxel_neighbor[local]; + + Cells_incident_to_edge cite; + for (std::size_t i = 0; i < cite.size(); i++) { + for (std::size_t j = 0; j < cite[i].size(); j++) { + cite[i][j] = e[j] + neighbors[i][j]; + } + } + return cite; + } + + Cell_vertices cell_vertices(const Cell_descriptor& c) const { + Cell_vertices cv; + for (std::size_t i = 0; i < cv.size(); i++) { + for (std::size_t j = 0; j < c.size(); j++) { + cv[i][j] = c[j] + internal::Cube_table::local_vertex_position[i][j]; + } + } + return cv; + } + + Cell_edges cell_edges(const Cell_descriptor& c) const { + Cell_edges ce; + for (std::size_t i = 0; i < ce.size(); i++) { + for (std::size_t j = 0; j < c.size(); j++) { + ce[i][j] = c[j] + internal::Cube_table::global_edge_id[i][j]; + } + ce[i][3] = internal::Cube_table::global_edge_id[i][3]; + } + return ce; + } + + template + void iterate_vertices(Functor& f, Sequential_tag) const { + for (std::size_t i = 0; i < size_i; i++) { + for (std::size_t j = 0; j < size_j; j++) { + for (std::size_t k = 0; k < size_k; k++) { + f({i, j, k}); + } + } + } + } + + template + void iterate_edges(Functor& f, Sequential_tag) const { + for (std::size_t i = 0; i < size_i - 1; i++) { + for (std::size_t j = 0; j < size_j - 1; j++) { + for (std::size_t k = 0; k < size_k - 1; k++) { + f({i, j, k, 0}); + f({i, j, k, 1}); + f({i, j, k, 2}); + } + } + } + } + + template + void iterate_cells(Functor& f, Sequential_tag) const { + for (std::size_t i = 0; i < size_i - 1; i++) { + for (std::size_t j = 0; j < size_j - 1; j++) { + for (std::size_t k = 0; k < size_k - 1; k++) { + f({i, j, k}); + } + } + } + } + +#ifdef CGAL_LINKED_WITH_TBB + template + void iterate_vertices(Functor& f, Parallel_tag) const { + auto iterator = [&f, size_i, size_j, size_k](const tbb::blocked_range& r) { + for (std::size_t i = r.begin(); i != r.end(); i++) { + for (std::size_t j = 0; j < size_j; j++) { + for (std::size_t k = 0; k < size_k; k++) { + f({i, j, k}); + } + } + } + }; + + tbb::parallel_for(tbb::blocked_range(0, size_i), iterator); + } + + template + void iterate_edges(Functor& f, Parallel_tag) const { + auto iterator = [&f, size_i, size_j, size_k](const tbb::blocked_range& r) { + for (std::size_t i = r.begin(); i != r.end(); i++) { + for (std::size_t j = 0; j < size_j - 1; j++) { + for (std::size_t k = 0; k < size_k - 1; k++) { + f({i, j, k, 0}); + f({i, j, k, 1}); + f({i, j, k, 2}); + } + } + } + }; + + tbb::parallel_for(tbb::blocked_range(0, size_i - 1), iterator); + } + + template + void iterate_cells(Functor& f, Parallel_tag) const { + auto iterator = [&f, size_i, size_j, size_k](const tbb::blocked_range& r) { + for (std::size_t i = r.begin(); i != r.end(); i++) { + for (std::size_t j = 0; j < size_j - 1; j++) { + for (std::size_t k = 0; k < size_k - 1; k++) { + f({i, j, k}); + } + } + } + }; + + tbb::parallel_for(tbb::blocked_range(0, size_i - 1), iterator); + } +#endif // CGAL_LINKED_WITH_TBB + +private: + std::size_t size_i; + std::size_t size_j; + std::size_t size_k; +}; + +} // namespace Isosurfacing +} // namespace CGAL + +#endif // CGAL_GRID_TOPOLOGY_H diff --git a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Implicit_cartesian_grid_domain.h b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Implicit_cartesian_grid_domain.h new file mode 100644 index 00000000000..637b43bb029 --- /dev/null +++ b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Implicit_cartesian_grid_domain.h @@ -0,0 +1,72 @@ +// Copyright (c) 2022 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Julian Stahl + +#ifndef CGAL_IMPLICIT_CARTESIAN_GRID_DOMAIN_H +#define CGAL_IMPLICIT_CARTESIAN_GRID_DOMAIN_H + +#include +#include +#include +#include +#include +#include + +namespace CGAL { +namespace Isosurfacing { + +template +class Implicit_cartesian_grid_domain_with_gradient + : public Base_domain, + Implicit_function_with_geometry, Function_>, + Gradient_> { +public: + typedef GeomTraits Geom_traits; + typedef typename Geom_traits::Vector_3 Vector; + + typedef Grid_topology Topology; + typedef Cartesian_grid_geometry Geometry; + typedef Function_ Function_with_point; + typedef Implicit_function_with_geometry Function; + typedef Gradient_ Gradient; + + typedef typename Topology::Vertex_descriptor Vertex_descriptor; + +public: + Implicit_cartesian_grid_domain_with_gradient(const std::size_t size_i, const std::size_t size_j, + const std::size_t size_k, const Vector& offset, const Vector& spacing, + const Function_with_point& func_with_point, const Gradient& grad) + : topo(size_i, size_j, size_k), + geom(offset, spacing), + func(geom, func_with_point), + Base_domain(topo, geom, func, grad) {} + +private: + Topology topo; + Geometry geom; + Function func; +}; + +template +class Implicit_cartesian_grid_domain + : public Implicit_cartesian_grid_domain_with_gradient> { +public: + Implicit_cartesian_grid_domain(const std::size_t size_i, const std::size_t size_j, const std::size_t size_k, + const Vector& offset, const Vector& spacing, const Function_with_point& func) + : Implicit_cartesian_grid_domain_with_gradient(size_i, size_j, size_k, offset, spacing, func, grad) {} + +private: + Gradient grad; +}; + +} // namespace Isosurfacing +} // namespace CGAL + +#endif // CGAL_IMPLICIT_CARTESIAN_GRID_DOMAIN_H diff --git a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Implicit_function_with_geometry.h b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Implicit_function_with_geometry.h new file mode 100644 index 00000000000..74266c41dfa --- /dev/null +++ b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Implicit_function_with_geometry.h @@ -0,0 +1,42 @@ +// Copyright (c) 2022 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Julian Stahl + +#ifndef CGAL_IMPLICIT_FUNCTION_WITH_GEOMETRY_H +#define CGAL_IMPLICIT_FUNCTION_WITH_GEOMETRY_H + +#include + +namespace CGAL { +namespace Isosurfacing { + +template +class Implicit_function_with_geometry { +public: + typedef GeomTraits Geom_traits; + typedef typename Geom_traits::FT FT; + +public: + Implicit_function_with_geometry(const Geometry& geom, const Function& func) : geom(&geom), func(&func) {} + + template + FT operator()(const VertexDescriptor& v) const { + return func->operator()(geom->operator()(v)); + } + +private: + const Geometry* geom; + const Function* func; +}; + +} // namespace Isosurfacing +} // namespace CGAL + +#endif // CGAL_IMPLICIT_FUNCTION_WITH_GEOMETRY_H diff --git a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Implicit_octree_domain.h b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Implicit_octree_domain.h new file mode 100644 index 00000000000..03b74759686 --- /dev/null +++ b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Implicit_octree_domain.h @@ -0,0 +1,67 @@ +// Copyright (c) 2022 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Julian Stahl + +#ifndef CGAL_IMPLICIT_OCTREE_DOMAIN_H +#define CGAL_IMPLICIT_OCTREE_DOMAIN_H + +#include +#include +#include +#include +#include +#include +#include + +namespace CGAL { +namespace Isosurfacing { + +template +class Implicit_octree_domain_with_gradient + : public Base_domain, Octree_geometry, + Implicit_function_with_geometry, Function_>, + Gradient_> { +public: + typedef GeomTraits Geom_traits; + + typedef Octree_wrapper Octree; + + typedef Octree_topology Topology; + typedef Octree_geometry Geometry; + typedef Function_ Function_with_point; + typedef Implicit_function_with_geometry Function; + typedef Gradient_ Gradient; + +public: + Implicit_octree_domain_with_gradient(const Octree& octree, const Function_with_point& func_with_point, + const Gradient& grad) + : topo(octree), geom(octree), func(geom, func_with_point), Base_domain(topo, geom, func, grad) {} + +private: + Topology topo; + Geometry geom; + Function func; +}; + +template +class Implicit_octree_domain + : public Implicit_octree_domain_with_gradient> { +public: + Implicit_octree_domain(const Octree& octree, const Function_with_point& func) + : Implicit_cartesian_grid_domain_with_gradient(octree, func, grad) {} + +private: + Gradient grad; +}; + +} // namespace Isosurfacing +} // namespace CGAL + +#endif // CGAL_IMPLICIT_OCTREE_DOMAIN_H diff --git a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Octree_geometry.h b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Octree_geometry.h new file mode 100644 index 00000000000..66ce190b961 --- /dev/null +++ b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Octree_geometry.h @@ -0,0 +1,46 @@ +// Copyright (c) 2022 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Julian Stahl + +#ifndef CGAL_OCTREE_GEOMETRY_H +#define CGAL_OCTREE_GEOMETRY_H + +#include +#include +#include + +namespace CGAL { +namespace Isosurfacing { + +template +class Octree_geometry { +public: + typedef GeomTraits Geom_traits; + typedef typename Geom_traits::Point_3 Point; + + typedef Octree_wrapper Octree; + + typedef typename Octree_topology::Vertex_descriptor Vertex_descriptor; + +public: + Octree_geometry(const Octree& octree) : octree(&octree) {} + + Point operator()(const Vertex_descriptor& v) const { + return octree->point(v); + } + +private: + const Octree* octree; +}; + +} // namespace Isosurfacing +} // namespace CGAL + +#endif // CGAL_OCTREE_GEOMETRY_H diff --git a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Octree_topology.h b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Octree_topology.h new file mode 100644 index 00000000000..970348cf66b --- /dev/null +++ b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/Octree_topology.h @@ -0,0 +1,133 @@ +// Copyright (c) 2022 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Julian Stahl + +#ifndef CGAL_OCTREE_TOPOLOGY_H +#define CGAL_OCTREE_TOPOLOGY_H + +#include +#include +#include +#include + +#ifdef CGAL_LINKED_WITH_TBB +#include +#endif // CGAL_LINKED_WITH_TBB + +namespace CGAL { +namespace Isosurfacing { + +template // TODO: should not be necessary +class Octree_topology { +public: + typedef GeomTraits Geom_traits; + typedef Octree_wrapper Octree; + typedef typename Octree::Vertex_handle Vertex_descriptor; + typedef typename Octree::Edge_handle Edge_descriptor; + typedef typename Octree::Voxel_handle Cell_descriptor; + + static constexpr Cell_type CELL_TYPE = CUBICAL_CELL; + static constexpr std::size_t VERTICES_PER_CELL = 8; + static constexpr std::size_t EDGES_PER_CELL = 12; + + typedef std::array Vertices_incident_to_edge; + typedef std::array Cells_incident_to_edge; // TODO: not always 4 + typedef std::array Cell_vertices; + typedef std::array Cell_edges; + +public: + Octree_topology(const Octree& octree) : octree(&octree) {} + + Vertices_incident_to_edge edge_vertices(const Edge_descriptor& e) const { + return octree->edge_vertices(e); + } + + Cells_incident_to_edge cells_incident_to_edge(const Edge_descriptor& e) const { + return octree->edge_voxels(e); + } + + Cell_vertices cell_vertices(const Cell_descriptor& c) const { + return octree->voxel_vertices(c); + } + + Cell_edges cell_edges(const Cell_descriptor& c) const { + return octree->voxel_edges(c); + } + + template + void iterate_vertices(Functor& f, Sequential_tag) const { + for (const Vertex_descriptor& v : octree->leaf_vertices()) { + f(v); + } + } + + template + void iterate_edges(Functor& f, Sequential_tag) const { + for (const Edge_descriptor& e : octree->leaf_edges()) { + f(e); + } + } + + template + void iterate_cells(Functor& f, Sequential_tag) const { + for (const Cell_descriptor& v : octree->leaf_voxels()) { + f(v); + } + } + +#ifdef CGAL_LINKED_WITH_TBB + template + void iterate_vertices(Functor& f, Parallel_tag) const { + const auto& vertices = octree->leaf_vertices(); + + auto iterator = [&](const tbb::blocked_range& r) { + for (std::size_t i = r.begin(); i != r.end(); i++) { + f(vertices[i]); + } + }; + + tbb::parallel_for(tbb::blocked_range(0, vertices.size()), iterator); + } + + template + void iterate_edges(Functor& f) const { + const auto& edges = octree->leaf_edges(); + + auto iterator = [&](const tbb::blocked_range& r) { + for (std::size_t i = r.begin(); i != r.end(); i++) { + f(edges[i]); + } + }; + + tbb::parallel_for(tbb::blocked_range(0, edges.size()), iterator); + } + + template + void iterate_cells(Functor& f) const { + const auto& cells = octree->leaf_voxels(); + + auto iterator = [&](const tbb::blocked_range& r) { + for (std::size_t i = r.begin(); i != r.end(); i++) { + f(cells[i]); + } + }; + + tbb::parallel_for(tbb::blocked_range(0, cells.size()), iterator); + } +#endif // CGAL_LINKED_WITH_TBB + +private: + const Octree* octree; +}; + +} // namespace Isosurfacing +} // namespace CGAL + +#endif // CGAL_OCTREE_TOPOLOGY_H diff --git a/Isosurfacing_3/include/CGAL/Isosurfacing_domains.h b/Isosurfacing_3/include/CGAL/Isosurfacing_domains.h new file mode 100644 index 00000000000..01364e2b86b --- /dev/null +++ b/Isosurfacing_3/include/CGAL/Isosurfacing_domains.h @@ -0,0 +1,99 @@ +// Copyright (c) 2022 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Julian Stahl + +#ifndef CGAL_ISOSURFACING_DOMAINS_H +#define CGAL_ISOSURFACING_DOMAINS_H + +#include +#include +#include +#include +#include +#include +#include + +namespace CGAL { +namespace Isosurfacing { + +template +Implicit_cartesian_grid_domain_with_gradient create_implicit_cartesian_grid_domain( + const Bbox_3& bbox, const typename GeomTraits::Vector_3& spacing, const Function& func, const Gradient& grad) { + + const std::size_t size_i = std::ceil(bbox.x_span() / spacing.x()) + 1; + const std::size_t size_j = std::ceil(bbox.y_span() / spacing.y()) + 1; + const std::size_t size_k = std::ceil(bbox.z_span() / spacing.z()) + 1; + + const typename GeomTraits::Vector_3 offset(bbox.xmin(), bbox.ymin(), bbox.zmin()); + + return {size_i, size_j, size_k, offset, spacing, func, grad}; +} + +template +Implicit_cartesian_grid_domain create_implicit_cartesian_grid_domain( + const Bbox_3& bbox, const typename GeomTraits::Vector_3& spacing, const Function& func) { + + const std::size_t size_i = std::ceil(bbox.x_span() / spacing.x()) + 1; + const std::size_t size_j = std::ceil(bbox.y_span() / spacing.y()) + 1; + const std::size_t size_k = std::ceil(bbox.z_span() / spacing.z()) + 1; + + const typename GeomTraits::Vector_3 offset(bbox.xmin(), bbox.ymin(), bbox.zmin()); + + return {size_i, size_j, size_k, offset, spacing, func}; +} + +template +Explicit_cartesian_grid_domain_with_gradient create_explicit_cartesian_grid_domain( + const Cartesian_grid_3& grid, const Gradient& grad) { + + const std::size_t size_i = grid.xdim(); + const std::size_t size_j = grid.ydim(); + const std::size_t size_k = grid.zdim(); + + const Bbox_3& bbox = grid.get_bbox(); + const typename GeomTraits::Vector_3 offset(bbox.xmin(), bbox.ymin(), bbox.zmin()); + const typename GeomTraits::Vector_3 spacing = grid.get_spacing(); + + return {size_i, size_j, size_k, offset, spacing, grid, grad}; +} + +template +Explicit_cartesian_grid_domain create_explicit_cartesian_grid_domain( + const Cartesian_grid_3& grid) { + + const std::size_t size_i = grid.xdim(); + const std::size_t size_j = grid.ydim(); + const std::size_t size_k = grid.zdim(); + + const Bbox_3& bbox = grid.get_bbox(); + const typename GeomTraits::Vector_3 offset(bbox.xmin(), bbox.ymin(), bbox.zmin()); + const typename GeomTraits::Vector_3 spacing = grid.get_spacing(); + + return {size_i, size_j, size_k, offset, spacing, grid}; +} + +template +Implicit_octree_domain_with_gradient create_implicit_octree_domain( + const Octree_wrapper& octree, const Function& func, const Gradient& grad) { + + return {octree, func, grad}; +} + +template +Implicit_octree_domain create_implicit_octree_domain(const Octree_wrapper& octree, + const Function& func) { + + return {octree, func}; +} + +} // namespace Isosurfacing +} // namespace CGAL + +#endif // CGAL_ISOSURFACING_DOMAINS_H diff --git a/Isosurfacing_3/include/CGAL/Octree_domain.h b/Isosurfacing_3/include/CGAL/Octree_domain.h deleted file mode 100644 index 623d691deaf..00000000000 --- a/Isosurfacing_3/include/CGAL/Octree_domain.h +++ /dev/null @@ -1,153 +0,0 @@ -// Copyright (c) 2022 INRIA Sophia-Antipolis (France). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial -// -// Author(s) : Julian Stahl - -#ifndef CGAL_OCTREE_DOMAIN_H -#define CGAL_OCTREE_DOMAIN_H - -#include -#include -#include -#include - -#ifdef CGAL_LINKED_WITH_TBB -#include -#endif // CGAL_LINKED_WITH_TBB - -#include - -namespace CGAL { -namespace Isosurfacing { - -template > -class Octree_domain { -public: - typedef GeomTraits Geom_traits; - typedef typename Geom_traits::FT FT; - typedef typename Geom_traits::Point_3 Point; - typedef typename Geom_traits::Vector_3 Vector; - - typedef Octree_wrapper Octree; - typedef typename Octree::Vertex_handle Vertex_handle; - typedef typename Octree::Edge_handle Edge_handle; - typedef typename Octree::Voxel_handle Cell_handle; - - static constexpr Cell_type CELL_TYPE = CUBICAL_CELL; - static constexpr std::size_t VERTICES_PER_CELL = 8; - static constexpr std::size_t EDGES_PER_CELL = 12; - - typedef std::array Edge_vertices; - typedef std::array Cells_incident_to_edge; // TODO: not alwayys 4 - typedef std::array Cell_vertices; - typedef std::array Cell_edges; - -public: - Octree_domain(const Octree& octree, const Gradient& grad = Gradient()) : octree_(&octree), grad(&grad) {} - - Point position(const Vertex_handle& v) const { - return octree_->point(v); - } - - Vector gradient(const Point& p) const { - return grad->operator()(p); - } - - FT value(const Vertex_handle& v) const { - return octree_->vertex_value(v); - } - - Edge_vertices edge_vertices(const Edge_handle& e_id) const { - return octree_->edge_vertices(e_id); - } - - Cells_incident_to_edge cells_incident_to_edge(const Edge_handle& e_id) const { - return octree_->edge_voxels(e_id); - } - - Cell_vertices cell_vertices(const Cell_handle& vox) const { - return octree_->voxel_vertices(vox); - } - - Cell_edges cell_edges(const Cell_handle& vox) const { - return octree_->voxel_edges(vox); - } - - template - void iterate_vertices(Functor& f, Sequential_tag = Sequential_tag()) const { - for (const Vertex_handle& v : octree_->leaf_vertices()) { - f(v); - } - } - - template - void iterate_edges(Functor& f, Sequential_tag = Sequential_tag()) const { - for (const Edge_handle& e : octree_->leaf_edges()) { - f(e); - } - } - - template - void iterate_cells(Functor& f, Sequential_tag = Sequential_tag()) const { - for (const Cell_handle& v : octree_->leaf_voxels()) { - f(v); - } - } - -#ifdef CGAL_LINKED_WITH_TBB - template - void iterate_vertices(Functor& f, Parallel_tag) const { - const auto& vertices = octree_->leaf_vertices(); - - auto iterator = [&](const tbb::blocked_range& r) { - for (std::size_t i = r.begin(); i != r.end(); i++) { - f(vertices[i]); - } - }; - - tbb::parallel_for(tbb::blocked_range(0, vertices.size()), iterator); - } - - template - void iterate_edges(Functor& f, Parallel_tag) const { - const auto& edges = octree_->leaf_edges(); - - auto iterator = [&](const tbb::blocked_range& r) { - for (std::size_t i = r.begin(); i != r.end(); i++) { - f(edges[i]); - } - }; - - tbb::parallel_for(tbb::blocked_range(0, edges.size()), iterator); - } - - template - void iterate_cells(Functor& f, Parallel_tag) const { - const auto& cells = octree_->leaf_voxels(); - - auto iterator = [&](const tbb::blocked_range& r) { - for (std::size_t i = r.begin(); i != r.end(); i++) { - f(cells[i]); - } - }; - - tbb::parallel_for(tbb::blocked_range(0, cells.size()), iterator); - } -#endif // CGAL_LINKED_WITH_TBB - -private: - const Octree* octree_; - - const Gradient* grad; -}; - -} // namespace Isosurfacing -} // namespace CGAL - -#endif // CGAL_OCTREE_DOMAIN_H