1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-27 21:24:47 +01:00

Code cleanup

This commit is contained in:
Martin Tůma 2024-06-06 18:51:24 +02:00
parent 98704ef44b
commit 3e6ad20c05
6 changed files with 77 additions and 80 deletions

View File

@ -128,9 +128,9 @@ HEADERS += src/common/config.h \
src/map/ENC/objects.h \ src/map/ENC/objects.h \
src/map/ENC/rastertile.h \ src/map/ENC/rastertile.h \
src/map/ENC/style.h \ src/map/ENC/style.h \
src/map/IMG/dem.h \
src/map/IMG/demfile.h \ src/map/IMG/demfile.h \
src/map/IMG/demtile.h \ src/map/IMG/demtile.h \
src/map/IMG/demtree.h \
src/map/IMG/jls.h \ src/map/IMG/jls.h \
src/map/IMG/section.h \ src/map/IMG/section.h \
src/map/IMG/zoom.h \ src/map/IMG/zoom.h \
@ -351,8 +351,8 @@ SOURCES += src/main.cpp \
src/map/ENC/mapdata.cpp \ src/map/ENC/mapdata.cpp \
src/map/ENC/rastertile.cpp \ src/map/ENC/rastertile.cpp \
src/map/ENC/style.cpp \ src/map/ENC/style.cpp \
src/map/IMG/dem.cpp \
src/map/IMG/demfile.cpp \ src/map/IMG/demfile.cpp \
src/map/IMG/demtree.cpp \
src/map/IMG/jls.cpp \ src/map/IMG/jls.cpp \
src/map/conversion.cpp \ src/map/conversion.cpp \
src/map/encatlas.cpp \ src/map/encatlas.cpp \

View File

@ -1,44 +0,0 @@
#ifndef IMG_DEM_H
#define IMG_DEM_H
#include "common/rtree.h"
#include "mapdata.h"
namespace IMG {
class DEM {
public:
typedef RTree<const MapData::Elevation*, double, 2> DEMTRee;
static void buildTree(const QList<MapData::Elevation> &tiles, DEMTRee &tree);
static void searchTree(const DEMTRee &tree, const Coordinates &c,
double &ele);
private:
struct ElevationCTX {
ElevationCTX(const DEMTRee &tree, const Coordinates &c, double &ele)
: tree(tree), c(c), ele(ele) {}
const DEMTRee &tree;
const Coordinates &c;
double &ele;
};
struct EdgeCTX {
EdgeCTX(const Coordinates &c, double &ele) : c(c), ele(ele) {}
const Coordinates &c;
double &ele;
};
static double edge(const DEMTRee &tree, const Coordinates &c);
static double elevation(const DEMTRee &tree, const MapData::Elevation *e,
const Coordinates &c);
static bool elevationCb(const MapData::Elevation *e, void *context);
static bool edgeCb(const MapData::Elevation *e, void *context);
};
}
#endif // IMG_DEM_H

View File

@ -1,4 +1,4 @@
#include "dem.h" #include "demtree.h"
using namespace IMG; using namespace IMG;
@ -17,7 +17,15 @@ static double val(const Matrix<qint16> &m, int row, int col)
return (v == -32768) ? NAN : (double)v; return (v == -32768) ? NAN : (double)v;
} }
bool DEM::edgeCb(const MapData::Elevation *e, void *context) bool DEMTree::elevationCb(const MapData::Elevation *e, void *context)
{
ElevationCTX *ctx = (ElevationCTX*)context;
ctx->ele = elevation(ctx->tree, e, ctx->c);
return std::isnan(ctx->ele);
}
bool DEMTree::edgeCb(const MapData::Elevation *e, void *context)
{ {
EdgeCTX *ctx = (EdgeCTX*)context; EdgeCTX *ctx = (EdgeCTX*)context;
@ -31,10 +39,10 @@ bool DEM::edgeCb(const MapData::Elevation *e, void *context)
return std::isnan(ctx->ele); return std::isnan(ctx->ele);
} }
double DEM::edge(const DEMTRee &tree, const Coordinates &c) double DEMTree::edge(const Tree &tree, const Coordinates &c)
{ {
double min[2], max[2];
double ele = NAN; double ele = NAN;
double min[2], max[2];
EdgeCTX ctx(c, ele); EdgeCTX ctx(c, ele);
min[0] = c.lon(); min[0] = c.lon();
@ -47,7 +55,7 @@ double DEM::edge(const DEMTRee &tree, const Coordinates &c)
return ele; return ele;
} }
double DEM::elevation(const DEMTRee &tree, const MapData::Elevation *e, double DEMTree::elevation(const Tree &tree, const MapData::Elevation *e,
const Coordinates &c) const Coordinates &c)
{ {
double x = (c.lon() - e->rect.left()) / e->xr; double x = (c.lon() - e->rect.left()) / e->xr;
@ -72,7 +80,7 @@ double DEM::elevation(const DEMTRee &tree, const MapData::Elevation *e,
return interpolate(x - col, y - row, p0, p1, p2, p3); return interpolate(x - col, y - row, p0, p1, p2, p3);
} }
void DEM::buildTree(const QList<MapData::Elevation> &tiles, DEMTRee &tree) DEMTree::DEMTree(const QList<MapData::Elevation> &tiles)
{ {
double min[2], max[2]; double min[2], max[2];
@ -84,29 +92,22 @@ void DEM::buildTree(const QList<MapData::Elevation> &tiles, DEMTRee &tree)
max[0] = e.rect.right(); max[0] = e.rect.right();
max[1] = e.rect.top(); max[1] = e.rect.top();
tree.Insert(min, max, &e); _tree.Insert(min, max, &e);
} }
} }
bool DEM::elevationCb(const MapData::Elevation *e, void *context) double DEMTree::elevation(const Coordinates &c) const
{
ElevationCTX *ctx = (ElevationCTX*)context;
ctx->ele = elevation(ctx->tree, e, ctx->c);
return std::isnan(ctx->ele);
}
void DEM::searchTree(const DEMTRee &tree, const Coordinates &c,
double &ele)
{ {
double ele = NAN;
double min[2], max[2]; double min[2], max[2];
ElevationCTX ctx(tree, c, ele); ElevationCTX ctx(_tree, c, ele);
min[0] = c.lon(); min[0] = c.lon();
min[1] = c.lat(); min[1] = c.lat();
max[0] = c.lon(); max[0] = c.lon();
max[1] = c.lat(); max[1] = c.lat();
ele = NAN; _tree.Search(min, max, elevationCb, &ctx);
tree.Search(min, max, elevationCb, &ctx);
return ele;
} }

