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
17fe7893
Commit
17fe7893
authored
7 years ago
by
Andreas Bircher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes
parent
54c7e7dd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
19 deletions
+36
-19
Terrain.cc
src/Terrain.cc
+7
-3
Terrain.h
src/Terrain.h
+2
-2
TerrainTile.cc
src/TerrainTile.cc
+18
-12
TerrainTile.h
src/TerrainTile.h
+9
-2
No files found.
src/Terrain.cc
View file @
17fe7893
...
...
@@ -20,6 +20,10 @@
QGC_LOGGING_CATEGORY
(
TerrainLog
,
"TerrainLog"
)
QMutex
ElevationProvider
::
_tilesMutex
;
QHash
<
QString
,
TerrainTile
>
ElevationProvider
::
_tiles
;
QStringList
ElevationProvider
::
_downloadQueue
;
ElevationProvider
::
ElevationProvider
(
QObject
*
parent
)
:
QObject
(
parent
)
{
...
...
@@ -101,7 +105,7 @@ bool ElevationProvider::cacheTerrainTiles(const QList<QGeoCoordinate>& coordinat
QString
uniqueTileId
=
_uniqueTileId
(
coordinate
);
_tilesMutex
.
lock
();
if
(
_downloadQueue
.
contains
(
uniqueTileId
)
||
_tiles
.
contains
(
uniqueTileId
))
{
continue
continue
;
}
_downloadQueue
.
append
(
uniqueTileId
.
replace
(
"-"
,
","
));
_tilesMutex
.
unlock
();
...
...
@@ -209,7 +213,7 @@ void ElevationProvider::_downloadTiles(void)
QNetworkReply
*
networkReply
=
_networkManager
.
get
(
request
);
if
(
!
networkReply
)
{
return
false
;
return
;
}
connect
(
networkReply
,
&
QNetworkReply
::
finished
,
this
,
&
ElevationProvider
::
_requestFinishedTile
);
...
...
@@ -229,7 +233,7 @@ QString ElevationProvider::_uniqueTileId(const QGeoCoordinate& coordinate)
QString
ret
=
QString
::
number
(
southEast
.
latitude
(),
'f'
,
6
)
+
"-"
+
QString
::
number
(
southEast
.
longitude
(),
'f'
,
6
)
+
"-"
+
QString
::
number
(
northEast
.
latitude
(),
'f'
,
6
)
+
"-"
+
QString
::
number
(
northEast
.
longitude
(),
'f'
,
6
);
qCDebug
<<
"Computing unique tile id for "
<<
coordinate
<<
ret
;
qCDebug
(
TerrainLog
)
<<
"Computing unique tile id for "
<<
coordinate
<<
ret
;
return
ret
;
}
This diff is collapsed.
Click to expand it.
src/Terrain.h
View file @
17fe7893
...
...
@@ -50,7 +50,7 @@ public:
* @param southWest
* @param northEast
*/
void
cacheTerrainData
(
const
QGeoCoordinate
&
southWest
,
const
QGeoCoordinate
&
northEast
);
bool
cacheTerrainTiles
(
const
QList
<
QGeoCoordinate
>&
coordinates
);
signals:
void
terrainData
(
bool
success
,
QList
<
float
>
altitudes
);
...
...
@@ -74,5 +74,5 @@ private:
static
QMutex
_tilesMutex
;
static
QHash
<
QString
,
TerrainTile
>
_tiles
;
QStringList
_downloadQueue
;
static
QStringList
_downloadQueue
;
};
This diff is collapsed.
Click to expand it.
src/TerrainTile.cc
View file @
17fe7893
...
...
@@ -7,6 +7,7 @@
QGC_LOGGING_CATEGORY
(
TerrainTileLog
,
"TerrainTileLog"
)
const
double
TerrainTile
::
_srtm1TileSize
=
0.025
;
const
char
*
TerrainTile
::
_jsonStatusKey
=
"status"
;
const
char
*
TerrainTile
::
_jsonDataKey
=
"data"
;
const
char
*
TerrainTile
::
_jsonBoundsKey
=
"bounds"
;
...
...
@@ -50,7 +51,7 @@ TerrainTile::TerrainTile(QJsonDocument document)
};
if
(
!
JsonHelper
::
validateKeys
(
rootObject
,
rootVersionKeyInfoList
,
errorString
))
{
qCDebug
(
TerrainTileLog
)
<<
"Error in reading json: "
<<
errorString
;
return
false
;
return
;
}
if
(
rootObject
[
_jsonStatusKey
].
toString
()
!=
"success"
)
{
...
...
@@ -65,7 +66,7 @@ TerrainTile::TerrainTile(QJsonDocument document)
};
if
(
!
JsonHelper
::
validateKeys
(
dataObject
,
dataVersionKeyInfoList
,
errorString
))
{
qCDebug
(
TerrainTileLog
)
<<
"Error in reading json: "
<<
errorString
;
return
false
;
return
;
}
// Bounds
...
...
@@ -76,7 +77,7 @@ TerrainTile::TerrainTile(QJsonDocument document)
};
if
(
!
JsonHelper
::
validateKeys
(
boundsObject
,
boundsVersionKeyInfoList
,
errorString
))
{
qCDebug
(
TerrainTileLog
)
<<
"Error in reading json: "
<<
errorString
;
return
false
;
return
;
}
const
QJsonArray
&
swArray
=
boundsObject
[
_jsonSouthWestKey
].
toArray
();
const
QJsonArray
&
neArray
=
boundsObject
[
_jsonNorthEastKey
].
toArray
();
...
...
@@ -98,7 +99,7 @@ TerrainTile::TerrainTile(QJsonDocument document)
};
if
(
!
JsonHelper
::
validateKeys
(
statsObject
,
statsVersionKeyInfoList
,
errorString
))
{
qCDebug
(
TerrainTileLog
)
<<
"Error in reading json: "
<<
errorString
;
return
false
;
return
;
}
_maxElevation
=
statsObject
[
_jsonMaxElevationKey
].
toInt
();
_minElevation
=
statsObject
[
_jsonMinElevationKey
].
toInt
();
...
...
@@ -129,28 +130,33 @@ bool TerrainTile::isIn(const QGeoCoordinate& coordinate) const
qCDebug
(
TerrainTileLog
)
<<
"isIn requested, but tile not valid"
;
return
false
;
}
bool
ret
=
coord
.
latitude
()
>=
_southWest
.
longitude
()
&&
coord
.
longitude
()
>=
_southWest
.
longitude
()
&&
coord
.
latitude
()
<=
_northEast
.
longitude
()
&&
coord
.
longitude
()
<=
_northEast
.
longitude
();
qCDebug
(
TerrainTileLog
)
<<
"Checking isIn: "
<<
coord
<<
" , in sw "
<<
_southWest
<<
" , ne "
<<
_northEast
<<
": "
<<
ret
;
bool
ret
=
coord
inate
.
latitude
()
>=
_southWest
.
longitude
()
&&
coordinate
.
longitude
()
>=
_southWest
.
longitude
()
&&
coord
inate
.
latitude
()
<=
_northEast
.
longitude
()
&&
coordinate
.
longitude
()
<=
_northEast
.
longitude
();
qCDebug
(
TerrainTileLog
)
<<
"Checking isIn: "
<<
coord
inate
<<
" , in sw "
<<
_southWest
<<
" , ne "
<<
_northEast
<<
": "
<<
ret
;
return
ret
;
}
float
TerrainTile
::
elevation
(
const
QGeoCoordinate
&
coordinate
)
const
{
if
(
_isValid
)
{
qCDebug
<<
"elevation: "
<<
coord
<<
" , in sw "
<<
_southWest
<<
" , ne "
<<
_northEast
;
qCDebug
(
TerrainTileLog
)
<<
"elevation: "
<<
coordinate
<<
" , in sw "
<<
_southWest
<<
" , ne "
<<
_northEast
;
// Get the index at resolution of 1 arc second
int
indexLat
=
std
::
round
((
coord
.
latitude
()
-
_southWest
.
latitude
())
/
_srtm1Increment
);
int
indexLon
=
std
::
round
((
coord
.
longitude
()
-
_southWest
.
longitude
())
/
_srtm1Increment
);
qCDebug
<<
"indexLat:indexLon"
<<
indexLat
<<
indexLon
;
// TODO (birchera): Move this down to the next debug output, once this is all properly working.
int
indexLat
=
std
::
round
((
coord
inate
.
latitude
()
-
_southWest
.
latitude
())
*
_gridSize
/
_srtm1TileSize
);
int
indexLon
=
std
::
round
((
coord
inate
.
longitude
()
-
_southWest
.
longitude
())
*
_gridSize
/
_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
);
Q_ASSERT
(
indexLon
>=
0
);
Q_ASSERT
(
indexLon
<
_gridSize
);
qCDebug
<<
"elevation"
<<
_data
[
indexLat
][
indexLon
];
qCDebug
(
TerrainTileLog
)
<<
"elevation"
<<
_data
[
indexLat
][
indexLon
];
return
_data
[
indexLat
][
indexLon
];
}
else
{
qCDebug
(
TerrainTileLog
)
<<
"Asking for elevation, but no valid data."
;
return
-
1.0
;
}
}
QGeoCoordinate
TerrainTile
::
centerCoordinate
(
void
)
const
{
return
_southWest
.
atDistanceAndAzimuth
(
_southWest
.
distanceTo
(
_northEast
)
/
2.0
,
_southWest
.
azimuthTo
(
_northEast
));
}
This diff is collapsed.
Click to expand it.
src/TerrainTile.h
View file @
17fe7893
...
...
@@ -66,11 +66,18 @@ public:
*/
float
avgElevation
(
void
)
const
{
return
_avgElevation
;
}
/**
* Accessor for the center coordinate
*
* @return center coordinate
*/
QGeoCoordinate
centerCoordinate
(
void
)
const
;
/// tile grid size in lat and lon
static
const
int
_gridSize
=
TERRAIN_TILE_SIZE
;
///
grid spacing
in degree
static
const
float
_srtm1Increment
=
1
.
0
/
(
60
.
0
*
60
.
0
)
;
///
size of a tile
in degree
static
const
double
_srtm1TileSize
;
private:
QGeoCoordinate
_southWest
;
/// South west corner of the tile
...
...
This diff is collapsed.
Click to expand it.
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