mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-03-13 18:47:45 +01:00
Only render the levels that need to be rendered
This commit is contained in:
parent
3804e8ca7c
commit
d91acb66f2
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#define CATACH 8
|
#define CATACH 8
|
||||||
#define CATBUA 10
|
#define CATBUA 10
|
||||||
|
#define CATCOV 18
|
||||||
#define CATDIS 21
|
#define CATDIS 21
|
||||||
#define CATHAF 30
|
#define CATHAF 30
|
||||||
#define CATLMK 35
|
#define CATLMK 35
|
||||||
|
@ -425,6 +425,8 @@ MapData::Poly::Poly(uint type, const Polygon &path, const Attributes &attr,
|
|||||||
subtype = CATMFA;
|
subtype = CATMFA;
|
||||||
else if (type == I_BERTHS)
|
else if (type == I_BERTHS)
|
||||||
subtype = I_CATBRT;
|
subtype = I_CATBRT;
|
||||||
|
else if (type == M_COVR)
|
||||||
|
subtype = CATCOV;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case DEPARE:
|
case DEPARE:
|
||||||
|
@ -257,17 +257,15 @@ void RasterTile::drawSectorLights(QPainter *painter,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterTile::processPoints(QList<Data::Point> &points,
|
void RasterTile::processPoints(const QList<Data::Point> &points,
|
||||||
QList<TextItem*> &textItems, QList<TextItem*> &lights,
|
QList<TextItem*> &textItems, QList<TextItem*> &lights,
|
||||||
QList<SectorLight> §orLights, bool overZoom)
|
QList<SectorLight> §orLights, bool overZoom) const
|
||||||
{
|
{
|
||||||
LightMap lightsMap;
|
LightMap lightsMap;
|
||||||
SignalSet signalsSet;
|
SignalSet signalsSet;
|
||||||
QSet<Coordinates> slMap;
|
QSet<Coordinates> slMap;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
std::sort(points.begin(), points.end());
|
|
||||||
|
|
||||||
/* Lights & Signals */
|
/* Lights & Signals */
|
||||||
for (i = 0; i < points.size(); i++) {
|
for (i = 0; i < points.size(); i++) {
|
||||||
const Data::Point &point = points.at(i);
|
const Data::Point &point = points.at(i);
|
||||||
@ -328,7 +326,7 @@ void RasterTile::processPoints(QList<Data::Point> &points,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RasterTile::processLines(const QList<Data::Line> &lines,
|
void RasterTile::processLines(const QList<Data::Line> &lines,
|
||||||
QList<TextItem*> &textItems)
|
QList<TextItem*> &textItems) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < lines.size(); i++) {
|
for (int i = 0; i < lines.size(); i++) {
|
||||||
const Data::Line &line = lines.at(i);
|
const Data::Line &line = lines.at(i);
|
||||||
@ -351,19 +349,45 @@ void RasterTile::processLines(const QList<Data::Line> &lines,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterTile::render()
|
void RasterTile::drawLevels(QPainter *painter, const QList<Level> &levels)
|
||||||
{
|
{
|
||||||
QImage img(_rect.width() * _ratio, _rect.height() * _ratio,
|
for (int i = levels.size() - 1; i >= 0; i--) {
|
||||||
QImage::Format_ARGB32_Premultiplied);
|
QList<TextItem*> textItems, lights;
|
||||||
|
QList<SectorLight> sectorLights;
|
||||||
|
const Level &l = levels.at(i);
|
||||||
|
|
||||||
img.setDevicePixelRatio(_ratio);
|
processPoints(l.points, textItems, lights, sectorLights, l.overZoom);
|
||||||
img.fill(Qt::transparent);
|
processLines(l.lines, textItems);
|
||||||
|
|
||||||
QPainter painter(&img);
|
drawPolygons(painter, l.polygons);
|
||||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
drawLines(painter, l.lines);
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
drawArrows(painter, l.points);
|
||||||
painter.translate(-_rect.x(), -_rect.y());
|
|
||||||
|
|
||||||
|
drawTextItems(painter, lights);
|
||||||
|
drawSectorLights(painter, sectorLights);
|
||||||
|
drawTextItems(painter, textItems);
|
||||||
|
|
||||||
|
qDeleteAll(textItems);
|
||||||
|
qDeleteAll(lights);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QPainterPath RasterTile::shape(const QList<Data::Poly> &polygons) const
|
||||||
|
{
|
||||||
|
QPainterPath shp;
|
||||||
|
|
||||||
|
for (int i = 0; i < polygons.size(); i++) {
|
||||||
|
const Data::Poly &p = polygons.at(i);
|
||||||
|
if (p.type() == SUBTYPE(M_COVR, 1))
|
||||||
|
shp.addPath(painterPath(p.path()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return shp;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<RasterTile::Level> RasterTile::fetchLevels()
|
||||||
|
{
|
||||||
|
QList<RasterTile::Level> list;
|
||||||
QPoint ttl(_rect.topLeft());
|
QPoint ttl(_rect.topLeft());
|
||||||
QRectF polyRect(ttl, QPointF(ttl.x() + _rect.width(), ttl.y()
|
QRectF polyRect(ttl, QPointF(ttl.x() + _rect.width(), ttl.y()
|
||||||
+ _rect.height()));
|
+ _rect.height()));
|
||||||
@ -378,31 +402,41 @@ void RasterTile::render()
|
|||||||
RectC pointRectC(pointRectD.toRectC(_proj, 20));
|
RectC pointRectC(pointRectD.toRectC(_proj, 20));
|
||||||
|
|
||||||
for (int i = 0; i < _data.size(); i++) {
|
for (int i = 0; i < _data.size(); i++) {
|
||||||
QList<Data::Line> lines;
|
Level level;
|
||||||
QList<Data::Poly> polygons;
|
|
||||||
QList<Data::Point> points;
|
|
||||||
QList<TextItem*> textItems, lights;
|
|
||||||
QList<SectorLight> sectorLights;
|
|
||||||
|
|
||||||
_data.at(i)->polys(polyRectC, &polygons, &lines);
|
_data.at(i)->polys(polyRectC, &level.polygons, &level.lines);
|
||||||
_data.at(i)->points(pointRectC, &points);
|
_data.at(i)->points(pointRectC, &level.points);
|
||||||
|
level.overZoom = i > 0;
|
||||||
|
|
||||||
processPoints(points, textItems, lights, sectorLights,
|
std::sort(level.points.begin(), level.points.end());
|
||||||
_data.size() > 1 && i == 0);
|
|
||||||
processLines(lines, textItems);
|
|
||||||
|
|
||||||
drawPolygons(&painter, polygons);
|
if (!level.isNull())
|
||||||
drawLines(&painter, lines);
|
list.append(level);
|
||||||
drawArrows(&painter, points);
|
|
||||||
|
|
||||||
drawTextItems(&painter, lights);
|
if (shape(level.polygons).contains(_rect))
|
||||||
drawSectorLights(&painter, sectorLights);
|
break;
|
||||||
drawTextItems(&painter, textItems);
|
|
||||||
|
|
||||||
qDeleteAll(textItems);
|
|
||||||
qDeleteAll(lights);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RasterTile::render()
|
||||||
|
{
|
||||||
|
QList<Level> levels(fetchLevels());
|
||||||
|
|
||||||
|
QImage img(_rect.width() * _ratio, _rect.height() * _ratio,
|
||||||
|
QImage::Format_ARGB32_Premultiplied);
|
||||||
|
|
||||||
|
img.setDevicePixelRatio(_ratio);
|
||||||
|
img.fill(Qt::transparent);
|
||||||
|
|
||||||
|
QPainter painter(&img);
|
||||||
|
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
painter.translate(-_rect.x(), -_rect.y());
|
||||||
|
|
||||||
|
drawLevels(&painter, levels);
|
||||||
|
|
||||||
//painter.setPen(Qt::red);
|
//painter.setPen(Qt::red);
|
||||||
//painter.setBrush(Qt::NoBrush);
|
//painter.setBrush(Qt::NoBrush);
|
||||||
//painter.setRenderHint(QPainter::Antialiasing, false);
|
//painter.setRenderHint(QPainter::Antialiasing, false);
|
||||||
|
@ -51,6 +51,16 @@ private:
|
|||||||
double end;
|
double end;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Level {
|
||||||
|
QList<Data::Line> lines;
|
||||||
|
QList<Data::Poly> polygons;
|
||||||
|
QList<Data::Point> points;
|
||||||
|
bool overZoom;
|
||||||
|
|
||||||
|
bool isNull() const
|
||||||
|
{return lines.isEmpty() && polygons.isEmpty() && points.isEmpty();}
|
||||||
|
};
|
||||||
|
|
||||||
typedef QMap<Coordinates, Style::Color> LightMap;
|
typedef QMap<Coordinates, Style::Color> LightMap;
|
||||||
typedef QSet<Coordinates> SignalSet;
|
typedef QSet<Coordinates> SignalSet;
|
||||||
|
|
||||||
@ -61,16 +71,20 @@ private:
|
|||||||
QVector<QPolygonF> polylineM(const QVector<Coordinates> &path) const;
|
QVector<QPolygonF> polylineM(const QVector<Coordinates> &path) const;
|
||||||
QPolygonF tsslptArrow(const QPointF &p, qreal angle) const;
|
QPolygonF tsslptArrow(const QPointF &p, qreal angle) const;
|
||||||
QPointF centroid(const QVector<Coordinates> &polygon) const;
|
QPointF centroid(const QVector<Coordinates> &polygon) const;
|
||||||
void processPoints(QList<Data::Point> &points,
|
void processPoints(const QList<Data::Point> &points,
|
||||||
QList<TextItem*> &textItems, QList<TextItem *> &lights,
|
QList<TextItem*> &textItems, QList<TextItem *> &lights,
|
||||||
QList<SectorLight> §orLights, bool overZoom);
|
QList<SectorLight> §orLights, bool overZoom) const;
|
||||||
void processLines(const QList<Data::Line> &lines, QList<TextItem*> &textItems);
|
void processLines(const QList<Data::Line> &lines,
|
||||||
|
QList<TextItem*> &textItems) const;
|
||||||
void drawArrows(QPainter *painter, const QList<Data::Point> &points) const;
|
void drawArrows(QPainter *painter, const QList<Data::Point> &points) const;
|
||||||
void drawPolygons(QPainter *painter, const QList<Data::Poly> &polygons) const;
|
void drawPolygons(QPainter *painter, const QList<Data::Poly> &polygons) const;
|
||||||
void drawLines(QPainter *painter, const QList<Data::Line> &lines) const;
|
void drawLines(QPainter *painter, const QList<Data::Line> &lines) const;
|
||||||
void drawTextItems(QPainter *painter, const QList<TextItem*> &textItems) const;
|
void drawTextItems(QPainter *painter, const QList<TextItem*> &textItems) const;
|
||||||
void drawSectorLights(QPainter *painter, const QList<SectorLight> &lights) const;
|
void drawSectorLights(QPainter *painter, const QList<SectorLight> &lights) const;
|
||||||
bool showLabel(const QImage *img, int type) const;
|
bool showLabel(const QImage *img, int type) const;
|
||||||
|
void drawLevels(QPainter *painter, const QList<Level> &levels);
|
||||||
|
QList<Level> fetchLevels();
|
||||||
|
QPainterPath shape(const QList<Data::Poly> &polygons) const;
|
||||||
|
|
||||||
Projection _proj;
|
Projection _proj;
|
||||||
Transform _transform;
|
Transform _transform;
|
||||||
|
@ -350,9 +350,9 @@ QList<Data*> ENCAtlas::levels() const
|
|||||||
QList<Data*> list;
|
QList<Data*> list;
|
||||||
QMap<IntendedUsage, ENC::AtlasData*>::const_iterator it = _data.find(_usage);
|
QMap<IntendedUsage, ENC::AtlasData*>::const_iterator it = _data.find(_usage);
|
||||||
|
|
||||||
list.append(it.value());
|
do {
|
||||||
if (it != _data.cbegin())
|
list.append(it.value());
|
||||||
list.prepend((--it).value());
|
} while (it-- != _data.cbegin());
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user