Update to OsgEarth 2.0

This commit is contained in:
Pirmin Kalberer 2011-03-06 00:26:24 +01:00
parent 6b84c44403
commit 4c36e58004
8 changed files with 175 additions and 2078 deletions

View File

@ -13,7 +13,6 @@ SET (globe_plugin_SRCS
globe_plugin.cpp
qgsosgviewer.cpp
qgsosgearthtilesource.cpp
Controls.cpp
globe_plugin_dialog.cpp
)

View File

@ -1,516 +0,0 @@
/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2008-2010 Pelican Mapping
* http://osgearth.org
*
* osgEarth is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef OSGEARTHUTIL_CONTROLS
#define OSGEARTHUTIL_CONTROLS
#include <osgEarthUtil/Common>
#include <osgEarth/Common>
#include <osg/Drawable>
#include <osg/Geode>
#include <osgGA/GUIEventHandler>
#include <osgViewer/View>
#include <osgText/Font>
#include <osgText/Text>
#include <vector>
#include <queue>
/**
* Controls - A simple 2D UI toolkit.
*
* Controls are 2D interface components that automatically layout to fit their containers.
* The support layout containers, margins and padding, alignment/justification, and docking.
* Controls are a quick and easy way to add "HUD" components to a scene. Just create a
* ControlSurface and add it to a View's scene. Then create and add Controls to that
* surface.
*/
namespace osgEarthUtil { namespace Controls2
{
using namespace osgEarth;
typedef std::vector< osg::ref_ptr<osg::Drawable> > DrawableList;
typedef std::map< class Control*, osg::Geode* > GeodeTable;
// holds 4-sided gutter dimensions (for margins and padding) .. no-export, header-only.
struct Gutter
{
Gutter()
: _top(0), _right(0), _bottom(0), _left(0) { }
Gutter( float top, float right, float bottom, float left )
: _top(top), _right(right), _bottom(bottom), _left(left) { }
Gutter( float y, float x )
: _top(y), _right(x), _bottom(y), _left(x) { }
Gutter( float all )
: _top(all), _right(all), _bottom(all), _left(all) { }
bool operator !=( const Gutter& rhs ) const {
return top() != rhs.top() || right() != rhs.right() || bottom() != rhs.bottom() || left() != rhs.left(); }
float top() const { return _top; }
float left() const { return _left; }
float right() const { return _right; }
float bottom() const { return _bottom; }
float x() const { return _left + _right; }
float y() const { return _top + _bottom; }
osg::Vec2f offset() const { return osg::Vec2f( _left, _top ); }
private:
float _top, _right, _left, _bottom;
};
// internal state class
struct ControlContext
{
ControlContext() : _viewContextID(~0) { }
osg::ref_ptr<const osg::Viewport> _vp;
unsigned int _viewContextID;
std::queue< osg::ref_ptr<class Control> > _active;
};
// base class for control events
class ControlEventHandler : public osg::Referenced
{
public:
virtual void onClick( class Control* control, int mouseButtonMask ) { }
virtual void onValueChanged( class Control* control, float value ) { }
virtual void onValueChanged( class Control* control, bool value ) { }
};
typedef std::list< osg::ref_ptr<ControlEventHandler> > ControlEventHandlerList;
/**
* Base class for all controls. You can actually use a Control directly and it
* will just render as a rectangle.
*/
class OSGEARTHUTIL_EXPORT Control : public osg::Referenced
{
public:
enum Alignment
{
ALIGN_NONE, ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, ALIGN_TOP, ALIGN_BOTTOM
};
enum Dock
{
DOCK_NONE, DOCK_LEFT, DOCK_RIGHT, DOCK_TOP, DOCK_BOTTOM, DOCK_FILL
};
public:
Control();
void setX( float value );
const osgEarth::optional<float>& x() const { return _x; }
void setY( float value );
const osgEarth::optional<float>& y() const { return _y; }
void setPosition( float x, float y );
void setWidth( float value );
const osgEarth::optional<float>& width() const { return _width; }
void setHeight( float value );
const osgEarth::optional<float>& height() const { return _height; }
void setSize( float w, float h );
void setMargin( const Gutter& value );
const Gutter& margin() const { return _margin; }
// space between container and its content
void setPadding( const Gutter& value );
void setPadding( float globalValue );
const Gutter& padding() const { return _padding; }
void setVertAlign( const Alignment& value );
const optional<Alignment>& vertAlign() const { return _valign; }
void setHorizAlign( const Alignment& value );
const optional<Alignment>& horizAlign() const { return _halign; }
void setVisible( bool value );
const bool visible() const { return _visible; }
void setForeColor( const osg::Vec4f& value );
void setForeColor( float r, float g, float b, float a ) { setForeColor( osg::Vec4f(r,g,b,a) ); }
const osgEarth::optional<osg::Vec4f> foreColor() const { return _foreColor; }
void setBackColor( const osg::Vec4f& value );
void setBackColor( float r, float g, float b, float a ) { setBackColor( osg::Vec4f(r,g,b,a) ); }
const osgEarth::optional<osg::Vec4f>& backColor() const { return _backColor; }
void setActiveColor( const osg::Vec4f& value );
void setActiveColor( float r, float g, float b, float a ) { setActiveColor( osg::Vec4f(r,g,b,a) ); }
const osgEarth::optional<osg::Vec4f>& activeColor() const { return _activeColor; }
bool getParent( osg::ref_ptr<Control>& out ) const;
void setActive( bool value );
bool getActive() const { return _active; }
void setAbsorbEvents( bool value ) { _absorbEvents = value; }
bool getAbsorbEvents() const { return _absorbEvents; }
void addEventHandler( ControlEventHandler* handler );
public:
// mark the control as dirty so that it will regenerate on the next pass.
virtual void dirty();
bool isDirty() const { return _dirty; }
virtual void calcSize( const ControlContext& context, osg::Vec2f& out_size );
virtual void calcPos ( const ControlContext& context, const osg::Vec2f& cursor, const osg::Vec2f& parentSize );
virtual void draw ( const ControlContext& context, DrawableList& out_drawables );
// actual rendering region on the control surface
const osg::Vec2f& renderPos() const { return _renderPos; }
const osg::Vec2f& renderSize() const { return _renderSize; }
// does the control contain the point?
bool intersects( float x, float y ) const;
void setParent( class Control* c ) { _parent = c; }
protected:
bool _dirty;
osg::Vec2f _renderPos; // rendering position (includes padding offset)
osg::Vec2f _renderSize; // rendering size (includes padding)
// adjusts renderpos for alignment.
void align();
// event handler
friend class ControlCanvas;
friend class Container;
virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, ControlContext& cx );
ControlEventHandlerList _eventHandlers;
private:
osgEarth::optional<float> _x, _y, _width, _height;
Gutter _margin;
Gutter _padding;
bool _visible;
optional<Alignment> _valign, _halign;
optional<osg::Vec4f> _backColor, _foreColor, _activeColor;
osg::observer_ptr<Control> _parent;
bool _active;
bool _absorbEvents;
};
/**
* Control that contains a text string, obviously
*/
class OSGEARTHUTIL_EXPORT LabelControl : public Control
{
public:
LabelControl(
const std::string& value ="",
float fontSize =18.0f,
const osg::Vec4f& foreColor =osg::Vec4f(1,1,1,1) );
void setText( const std::string& value );
const std::string& text() const { return _text; }
void setFont( osgText::Font* font );
osgText::Font* font() const { return _font.get(); }
void setFontSize( float value );
float fontSize() const { return _fontSize; }
public: // Control
virtual void calcSize( const ControlContext& context, osg::Vec2f& out_size );
//virtual void calcPos ( const ControlContext& context, const osg::Vec2f& cursor, const osg::Vec2f& parentSize );
virtual void draw ( const ControlContext& context, DrawableList& out_drawables );
private:
std::string _text;
osg::ref_ptr<osgText::Font> _font;
float _fontSize;
osg::ref_ptr<osgText::Text> _drawable;
osg::Vec3 _bmin, _bmax;
};
/**
* Control that contains a raster image
*/
class OSGEARTHUTIL_EXPORT ImageControl : public Control
{
public:
ImageControl( osg::Image* image =0L );
void setImage( osg::Image* image );
osg::Image* getImage() const { return _image.get(); }
public: // Control
virtual void calcSize( const ControlContext& context, osg::Vec2f& out_size );
virtual void draw( const ControlContext& cx, DrawableList& out );
private:
osg::ref_ptr<osg::Image> _image;
};
/**
* A control that provides a horizontal sliding value controller.
*/
class OSGEARTHUTIL_EXPORT HSliderControl : public Control
{
public:
HSliderControl( float min = 0.0f, float max = 100.0f, float value = 50.0f );
void setMin( float min );
float getMin() const { return _min; }
void setMax( float max );
float getMax() const { return _max; }
void setValue( float value );
float getValue() const { return _value; }
public: // Control
//virtual void calcSize( const ControlContext& context, osg::Vec2f& out_size );
virtual void draw( const ControlContext& cx, DrawableList& out );
protected:
virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, ControlContext& cx );
void fireValueChanged();
private:
float _min, _max, _value;
};
/**
* A check box toggle.
*/
class OSGEARTHUTIL_EXPORT CheckBoxControl : public Control
{
public:
CheckBoxControl( bool checked =false );
void setValue( bool value );
bool getValue() const { return _value; }
public:
virtual void draw( const ControlContext& cx, DrawableList& out );
protected:
virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, ControlContext& cx );
void fireValueChanged();
private:
bool _value;
};
typedef std::vector< osg::ref_ptr<Control> > ControlList;
/**
* A control that renders a simple rectangular border for a container.
* This is also the base class for all Frame objects.
*/
class OSGEARTHUTIL_EXPORT Frame : public ImageControl
{
public:
Frame();
public: // Control
virtual void calcPos ( const ControlContext& context, const osg::Vec2f& cursor, const osg::Vec2f& parentSize );
virtual void draw( const ControlContext& context, DrawableList& drawables );
};
/**
* A Frame with nice rounded corners.
*/
class OSGEARTHUTIL_EXPORT RoundedFrame : public Frame
{
public:
RoundedFrame();
public:
virtual void draw( const ControlContext& cx, DrawableList& drawables );
};
/**
* Container is a control that houses child controls. This is the base class for
* all containers. (It is abstract so cannot be used directly)
* Containers are control, so you can nest them in other containers.
*/
class OSGEARTHUTIL_EXPORT Container : public Control
{
public:
Container();
// the Frame connected to this container. can be NULL for no frame.
void setFrame( Frame* frame );
Frame* getFrame() const { return _frame.get(); }
// space between children
void setSpacing( float value );
float spacing() const { return _spacing; }
// horiz alignment to set on children (that do not already have alignment explicity set)
void setChildHorizAlign( Alignment align );
const optional<Alignment>& childHorizAlign() const { return _childhalign; }
// vert alignment to set on children (that do not already have alignment explicity set)
void setChildVertAlign( Alignment align );
const optional<Alignment>& childVertAlign() const { return _childvalign; }
// default add function.
virtual void addControl( Control* control, int index =-1 ) =0;
// access to the child list.
virtual const ControlList& children() const =0;
// clear the controls list.
virtual void clearControls() =0;
public:
virtual void calcSize( const ControlContext& context, osg::Vec2f& out_size );
virtual void calcPos ( const ControlContext& context, const osg::Vec2f& cursor, const osg::Vec2f& parentSize );
virtual void draw( const ControlContext& context, DrawableList& drawables );
protected:
virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, ControlContext& cx );
private:
osg::ref_ptr<Frame> _frame;
float _spacing;
optional<Alignment> _childhalign;
optional<Alignment> _childvalign;
};
/**
* Container that stacks controls vertically.
*/
class OSGEARTHUTIL_EXPORT VBox : public Container
{
public:
VBox();
public: // Container
virtual void addControl( Control* control, int index =-1 );
virtual const ControlList& children() const { return _controls; }
virtual void clearControls();
public: // Control
virtual void calcSize( const ControlContext& context, osg::Vec2f& out_size );
virtual void calcPos ( const ControlContext& context, const osg::Vec2f& cursor, const osg::Vec2f& parentSize );
virtual void draw( const ControlContext& context, DrawableList& drawables );
private:
ControlList _controls;
};
/**
* Container that stacks controls horizontally.
*/
class OSGEARTHUTIL_EXPORT HBox : public Container
{
public:
HBox();
public: // Container
virtual void addControl( Control* control, int index =-1 );
virtual const ControlList& children() const { return _controls; }
virtual void clearControls();
public: // Control
virtual void calcSize( const ControlContext& context, osg::Vec2f& out_size );
virtual void calcPos ( const ControlContext& context, const osg::Vec2f& cursor, const osg::Vec2f& parentSize );
virtual void draw( const ControlContext& context, DrawableList& drawables );
private:
ControlList _controls;
};
/**
* Container that organizes its children in a grid.
*/
class OSGEARTHUTIL_EXPORT Grid : public Container
{
public:
Grid();
void setControl( int col, int row, Control* control );
public: // Container
virtual void addControl( Control* control, int index =-1 );
virtual const ControlList& children() const { return _children; }
virtual void clearControls();
public: // Control
virtual void calcSize( const ControlContext& context, osg::Vec2f& out_size );
virtual void calcPos ( const ControlContext& context, const osg::Vec2f& cursor, const osg::Vec2f& parentSize );
virtual void draw( const ControlContext& context, DrawableList& drawables );
private:
typedef std::vector< osg::ref_ptr<Control> > Row;
typedef std::vector< Row > RowVector;
RowVector _rows;
ControlList _children;
osg::ref_ptr<Control>& cell(int col, int row);
void expandToInclude(int cols, int rows);
std::vector<float> _rowHeights, _colWidths;
};
/**
* Associates controls with an OSG View.
*/
class OSGEARTHUTIL_EXPORT ControlCanvas : public osg::Camera
{
public:
ControlCanvas( osgViewer::View* view );
// adds a top-level control to this surface.
void addControl( Control* control );
// removes a top-level control.
void removeControl( Control* control );
// gets the top-most control that intersects the specified position.
Control* getControlAtMouse( float x, float y ) const;
public:
// internal- no need to call directly
void update();
// internal - no need to call directly
void setControlContext( const ControlContext& );
protected:
ControlList _controls;
GeodeTable _geodeTable;
ControlContext _context;
bool _contextDirty;
private:
friend struct ControlCanvasEventHandler;
bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa );
};
} } // namespace osgEarthUtil::Controls
#endif // OSGEARTHUTIL_CONTROLS

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,90 @@
/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2008-2010 Pelican Mapping
* http://osgearth.org
*
* osgEarth is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef OSGEARTH_DRIVER_WORLDWIND_DRIVEROPTIONS
#define OSGEARTH_DRIVER_WORLDWIND_DRIVEROPTIONS 1
#include <osgEarth/Common>
#include <osgEarth/TileSource>
namespace osgEarth { namespace Drivers
{
using namespace osgEarth;
class WorldWindOptions : public TileSourceOptions // NO EXPORT; header only
{
public:
optional<int>& maxLOD() { return _maxLOD; }
const optional<int>& maxLOD() const { return _maxLOD; }
optional<std::string>& elevationCachePath() { return _elevationCachePath; }
const optional<std::string>& elevationCachePath() const { return _elevationCachePath; }
optional<std::string>& elevationURL() { return _elevationURL; }
const optional<std::string>& elevationURL() const { return _elevationURL; }
// image support NYI ... use the "tileservice" plugin instead
//optional<std::string>& imageURL() { return _imageURL; }
//const optional<std::string>& imageURL() const { return _imageURL; }
public:
WorldWindOptions( const TileSourceOptions& opt =TileSourceOptions() ) : TileSourceOptions( opt ),
_maxLOD( 11 ),
_elevationURL( "http://worldwind25.arc.nasa.gov/wwelevation/wwelevation.aspx?T=srtm30pluszip" ),
_imageURL( "http://s0.tileservice.worldwindcentral.com/getTile?" )
{
setDriver( "worldwind" );
fromConfig( _conf );
}
public:
Config getConfig() const {
Config conf = TileSourceOptions::getConfig();
conf.updateIfSet("image_url", _imageURL);
conf.updateIfSet("elevation_url", _elevationURL);
conf.updateIfSet("max_lod", _maxLOD);
conf.updateIfSet("elevation_cache", _elevationCachePath);
return conf;
}
protected:
void mergeConfig( const Config& conf ) {
TileSourceOptions::mergeConfig( conf );
fromConfig( conf );
}
private:
void fromConfig( const Config& conf ) {
conf.getIfSet("image_url", _imageURL);
conf.getIfSet("elevation_url", _elevationURL);
conf.getIfSet("max_lod", _maxLOD);
conf.getIfSet("elevation_cache", _elevationCachePath);
conf.getIfSet("worldwind_cache", _elevationCachePath); // back compat
}
optional<std::string> _imageURL;
optional<std::string> _elevationURL;
optional<std::string> _elevationCachePath;
optional<int> _maxLOD;
};
} } // namespace osgEarth::Drivers
#endif // OSGEARTH_DRIVER_WMS_DRIVEROPTIONS

