Minor API update for Cartesian_grid_3

This commit is contained in:
Mael Rouxel-Labbé 2024-02-24 22:25:27 +01:00
parent f6c22b9223
commit 4ca692378b
13 changed files with 37 additions and 44 deletions

View File

@ -171,7 +171,7 @@ struct Grid_sphere
Grid_sphere(const std::size_t N) Grid_sphere(const std::size_t N)
{ {
const CGAL::Bbox_3 bbox{-1., -1., -1., 1., 1., 1.}; const CGAL::Bbox_3 bbox{-1., -1., -1., 1., 1., 1.};
grid = Grid { bbox, N, N, N }; grid = Grid { bbox, CGAL::make_array<std::size_t>(N, N, N) };
values = { grid }; values = { grid };
gradients = { grid }; gradients = { grid };

View File

@ -46,7 +46,7 @@ int main(int argc, char** argv)
// create bounding box and grid // create bounding box and grid
const CGAL::Bbox_3 bbox = {-2., -2., -2., 2., 2., 2.}; const CGAL::Bbox_3 bbox = {-2., -2., -2., 2., 2., 2.};
Grid grid { bbox, 150, 150, 150 }; Grid grid { bbox, CGAL::make_array<std::size_t>(150, 150, 150) };
std::cout << "Bbox: " << grid.bbox() << std::endl; std::cout << "Bbox: " << grid.bbox() << std::endl;
std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl; std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl;

View File

@ -108,7 +108,7 @@ int main(int argc, char** argv)
// create bounding box and grid // create bounding box and grid
const CGAL::Bbox_3 bbox { -1., -1., -1., 1., 1., 1. }; const CGAL::Bbox_3 bbox { -1., -1., -1., 1., 1., 1. };
Grid grid { bbox, 30, 30, 30 }; Grid grid { bbox, CGAL::make_array<std::size_t>(30, 30, 30) };
std::cout << "Bbox: " << grid.bbox() << std::endl; std::cout << "Bbox: " << grid.bbox() << std::endl;
std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl; std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl;

View File

@ -96,7 +96,7 @@ int main(int argc, char* argv[])
// convert image to a Cartesian grid // convert image to a Cartesian grid
Grid 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)) if(!IS::IO::read_Image_3(image, grid, values))
{ {
std::cerr << "Error: Cannot convert image to Cartesian grid" << std::endl; std::cerr << "Error: Cannot convert image to Cartesian grid" << std::endl;

View File

@ -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.xmax(), bbox.ymax(), bbox.zmax()) + aabb_increase_vec).bbox();
bbox += (Point(bbox.xmin(), bbox.ymin(), bbox.zmin()) - aabb_increase_vec).bbox(); bbox += (Point(bbox.xmin(), bbox.ymin(), bbox.zmin()) - aabb_increase_vec).bbox();
const int n_voxels = 250; const int nv = 15;
Grid grid { bbox, n_voxels, n_voxels, n_voxels };
bbox = CGAL::Bbox_3{ -5, -5, -5, 15, 15, 15 };
Grid grid { bbox, CGAL::make_array<std::size_t>(nv, nv, nv) };
std::cout << "Bbox: " << grid.bbox() << std::endl; std::cout << "Bbox: " << grid.bbox() << std::endl;
std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl; std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl;

View File

@ -29,7 +29,7 @@ int main(int argc, char** argv)
// create bounding box and grid // create bounding box and grid
const CGAL::Bbox_3 bbox { -1., -1., -1., 1., 1., 1. }; const CGAL::Bbox_3 bbox { -1., -1., -1., 1., 1., 1. };
Grid grid { bbox, 30, 30, 30 }; Grid grid { bbox, CGAL::make_array<std::size_t>(30, 30, 30) };
std::cout << "Bbox: " << grid.bbox() << std::endl; std::cout << "Bbox: " << grid.bbox() << std::endl;
std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl; std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl;

View File

@ -47,7 +47,7 @@ int main(int argc, char** argv)
// create bounding box and grid // create bounding box and grid
const CGAL::Bbox_3 bbox = {-2., -2., -2., 2., 2., 2.}; const CGAL::Bbox_3 bbox = {-2., -2., -2., 2., 2., 2.};
Grid grid { bbox, 50, 50, 50 }; Grid grid { bbox, CGAL::make_array<std::size_t>(50, 50, 50) };
std::cout << "Bbox: " << grid.bbox() << std::endl; std::cout << "Bbox: " << grid.bbox() << std::endl;
std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl; std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl;

View File

