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
c1613c0e
Commit
c1613c0e
authored
Oct 29, 2010
by
hengli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added new 3D terrain model feature to 3D view perspective.
parent
1dc379f0
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
219 additions
and
39 deletions
+219
-39
Imagery.cc
src/ui/map3D/Imagery.cc
+9
-7
Imagery.h
src/ui/map3D/Imagery.h
+4
-3
QMap3DWidget.cc
src/ui/map3D/QMap3DWidget.cc
+18
-3
Texture.cc
src/ui/map3D/Texture.cc
+76
-12
Texture.h
src/ui/map3D/Texture.h
+5
-0
TextureCache.cc
src/ui/map3D/TextureCache.cc
+8
-6
TextureCache.h
src/ui/map3D/TextureCache.h
+3
-2
WebImage.cc
src/ui/map3D/WebImage.cc
+68
-1
WebImage.h
src/ui/map3D/WebImage.h
+7
-1
WebImageCache.cc
src/ui/map3D/WebImageCache.cc
+19
-3
WebImageCache.h
src/ui/map3D/WebImageCache.h
+2
-1
No files found.
src/ui/map3D/Imagery.cc
View file @
c1613c0e
...
@@ -165,7 +165,7 @@ void
...
@@ -165,7 +165,7 @@ void
Imagery
::
prefetch3D
(
double
radius
,
double
tileResolution
,
Imagery
::
prefetch3D
(
double
radius
,
double
tileResolution
,
double
xOrigin
,
double
yOrigin
,
double
xOrigin
,
double
yOrigin
,
double
viewXOffset
,
double
viewYOffset
,
double
viewXOffset
,
double
viewYOffset
,
const
QString
&
utmZone
)
const
QString
&
utmZone
,
bool
useHeightModel
)
{
{
int32_t
minTileX
,
minTileY
,
maxTileX
,
maxTileY
;
int32_t
minTileX
,
minTileY
,
maxTileX
,
maxTileY
;
int32_t
zoomLevel
;
int32_t
zoomLevel
;
...
@@ -183,7 +183,7 @@ Imagery::prefetch3D(double radius, double tileResolution,
...
@@ -183,7 +183,7 @@ Imagery::prefetch3D(double radius, double tileResolution,
{
{
QString
url
=
getTileLocation
(
c
,
r
,
zoomLevel
,
tileResolution
);
QString
url
=
getTileLocation
(
c
,
r
,
zoomLevel
,
tileResolution
);
TexturePtr
t
=
textureCache
->
get
(
url
);
TexturePtr
t
=
textureCache
->
get
(
url
,
useHeightModel
);
}
}
}
}
}
}
...
@@ -192,7 +192,7 @@ void
...
@@ -192,7 +192,7 @@ void
Imagery
::
draw3D
(
double
radius
,
double
tileResolution
,
Imagery
::
draw3D
(
double
radius
,
double
tileResolution
,
double
xOrigin
,
double
yOrigin
,
double
xOrigin
,
double
yOrigin
,
double
viewXOffset
,
double
viewYOffset
,
double
viewXOffset
,
double
viewYOffset
,
const
QString
&
utmZone
)
const
QString
&
utmZone
,
bool
useHeightModel
)
{
{
int32_t
minTileX
,
minTileY
,
maxTileX
,
maxTileY
;
int32_t
minTileX
,
minTileY
,
maxTileX
,
maxTileY
;
int32_t
zoomLevel
;
int32_t
zoomLevel
;
...
@@ -213,7 +213,7 @@ Imagery::draw3D(double radius, double tileResolution,
...
@@ -213,7 +213,7 @@ Imagery::draw3D(double radius, double tileResolution,
double
x1
,
y1
,
x2
,
y2
,
x3
,
y3
,
x4
,
y4
;
double
x1
,
y1
,
x2
,
y2
,
x3
,
y3
,
x4
,
y4
;
imageBounds
(
c
,
r
,
tileResolution
,
x1
,
y1
,
x2
,
y2
,
x3
,
y3
,
x4
,
y4
);
imageBounds
(
c
,
r
,
tileResolution
,
x1
,
y1
,
x2
,
y2
,
x3
,
y3
,
x4
,
y4
);
TexturePtr
t
=
textureCache
->
get
(
tileURL
);
TexturePtr
t
=
textureCache
->
get
(
tileURL
,
useHeightModel
);
if
(
!
t
.
isNull
())
if
(
!
t
.
isNull
())
{
{
...
@@ -257,7 +257,8 @@ Imagery::imageBounds(int32_t tileX, int32_t tileY, double tileResolution,
...
@@ -257,7 +257,8 @@ Imagery::imageBounds(int32_t tileX, int32_t tileY, double tileResolution,
LLtoUTM
(
lat2
,
lon2
,
x3
,
y3
,
utmZone
);
LLtoUTM
(
lat2
,
lon2
,
x3
,
y3
,
utmZone
);
LLtoUTM
(
lat2
,
lon1
,
x4
,
y4
,
utmZone
);
LLtoUTM
(
lat2
,
lon1
,
x4
,
y4
,
utmZone
);
}
}
else
if
(
currentImageryType
==
SWISSTOPO_SATELLITE
)
else
if
(
currentImageryType
==
SWISSTOPO_SATELLITE
||
currentImageryType
==
SWISSTOPO_SATELLITE_3D
)
{
{
double
utmMultiplier
=
tileResolution
*
200.0
;
double
utmMultiplier
=
tileResolution
*
200.0
;
double
minX
=
tileX
*
utmMultiplier
;
double
minX
=
tileX
*
utmMultiplier
;
...
@@ -294,7 +295,8 @@ Imagery::tileBounds(double tileResolution,
...
@@ -294,7 +295,8 @@ Imagery::tileBounds(double tileResolution,
UTMtoTile
(
maxUtmX
,
maxUtmY
,
utmZone
,
tileResolution
,
UTMtoTile
(
maxUtmX
,
maxUtmY
,
utmZone
,
tileResolution
,
maxTileX
,
minTileY
,
zoomLevel
);
maxTileX
,
minTileY
,
zoomLevel
);
}
}
else
if
(
currentImageryType
==
SWISSTOPO_SATELLITE
)
else
if
(
currentImageryType
==
SWISSTOPO_SATELLITE
||
currentImageryType
==
SWISSTOPO_SATELLITE_3D
)
{
{
double
utmMultiplier
=
tileResolution
*
200
;
double
utmMultiplier
=
tileResolution
*
200
;
...
@@ -570,7 +572,7 @@ Imagery::getTileLocation(int32_t tileX, int32_t tileY, int32_t zoomLevel,
...
@@ -570,7 +572,7 @@ Imagery::getTileLocation(int32_t tileX, int32_t tileY, int32_t zoomLevel,
oss
<<
"http://khm.google.com/vt/lbw/lyrs=y&x="
<<
tileX
oss
<<
"http://khm.google.com/vt/lbw/lyrs=y&x="
<<
tileX
<<
"&y="
<<
tileY
<<
"&z="
<<
zoomLevel
;
<<
"&y="
<<
tileY
<<
"&z="
<<
zoomLevel
;
break
;
break
;
case
SWISSTOPO_SATELLITE
:
case
SWISSTOPO_SATELLITE
:
case
SWISSTOPO_SATELLITE_3D
:
oss
<<
"../map/eth_zurich_swissimage_025/200/color/"
<<
tileY
oss
<<
"../map/eth_zurich_swissimage_025/200/color/"
<<
tileY
<<
"/tile-"
;
<<
"/tile-"
;
if
(
tileResolution
<
1.0
)
if
(
tileResolution
<
1.0
)
...
...
src/ui/map3D/Imagery.h
View file @
c1613c0e
...
@@ -45,7 +45,8 @@ public:
...
@@ -45,7 +45,8 @@ public:
{
{
GOOGLE_MAP
=
0
,
GOOGLE_MAP
=
0
,
GOOGLE_SATELLITE
=
1
,
GOOGLE_SATELLITE
=
1
,
SWISSTOPO_SATELLITE
=
2
SWISSTOPO_SATELLITE
=
2
,
SWISSTOPO_SATELLITE_3D
=
3
};
};
void
setImageryType
(
ImageryType
type
);
void
setImageryType
(
ImageryType
type
);
...
@@ -63,11 +64,11 @@ public:
...
@@ -63,11 +64,11 @@ public:
void
prefetch3D
(
double
radius
,
double
tileResolution
,
void
prefetch3D
(
double
radius
,
double
tileResolution
,
double
xOrigin
,
double
yOrigin
,
double
xOrigin
,
double
yOrigin
,
double
viewXOffset
,
double
viewYOffset
,
double
viewXOffset
,
double
viewYOffset
,
const
QString
&
utmZone
);
const
QString
&
utmZone
,
bool
useHeightModel
);
void
draw3D
(
double
radius
,
double
tileResolution
,
void
draw3D
(
double
radius
,
double
tileResolution
,
double
xOrigin
,
double
yOrigin
,
double
xOrigin
,
double
yOrigin
,
double
viewXOffset
,
double
viewYOffset
,
double
viewXOffset
,
double
viewYOffset
,
const
QString
&
utmZone
);
const
QString
&
utmZone
,
bool
useHeightModel
);
bool
update
(
void
);
bool
update
(
void
);
...
...
src/ui/map3D/QMap3DWidget.cc
View file @
c1613c0e
...
@@ -96,6 +96,7 @@ QMap3DWidget::buildLayout(void)
...
@@ -96,6 +96,7 @@ QMap3DWidget::buildLayout(void)
imageryComboBox
->
addItem
(
"Map (Google)"
);
imageryComboBox
->
addItem
(
"Map (Google)"
);
imageryComboBox
->
addItem
(
"Satellite (Google)"
);
imageryComboBox
->
addItem
(
"Satellite (Google)"
);
imageryComboBox
->
addItem
(
"Satellite (Swisstopo)"
);
imageryComboBox
->
addItem
(
"Satellite (Swisstopo)"
);
imageryComboBox
->
addItem
(
"3D Satellite (Swisstopo)"
);
QPushButton
*
recenterButton
=
new
QPushButton
(
this
);
QPushButton
*
recenterButton
=
new
QPushButton
(
this
);
recenterButton
->
setText
(
"Recenter Camera"
);
recenterButton
->
setText
(
"Recenter Camera"
);
...
@@ -547,6 +548,10 @@ QMap3DWidget::showImagery(const QString& text)
...
@@ -547,6 +548,10 @@ QMap3DWidget::showImagery(const QString& text)
{
{
imagery
->
setImageryType
(
Imagery
::
SWISSTOPO_SATELLITE
);
imagery
->
setImageryType
(
Imagery
::
SWISSTOPO_SATELLITE
);
}
}
else
if
(
text
.
compare
(
"3D Satellite (Swisstopo)"
)
==
0
)
{
imagery
->
setImageryType
(
Imagery
::
SWISSTOPO_SATELLITE_3D
);
}
displayImagery
=
true
;
displayImagery
=
true
;
}
}
}
}
...
@@ -678,6 +683,7 @@ QMap3DWidget::drawImagery(double originX, double originY, double originZ,
...
@@ -678,6 +683,7 @@ QMap3DWidget::drawImagery(double originX, double originY, double originZ,
double
minResolution
=
0.25
;
double
minResolution
=
0.25
;
double
centerResolution
=
cameraPose
.
distance
/
100.0
;
double
centerResolution
=
cameraPose
.
distance
/
100.0
;
double
maxResolution
=
1048576.0
;
double
maxResolution
=
1048576.0
;
bool
useHeightModel
=
false
;
if
(
imageryComboBox
->
currentText
().
compare
(
"Map (Google)"
)
==
0
)
if
(
imageryComboBox
->
currentText
().
compare
(
"Map (Google)"
)
==
0
)
{
{
...
@@ -692,6 +698,12 @@ QMap3DWidget::drawImagery(double originX, double originY, double originZ,
...
@@ -692,6 +698,12 @@ QMap3DWidget::drawImagery(double originX, double originY, double originZ,
minResolution
=
0.25
;
minResolution
=
0.25
;
maxResolution
=
0.25
;
maxResolution
=
0.25
;
}
}
else
if
(
imageryComboBox
->
currentText
().
compare
(
"3D Satellite (Swisstopo)"
)
==
0
)
{
minResolution
=
0.25
;
maxResolution
=
0.25
;
useHeightModel
=
true
;
}
double
resolution
=
minResolution
;
double
resolution
=
minResolution
;
while
(
resolution
*
2.0
<
centerResolution
)
while
(
resolution
*
2.0
<
centerResolution
)
...
@@ -704,7 +716,8 @@ QMap3DWidget::drawImagery(double originX, double originY, double originZ,
...
@@ -704,7 +716,8 @@ QMap3DWidget::drawImagery(double originX, double originY, double originZ,
}
}
imagery
->
draw3D
(
viewingRadius
,
resolution
,
originX
,
originY
,
imagery
->
draw3D
(
viewingRadius
,
resolution
,
originX
,
originY
,
cameraPose
.
xOffset
,
cameraPose
.
yOffset
,
zone
);
cameraPose
.
xOffset
,
cameraPose
.
yOffset
,
zone
,
useHeightModel
);
if
(
prefetch
)
if
(
prefetch
)
{
{
...
@@ -712,13 +725,15 @@ QMap3DWidget::drawImagery(double originX, double originY, double originZ,
...
@@ -712,13 +725,15 @@ QMap3DWidget::drawImagery(double originX, double originY, double originZ,
{
{
imagery
->
prefetch3D
(
viewingRadius
/
2.0
,
resolution
/
2.0
,
imagery
->
prefetch3D
(
viewingRadius
/
2.0
,
resolution
/
2.0
,
originX
,
originY
,
originX
,
originY
,
cameraPose
.
xOffset
,
cameraPose
.
yOffset
,
zone
);
cameraPose
.
xOffset
,
cameraPose
.
yOffset
,
zone
,
useHeightModel
);
}
}
if
(
resolution
*
2.0
<=
maxResolution
)
if
(
resolution
*
2.0
<=
maxResolution
)
{
{
imagery
->
prefetch3D
(
viewingRadius
*
2.0
,
resolution
*
2.0
,
imagery
->
prefetch3D
(
viewingRadius
*
2.0
,
resolution
*
2.0
,
originX
,
originY
,
originX
,
originY
,
cameraPose
.
xOffset
,
cameraPose
.
yOffset
,
zone
);
cameraPose
.
xOffset
,
cameraPose
.
yOffset
,
zone
,
useHeightModel
);
}
}
}
}
...
...
src/ui/map3D/Texture.cc
View file @
c1613c0e
...
@@ -32,6 +32,7 @@ This file is part of the QGROUNDCONTROL project
...
@@ -32,6 +32,7 @@ This file is part of the QGROUNDCONTROL project
#include "Texture.h"
#include "Texture.h"
Texture
::
Texture
()
Texture
::
Texture
()
:
_is3D
(
false
)
{
{
}
}
...
@@ -54,9 +55,11 @@ Texture::sync(const WebImagePtr& image)
...
@@ -54,9 +55,11 @@ Texture::sync(const WebImagePtr& image)
state
=
static_cast
<
State
>
(
image
->
getState
());
state
=
static_cast
<
State
>
(
image
->
getState
());
if
(
image
->
getState
()
!=
WebImage
::
UNINITIALIZED
&&
if
(
image
->
getState
()
!=
WebImage
::
UNINITIALIZED
&&
sourceURL
!=
image
->
getSourceURL
())
(
sourceURL
!=
image
->
getSourceURL
()
||
_is3D
!=
image
->
is3D
()))
{
{
sourceURL
=
image
->
getSourceURL
();
sourceURL
=
image
->
getSourceURL
();
_is3D
=
image
->
is3D
();
}
}
if
(
image
->
getState
()
==
WebImage
::
READY
&&
image
->
getSyncFlag
())
if
(
image
->
getState
()
==
WebImage
::
READY
&&
image
->
getSyncFlag
())
...
@@ -91,7 +94,9 @@ Texture::sync(const WebImagePtr& image)
...
@@ -91,7 +94,9 @@ Texture::sync(const WebImagePtr& image)
glBindTexture
(
GL_TEXTURE_2D
,
id
);
glBindTexture
(
GL_TEXTURE_2D
,
id
);
glTexSubImage2D
(
GL_TEXTURE_2D
,
0
,
0
,
0
,
imageWidth
,
imageHeight
,
glTexSubImage2D
(
GL_TEXTURE_2D
,
0
,
0
,
0
,
imageWidth
,
imageHeight
,
GL_RGBA
,
GL_UNSIGNED_BYTE
,
image
->
getData
());
GL_RGBA
,
GL_UNSIGNED_BYTE
,
image
->
getImageData
());
heightModel
=
image
->
getHeightModel
();
}
}
}
}
...
@@ -140,18 +145,77 @@ Texture::draw(float x1, float y1, float x2, float y2,
...
@@ -140,18 +145,77 @@ Texture::draw(float x1, float y1, float x2, float y2,
}
}
glColor3f
(
1.0
f
,
1.0
f
,
1.0
f
);
glColor3f
(
1.0
f
,
1.0
f
,
1.0
f
);
glBegin
(
GL_QUADS
);
if
(
!
_is3D
)
{
glBegin
(
GL_QUADS
);
glTexCoord2f
(
dx
,
maxV
-
dy
);
glVertex3f
(
x1
,
y1
,
0.0
f
);
glTexCoord2f
(
maxU
-
dx
,
maxV
-
dy
);
glVertex3f
(
x2
,
y2
,
0.0
f
);
glTexCoord2f
(
maxU
-
dx
,
dy
);
glVertex3f
(
x3
,
y3
,
0.0
f
);
glTexCoord2f
(
dx
,
dy
);
glVertex3f
(
x4
,
y4
,
0.0
f
);
glEnd
();
}
else
{
float
scaleX
=
1.0
f
/
static_cast
<
float
>
(
heightModel
.
size
()
-
1
);
for
(
int32_t
i
=
0
;
i
<
heightModel
.
size
()
-
1
;
++
i
)
{
float
scaleI
=
scaleX
*
static_cast
<
float
>
(
i
);
glTexCoord2f
(
dx
,
maxV
-
dy
);
float
scaleY
=
glVertex2f
(
x1
,
y1
);
1.0
f
/
static_cast
<
float
>
(
heightModel
[
i
].
size
()
-
1
);
glTexCoord2f
(
maxU
-
dx
,
maxV
-
dy
);
glVertex2f
(
x2
,
y2
);
glTexCoord2f
(
maxU
-
dx
,
dy
);
glVertex2f
(
x3
,
y3
);
glTexCoord2f
(
dx
,
dy
);
glVertex2f
(
x4
,
y4
);
glEnd
();
float
x1i
=
x1
+
scaleI
*
(
x4
-
x1
);
float
x1f
=
x2
+
scaleI
*
(
x3
-
x2
);
float
x2i
=
x1i
+
scaleX
*
(
x4
-
x1
);
float
x2f
=
x1f
+
scaleX
*
(
x3
-
x2
);
for
(
int32_t
j
=
0
;
j
<
heightModel
[
i
].
size
()
-
1
;
++
j
)
{
float
scaleJ
=
scaleY
*
static_cast
<
float
>
(
j
);
float
y1i
=
y1
+
scaleJ
*
(
y2
-
y1
);
float
y1f
=
y4
+
scaleJ
*
(
y3
-
y4
);
float
y2i
=
y1i
+
scaleY
*
(
y2
-
y1
);
float
y2f
=
y1f
+
scaleY
*
(
y3
-
y4
);
float
nx1
=
x1i
+
scaleJ
*
(
x1f
-
x1i
);
float
nx2
=
x1i
+
(
scaleJ
+
scaleY
)
*
(
x1f
-
x1i
);
float
nx3
=
x2i
+
(
scaleJ
+
scaleY
)
*
(
x2f
-
x2i
);
float
nx4
=
x2i
+
scaleJ
*
(
x2f
-
x2i
);
float
ny1
=
y1i
+
scaleI
*
(
y1f
-
y1i
);
float
ny2
=
y2i
+
scaleI
*
(
y2f
-
y2i
);
float
ny3
=
y2i
+
(
scaleI
+
scaleX
)
*
(
y2f
-
y2i
);
float
ny4
=
y1i
+
(
scaleI
+
scaleX
)
*
(
y1f
-
y1i
);
glBegin
(
GL_QUADS
);
glTexCoord2f
(
dx
+
scaleJ
*
(
maxU
-
dx
*
2.0
f
),
dy
+
(
1.0
f
-
scaleI
)
*
(
maxV
-
dy
*
2.0
f
));
glVertex3f
(
nx1
,
ny1
,
-
static_cast
<
float
>
(
heightModel
[
i
][
j
]));
glTexCoord2f
(
dx
+
(
scaleJ
+
scaleY
)
*
(
maxU
-
dx
*
2.0
f
),
dy
+
(
1.0
f
-
scaleI
)
*
(
maxV
-
dy
*
2.0
f
));
glVertex3f
(
nx2
,
ny2
,
-
static_cast
<
float
>
(
heightModel
[
i
][
j
+
1
]));
glTexCoord2f
(
dx
+
(
scaleJ
+
scaleY
)
*
(
maxU
-
dx
*
2.0
f
),
dy
+
(
1.0
f
-
scaleI
-
scaleX
)
*
(
maxV
-
dy
*
2.0
f
));
glVertex3f
(
nx3
,
ny3
,
-
static_cast
<
float
>
(
heightModel
[
i
+
1
][
j
+
1
]));
glTexCoord2f
(
dx
+
scaleJ
*
(
maxU
-
dx
*
2.0
f
),
dy
+
(
1.0
f
-
scaleI
-
scaleX
)
*
(
maxV
-
dy
*
2.0
f
));
glVertex3f
(
nx4
,
ny4
,
-
static_cast
<
float
>
(
heightModel
[
i
+
1
][
j
]));
glEnd
();
}
}
}
glDisable
(
GL_TEXTURE_2D
);
glDisable
(
GL_TEXTURE_2D
);
}
}
bool
Texture
::
is3D
(
void
)
const
{
return
_is3D
;
}
src/ui/map3D/Texture.h
View file @
c1613c0e
...
@@ -59,6 +59,8 @@ public:
...
@@ -59,6 +59,8 @@ public:
float
x3
,
float
y3
,
float
x4
,
float
y4
,
float
x3
,
float
y3
,
float
x4
,
float
y4
,
bool
smoothInterpolation
)
const
;
bool
smoothInterpolation
)
const
;
bool
is3D
(
void
)
const
;
private:
private:
enum
State
enum
State
{
{
...
@@ -77,6 +79,9 @@ private:
...
@@ -77,6 +79,9 @@ private:
int32_t
imageWidth
;
int32_t
imageWidth
;
int32_t
imageHeight
;
int32_t
imageHeight
;
bool
_is3D
;
QVector
<
QVector
<
int32_t
>
>
heightModel
;
float
maxU
;
float
maxU
;
float
maxV
;
float
maxV
;
};
};
...
...
src/ui/map3D/TextureCache.cc
View file @
c1613c0e
...
@@ -52,19 +52,20 @@ TextureCache::TextureCache(uint32_t _cacheSize)
...
@@ -52,19 +52,20 @@ TextureCache::TextureCache(uint32_t _cacheSize)
}
}
TexturePtr
TexturePtr
TextureCache
::
get
(
const
QString
&
tileURL
)
TextureCache
::
get
(
const
QString
&
tileURL
,
bool
useHeightModel
)
{
{
QPair
<
TexturePtr
,
int32_t
>
p1
=
lookup
(
tileURL
);
QPair
<
TexturePtr
,
int32_t
>
p1
=
lookup
(
tileURL
,
useHeightModel
);
if
(
!
p1
.
first
.
isNull
())
if
(
!
p1
.
first
.
isNull
())
{
{
return
p1
.
first
;
return
p1
.
first
;
}
}
QPair
<
WebImagePtr
,
int32_t
>
p2
=
imageCache
->
lookup
(
tileURL
);
QPair
<
WebImagePtr
,
int32_t
>
p2
=
imageCache
->
lookup
(
tileURL
,
useHeightModel
);
if
(
!
p2
.
first
.
isNull
())
if
(
!
p2
.
first
.
isNull
())
{
{
textures
[
p2
.
second
]
->
sync
(
p2
.
first
);
textures
[
p2
.
second
]
->
sync
(
p2
.
first
);
p1
=
lookup
(
tileURL
);
p1
=
lookup
(
tileURL
,
useHeightModel
);
return
p1
.
first
;
return
p1
.
first
;
}
}
...
@@ -85,11 +86,12 @@ TextureCache::sync(void)
...
@@ -85,11 +86,12 @@ TextureCache::sync(void)
}
}
QPair
<
TexturePtr
,
int32_t
>
QPair
<
TexturePtr
,
int32_t
>
TextureCache
::
lookup
(
const
QString
&
tileURL
)
TextureCache
::
lookup
(
const
QString
&
tileURL
,
bool
useHeightModel
)
{
{
for
(
int32_t
i
=
0
;
i
<
textures
.
size
();
++
i
)
for
(
int32_t
i
=
0
;
i
<
textures
.
size
();
++
i
)
{
{
if
(
textures
[
i
]
->
getSourceURL
()
==
tileURL
)
if
(
textures
[
i
]
->
getSourceURL
()
==
tileURL
&&
textures
[
i
]
->
is3D
()
==
useHeightModel
)
{
{
return
qMakePair
(
textures
[
i
],
i
);
return
qMakePair
(
textures
[
i
],
i
);
}
}
...
...
src/ui/map3D/TextureCache.h
View file @
c1613c0e
...
@@ -42,12 +42,13 @@ class TextureCache
...
@@ -42,12 +42,13 @@ class TextureCache
public:
public:
explicit
TextureCache
(
uint32_t
cacheSize
);
explicit
TextureCache
(
uint32_t
cacheSize
);
TexturePtr
get
(
const
QString
&
tileURL
);
TexturePtr
get
(
const
QString
&
tileURL
,
bool
useHeightModel
=
false
);
void
sync
(
void
);
void
sync
(
void
);
private:
private:
QPair
<
TexturePtr
,
int32_t
>
lookup
(
const
QString
&
tileURL
);
QPair
<
TexturePtr
,
int32_t
>
lookup
(
const
QString
&
tileURL
,
bool
useHeightModel
);
bool
requireSync
(
void
)
const
;
bool
requireSync
(
void
)
const
;
...
...
src/ui/map3D/WebImage.cc
View file @
c1613c0e
...
@@ -31,6 +31,7 @@ This file is part of the QGROUNDCONTROL project
...
@@ -31,6 +31,7 @@ This file is part of the QGROUNDCONTROL project
#include "WebImage.h"
#include "WebImage.h"
#include <QFile>
#include <QGLWidget>
#include <QGLWidget>
WebImage
::
WebImage
()
WebImage
::
WebImage
()
...
@@ -38,6 +39,7 @@ WebImage::WebImage()
...
@@ -38,6 +39,7 @@ WebImage::WebImage()
,
sourceURL
(
""
)
,
sourceURL
(
""
)
,
image
(
0
)
,
image
(
0
)
,
lastReference
(
0
)
,
lastReference
(
0
)
,
_is3D
(
false
)
,
syncFlag
(
false
)
,
syncFlag
(
false
)
{
{
...
@@ -50,6 +52,7 @@ WebImage::clear(void)
...
@@ -50,6 +52,7 @@ WebImage::clear(void)
sourceURL
.
clear
();
sourceURL
.
clear
();
state
=
WebImage
::
UNINITIALIZED
;
state
=
WebImage
::
UNINITIALIZED
;
lastReference
=
0
;
lastReference
=
0
;
heightModel
.
clear
();
}
}
WebImage
::
State
WebImage
::
State
...
@@ -77,11 +80,17 @@ WebImage::setSourceURL(const QString& url)
...
@@ -77,11 +80,17 @@ WebImage::setSourceURL(const QString& url)
}
}
const
uint8_t
*
const
uint8_t
*
WebImage
::
getData
(
void
)
const
WebImage
::
get
Image
Data
(
void
)
const
{
{
return
image
->
scanLine
(
0
);
return
image
->
scanLine
(
0
);
}
}
const
QVector
<
QVector
<
int32_t
>
>&
WebImage
::
getHeightModel
(
void
)
const
{
return
heightModel
;
}
bool
bool
WebImage
::
setData
(
const
QByteArray
&
data
)
WebImage
::
setData
(
const
QByteArray
&
data
)
{
{
...
@@ -122,6 +131,58 @@ WebImage::setData(const QString& filename)
...
@@ -122,6 +131,58 @@ WebImage::setData(const QString& filename)
}
}
}
}
bool
WebImage
::
setData
(
const
QString
&
imageFilename
,
const
QString
&
heightFilename
)
{
QFile
heightFile
(
heightFilename
);
QImage
tempImage
;
if
(
tempImage
.
load
(
imageFilename
)
&&
heightFile
.
open
(
QIODevice
::
ReadOnly
))
{
if
(
image
.
isNull
())
{
image
.
reset
(
new
QImage
);
}
*
image
=
QGLWidget
::
convertToGLFormat
(
tempImage
);
QDataStream
heightDataStream
(
&
heightFile
);
// read in width and height values for height map
char
header
[
8
];
heightDataStream
.
readRawData
(
header
,
8
);
int32_t
height
=
*
(
reinterpret_cast
<
int32_t
*>
(
header
));
int32_t
width
=
*
(
reinterpret_cast
<
int32_t
*>
(
header
+
4
));
char
buffer
[
height
*
width
*
sizeof
(
int32_t
)];
heightDataStream
.
readRawData
(
buffer
,
height
*
width
*
sizeof
(
int32_t
));
heightModel
.
clear
();
for
(
int32_t
i
=
0
;
i
<
height
;
++
i
)
{
QVector
<
int32_t
>
scanline
;
for
(
int32_t
j
=
0
;
j
<
width
;
++
j
)
{
int32_t
n
=
*
(
reinterpret_cast
<
int32_t
*>
(
buffer
+
(
i
*
height
+
j
)
*
sizeof
(
int32_t
)));
scanline
.
push_back
(
n
);
}
heightModel
.
push_back
(
scanline
);
}
heightFile
.
close
();
_is3D
=
true
;
return
true
;
}
else
{
return
false
;
}
}
int32_t
int32_t
WebImage
::
getWidth
(
void
)
const
WebImage
::
getWidth
(
void
)
const
{
{
...
@@ -140,6 +201,12 @@ WebImage::getByteCount(void) const
...
@@ -140,6 +201,12 @@ WebImage::getByteCount(void) const
return
image
->
byteCount
();
return
image
->
byteCount
();
}
}
bool
WebImage
::
is3D
(
void
)
const
{
return
_is3D
;
}
uint64_t
uint64_t
WebImage
::
getLastReference
(
void
)
const
WebImage
::
getLastReference
(
void
)
const
{
{
...
...
src/ui/map3D/WebImage.h
View file @
c1613c0e
...
@@ -57,14 +57,18 @@ public:
...
@@ -57,14 +57,18 @@ public:
const
QString
&
getSourceURL
(
void
)
const
;
const
QString
&
getSourceURL
(
void
)
const
;
void
setSourceURL
(
const
QString
&
url
);
void
setSourceURL
(
const
QString
&
url
);
const
uint8_t
*
getData
(
void
)
const
;
const
uint8_t
*
getImageData
(
void
)
const
;
const
QVector
<
QVector
<
int32_t
>
>&
getHeightModel
(
void
)
const
;
bool
setData
(
const
QByteArray
&
data
);
bool
setData
(
const
QByteArray
&
data
);
bool
setData
(
const
QString
&
filename
);
bool
setData
(
const
QString
&
filename
);
bool
setData
(
const
QString
&
imageFilename
,
const
QString
&
heightFilename
);
int32_t
getWidth
(
void
)
const
;
int32_t
getWidth
(
void
)
const
;
int32_t
getHeight
(
void
)
const
;
int32_t
getHeight
(
void
)
const
;
int32_t
getByteCount
(
void
)
const
;
int32_t
getByteCount
(
void
)
const
;
bool
is3D
(
void
)
const
;
uint64_t
getLastReference
(
void
)
const
;
uint64_t
getLastReference
(
void
)
const
;
void
setLastReference
(
uint64_t
value
);
void
setLastReference
(
uint64_t
value
);
...
@@ -75,7 +79,9 @@ private:
...
@@ -75,7 +79,9 @@ private:
State
state
;
State
state
;
QString
sourceURL
;
QString
sourceURL
;
QScopedPointer
<
QImage
>
image
;
QScopedPointer
<
QImage
>
image
;
QVector
<
QVector
<
int32_t
>
>
heightModel
;
uint64_t
lastReference
;
uint64_t
lastReference
;
bool
_is3D
;
bool
syncFlag
;
bool
syncFlag
;
};
};
...
...
src/ui/map3D/WebImageCache.cc
View file @
c1613c0e
...
@@ -52,14 +52,15 @@ WebImageCache::WebImageCache(QObject* parent, uint32_t _cacheSize)
...
@@ -52,14 +52,15 @@ WebImageCache::WebImageCache(QObject* parent, uint32_t _cacheSize)
}
}
QPair
<
WebImagePtr
,
int32_t
>
QPair
<
WebImagePtr
,
int32_t
>
WebImageCache
::
lookup
(
const
QString
&
url
)
WebImageCache
::
lookup
(
const
QString
&
url
,
bool
useHeightModel
)
{
{
QPair
<
WebImagePtr
,
int32_t
>
cacheEntry
;
QPair
<
WebImagePtr
,
int32_t
>
cacheEntry
;
for
(
int32_t
i
=
0
;
i
<
webImages
.
size
();
++
i
)
for
(
int32_t
i
=
0
;
i
<
webImages
.
size
();
++
i
)
{
{
if
(
webImages
[
i
]
->
getState
()
!=
WebImage
::
UNINITIALIZED
&&
if
(
webImages
[
i
]
->
getState
()
!=
WebImage
::
UNINITIALIZED
&&
webImages
[
i
]
->
getSourceURL
()
==
url
)
webImages
[
i
]
->
getSourceURL
()
==
url
&&
webImages
[
i
]
->
is3D
()
==
useHeightModel
)
{
{
cacheEntry
.
first
=
webImages
[
i
];
cacheEntry
.
first
=
webImages
[
i
];
cacheEntry
.
second
=
i
;
cacheEntry
.
second
=
i
;
...
@@ -110,7 +111,22 @@ WebImageCache::lookup(const QString& url)
...
@@ -110,7 +111,22 @@ WebImageCache::lookup(const QString& url)
}
}
else
else
{
{
if
(
cacheEntry
.
first
->
setData
(
url
))
bool
success
;
if
(
useHeightModel
)
{
QString
heightURL
=
url
;
heightURL
.
replace
(
"color"
,
"dom"
);
heightURL
.
replace
(
".jpg"
,
".txt"
);
success
=
cacheEntry
.
first
->
setData
(
url
,
heightURL
);
}
else
{
success
=
cacheEntry
.
first
->
setData
(
url
);
}
if
(
success
)
{
{
cacheEntry
.
first
->
setSyncFlag
(
true
);
cacheEntry
.
first
->
setSyncFlag
(
true
);
cacheEntry
.
first
->
setState
(
WebImage
::
READY
);
cacheEntry
.
first
->
setState
(
WebImage
::
READY
);
...
...
src/ui/map3D/WebImageCache.h
View file @
c1613c0e
...
@@ -45,7 +45,8 @@ class WebImageCache : public QObject
...
@@ -45,7 +45,8 @@ class WebImageCache : public QObject
public:
public:
WebImageCache
(
QObject
*
parent
,
uint32_t
cacheSize
);
WebImageCache
(
QObject
*
parent
,
uint32_t
cacheSize
);
QPair
<
WebImagePtr
,
int32_t
>
lookup
(
const
QString
&
url
);
QPair
<
WebImagePtr
,
int32_t
>
lookup
(
const
QString
&
url
,
bool
useHeightModel
);
WebImagePtr
at
(
int32_t
index
)
const
;
WebImagePtr
at
(
int32_t
index
)
const
;
...
...
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