Use shared_ptr from user and fix compile errors

This commit is contained in:
Julian Stahl 2022-11-11 22:06:21 +01:00
parent 777a39c65a
commit 5a31df49de
14 changed files with 96 additions and 85 deletions

View File

@ -3,7 +3,8 @@
#include <CGAL/Default_gradients.h>
#include <CGAL/Dual_contouring_3.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Isosurfacing_domains.h>
#include <CGAL/Explicit_cartesian_grid_domain.h>
#include <CGAL/Implicit_cartesian_grid_domain.h>
#include <CGAL/Marching_cubes_3.h>
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>
#include <CGAL/Simple_cartesian.h>
@ -39,8 +40,8 @@ struct SphereGradient {
template <class GeomTraits>
struct Implicit_sphere {
typedef CGAL::Isosurfacing::Implicit_cartesian_grid_domain_with_gradient<GeomTraits, SphereValue<GeomTraits>,
SphereGradient<GeomTraits>>
typedef CGAL::Isosurfacing::Implicit_cartesian_grid_domain<GeomTraits, SphereValue<GeomTraits>,
SphereGradient<GeomTraits>>
Domain;
typedef typename GeomTraits::Vector_3 Vector;
@ -97,8 +98,8 @@ struct IWPGradient {
template <class GeomTraits>
struct Implicit_iwp {
typedef CGAL::Isosurfacing::Implicit_cartesian_grid_domain_with_gradient<GeomTraits, IWPValue<GeomTraits>,
IWPGradient<GeomTraits>>
typedef CGAL::Isosurfacing::Implicit_cartesian_grid_domain<GeomTraits, IWPValue<GeomTraits>,
IWPGradient<GeomTraits>>
Domain;
typedef typename GeomTraits::Vector_3 Vector;
@ -123,27 +124,30 @@ template <class GeomTraits>
struct Grid_sphere {
typedef CGAL::Isosurfacing::Explicit_cartesian_grid_gradient<GeomTraits> Gradient;
typedef CGAL::Isosurfacing::Explicit_cartesian_grid_domain_with_gradient<GeomTraits, Gradient> Domain;
typedef CGAL::Isosurfacing::Explicit_cartesian_grid_domain<GeomTraits, Gradient> Domain;
typedef CGAL::Cartesian_grid_3<GeomTraits> 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<Grid>(N, N, N, bbox);
const FT resolution = 2.0 / N;
SphereValue<GeomTraits> val;
SphereGradient<GeomTraits> 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> grid;
};
template <class GeomTraits>
struct Skull_image {
typedef CGAL::Isosurfacing::Explicit_cartesian_grid_gradient<GeomTraits> Gradient;
typedef CGAL::Isosurfacing::Explicit_cartesian_grid_domain_with_gradient<GeomTraits, Gradient> Domain;
typedef CGAL::Isosurfacing::Explicit_cartesian_grid_domain<GeomTraits, Gradient> Domain;
typedef CGAL::Cartesian_grid_3<GeomTraits> 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<Grid>(image);
}
Domain domain() const {
@ -187,7 +191,7 @@ struct Skull_image {
}
private:
Grid grid;
std::shared_ptr<Grid> grid;
};
int main(int argc, char* argv[]) {

View File

@ -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> grid = std::make_shared<Grid>(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)});
}
}
}

View File

@ -17,21 +17,22 @@ typedef std::vector<std::vector<std::size_t>> 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> grid = std::make_shared<Grid>(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;
}
}
}

View File

@ -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_wrapper_> octree_wrap = std::make_shared<Octree_wrapper_>(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()); };

View File

@ -16,19 +16,20 @@ typedef std::vector<std::vector<std::size_t>> 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> grid = std::make_shared<Grid>(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);
}
}
}

View File

@ -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<Kernel>(bbox, spacing, std::move(sphere_function));
auto domain =
CGAL::Isosurfacing::create_implicit_cartesian_grid_domain<Kernel>(bbox, spacing, std::move(sphere_function));
// prepare collections for the result
Point_range points;

View File

@ -24,7 +24,7 @@ int main() {
}
// convert it to a cartesian grid
const Grid grid(image);
std::shared_ptr<Grid> grid = std::make_shared<Grid>(image);
// create a domain from the grid
auto domain = CGAL::Isosurfacing::create_explicit_cartesian_grid_domain<Kernel>(grid);

