14#include <lagrange/Mesh.h>
15#include <lagrange/MeshTrait.h>
16#include <lagrange/create_mesh.h>
17#include <lagrange/legacy/inline.h>
20namespace subdivision {
37 std::enable_if_t<lagrange::MeshTraitHelper::is_mesh<MeshType>::value>* =
nullptr>
40 static_assert(MeshTrait<MeshType>::is_mesh(),
"Input type is not Mesh");
41 la_runtime_assert(mesh.get_vertex_per_facet() == 3,
"Only triangle meshes are supported");
43 using Scalar =
typename MeshType::Scalar;
44 using Index =
typename MeshType::Index;
45 using VertexArray =
typename MeshType::VertexArray;
46 using FacetArray =
typename MeshType::FacetArray;
48 mesh.initialize_edge_data();
49 const auto nv = mesh.get_num_vertices();
50 const auto ne = mesh.get_num_edges();
51 const auto nf = mesh.get_num_facets();
53 VertexArray V(nv + ne, mesh.get_dim());
54 FacetArray F(nf * 4, 3);
55 V.topRows(nv) = mesh.get_vertices();
56 for (Index e = 0; e < ne; ++e) {
57 auto v = mesh.get_edge_vertices(e);
59 Scalar(0.5) * (mesh.get_vertices().row(v[0]) + mesh.get_vertices().row(v[1]));
61 for (Index f = 0; f < mesh.get_num_facets(); ++f) {
62 const Index v0 = mesh.get_facets()(f, 0);
63 const Index v1 = mesh.get_facets()(f, 1);
64 const Index v2 = mesh.get_facets()(f, 2);
65 const Index e0 = nv + mesh.get_edge(f, 0);
66 const Index e1 = nv + mesh.get_edge(f, 1);
67 const Index e2 = nv + mesh.get_edge(f, 2);
68 F.row(4 * f + 0) << v0, e0, e2;
69 F.row(4 * f + 1) << v1, e1, e0;
70 F.row(4 * f + 2) << v2, e2, e1;
71 F.row(4 * f + 3) << e0, e1, e2;
#define la_runtime_assert(...)
Runtime assertion check.
Definition: assert.h:169
SurfaceMesh< Scalar, Index > midpoint_subdivision(const SurfaceMesh< Scalar, Index > &mesh)
Performs one step of midpoint subdivision for triangle meshes.
Definition: midpoint_subdivision.cpp:22
Main namespace for Lagrange.
Definition: AABBIGL.h:30
auto create_mesh(const Eigen::MatrixBase< DerivedV > &vertices, const Eigen::MatrixBase< DerivedF > &facets)
This function create a new mesh given the vertex and facet arrays by copying data into the Mesh objec...
Definition: create_mesh.h:39