diff --git a/Isosurfacing_3/benchmark/Isosurfacing_3/benchmark.cpp b/Isosurfacing_3/benchmark/Isosurfacing_3/benchmark.cpp index 600b6e3e7ee..c66f925a811 100644 --- a/Isosurfacing_3/benchmark/Isosurfacing_3/benchmark.cpp +++ b/Isosurfacing_3/benchmark/Isosurfacing_3/benchmark.cpp @@ -3,7 +3,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -39,8 +40,8 @@ struct SphereGradient { template struct Implicit_sphere { - typedef CGAL::Isosurfacing::Implicit_cartesian_grid_domain_with_gradient, - SphereGradient> + typedef CGAL::Isosurfacing::Implicit_cartesian_grid_domain, + SphereGradient> Domain; typedef typename GeomTraits::Vector_3 Vector; @@ -97,8 +98,8 @@ struct IWPGradient { template struct Implicit_iwp { - typedef CGAL::Isosurfacing::Implicit_cartesian_grid_domain_with_gradient, - IWPGradient> + typedef CGAL::Isosurfacing::Implicit_cartesian_grid_domain, + IWPGradient> Domain; typedef typename GeomTraits::Vector_3 Vector; @@ -123,27 +124,30 @@ template struct Grid_sphere { typedef CGAL::Isosurfacing::Explicit_cartesian_grid_gradient Gradient; - typedef CGAL::Isosurfacing::Explicit_cartesian_grid_domain_with_gradient Domain; + typedef CGAL::Isosurfacing::Explicit_cartesian_grid_domain Domain; typedef CGAL::Cartesian_grid_3 Grid; typedef typename GeomTraits::FT FT; typedef typename GeomTraits::Point_3 Point; - Grid_sphere(const std::size_t N) : grid(N, N, N, {-1, -1, -1, 1, 1, 1}) { + Grid_sphere(const std::size_t N) { + const CGAL::Bbox_3 bbox(-1, -1, -1, 1, 1, 1); + grid = std::make_shared(N, N, N, bbox); + const FT resolution = 2.0 / N; SphereValue val; SphereGradient grad; - for (std::size_t x = 0; x < grid.xdim(); x++) { + for (std::size_t x = 0; x < grid->xdim(); x++) { const FT xp = x * resolution - 1.0; - for (std::size_t y = 0; y < grid.ydim(); y++) { + for (std::size_t y = 0; y < grid->ydim(); y++) { const FT yp = y * resolution - 1.0; - for (std::size_t z = 0; z < grid.zdim(); z++) { + for (std::size_t z = 0; z < grid->zdim(); z++) { const FT zp = z * resolution - 1.0; - grid.value(x, y, z) = val(Point(xp, yp, zp)); - grid.gradient(x, y, z) = grad(Point(xp, yp, zp)); + grid->value(x, y, z) = val(Point(xp, yp, zp)); + grid->gradient(x, y, z) = grad(Point(xp, yp, zp)); } } } @@ -158,24 +162,24 @@ struct Grid_sphere { } private: - Grid grid; + std::shared_ptr grid; }; template struct Skull_image { typedef CGAL::Isosurfacing::Explicit_cartesian_grid_gradient Gradient; - typedef CGAL::Isosurfacing::Explicit_cartesian_grid_domain_with_gradient Domain; + typedef CGAL::Isosurfacing::Explicit_cartesian_grid_domain Domain; typedef CGAL::Cartesian_grid_3 Grid; - Skull_image(const std::size_t N) : grid(2, 2, 2, {-1, -1, -1, 1, 1, 1}) { + Skull_image(const std::size_t N) { const std::string fname = CGAL::data_file_path("images/skull_2.9.inr"); CGAL::Image_3 image; if (!image.read(fname)) { std::cerr << "Error: Cannot read file " << fname << std::endl; } - grid = Grid(image); + grid = std::make_shared(image); } Domain domain() const { @@ -187,7 +191,7 @@ struct Skull_image { } private: - Grid grid; + std::shared_ptr grid; }; int main(int argc, char* argv[]) { diff --git a/Isosurfacing_3/examples/Isosurfacing_3/all_cartesian_cube.cpp b/Isosurfacing_3/examples/Isosurfacing_3/all_cartesian_cube.cpp index 6b8acc85efa..e80b54582c9 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/all_cartesian_cube.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/all_cartesian_cube.cpp @@ -21,19 +21,20 @@ FT sign(FT value) { int main() { // create a cartesian grid with 100^3 grid points and the bounding box [-1, 1]^3 - Grid grid(7, 7, 7, {-1, -1, -1, 1, 1, 1}); + const CGAL::Bbox_3 bbox(-1, -1, -1, 1, 1, 1); + std::shared_ptr grid = std::make_shared(7, 7, 7, bbox); // calculate the value at all grid points - for (std::size_t x = 0; x < grid.xdim(); x++) { - for (std::size_t y = 0; y < grid.ydim(); y++) { - for (std::size_t z = 0; z < grid.zdim(); z++) { + for (std::size_t x = 0; x < grid->xdim(); x++) { + for (std::size_t y = 0; y < grid->ydim(); y++) { + for (std::size_t z = 0; z < grid->zdim(); z++) { - const FT pos_x = x * grid.get_spacing()[0] + grid.get_bbox().xmin(); - const FT pos_y = y * grid.get_spacing()[1] + grid.get_bbox().ymin(); - const FT pos_z = z * grid.get_spacing()[2] + grid.get_bbox().zmin(); + const FT pos_x = x * grid->get_spacing()[0] + bbox.xmin(); + const FT pos_y = y * grid->get_spacing()[1] + bbox.ymin(); + const FT pos_z = z * grid->get_spacing()[2] + bbox.zmin(); // manhattan distance to the origin - grid.value(x, y, z) = std::max({std::abs(pos_x), std::abs(pos_y), std::abs(pos_z)}); + grid->value(x, y, z) = std::max({std::abs(pos_x), std::abs(pos_y), std::abs(pos_z)}); } } } diff --git a/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_cartesian_grid.cpp b/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_cartesian_grid.cpp index b5da6966425..ae1f96d68a0 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_cartesian_grid.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_cartesian_grid.cpp @@ -17,21 +17,22 @@ typedef std::vector> Polygon_range; int main() { - Grid grid(30, 30, 30, {-1, -1, -1, 1, 1, 1}); + const CGAL::Bbox_3 bbox(-1, -1, -1, 1, 1, 1); + std::shared_ptr grid = std::make_shared(30, 30, 30, bbox); - for (std::size_t x = 0; x < grid.xdim(); x++) { - for (std::size_t y = 0; y < grid.ydim(); y++) { - for (std::size_t z = 0; z < grid.zdim(); z++) { + for (std::size_t x = 0; x < grid->xdim(); x++) { + for (std::size_t y = 0; y < grid->ydim(); y++) { + for (std::size_t z = 0; z < grid->zdim(); z++) { - const FT pos_x = x * grid.get_spacing()[0] + grid.get_bbox().xmin(); - const FT pos_y = y * grid.get_spacing()[1] + grid.get_bbox().ymin(); - const FT pos_z = z * grid.get_spacing()[2] + grid.get_bbox().zmin(); + const FT pos_x = x * grid->get_spacing()[0] + bbox.xmin(); + const FT pos_y = y * grid->get_spacing()[1] + bbox.ymin(); + const FT pos_z = z * grid->get_spacing()[2] + bbox.zmin(); const Vector direction(pos_x, pos_y, pos_z); const FT distance = CGAL::approximate_sqrt(direction.squared_length()); - grid.value(x, y, z) = distance; - grid.gradient(x, y, z) = direction / distance; + grid->value(x, y, z) = distance; + grid->gradient(x, y, z) = direction / distance; } } } diff --git a/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_octree.cpp b/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_octree.cpp index d1b5734b9fe..8ed85436a9b 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_octree.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_octree.cpp @@ -62,10 +62,11 @@ struct Refine_one_eighth { }; int main() { - Octree_wrapper_ octree_wrap({-1, -1, -1, 1, 1, 1}); + const CGAL::Bbox_3 bbox(-1, -1, -1, 1, 1, 1); + std::shared_ptr octree_wrap = std::make_shared(bbox); Refine_one_eighth split_predicate(3, 4); - octree_wrap.refine(split_predicate); + octree_wrap->refine(split_predicate); auto sphere_function = [&](const Point& p) { return std::sqrt(p.x() * p.x() + p.y() * p.y() + p.z() * p.z()); }; diff --git a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_cartesian_grid_sphere.cpp b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_cartesian_grid_sphere.cpp index e640c5131f2..1811eea7218 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_cartesian_grid_sphere.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_cartesian_grid_sphere.cpp @@ -16,19 +16,20 @@ typedef std::vector> Polygon_range; int main() { // create a cartesian grid with 100^3 grid points and the bounding box [-1, 1]^3 - Grid grid(50, 50, 50, {-1, -1, -1, 1, 1, 1}); + const CGAL::Bbox_3 bbox(-1, -1, -1, 1, 1, 1); + std::shared_ptr grid = std::make_shared(50, 50, 50, bbox); // calculate the value at all grid points - for (std::size_t x = 0; x < grid.xdim(); x++) { - for (std::size_t y = 0; y < grid.ydim(); y++) { - for (std::size_t z = 0; z < grid.zdim(); z++) { + for (std::size_t x = 0; x < grid->xdim(); x++) { + for (std::size_t y = 0; y < grid->ydim(); y++) { + for (std::size_t z = 0; z < grid->zdim(); z++) { - const FT pos_x = x * grid.get_spacing()[0] + grid.get_bbox().xmin(); - const FT pos_y = y * grid.get_spacing()[1] + grid.get_bbox().ymin(); - const FT pos_z = z * grid.get_spacing()[2] + grid.get_bbox().zmin(); + const FT pos_x = x * grid->get_spacing()[0] + bbox.xmin(); + const FT pos_y = y * grid->get_spacing()[1] + bbox.ymin(); + const FT pos_z = z * grid->get_spacing()[2] + bbox.zmin(); // distance to the origin - grid.value(x, y, z) = std::sqrt(pos_x * pos_x + pos_y * pos_y + pos_z * pos_z); + grid->value(x, y, z) = std::sqrt(pos_x * pos_x + pos_y * pos_y + pos_z * pos_z); } } } diff --git a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_implicit_sphere.cpp b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_implicit_sphere.cpp index 64bb6372f43..5f085001d74 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_implicit_sphere.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_implicit_sphere.cpp @@ -19,7 +19,8 @@ int main() { auto sphere_function = [&](const Point& p) { return std::sqrt(p.x() * p.x() + p.y() * p.y() + p.z() * p.z()); }; // create a domain with bounding box [-1, 1]^3 and grid spacing 0.02 - auto domain = CGAL::Isosurfacing::create_implicit_cartesian_grid_domain(bbox, spacing, std::move(sphere_function)); + auto domain = + CGAL::Isosurfacing::create_implicit_cartesian_grid_domain(bbox, spacing, std::move(sphere_function)); // prepare collections for the result Point_range points; diff --git a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_inrimage.cpp b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_inrimage.cpp index 8564ef7dd7f..a17d2390bc0 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_inrimage.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_inrimage.cpp @@ -24,7 +24,7 @@ int main() { } // convert it to a cartesian grid - const Grid grid(image); + std::shared_ptr grid = std::make_shared(image); // create a domain from the grid auto domain = CGAL::Isosurfacing::create_explicit_cartesian_grid_domain(grid); diff --git a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_mesh_offset.cpp b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_mesh_offset.cpp index 1deb39ecff0..0f13251d035 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_mesh_offset.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_mesh_offset.cpp @@ -58,24 +58,24 @@ int main() { CGAL::Side_of_triangle_mesh::type> sotm(mesh_input); // create the grid - Grid grid(n_voxels, n_voxels, n_voxels, aabb_grid); + std::shared_ptr grid = std::make_shared(n_voxels, n_voxels, n_voxels, aabb_grid); - for (std::size_t z = 0; z < grid.zdim(); z++) { - for (std::size_t y = 0; y < grid.ydim(); y++) { - for (std::size_t x = 0; x < grid.xdim(); x++) { + for (std::size_t z = 0; z < grid->zdim(); z++) { + for (std::size_t y = 0; y < grid->ydim(); y++) { + for (std::size_t x = 0; x < grid->xdim(); x++) { - const FT pos_x = x * grid.get_spacing()[0] + grid.get_bbox().xmin(); - const FT pos_y = y * grid.get_spacing()[1] + grid.get_bbox().ymin(); - const FT pos_z = z * grid.get_spacing()[2] + grid.get_bbox().zmin(); + const FT pos_x = x * grid->get_spacing()[0] + grid->get_bbox().xmin(); + const FT pos_y = y * grid->get_spacing()[1] + grid->get_bbox().ymin(); + const FT pos_z = z * grid->get_spacing()[2] + grid->get_bbox().zmin(); const Point p(pos_x, pos_y, pos_z); // compute the distance - grid.value(x, y, z) = distance_to_mesh(tree, p); + grid->value(x, y, z) = distance_to_mesh(tree, p); // flip the sign, so the distance is negative inside the mesh const bool is_inside = (sotm(p) == CGAL::ON_BOUNDED_SIDE); if (is_inside) { - grid.value(x, y, z) *= -1; + grid->value(x, y, z) *= -1; } } } diff --git a/Isosurfacing_3/include/CGAL/Default_gradients.h b/Isosurfacing_3/include/CGAL/Default_gradients.h index 9e17196e42c..b7caf586245 100644 --- a/Isosurfacing_3/include/CGAL/Default_gradients.h +++ b/Isosurfacing_3/include/CGAL/Default_gradients.h @@ -32,7 +32,7 @@ public: } }; -template +template class Finite_difference_gradient { public: typedef GeomTraits Geom_traits; @@ -41,7 +41,7 @@ public: typedef typename Geom_traits::Vector_3 Vector; public: - Finite_difference_gradient(const Function& func, const FT delta = 0.001) : func(&func), delta(delta) {} + Finite_difference_gradient(const PointFunction& func, const FT delta = 0.001) : func(func), delta(delta) {} Vector operator()(const Point& point) const { // TODO // compute the gradient by sampling the function with finite differences @@ -53,15 +53,15 @@ public: const Point p4 = point + Vector(0, 0, delta); const Point p5 = point - Vector(0, 0, delta); - const FT gx = (func->operator()(p0) - func->operator()(p1)) / (2 * delta); - const FT gy = (func->operator()(p2) - func->operator()(p3)) / (2 * delta); - const FT gz = (func->operator()(p4) - func->operator()(p5)) / (2 * delta); + const FT gx = (func(p0) - func(p1)) / (2 * delta); + const FT gy = (func(p2) - func(p3)) / (2 * delta); + const FT gz = (func(p4) - func(p5)) / (2 * delta); return Vector(gx, gy, gz); } private: - const Function* func; + const PointFunction func; FT delta; }; @@ -73,10 +73,10 @@ public: typedef typename Geom_traits::Point_3 Point; typedef typename Geom_traits::Vector_3 Vector; - typedef Cartesian_grid_3 Grid; + typedef std::shared_ptr> Grid; public: - Explicit_cartesian_grid_gradient(const Grid& grid) : grid(&grid) {} + Explicit_cartesian_grid_gradient(const Grid& grid) : grid(grid) {} Vector operator()(const Point& point) const { // trilinear interpolation of stored gradients @@ -128,7 +128,7 @@ public: } private: - const Grid* grid; + const Grid grid; }; } // namespace Isosurfacing diff --git a/Isosurfacing_3/include/CGAL/Explicit_cartesian_grid_domain.h b/Isosurfacing_3/include/CGAL/Explicit_cartesian_grid_domain.h index e868268ffb8..e554a1abf58 100644 --- a/Isosurfacing_3/include/CGAL/Explicit_cartesian_grid_domain.h +++ b/Isosurfacing_3/include/CGAL/Explicit_cartesian_grid_domain.h @@ -28,7 +28,7 @@ using Explicit_cartesian_grid_domain = Base_domain> Explicit_cartesian_grid_domain create_explicit_cartesian_grid_domain( - const Cartesian_grid_3& grid, const Gradient_& gradient = Gradient_()) { + const std::shared_ptr> grid, const Gradient_& gradient = Gradient_()) { typedef Explicit_cartesian_grid_domain Domain; typedef typename Domain::Topology Topology; @@ -36,17 +36,17 @@ Explicit_cartesian_grid_domain create_explicit_cartesian_ typedef typename Domain::Function Function; typedef typename Domain::Gradient Gradient; - 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 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 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(); + const typename GeomTraits::Vector_3 spacing = grid->get_spacing(); const Topology topo = std::make_shared(size_i, size_j, size_k); const Geometry geom = std::make_shared(offset, spacing); - const Function func = std::make_shared(grid); + const Function func = grid; const Gradient grad = std::make_shared(gradient); return Domain(topo, geom, func, grad); diff --git a/Isosurfacing_3/include/CGAL/Implicit_octree_domain.h b/Isosurfacing_3/include/CGAL/Implicit_octree_domain.h index 2ecced0e35f..8677a97c241 100644 --- a/Isosurfacing_3/include/CGAL/Implicit_octree_domain.h +++ b/Isosurfacing_3/include/CGAL/Implicit_octree_domain.h @@ -31,7 +31,7 @@ using Implicit_octree_domain = template > Implicit_octree_domain create_implicit_octree_domain( - const Octree_wrapper& octree, const PointFunction& point_function, + const std::shared_ptr> octree, const PointFunction& point_function, const Gradient_& gradient = Gradient_()) { typedef Implicit_octree_domain Domain; @@ -42,7 +42,7 @@ Implicit_octree_domain create_implicit_oct typedef typename Function::element_type::Point_function Point_function; typedef typename Topology::element_type::Octree Octree; - const Octree oct = std::make_shared(octree); + const Octree oct = octree; const Topology topo = std::make_shared(oct); const Geometry geom = std::make_shared(oct); const Point_function point_func = std::make_shared(point_function); diff --git a/Isosurfacing_3/test/Isosurfacing_3/test_dual_contouring.cpp b/Isosurfacing_3/test/Isosurfacing_3/test_dual_contouring.cpp index 541a7cdb421..b99836ea1bd 100644 --- a/Isosurfacing_3/test/Isosurfacing_3/test_dual_contouring.cpp +++ b/Isosurfacing_3/test/Isosurfacing_3/test_dual_contouring.cpp @@ -1,6 +1,7 @@ #include #include -#include +#include +#include #include #include #include @@ -37,16 +38,16 @@ int main() { const std::size_t ny = static_cast(2.0 / spacing.y()); const std::size_t nz = static_cast(2.0 / spacing.z()); - Grid grid(nx, ny, nz, bbox); + std::shared_ptr grid = std::make_shared(nx, ny, nz, bbox); - for (std::size_t x = 0; x < grid.xdim(); x++) { - for (std::size_t y = 0; y < grid.ydim(); y++) { - for (std::size_t z = 0; z < grid.zdim(); z++) { + for (std::size_t x = 0; x < grid->xdim(); x++) { + for (std::size_t y = 0; y < grid->ydim(); y++) { + for (std::size_t z = 0; z < grid->zdim(); z++) { const Point pos(x * spacing.x() + bbox.xmin(), y * spacing.y() + bbox.ymin(), z * spacing.z() + bbox.zmin()); - grid.value(x, y, z) = sphere_function(pos); + grid->value(x, y, z) = sphere_function(pos); } } } diff --git a/Isosurfacing_3/test/Isosurfacing_3/test_marching_cubes.cpp b/Isosurfacing_3/test/Isosurfacing_3/test_marching_cubes.cpp index c8688dd6b47..f147111a945 100644 --- a/Isosurfacing_3/test/Isosurfacing_3/test_marching_cubes.cpp +++ b/Isosurfacing_3/test/Isosurfacing_3/test_marching_cubes.cpp @@ -49,16 +49,16 @@ void test_grid_sphere(const std::size_t n) { Sphere_function sphere_function; - Grid grid(n, n, n, bbox); + std::shared_ptr grid = std::make_shared(n, n, n, bbox); - for (std::size_t x = 0; x < grid.xdim(); x++) { - for (std::size_t y = 0; y < grid.ydim(); y++) { - for (std::size_t z = 0; z < grid.zdim(); z++) { + for (std::size_t x = 0; x < grid->xdim(); x++) { + for (std::size_t y = 0; y < grid->ydim(); y++) { + for (std::size_t z = 0; z < grid->zdim(); z++) { const Point pos(x * spacing.x() + bbox.xmin(), y * spacing.y() + bbox.ymin(), z * spacing.z() + bbox.zmin()); - grid.value(x, y, z) = sphere_function(pos); + grid->value(x, y, z) = sphere_function(pos); } } } diff --git a/Isosurfacing_3/test/Isosurfacing_3/test_util.h b/Isosurfacing_3/test/Isosurfacing_3/test_util.h index 2b89934b7ad..cf51ee06882 100644 --- a/Isosurfacing_3/test/Isosurfacing_3/test_util.h +++ b/Isosurfacing_3/test/Isosurfacing_3/test_util.h @@ -3,7 +3,8 @@ #include #include -#include +#include +#include #include #include #include