Enmesh
Loading...
Searching...
No Matches
triangle.h
1#ifndef TRIANGLE_H
2#define TRIANGLE_H
3
4#include <vector>
5#include <array>
6#include <iostream>
7#include <cmath>
8#include <unordered_set>
9#include <unordered_map>
10#include <fstream>
11#include <sstream>
12#include <string>
13#include <algorithm>
14
15
16#include "geometry/point.h"
17#include "geometry/edge.h"
18
19namespace Enmesh {
20
25struct Triangle {
26
27 static constexpr size_t elementType = 2;
28 static constexpr size_t numVertices = 3;
29
30 std::array<size_t, 3> v;
31 bool isBad = false;
32
33
39 bool containsEdge(size_t v1, size_t v2) const;
40
41
48 bool containsPoint(const std::vector<Point>& vertices, const Point& point);
49
56 bool operator==(const Triangle& other) const {
57 std::array<size_t, 3> sortedV1 = v;
58 std::array<size_t, 3> sortedV2 = other.v;
59 std::sort(sortedV1.begin(), sortedV1.end());
60 std::sort(sortedV2.begin(), sortedV2.end());
61 return sortedV1 == sortedV2;
62 }
63
64};
65
66
69 size_t operator()(const Triangle& triangle) const {
70 // Combine the hashes of the three vertex indices to create a unique hash for the triangle
71 size_t h = std::hash<size_t>{}(triangle.v[0]);
72 h ^= std::hash<size_t>{}(triangle.v[1]) + 0x9e3779b9 + (h << 6) + (h >> 2); // Combine with the second vertex index
73 h ^= std::hash<size_t>{}(triangle.v[2]) + 0x9e3779b9 + (h << 6) + (h >> 2); // Combine with the third vertex index
74 return h;
75 }
76};
77
78} // namespace Enmesh
79
80#endif
A struct representing a point in 3D space.
Definition point.h:15
A hash function for triangles.
Definition triangle.h:68
A struct representing a triangle in the mesh.
Definition triangle.h:25
bool operator==(const Triangle &other) const
Overload the == operator to compare two triangles based on their vertex indices.
Definition triangle.h:56
std::array< size_t, 3 > v
Indices of the vertices that form the triangle.
Definition triangle.h:30
static constexpr size_t elementType
Gmsh element type for triangles.
Definition triangle.h:27
bool isBad
Flag used in Delaunay triangulation to mark triangles that need to be removed.
Definition triangle.h:31
bool containsEdge(size_t v1, size_t v2) const
Check if the circum circle of the triangle contains a specific edge defined by two vertex indices.
Definition triangle.cpp:5
bool containsPoint(const std::vector< Point > &vertices, const Point &point)
Check if the circum circle of the triangle contains a specific point.
Definition triangle.cpp:12
static constexpr size_t numVertices
Number of vertices in a triangle.
Definition triangle.h:28