diff --git a/Isosurfacing_3/examples/Isosurfacing_3/all_cartesian_cube.cpp b/Isosurfacing_3/examples/Isosurfacing_3/all_cartesian_cube.cpp index 2dfa0406842..86d686fc117 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/all_cartesian_cube.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/all_cartesian_cube.cpp @@ -2,12 +2,10 @@ #include #include #include -#include #include +#include #include -#include - typedef CGAL::Simple_cartesian Kernel; typedef typename Kernel::FT FT; typedef typename Kernel::Point_3 Point; @@ -15,8 +13,8 @@ typedef typename Kernel::Vector_3 Vector; typedef CGAL::Cartesian_grid_3 Grid; -typedef tbb::concurrent_vector Point_range; -typedef tbb::concurrent_vector> Polygon_range; +typedef std::vector Point_range; +typedef std::vector> Polygon_range; FT sign(FT value) { return (value > 0) - (value < 0); @@ -24,7 +22,7 @@ FT sign(FT value) { int main() { // create a cartesian grid with 100^3 grid points and the bounding box [-1, 1]^3 - Grid grid(100, 100, 100, {-1, -1, -1, 1, 1, 1}); + Grid grid(7, 7, 7, {-1, -1, -1, 1, 1, 1}); // calculate the value at all grid points for (std::size_t x = 0; x < grid.xdim(); x++) { @@ -37,28 +35,33 @@ int main() { // manhattan distance to the origin grid.value(x, y, z) = std::max({std::abs(pos_x), std::abs(pos_y), std::abs(pos_z)}); - - // the normal depends on the side of the cube - grid.gradient(x, y, z) = Vector(0, 0, 0); - if (grid.value(x, y, z) == std::abs(pos_x)) { - grid.gradient(x, y, z) += Vector(sign(pos_x), 0, 0); - } - if (grid.value(x, y, z) == std::abs(pos_y)) { - grid.gradient(x, y, z) += Vector(0, sign(pos_y), 0); - } - if (grid.value(x, y, z) == std::abs(pos_z)) { - grid.gradient(x, y, z) += Vector(0, 0, sign(pos_z)); - } - const FT length_sq = grid.gradient(x, y, z).squared_length(); - if (length_sq > 0.00001) { - grid.gradient(x, y, z) /= CGAL::approximate_sqrt(length_sq); - } } } } + 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())}); + + Vector g(0, 0, 0); + if (max_value == std::abs(p.x())) { + g += Vector(sign(p.x()), 0, 0); + } + if (max_value == std::abs(p.y())) { + g += Vector(0, sign(p.y()), 0); + } + if (max_value == std::abs(p.z())) { + g += Vector(0, 0, sign(p.z())); + } + const FT length_sq = g.squared_length(); + if (length_sq > 0.00001) { + g /= CGAL::approximate_sqrt(length_sq); + } + return g; + }; + // create a domain from the grid - CGAL::Isosurfacing::Cartesian_grid_domain domain(grid); + CGAL::Isosurfacing::Cartesian_grid_domain domain(grid, cube_gradient); // prepare collections for the results Point_range points_mc, points_tmc, points_dc; @@ -66,7 +69,7 @@ int main() { // execute marching cubes, topologically correct marching cubes and dual contouring with an isovalue of 0.8 CGAL::Isosurfacing::make_triangle_mesh_using_marching_cubes(domain, 0.88, points_mc, polygons_mc); - //CGAL::Isosurfacing::make_triangle_mesh_using_tmc(domain, 0.88, points_tmc, polygons_tmc); + CGAL::Isosurfacing::make_triangle_mesh_using_tmc(domain, 0.88, points_tmc, polygons_tmc); CGAL::Isosurfacing::make_quad_mesh_using_dual_contouring(domain, 0.88, points_dc, polygons_dc); // save the results in the OFF format diff --git a/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_implicit_iwp.cpp b/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_implicit_iwp.cpp index 7bd920943be..450efcce412 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_implicit_iwp.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_implicit_iwp.cpp @@ -2,15 +2,14 @@ #include #include #include -#include typedef CGAL::Simple_cartesian Kernel; typedef typename Kernel::FT FT; typedef typename Kernel::Vector_3 Vector; typedef typename Kernel::Point_3 Point; -typedef tbb::concurrent_vector Point_range; -typedef tbb::concurrent_vector> Polygon_range; +typedef std::vector Point_range; +typedef std::vector> Polygon_range; #ifndef M_PI #define M_PI 3.141592653589793238462643383279502884L diff --git a/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_mesh_offset.cpp b/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_mesh_offset.cpp index b5d838f3a69..c976a4c6c12 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_mesh_offset.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_mesh_offset.cpp @@ -1,9 +1,8 @@ #include #include #include -#include -#include #include +#include #include #include #include @@ -16,8 +15,6 @@ typedef typename Kernel::FT FT; typedef typename Kernel::Point_3 Point; typedef typename Kernel::Vector_3 Vector; -typedef CGAL::Cartesian_grid_3 Grid; - typedef CGAL::Surface_mesh Mesh; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; @@ -27,14 +24,9 @@ typedef CGAL::AABB_tree Tree; typedef std::vector Point_range; typedef std::vector> Polygon_range; -inline Kernel::FT distance_to_mesh(const Tree& tree, const Point& p) { - const Point& x = tree.closest_point(p); - return std::sqrt((p - x).squared_length()); -} - int main() { - const std::string input_name = "../data/bunny.off"; - const int n_voxels = 20; + const std::string input_name = "../../../data/bunny.off"; + const Vector grid_spacing(0.005, 0.005, 0.005); const FT offset_value = 0.01; Mesh mesh_input; @@ -54,30 +46,21 @@ int main() { CGAL::Side_of_triangle_mesh::type> sotm(mesh_input); - Grid grid(n_voxels, n_voxels, n_voxels, aabb_grid); - CGAL::Isosurfacing::Cartesian_grid_domain domain(grid); + auto mesh_distance = [&tree](const Point& p) { + const Point& x = tree.closest_point(p); + return std::sqrt((p - x).squared_length()); + }; - 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++) { + auto mesh_normal = [&tree](const Point& p) { + const Point& x = tree.closest_point(p); + const Vector n = p - x; + return n / std::sqrt(n.squared_length()); + }; - 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); - - grid.value(x, y, z) = distance_to_mesh(tree, p); - - // const bool is_inside = (sotm(p) == CGAL::ON_BOUNDED_SIDE); - // if (is_inside) { - // grid.value(x, y, z) *= -1; - //} - - // TODO: mormals - } - } - } + // create a domain with bounding box [-1, 1]^3 and grid spacing 0.02 + CGAL::Isosurfacing::Implicit_domain domain( + aabb_grid, grid_spacing, mesh_distance, mesh_normal); Point_range points; Polygon_range polygons; diff --git a/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_octree.cpp b/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_octree.cpp index 0244ecdeb82..6220f58e044 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_octree.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_octree.cpp @@ -32,7 +32,7 @@ struct Refine_one_eighth { auto coords = node.global_coordinates(); const std::size_t depth_factor = std::size_t(1) << (max_depth_ - node.depth()); for (int i = 0; i < Octree_wrapper_::Octree::Node::Dimension::value; ++i) { - coords[i] *= (uint32_t) depth_factor; + coords[i] *= (uint32_t)depth_factor; } return coords; 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 308b1c3dd3b..897f7ce458c 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 @@ -5,16 +5,14 @@ #include #include -#include - typedef CGAL::Simple_cartesian Kernel; typedef typename Kernel::FT FT; typedef typename Kernel::Point_3 Point; typedef CGAL::Cartesian_grid_3 Grid; -typedef tbb::concurrent_vector Point_range; -typedef tbb::concurrent_vector> Polygon_range; +typedef std::vector Point_range; +typedef std::vector> Polygon_range; int main() { // create a cartesian grid with 100^3 grid points and the bounding box [-1, 1]^3 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 3b43e209f97..7b53dae8ab1 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_implicit_sphere.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_implicit_sphere.cpp @@ -3,14 +3,13 @@ #include #include #include -#include typedef CGAL::Simple_cartesian Kernel; typedef typename Kernel::Vector_3 Vector; typedef typename Kernel::Point_3 Point; -typedef tbb::concurrent_vector Point_range; -typedef tbb::concurrent_vector> Polygon_range; +typedef std::vector Point_range; +typedef std::vector> Polygon_range; int main() { // distance to the origin diff --git a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_inrimage.cpp b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_inrimage.cpp index eeab2095b46..917dd62534a 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_inrimage.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_inrimage.cpp @@ -1,19 +1,16 @@ #include #include -#include +#include #include #include -#include - typedef CGAL::Simple_cartesian Kernel; -typedef typename Kernel::FT FT; typedef typename Kernel::Point_3 Point; typedef CGAL::Cartesian_grid_3 Grid; -typedef tbb::concurrent_vector Point_range; -typedef tbb::concurrent_vector> Polygon_range; +typedef std::vector Point_range; +typedef std::vector> Polygon_range; int main() { @@ -37,7 +34,7 @@ int main() { Polygon_range polygons; // execute marching cubes with an isovalue of 2.9 - CGAL::Isosurfacing::make_quad_mesh_using_dual_contouring(domain, 2.9, points, polygons); + CGAL::Isosurfacing::make_triangle_mesh_using_marching_cubes(domain, 2.9, points, polygons); // save the result in the OFF format CGAL::IO::write_OFF("result.off", points, polygons); 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 4955825aa6f..e782337e111 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_mesh_offset.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_mesh_offset.cpp @@ -9,8 +9,6 @@ #include #include -#include - #include typedef CGAL::Simple_cartesian Kernel; @@ -26,8 +24,8 @@ typedef CGAL::AABB_face_graph_triangle_primitive Primitive; typedef CGAL::AABB_traits Traits; typedef CGAL::AABB_tree Tree; -typedef tbb::concurrent_vector Point_range; -typedef tbb::concurrent_vector> Polygon_range; +typedef std::vector Point_range; +typedef std::vector> Polygon_range; // computes the distance of a point p from the mesh with the use of a AABB_tree @@ -37,9 +35,9 @@ inline Kernel::FT distance_to_mesh(const Tree& tree, const Point& p) { } int main() { - const std::string input_name = "../data/bunny.off"; + const std::string input_name = "../../../data/bunny.off"; const int n_voxels = 20; - const FT offset_value = 0.01; + const FT offset_value = -0.03; // load the original mesh Mesh mesh_input;