Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
b91d7290
Commit
b91d7290
authored
Nov 16, 2017
by
Andreas Bircher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
online version
parent
8b7553b5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
39 deletions
+62
-39
Terrain.cc
src/Terrain.cc
+49
-35
Terrain.h
src/Terrain.h
+10
-1
TerrainTile.cc
src/TerrainTile.cc
+2
-2
TerrainTile.h
src/TerrainTile.h
+1
-1
No files found.
src/Terrain.cc
View file @
b91d7290
...
...
@@ -30,39 +30,9 @@ ElevationProvider::ElevationProvider(QObject* parent)
}
bool
ElevationProvider
::
queryTerrainData
(
const
QList
<
QGeoCoordinate
>&
coordinates
)
bool
ElevationProvider
::
queryTerrainData
Points
(
const
QList
<
QGeoCoordinate
>&
coordinates
)
{
if
(
coordinates
.
length
()
==
0
)
{
return
false
;
}
bool
fallBackToOnline
=
false
;
QList
<
float
>
altitudes
;
foreach
(
QGeoCoordinate
coordinate
,
coordinates
)
{
QString
uniqueTileId
=
_uniqueTileId
(
coordinate
);
_tilesMutex
.
lock
();
if
(
!
_tiles
.
contains
(
uniqueTileId
))
{
_tilesMutex
.
unlock
();
fallBackToOnline
=
true
;
break
;
}
else
{
if
(
_tiles
[
uniqueTileId
].
isIn
(
coordinate
))
{
altitudes
.
push_back
(
_tiles
[
uniqueTileId
].
elevation
(
coordinate
));
}
else
{
qCDebug
(
TerrainLog
)
<<
"Error: coordinate not in tile region"
;
altitudes
.
push_back
(
-
1.0
);
}
}
_tilesMutex
.
unlock
();
}
if
(
!
fallBackToOnline
)
{
qCDebug
(
TerrainLog
)
<<
"All altitudes taken from cached data"
;
emit
terrainData
(
true
,
altitudes
);
return
true
;
}
if
(
_state
!=
State
::
Idle
)
{
if
(
_state
!=
State
::
Idle
||
coordinates
.
length
()
==
0
)
{
return
false
;
}
...
...
@@ -95,6 +65,47 @@ bool ElevationProvider::queryTerrainData(const QList<QGeoCoordinate>& coordinate
return
true
;
}
bool
ElevationProvider
::
queryTerrainData
(
const
QList
<
QGeoCoordinate
>&
coordinates
)
{
if
(
_state
!=
State
::
Idle
||
coordinates
.
length
()
==
0
)
{
return
false
;
}
QList
<
float
>
altitudes
;
bool
needToDownload
=
false
;
foreach
(
QGeoCoordinate
coordinate
,
coordinates
)
{
QString
uniqueTileId
=
_uniqueTileId
(
coordinate
);
_tilesMutex
.
lock
();
if
(
!
_tiles
.
contains
(
uniqueTileId
))
{
qCDebug
(
TerrainLog
)
<<
"Need to download tile "
<<
uniqueTileId
;
_downloadQueue
.
append
(
uniqueTileId
);
needToDownload
=
true
;
}
else
{
if
(
!
needToDownload
)
{
if
(
_tiles
[
uniqueTileId
].
isIn
(
coordinate
))
{
altitudes
.
push_back
(
_tiles
[
uniqueTileId
].
elevation
(
coordinate
));
}
else
{
qCDebug
(
TerrainLog
)
<<
"Error: coordinate not in tile region"
;
altitudes
.
push_back
(
-
1.0
);
}
}
}
_tilesMutex
.
unlock
();
}
if
(
!
needToDownload
)
{
qCDebug
(
TerrainLog
)
<<
"All altitudes taken from cached data"
;
emit
terrainData
(
true
,
altitudes
);
_coordinates
.
clear
();
return
true
;
}
_coordinates
=
coordinates
;
_downloadTiles
();
return
true
;
}
bool
ElevationProvider
::
cacheTerrainTiles
(
const
QGeoCoordinate
&
southWest
,
const
QGeoCoordinate
&
northEast
)
{
qCDebug
(
TerrainLog
)
<<
"Cache terrain tiles southWest:northEast"
<<
southWest
<<
northEast
;
...
...
@@ -116,7 +127,7 @@ bool ElevationProvider::cacheTerrainTiles(const QGeoCoordinate& southWest, const
_tilesMutex
.
unlock
();
continue
;
}
_downloadQueue
.
append
(
uniqueTileId
.
replace
(
"_"
,
","
)
);
_downloadQueue
.
append
(
uniqueTileId
);
_tilesMutex
.
unlock
();
qCDebug
(
TerrainLog
)
<<
"Adding tile to download queue: "
<<
uniqueTileId
;
}
...
...
@@ -139,7 +150,7 @@ bool ElevationProvider::cacheTerrainTiles(const QList<QGeoCoordinate>& coordinat
_tilesMutex
.
unlock
();
continue
;
}
_downloadQueue
.
append
(
uniqueTileId
.
replace
(
"_"
,
","
)
);
_downloadQueue
.
append
(
uniqueTileId
);
_tilesMutex
.
unlock
();
qCDebug
(
TerrainLog
)
<<
"Adding tile to download queue: "
<<
uniqueTileId
;
}
...
...
@@ -233,12 +244,13 @@ void ElevationProvider::_downloadTiles(void)
QUrlQuery
query
;
_tilesMutex
.
lock
();
qCDebug
(
TerrainLog
)
<<
"Starting download for "
<<
_downloadQueue
.
first
();
query
.
addQueryItem
(
QStringLiteral
(
"points"
),
_downloadQueue
.
first
());
query
.
addQueryItem
(
QStringLiteral
(
"points"
),
_downloadQueue
.
first
()
.
replace
(
"_"
,
","
)
);
_downloadQueue
.
pop_front
();
_tilesMutex
.
unlock
();
QUrl
url
(
QStringLiteral
(
"https://api.airmap.com/elevation/stage/srtm1/ele/carpet"
));
url
.
setQuery
(
query
);
qWarning
()
<<
"url"
<<
url
;
QNetworkRequest
request
(
url
);
QNetworkProxy
tProxy
;
...
...
@@ -253,6 +265,8 @@ void ElevationProvider::_downloadTiles(void)
connect
(
networkReply
,
&
QNetworkReply
::
finished
,
this
,
&
ElevationProvider
::
_requestFinishedTile
);
_state
=
State
::
Downloading
;
}
else
if
(
_state
==
State
::
Idle
)
{
queryTerrainData
(
_coordinates
);
}
}
...
...
src/Terrain.h
View file @
b91d7290
...
...
@@ -38,7 +38,15 @@ public:
/**
* Async elevation query for a list of lon,lat coordinates. When the query is done, the terrainData() signal
* is emitted.
* is emitted. This call directly looks elevations up online.
* @param coordinates
* @return true on success
*/
bool
queryTerrainDataPoints
(
const
QList
<
QGeoCoordinate
>&
coordinates
);
/**
* Async elevation query for a list of lon,lat coordinates. When the query is done, the terrainData() signal
* is emitted. This call caches local elevation tables for faster lookup in the future.
* @param coordinates
* @return true on success
*/
...
...
@@ -80,6 +88,7 @@ private:
State
_state
=
State
::
Idle
;
QNetworkAccessManager
_networkManager
;
QList
<
QGeoCoordinate
>
_coordinates
;
static
QMutex
_tilesMutex
;
static
QHash
<
QString
,
TerrainTile
>
_tiles
;
...
...
src/TerrainTile.cc
View file @
b91d7290
...
...
@@ -141,8 +141,8 @@ float TerrainTile::elevation(const QGeoCoordinate& coordinate) const
if
(
_isValid
)
{
qCDebug
(
TerrainTileLog
)
<<
"elevation: "
<<
coordinate
<<
" , in sw "
<<
_southWest
<<
" , ne "
<<
_northEast
;
// Get the index at resolution of 1 arc second
int
indexLat
=
std
::
round
((
coordinate
.
latitude
()
-
_southWest
.
latitude
())
*
gridSize
/
srtm1TileSize
);
int
indexLon
=
std
::
round
((
coordinate
.
longitude
()
-
_southWest
.
longitude
())
*
gridSize
/
srtm1TileSize
);
int
indexLat
=
round
((
coordinate
.
latitude
()
-
_southWest
.
latitude
())
*
(
gridSize
-
1
)
/
srtm1TileSize
);
int
indexLon
=
round
((
coordinate
.
longitude
()
-
_southWest
.
longitude
())
*
(
gridSize
-
1
)
/
srtm1TileSize
);
qCDebug
(
TerrainTileLog
)
<<
"indexLat:indexLon"
<<
indexLat
<<
indexLon
;
// TODO (birchera): Move this down to the next debug output, once this is all properly working.
Q_ASSERT
(
indexLat
>=
0
);
Q_ASSERT
(
indexLat
<
gridSize
);
...
...
src/TerrainTile.h
View file @
b91d7290
...
...
@@ -5,7 +5,7 @@
#include <QGeoCoordinate>
#define TERRAIN_TILE_SIZE 9
0
#define TERRAIN_TILE_SIZE 9
1
Q_DECLARE_LOGGING_CATEGORY
(
TerrainTileLog
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment