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
9adfc8dc
Commit
9adfc8dc
authored
Feb 25, 2012
by
Lionel Heng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disabled culling of imagery tiles.
parent
ee74c2c3
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
241 additions
and
179 deletions
+241
-179
Imagery.cc
src/ui/map3D/Imagery.cc
+2
-2
Pixhawk3DWidget.cc
src/ui/map3D/Pixhawk3DWidget.cc
+2
-2
Texture.cc
src/ui/map3D/Texture.cc
+62
-49
Texture.h
src/ui/map3D/Texture.h
+10
-9
TextureCache.cc
src/ui/map3D/TextureCache.cc
+29
-20
TextureCache.h
src/ui/map3D/TextureCache.h
+5
-5
WebImage.cc
src/ui/map3D/WebImage.cc
+41
-33
WebImage.h
src/ui/map3D/WebImage.h
+7
-7
WebImageCache.cc
src/ui/map3D/WebImageCache.cc
+75
-44
WebImageCache.h
src/ui/map3D/WebImageCache.h
+8
-8
No files found.
src/ui/map3D/Imagery.cc
View file @
9adfc8dc
...
@@ -42,13 +42,13 @@ const double WGS84_ECCSQ = 0.00669437999013;
...
@@ -42,13 +42,13 @@ const double WGS84_ECCSQ = 0.00669437999013;
const
int
MAX_ZOOM_LEVEL
=
20
;
const
int
MAX_ZOOM_LEVEL
=
20
;
Imagery
::
Imagery
()
Imagery
::
Imagery
()
:
mTextureCache
(
new
TextureCache
(
5
00
))
:
mTextureCache
(
new
TextureCache
(
10
00
))
,
mImageryType
(
Imagery
::
BLANK_MAP
)
,
mImageryType
(
Imagery
::
BLANK_MAP
)
,
mXOffset
(
0.0
)
,
mXOffset
(
0.0
)
,
mYOffset
(
0.0
)
,
mYOffset
(
0.0
)
,
mZOffset
(
0.0
)
,
mZOffset
(
0.0
)
{
{
setCullingActive
(
false
);
}
}
Imagery
::
Type
Imagery
::
Type
...
...
src/ui/map3D/Pixhawk3DWidget.cc
View file @
9adfc8dc
...
@@ -2053,9 +2053,9 @@ Pixhawk3DWidget::updateImagery(double originX, double originY,
...
@@ -2053,9 +2053,9 @@ Pixhawk3DWidget::updateImagery(double originX, double originY,
}
}
double
viewingRadius
=
m3DWidget
->
cameraManipulator
()
->
getDistance
()
*
10.0
;
double
viewingRadius
=
m3DWidget
->
cameraManipulator
()
->
getDistance
()
*
10.0
;
if
(
viewingRadius
<
1
00.0
)
if
(
viewingRadius
<
2
00.0
)
{
{
viewingRadius
=
1
00.0
;
viewingRadius
=
2
00.0
;
}
}
double
minResolution
=
0.25
;
double
minResolution
=
0.25
;
...
...
src/ui/map3D/Texture.cc
View file @
9adfc8dc
...
@@ -25,7 +25,7 @@ This file is part of the QGROUNDCONTROL project
...
@@ -25,7 +25,7 @@ This file is part of the QGROUNDCONTROL project
* @file
* @file
* @brief Definition of the class Texture.
* @brief Definition of the class Texture.
*
*
* @author Lionel Heng <hengli@
student
.ethz.ch>
* @author Lionel Heng <hengli@
inf
.ethz.ch>
*
*
*/
*/
...
@@ -33,69 +33,78 @@ This file is part of the QGROUNDCONTROL project
...
@@ -33,69 +33,78 @@ This file is part of the QGROUNDCONTROL project
#include "Texture.h"
#include "Texture.h"
Texture
::
Texture
(
unsigned
int
_
id
)
Texture
::
Texture
(
quint64
id
)
:
id
(
_
id
)
:
mId
(
id
)
,
t
exture2D
(
new
osg
::
Texture2D
)
,
mT
exture2D
(
new
osg
::
Texture2D
)
,
g
eometry
(
new
osg
::
Geometry
)
,
mG
eometry
(
new
osg
::
Geometry
)
{
{
t
exture2D
->
setFilter
(
osg
::
Texture
::
MIN_FILTER
,
osg
::
Texture
::
NEAREST
);
mT
exture2D
->
setFilter
(
osg
::
Texture
::
MIN_FILTER
,
osg
::
Texture
::
NEAREST
);
t
exture2D
->
setFilter
(
osg
::
Texture
::
MAG_FILTER
,
osg
::
Texture
::
NEAREST
);
mT
exture2D
->
setFilter
(
osg
::
Texture
::
MAG_FILTER
,
osg
::
Texture
::
NEAREST
);
t
exture2D
->
setDataVariance
(
osg
::
Object
::
DYNAMIC
);
mT
exture2D
->
setDataVariance
(
osg
::
Object
::
DYNAMIC
);
t
exture2D
->
setResizeNonPowerOfTwoHint
(
false
);
mT
exture2D
->
setResizeNonPowerOfTwoHint
(
false
);
osg
::
ref_ptr
<
osg
::
Image
>
image
=
new
osg
::
Image
;
osg
::
ref_ptr
<
osg
::
Image
>
image
=
new
osg
::
Image
;
t
exture2D
->
setImage
(
image
);
mT
exture2D
->
setImage
(
image
);
osg
::
ref_ptr
<
osg
::
Vec3dArray
>
vertices
(
new
osg
::
Vec3dArray
(
4
));
osg
::
ref_ptr
<
osg
::
Vec3dArray
>
vertices
(
new
osg
::
Vec3dArray
(
4
));
g
eometry
->
setVertexArray
(
vertices
);
mG
eometry
->
setVertexArray
(
vertices
);
osg
::
ref_ptr
<
osg
::
Vec2Array
>
textureCoords
=
new
osg
::
Vec2Array
;
osg
::
ref_ptr
<
osg
::
Vec2Array
>
textureCoords
=
new
osg
::
Vec2Array
;
textureCoords
->
push_back
(
osg
::
Vec2
(
0.0
f
,
1.0
f
));
textureCoords
->
push_back
(
osg
::
Vec2
(
0.0
f
,
1.0
f
));
textureCoords
->
push_back
(
osg
::
Vec2
(
1.0
f
,
1.0
f
));
textureCoords
->
push_back
(
osg
::
Vec2
(
1.0
f
,
1.0
f
));
textureCoords
->
push_back
(
osg
::
Vec2
(
1.0
f
,
0.0
f
));
textureCoords
->
push_back
(
osg
::
Vec2
(
1.0
f
,
0.0
f
));
textureCoords
->
push_back
(
osg
::
Vec2
(
0.0
f
,
0.0
f
));
textureCoords
->
push_back
(
osg
::
Vec2
(
0.0
f
,
0.0
f
));
g
eometry
->
setTexCoordArray
(
0
,
textureCoords
);
mG
eometry
->
setTexCoordArray
(
0
,
textureCoords
);
g
eometry
->
addPrimitiveSet
(
new
osg
::
DrawArrays
(
osg
::
PrimitiveSet
::
LINES
,
mG
eometry
->
addPrimitiveSet
(
new
osg
::
DrawArrays
(
osg
::
PrimitiveSet
::
LINES
,
0
,
4
));
0
,
4
));
osg
::
ref_ptr
<
osg
::
Vec4Array
>
colors
(
new
osg
::
Vec4Array
);
osg
::
ref_ptr
<
osg
::
Vec4Array
>
colors
(
new
osg
::
Vec4Array
);
colors
->
push_back
(
osg
::
Vec4
(
0.0
f
,
0.0
f
,
1.0
f
,
1.0
f
));
colors
->
push_back
(
osg
::
Vec4
(
0.0
f
,
0.0
f
,
1.0
f
,
1.0
f
));
g
eometry
->
setColorArray
(
colors
);
mG
eometry
->
setColorArray
(
colors
);
g
eometry
->
setColorBinding
(
osg
::
Geometry
::
BIND_OVERALL
);
mG
eometry
->
setColorBinding
(
osg
::
Geometry
::
BIND_OVERALL
);
g
eometry
->
setUseDisplayList
(
false
);
mG
eometry
->
setUseDisplayList
(
false
);
osg
::
ref_ptr
<
osg
::
LineWidth
>
linewidth
(
new
osg
::
LineWidth
);
osg
::
ref_ptr
<
osg
::
LineWidth
>
linewidth
(
new
osg
::
LineWidth
);
linewidth
->
setWidth
(
2.0
f
);
linewidth
->
setWidth
(
2.0
f
);
g
eometry
->
getOrCreateStateSet
()
->
mG
eometry
->
getOrCreateStateSet
()
->
setAttributeAndModes
(
linewidth
,
osg
::
StateAttribute
::
ON
);
setAttributeAndModes
(
linewidth
,
osg
::
StateAttribute
::
ON
);
g
eometry
->
getOrCreateStateSet
()
->
mG
eometry
->
getOrCreateStateSet
()
->
setMode
(
GL_LIGHTING
,
osg
::
StateAttribute
::
OFF
);
setMode
(
GL_LIGHTING
,
osg
::
StateAttribute
::
OFF
);
}
}
const
QString
&
const
QString
&
Texture
::
getSourceURL
(
void
)
const
Texture
::
getSourceURL
(
void
)
const
{
{
return
sourceURL
;
return
mSourceURL
;
}
void
Texture
::
setId
(
quint64
id
)
{
mId
=
id
;
}
}
void
void
Texture
::
sync
(
const
WebImagePtr
&
image
)
Texture
::
sync
(
const
WebImagePtr
&
image
)
{
{
s
tate
=
static_cast
<
State
>
(
image
->
getState
());
mS
tate
=
static_cast
<
State
>
(
image
->
getState
());
if
(
image
->
getState
()
!=
WebImage
::
UNINITIALIZED
&&
if
(
image
->
getState
()
!=
WebImage
::
UNINITIALIZED
&&
sourceURL
!=
image
->
getSourceURL
())
{
mSourceURL
!=
image
->
getSourceURL
())
sourceURL
=
image
->
getSourceURL
();
{
mSourceURL
=
image
->
getSourceURL
();
}
}
if
(
image
->
getState
()
==
WebImage
::
READY
&&
image
->
getSyncFlag
())
{
if
(
image
->
getState
()
==
WebImage
::
READY
&&
image
->
getSyncFlag
())
{
image
->
setSyncFlag
(
false
);
image
->
setSyncFlag
(
false
);
if
(
texture2D
->
getImage
()
!=
NULL
)
{
if
(
mTexture2D
->
getImage
()
!=
NULL
)
texture2D
->
getImage
()
->
setImage
(
image
->
getWidth
(),
{
mTexture2D
->
getImage
()
->
setImage
(
image
->
getWidth
(),
image
->
getHeight
(),
image
->
getHeight
(),
1
,
1
,
GL_RGBA
,
GL_RGBA
,
...
@@ -103,7 +112,7 @@ Texture::sync(const WebImagePtr& image)
...
@@ -103,7 +112,7 @@ Texture::sync(const WebImagePtr& image)
GL_UNSIGNED_BYTE
,
GL_UNSIGNED_BYTE
,
image
->
getImageData
(),
image
->
getImageData
(),
osg
::
Image
::
NO_DELETE
);
osg
::
Image
::
NO_DELETE
);
t
exture2D
->
getImage
()
->
dirty
();
mT
exture2D
->
getImage
()
->
dirty
();
}
}
}
}
}
}
...
@@ -123,40 +132,44 @@ Texture::draw(double x1, double y1, double x2, double y2,
...
@@ -123,40 +132,44 @@ Texture::draw(double x1, double y1, double x2, double y2,
bool
smoothInterpolation
)
const
bool
smoothInterpolation
)
const
{
{
osg
::
Vec3dArray
*
vertices
=
osg
::
Vec3dArray
*
vertices
=
static_cast
<
osg
::
Vec3dArray
*>
(
g
eometry
->
getVertexArray
());
static_cast
<
osg
::
Vec3dArray
*>
(
mG
eometry
->
getVertexArray
());
(
*
vertices
)[
0
].
set
(
x1
,
y1
,
z
);
(
*
vertices
)[
0
].
set
(
x1
,
y1
,
z
);
(
*
vertices
)[
1
].
set
(
x2
,
y2
,
z
);
(
*
vertices
)[
1
].
set
(
x2
,
y2
,
z
);
(
*
vertices
)[
2
].
set
(
x3
,
y3
,
z
);
(
*
vertices
)[
2
].
set
(
x3
,
y3
,
z
);
(
*
vertices
)[
3
].
set
(
x4
,
y4
,
z
);
(
*
vertices
)[
3
].
set
(
x4
,
y4
,
z
);
osg
::
DrawArrays
*
drawarrays
=
osg
::
DrawArrays
*
drawarrays
=
static_cast
<
osg
::
DrawArrays
*>
(
g
eometry
->
getPrimitiveSet
(
0
));
static_cast
<
osg
::
DrawArrays
*>
(
mG
eometry
->
getPrimitiveSet
(
0
));
osg
::
Vec4Array
*
colors
=
osg
::
Vec4Array
*
colors
=
static_cast
<
osg
::
Vec4Array
*>
(
g
eometry
->
getColorArray
());
static_cast
<
osg
::
Vec4Array
*>
(
mG
eometry
->
getColorArray
());
if
(
state
==
REQUESTED
)
{
if
(
mState
==
REQUESTED
)
{
drawarrays
->
set
(
osg
::
PrimitiveSet
::
LINE_LOOP
,
0
,
4
);
drawarrays
->
set
(
osg
::
PrimitiveSet
::
LINE_LOOP
,
0
,
4
);
(
*
colors
)[
0
].
set
(
0.0
f
,
0.0
f
,
1.0
f
,
1.0
f
);
(
*
colors
)[
0
].
set
(
0.0
f
,
0.0
f
,
1.0
f
,
1.0
f
);
g
eometry
->
getOrCreateStateSet
()
->
mG
eometry
->
getOrCreateStateSet
()
->
setTextureAttributeAndModes
(
0
,
t
exture2D
,
osg
::
StateAttribute
::
OFF
);
setTextureAttributeAndModes
(
0
,
mT
exture2D
,
osg
::
StateAttribute
::
OFF
);
return
g
eometry
;
return
mG
eometry
;
}
}
if
(
smoothInterpolation
)
{
if
(
smoothInterpolation
)
texture2D
->
setFilter
(
osg
::
Texture
::
MIN_FILTER
,
osg
::
Texture
::
LINEAR
);
{
texture2D
->
setFilter
(
osg
::
Texture
::
MAG_FILTER
,
osg
::
Texture
::
LINEAR
);
mTexture2D
->
setFilter
(
osg
::
Texture
::
MIN_FILTER
,
osg
::
Texture
::
LINEAR
);
}
else
{
mTexture2D
->
setFilter
(
osg
::
Texture
::
MAG_FILTER
,
osg
::
Texture
::
LINEAR
);
texture2D
->
setFilter
(
osg
::
Texture
::
MIN_FILTER
,
osg
::
Texture
::
NEAREST
);
}
texture2D
->
setFilter
(
osg
::
Texture
::
MAG_FILTER
,
osg
::
Texture
::
NEAREST
);
else
{
mTexture2D
->
setFilter
(
osg
::
Texture
::
MIN_FILTER
,
osg
::
Texture
::
NEAREST
);
mTexture2D
->
setFilter
(
osg
::
Texture
::
MAG_FILTER
,
osg
::
Texture
::
NEAREST
);
}
}
drawarrays
->
set
(
osg
::
PrimitiveSet
::
POLYGON
,
0
,
4
);
drawarrays
->
set
(
osg
::
PrimitiveSet
::
POLYGON
,
0
,
4
);
(
*
colors
)[
0
].
set
(
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
);
(
*
colors
)[
0
].
set
(
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
);
g
eometry
->
getOrCreateStateSet
()
->
mG
eometry
->
getOrCreateStateSet
()
->
setTextureAttributeAndModes
(
0
,
t
exture2D
,
osg
::
StateAttribute
::
ON
);
setTextureAttributeAndModes
(
0
,
mT
exture2D
,
osg
::
StateAttribute
::
ON
);
return
g
eometry
;
return
mG
eometry
;
}
}
src/ui/map3D/Texture.h
View file @
9adfc8dc
...
@@ -25,7 +25,7 @@ This file is part of the QGROUNDCONTROL project
...
@@ -25,7 +25,7 @@ This file is part of the QGROUNDCONTROL project
* @file
* @file
* @brief Definition of the class Texture.
* @brief Definition of the class Texture.
*
*
* @author Lionel Heng <hengli@
student
.ethz.ch>
* @author Lionel Heng <hengli@
inf
.ethz.ch>
*
*
*/
*/
...
@@ -43,11 +43,11 @@ This file is part of the QGROUNDCONTROL project
...
@@ -43,11 +43,11 @@ This file is part of the QGROUNDCONTROL project
class
Texture
class
Texture
{
{
public:
public:
explicit
Texture
(
unsigned
int
_
id
);
explicit
Texture
(
quint64
id
);
const
QString
&
getSourceURL
(
void
)
const
;
const
QString
&
getSourceURL
(
void
)
const
;
void
setId
(
unsigned
int
_
id
);
void
setId
(
quint64
id
);
void
sync
(
const
WebImagePtr
&
image
);
void
sync
(
const
WebImagePtr
&
image
);
...
@@ -60,17 +60,18 @@ public:
...
@@ -60,17 +60,18 @@ public:
bool
smoothInterpolation
)
const
;
bool
smoothInterpolation
)
const
;
private:
private:
enum
State
{
enum
State
{
UNINITIALIZED
=
0
,
UNINITIALIZED
=
0
,
REQUESTED
=
1
,
REQUESTED
=
1
,
READY
=
2
READY
=
2
};
};
State
s
tate
;
State
mS
tate
;
QString
s
ourceURL
;
QString
mS
ourceURL
;
unsigned
int
i
d
;
quint64
mI
d
;
osg
::
ref_ptr
<
osg
::
Texture2D
>
t
exture2D
;
osg
::
ref_ptr
<
osg
::
Texture2D
>
mT
exture2D
;
osg
::
ref_ptr
<
osg
::
Geometry
>
g
eometry
;
osg
::
ref_ptr
<
osg
::
Geometry
>
mG
eometry
;
};
};
typedef
QSharedPointer
<
Texture
>
TexturePtr
;
typedef
QSharedPointer
<
Texture
>
TexturePtr
;
...
...
src/ui/map3D/TextureCache.cc
View file @
9adfc8dc
...
@@ -25,34 +25,37 @@ This file is part of the QGROUNDCONTROL project
...
@@ -25,34 +25,37 @@ This file is part of the QGROUNDCONTROL project
* @file
* @file
* @brief Definition of the class TextureCache.
* @brief Definition of the class TextureCache.
*
*
* @author Lionel Heng <hengli@
student
.ethz.ch>
* @author Lionel Heng <hengli@
inf
.ethz.ch>
*
*
*/
*/
#include "TextureCache.h"
#include "TextureCache.h"
TextureCache
::
TextureCache
(
uint32_t
_
cacheSize
)
TextureCache
::
TextureCache
(
int
cacheSize
)
:
cacheSize
(
_
cacheSize
)
:
mCacheSize
(
cacheSize
)
,
i
mageCache
(
new
WebImageCache
(
0
,
cacheSize
))
,
mI
mageCache
(
new
WebImageCache
(
0
,
cacheSize
))
{
{
for
(
uint32_t
i
=
0
;
i
<
cacheSize
;
++
i
)
{
for
(
int
i
=
0
;
i
<
mCacheSize
;
++
i
)
{
TexturePtr
t
(
new
Texture
(
i
));
TexturePtr
t
(
new
Texture
(
i
));
t
extures
.
push_back
(
t
);
mT
extures
.
push_back
(
t
);
}
}
}
}
TexturePtr
TexturePtr
TextureCache
::
get
(
const
QString
&
tileURL
)
TextureCache
::
get
(
const
QString
&
tileURL
)
{
{
QPair
<
TexturePtr
,
int32_t
>
p1
=
lookup
(
tileURL
);
QPair
<
TexturePtr
,
int
>
p1
=
lookup
(
tileURL
);
if
(
!
p1
.
first
.
isNull
())
{
if
(
!
p1
.
first
.
isNull
())
{
return
p1
.
first
;
return
p1
.
first
;
}
}
QPair
<
WebImagePtr
,
int32_t
>
p2
=
imageCache
->
lookup
(
tileURL
);
QPair
<
WebImagePtr
,
int
>
p2
=
mImageCache
->
lookup
(
tileURL
);
if
(
!
p2
.
first
.
isNull
())
{
if
(
!
p2
.
first
.
isNull
())
textures
[
p2
.
second
]
->
sync
(
p2
.
first
);
{
mTextures
[
p2
.
second
]
->
sync
(
p2
.
first
);
p1
=
lookup
(
tileURL
);
p1
=
lookup
(
tileURL
);
return
p1
.
first
;
return
p1
.
first
;
...
@@ -64,19 +67,23 @@ TextureCache::get(const QString& tileURL)
...
@@ -64,19 +67,23 @@ TextureCache::get(const QString& tileURL)
void
void
TextureCache
::
sync
(
void
)
TextureCache
::
sync
(
void
)
{
{
if
(
requireSync
())
{
if
(
requireSync
())
for
(
int32_t
i
=
0
;
i
<
textures
.
size
();
++
i
)
{
{
textures
[
i
]
->
sync
(
imageCache
->
at
(
i
));
for
(
int
i
=
0
;
i
<
mTextures
.
size
();
++
i
)
{
mTextures
[
i
]
->
sync
(
mImageCache
->
at
(
i
));
}
}
}
}
}
}
QPair
<
TexturePtr
,
int
32_t
>
QPair
<
TexturePtr
,
int
>
TextureCache
::
lookup
(
const
QString
&
tileURL
)
TextureCache
::
lookup
(
const
QString
&
tileURL
)
{
{
for
(
int32_t
i
=
0
;
i
<
textures
.
size
();
++
i
)
{
for
(
int
i
=
0
;
i
<
mTextures
.
size
();
++
i
)
if
(
textures
[
i
]
->
getSourceURL
()
==
tileURL
)
{
{
return
qMakePair
(
textures
[
i
],
i
);
if
(
mTextures
[
i
]
->
getSourceURL
()
==
tileURL
)
{
return
qMakePair
(
mTextures
[
i
],
i
);
}
}
}
}
...
@@ -86,8 +93,10 @@ TextureCache::lookup(const QString& tileURL)
...
@@ -86,8 +93,10 @@ TextureCache::lookup(const QString& tileURL)
bool
bool
TextureCache
::
requireSync
(
void
)
const
TextureCache
::
requireSync
(
void
)
const
{
{
for
(
uint32_t
i
=
0
;
i
<
cacheSize
;
++
i
)
{
for
(
int
i
=
0
;
i
<
mCacheSize
;
++
i
)
if
(
imageCache
->
at
(
i
)
->
getSyncFlag
())
{
{
if
(
mImageCache
->
at
(
i
)
->
getSyncFlag
())
{
return
true
;
return
true
;
}
}
}
}
...
...
src/ui/map3D/TextureCache.h
View file @
9adfc8dc
...
@@ -25,7 +25,7 @@ This file is part of the QGROUNDCONTROL project
...
@@ -25,7 +25,7 @@ This file is part of the QGROUNDCONTROL project
* @file
* @file
* @brief Definition of the class TextureCache.
* @brief Definition of the class TextureCache.
*
*
* @author Lionel Heng <hengli@
student
.ethz.ch>
* @author Lionel Heng <hengli@
inf
.ethz.ch>
*
*
*/
*/
...
@@ -40,7 +40,7 @@ This file is part of the QGROUNDCONTROL project
...
@@ -40,7 +40,7 @@ This file is part of the QGROUNDCONTROL project
class
TextureCache
class
TextureCache
{
{
public:
public:
explicit
TextureCache
(
uint32_
t
cacheSize
);
explicit
TextureCache
(
in
t
cacheSize
);
TexturePtr
get
(
const
QString
&
tileURL
);
TexturePtr
get
(
const
QString
&
tileURL
);
...
@@ -51,10 +51,10 @@ private:
...
@@ -51,10 +51,10 @@ private:
bool
requireSync
(
void
)
const
;
bool
requireSync
(
void
)
const
;
uint32_t
c
acheSize
;
int
mC
acheSize
;
QVector
<
TexturePtr
>
t
extures
;
QVector
<
TexturePtr
>
mT
extures
;
QScopedPointer
<
WebImageCache
>
i
mageCache
;
QScopedPointer
<
WebImageCache
>
mI
mageCache
;
};
};
#endif // TEXTURECACHE_H
#endif // TEXTURECACHE_H
src/ui/map3D/WebImage.cc
View file @
9adfc8dc
...
@@ -35,11 +35,11 @@ This file is part of the QGROUNDCONTROL project
...
@@ -35,11 +35,11 @@ This file is part of the QGROUNDCONTROL project
#include <QGLWidget>
#include <QGLWidget>
WebImage
::
WebImage
()
WebImage
::
WebImage
()
:
s
tate
(
WebImage
::
UNINITIALIZED
)
:
mS
tate
(
WebImage
::
UNINITIALIZED
)
,
s
ourceURL
(
""
)
,
mS
ourceURL
(
""
)
,
i
mage
(
0
)
,
mI
mage
(
0
)
,
l
astReference
(
0
)
,
mL
astReference
(
0
)
,
s
yncFlag
(
false
)
,
mS
yncFlag
(
false
)
{
{
}
}
...
@@ -47,54 +47,58 @@ WebImage::WebImage()
...
@@ -47,54 +47,58 @@ WebImage::WebImage()
void
void
WebImage
::
clear
(
void
)
WebImage
::
clear
(
void
)
{
{
i
mage
.
reset
();
mI
mage
.
reset
();
s
ourceURL
.
clear
();
mS
ourceURL
.
clear
();
s
tate
=
WebImage
::
UNINITIALIZED
;
mS
tate
=
WebImage
::
UNINITIALIZED
;
l
astReference
=
0
;
mL
astReference
=
0
;
}
}
WebImage
::
State
WebImage
::
State
WebImage
::
getState
(
void
)
const
WebImage
::
getState
(
void
)
const
{
{
return
s
tate
;
return
mS
tate
;
}
}
void
void
WebImage
::
setState
(
State
state
)
WebImage
::
setState
(
State
state
)
{
{
this
->
s
tate
=
state
;
mS
tate
=
state
;
}
}
const
QString
&
const
QString
&
WebImage
::
getSourceURL
(
void
)
const
WebImage
::
getSourceURL
(
void
)
const
{
{
return
s
ourceURL
;
return
mS
ourceURL
;
}
}
void
void
WebImage
::
setSourceURL
(
const
QString
&
url
)
WebImage
::
setSourceURL
(
const
QString
&
url
)
{
{
s
ourceURL
=
url
;
mS
ourceURL
=
url
;
}
}
uchar
*
uchar
*
WebImage
::
getImageData
(
void
)
const
WebImage
::
getImageData
(
void
)
const
{
{
return
i
mage
->
scanLine
(
0
);
return
mI
mage
->
scanLine
(
0
);
}
}
bool
bool
WebImage
::
setData
(
const
QByteArray
&
data
)
WebImage
::
setData
(
const
QByteArray
&
data
)
{
{
QImage
tempImage
;
QImage
tempImage
;
if
(
tempImage
.
loadFromData
(
data
))
{
if
(
tempImage
.
loadFromData
(
data
))
if
(
image
.
isNull
())
{
{
image
.
reset
(
new
QImage
);
if
(
mImage
.
isNull
())
{
mImage
.
reset
(
new
QImage
);
}
}
*
i
mage
=
QGLWidget
::
convertToGLFormat
(
tempImage
);
*
mI
mage
=
QGLWidget
::
convertToGLFormat
(
tempImage
);
return
true
;
return
true
;
}
else
{
}
else
{
return
false
;
return
false
;
}
}
}
}
...
@@ -103,14 +107,18 @@ bool
...
@@ -103,14 +107,18 @@ bool
WebImage
::
setData
(
const
QString
&
filename
)
WebImage
::
setData
(
const
QString
&
filename
)
{
{
QImage
tempImage
;
QImage
tempImage
;
if
(
tempImage
.
load
(
filename
))
{
if
(
tempImage
.
load
(
filename
))
if
(
image
.
isNull
())
{
{
image
.
reset
(
new
QImage
);
if
(
mImage
.
isNull
())
{
mImage
.
reset
(
new
QImage
);
}
}
*
i
mage
=
QGLWidget
::
convertToGLFormat
(
tempImage
);
*
mI
mage
=
QGLWidget
::
convertToGLFormat
(
tempImage
);
return
true
;
return
true
;
}
else
{
}
else
{
return
false
;
return
false
;
}
}
}
}
...
@@ -118,41 +126,41 @@ WebImage::setData(const QString& filename)
...
@@ -118,41 +126,41 @@ WebImage::setData(const QString& filename)
int
int
WebImage
::
getWidth
(
void
)
const
WebImage
::
getWidth
(
void
)
const
{
{
return
i
mage
->
width
();
return
mI
mage
->
width
();
}
}
int
int
WebImage
::
getHeight
(
void
)
const
WebImage
::
getHeight
(
void
)
const
{
{
return
i
mage
->
height
();
return
mI
mage
->
height
();
}
}
int
int
WebImage
::
getByteCount
(
void
)
const
WebImage
::
getByteCount
(
void
)
const
{
{
return
i
mage
->
byteCount
();
return
mI
mage
->
byteCount
();
}
}
ulong
quint64
WebImage
::
getLastReference
(
void
)
const
WebImage
::
getLastReference
(
void
)
const
{
{
return
l
astReference
;
return
mL
astReference
;
}
}
void
void
WebImage
::
setLastReference
(
ulong
value
)
WebImage
::
setLastReference
(
quint64
value
)
{
{
l
astReference
=
value
;
mL
astReference
=
value
;
}
}
bool
bool
WebImage
::
getSyncFlag
(
void
)
const
WebImage
::
getSyncFlag
(
void
)
const
{
{
return
s
yncFlag
;
return
mS
yncFlag
;
}
}
void
void
WebImage
::
setSyncFlag
(
bool
onoff
)
WebImage
::
setSyncFlag
(
bool
onoff
)
{
{
s
yncFlag
=
onoff
;
mS
yncFlag
=
onoff
;
}
}
src/ui/map3D/WebImage.h
View file @
9adfc8dc
...
@@ -64,18 +64,18 @@ public:
...
@@ -64,18 +64,18 @@ public:
int
getHeight
(
void
)
const
;
int
getHeight
(
void
)
const
;
int
getByteCount
(
void
)
const
;
int
getByteCount
(
void
)
const
;
ulong
getLastReference
(
void
)
const
;
quint64
getLastReference
(
void
)
const
;
void
setLastReference
(
ulong
value
);
void
setLastReference
(
quint64
value
);
bool
getSyncFlag
(
void
)
const
;
bool
getSyncFlag
(
void
)
const
;
void
setSyncFlag
(
bool
onoff
);
void
setSyncFlag
(
bool
onoff
);
private:
private:
State
s
tate
;
State
mS
tate
;
QString
s
ourceURL
;
QString
mS
ourceURL
;
QScopedPointer
<
QImage
>
i
mage
;
QScopedPointer
<
QImage
>
mI
mage
;
ulong
l
astReference
;
quint64
mL
astReference
;
bool
s
yncFlag
;
bool
mS
yncFlag
;
};
};
typedef
QSharedPointer
<
WebImage
>
WebImagePtr
;
typedef
QSharedPointer
<
WebImage
>
WebImagePtr
;
...
...
src/ui/map3D/WebImageCache.cc
View file @
9adfc8dc
...
@@ -25,102 +25,129 @@ This file is part of the QGROUNDCONTROL project
...
@@ -25,102 +25,129 @@ This file is part of the QGROUNDCONTROL project
* @file
* @file
* @brief Definition of the class WebImageCache.
* @brief Definition of the class WebImageCache.
*
*
* @author Lionel Heng <hengli@
student
.ethz.ch>
* @author Lionel Heng <hengli@
inf
.ethz.ch>
*
*
*/
*/
#include "WebImageCache.h"
#include "WebImageCache.h"
#include <cstdio>
#include <QNetworkReply>
#include <QNetworkReply>
#include <QPixmap>
#include <QPixmap>
WebImageCache
::
WebImageCache
(
QObject
*
parent
,
uint32_t
_
cacheSize
)
WebImageCache
::
WebImageCache
(
QObject
*
parent
,
int
cacheSize
)
:
QObject
(
parent
)
:
QObject
(
parent
)
,
cacheSize
(
_
cacheSize
)
,
mCacheSize
(
cacheSize
)
,
c
urrentReference
(
0
)
,
mC
urrentReference
(
0
)
,
n
etworkManager
(
new
QNetworkAccessManager
)
,
mN
etworkManager
(
new
QNetworkAccessManager
)
{
{
for
(
uint32_t
i
=
0
;
i
<
cacheSize
;
++
i
)
{
for
(
int
i
=
0
;
i
<
mCacheSize
;
++
i
)
{
WebImagePtr
image
(
new
WebImage
);
WebImagePtr
image
(
new
WebImage
);
w
ebImages
.
push_back
(
image
);
mW
ebImages
.
push_back
(
image
);
}
}
connect
(
n
etworkManager
.
data
(),
SIGNAL
(
finished
(
QNetworkReply
*
)),
connect
(
mN
etworkManager
.
data
(),
SIGNAL
(
finished
(
QNetworkReply
*
)),
this
,
SLOT
(
downloadFinished
(
QNetworkReply
*
)));
this
,
SLOT
(
downloadFinished
(
QNetworkReply
*
)));
}
}
QPair
<
WebImagePtr
,
int
32_t
>
QPair
<
WebImagePtr
,
int
>
WebImageCache
::
lookup
(
const
QString
&
url
)
WebImageCache
::
lookup
(
const
QString
&
url
)
{
{
QPair
<
WebImagePtr
,
int
32_t
>
cacheEntry
;
QPair
<
WebImagePtr
,
int
>
cacheEntry
;
for
(
int32_t
i
=
0
;
i
<
webImages
.
size
();
++
i
)
{
for
(
int
i
=
0
;
i
<
mWebImages
.
size
();
++
i
)
if
(
webImages
[
i
]
->
getState
()
!=
WebImage
::
UNINITIALIZED
&&
{
webImages
[
i
]
->
getSourceURL
()
==
url
)
{
WebImagePtr
&
image
=
mWebImages
[
i
];
cacheEntry
.
first
=
webImages
[
i
];
if
(
image
->
getState
()
!=
WebImage
::
UNINITIALIZED
&&
image
->
getSourceURL
()
==
url
)
{
cacheEntry
.
first
=
image
;
cacheEntry
.
second
=
i
;
cacheEntry
.
second
=
i
;
break
;
break
;
}
}
}
}
if
(
cacheEntry
.
first
.
isNull
())
{
if
(
cacheEntry
.
first
.
isNull
())
for
(
int32_t
i
=
0
;
i
<
webImages
.
size
();
++
i
)
{
{
for
(
int
i
=
0
;
i
<
mWebImages
.
size
();
++
i
)
{
WebImagePtr
&
image
=
mWebImages
[
i
];
// get uninitialized image
// get uninitialized image
if
(
webImages
[
i
]
->
getState
()
==
WebImage
::
UNINITIALIZED
)
{
if
(
image
->
getState
()
==
WebImage
::
UNINITIALIZED
)
cacheEntry
.
first
=
webImages
[
i
];
{
cacheEntry
.
first
=
image
;
cacheEntry
.
second
=
i
;
cacheEntry
.
second
=
i
;
break
;
break
;
}
}
// get oldest image
// get oldest image
else
if
(
webImages
[
i
]
->
getState
()
==
WebImage
::
READY
&&
else
if
(
image
->
getState
()
==
WebImage
::
READY
&&
(
cacheEntry
.
first
.
isNull
()
||
(
cacheEntry
.
first
.
isNull
()
||
webImages
[
i
]
->
getLastReference
()
<
image
->
getLastReference
()
<
cacheEntry
.
first
->
getLastReference
()))
{
cacheEntry
.
first
->
getLastReference
()))
cacheEntry
.
first
=
webImages
[
i
];
{
cacheEntry
.
first
=
image
;
cacheEntry
.
second
=
i
;
cacheEntry
.
second
=
i
;
}
}
}
}
if
(
cacheEntry
.
first
.
isNull
())
{
if
(
cacheEntry
.
first
.
isNull
())
{
return
qMakePair
(
WebImagePtr
(),
-
1
);
return
qMakePair
(
WebImagePtr
(),
-
1
);
}
else
{
}
if
(
cacheEntry
.
first
->
getState
()
==
WebImage
::
READY
)
{
else
{
if
(
cacheEntry
.
first
->
getState
()
==
WebImage
::
READY
)
{
cacheEntry
.
first
->
clear
();
cacheEntry
.
first
->
clear
();
}
}
cacheEntry
.
first
->
setSourceURL
(
url
);
cacheEntry
.
first
->
setSourceURL
(
url
);
cacheEntry
.
first
->
setLastReference
(
c
urrentReference
);
cacheEntry
.
first
->
setLastReference
(
mC
urrentReference
);
++
c
urrentReference
;
++
mC
urrentReference
;
cacheEntry
.
first
->
setState
(
WebImage
::
REQUESTED
);
cacheEntry
.
first
->
setState
(
WebImage
::
REQUESTED
);
if
(
url
.
left
(
4
).
compare
(
"http"
)
==
0
)
{
if
(
url
.
left
(
4
).
compare
(
"http"
)
==
0
)
networkManager
->
get
(
QNetworkRequest
(
QUrl
(
url
)));
{
}
else
{
mNetworkManager
->
get
(
QNetworkRequest
(
QUrl
(
url
)));
if
(
cacheEntry
.
first
->
setData
(
url
))
{
}
else
{
if
(
cacheEntry
.
first
->
setData
(
url
))
{
cacheEntry
.
first
->
setSyncFlag
(
true
);
cacheEntry
.
first
->
setSyncFlag
(
true
);
cacheEntry
.
first
->
setState
(
WebImage
::
READY
);
cacheEntry
.
first
->
setState
(
WebImage
::
READY
);
}
else
{
}
else
{
cacheEntry
.
first
->
setState
(
WebImage
::
UNINITIALIZED
);
cacheEntry
.
first
->
setState
(
WebImage
::
UNINITIALIZED
);
}
}
}
}
return
cacheEntry
;
return
cacheEntry
;
}
}
}
else
{
}
if
(
cacheEntry
.
first
->
getState
()
==
WebImage
::
READY
)
{
else
cacheEntry
.
first
->
setLastReference
(
currentReference
);
{
++
currentReference
;
if
(
cacheEntry
.
first
->
getState
()
==
WebImage
::
READY
)
{
cacheEntry
.
first
->
setLastReference
(
mCurrentReference
);
++
mCurrentReference
;
return
cacheEntry
;
return
cacheEntry
;
}
else
{
}
else
{
return
qMakePair
(
WebImagePtr
(),
-
1
);
return
qMakePair
(
WebImagePtr
(),
-
1
);
}
}
}
}
}
}
WebImagePtr
WebImagePtr
WebImageCache
::
at
(
int
32_t
index
)
const
WebImageCache
::
at
(
int
index
)
const
{
{
return
w
ebImages
[
index
];
return
mW
ebImages
[
index
];
}
}
void
void
...
@@ -128,17 +155,21 @@ WebImageCache::downloadFinished(QNetworkReply* reply)
...
@@ -128,17 +155,21 @@ WebImageCache::downloadFinished(QNetworkReply* reply)
{
{
reply
->
deleteLater
();
reply
->
deleteLater
();
if
(
reply
->
error
()
!=
QNetworkReply
::
NoError
)
{
if
(
reply
->
error
()
!=
QNetworkReply
::
NoError
)
{
return
;
return
;
}
}
QVariant
attribute
=
reply
->
attribute
(
QNetworkRequest
::
RedirectionTargetAttribute
);
QVariant
attribute
=
reply
->
attribute
(
QNetworkRequest
::
RedirectionTargetAttribute
);
if
(
attribute
.
isValid
())
{
if
(
attribute
.
isValid
())
{
return
;
return
;
}
}
WebImagePtr
image
;
WebImagePtr
image
;
foreach
(
image
,
webImages
)
{
foreach
(
image
,
mWebImages
)
if
(
reply
->
url
().
toString
()
==
image
->
getSourceURL
())
{
{
if
(
reply
->
url
().
toString
()
==
image
->
getSourceURL
())
{
image
->
setData
(
reply
->
readAll
());
image
->
setData
(
reply
->
readAll
());
image
->
setSyncFlag
(
true
);
image
->
setSyncFlag
(
true
);
image
->
setState
(
WebImage
::
READY
);
image
->
setState
(
WebImage
::
READY
);
...
...
src/ui/map3D/WebImageCache.h
View file @
9adfc8dc
...
@@ -25,7 +25,7 @@ This file is part of the QGROUNDCONTROL project
...
@@ -25,7 +25,7 @@ This file is part of the QGROUNDCONTROL project
* @file
* @file
* @brief Definition of the class WebImageCache.
* @brief Definition of the class WebImageCache.
*
*
* @author Lionel Heng <hengli@
student
.ethz.ch>
* @author Lionel Heng <hengli@
inf
.ethz.ch>
*
*
*/
*/
...
@@ -43,22 +43,22 @@ class WebImageCache : public QObject
...
@@ -43,22 +43,22 @@ class WebImageCache : public QObject
Q_OBJECT
Q_OBJECT
public:
public:
WebImageCache
(
QObject
*
parent
,
uint32_
t
cacheSize
);
WebImageCache
(
QObject
*
parent
,
in
t
cacheSize
);
QPair
<
WebImagePtr
,
int
32_t
>
lookup
(
const
QString
&
url
);
QPair
<
WebImagePtr
,
int
>
lookup
(
const
QString
&
url
);
WebImagePtr
at
(
int
32_t
index
)
const
;
WebImagePtr
at
(
int
index
)
const
;
private
Q_SLOTS
:
private
Q_SLOTS
:
void
downloadFinished
(
QNetworkReply
*
reply
);
void
downloadFinished
(
QNetworkReply
*
reply
);
private:
private:
uint32_t
c
acheSize
;
int
mC
acheSize
;
QVector
<
WebImagePtr
>
w
ebImages
;
QVector
<
WebImagePtr
>
mW
ebImages
;
uint64_t
c
urrentReference
;
quint64
mC
urrentReference
;
QScopedPointer
<
QNetworkAccessManager
>
n
etworkManager
;
QScopedPointer
<
QNetworkAccessManager
>
mN
etworkManager
;
};
};
#endif // WEBIMAGECACHE_H
#endif // WEBIMAGECACHE_H
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