30 #include "MeshKernel/Constants.hpp"
31 #include "MeshKernel/Entities.hpp"
32 #include "MeshKernel/Exceptions.hpp"
33 #include "MeshKernel/Point.hpp"
34 #include "MeshKernel/PolygonalEnclosure.hpp"
46 double const*
const xs,
47 double const*
const ys,
81 template <std::derived_from<Po
int> T>
82 void Compute(
const std::vector<T>& inputNodes,
84 double averageTriangleArea,
85 UInt estimatedNumberOfTriangles)
87 if (inputNodes.empty())
91 std::vector<double> xLocalPolygon(inputNodes.size());
92 std::vector<double> yLocalPolygon(inputNodes.size());
93 for (
UInt i = 0; i < inputNodes.size(); ++i)
95 xLocalPolygon[i] = inputNodes[i].x;
96 yLocalPolygon[i] = inputNodes[i].y;
103 int numInputNodes =
static_cast<int>(inputNodes.size());
104 auto intTriangulationOption =
static_cast<int>(triangulationOption);
106 if (estimatedNumberOfTriangles == 0)
108 estimatedNumberOfTriangles =
static_cast<UInt>(inputNodes.size()) * 6 + 10;
112 while (m_numFaces < 0)
114 m_numFaces =
static_cast<int>(estimatedNumberOfTriangles);
116 m_faceNodesFlat.resize(estimatedNumberOfTriangles * 3);
117 std::ranges::fill(m_faceNodesFlat, 0);
119 m_edgeNodesFlat.resize(estimatedNumberOfTriangles * 2);
120 std::ranges::fill(m_edgeNodesFlat, 0);
122 m_faceEdgesFlat.resize(estimatedNumberOfTriangles * 3);
123 std::ranges::fill(m_faceEdgesFlat, 0);
125 m_xCoordFlat.resize(estimatedNumberOfTriangles * 3, constants::missing::doubleValue);
126 std::ranges::fill(m_xCoordFlat, 0.0);
128 m_yCoordFlat.resize(estimatedNumberOfTriangles * 3, constants::missing::doubleValue);
129 std::ranges::fill(m_yCoordFlat, 0.0);
132 xLocalPolygon.data(),
133 yLocalPolygon.data(),
135 m_faceNodesFlat.data(),
137 m_edgeNodesFlat.data(),
139 m_faceEdgesFlat.data(),
143 averageTriangleArea);
144 if (estimatedNumberOfTriangles > 0)
146 estimatedNumberOfTriangles = -m_numFaces;
180 [[nodiscard]]
const std::vector<Point>&
GetNodes()
const
190 return m_faceNodes[faceIndex];
199 return m_faceNodes[faceIndex][nodeIndex];
208 return m_faceEdges[faceIndex][edgeIndex];
217 return m_edgeNodes[edgeIndex][nodeIndex];
226 return m_edgesFaces[edgeIndex][faceIndex];
234 return m_xCoordFlat[nodeIndex];
242 return m_yCoordFlat[nodeIndex];
250 return Point(m_xCoordFlat[nodeIndex], m_yCoordFlat[nodeIndex]);
254 std::vector<int> m_faceNodesFlat;
255 std::vector<int> m_edgeNodesFlat;
256 std::vector<int> m_faceEdgesFlat;
257 std::vector<double> m_xCoordFlat;
258 std::vector<double> m_yCoordFlat;
263 std::vector<Point> m_nodes;
264 std::vector<std::vector<UInt>> m_faceNodes;
265 std::vector<std::vector<UInt>> m_faceEdges;
266 std::vector<std::vector<UInt>> m_edgeNodes;
267 std::vector<std::vector<UInt>> m_edgesFaces;
@ TriangulatePointsAndGenerateFaces
generate Delaunay triangulation from input nodes with m_faceEdges and m_edgeNodes
UInt GetFaceEdge(const UInt faceIndex, const UInt edgeIndex) const
Retrieves the face edge.
Definition: TriangulationWrapper.hpp:206
@ GeneratePoints
generate internal nodes in polygon that produce a Delaunay triangulation
std::vector< Point > SelectNodes(const PolygonalEnclosure &enclosure) const
From the set of computed points, select those that are contained within the enclosure.
void BuildTriangulation()
Build the internal triangulation from the flat triangulation.
@ TriangulatePoints
generate Delaunay triangulation from input nodes
A struct describing a point in a two-dimensional space.
Definition: Point.hpp:40
Point GetCoord(const UInt nodeIndex) const
Retrieves the (x,y) coordinate of a triangulated node.
Definition: TriangulationWrapper.hpp:248
UInt GetEdgeFace(const UInt edgeIndex, const UInt faceIndex) const
Retrieves the edge face.
Definition: TriangulationWrapper.hpp:224
TriangulationOptions
Enumerator describing all triangulation options.
Definition: TriangulationWrapper.hpp:68
double GetXCoord(const UInt nodeIndex) const
Retrieves the x coordinate of a triangulated node.
Definition: TriangulationWrapper.hpp:232
int GetNumFaces() const
Gets the number of triangulated faces.
Definition: TriangulationWrapper.hpp:173
double GetYCoord(const UInt nodeIndex) const
Retrieves the y coordinate of a triangulated node.
Definition: TriangulationWrapper.hpp:240
Wrapper around the Triangle library.
Definition: TriangulationWrapper.hpp:65
UInt GetFaceNode(const UInt faceIndex, const UInt nodeIndex) const
Retrieves the face node.
Definition: TriangulationWrapper.hpp:197
void Compute(const std::vector< T > &inputNodes, TriangulationOptions triangulationOption, double averageTriangleArea, UInt estimatedNumberOfTriangles)
Compute the triangulation.
Definition: TriangulationWrapper.hpp:82
Contains the logic of the C++ static library.
Definition: AveragingInterpolation.hpp:36
A region enclosed by a polygonal permieter.
Definition: PolygonalEnclosure.hpp:45
std::uint32_t UInt
Integer type used when indexing mesh graph entities.
Definition: Definitions.hpp:38
const std::vector< UInt > & GetFaceNodes(const UInt faceIndex) const
Gets the nodes of a triangulated face.
Definition: TriangulationWrapper.hpp:188
void Triangulation(int jatri, double const *const xs, double const *const ys, int ns, int *const indx, int *const numtri, int *const edgeidx, int *const numedge, int *const triedge, double *const xs3, double *const ys3, int *const ns3, double trisize)
Function of the Triangle library.
int GetNumNodes() const
Gets the number of triangulated nodes.
Definition: TriangulationWrapper.hpp:166
An exception class thrown when an attempt is made that violates a range constraint.
Definition: Exceptions.hpp:266
const std::vector< Point > & GetNodes() const
Gets the triangulated nodes.
Definition: TriangulationWrapper.hpp:180
UInt GetEdgeNode(const UInt edgeIndex, const UInt nodeIndex) const
Retrieves the edge node.
Definition: TriangulationWrapper.hpp:215
int GetNumEdges() const
Gets the number of triangulated edges.
Definition: TriangulationWrapper.hpp:159