PolyFEM
Loading...
Searching...
No Matches
MeshUtils.hpp
Go to the documentation of this file.
1#pragma once
2
6#include <Eigen/Dense>
7#include <vector>
8#include <memory>
9
10namespace polyfem
11{
12
13 namespace mesh
14 {
15 class Mesh2D;
16 class Mesh3D;
17
26 PolygonMesh::Point mesh_vertex(const PolygonMesh &M, int v);
27
28 // Compute facet barycenter.
29 //
30 // @param[in] M Input mesh
31 // @param[in] f Facet whose barycenter to compute
32 //
33 // @return Barycenter position in 3D
34 //
35 PolygonMesh::Point facet_barycenter(const PolygonMesh &M, int f);
36
37 // Create a new mesh vertex with given coordinates.
38 //
39 // @param M Mesh to modify
40 // @param[in] p New vertex position
41 //
42 // @return Index of the newly created vertex
43 //
44 int mesh_create_vertex(PolygonMesh &M, const PolygonMesh::Point &p);
45
52 void compute_element_tags(const PolygonMesh &M, std::vector<ElementType> &element_tags);
53
60 void orient_normals_2d(PolygonMesh &M);
61
71 void reorder_mesh(Eigen::MatrixXd &V, Eigen::MatrixXi &F, const Eigen::VectorXi &C, Eigen::VectorXi &R);
72
75 void offset_surface_vertices(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F,
76 const Eigen::RowVector3d &interior_point, double distance, Eigen::MatrixXd &offset);
77
90 void signed_squared_distances(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F,
91 const Eigen::MatrixXd &P, Eigen::VectorXd &D);
92
101 double signed_volume(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F);
102
110 void orient_closed_surface(const Eigen::MatrixXd &V, Eigen::MatrixXi &F, bool positive = true);
111
113 std::vector<std::pair<Navigation::Index, Navigation::Index>> compute_mesh_interface(
114 const Mesh2D &first, const Mesh2D &second);
115
117 std::vector<std::pair<Navigation3D::Index, Navigation3D::Index>> compute_mesh_interface(
118 const Mesh3D &first, const Mesh3D &second);
119
129 void extract_parent_edges(const Eigen::MatrixXd &IV, const Eigen::MatrixXi &IE,
130 const Eigen::MatrixXd &BV, const Eigen::MatrixXi &BE, Eigen::MatrixXi &OE);
131
138 void find_triangle_surface_from_tets(const Eigen::MatrixXi &tets, Eigen::MatrixXi &faces);
139
147 const Eigen::MatrixXd &vertices,
148 const Eigen::MatrixXi &tets,
149 Eigen::MatrixXd &surface_vertices,
150 Eigen::MatrixXi &tris);
151
153 bool is_planar(const Eigen::MatrixXd &V, const double tol = 1e-5);
154
156 int count_faces(const int dim, const Eigen::MatrixXi &cells);
157
160 void generate_edges(PolygonMesh &M);
161 } // namespace mesh
162} // namespace polyfem
int V
std::vector< Eigen::VectorXi > faces
std::vector< std::pair< Navigation::Index, Navigation::Index > > compute_mesh_interface(const Mesh2D &first, const Mesh2D &second)
Pair coincident boundary edges, including nonconforming leader/follower edges.
void orient_closed_surface(const Eigen::MatrixXd &V, Eigen::MatrixXi &F, bool positive=true)
Orient a triangulated surface to have positive volume.
double signed_volume(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F)
Compute the signed volume of a surface mesh.
PolygonMesh::Point mesh_vertex(const PolygonMesh &M, int v)
Retrieve a 3D vector with the position of a given vertex.
Definition MeshUtils.cpp:39
void offset_surface_vertices(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, const Eigen::RowVector3d &interior_point, double distance, Eigen::MatrixXd &offset)
Offset along area-weighted surface normals, using the direction away from an interior point where inc...
void reorder_mesh(Eigen::MatrixXd &V, Eigen::MatrixXi &F, const Eigen::VectorXi &C, Eigen::VectorXi &R)
Reorder vertices of a mesh using color tags, so that vertices are ordered by increasing colors.
void find_triangle_surface_from_tets(const Eigen::MatrixXi &tets, Eigen::MatrixXi &faces)
Boundary triangles of a tet mesh, indexing the tets' vertices.
bool is_planar(const Eigen::MatrixXd &V, const double tol=1e-5)
Determine if the given V x (2|3) vertices are planar (2D or z-range below tol).
Definition MeshUtils.cpp:26
void extract_parent_edges(const Eigen::MatrixXd &IV, const Eigen::MatrixXi &IE, const Eigen::MatrixXd &BV, const Eigen::MatrixXi &BE, Eigen::MatrixXi &OE)
Extract a set of edges that are overlap with a set given set of parent edges, using vertices position...
void extract_triangle_surface_from_tets(const Eigen::MatrixXd &vertices, const Eigen::MatrixXi &tets, Eigen::MatrixXd &surface_vertices, Eigen::MatrixXi &tris)
Extract triangular surface from a tetmesh.
void signed_squared_distances(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, const Eigen::MatrixXd &P, Eigen::VectorXd &D)
Computes the signed squared distance from a list of points to a triangle mesh.
PolygonMesh::Point facet_barycenter(const PolygonMesh &M, int f)
Definition MeshUtils.cpp:46
void compute_element_tags(const PolygonMesh &M, std::vector< ElementType > &element_tags)
Compute the type of each facet in a surface mesh.
Definition MeshUtils.cpp:65
int mesh_create_vertex(PolygonMesh &M, const PolygonMesh::Point &p)
Definition MeshUtils.cpp:58
void orient_normals_2d(PolygonMesh &M)
Orient facets of a 2D mesh so that each connected component has positive volume.
void generate_edges(PolygonMesh &M)
Creates the edges of M (sorted by vertex pair) if it has none yet.
int count_faces(const int dim, const Eigen::MatrixXi &cells)
Count the number of boundary elements (triangles for tetmesh and edges for triangle mesh)