23#ifndef OPENSWMMVIS_MESH_MESHCELLGEOM_H
24#define OPENSWMMVIS_MESH_MESHCELLGEOM_H
50 const int nv =
t.vertexCount();
51 a =
t.vertex((
k + 1) %
nv);
52 b =
t.vertex((
k + 2) %
nv);
69 const float *flux,
const float *
length,
70 const float *
nx,
const float *
ny,
71 double &qx,
double &qy)
noexcept
73 constexpr double kQMax = 10.0;
74 double a00 = 0.0, a01 = 0.0, a11 = 0.0;
75 double b0 = 0.0, b1 = 0.0;
76 for (
int e = 0;
e <
nv; ++
e) {
79 if (
len <= 1
e-12)
continue;
81 if (!std::isfinite(q))
continue;
82 if (q > kQMax) q = kQMax;
83 if (q < -kQMax) q = -kQMax;
84 const double enx =
nx[idx], eny =
ny[idx];
91 const double det = a00 * a11 - a01 * a01;
94 if (!(std::abs(det) >= 1
e-12))
return false;
95 const double inv_det = 1.0 / det;
96 qx = ( a11 * b0 - a01 * b1) * inv_det;
97 qy = (-a01 * b0 + a00 * b1) * inv_det;
108 std::array<std::array<int, 3>, 2>
sub{};
124 auto triArea = [&](
int a,
int b,
int c) {
125 const QPointF &A = vertices[
a].xy, &B = vertices[
b].xy, &C = vertices[c].xy;
126 return 0.5 * std::abs((B.x() - A.x()) * (C.y() - A.y()) - (C.x() - A.x()) * (B.y() - A.y()));
128 auto triCentroid = [&](
int a,
int b,
int c) {
129 const QPointF &A = vertices[
a].xy, &B = vertices[
b].xy, &C = vertices[c].xy;
130 return QPointF((A.x() + B.x() + C.x()) / 3.0, (A.y() + B.y() + C.y()) / 3.0);
134 g.
sub[0] = {
t.v0,
t.v1,
t.v2};
135 g.
area = triArea(
t.v0,
t.v1,
t.v2);
137 g.
zMean = (vertices[
t.v0].z + vertices[
t.v1].z + vertices[
t.v2].z) / 3.0;
140 const int v[4] = {
t.v0,
t.v1,
t.v2,
t.v3};
142 int p[4] = {0, 1, 2, 3};
143 for (
int i = 1;
i < 4; ++
i) {
144 const int key =
p[
i];
146 while (j >= 0 && vertices[
v[
p[j]]].z > vertices[
v[
key]].z) {
p[j + 1] =
p[j]; --j; }
149 const int n1 =
p[0], n2 =
p[1], n3 =
p[2], n4 =
p[3];
150 auto adjacent = [](
int a,
int b) {
const int d = (
a -
b + 4) % 4;
return d == 1 || d == 3; };
152 if (!adjacent(n1, n4)) { g.
diagCase = 1;
t1[0]=n1;
t1[1]=n2;
t1[2]=n4;
t2[0]=n1;
t2[1]=n3;
t2[2]=n4; }
153 else if (adjacent(n2, n1)) { g.
diagCase = 2;
t1[0]=n1;
t1[1]=n2;
t1[2]=n4;
t2[0]=n2;
t2[1]=n3;
t2[2]=n4; }
158 const double a1 = triArea(g.
sub[0][0], g.
sub[0][1], g.
sub[0][2]);
159 const double a2 = triArea(g.
sub[1][0], g.
sub[1][1], g.
sub[1][2]);
161 const QPointF c1 = triCentroid(g.
sub[0][0], g.
sub[0][1], g.
sub[0][2]);
162 const QPointF c2 = triCentroid(g.
sub[1][0], g.
sub[1][1], g.
sub[1][2]);
164 ? QPointF((a1 * c1.x() + a2 * c2.x()) / g.
area, (a1 * c1.y() + a2 * c2.y()) / g.
area)
165 : QPointF((vertices[
t.v0].xy + vertices[
t.v1].xy + vertices[
t.v2].xy + vertices[
t.v3].xy) / 4.0);
166 g.
zMean = (vertices[
t.v0].z + vertices[
t.v1].z + vertices[
t.v2].z + vertices[
t.v3].z) / 4.0;
173 const int nv =
t.vertexCount();
175 for (
int k = 0;
k <
nv; ++
k) {
176 const QPointF &
a = vertices[
t.vertex(
k)].xy, &
b = vertices[
t.vertex((
k + 1) %
nv)].xy;
177 s +=
a.x() *
b.y() -
b.x() *
a.y();
186 if (!
t.isQuad())
return true;
188 for (
int k = 0;
k < 4; ++
k) {
189 const QPointF &
p = vertices[
t.vertex(
k)].xy;
190 const QPointF &q = vertices[
t.vertex((
k + 1) % 4)].xy;
191 const QPointF &r = vertices[
t.vertex((
k + 2) % 4)].xy;
192 const double cr = (q.x() -
p.x()) * (r.y() - q.y()) - (q.y() -
p.y()) * (r.x() - q.x());
193 const int s = (cr > 0.0) ? 1 : (cr < 0.0) ? -1 : 0;
194 if (
s == 0 || (sign != 0 &&
s != sign))
return false;
202 const QPointF &
p,
double eps = 0.0) noexcept
205 for (
int s = 0;
s < g.
nSub; ++
s) {
206 const QPointF &
a = vertices[g.
sub[
s][0]].xy, &
b = vertices[g.
sub[
s][1]].xy,
207 &c = vertices[g.
sub[
s][2]].xy;
208 const double d = (
b.y() - c.y()) * (
a.x() - c.x()) + (c.x() -
b.x()) * (
a.y() - c.y());
209 if (std::abs(d) < 1
e-300)
continue;
210 const double l1 = ((
b.y() - c.y()) * (
p.x() - c.x()) + (c.x() -
b.x()) * (
p.y() - c.y())) / d;
211 const double l2 = ((c.y() -
a.y()) * (
p.x() - c.x()) + (
a.x() - c.x()) * (
p.y() - c.y())) / d;
212 const double l3 = 1.0 - l1 - l2;
213 if (l1 >= -eps && l2 >= -eps && l3 >= -eps)
return true;
size_t i
Definition contourjob.cpp:27
DiagramType t
Definition diagramspec.cpp:20
double s
Scene px per model length unit.
Definition inletdrawingview.cpp:82
int e
Definition inpmeshreader.cpp:41
ArrowPlacement p
Definition linesymbollayer.cpp:27
std::vector< double > nx
Definition mesh2dresultsexport.cpp:448
std::vector< double > ny
Definition mesh2dresultsexport.cpp:448
std::vector< double > len
Definition mesh2dresultsexport.cpp:448
int k
Definition mesh2dresultsexport.cpp:549
std::vector< int > cell
Definition mesh2dresultsexport.cpp:609
const char * key
Definition meshcellparams.cpp:24
int nv
Definition meshenginesync.cpp:32
double length
Definition meshpatch.cpp:64
int b
local residual indices, a < b
Definition meshquadmatch.cpp:46
int t1
Definition meshquadmatch.cpp:40
int a
Definition meshquadmatch.cpp:46
int t2
Definition meshquadmatch.cpp:40
Definition meshcommands.h:302
bool cellContains(const QVector< MeshVertex > &vertices, const MeshTriangle &t, const QPointF &p, double eps=0.0) noexcept
Point-in-cell test on the sub-triangle fan (barycentric per sub-triangle).
Definition meshcellgeom.h:201
void edgeEndpoints(const MeshTriangle &t, int k, int &a, int &b) noexcept
Definition meshcellgeom.h:48
bool rt0CellDischarge(int cell, int nv, const float *flux, const float *length, const float *nx, const float *ny, double &qx, double &qy) noexcept
RT0 least-squares specific discharge (m²/s) of one cell from its outward-positive normal edge fluxes ...
Definition meshcellgeom.h:68
CellGeom cellGeom(const QVector< MeshVertex > &vertices, const MeshTriangle &t)
Geometry of cell t against vertices.
Definition meshcellgeom.h:121
constexpr int edgeSlot(int cell, int e) noexcept
Definition meshcellgeom.h:40
constexpr int kEdgeStride
Definition meshcellgeom.h:37
double cellSignedArea(const QVector< MeshVertex > &vertices, const MeshTriangle &t) noexcept
Signed area of the polygon (positive = counter-clockwise).
Definition meshcellgeom.h:171
bool cellIsConvex(const QVector< MeshVertex > &vertices, const MeshTriangle &t) noexcept
Convexity test for a quad (every consecutive cross product has the same non-zero sign)....
Definition meshcellgeom.h:184
constexpr int slotLocal(int slot) noexcept
Definition meshcellgeom.h:43
constexpr int slotCell(int slot) noexcept
Definition meshcellgeom.h:42
constexpr int edgeSlotCount(int nCells) noexcept
Definition meshcellgeom.h:45
QVector< int > v
pool vertex indices
Definition pslgminsize.cpp:159
Per-cell derived geometry shared by every consumer.
Definition meshcellgeom.h:103
double zMean
mean of the vertex elevations
Definition meshcellgeom.h:106
std::array< std::array< int, 3 >, 2 > sub
sub-triangle vertex indices
Definition meshcellgeom.h:108
QPointF centroid
AREA centroid (not the vertex mean for a quad)
Definition meshcellgeom.h:105
int diagCase
B&S 2007 case (1..3) for a quad; 0 for a triangle.
Definition meshcellgeom.h:109
int nSub
sub-triangles: 1 (triangle) or 2 (quad)
Definition meshcellgeom.h:107
double area
planimetric (map units²)
Definition meshcellgeom.h:104
A cell in the mesh — a triangle or (since the engine's mixed tri-quad meshes, workplans/TRI_QUAD_MESH...
Definition meshresult.h:54
double
Definition swmmpollutantpropertyadapter.cpp:50