darikg / seagullmesh

Python bindings to CGAL's Surface Mesh and Polygon Mesh Processing
GNU Lesser General Public License v3.0
7 stars 1 forks source link

Seagull Mesh

Python bindings to CGAL's Surface Mesh and Polygon Mesh Processing modules, plus some other assorted extras.

Installation

# pyvista and ceres-solver are optional
conda create --name seagull -c conda-forge cgal-cpp pybind11 eigen ceres-solver pyvista
conda activate seagull

On linux, you'll also need

conda install -c conda-forge gxx_linux-64 libgcc

Finally,

git clone git@github.com:darikg/seagullmesh.git
pip install -vv ./seagullmesh

Usage

Overview

This package provides bindings to the Surface_mesh<Point_3> class using Exact_predicates_inexact_constructions_kernel. Because CGAL is a heavily templated library, only a few convenience bindings per overloaded method are available, more added as-needed. To simplify some of the python/C++ mappings, the bound classes and methods are further wrapped in a python layer.

Mesh IO

3 constructors are available:

from seagullmesh import Mesh3

mesh = Mesh3.from_polygon_soup(verts, faces)
mesh = Mesh3.from_file('mesh.ply')
mesh = Mesh3.from_pyvista(polydata)

with the corresponding output methods mesh.to_polygon_soup, mesh.to_file, mesh.to_pyvista.

Mesh indices

CGAL indices Surface_mesh::vertex_index, ::edge_index, ::face_index, ::edge_index, and ::halfedge_index are exposed in the python properties mesh.vertices, .faces, .edges, and .halfedges, which are returned as numpy arrays of indices for convenience. These arrays are used for indexing property maps and specifying regions for further processing. (See below.)

Mesh property maps

Property maps are stored in the python properties mesh.vertex_data, edge_data, etc. They can be manually created by specifying a default value:

mesh.vertex_data.add_property('my_property1', default=1)

Or automatically on insert, where a default value of 0 is assumed:

mesh.vertex_data['my_property2'] = np.arange(mesh.n_vertices)

Indexing can use the appropriate keys:

my_property_vals = mesh.vertex_data['my_property2'][mesh.vertices]

Numpy indexing is also supported for convenience:

first_10 = mesh.vertex_data['my_property2'][:10]

Non-scalar valued properties are supported in the form of CGAL's Point_2, Point_3, Vector_2, Vector_3 objects must be constructed manually. Conversion to and from numpy arrays is handled automatically.

from seagullmesh import Point2
mesh.vertex_data.add_property('uv_map', default=Point2(0, 0))
mesh.vertex_data['uv_map'] =  np.random.uniform(-1, 1, (mesh.n_vertices, 2))

Mesh processing

Currently implemented are:

From PMP Meshing:

From PMP Corefinement and Boolean Operations

From the PMP Location Functions

From Triangulated Surface Mesh Shortest Paths

From The Heat Method

From Planar Parameterization of Triangulated Surface Meshes

Acknowledgements

The basis of the pybind11-cgal infrastructure is inspired very heavily by Scikit-geometry.

See also

License

This software is licensed under the LGPL-3 license. See the LICENSE file for details.