CGAL / cgal

The public CGAL repository, see the README below
https://github.com/CGAL/cgal#readme
Other
4.99k stars 1.39k forks source link

Some methods in Mesh_3 are missing in CGAL 5.5.1 #7358

Closed Resacd closed 1 year ago

Resacd commented 1 year ago

I am using CGAL 5.5.1 to generate block mesh inside complex geometry. I already have the code for generating the mesh but it seems that most of the functions in Mesh_3 class have been deprecated in this version. I tried some older versions of CGAL including version 5.3, 5.2.1 and the same problem was there. I got stuck with this issue for more than 2 weeks and I would appreciate if you could help me to fix this. The code I'm working on is supposed to read a stl file representing the surface triangulation, get a vector of triangles and then distribute this vector across all MPI processors. Then CGAL functions for generating the block mesh will be called in all MPI processors and at the end the mesh will be refined and merged(The functions for merge and refine also are not found). I used vcpkg to install the CGAL library. Here is the code

#include "blockmesh.h"

#include <CGAL/Polyhedral_mesh_domain_with_features_3.h>
#include <CGAL/Implicit_mesh_domain_3.h>
#include <CGAL/make_mesh_3.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Polygon_mesh_processing/triangulate_hole.h>
#include <CGAL/Mesh_3/Robust_intersection_traits_3.h>
#include <CGAL/Mesh_3/Polyhedral_complex_traits_with_shared_vertices_3.h>
#include <CGAL/Mesh_3/intersection_of_surface_meshes.h>
#include <CGAL/Mesh_3/repair_polygon_soup.h>

BlockMesh::BlockMesh() {

}

BlockMesh::~BlockMesh() {

}