@ -45,7 +45,7 @@ int main(int argc, char** argv)
// create bounding box and grid // create bounding box and grid
const CGAL::Bbox_3 bbox = {-2., -2., -2., 2., 2., 2.}; const CGAL::Bbox_3 bbox = {-2., -2., -2., 2., 2., 2.};
Grid grid { bbox, 50, 50, 50 }; Grid grid { bbox, CGAL::make_array<std::size_t>(50, 50, 50) };
std::cout << "Bbox: " << grid.bbox() << std::endl; std::cout << "Bbox: " << grid.bbox() << std::endl;
std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl; std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl;

View File

@ -27,7 +27,7 @@ int main(int argc, char** argv)
// create bounding box and grid // create bounding box and grid
const CGAL::Bbox_3 bbox { -1., -1., -1., 1., 1., 1. }; const CGAL::Bbox_3 bbox { -1., -1., -1., 1., 1., 1. };
Grid grid { bbox, 30, 30, 30 }; Grid grid { bbox, CGAL::make_array<std::size_t>(30, 30, 30) };
std::cout << "Bbox: " << grid.bbox() << std::endl; std::cout << "Bbox: " << grid.bbox() << std::endl;
std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl; std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl;

View File

@ -28,7 +28,7 @@ int main(int argc, char** argv)
// create bounding box and grid // create bounding box and grid
const CGAL::Bbox_3 bbox { -1., -1., -1., 1., 1., 1. }; const CGAL::Bbox_3 bbox { -1., -1., -1., 1., 1., 1. };
Grid grid { bbox, 30, 30, 30 }; Grid grid { bbox, CGAL::make_array<std::size_t>(30, 30, 30) };
std::cout << "Bbox: " << grid.bbox() << std::endl; std::cout << "Bbox: " << grid.bbox() << std::endl;
std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl; std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl;

View File