View File

@ -51,10 +51,11 @@
#include <osgEarth/MapNode>
#include <osgEarth/TileSource>
#include <osgEarthDrivers/gdal/GDALOptions>
#include "WorldWindOptions"
#include <osgEarthDrivers/tms/TMSOptions>
using namespace osgEarth::Drivers;
using namespace osgEarthUtil::Controls2;
using namespace osgEarth::Util::Controls;
#define MOVE_OFFSET 0.05
@ -94,20 +95,20 @@ GlobePlugin::~GlobePlugin()
struct PanControlHandler : public NavigationControlHandler
{
PanControlHandler( osgEarthUtil::EarthManipulator* manip, double dx, double dy ) : _manip( manip ), _dx( dx ), _dy( dy ) { }
PanControlHandler( osgEarth::Util::EarthManipulator* manip, double dx, double dy ) : _manip( manip ), _dx( dx ), _dy( dy ) { }
virtual void onMouseDown( Control* control, int mouseButtonMask )
{
_manip->pan( _dx, _dy );
}
private:
osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
osg::observer_ptr<osgEarth::Util::EarthManipulator> _manip;
double _dx;
double _dy;
};
struct RotateControlHandler : public NavigationControlHandler
{
RotateControlHandler( osgEarthUtil::EarthManipulator* manip, double dx, double dy ) : _manip( manip ), _dx( dx ), _dy( dy ) { }
RotateControlHandler( osgEarth::Util::EarthManipulator* manip, double dx, double dy ) : _manip( manip ), _dx( dx ), _dy( dy ) { }
virtual void onMouseDown( Control* control, int mouseButtonMask )
{
if( 0 == _dx && 0 == _dy )
@ -120,33 +121,33 @@ struct RotateControlHandler : public NavigationControlHandler
}
}
private:
osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
osg::observer_ptr<osgEarth::Util::EarthManipulator> _manip;
double _dx;
double _dy;
};
struct ZoomControlHandler : public NavigationControlHandler
{
ZoomControlHandler( osgEarthUtil::EarthManipulator* manip, double dx, double dy ) : _manip( manip ), _dx( dx ), _dy( dy ) { }
ZoomControlHandler( osgEarth::Util::EarthManipulator* manip, double dx, double dy ) : _manip( manip ), _dx( dx ), _dy( dy ) { }
virtual void onMouseDown( Control* control, int mouseButtonMask )
{
_manip->zoom( _dx, _dy );
}
private:
osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
osg::observer_ptr<osgEarth::Util::EarthManipulator> _manip;
double _dx;
double _dy;
};
struct HomeControlHandler : public NavigationControlHandler
{
HomeControlHandler( osgEarthUtil::EarthManipulator* manip ) : _manip( manip ) { }
HomeControlHandler( osgEarth::Util::EarthManipulator* manip ) : _manip( manip ) { }
virtual void onClick( Control* control, int mouseButtonMask, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
_manip->home( ea, aa );
}
private:
osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
osg::observer_ptr<osgEarth::Util::EarthManipulator> _manip;
};
struct RefreshControlHandler : public ControlEventHandler
@ -224,7 +225,7 @@ void GlobePlugin::run()
setupProxy();
// install the programmable manipulator.
osgEarthUtil::EarthManipulator* manip = new osgEarthUtil::EarthManipulator();
osgEarth::Util::EarthManipulator* manip = new osgEarth::Util::EarthManipulator();
viewer.setCameraManipulator( manip );
setupMap();
@ -233,7 +234,7 @@ void GlobePlugin::run()
// Set a home viewpoint
manip->setHomeViewpoint(
osgEarthUtil::Viewpoint( osg::Vec3d( -90, 0, 0 ), 0.0, -90.0, 4e7 ),
osgEarth::Util::Viewpoint( osg::Vec3d( -90, 0, 0 ), 0.0, -90.0, 4e7 ),
1.0 );
// create a surface to house the controls
@ -273,7 +274,6 @@ void GlobePlugin::setupMap()
{
// read base layers from earth file
QString earthFileName = QDir::cleanPath( QgsApplication::pkgDataPath() + "/globe/globe.earth" );
EarthFile earthFile;
QFile earthFileTemplate( earthFileName );
if( !earthFileTemplate.open( QIODevice::ReadOnly | QIODevice::Text ) )
{
@ -294,7 +294,8 @@ void GlobePlugin::setupMap()
}
std::istringstream istream( earthxml.toStdString() );
if( !earthFile.readXML( istream, earthFileName.toStdString() ) )
osg::Node* node = osgDB::readNodeFile( earthFileName.toStdString() ); //TODO: from istream earthFile.readXML( istream, earthFileName.toStdString() )
if( !node )
{
return;
}
@ -302,18 +303,18 @@ void GlobePlugin::setupMap()
mRootNode = new osg::Group();
// The MapNode will render the Map object in the scene graph.
mMapNode = new osgEarth::MapNode( earthFile.getMap() );
mMapNode = MapNode::findMapNode( node );
mRootNode->addChild( mMapNode );
// Add layers to the map
layersChanged();
// model placement utils
mElevationManager = new osgEarthUtil::ElevationManager( mMapNode->getMap() );
mElevationManager->setTechnique( osgEarthUtil::ElevationManager::TECHNIQUE_GEOMETRIC );
mElevationManager = new osgEarth::Util::ElevationManager( mMapNode->getMap() );
mElevationManager->setTechnique( osgEarth::Util::ElevationManager::TECHNIQUE_GEOMETRIC );
mElevationManager->setMaxTilesToCache( 50 );
mObjectPlacer = new osgEarthUtil::ObjectPlacer( mMapNode );
mObjectPlacer = new osgEarth::Util::ObjectPlacer( mMapNode );
// place 3D model on point layer
if ( mSettingsDialog.modelLayer() && !mSettingsDialog.modelPath().isEmpty() )
@ -398,7 +399,7 @@ double GlobePlugin::getSelectedElevation()
void GlobePlugin::syncExtent()
{
osgEarthUtil::EarthManipulator* manip = dynamic_cast<osgEarthUtil::EarthManipulator*>( viewer.getCameraManipulator() );
osgEarth::Util::EarthManipulator* manip = dynamic_cast<osgEarth::Util::EarthManipulator*>( viewer.getCameraManipulator() );
//rotate earth to north and perpendicular to camera
manip->setRotation( osg::Quat() );
@ -417,7 +418,7 @@ void GlobePlugin::syncExtent()
OE_NOTICE << "map extent: " << height << " camera distance: " << distance << std::endl;
osgEarthUtil::Viewpoint viewpoint( osg::Vec3d( extent.center().x(), extent.center().y(), 0.0 ), 0.0, -90.0, distance );
osgEarth::Util::Viewpoint viewpoint( osg::Vec3d( extent.center().x(), extent.center().y(), 0.0 ), 0.0, -90.0, distance );
manip->setViewpoint( viewpoint, 4.0 );
}
@ -438,7 +439,7 @@ void GlobePlugin::setupControls()
moveHControls->setPosition( 5, 30 );
moveHControls->setPadding( 6 );
osgEarthUtil::EarthManipulator* manip = dynamic_cast<osgEarthUtil::EarthManipulator*>( viewer.getCameraManipulator() );
osgEarth::Util::EarthManipulator* manip = dynamic_cast<osgEarth::Util::EarthManipulator*>( viewer.getCameraManipulator() );
//Move Left
osg::Image* moveLeftImg = osgDB::readImageFile( imgDir + "/move-left.png" );
ImageControl* moveLeft = new NavigationControl( moveLeftImg );
@ -637,24 +638,23 @@ void GlobePlugin::extentsChanged()
QgsDebugMsg( "extentsChanged: " + mQGisIface->mapCanvas()->extent().toString() );
}
typedef std::list< osg::ref_ptr<VersionedTile> > TileList;
void GlobePlugin::layersChanged()
{
if ( mIsGlobeRunning ){
QgsDebugMsg( "layersChanged: Globe Running, executing" );
osg::ref_ptr<Map> map = mMapNode->getMap();
if( map->getImageMapLayers().size() > 1 || map->getHeightFieldMapLayers().size() > 1)
if( map->getNumImageLayers() > 1 || map->getNumElevationLayers() > 1)
{
viewer.getDatabasePager()->clear();
}
// Remove elevation layers
MapLayerList list = map->getHeightFieldMapLayers();
for( MapLayerList::iterator i = list.begin(); i != list.end(); i++ )
ElevationLayerVector list;
map->getElevationLayers( list );
for( ElevationLayerVector::iterator i = list.begin(); i != list.end(); i++ )
{
map->removeMapLayer( *i );
map->removeElevationLayer( *i );
}
// Add elevation layers
@ -666,32 +666,27 @@ void GlobePlugin::layersChanged()
QString type = table->item(i, 0)->text();
bool cache = table->item(i, 1)->checkState();
QString uri = table->item(i, 2)->text();
MapLayer* layer = 0;
ElevationLayer* layer = 0;
if( "Raster" == type)
{
GDALOptions* options = new GDALOptions();
options->url() = uri.toStdString();
layer = new osgEarth::HeightFieldMapLayer( uri.toStdString(), options );
GDALOptions options;
options.url() = uri.toStdString();
layer = new osgEarth::ElevationLayer( uri.toStdString(), options );
}
else if ( "Worldwind" == type )
{
EarthFile* tmpEarth = new EarthFile(); //Hack for programatic WorldWind layer generation
std::string xml = "<map name=\"Dummy\" type=\"geocentric\"><heightfield name=\"WorldWind bil\" driver=\"worldwind\"><worldwind_cache>" + cacheDirectory.toStdString() + "/globe/worldwind_srtm</worldwind_cache></heightfield></map>";
std::stringstream strstr(xml);
tmpEarth->readXML( strstr, "" );
layer = tmpEarth->getMap()->getHeightFieldMapLayers().front();
WorldWindOptions options;
//TODO: <heightfield name=\"WorldWind bil\" driver=\"worldwind\"><worldwind_cache>" + cacheDirectory.toStdString() + "/globe/worldwind_srtm";
layer = new osgEarth::ElevationLayer( "WorldWind bil", options );
}
else if ( "TMS" == type )
{
TMSOptions* options = new TMSOptions();
options->url() = uri.toStdString();
layer = new osgEarth::HeightFieldMapLayer( uri.toStdString(), options );
//osgEarth 2.0 API:
//TMSOptions tms( "http://demo.pelicanmapping.com/rmweb/data/srtm30_plus_tms/tms.xml" );
//map->addElevationLayer( new osgEarth::ElevationLayer( "SRTM", tms ) );
TMSOptions options;
options.url() = uri.toStdString();
layer = new osgEarth::ElevationLayer( uri.toStdString(), options );
}
map->addMapLayer( layer );
map->addElevationLayer( layer );
if ( !cache || type == "Worldwind" ) layer->setCache( 0 ); //no tms cache for worldwind (use worldwind_cache)
}
@ -700,15 +695,16 @@ void GlobePlugin::layersChanged()
if( mQgisMapLayer )
{
QgsDebugMsg( "removeMapLayer" );
map->removeMapLayer( mQgisMapLayer );
map->removeImageLayer( mQgisMapLayer );
}
//add QGIS layer
QgsDebugMsg( "addMapLayer" );
mTileSource = new QgsOsgEarthTileSource( mQGisIface );
mTileSource->initialize( "", 0 );
mQgisMapLayer = new ImageMapLayer( "QGIS", mTileSource );
map->addMapLayer( mQgisMapLayer );
ImageLayerOptions options( "QGIS" );
mQgisMapLayer = new ImageLayer( options, mTileSource );
map->addImageLayer( mQgisMapLayer );
mQgisMapLayer->setCache( 0 ); //disable caching
}
else
@ -822,40 +818,40 @@ bool NavigationControl::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActi
bool KeyboardControlHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
/*
osgEarthUtil::EarthManipulator::Settings* _manipSettings = _manip->getSettings();
_manip->getSettings()->bindKey(osgEarthUtil::EarthManipulator::ACTION_ZOOM_IN, osgGA::GUIEventAdapter::KEY_Space);
osgEarth::Util::EarthManipulator::Settings* _manipSettings = _manip->getSettings();
_manip->getSettings()->bindKey(osgEarth::Util::EarthManipulator::ACTION_ZOOM_IN, osgGA::GUIEventAdapter::KEY_Space);
//install default action bindings:
osgEarthUtil::EarthManipulator::ActionOptions options;
osgEarth::Util::EarthManipulator::ActionOptions options;
_manipSettings->bindKey( osgEarthUtil::EarthManipulator::ACTION_HOME, osgGA::GUIEventAdapter::KEY_Space );
_manipSettings->bindKey( osgEarth::Util::EarthManipulator::ACTION_HOME, osgGA::GUIEventAdapter::KEY_Space );
_manipSettings->bindMouse( osgEarthUtil::EarthManipulator::ACTION_PAN, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON );
_manipSettings->bindMouse( osgEarth::Util::EarthManipulator::ACTION_PAN, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON );
// zoom as you hold the right button:
options.clear();
options.add( osgEarthUtil::EarthManipulator::OPTION_CONTINUOUS, true );
_manipSettings->bindMouse( osgEarthUtil::EarthManipulator::ACTION_ROTATE, osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON, 0L, options );
options.add( osgEarth::Util::EarthManipulator::OPTION_CONTINUOUS, true );
_manipSettings->bindMouse( osgEarth::Util::EarthManipulator::ACTION_ROTATE, osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON, 0L, options );
// zoom with the scroll wheel:
_manipSettings->bindScroll( osgEarthUtil::EarthManipulator::ACTION_ZOOM_IN, osgGA::GUIEventAdapter::SCROLL_DOWN );
_manipSettings->bindScroll( osgEarthUtil::EarthManipulator::ACTION_ZOOM_OUT, osgGA::GUIEventAdapter::SCROLL_UP );
_manipSettings->bindScroll( osgEarth::Util::EarthManipulator::ACTION_ZOOM_IN, osgGA::GUIEventAdapter::SCROLL_DOWN );
_manipSettings->bindScroll( osgEarth::Util::EarthManipulator::ACTION_ZOOM_OUT, osgGA::GUIEventAdapter::SCROLL_UP );
// pan around with arrow keys:
_manipSettings->bindKey( osgEarthUtil::EarthManipulator::ACTION_PAN_LEFT, osgGA::GUIEventAdapter::KEY_Left );
_manipSettings->bindKey( osgEarthUtil::EarthManipulator::ACTION_PAN_RIGHT, osgGA::GUIEventAdapter::KEY_Right );
_manipSettings->bindKey( osgEarthUtil::EarthManipulator::ACTION_PAN_UP, osgGA::GUIEventAdapter::KEY_Up );
_manipSettings->bindKey( osgEarthUtil::EarthManipulator::ACTION_PAN_DOWN, osgGA::GUIEventAdapter::KEY_Down );
_manipSettings->bindKey( osgEarth::Util::EarthManipulator::ACTION_PAN_LEFT, osgGA::GUIEventAdapter::KEY_Left );
_manipSettings->bindKey( osgEarth::Util::EarthManipulator::ACTION_PAN_RIGHT, osgGA::GUIEventAdapter::KEY_Right );
_manipSettings->bindKey( osgEarth::Util::EarthManipulator::ACTION_PAN_UP, osgGA::GUIEventAdapter::KEY_Up );
_manipSettings->bindKey( osgEarth::Util::EarthManipulator::ACTION_PAN_DOWN, osgGA::GUIEventAdapter::KEY_Down );
// double click the left button to zoom in on a point:
options.clear();
options.add( osgEarthUtil::EarthManipulator::OPTION_GOTO_RANGE_FACTOR, 0.4 );
_manipSettings->bindMouseDoubleClick( osgEarthUtil::EarthManipulator::ACTION_GOTO, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON, 0L, options );
options.add( osgEarth::Util::EarthManipulator::OPTION_GOTO_RANGE_FACTOR, 0.4 );
_manipSettings->bindMouseDoubleClick( osgEarth::Util::EarthManipulator::ACTION_GOTO, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON, 0L, options );
// double click the right button(or CTRL-left button) to zoom out to a point
options.clear();
options.add( osgEarthUtil::EarthManipulator::OPTION_GOTO_RANGE_FACTOR, 2.5 );
_manipSettings->bindMouseDoubleClick( osgEarthUtil::EarthManipulator::ACTION_GOTO, osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON, 0L, options );
_manipSettings->bindMouseDoubleClick( osgEarthUtil::EarthManipulator::ACTION_GOTO, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON, osgGA::GUIEventAdapter::MODKEY_CTRL, options );
options.add( osgEarth::Util::EarthManipulator::OPTION_GOTO_RANGE_FACTOR, 2.5 );
_manipSettings->bindMouseDoubleClick( osgEarth::Util::EarthManipulator::ACTION_GOTO, osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON, 0L, options );
_manipSettings->bindMouseDoubleClick( osgEarth::Util::EarthManipulator::ACTION_GOTO, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON, osgGA::GUIEventAdapter::MODKEY_CTRL, options );
_manipSettings->setThrowingEnabled( false );
_manipSettings->setLockAzimuthWhilePanning( true );

View File

@ -23,11 +23,11 @@
#include "qgsosgviewer.h"
#include "qgsosgearthtilesource.h"
#include "globe_plugin_dialog.h"
#include "Controls"
#include <QObject>
#include <osgEarth/MapNode>
#include <osgEarth/MapLayer>
#include <osgEarth/ImageLayer>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarthUtil/Controls>
#include <osgEarthUtil/ElevationManager>
#include <osgEarthUtil/ObjectPlacer>
@ -122,15 +122,15 @@ class GlobePlugin : public QObject, public QgisPlugin
//! Map node
osgEarth::MapNode* mMapNode;
//! QGIS maplayer
osgEarth::MapLayer* mQgisMapLayer;
osgEarth::ImageLayer* mQgisMapLayer;
//! Tile source
osgEarth::Drivers::QgsOsgEarthTileSource* mTileSource;
//! Control Canvas
osgEarthUtil::Controls2::ControlCanvas* mControlCanvas;
osgEarth::Util::Controls::ControlCanvas* mControlCanvas;
//! Elevation manager
osgEarthUtil::ElevationManager* mElevationManager;
osgEarth::Util::ElevationManager* mElevationManager;
//! Object placer
osgEarthUtil::ObjectPlacer* mObjectPlacer;
osgEarth::Util::ObjectPlacer* mObjectPlacer;
//! tracks if the globe is open
bool mIsGlobeRunning;
//! coordinates of the right-clicked point on the globe
@ -158,7 +158,7 @@ class FlyToExtentHandler : public osgGA::GUIEventHandler
class QueryCoordinatesHandler : public osgGA::GUIEventHandler
{
public:
QueryCoordinatesHandler( GlobePlugin* globe, osgEarthUtil::ElevationManager* elevMan,
QueryCoordinatesHandler( GlobePlugin* globe, osgEarth::Util::ElevationManager* elevMan,
const osgEarth::SpatialReference* mapSRS )
: mGlobe ( globe ), _elevMan(elevMan), _mapSRS( mapSRS ), _mouseDown( false ) { }
@ -169,7 +169,7 @@ public:
private:
GlobePlugin* mGlobe;
osg::ref_ptr<const SpatialReference> _mapSRS;
osg::ref_ptr<osgEarthUtil::ElevationManager> _elevMan;
osg::ref_ptr<osgEarth::Util::ElevationManager> _elevMan;
bool _mouseDown;
};
@ -177,40 +177,41 @@ private:
class KeyboardControlHandler : public osgGA::GUIEventHandler
{
public:
KeyboardControlHandler( osgEarthUtil::EarthManipulator* manip, QgisInterface *qGisIface ) : _manip(manip), mQGisIface(qGisIface) { }
KeyboardControlHandler( osgEarth::Util::EarthManipulator* manip, QgisInterface *qGisIface ) : _manip(manip), mQGisIface(qGisIface) { }
bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa );
private:
osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
osg::observer_ptr<osgEarth::Util::EarthManipulator> _manip;
//! Pointer to the QGIS interface object
QgisInterface *mQGisIface;
};
namespace osgEarthUtil
namespace osgEarth { namespace Util
{
namespace Controls2
namespace Controls
{
class NavigationControlHandler : public ControlEventHandler
{
public:
virtual void onMouseDown( class Control* control, int mouseButtonMask ) { }
virtual void onClick( class Control* control, int mouseButtonMask, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ) { }
};
};
class NavigationControl : public ImageControl
{
public:
class NavigationControl : public ImageControl
{
public:
NavigationControl( osg::Image* image = 0L ) : ImageControl( image ), _mouse_down_event( NULL ) {}
protected:
protected:
virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, ControlContext& cx );
private:
osg::ref_ptr<const osgGA::GUIEventAdapter> _mouse_down_event;
};
}
}
} }
#endif // QGS_GLOBE_PLUGIN_H

View File

@ -30,7 +30,7 @@ using namespace osgEarth;
using namespace osgEarth::Drivers;
QgsOsgEarthTileSource::QgsOsgEarthTileSource( QgisInterface* theQgisInterface, const PluginOptions* options ) : TileSource(options), mQGisIface(theQgisInterface), mCoordTranform(0)
QgsOsgEarthTileSource::QgsOsgEarthTileSource( QgisInterface* theQgisInterface, const TileSourceOptions& options ) : TileSource(options), mQGisIface(theQgisInterface), mCoordTranform(0)
{
}
@ -58,15 +58,14 @@ void QgsOsgEarthTileSource::initialize( const std::string& referenceURI, const P
mMapRenderer->setLabelingEngine( new QgsPalLabeling() );
}
osg::Image* QgsOsgEarthTileSource::createImage( const TileKey* key,
ProgressCallback* progress )
osg::Image* QgsOsgEarthTileSource::createImage( const TileKey& key, ProgressCallback* progress )
{
osg::ref_ptr<osg::Image> image;
if (intersects(key))
if (intersects(&key))
{
//Get the extents of the tile
double xmin, ymin, xmax, ymax;
key->getGeoExtent().getBounds(xmin, ymin, xmax, ymax);
key.getExtent().getBounds(xmin, ymin, xmax, ymax);
int tileSize = getPixelsPerTile();
int target_width = tileSize;
@ -162,7 +161,7 @@ bool QgsOsgEarthTileSource::intersects(const TileKey* key)
{
//Get the native extents of the tile
double xmin, ymin, xmax, ymax;
key->getGeoExtent().getBounds(xmin, ymin, xmax, ymax);
key->getExtent().getBounds(xmin, ymin, xmax, ymax);
QgsRectangle extent = mQGisIface->mapCanvas()->fullExtent();
if (mCoordTranform) extent = mCoordTranform->transformBoundingBox(extent);
return ! ( xmin >= extent.xMaximum() || xmax <= extent.xMinimum() || ymin >= extent.yMaximum() || ymax <= extent.yMinimum() );

View File

@ -17,12 +17,11 @@ namespace osgEarth { namespace Drivers
class QgsOsgEarthTileSource : public TileSource
{
public:
QgsOsgEarthTileSource( QgisInterface* theQgisInterface, const PluginOptions* options = NULL );
QgsOsgEarthTileSource( QgisInterface* theQgisInterface, const TileSourceOptions& options =TileSourceOptions() );
void initialize( const std::string& referenceURI, const Profile* overrideProfile = NULL );
osg::Image* createImage( const TileKey* key,
ProgressCallback* progress );
osg::Image* createImage( const TileKey& key, ProgressCallback* progress );
osg::HeightField* createHeightField( const TileKey* key,
ProgressCallback* progress)