2019-05-10 18:56:19 +02:00
|
|
|
#include "vectortile.h"
|
|
|
|
|
2020-02-07 22:10:06 +01:00
|
|
|
|
2020-11-10 00:58:19 +01:00
|
|
|
static void copyPolys(const RectC &rect, QList<MapData::Poly> *src,
|
|
|
|
QList<MapData::Poly> *dst)
|
2020-02-07 22:10:06 +01:00
|
|
|
{
|
|
|
|
for (int i = 0; i < src->size(); i++)
|
|
|
|
if (rect.intersects(src->at(i).boundingRect))
|
|
|
|
dst->append(src->at(i));
|
|
|
|
}
|
|
|
|
|
2020-11-10 00:58:19 +01:00
|
|
|
static void copyPoints(const RectC &rect, QList<MapData::Point> *src,
|
|
|
|
QList<MapData::Point> *dst)
|
2020-02-07 22:10:06 +01:00
|
|
|
{
|
|
|
|
for (int j = 0; j < src->size(); j++)
|
|
|
|
if (rect.contains(src->at(j).coordinates))
|
|
|
|
dst->append(src->at(j));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 18:56:19 +02:00
|
|
|
SubFile *VectorTile::file(SubFile::Type type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case SubFile::TRE:
|
|
|
|
return _tre;
|
|
|
|
case SubFile::RGN:
|
|
|
|
return _rgn;
|
|
|
|
case SubFile::LBL:
|
|
|
|
return _lbl;
|
|
|
|
case SubFile::NET:
|
|
|
|
return _net;
|
2020-06-27 22:46:26 +02:00
|
|
|
case SubFile::NOD:
|
|
|
|
return _nod;
|
2019-09-05 22:31:13 +02:00
|
|
|
case SubFile::GMP:
|
|
|
|
return _gmp;
|
2019-05-10 18:56:19 +02:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-17 09:19:15 +01:00
|
|
|
bool VectorTile::init()
|
2019-05-10 18:56:19 +02:00
|
|
|
{
|
2019-09-05 22:31:13 +02:00
|
|
|
if (_gmp && !initGMP())
|
2019-05-10 18:56:19 +02:00
|
|
|
return false;
|
2019-09-05 22:31:13 +02:00
|
|
|
|
2020-02-17 09:19:15 +01:00
|
|
|
if (!(_tre && _tre->init() && _rgn))
|
2019-05-10 18:56:19 +02:00
|
|
|
return false;
|
2019-09-05 22:31:13 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VectorTile::initGMP()
|
|
|
|
{
|
2020-02-09 23:24:48 +01:00
|
|
|
SubFile::Handle hdl(_gmp);
|
2020-06-27 22:46:26 +02:00
|
|
|
quint32 tre, rgn, lbl, net, nod;
|
2019-09-05 22:31:13 +02:00
|
|
|
|
|
|
|
if (!(_gmp->seek(hdl, 0x19) && _gmp->readUInt32(hdl, tre)
|
|
|
|
&& _gmp->readUInt32(hdl, rgn) && _gmp->readUInt32(hdl, lbl)
|
2020-06-27 22:46:26 +02:00
|
|
|
&& _gmp->readUInt32(hdl, net) && _gmp->readUInt32(hdl, nod)))
|
2019-05-10 18:56:19 +02:00
|
|
|
return false;
|
|
|
|
|
2020-02-08 16:01:22 +01:00
|
|
|
_tre = tre ? new TREFile(_gmp, tre) : 0;
|
|
|
|
_rgn = rgn ? new RGNFile(_gmp, rgn) : 0;
|
|
|
|
_lbl = lbl ? new LBLFile(_gmp, lbl) : 0;
|
|
|
|
_net = net ? new NETFile(_gmp, net) : 0;
|
2020-06-27 22:46:26 +02:00
|
|
|
_nod = nod ? new NODFile(_gmp, nod) : 0;
|
2019-09-05 22:31:13 +02:00
|
|
|
|
2019-05-10 18:56:19 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-10 00:58:19 +01:00
|
|
|
bool VectorTile::load(SubFile::Handle &rgnHdl, SubFile::Handle &lblHdl,
|
|
|
|
SubFile::Handle &netHdl, SubFile::Handle &nodHdl)
|
|
|
|
{
|
|
|
|
_loaded = -1;
|
|
|
|
|
|
|
|
if (!_rgn->load(rgnHdl))
|
|
|
|
return false;
|
|
|
|
if (_lbl && !_lbl->load(lblHdl, _rgn, rgnHdl))
|
|
|
|
return false;
|
|
|
|
if (_net && !_net->load(netHdl, _rgn, rgnHdl))
|
|
|
|
return false;
|
|
|
|
if (_nod && !_nod->load(nodHdl))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
_loaded = 1;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VectorTile::clear()
|
|
|
|
{
|
|
|
|
_tre->clear();
|
|
|
|
_rgn->clear();
|
|
|
|
if (_lbl)
|
|
|
|
_lbl->clear();
|
|
|
|
if (_net)
|
|
|
|
_net->clear();
|
|
|
|
|
|
|
|
_loaded = 0;
|
|
|
|
}
|
|
|
|
|
2020-02-11 21:03:55 +01:00
|
|
|
void VectorTile::polys(const RectC &rect, int bits, bool baseMap,
|
2020-11-10 00:58:19 +01:00
|
|
|
QList<MapData::Poly> *polygons, QList<MapData::Poly> *lines,
|
|
|
|
QCache<const SubDiv *, MapData::Polys> *polyCache)
|
2019-05-10 18:56:19 +02:00
|
|
|
{
|
2020-06-27 22:46:26 +02:00
|
|
|
SubFile::Handle rgnHdl(_rgn), lblHdl(_lbl), netHdl(_net), nodHdl(_nod);
|
2020-02-07 22:10:06 +01:00
|
|
|
|
2020-11-10 00:58:19 +01:00
|
|
|
if (_loaded < 0 || (!_loaded && !load(rgnHdl, lblHdl, netHdl, nodHdl)))
|
2020-02-07 22:10:06 +01:00
|
|
|
return;
|
|
|
|
|
2020-02-11 21:03:55 +01:00
|
|
|
QList<SubDiv*> subdivs = _tre->subdivs(rect, bits, baseMap);
|
2019-05-10 18:56:19 +02:00
|
|
|
for (int i = 0; i < subdivs.size(); i++) {
|
2020-02-07 22:10:06 +01:00
|
|
|
SubDiv *subdiv = subdivs.at(i);
|
|
|
|
|
2020-11-10 00:58:19 +01:00
|
|
|
MapData::Polys *polys = polyCache->object(subdiv);
|
2020-02-07 22:10:06 +01:00
|
|
|
if (!polys) {
|
|
|
|
quint32 shift = _tre->shift(subdiv->bits());
|
2020-11-10 00:58:19 +01:00
|
|
|
QList<MapData::Poly> p, l;
|
2020-02-07 22:10:06 +01:00
|
|
|
|
|
|
|
if (!subdiv->initialized() && !_rgn->subdivInit(rgnHdl, subdiv))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
_rgn->polyObjects(rgnHdl, subdiv, RGNFile::Polygon, _lbl, lblHdl,
|
|
|
|
_net, netHdl, &p);
|
|
|
|
_rgn->polyObjects(rgnHdl, subdiv, RGNFile::Line, _lbl, lblHdl,
|
|
|
|
_net, netHdl, &l);
|
|
|
|
_rgn->extPolyObjects(rgnHdl, subdiv, shift, RGNFile::Polygon, _lbl,
|
|
|
|
lblHdl, &p);
|
|
|
|
_rgn->extPolyObjects(rgnHdl, subdiv, shift, RGNFile::Line, _lbl,
|
|
|
|
lblHdl, &l);
|
2020-09-18 20:56:00 +02:00
|
|
|
_rgn->links(rgnHdl, subdiv, shift, _net, netHdl, _nod, nodHdl, _lbl,
|
|
|
|
lblHdl, &l);
|
2020-02-07 22:10:06 +01:00
|
|
|
|
|
|
|
copyPolys(rect, &p, polygons);
|
|
|
|
copyPolys(rect, &l, lines);
|
2020-11-10 00:58:19 +01:00
|
|
|
polyCache->insert(subdiv, new MapData::Polys(p, l));
|
2020-02-07 22:10:06 +01:00
|
|
|
} else {
|
|
|
|
copyPolys(rect, &(polys->polygons), polygons);
|
|
|
|
copyPolys(rect, &(polys->lines), lines);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-11 21:03:55 +01:00
|
|
|
void VectorTile::points(const RectC &rect, int bits, bool baseMap,
|
2020-11-10 00:58:19 +01:00
|
|
|
QList<MapData::Point> *points, QCache<const SubDiv *,
|
|
|
|
QList<MapData::Point> > *pointCache)
|
2020-02-07 22:10:06 +01:00
|
|
|
{
|
2020-11-10 00:58:19 +01:00
|
|
|
SubFile::Handle rgnHdl(_rgn), lblHdl(_lbl), netHdl(_net), nodHdl(_nod);
|
2020-02-07 22:10:06 +01:00
|
|
|
|
2020-11-10 00:58:19 +01:00
|
|
|
if (_loaded < 0 || (!_loaded && !load(rgnHdl, lblHdl, netHdl, nodHdl)))
|
2020-02-07 22:10:06 +01:00
|
|
|
return;
|
|
|
|
|
2020-02-11 21:03:55 +01:00
|
|
|
QList<SubDiv*> subdivs = _tre->subdivs(rect, bits, baseMap);
|
2020-02-07 22:10:06 +01:00
|
|
|
for (int i = 0; i < subdivs.size(); i++) {
|
|
|
|
SubDiv *subdiv = subdivs.at(i);
|
|
|
|
|
2020-11-10 00:58:19 +01:00
|
|
|
QList<MapData::Point> *pl = pointCache->object(subdiv);
|
2020-02-07 22:10:06 +01:00
|
|
|
if (!pl) {
|
2020-11-10 00:58:19 +01:00
|
|
|
QList<MapData::Point> p;
|
2020-02-07 22:10:06 +01:00
|
|
|
|
|
|
|
if (!subdiv->initialized() && !_rgn->subdivInit(rgnHdl, subdiv))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
_rgn->pointObjects(rgnHdl, subdiv, RGNFile::Point, _lbl, lblHdl,
|
|
|
|
&p);
|
|
|
|
_rgn->pointObjects(rgnHdl, subdiv, RGNFile::IndexedPoint, _lbl,
|
|
|
|
lblHdl, &p);
|
|
|
|
_rgn->extPointObjects(rgnHdl, subdiv, _lbl, lblHdl, &p);
|
2020-01-21 21:50:13 +01:00
|
|
|
|
2020-02-07 22:10:06 +01:00
|
|
|
copyPoints(rect, &p, points);
|
2020-11-10 00:58:19 +01:00
|
|
|
pointCache->insert(subdiv, new QList<MapData::Point>(p));
|
2020-02-07 22:10:06 +01:00
|
|
|
} else
|
|
|
|
copyPoints(rect, pl, points);
|
2019-05-10 18:56:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef QT_NO_DEBUG
|
|
|
|
QDebug operator<<(QDebug dbg, const VectorTile &tile)
|
|
|
|
{
|
2020-01-19 13:23:20 +01:00
|
|
|
dbg.nospace() << "VectorTile(" << tile.bounds() <<")";
|
2019-05-10 18:56:19 +02:00
|
|
|
|
|
|
|
return dbg.space();
|
|
|
|
}
|
|
|
|
#endif // QT_NO_DEBUG
|