Volume Mesh

1. Overview

The Ktirio library provides functionalities for converting geometric meshes into 3D mesh formats that are suitable for visualization and further analysis. This page covers the key functions used for these conversions: meshToPolyhedron, polyhedronTo3DMesh, and mesh_3d.

2. Functions

2.1. meshToPolyhedron

The meshToPolyhedron function converts a Mesh object into a CGAL::Polyhedron_3 object. This conversion allows the use of CGAL’s advanced mesh processing features.

Function Signature:

template <typename KernelType>
auto meshToPolyhedron(const Mesh& mesh, bool debug=false);

Parameters:

  • mesh: The Mesh object that contains the geometric data to be converted.

  • debug: Optional boolean flag (default is false). When set to true, enables debug mode to check whether the resulting polyhedron is properly triangulated.

Description: This function takes a Mesh and converts it into a CGAL::Polyhedron_3 object using the Polyhedron_scan_Mesh class. The resulting polyhedron is suitable for advanced mesh operations provided by CGAL.

2.2. polyhedronTo3DMesh

The polyhedronTo3DMesh function generates a 3D mesh from a CGAL::Polyhedron_3 object. This function involves meshing the polyhedron according to specified criteria and outputs the result to a file.

Function Signature:

template <typename KernelType>
void polyhedronTo3DMesh(const CGAL::Polyhedron_3<KernelType, CGAL::Mesh_3::Mesh_polyhedron_items<int>>& polyhedron, std::string outfile, bool debug=false, bool write_mesh=false);

Parameters:

  • polyhedron: The CGAL::Polyhedron_3 object that represents the geometric data.

  • outfile: The name of the output file where the 3D mesh will be saved.

  • debug: Optional boolean flag (default is false). When enabled, logs information about the meshing process and the time taken.

  • write_mesh: Optional boolean flag (default is false). When enabled, .mesh file will be write in addition to .vtu

Description: This function takes a CGAL::Polyhedron_3 object and generates a 3D mesh. It creates a mesh domain from the polyhedron, sets meshing criteria such as edge size and facet angle, and performs the meshing operation. The resulting 3D mesh is saved to files in .vtu and .mesh formats if asked. Debug mode provides additional logs for the meshing process.

2.3. mesh_3d

The mesh_3d function provides a high-level interface that combines meshToPolyhedron and polyhedronTo3DMesh to perform the entire conversion process from a Mesh to a 3D mesh file.

Function Signature:

template <typename KernelType>
void mesh_3d(Mesh& mesh, std::string outfile="out3DMesh.vtu", bool debug=false);

Parameters:

  • mesh: The Mesh object containing the data to be converted into a 3D mesh.

  • outfile: The name of the output file for the 3D mesh (default is "out3DMesh.vtu").

  • debug: Optional boolean flag (default is false). Enables debug mode for tracing the conversion process.

Description: This function integrates meshToPolyhedron and polyhedronTo3DMesh into a single workflow. It first converts the provided Mesh into a CGAL::Polyhedron_3 object and then uses that polyhedron to generate a 3D mesh. The resulting mesh is saved to the specified file. Debug mode helps in tracking the process and verifying results.

3. Supporting Class

3.1. Polyhedron_scan_Mesh

The Polyhedron_scan_Mesh class is used internally by meshToPolyhedron to convert a Mesh into a CGAL::Polyhedron_3 object. This class is a key component in the conversion process.

Class Definition:

template <class HDS>
class Polyhedron_scan_Mesh : public CGAL::Modifier_base<HDS>
{
public:
    Polyhedron_scan_Mesh(const Mesh& mesh) : mesh_(mesh) {}

    void operator()(HDS& hds)
    {
        CGAL::Polyhedron_incremental_builder_3<HDS> builder(hds, true);
        builder.begin_surface(mesh_.nPoints(), mesh_.nTriangles());

        // Add vertices
        std::unordered_map<int, std::size_t> vertex_map;
        std::size_t vertex_index = 0;
        for (const auto& [id, point_ptr] : mesh_.points())
        {
            auto point = point_ptr->geometricPoint();
            builder.add_vertex(CGAL::Point_3<CGAL::Exact_predicates_inexact_constructions_kernel>(point.x(), point.y(), point.z()));
            vertex_map[id] = vertex_index++;
        }

        // Add faces
        for (const auto& triangle_ptr : mesh_.triangles())
        {
            builder.begin_facet();
            for (int i = 0; i < 3; ++i)
            {
                builder.add_vertex_to_facet(vertex_map[triangle_ptr->point(i).id()]);
            }
            builder.end_facet();
        }

        builder.end_surface();
    }

private:
    const Mesh& mesh_;
};

Description: The Polyhedron_scan_Mesh class is used to build a CGAL::Polyhedron_3 incrementally from a Mesh. It overrides the operator() method to add vertices and faces to the polyhedron. This class uses CGAL::Polyhedron_incremental_builder_3 to efficiently construct the polyhedron by scanning the mesh data and mapping it into the polyhedral structure.

Constructor:

  • Polyhedron_scan_Mesh(const Mesh& mesh): Initializes the class with a Mesh object to be converted.

Method:

  • void operator()(HDS& hds): Implements the conversion logic by adding vertices and faces to the halfedge data structure (HDS).

4. Summary

The Ktirio library’s functions for 3D mesh conversion meshToPolyhedron, polyhedronTo3DMesh, and mesh_3d provide a comprehensive approach to transforming geometric meshes into 3D formats. The Polyhedron_scan_Mesh class is an integral part of this process, enabling efficient conversion of Mesh data into a CGAL::Polyhedron_3 object. Together, these tools facilitate effective processing and visualization of complex geometric data.