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
tilepyramidlayer.h
Go to the documentation of this file.
1
13#ifndef TILEPYRAMIDLAYER_H
14#define TILEPYRAMIDLAYER_H
15
17
18#include <QCache>
19#include <QHash>
20#include <QImage>
21#include <QMutex>
22#include <QPair>
23#include <QRectF>
24#include <QString>
25
47{
48 Q_OBJECT
49
50public:
51 explicit TilePyramidLayer(OpenSWMMVisWorkspace *parent = nullptr);
53
54protected:
59 struct TileDraw
60 {
61 QImage img;
62 QRectF src;
63 bool exact = false;
64 };
65
70 void cacheTile(const QString &key, const QImage &img,
71 const MapExtent &extent, int level);
72
75 [[nodiscard]] bool isTileCached(const QString &key) const;
76
78 [[nodiscard]] QImage cachedTileImage(const QString &key) const;
79
81 void clearTiles();
82
83 void setTileCacheCapacity(int maxTiles);
84 [[nodiscard]] int tileCacheCapacity() const;
85
97 [[nodiscard]] bool resolveTileForDraw(const QString &key,
98 const MapExtent &tileExtent,
99 double maxSpanRatio,
100 TileDraw &out) const;
101
102private:
103 struct CachedTile
104 {
105 QImage img;
106 MapExtent extent;
107 int level = 0;
108 };
109
110 mutable QMutex m_tileMutex;
111 QCache<QString, CachedTile> m_tileCache{256};
112 // extent/level side-index of the cache contents, iterated by the fallback
113 // search (QCache itself can't be walked without promoting entries).
114 // QCache evicts silently, so the index is pruned lazily on lookup misses
115 // and swept whenever it outgrows the cache capacity.
116 mutable QHash<QString, QPair<MapExtent, int>> m_tileIndex;
117
118 void pruneIndexLocked();
119};
120
121#endif // TILEPYRAMIDLAYER_H
An axis-aligned bounding box in the coordinate space of a given CRS.
Definition mapextent.h:26
Abstract base class for all layers displayed in the MapCanvas.
Definition openswmmvislayer.h:116
MapExtent extent() const
Returns the layer extent in the layer's own CRS.
Definition openswmmvislayer.cpp:252
Top-level project container managing sessions, the SWMM model layer, and persistence paths for one SW...
Definition openswmmvisworkspace.h:42
Base class owning the tile cache + parent-fallback compositor shared by tile-pyramid layers.
Definition tilepyramidlayer.h:47
void cacheTile(const QString &key, const QImage &img, const MapExtent &extent, int level)
Insert a produced tile (no-op for null images). extent is the tile's geographic extent in the subclas...
Definition tilepyramidlayer.cpp:18
~TilePyramidLayer() override
bool isTileCached(const QString &key) const
True when key holds a non-null cached tile. Does not promote the entry in the LRU.
Definition tilepyramidlayer.cpp:30
int tileCacheCapacity() const
Definition tilepyramidlayer.cpp:56
bool resolveTileForDraw(const QString &key, const MapExtent &tileExtent, double maxSpanRatio, TileDraw &out) const
Resolve the image + source sub-rect that should paint the tile key with geographic extent tileExtent.
Definition tilepyramidlayer.cpp:75
void setTileCacheCapacity(int maxTiles)
Definition tilepyramidlayer.cpp:50
void clearTiles()
Drop every cached tile (style / CRS / source change).
Definition tilepyramidlayer.cpp:43
QImage cachedTileImage(const QString &key) const
The cached image for key, or a null QImage.
Definition tilepyramidlayer.cpp:36
const char * key
Definition meshcellparams.cpp:24
Abstract base class for all map layers displayed in the MapCanvas.
QVector< int > parent
union-find
Definition pslgminsize.cpp:176
A resolved per-tile draw: paint src (a sub-rect of img, in image pixels with row 0 = the tile extent'...
Definition tilepyramidlayer.h:60
QImage img
Definition tilepyramidlayer.h:61
QRectF src
Definition tilepyramidlayer.h:62
bool exact
Definition tilepyramidlayer.h:63