View File

@ -58,24 +58,24 @@ int main() {
CGAL::Side_of_triangle_mesh<Mesh, CGAL::GetGeomTraits<Mesh>::type> sotm(mesh_input);
// create the grid
Grid grid(n_voxels, n_voxels, n_voxels, aabb_grid);
std::shared_ptr<Grid> grid = std::make_shared<Grid>(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;
}
}
}

View File

@ -32,7 +32,7 @@ public:
}
};
template <class GeomTraits, typename Function>
template <class GeomTraits, typename PointFunction>
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<Geom_traits> Grid;
typedef std::shared_ptr<Cartesian_grid_3<Geom_traits>> 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

View File

@ -28,7 +28,7 @@ using Explicit_cartesian_grid_domain = Base_domain<GeomTraits, Grid_topology, Ca
template <class GeomTraits, typename Gradient_ = Zero_gradient<GeomTraits>>
Explicit_cartesian_grid_domain<GeomTraits, Gradient_> create_explicit_cartesian_grid_domain(
const Cartesian_grid_3<GeomTraits>& grid, const Gradient_& gradient = Gradient_()) {
const std::shared_ptr<Cartesian_grid_3<GeomTraits>> grid, const Gradient_& gradient = Gradient_()) {
typedef Explicit_cartesian_grid_domain<GeomTraits, Gradient_> Domain;
typedef typename Domain::Topology Topology;
@ -36,17 +36,17 @@ Explicit_cartesian_grid_domain<GeomTraits, Gradient_> 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<Topology::element_type>(size_i, size_j, size_k);
const Geometry geom = std::make_shared<Geometry::element_type>(offset, spacing);
const Function func = std::make_shared<Function::element_type>(grid);
const Function func = grid;
const Gradient grad = std::make_shared<Gradient::element_type>(gradient);
return Domain(topo, geom, func, grad);

View File

@ -31,7 +31,7 @@ using Implicit_octree_domain =
template <class GeomTraits, typename PointFunction, typename Gradient_ = Zero_gradient<GeomTraits>>
Implicit_octree_domain<GeomTraits, PointFunction, Gradient_> create_implicit_octree_domain(
const Octree_wrapper<GeomTraits>& octree, const PointFunction& point_function,
const std::shared_ptr<Octree_wrapper<GeomTraits>> octree, const PointFunction& point_function,
const Gradient_& gradient = Gradient_()) {
typedef Implicit_octree_domain<GeomTraits, PointFunction, Gradient_> Domain;
@ -42,7 +42,7 @@ Implicit_octree_domain<GeomTraits, PointFunction, Gradient_> 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::element_type>(octree);
const Octree oct = octree;
const Topology topo = std::make_shared<Topology::element_type>(oct);
const Geometry geom = std::make_shared<Geometry::element_type>(oct);
const Point_function point_func = std::make_shared<Point_function::element_type>(point_function);

View File

@ -1,6 +1,7 @@
#include <CGAL/Cartesian_grid_3.h>
#include <CGAL/Dual_contouring_3.h>
#include <CGAL/Isosurfacing_domains.h>
#include <CGAL/Explicit_cartesian_grid_domain.h>
#include <CGAL/Implicit_cartesian_grid_domain.h>
#include <CGAL/Marching_cubes_3.h>
#include <CGAL/Octree_wrapper.h>
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>
@ -37,16 +38,16 @@ int main() {
const std::size_t ny = static_cast<std::size_t>(2.0 / spacing.y());
const std::size_t nz = static_cast<std::size_t>(2.0 / spacing.z());
Grid grid(nx, ny, nz, bbox);
std::shared_ptr<Grid> grid = std::make_shared<Grid>(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);
}
}
}

View File

@ -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> grid = std::make_shared<Grid>(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);
}
}
}

View File

@ -3,7 +3,8 @@
#include <CGAL/Cartesian_grid_3.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Isosurfacing_domains.h>
#include <CGAL/Explicit_cartesian_grid_domain.h>
#include <CGAL/Implicit_cartesian_grid_domain.h>
#include <CGAL/Polygon_mesh_processing/distance.h>
#include <CGAL/Polygon_mesh_processing/manifoldness.h>
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>