45
src/map/IMG/demtree.h Normal file
View File

@ -0,0 +1,45 @@
#ifndef IMG_DEMTREE_H
#define IMG_DEMTREE_H
#include "common/rtree.h"
#include "mapdata.h"
namespace IMG {
class DEMTree {
public:
DEMTree(const QList<MapData::Elevation> &tiles);
double elevation(const Coordinates &c) const;
private:
typedef RTree<const MapData::Elevation*, double, 2> Tree;
struct ElevationCTX {
ElevationCTX(const Tree &tree, const Coordinates &c, double &ele)
: tree(tree), c(c), ele(ele) {}
const Tree &tree;
const Coordinates &c;
double &ele;
};
struct EdgeCTX {
EdgeCTX(const Coordinates &c, double &ele) : c(c), ele(ele) {}
const Coordinates &c;
double &ele;
};
static double edge(const Tree &tree, const Coordinates &c);
static double elevation(const Tree &tree, const MapData::Elevation *e,
const Coordinates &c);
static bool elevationCb(const MapData::Elevation *e, void *context);
static bool edgeCb(const MapData::Elevation *e, void *context);
Tree _tree;
};
}
#endif // IMG_DEMTREE_H

View File

@ -10,7 +10,7 @@
#include "map/filter.h" #include "map/filter.h"
#include "style.h" #include "style.h"
#include "lblfile.h" #include "lblfile.h"
#include "dem.h" #include "demtree.h"
#include "rastertile.h" #include "rastertile.h"
using namespace IMG; using namespace IMG;
@ -470,7 +470,6 @@ MatrixD RasterTile::elevation(int extend) const
if (_data->hasDEM()) { if (_data->hasDEM()) {
RectC rect; RectC rect;
QList<MapData::Elevation> tiles; QList<MapData::Elevation> tiles;
DEMTRee tree;
for (int i = 0; i < ll.size(); i++) for (int i = 0; i < ll.size(); i++)
rect = rect.united(ll.at(i)); rect = rect.united(ll.at(i));
@ -480,14 +479,14 @@ MatrixD RasterTile::elevation(int extend) const
_data->elevations(rect.adjusted(0, 0, rect.width() / factor, _data->elevations(rect.adjusted(0, 0, rect.width() / factor,
-rect.height() / factor), _zoom, &tiles); -rect.height() / factor), _zoom, &tiles);
DEM::buildTree(tiles, tree); DEMTree tree(tiles);
for (int i = 0; i < ll.size(); i++) for (int i = 0; i < ll.size(); i++)
DEM::searchTree(tree, ll.at(i), m.at(i)); m.at(i) = tree.elevation(ll.at(i));
} else { } else {
::DEM::lock(); DEM::lock();
for (int i = 0; i < ll.size(); i++) for (int i = 0; i < ll.size(); i++)
m.at(i) = ::DEM::elevation(ll.at(i)); m.at(i) = DEM::elevation(ll.at(i));
::DEM::unlock(); DEM::unlock();
} }
return m; return m;

View File

@ -8,7 +8,7 @@
#include "IMG/imgdata.h" #include "IMG/imgdata.h"
#include "IMG/gmapdata.h" #include "IMG/gmapdata.h"
#include "IMG/rastertile.h" #include "IMG/rastertile.h"
#include "IMG/dem.h" #include "IMG/demtree.h"
#include "osm.h" #include "osm.h"
#include "pcs.h" #include "pcs.h"
#include "rectd.h" #include "rectd.h"
@ -273,16 +273,12 @@ double IMGMap::elevation(const Coordinates &c)
if (d->hasDEM()) { if (d->hasDEM()) {
QList<MapData::Elevation> tiles; QList<MapData::Elevation> tiles;
DEM::DEMTRee tree;
double ele = NAN;
d->elevations(RectC(Coordinates(c), Coordinates(c)), d->zooms().max(), d->elevations(RectC(Coordinates(c), Coordinates(c)), d->zooms().max(),
&tiles); &tiles);
DEMTree tree(tiles);
DEM::buildTree(tiles, tree); return tree.elevation(c);
DEM::searchTree(tree, c, ele);
return ele;
} else } else
return Map::elevation(c); return Map::elevation(c);
} }