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
swmm2dresultsqsgrenderer.h
Go to the documentation of this file.
1
56#ifndef SWMM2DRESULTSQSGRENDERER_H
57#define SWMM2DRESULTSQSGRENDERER_H
58
59#include "map/mapextent.h"
60#include "render/contourjob.h"
66
67#include <QFutureWatcher>
68#include <QHash>
69#include <QImage>
70#include <QPointer>
71#include <QQuickItem>
72#include <QRectF>
73#include <QSet>
74#include <QString>
75
76#include <limits>
77#include <memory>
78#include <vector>
79
80class QSGTexture;
82
83namespace OpenSWMM::Contour {
84struct IsoBandPolygon;
85struct IsoLineSegment;
86}
87
88class SWMM2DResultsQSGRenderer : public QQuickItem
89{
90 Q_OBJECT
91
92public:
93 explicit SWMM2DResultsQSGRenderer(QQuickItem *parent = nullptr);
95
96 void setLayer(SWMM2DResultsLayer *layer);
97 void setMapExtent(const MapExtent &extent);
98
101 void forceRebuild();
102
109 [[nodiscard]] quint64 contentRevision() const noexcept
110 { return m_contentRev; }
111
112signals:
119
120protected:
121 QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override;
122
123private:
126 void noteContentChanged() { ++m_contentRev; update(); }
127
128 QPointer<SWMM2DResultsLayer> m_layer;
129 quint64 m_contentRev = 0;
130 MapExtent m_extent;
131
132 // Fixed scene-space anchor (bbox centre) — keeps float vertex coords
133 // small even in UTM coordinates; stable across pans. Recomputed only
134 // when the geometry domain is dirty.
135 double m_anchorX = 0.0;
136 double m_anchorY = 0.0;
137
138 // ── QSG-2D-1M dirty/LOD state ──────────────────────────────────────
140
143 quint64 m_builtLodKey = ~quint64(0);
144 QRectF m_builtCoverage;
145 int m_lastBucket = -1;
146 int m_lastZoomStep = std::numeric_limits<int>::min();
147
149 quint64 m_lastGeomRev = ~quint64(0);
150 QSet<int> m_lastHighlight;
151
155 int m_lastRenderedTime = -1;
156
159 quint64 m_chunksRev = ~quint64(0);
160
164
167 enum class SmoothFillMode { VertexColor, Shader };
168 SmoothFillMode m_smoothFillMode = SmoothFillMode::VertexColor;
169
172 QImage m_smoothLutImage;
173
174 // ── Phase 7: async contour recomputation ───────────────────────────
177 struct ContourJobKey
178 {
179 int time = -1;
180 double lo = 0.0;
181 double hi = 0.0;
182 int bandCount = -1;
183 quint64 paramsRev = 0;
184 size_t tris = 0;
185 quint64 geomRev = ~quint64(0);
186 bool valid = false;
187 bool operator==(const ContourJobKey &o) const
188 {
189 return valid == o.valid && time == o.time && lo == o.lo
190 && hi == o.hi && bandCount == o.bandCount
191 && paramsRev == o.paramsRev && tris == o.tris
192 && geomRev == o.geomRev;
193 }
194 bool operator!=(const ContourJobKey &o) const { return !(*this == o); }
195 };
196
197 struct AsyncContourJob
198 {
201 quint64 inflightGen = 0;
202 ContourJobKey inflightKey;
203 ContourJobKey publishedKey;
204 bool relaunch = false;
205 };
206 AsyncContourJob m_bandJob;
207 AsyncContourJob m_isoJob;
208
210 std::shared_ptr<const std::vector<OpenSWMM::Render::ContourJobInput::TriPos>>
211 m_contourPositions;
212 quint64 m_contourPositionsRev = ~quint64(0);
213
215 std::shared_ptr<const std::vector<std::array<float, 3>>> m_contourScalars;
216 int m_contourScalarsTime = -1;
217 quint64 m_contourScalarsGeomRev = ~quint64(0);
218
219 void setupAsyncContourJob(AsyncContourJob &job);
220
221 // ── Isoline-label texture cache ────────────────────────────────────
222 // Keyed by "text|fontPt|halo|color" so style edits re-rasterise.
223 // QSGTexture ownership is ours; released via deleteLater() (textures
224 // must die on the render thread).
225 mutable QHash<QString, QSGTexture *> m_labelTextureCache;
226 void clearLabelTextureCache();
227
228 // ── Per-frame contour geometry caches ──────────────────────────────
229 // Marching output depends on the depth frame + classification params
230 // but is invariant under pan/zoom, so ticks rebuild and interactions
231 // reuse. Key: (time index, range, level params, triangle count).
232 int m_bandCacheTime = -1;
233 double m_bandCacheLo = 0.0;
234 double m_bandCacheHi = 0.0;
235 int m_bandCacheCount = -1;
236 size_t m_bandCacheTris = 0;
237 quint64 m_bandCacheRev = 0;
238 std::vector<OpenSWMM::Contour::IsoBandPolygon> m_cachedBands;
239
240 int m_isoCacheTime = -1;
241 double m_isoCacheLo = 0.0;
242 double m_isoCacheHi = 0.0;
243 quint64 m_isoCacheParams = 0;
244 size_t m_isoCacheTris = 0;
245 std::vector<OpenSWMM::Contour::IsoLineSegment> m_cachedSegs;
246};
247
248#endif // SWMM2DRESULTSQSGRENDERER_H
An axis-aligned bounding box in the coordinate space of a given CRS.
Definition mapextent.h:26
Definition meshrenderchunkindex.h:43
Definition meshstaticgeometrybuffers.h:51
Definition qsg2dasyncresult.h:42
Definition qsg2ddirtystate.h:55
Definition maptoolselectprofile.h:37
Definition swmm2dresultslayer.h:550
Definition swmm2dresultsqsgrenderer.h:89
~SWMM2DResultsQSGRenderer() override
Definition swmm2dresultsqsgrenderer.cpp:390
quint64 contentRevision() const noexcept
Definition swmm2dresultsqsgrenderer.h:109
void setMapExtent(const MapExtent &extent)
Definition swmm2dresultsqsgrenderer.cpp:455
QSGNode * updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override
Definition swmm2dresultsqsgrenderer.cpp:482
void setLayer(SWMM2DResultsLayer *layer)
Definition swmm2dresultsqsgrenderer.cpp:402
void forceRebuild()
Definition swmm2dresultsqsgrenderer.cpp:469
Axis-aligned bounding box in a map coordinate system, used by MapCanvas and all layer types to define...
Definition contourchain.h:23
bool operator==(const InletDesignData &a, const InletDesignData &b)
Field-by-field equality — used by setDesign to suppress no-op notifications and by the undo commands ...
Definition inletprovider.cpp:11
bool operator!=(const InletDesignData &a, const InletDesignData &b)
Definition inletprovider.h:157
QVector< int > parent
union-find
Definition pslgminsize.cpp:176