8 inline std::pair<int, int>
makeEdge(
const int i1,
const int i2) {
9 return std::make_pair(
min(i1, i2),
max(i1, i2));
14 for (
Size i = 0; i < mesh.
faces.size(); ++i) {
21 for (
auto& p : edges) {
22 if (p.second.size() != 2) {
31 for (
Size i = 0; i < mesh.
faces.size(); ++i) {
33 vertexNeighs[f[0]].
insert(f[1]);
34 vertexNeighs[f[0]].
insert(f[2]);
35 vertexNeighs[f[1]].
insert(f[0]);
36 vertexNeighs[f[1]].
insert(f[2]);
37 vertexNeighs[f[2]].
insert(f[0]);
38 vertexNeighs[f[2]].
insert(f[1]);
45 for (
Size j : vertexNeighs[i]) {
62 const Vector p12 = 0.5_f * (p1 + p2);
63 const Vector p13 = 0.5_f * (p1 + p3);
64 const Vector p23 = 0.5_f * (p2 + p3);
65 const Size i2 = face[1];
66 const Size i3 = face[2];
68 const Size i13 = i12 + 1;
69 const Size i23 = i12 + 2;
80 mesh.
faces.pushAll(std::move(newFaces));
88 Order lexicographicalOrder(triangles.
size() * 3);
89 lexicographicalOrder.
shuffle([&triangles](
const Size i1,
const Size i2) {
90 const Vector v1 = triangles[i1 / 3][i1 % 3];
91 const Vector v2 = triangles[i2 / 3][i2 % 3];
100 insertedVerticesIdxs.
fill(
Size(-1));
102 for (
Size i = 0; i < triangles.
size(); ++i) {
104 for (
Size j = 0; j < 3; ++j) {
106 const Size idxInSorted = mappingOrder[3 * i + j];
108 bool vertexFound =
false;
110 auto check = [&](
const Size k) {
111 const Size idxInInput = lexicographicalOrder[k];
112 const Vector v = triangles[idxInInput / 3][idxInInput % 3];
114 if (insertedVerticesIdxs[idxInInput] !=
Size(-1)) {
116 mesh.
faces[i][j] = insertedVerticesIdxs[idxInInput];
118 insertedVerticesIdxs[3 * i + j] = insertedVerticesIdxs[idxInInput];
131 for (
Size k = idxInSorted + 1; k < lexicographicalOrder.
size(); ++k) {
138 for (
int k = idxInSorted - 1; k >= 0; --k) {
147 insertedVerticesIdxs[3 * i + j] = mesh.
vertices.size();
158 for (
Size i = 0; i < mesh.
faces.size(); ++i) {
160 if (f[0] == f[1] || f[1] == f[2] || f[0] == f[2]) {
164 mesh.
faces.remove(toRemove);
171 for (
Size i = 0; i < mesh.
faces.size(); ++i) {
INLINE bool almostEqual(const AffineMatrix &m1, const AffineMatrix &m2, const Float eps=EPS)
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
constexpr INLINE T max(const T &f1, const T &f2)
NAMESPACE_SPH_BEGIN constexpr INLINE T min(const T &f1, const T &f2)
Minimum & Maximum value.
void refineMesh(Mesh &mesh)
Improves mesh quality using edge flips (valence equalization) and tangential relaxation.
bool isMeshClosed(const Mesh &mesh)
Checks if the mesh represents a single closed surface.
void subdivideMesh(Mesh &mesh)
Subdivides all triangles of the mesh using 1-4 scheme.
NAMESPACE_SPH_BEGIN std::pair< int, int > makeEdge(const int i1, const int i2)
Mesh getMeshFromTriangles(ArrayView< const Triangle > triangles, const Float eps)
Converts array of triangles into a mesh.
Array< Triangle > getTrianglesFromMesh(const Mesh &mesh)
Expands the mesh into an array of triangles.
#define NAMESPACE_SPH_END
Helper object defining permutation.
INLINE bool lexicographicalLess(const Vector &v1, const Vector &v2)
Compares components of two vectors lexicographically, primary component is z.
Object providing safe access to continuous memory of data.
INLINE TCounter size() const
INLINE void push(U &&u)
Adds new element to the end of the array, resizing the array if necessary.
void fill(const T &t)
Sets all elements of the array to given value.
void insert(const TCounter position, U &&value)
Inserts a new element to given position in the array.
INLINE TCounter size() const noexcept
Permutation, i.e. (discrete) invertible function int->int.
void shuffle(TBinaryPredicate &&predicate)
Shuffles the order using a binary predicate.
Order getInverted() const
Returns the inverted order.