PolyFEM
Loading...
Searching...
No Matches
MeshUtils.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <geogram/mesh/mesh.h>
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
28 GEO::vec3 mesh_vertex(const GEO::Mesh &M, GEO::index_t v);
29
30 // Compute facet barycenter.
31 //
32 // @param[in] M Input mesh
33 // @param[in] f Facet whose barycenter to compute
34 //
35 // @return Barycenter position in 3D
36 //
37 GEO::vec3 facet_barycenter(const GEO::Mesh &M, GEO::index_t f);
38
39 // Create a new mesh vertex with given coordinates.
40 //
41 // @param M Mesh to modify
42 // @param[in] p New vertex position
43 //
44 // @return Index of the newly created vertex
45 //
46 GEO::index_t mesh_create_vertex(GEO::Mesh &M, const GEO::vec3 &p);
47
54 void compute_element_tags(const GEO::Mesh &M, std::vector<ElementType> &element_tags);
55
62 void orient_normals_2d(GEO::Mesh &M);
63
73 void reorder_mesh(Eigen::MatrixXd &V, Eigen::MatrixXi &F, const Eigen::VectorXi &C, Eigen::VectorXi &R);
74
87 void signed_squared_distances(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F,
88 const Eigen::MatrixXd &P, Eigen::VectorXd &D);
89
97 void to_geogram_mesh(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, GEO::Mesh &M);
98 // void to_geogram_mesh_3d(const Eigen::MatrixXd &V, const Eigen::MatrixXi &C, GEO::Mesh &M);
99
108 void from_geogram_mesh(const GEO::Mesh &M, Eigen::MatrixXd &V, Eigen::MatrixXi &F, Eigen::MatrixXi &T);
109
116 void to_geogram_mesh(const Mesh3D &mesh, GEO::Mesh &M);
117
126 double signed_volume(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F);
127
135 void orient_closed_surface(const Eigen::MatrixXd &V, Eigen::MatrixXi &F, bool positive = true);
136
143 void extract_polyhedra(const Mesh3D &mesh, std::vector<std::unique_ptr<GEO::Mesh>> &polys, bool triangulated = false);
144
146 std::vector<std::pair<Navigation::Index, Navigation::Index>> compute_mesh_interface(
147 const Mesh2D &first, const Mesh2D &second);
148
150 std::vector<std::pair<Navigation3D::Index, Navigation3D::Index>> compute_mesh_interface(
151 const Mesh3D &first, const Mesh3D &second);
152
164 void sample_surface(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, int num_samples,
165 Eigen::MatrixXd &P, Eigen::MatrixXd *N = nullptr, int num_lloyd = 10, int num_newton = 10);
166
176 void extract_parent_edges(const Eigen::MatrixXd &IV, const Eigen::MatrixXi &IE,
177 const Eigen::MatrixXd &BV, const Eigen::MatrixXi &BE, Eigen::MatrixXi &OE);
178
186 const Eigen::MatrixXd &vertices,
187 const Eigen::MatrixXi &tets,
188 Eigen::MatrixXd &surface_vertices,
189 Eigen::MatrixXi &tris);
190
200 bool read_surface_mesh(const std::string &mesh_path, Eigen::MatrixXd &vertices, Eigen::VectorXi &codim_vertices, Eigen::MatrixXi &codim_edges, Eigen::MatrixXi &faces);
201
203 bool is_planar(const GEO::Mesh &M, const double tol = 1e-5);
204
206 int count_faces(const int dim, const Eigen::MatrixXi &cells);
207
210 void generate_edges(GEO::Mesh &M);
211 } // namespace mesh
212} // 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.
bool is_planar(const GEO::Mesh &M, const double tol=1e-5)
Determine if the given mesh is planar (2D or tiny z-range).
Definition MeshUtils.cpp:35
void sample_surface(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, int num_samples, Eigen::MatrixXd &P, Eigen::MatrixXd *N=nullptr, int num_lloyd=10, int num_newton=10)
Samples points on a surface.
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.
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 orient_normals_2d(GEO::Mesh &M)
Orient facets of a 2D mesh so that each connected component has positive volume.
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.
GEO::vec3 mesh_vertex(const GEO::Mesh &M, GEO::index_t v)
Retrieve a 3D vector with the position of a given vertex.
Definition MeshUtils.cpp:48
GEO::index_t mesh_create_vertex(GEO::Mesh &M, const GEO::vec3 &p)
Definition MeshUtils.cpp:81
void to_geogram_mesh(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, GEO::Mesh &M)
Converts a triangle mesh to a Geogram mesh.
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.
GEO::vec3 facet_barycenter(const GEO::Mesh &M, GEO::index_t f)
Definition MeshUtils.cpp:68
void from_geogram_mesh(const GEO::Mesh &M, Eigen::MatrixXd &V, Eigen::MatrixXi &F, Eigen::MatrixXi &T)
Extract simplices from a Geogram mesh.
void generate_edges(GEO::Mesh &M)
assing edges to M
bool read_surface_mesh(const std::string &mesh_path, Eigen::MatrixXd &vertices, Eigen::VectorXi &codim_vertices, Eigen::MatrixXi &codim_edges, Eigen::MatrixXi &faces)
read a surface mesh
void extract_polyhedra(const Mesh3D &mesh, std::vector< std::unique_ptr< GEO::Mesh > > &polys, bool triangulated=false)
Extract polyhedra from a 3D volumetric mesh.
int count_faces(const int dim, const Eigen::MatrixXi &cells)
Count the number of boundary elements (triangles for tetmesh and edges for triangle mesh)
void compute_element_tags(const GEO::Mesh &M, std::vector< ElementType > &element_tags)
Compute the type of each facet in a surface mesh.