From dec76cf6d3ba49e6e930fb6d5c5c9e2d7cd40f2d Mon Sep 17 00:00:00 2001 From: Sven Oesau Date: Fri, 27 Sep 2024 16:15:38 +0200 Subject: [PATCH] moving dual_contouring_octree.cpp back into examples --- .../examples/Isosurfacing_3/CMakeLists.txt | 3 + .../internal/partition_traits_Octree.h | 6 +- .../test/Isosurfacing_3/CMakeLists.txt | 3 - .../Isosurfacing_3/dual_contouring_octree.cpp | 140 ------------------ 4 files changed, 6 insertions(+), 146 deletions(-) delete mode 100644 Isosurfacing_3/test/Isosurfacing_3/dual_contouring_octree.cpp diff --git a/Isosurfacing_3/examples/Isosurfacing_3/CMakeLists.txt b/Isosurfacing_3/examples/Isosurfacing_3/CMakeLists.txt index b4743911278..4f360965804 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/CMakeLists.txt +++ b/Isosurfacing_3/examples/Isosurfacing_3/CMakeLists.txt @@ -36,12 +36,14 @@ create_single_source_cgal_program("marching_cubes_strategies.cpp") if(TARGET CGAL::Eigen3_support) create_single_source_cgal_program("dual_contouring.cpp") + create_single_source_cgal_program("dual_contouring_octree.cpp") create_single_source_cgal_program("contouring_discrete_data.cpp") create_single_source_cgal_program("contouring_inrimage.cpp") create_single_source_cgal_program("contouring_implicit_data.cpp") create_single_source_cgal_program("contouring_mesh_offset.cpp") target_link_libraries(dual_contouring PRIVATE CGAL::Eigen3_support) + target_link_libraries(dual_contouring_octree PRIVATE CGAL::Eigen3_support) target_link_libraries(contouring_discrete_data PRIVATE CGAL::Eigen3_support) target_link_libraries(contouring_inrimage PRIVATE CGAL::Eigen3_support) target_link_libraries(contouring_implicit_data PRIVATE CGAL::Eigen3_support) @@ -49,6 +51,7 @@ if(TARGET CGAL::Eigen3_support) if(TARGET CGAL::TBB_support) target_link_libraries(dual_contouring PRIVATE CGAL::TBB_support) + target_link_libraries(dual_contouring_octree PRIVATE CGAL::TBB_support) target_link_libraries(contouring_discrete_data PRIVATE CGAL::TBB_support) target_link_libraries(contouring_inrimage PRIVATE CGAL::TBB_support) target_link_libraries(contouring_implicit_data PRIVATE CGAL::TBB_support) diff --git a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/partition_traits_Octree.h b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/partition_traits_Octree.h index 772790966e4..d7cdb98851a 100644 --- a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/partition_traits_Octree.h +++ b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/partition_traits_Octree.h @@ -97,7 +97,7 @@ public: private: static std::set get_leaf_edges(const Orthtree& o) { std::set leaf_edge_set; - std::size_t dim = 1 << o.depth(); + std::size_t dim = std::size_t(1) << o.depth(); for (Node_index node_index : o.traverse(CGAL::Orthtrees::Leaves_traversal(o))) { const Uniform_coords& coords_uniform = uniform_coordinates(node_index, o); @@ -105,7 +105,7 @@ private: // write all leaf edges in a set const Uniform_coords& coords_global = o.global_coordinates(node_index); const std::size_t depth = o.depth(node_index); - const std::size_t df = 1 << (o.depth() - depth); + const std::size_t df = std::size_t(1) << (o.depth() - depth); for (const auto& edge_voxels : internal::Cube_table::edge_to_voxel_neighbor) { bool are_all_voxels_leafs = true; @@ -404,7 +404,7 @@ private: static Uniform_coords uniform_coordinates(Node_index node_index, const Orthtree &o) { Uniform_coords coords = o.global_coordinates(node_index); - const std::size_t df = 1 << (o.depth() - o.depth(node_index)); + const std::size_t df = std::size_t(1) << (o.depth() - o.depth(node_index)); for (int i = 0; i < 3; ++i) coords[i] *= static_cast(df); diff --git a/Isosurfacing_3/test/Isosurfacing_3/CMakeLists.txt b/Isosurfacing_3/test/Isosurfacing_3/CMakeLists.txt index c367b057d6f..e8991b30f01 100644 --- a/Isosurfacing_3/test/Isosurfacing_3/CMakeLists.txt +++ b/Isosurfacing_3/test/Isosurfacing_3/CMakeLists.txt @@ -25,16 +25,13 @@ if(TARGET CGAL::Eigen3_support) endif() #examples to be moved in example when reading to be documented - create_single_source_cgal_program("dual_contouring_octree.cpp") create_single_source_cgal_program("dual_contouring_strategies.cpp") create_single_source_cgal_program("dual_contouring_intersection_oracles.cpp") - target_link_libraries(dual_contouring_octree PRIVATE CGAL::Eigen3_support) target_link_libraries(dual_contouring_strategies PRIVATE CGAL::Eigen3_support) target_link_libraries(dual_contouring_intersection_oracles PRIVATE CGAL::Eigen3_support) if(TARGET CGAL::TBB_support) - target_link_libraries(dual_contouring_octree PRIVATE CGAL::TBB_support) target_link_libraries(dual_contouring_strategies PRIVATE CGAL::TBB_support) target_link_libraries(dual_contouring_intersection_oracles PRIVATE CGAL::TBB_support) endif() diff --git a/Isosurfacing_3/test/Isosurfacing_3/dual_contouring_octree.cpp b/Isosurfacing_3/test/Isosurfacing_3/dual_contouring_octree.cpp deleted file mode 100644 index ecc4ee80df8..00000000000 --- a/Isosurfacing_3/test/Isosurfacing_3/dual_contouring_octree.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -using Kernel = CGAL::Simple_cartesian; -using FT = typename Kernel::FT; -using Vector = typename Kernel::Vector_3; -using Point = typename Kernel::Point_3; - -using Point_range = std::vector; -using Polygon_range = std::vector >; - -using Octree = CGAL::Octree >; -using Values = CGAL::Isosurfacing::Value_function_3; -using Gradients = CGAL::Isosurfacing::Gradient_function_3; -using MC_Domain = CGAL::Isosurfacing::Marching_cubes_domain_3; -using Domain = CGAL::Isosurfacing::Dual_contouring_domain_3; - -// Refine one of the octant -struct Refine_one_eighth -{ - std::size_t min_depth_; - std::size_t max_depth_; - - std::size_t octree_dim_; - - Refine_one_eighth(std::size_t min_depth, - std::size_t max_depth) - : min_depth_(min_depth), - max_depth_(max_depth) - { - octree_dim_ = std::size_t(1) << max_depth_; - } - - Octree::Global_coordinates uniform_coordinates(const Octree::Node_index& node_index, const Octree& octree) const - { - auto coords = octree.global_coordinates(node_index); - const std::size_t depth_factor = std::size_t(1) << (max_depth_ - octree.depth(node_index)); - for(int i=0; i < 3; ++i) - coords[i] *= uint32_t(depth_factor); - - return coords; - } - - bool operator()(const Octree::Node_index& ni, const Octree& octree) const - { - if(octree.depth(ni) < min_depth_) - return true; - - if(octree.depth(ni) == max_depth_) - return false; - - auto leaf_coords = uniform_coordinates(ni, octree); - - if(leaf_coords[0] >= octree_dim_ / 2) - return false; - - if(leaf_coords[1] >= octree_dim_ / 2) - return false; - - if(leaf_coords[2] >= octree_dim_ / 2) - return false; - - return true; - } -}; - -auto sphere_function = [](const Point& p) -> FT -{ - return std::sqrt(p.x()*p.x() + p.y()*p.y() + p.z()*p.z()); -}; - -auto sphere_gradient = [](const Point& p) -> Vector -{ - const Vector g = p - CGAL::ORIGIN; - return g / std::sqrt(g.squared_length()); -}; - -int main(int argc, char** argv) -{ - const FT isovalue = (argc > 1) ? std::stod(argv[1]) : 0.8; - - const CGAL::Bbox_3 bbox{-1., -1., -1., 1., 1., 1.}; - std::vector bbox_points { {bbox.xmin(), bbox.ymin(), bbox.zmin()}, - { bbox.xmax(), bbox.ymax(), bbox.zmax() } }; - - CGAL::Real_timer timer; - timer.start(); - - Octree octree(bbox_points); - Refine_one_eighth split_predicate(3, 5); - octree.refine(split_predicate); - - std::ofstream oo("octree2.polylines.txt"); - oo.precision(17); - octree.dump_to_polylines(oo); - - std::cout << "Running Dual Contouring with isovalue = " << isovalue << std::endl; - - // fill up values and gradients - Values values { sphere_function, octree }; - Gradients gradients { sphere_gradient, octree }; - Domain domain { octree, values, gradients }; - - // output containers - Point_range points; - Polygon_range triangles; - - // run Dual Contouring - CGAL::Isosurfacing::dual_contouring(domain, isovalue, points, triangles, CGAL::parameters::do_not_triangulate_faces(true)); - - // run Marching Cubes - // ToDo: Does not yet work with topologically correct marching cubes - // MC_Domain mcdomain{ octree, values }; - // CGAL::Isosurfacing::marching_cubes(mcdomain, isovalue, points, triangles); - - timer.stop(); - - std::cout << "Output #vertices (DC): " << points.size() << std::endl; - std::cout << "Output #triangles (DC): " << triangles.size() << std::endl; - std::cout << "Elapsed time: " << timer.time() << " seconds" << std::endl; - CGAL::IO::write_polygon_soup("dual_contouring_octree.off", points, triangles); - - std::cout << "Done" << std::endl; - - return EXIT_SUCCESS; -}