From 4ca692378bf4061e34ba7e9f6d86c718a12017f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Sat, 24 Feb 2024 22:25:27 +0100 Subject: [PATCH] Minor API update for Cartesian_grid_3 --- .../benchmark/Isosurfacing_3/benchmark.cpp | 2 +- .../contouring_seq_vs_parallel_implicit.cpp | 2 +- .../contouring_discrete_data.cpp | 2 +- .../Isosurfacing_3/contouring_image.cpp | 2 +- .../Isosurfacing_3/contouring_mesh_offset.cpp | 6 ++- .../Isosurfacing_3/dual_contouring.cpp | 2 +- .../dual_contouring_intersection_oracles.cpp | 2 +- .../dual_contouring_strategies.cpp | 2 +- .../Isosurfacing_3/marching_cubes.cpp | 2 +- .../marching_cubes_strategies.cpp | 2 +- .../CGAL/Isosurfacing_3/Cartesian_grid_3.h | 38 ++++++++----------- .../Isosurfacing_3/interpolation_schemes_3.h | 17 ++++----- .../Isosurfacing_3/test_marching_cubes.cpp | 2 +- 13 files changed, 37 insertions(+), 44 deletions(-) diff --git a/Isosurfacing_3/benchmark/Isosurfacing_3/benchmark.cpp b/Isosurfacing_3/benchmark/Isosurfacing_3/benchmark.cpp index 7c2dde3b3be..6486d275567 100644 --- a/Isosurfacing_3/benchmark/Isosurfacing_3/benchmark.cpp +++ b/Isosurfacing_3/benchmark/Isosurfacing_3/benchmark.cpp @@ -171,7 +171,7 @@ struct Grid_sphere Grid_sphere(const std::size_t N) { const CGAL::Bbox_3 bbox{-1., -1., -1., 1., 1., 1.}; - grid = Grid { bbox, N, N, N }; + grid = Grid { bbox, CGAL::make_array(N, N, N) }; values = { grid }; gradients = { grid }; diff --git a/Isosurfacing_3/benchmark/Isosurfacing_3/contouring_seq_vs_parallel_implicit.cpp b/Isosurfacing_3/benchmark/Isosurfacing_3/contouring_seq_vs_parallel_implicit.cpp index 956e38c60e2..bfbf434f200 100644 --- a/Isosurfacing_3/benchmark/Isosurfacing_3/contouring_seq_vs_parallel_implicit.cpp +++ b/Isosurfacing_3/benchmark/Isosurfacing_3/contouring_seq_vs_parallel_implicit.cpp @@ -46,7 +46,7 @@ int main(int argc, char** argv) // create bounding box and grid const CGAL::Bbox_3 bbox = {-2., -2., -2., 2., 2., 2.}; - Grid grid { bbox, 150, 150, 150 }; + Grid grid { bbox, CGAL::make_array(150, 150, 150) }; std::cout << "Bbox: " << grid.bbox() << std::endl; std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl; diff --git a/Isosurfacing_3/examples/Isosurfacing_3/contouring_discrete_data.cpp b/Isosurfacing_3/examples/Isosurfacing_3/contouring_discrete_data.cpp index 12d282288f8..f82908631da 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/contouring_discrete_data.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/contouring_discrete_data.cpp @@ -108,7 +108,7 @@ int main(int argc, char** argv) // create bounding box and grid const CGAL::Bbox_3 bbox { -1., -1., -1., 1., 1., 1. }; - Grid grid { bbox, 30, 30, 30 }; + Grid grid { bbox, CGAL::make_array(30, 30, 30) }; std::cout << "Bbox: " << grid.bbox() << std::endl; std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl; diff --git a/Isosurfacing_3/examples/Isosurfacing_3/contouring_image.cpp b/Isosurfacing_3/examples/Isosurfacing_3/contouring_image.cpp index 707c6061070..255483cb175 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/contouring_image.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/contouring_image.cpp @@ -96,7 +96,7 @@ int main(int argc, char* argv[]) // convert image to a Cartesian grid Grid grid; - Values values { grid }; + Values values { grid }; // 'values' keeps a reference to the grid if(!IS::IO::read_Image_3(image, grid, values)) { std::cerr << "Error: Cannot convert image to Cartesian grid" << std::endl; diff --git a/Isosurfacing_3/examples/Isosurfacing_3/contouring_mesh_offset.cpp b/Isosurfacing_3/examples/Isosurfacing_3/contouring_mesh_offset.cpp index 028030fa09b..e809d018e19 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/contouring_mesh_offset.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/contouring_mesh_offset.cpp @@ -156,8 +156,10 @@ int main(int argc, char** argv) bbox += (Point(bbox.xmax(), bbox.ymax(), bbox.zmax()) + aabb_increase_vec).bbox(); bbox += (Point(bbox.xmin(), bbox.ymin(), bbox.zmin()) - aabb_increase_vec).bbox(); - const int n_voxels = 250; - Grid grid { bbox, n_voxels, n_voxels, n_voxels }; + const int nv = 15; + + bbox = CGAL::Bbox_3{ -5, -5, -5, 15, 15, 15 }; + Grid grid { bbox, CGAL::make_array(nv, nv, nv) }; std::cout << "Bbox: " << grid.bbox() << std::endl; std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl; diff --git a/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring.cpp b/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring.cpp index 3823714069e..beda605d61b 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring.cpp @@ -29,7 +29,7 @@ int main(int argc, char** argv) // create bounding box and grid const CGAL::Bbox_3 bbox { -1., -1., -1., 1., 1., 1. }; - Grid grid { bbox, 30, 30, 30 }; + Grid grid { bbox, CGAL::make_array(30, 30, 30) }; std::cout << "Bbox: " << grid.bbox() << std::endl; std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl; diff --git a/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_intersection_oracles.cpp b/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_intersection_oracles.cpp index 68e56894907..c4fff6c84d5 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_intersection_oracles.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_intersection_oracles.cpp @@ -47,7 +47,7 @@ int main(int argc, char** argv) // create bounding box and grid const CGAL::Bbox_3 bbox = {-2., -2., -2., 2., 2., 2.}; - Grid grid { bbox, 50, 50, 50 }; + Grid grid { bbox, CGAL::make_array(50, 50, 50) }; std::cout << "Bbox: " << grid.bbox() << std::endl; std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl; diff --git a/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_strategies.cpp b/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_strategies.cpp index 4c8a355ea20..5976caac6fc 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_strategies.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_strategies.cpp @@ -45,7 +45,7 @@ int main(int argc, char** argv) // create bounding box and grid const CGAL::Bbox_3 bbox = {-2., -2., -2., 2., 2., 2.}; - Grid grid { bbox, 50, 50, 50 }; + Grid grid { bbox, CGAL::make_array(50, 50, 50) }; std::cout << "Bbox: " << grid.bbox() << std::endl; std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl; diff --git a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes.cpp b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes.cpp index a5e3fb38bb9..81a37513162 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes.cpp @@ -27,7 +27,7 @@ int main(int argc, char** argv) // create bounding box and grid const CGAL::Bbox_3 bbox { -1., -1., -1., 1., 1., 1. }; - Grid grid { bbox, 30, 30, 30 }; + Grid grid { bbox, CGAL::make_array(30, 30, 30) }; std::cout << "Bbox: " << grid.bbox() << std::endl; std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl; diff --git a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_strategies.cpp b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_strategies.cpp index 7cfd37cbd12..3c879121acc 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_strategies.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_strategies.cpp @@ -28,7 +28,7 @@ int main(int argc, char** argv) // create bounding box and grid const CGAL::Bbox_3 bbox { -1., -1., -1., 1., 1., 1. }; - Grid grid { bbox, 30, 30, 30 }; + Grid grid { bbox, CGAL::make_array(30, 30, 30) }; std::cout << "Bbox: " << grid.bbox() << std::endl; std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl; diff --git a/Isosurfacing_3/include/CGAL/Isosurfacing_3/Cartesian_grid_3.h b/Isosurfacing_3/include/CGAL/Isosurfacing_3/Cartesian_grid_3.h index 40358046a42..36c24e49a9b 100644 --- a/Isosurfacing_3/include/CGAL/Isosurfacing_3/Cartesian_grid_3.h +++ b/Isosurfacing_3/include/CGAL/Isosurfacing_3/Cartesian_grid_3.h @@ -85,7 +85,7 @@ public: private: Iso_cuboid_3 m_bbox; std::array m_sizes; - std::array m_spacing; + Vector_3 m_spacing; Geom_traits m_gt; @@ -95,6 +95,7 @@ private: auto x_coord = m_gt.compute_x_3_object(); auto y_coord = m_gt.compute_y_3_object(); auto z_coord = m_gt.compute_z_3_object(); + auto vector = m_gt.construct_vector_3_object(); auto vertex = m_gt.construct_vertex_3_object(); // calculate grid spacing @@ -108,7 +109,7 @@ private: const FT d_y = y_span / (m_sizes[1] - 1); const FT d_z = z_span / (m_sizes[2] - 1); - m_spacing = make_array(d_x, d_y, d_z); + m_spacing = vector(d_x, d_y, d_z); } public: @@ -128,20 +129,16 @@ public: * The grid covers the space described by a bounding box. * * \param bbox the bounding box of the grid - * \param xdim the number of grid vertices in the `x` direction - * \param ydim the number of grid vertices in the `y` direction - * \param zdim the number of grid vertices in the `z` direction + * \param dimensions the number of grid vertices in the `x`, `y`, and `z` directions * \param gt the geometric traits * - * \pre `xdim`, `ydim`, and `zdim` are (strictly) positive. + * \pre all dimensions are (strictly) positive. */ Cartesian_grid_3(const Iso_cuboid_3& bbox, - const std::size_t xdim, - const std::size_t ydim, - const std::size_t zdim, + const std::array& dimensions, const Geom_traits& gt = Geom_traits()) : m_bbox{bbox}, - m_sizes{xdim, ydim, zdim}, + m_sizes{dimensions}, m_gt{gt} { compute_spacing(); @@ -154,20 +151,16 @@ public: * * \param p the lowest corner of the bounding box of the grid * \param q the upper corner of the bounding box of the grid - * \param xdim the number of grid vertices in the `x` direction - * \param ydim the number of grid vertices in the `y` direction - * \param zdim the number of grid vertices in the `z` direction + * \param dimensions the number of grid vertices in the `x`, `y`, and `z` directions * \param gt the geometric traits * * \pre `p` is lexicographically (strictly) smaller than `q` - * \pre `xdim`, `ydim`, and `zdim` are (strictly) positive. + * \pre all dimensions are (strictly) positive. */ Cartesian_grid_3(const Point_3& p, const Point_3& q, - const std::size_t xdim, - const std::size_t ydim, - const std::size_t zdim, + const std::array& dimensions, const Geom_traits& gt = Geom_traits()) - : Cartesian_grid_3{Iso_cuboid_3{p, q}, xdim, ydim, zdim, gt} + : Cartesian_grid_3{Iso_cuboid_3{p, q}, dimensions, gt} { } /** @@ -182,7 +175,7 @@ public: * \pre the diagonal of `bbox` has length a multiple of `spacing` */ Cartesian_grid_3(const Iso_cuboid_3& bbox, - const std::array& spacing, + const Vector_3& spacing, const Geom_traits& gt = Geom_traits()) : m_bbox{bbox}, m_spacing{spacing}, @@ -218,7 +211,7 @@ public: * \pre the diagonal of the bounding box has length a multiple of `spacing` */ Cartesian_grid_3(const Point_3& p, const Point_3& q, - const std::array& spacing, + const Vector_3& spacing, const Geom_traits& gt = Geom_traits()) : Cartesian_grid_3{Iso_cuboid_3{p, q}, spacing, gt} { } @@ -250,7 +243,7 @@ public: * returns the spacing of the %Cartesian grid, that is a vector whose coordinates are * the grid steps in the `x`, `y`, and `z` directions, respectively */ - const std::array& spacing() const { return m_spacing; } + const Vector_3& spacing() const { return m_spacing; } /** * returns the number of grid vertices in the `x` direction @@ -273,7 +266,7 @@ public: */ void set_sizes(const std::size_t xdim, const std::size_t ydim, const std::size_t zdim) { - m_sizes = {xdim, ydim, zdim}; + m_sizes = { xdim, ydim, zdim }; compute_spacing(); } @@ -309,7 +302,6 @@ public: std::size_t j = (y_coord(p) - y_coord(min_p)) / m_spacing[1]; std::size_t k = (z_coord(p) - z_coord(min_p)) / m_spacing[2]; - // @todo check this if(i == xdim() - 1) --i; if(j == ydim() - 1) diff --git a/Isosurfacing_3/include/CGAL/Isosurfacing_3/interpolation_schemes_3.h b/Isosurfacing_3/include/CGAL/Isosurfacing_3/interpolation_schemes_3.h index e8278999bc3..61220502312 100644 --- a/Isosurfacing_3/include/CGAL/Isosurfacing_3/interpolation_schemes_3.h +++ b/Isosurfacing_3/include/CGAL/Isosurfacing_3/interpolation_schemes_3.h @@ -62,15 +62,14 @@ public: // trilinear interpolation of stored values const Iso_cuboid_3& bbox = g.bbox(); - const std::array& spacing = g.spacing(); + const Vector_3& spacing = g.spacing(); // calculate min index including border case const Point_3& min_p = vertex(bbox, 0); - std::size_t i = (x_coord(p) - x_coord(min_p)) / spacing[0]; - std::size_t j = (y_coord(p) - y_coord(min_p)) / spacing[1]; - std::size_t k = (z_coord(p) - z_coord(min_p)) / spacing[2]; + std::size_t i = (x_coord(p) - x_coord(min_p)) / x_coord(spacing); + std::size_t j = (y_coord(p) - y_coord(min_p)) / y_coord(spacing); + std::size_t k = (z_coord(p) - z_coord(min_p)) / z_coord(spacing); - // @todo check this if(i == g.xdim() - 1) --i; if(j == g.ydim() - 1) @@ -134,13 +133,13 @@ public: // trilinear interpolation of stored gradients const Iso_cuboid_3& bbox = g.bbox(); - const std::array& spacing = g.spacing(); + const Vector_3& spacing = g.spacing(); // calculate min index including border case const Point_3& min_p = vertex(bbox, 0); - std::size_t i = static_cast((x_coord(p) - x_coord(min_p)) / spacing[0]); - std::size_t j = static_cast((y_coord(p) - y_coord(min_p)) / spacing[1]); - std::size_t k = static_cast((z_coord(p) - z_coord(min_p)) / spacing[2]); + std::size_t i = static_cast((x_coord(p) - x_coord(min_p)) / x_coord(spacing)); + std::size_t j = static_cast((y_coord(p) - y_coord(min_p)) / y_coord(spacing)); + std::size_t k = static_cast((z_coord(p) - z_coord(min_p)) / z_coord(spacing)); if(i == g.xdim() - 1) // dim is the point number --i; diff --git a/Isosurfacing_3/test/Isosurfacing_3/test_marching_cubes.cpp b/Isosurfacing_3/test/Isosurfacing_3/test_marching_cubes.cpp index ce1ec43165a..8eee7d859f8 100644 --- a/Isosurfacing_3/test/Isosurfacing_3/test_marching_cubes.cpp +++ b/Isosurfacing_3/test/Isosurfacing_3/test_marching_cubes.cpp @@ -60,7 +60,7 @@ void test_grid_sphere(const std::size_t n) Sphere_function sphere_function; - Grid grid{n, n, n, bbox}; + Grid grid { bbox, CGAL::make_array(n, n, n) }; for(std::size_t x=0; x