#include #include #include #include "vde/mesh/delaunay_2d.h" #include "vde/mesh/delaunay_3d.h" #include "vde/mesh/halfedge_mesh.h" namespace py = pybind11; using namespace vde::mesh; void bind_mesh(py::module& m) { auto mesh = m.def_submodule("mesh", "Mesh generation and processing"); // ── DelaunayResult (2D) ────────────────────────── py::class_(mesh, "DelaunayResult", R"pbdoc( Result of 2D Delaunay triangulation. Attributes: vertices: list of Point2D triangles: list of [i, j, k] index triples )pbdoc") .def(py::init<>()) .def_readwrite("vertices", &DelaunayResult::vertices) .def_readwrite("triangles", &DelaunayResult::triangles) .def("__repr__", [](const DelaunayResult& r) { return "DelaunayResult(v=" + std::to_string(r.vertices.size()) + ", t=" + std::to_string(r.triangles.size()) + ")"; }); // ── TetrahedronMesh (3D) ───────────────────────── py::class_(mesh, "TetrahedronMesh", R"pbdoc( Result of 3D Delaunay tetrahedralization. Attributes: vertices: list of Point3D tetrahedra: list of [i, j, k, l] index quadruples )pbdoc") .def(py::init<>()) .def_readwrite("vertices", &TetrahedronMesh::vertices) .def_readwrite("tetrahedra", &TetrahedronMesh::tetrahedra) .def("__repr__", [](const TetrahedronMesh& m) { return "TetrahedronMesh(v=" + std::to_string(m.vertices.size()) + ", tet=" + std::to_string(m.tetrahedra.size()) + ")"; }); // ── Delaunay free functions ────────────────────── mesh.def("delaunay_2d", &delaunay_2d, py::arg("points"), "Bowyer-Watson 2D Delaunay triangulation"); mesh.def("delaunay_3d", &delaunay_3d, py::arg("points"), "3D Delaunay tetrahedralization (Bowyer-Watson)"); // ── HalfedgeMesh ───────────────────────────────── py::class_(mesh, "HalfedgeMesh", R"pbdoc( Half-edge data structure for polygon meshes. Supports construction from triangle soup and provides topology queries, normal computation, and iterators. )pbdoc") .def(py::init<>()) .def("clear", &HalfedgeMesh::clear) .def("add_vertex", &HalfedgeMesh::add_vertex, py::arg("point"), "Add a vertex, returns index") .def("add_face", &HalfedgeMesh::add_face, py::arg("vertex_indices"), "Add a face from vertex indices, returns face index") .def("build_from_triangles", &HalfedgeMesh::build_from_triangles, py::arg("vertices"), py::arg("triangles"), "Build from vertex list and triangle index list") .def_property_readonly("num_vertices", &HalfedgeMesh::num_vertices) .def_property_readonly("num_faces", &HalfedgeMesh::num_faces) .def_property_readonly("num_edges", &HalfedgeMesh::num_edges) .def("vertex", &HalfedgeMesh::vertex, py::arg("idx")) .def("set_vertex", &HalfedgeMesh::set_vertex, py::arg("idx"), py::arg("point")) .def("face_vertices", &HalfedgeMesh::face_vertices, py::arg("face_index"), "Get vertex indices of a face") .def("vertex_faces", &HalfedgeMesh::vertex_faces, py::arg("vertex_index"), "Get face indices incident to a vertex") .def("is_boundary_edge", &HalfedgeMesh::is_boundary_edge, py::arg("halfedge_index")) .def("is_boundary_vertex", &HalfedgeMesh::is_boundary_vertex, py::arg("vertex_index")) .def("face_normal", &HalfedgeMesh::face_normal, py::arg("face_index")) .def("vertex_normal", &HalfedgeMesh::vertex_normal, py::arg("vertex_index")) .def("update_normals", &HalfedgeMesh::update_normals) .def_property_readonly("bounds", &HalfedgeMesh::bounds) .def("__repr__", [](const HalfedgeMesh& m) { return "HalfedgeMesh(v=" + std::to_string(m.num_vertices()) + ", f=" + std::to_string(m.num_faces()) + ", e=" + std::to_string(m.num_edges()) + ")"; }); }