void BlockMesh::generateBlockMesh(std::vector<Triangle>& procTriangles, const std::string& outputFilename) {

    // Initialize MPI
    int rank, size;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    // Construct the domain and subdomains
    typedef CGAL::Polyhedral_mesh_domain_with_features_3<CGAL::Simple_cartesian<double>> Mesh_domain;
    typedef Mesh_domain::Corner_index Corner_index;
    typedef Mesh_domain::Curve_index Curve_index;
    typedef Mesh_domain::Point_3 Point_3;
    typedef Mesh_domain::Segment_index Segment_index;
    typedef Mesh_domain::Surface_patch_index Surface_patch_index;
    typedef Mesh_domain::Triangle_index Triangle_index;

    Mesh_domain domain(procTriangles.begin(), procTriangles.end());

    // Construct the surface mesh
    typedef CGAL::Mesh_3::Robust_intersection_traits_3<Mesh_domain> Intersection_traits;
    typedef CGAL::Mesh_3::Polyhedral_complex_traits_with_shared_vertices_3<Mesh_domain, Intersection_traits> Traits;
    typedef CGAL::Polyhedron_3<Traits> Polyhedron;
    typedef boost::graph_traits<Polyhedron>::halfedge_descriptor halfedge_descriptor;
    typedef boost::graph_traits<Polyhedron>::vertex_descriptor vertex_descriptor;

    Polyhedron surface_mesh;
    CGAL::extract_boundary_mesh(domain, surface_mesh);

    // Triangulate holes in the surface mesh
    std::vector<halfedge_descriptor> boundary;
    CGAL::Polygon_mesh_processing::triangulate_hole(
        surface_mesh,
        boundary,
        CGAL::Polygon_mesh_processing::parameters::vertex_point_map(CGAL::get(CGAL::vertex_point, surface_mesh)));

    // Repair the polygon soup
    CGAL::Polygon_mesh_processing::repair_polygon_soup(surface_mesh);

    // Construct the mesh
    typedef CGAL::Mesh_domain_with_polyline_features_3<Mesh_domain> Mesh_domain_with_features;
    typedef CGAL::Implicit_mesh_domain_3<Mesh_domain_with_features, CGAL::Simple_cartesian<double>> Implicit_domain;
    typedef CGAL::Mesh_3::Mesh_complex_3_in_triangulation_3<
        Implicit_domain,
        CGAL::Default,
        CGAL::Mesh_3::Mesh_polyhedron_3<Traits>::type> C3t3;
    typedef CGAL::Mesh_criteria_3<C3t3> Mesh_criteria;

    Mesh_criteria criteria(CGAL::parameters::edge_size = 0.5,
        CGAL::parameters::facet_angle = 25,
        CGAL::parameters::facet_size = 0.1,
        CGAL::parameters::facet_distance = 0.025,
        CGAL::parameters::cell_radius_edge_ratio = 3,
        CGAL::parameters::cell_size = 0.5);

    Mesh_domain_with_features domain_with_features(domain);
    Implicit_domain implicit_domain(domain_with_features);

    C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(
        implicit_domain,
        criteria,
        CGAL::parameters::mesh_improvement = CGAL::parameters::no,
        CGAL::parameters::no_lloyd = true,
        CGAL::parameters::no_odt = true,
        CGAL::parameters::no_perturb = true);

    // Merge the meshes from all the processes
    std::vector<C3t3> all_c3t3;
    MPI_Datatype c3t3_type;
    int block_lengths[] = { 1, 1, 1 };
    MPI_Aint displacements[] = { 0, sizeof(C3t3::Triangulation), sizeof(C3t3) };
    MPI_Datatype types[] = { MPI_UNSIGNED_LONG_LONG, MPI_UNSIGNED_LONG_LONG, MPI_BYTE };
    MPI_Type_create_struct(3, block_lengths, displacements, types, &c3t3_type);
    MPI_Type_commit(&c3t3_type);

    MPI_Gather(&c3t3, 1, c3t3_type, &all_c3t3[0], 1, c3t3_type, 0, MPI_COMM_WORLD);

    if (rank == 0) {
        // Merge the meshes
        C3t3 merged_c3t3 = all_c3t3[0];
        for (int i = 1; i < size; i++) {
            merged_c3t3.join_c3t3(all_c3t3[i]);
        }
        // Write the mesh to file
        std::ofstream outputFile(outputFilename, std::ios::binary);
        CGAL::set_binary_mode(outputFile);
        CGAL::IO::write(outputFile, merged_c3t3);
        outputFile.close();
    }
    MPI_Type_free(&c3t3_type);
    MPI_Finalize();
}
lrineau commented 1 year ago

Can you please detail which functions are missing? Can you also tell us in which CGAL version those functions were present?

Mesh_3 is not a class, but a CGAL package, that is a set of function and class templates.

Resacd commented 1 year ago

@lrineau Thank you for the answer, yes mesh_3 is a package. Here are the errors; can not open the source file for the following [#include <CGAL/Mesh_3/Polyhedral_complex_traits_with_shared_vertices_3.h>

include <CGAL/Mesh_3/intersection_of_surface_meshes.h>

include <CGAL/Mesh_3/repair_polygon_soup.h>](url)

The above headers don't exist in the Mesh_3 folder but I can find Robust_intersection_traits_3.h in mesh_3.

The error has no member "Segment_index" and "Segment_index" in the following lines, typedef Mesh_domain::Segment_index Segment_index; typedef Mesh_domain::Triangle_index Triangle_index; the same error in the following lines typedef CGAL::Mesh_3::Robust_intersection_traits_3 Intersection_traits; typedef CGAL::Mesh_3::Polyhedral_complex_traits_with_shared_vertices_3<Mesh_domain, Intersection_traits> Traits; typedef CGAL::Polyhedron_3 Polyhedron; typedef boost::graph_traits::halfedge_descriptor halfedge_descriptor; CGAL::extract_boundary_mesh(domain, surface_mesh); CGAL::Polygon_mesh_processing::repair_polygon_soup(surface_mesh); No instance of object matches the arguments list in the following line CGAL::Polygon_mesh_processing::triangulate_hole( surface_mesh, boundary, CGAL::Polygon_mesh_processing::parameters::vertex_point_map(CGAL::get(CGAL::vertex_point, surface_mesh)))