@ -85,7 +85,7 @@ public:
private: private:
Iso_cuboid_3 m_bbox; Iso_cuboid_3 m_bbox;
std::array<std::size_t, 3> m_sizes; std::array<std::size_t, 3> m_sizes;
std::array<FT, 3> m_spacing; Vector_3 m_spacing;
Geom_traits m_gt; Geom_traits m_gt;
@ -95,6 +95,7 @@ private:
auto x_coord = m_gt.compute_x_3_object(); auto x_coord = m_gt.compute_x_3_object();
auto y_coord = m_gt.compute_y_3_object(); auto y_coord = m_gt.compute_y_3_object();
auto z_coord = m_gt.compute_z_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(); auto vertex = m_gt.construct_vertex_3_object();
// calculate grid spacing // calculate grid spacing
@ -108,7 +109,7 @@ private:
const FT d_y = y_span / (m_sizes[1] - 1); const FT d_y = y_span / (m_sizes[1] - 1);
const FT d_z = z_span / (m_sizes[2] - 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: public:
@ -128,20 +129,16 @@ public:
* The grid covers the space described by a bounding box. * The grid covers the space described by a bounding box.
* *
* \param bbox the bounding box of the grid * \param bbox the bounding box of the grid
* \param xdim the number of grid vertices in the `x` direction * \param dimensions the number of grid vertices in the `x`, `y`, and `z` directions
* \param ydim the number of grid vertices in the `y` direction
* \param zdim the number of grid vertices in the `z` direction
* \param gt the geometric traits * \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, Cartesian_grid_3(const Iso_cuboid_3& bbox,
const std::size_t xdim, const std::array<std::size_t, 3>& dimensions,
const std::size_t ydim,
const std::size_t zdim,
const Geom_traits& gt = Geom_traits()) const Geom_traits& gt = Geom_traits())
: m_bbox{bbox}, : m_bbox{bbox},
m_sizes{xdim, ydim, zdim}, m_sizes{dimensions},
m_gt{gt} m_gt{gt}
{ {
compute_spacing(); compute_spacing();
@ -154,20 +151,16 @@ public:
* *
* \param p the lowest corner of the bounding box of the grid * \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 q the upper corner of the bounding box of the grid
* \param xdim the number of grid vertices in the `x` direction * \param dimensions the number of grid vertices in the `x`, `y`, and `z` directions
* \param ydim the number of grid vertices in the `y` direction
* \param zdim the number of grid vertices in the `z` direction
* \param gt the geometric traits * \param gt the geometric traits
* *
* \pre `p` is lexicographically (strictly) smaller than `q` * \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, Cartesian_grid_3(const Point_3& p, const Point_3& q,
const std::size_t xdim, const std::array<std::size_t, 3>& dimensions,
const std::size_t ydim,
const std::size_t zdim,
const Geom_traits& gt = Geom_traits()) 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` * \pre the diagonal of `bbox` has length a multiple of `spacing`
*/ */
Cartesian_grid_3(const Iso_cuboid_3& bbox, Cartesian_grid_3(const Iso_cuboid_3& bbox,
const std::array<FT, 3>& spacing, const Vector_3& spacing,
const Geom_traits& gt = Geom_traits()) const Geom_traits& gt = Geom_traits())
: m_bbox{bbox}, : m_bbox{bbox},
m_spacing{spacing}, m_spacing{spacing},
@ -218,7 +211,7 @@ public:
* \pre the diagonal of the bounding box has length a multiple of `spacing` * \pre the diagonal of the bounding box has length a multiple of `spacing`
*/ */
Cartesian_grid_3(const Point_3& p, const Point_3& q, Cartesian_grid_3(const Point_3& p, const Point_3& q,
const std::array<FT, 3>& spacing, const Vector_3& spacing,
const Geom_traits& gt = Geom_traits()) const Geom_traits& gt = Geom_traits())
: Cartesian_grid_3{Iso_cuboid_3{p, q}, spacing, gt} : 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 * 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 * the grid steps in the `x`, `y`, and `z` directions, respectively
*/ */
const std::array<FT, 3>& spacing() const { return m_spacing; } const Vector_3& spacing() const { return m_spacing; }
/** /**
* returns the number of grid vertices in the `x` direction * 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) 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(); compute_spacing();
} }
@ -309,7 +302,6 @@ public:
std::size_t j = (y_coord(p) - y_coord(min_p)) / m_spacing[1]; 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]; std::size_t k = (z_coord(p) - z_coord(min_p)) / m_spacing[2];
// @todo check this
if(i == xdim() - 1) if(i == xdim() - 1)
--i; --i;
if(j == ydim() - 1) if(j == ydim() - 1)

View File

@ -62,15 +62,14 @@ public:
// trilinear interpolation of stored values // trilinear interpolation of stored values
const Iso_cuboid_3& bbox = g.bbox(); const Iso_cuboid_3& bbox = g.bbox();
const std::array<FT, 3>& spacing = g.spacing(); const Vector_3& spacing = g.spacing();
// calculate min index including border case // calculate min index including border case
const Point_3& min_p = vertex(bbox, 0); const Point_3& min_p = vertex(bbox, 0);
std::size_t i = (x_coord(p) - x_coord(min_p)) / spacing[0]; 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)) / spacing[1]; 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)) / spacing[2]; std::size_t k = (z_coord(p) - z_coord(min_p)) / z_coord(spacing);
// @todo check this
if(i == g.xdim() - 1) if(i == g.xdim() - 1)
--i; --i;
if(j == g.ydim() - 1) if(j == g.ydim() - 1)
@ -134,13 +133,13 @@ public:
// trilinear interpolation of stored gradients // trilinear interpolation of stored gradients
const Iso_cuboid_3& bbox = g.bbox(); const Iso_cuboid_3& bbox = g.bbox();
const std::array<FT, 3>& spacing = g.spacing(); const Vector_3& spacing = g.spacing();
// calculate min index including border case // calculate min index including border case
const Point_3& min_p = vertex(bbox, 0); const Point_3& min_p = vertex(bbox, 0);
std::size_t i = static_cast<std::size_t>((x_coord(p) - x_coord(min_p)) / spacing[0]); std::size_t i = static_cast<std::size_t>((x_coord(p) - x_coord(min_p)) / x_coord(spacing));
std::size_t j = static_cast<std::size_t>((y_coord(p) - y_coord(min_p)) / spacing[1]); std::size_t j = static_cast<std::size_t>((y_coord(p) - y_coord(min_p)) / y_coord(spacing));
std::size_t k = static_cast<std::size_t>((z_coord(p) - z_coord(min_p)) / spacing[2]); std::size_t k = static_cast<std::size_t>((z_coord(p) - z_coord(min_p)) / z_coord(spacing));
if(i == g.xdim() - 1) // dim is the point number if(i == g.xdim() - 1) // dim is the point number
--i; --i;

View File

@ -60,7 +60,7 @@ void test_grid_sphere(const std::size_t n)
Sphere_function sphere_function; Sphere_function sphere_function;
Grid grid{n, n, n, bbox}; Grid grid { bbox, CGAL::make_array<std::size_t>(n, n, n) };
for(std::size_t x=0; x<grid.xdim(); ++x) { for(std::size_t x=0; x<grid.xdim(); ++x) {
for(std::size_t y=0; y<grid.ydim(); ++y) { for(std::size_t y=0; y<grid.ydim(); ++y) {