PolyFEM
Loading...
Searching...
No Matches
PolygonMesh.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <vector>
5
6namespace polyfem::mesh
7{
20 {
21 public:
24 struct Point
25 {
26 std::array<double, 3> coords = {{0, 0, 0}};
27
28 Point() = default;
29 Point(const double x, const double y, const double z) : coords{{x, y, z}} {}
30
31 double &operator[](const int i) { return coords[i]; }
32 double operator[](const int i) const { return coords[i]; }
33
35 {
36 coords[0] += v[0];
37 coords[1] += v[1];
38 coords[2] += v[2];
39 return *this;
40 }
41 Point operator+(const Point &v) const { return Point(coords[0] + v[0], coords[1] + v[1], coords[2] + v[2]); }
42 Point operator-(const Point &v) const { return Point(coords[0] - v[0], coords[1] - v[1], coords[2] - v[2]); }
43 Point operator/(const double s) const { return Point(coords[0] / s, coords[1] / s, coords[2] / s); }
44 friend Point operator*(const double s, const Point &v) { return Point(s * v[0], s * v[1], s * v[2]); }
45 };
46
48 void clear();
49
50 // -- Vertices ------------------------------------------------------------
51
52 int n_vertices() const { return points_.size(); }
53 const Point &point(const int v) const { return points_[v]; }
54 Point &point(const int v) { return points_[v]; }
55
57 int create_vertices(int n);
59 int create_vertex(const Point &p);
60
63 void bounding_box(Point &min, Point &max) const;
64
65 // -- Facets --------------------------------------------------------------
66
67 int n_facets() const { return int(facet_ptr_.size()) - 1; }
68 int n_facet_vertices(const int f) const { return facet_ptr_[f + 1] - facet_ptr_[f]; }
69 int facet_vertex(const int f, const int lv) const { return corner_vertex_[facet_ptr_[f] + lv]; }
70
71 int n_corners() const { return corner_vertex_.size(); }
72 int corners_begin(const int f) const { return facet_ptr_[f]; }
73 int corners_end(const int f) const { return facet_ptr_[f + 1]; }
74 int facet_corner(const int f, const int lv) const { return facet_ptr_[f] + lv; }
75 int corner_vertex(const int c) const { return corner_vertex_[c]; }
77 int corner_adjacent_facet(const int c) const { return corner_adjacent_facet_[c]; }
78 int next_corner_around_facet(const int f, const int c) const { return c + 1 == corners_end(f) ? corners_begin(f) : c + 1; }
79 int prev_corner_around_facet(const int f, const int c) const { return c == corners_begin(f) ? corners_end(f) - 1 : c - 1; }
80
82 int create_polygon(const std::vector<int> &vertices);
83
85 void flip_facet(int f);
86
88 void clear_facets();
89
92 void delete_facets(const std::vector<bool> &to_delete);
93
96 void connect_facets();
97
100 int connected_components(std::vector<int> &component) const;
101
102 // -- Edges (filled by Navigation::prepare_mesh) ---------------------------
103
104 int n_edges() const { return edges_.size(); }
105 int edge_vertex(const int e, const int lv) const { return edges_[e][lv]; }
106 int create_edge(int v0, int v1);
107 void clear_edges();
108
110 std::vector<int> corner_edge;
112 std::vector<bool> boundary_edge;
114 std::vector<bool> boundary_vertex;
115
116 private:
117 std::vector<Point> points_;
118 std::vector<int> facet_ptr_ = {0};
119 std::vector<int> corner_vertex_;
120 std::vector<int> corner_adjacent_facet_;
121 std::vector<std::array<int, 2>> edges_;
122 };
123} // namespace polyfem::mesh
int y
int z
int x
Minimal polygonal surface mesh used as the storage of CMesh2D.
std::vector< int > corner_vertex_
const Point & point(const int v) const
int corner_vertex(const int c) const
std::vector< Point > points_
int next_corner_around_facet(const int f, const int c) const
int corners_end(const int f) const
int facet_vertex(const int f, const int lv) const
int n_facet_vertices(const int f) const
std::vector< bool > boundary_edge
Whether each edge is on the boundary.
int edge_vertex(const int e, const int lv) const
std::vector< std::array< int, 2 > > edges_
int corner_adjacent_facet(const int c) const
Facet across the edge from corner c to the next corner of its facet, or -1.
std::vector< bool > boundary_vertex
Whether each vertex is on the boundary.
int facet_corner(const int f, const int lv) const
int prev_corner_around_facet(const int f, const int c) const
int corners_begin(const int f) const
Point & point(const int v)
std::vector< int > corner_edge
Index of the edge starting at each corner.
std::vector< int > corner_adjacent_facet_
Point operator/(const double s) const
Point & operator+=(const Point &v)
double operator[](const int i) const
Point(const double x, const double y, const double z)
Point operator-(const Point &v) const
Point operator+(const Point &v) const
friend Point operator*(const double s, const Point &v)
std::array< double, 3 > coords
double & operator[](const int i)