and there are errors of this kind in the code. I am using version 5.5.1. I just found some examples from CGAL website and in the internet to be able to write the code. I don't know in which version they were present but as I see here https://doc.cgal.org/latest/Mesh_3/Mesh_3_2mesh_polyhedral_domain_with_features_8cpp-example.html I can find Polyhedral_complex_traits_with_shared_vertices_3.h in CGAL 5.5.2 but still missing some others. here is the list of headers in mesh_3 packages C3T3_helpers.h Cell_criteria_visitor_with_balls.h Concurrent_mesher_config.h config.h dihedral_angle_3.h Dump_c3t3.h experimental Facet_criteria_visitor_with_balls.h Facet_on_same_surface_criterion.h generate_label_weights.h Has_features.h Image_plus_weights_to_labeled_function_wrapper.h Image_to_labeled_function_wrapper.h Implicit_surface_mesher_visitor.h initialize_triangulation_from_gray_image.h initialize_triangulation_from_labeled_image.h internal io_signature.h Is_mesh_domain_field_3.h Lloyd_move.h Mesher_3.h Mesher_level.h Mesher_level_default_implementations.h Mesh_complex_3_in_triangulation_3_base.h Mesh_complex_3_in_triangulation_3_fwd.h Mesh_global_optimizer.h Mesh_sizing_field.h mesh_standard_cell_criteria.h mesh_standard_criteria.h mesh_standard_facet_criteria.h Mesh_surface_cell_base_3.h min_dihedral_angle.h Null_exuder_visitor.h Null_global_optimizer_visitor.h Null_perturber_visitor.h Odt_move.h parameters_defaults.h Poisson_refine_cells_3.h polyhedral_to_labeled_function_wrapper.h polylines_to_protect.h Polyline_with_context.h Profile_counter.h Profiling_tools.h Protect_edges_sizing_field.h radius_ratio.h Refine_cells_3.h Refine_facets_3.h Refine_facets_manifold_base.h Refine_tets_visitor.h Robust_intersection_kernel.h Robust_intersection_traits_3.h search_for_connected_components_in_labeled_image.h Sizing_grid.h Slivers_exuder.h Slivers_exuder_cell_attributes_traits.h sliver_criteria.h Sliver_perturber.h squared_distance_Point_3_Triangle_3.h tet_soup_to_c3t3.h Triangle_accessor_primitive.h Triangulation_helpers.h Triangulation_sizing_field.h Uniform_sizing_field.h utilities.h vertex_perturbation.h Worksharing_data_structures.h

lrineau commented 1 year ago

@lrineau Thank you for the answer, yes mesh_3 is a package. Here are the errors; can not open the source file for the following

#include <CGAL/Mesh_3/Polyhedral_complex_traits_with_shared_vertices_3.h>
#include <CGAL/Mesh_3/intersection_of_surface_meshes.h>
#include <CGAL/Mesh_3/repair_polygon_soup.h>

None of those three headers have even been into CGAL. The code you are trying to compile was probably dependent on a very modified version of CGAL.

Resacd commented 1 year ago

Thanks for your answer. Yes I know that I can not access them. because those header are not in the Mesh_3 package. so are you saying they've never been in CGAL. from which packages of any standard CGAL I can get the functionality that I'm looking for.

lrineau commented 1 year ago

Those headers are not in CGAL, and never were. And no open source project on Github seems to know about Polyhedral_complex_traits_with_shared_vertices_3, for example. The code your are trying to compile, using the class BlockMesh, does not seem to be freely available. You should ask support from the authors of that class.

Resacd commented 1 year ago

I am writing this class. I didn't get it ready. I just followed examples from CGAL website and other examples in forums. the purpose of this code is to generate the block mesh inside the complex geometry (in this application it will be a vessel with lots of curvature and aneurysm). That's why I came to CGAL. does CGAL work for this? Is there any other library that could do the same job in C++?