Few more minor changes to examples

This commit is contained in:
Pierre Alliez 2023-12-25 18:46:33 +01:00
parent d83fcf752c
commit d2c94538ae
3 changed files with 15 additions and 12 deletions

View File

@ -17,7 +17,7 @@ using Grid = CGAL::Isosurfacing::Cartesian_grid_3<Kernel>;
using Point_range = std::vector<Point>;
using Polygon_range = std::vector<std::vector<std::size_t> >;
// return 1.0 if `value` has positive sign, and -1.0 otherwise
// return 1.0 if value has positive sign, and -1.0 otherwise
FT sign(FT value)
{
return (value > 0.0) - (value < 0.0);
@ -30,9 +30,9 @@ int main(int, char**)
Grid 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.spacing()[0] + bbox.xmin();
const FT pos_y = y * grid.spacing()[1] + bbox.ymin();
@ -48,11 +48,11 @@ int main(int, char**)
auto cube_gradient = [](const Point& p)
{
// the normal depends on the side of the cube
const FT max_value = (std::max)({std::abs(p.x()), std::abs(p.y()), std::abs(p.z())});
const FT max_value = std::max({ std::abs(p.x()), std::abs(p.y()), std::abs(p.z())});
Vector g(0.0, 0.0, 0.0);
if(max_value == std::abs(p.x()))
g += Vector(sign(p.x()), 0.0, 0.);
g += Vector(sign(p.x()), 0.0, 0.0);
if(max_value == std::abs(p.y()))
g += Vector(0.0, sign(p.y()), 0.0);
@ -80,8 +80,8 @@ int main(int, char**)
CGAL::Isosurfacing::dual_contouring(domain, isovalue, points_dc, polygons_dc);
// save output indexed meshes to files, in the OFF format
CGAL::IO::write_OFF("result_mc.off", points_mc, polygons_mc);
CGAL::IO::write_OFF("result_dc.off", points_dc, polygons_dc);
CGAL::IO::write_OFF("output_mc.off", points_mc, polygons_mc);
CGAL::IO::write_OFF("output_dc.off", points_dc, polygons_dc);
return EXIT_SUCCESS;
}

View File

@ -24,9 +24,9 @@ int main(int, char**)
Grid grid { 30, 30, 30, bbox };
// compute field values and gradients
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.spacing()[0] + bbox.xmin();
const FT pos_y = y * grid.spacing()[1] + bbox.ymin();
@ -54,7 +54,7 @@ int main(int, char**)
CGAL::Isosurfacing::dual_contouring(domain, 0.8, points, polygons);
// write output indexed surface mesh to file, in OFF format
CGAL::IO::write_OFF("result.off", points, polygons);
CGAL::IO::write_OFF("output.off", points, polygons);
return EXIT_SUCCESS;
}

View File

@ -40,6 +40,7 @@ inline Kernel::FT distance_to_mesh(const Tree& tree,
return std::sqrt((p - x).squared_length());
}
// Usage : marching_cubes_multiple_mesh_offsets input.off
int main(int argc, char **argv)
{
const std::string input_name(argv[1]);
@ -92,6 +93,8 @@ int main(int argc, char **argv)
// create domain from the grid
auto domain = CGAL::Isosurfacing::create_explicit_Cartesian_grid_domain(grid);
// run Marching cubes with a range of offsets,
// and save all output meshes to files "output-index.off"
int index = 0;
for(FT offset = 0.0; offset < 0.3; offset += 0.01, index++)
{