SWMMVis  6.0.0-alpha.4
Qt6/C++ GIS-based graphical user interface for the SWMMVis engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
marchingtriangles.h File Reference
#include <QColor>
#include <QPointF>
#include <algorithm>
#include <vector>
Include dependency graph for marchingtriangles.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  OpenSWMM::Contour::IsoLineSegment
 A single contour iso-line segment in scene space. More...
 
struct  OpenSWMM::Contour::IsoBandPolygon
 One filled-isoband polygon in scene space. Convex (Sutherland- Hodgman of a triangle yields a convex polygon with ≤ 5 vertices). More...
 

Namespaces

namespace  OpenSWMM
 
namespace  OpenSWMM::Contour
 
namespace  OpenSWMM::Contour::detail
 

Functions

QColor OpenSWMM::Contour::viridisAt (double t)
 Sample a 5-stop Viridis-inspired colour ramp at t in [0, 1].
 
template<typename TriRange , typename Extract >
std::vector< IsoLineSegmentOpenSWMM::Contour::marchingTriangles (const TriRange &tris, const std::vector< double > &levels, Extract extract)
 Generate iso-line segments for every (triangle, level) pair where the level crosses the triangle's value range.
 
std::vector< doubleOpenSWMM::Contour::evenlySpacedLevels (double vMin, double vMax, int count)
 Convenience helper that generates N evenly-spaced contour levels between vMin and vMax (exclusive of the endpoints).
 
std::vector< doubleOpenSWMM::Contour::evenlySpacedLevelsInclusive (double vMin, double vMax, int levelCount)
 Convenience helper that returns levelCount evenly-spaced break levels INCLUSIVE of both endpoints (vMin and vMax).
 
void OpenSWMM::Contour::detail::clipHalfplane (const std::vector< QPointF > &inPts, const std::vector< double > &inVals, double L, bool keepAbove, std::vector< QPointF > &outPts, std::vector< double > &outVals)
 Sutherland-Hodgman clip of a convex polygon against the half-plane defined by value >= L (when keepAbove) or value <= L (else).
 
template<typename TriRange , typename Extract >
std::vector< IsoBandPolygonOpenSWMM::Contour::marchingTrianglesIsobands (const TriRange &tris, const std::vector< double > &levels, Extract extract, bool clampUniformOutsideRange=true)
 Generate filled iso-band polygons for every (triangle, band) pair.
 

Detailed Description

Author
Caleb Buahin caleb.nosp@m..bua.nosp@m.hin@g.nosp@m.mail.nosp@m..com
Date
2026
License\n GPL-3.0-or-later

Slice BJ.2-lite — marching-triangles contour line extraction.

Per triangle and per contour level, the algorithm classifies each vertex as below/above the level (8 cases, 6 of which produce a single line segment crossing two edges). Linear-interpolation on the two edges with sign changes gives the iso-line segment endpoints.

The triangle iterator is templated so we don't tie the algorithm to any specific mesh type: callers pass a forward range of triangles plus a functor that extracts (p0, p1, p2, v0, v1, v2) per triangle. This lets SWMM2DMeshLayer feed its existing SceneTri cache directly, and lets the follow-up result-attribute slice swap the scalar source without touching the algorithm.

Output is a flat std::vector<IsoLineSegment> in scene space, suitable for QSG line-list upload (every two consecutive points = one segment).

Out-of-scope for the lite cut (deferred to follow-ups):

  • filled iso-bands (polygonisation between adjacent levels)
  • viewport / LOD culling (passed-in triangle range is iterated whole)
  • per-level pen / colour overrides (caller assigns)
  • contour labels (waits for BI.2 LabelExpression)
  • raster (marching squares — separate algorithm)