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