From ff28e631a82cc769424a65b8ee4a2690586466e3 Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Sun, 4 Mar 2018 15:00:11 +0100 Subject: [PATCH] LP-566 upgrade to osgEarth 2.9 fixes a compilation error related to elevation query older versions of osgEarth are still supported note that osgEarth is currently broken on windows probably due to Qt upgrade more fixes are on their way... --- .../osgQtQuick/OSGGeoTransformNode.cpp | 46 +++++++++---------- .../ga/OSGGeoTransformManipulator.cpp | 24 ++++------ .../gcs/src/libs/osgearth/utils/utility.cpp | 31 +++++++++---- ground/gcs/src/libs/osgearth/utils/utility.h | 3 +- 4 files changed, 54 insertions(+), 50 deletions(-) diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.cpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.cpp index 2575fdfe3..092f5199d 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.cpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.cpp @@ -117,32 +117,30 @@ public: } else { qWarning() << "OSGGeoTransformNode::updatePosition - scene node is not valid"; } - - // TODO factorize this logic to utility (same logic is found elsewhere) - osgEarth::GeoPoint geoPoint; if (mapNode) { - geoPoint = osgQtQuick::toGeoPoint(mapNode->getTerrain()->getSRS(), position); - } else { - qWarning() << "OSGGeoTransformNode::onChildNodeChanged - no map node"; - geoPoint = osgQtQuick::toGeoPoint(position); + osgEarth::GeoPoint geoPoint = createGeoPoint(position, mapNode); + if (clampToTerrain) { + // get "size" of model + // TODO this should be done once only... + #if 0 + osg::ComputeBoundsVisitor cbv; + transform->accept(cbv); + const osg::BoundingBox & bbox = cbv.getBoundingBox(); + offset = bbox.radius(); + #else + const osg::BoundingSphere & boundingSphere = transform->getBound(); + offset = boundingSphere.radius(); + #endif + // clamp model to terrain if needed + intoTerrain = clampGeoPoint(geoPoint, offset, mapNode); + if (intoTerrain) { + qDebug() << "OSGGeoTransformNode::updateNode - into terrain" << offset; + } + } else if (clampToTerrain) { + qWarning() << "OSGGeoTransformNode::onChildNodeChanged - cannot clamp without map node"; + } + transform->setPosition(geoPoint); } - if (clampToTerrain && mapNode) { - // get "size" of model - // TODO this should be done once only... - osg::ComputeBoundsVisitor cbv; - transform->accept(cbv); - const osg::BoundingBox & bbox = cbv.getBoundingBox(); - offset = bbox.radius(); - - // qDebug() << "OSGGeoTransformNode::updateNode - offset" << offset; - - // clamp model to terrain if needed - intoTerrain = clampGeoPoint(geoPoint, offset, mapNode); - } else if (clampToTerrain) { - qWarning() << "OSGGeoTransformNode::onChildNodeChanged - cannot clamp without map node"; - } - - transform->setPosition(geoPoint); } private slots: diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/ga/OSGGeoTransformManipulator.cpp b/ground/gcs/src/libs/osgearth/osgQtQuick/ga/OSGGeoTransformManipulator.cpp index 338754e82..380a16e48 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/ga/OSGGeoTransformManipulator.cpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/ga/OSGGeoTransformManipulator.cpp @@ -155,27 +155,21 @@ public: if (sceneNode && sceneNode->node()) { mapNode = osgEarth::MapNode::findMapNode(sceneNode->node()); - if (!mapNode) { - qWarning() << "OSGGeoTransformManipulator::updatePosition - manipulator node does not contain a map node"; - } } else { qWarning() << "OSGGeoTransformManipulator::updatePosition - scene node is null"; } - - osgEarth::GeoPoint geoPoint; if (mapNode) { - geoPoint = osgQtQuick::toGeoPoint(mapNode->getTerrain()->getSRS(), position); + osgEarth::GeoPoint geoPoint = osgQtQuick::createGeoPoint(position, mapNode); + if (clampToTerrain) { + // clamp model to terrain if needed + intoTerrain = osgQtQuick::clampGeoPoint(geoPoint, 0, mapNode); + } else if (clampToTerrain) { + qWarning() << "OSGGeoTransformManipulator::updatePosition - cannot clamp without map node"; + } + geoPoint.createLocalToWorld(cameraPosition); } else { - geoPoint = osgQtQuick::toGeoPoint(position); + qWarning() << "OSGGeoTransformManipulator::updatePosition - scene node does not contain a map node"; } - if (clampToTerrain && mapNode) { - // clamp model to terrain if needed - intoTerrain = osgQtQuick::clampGeoPoint(geoPoint, 0, mapNode); - } else if (clampToTerrain) { - qWarning() << "OSGGeoTransformManipulator::updatePosition - cannot clamp without map node"; - } - - geoPoint.createLocalToWorld(cameraPosition); } void updateAttitude() diff --git a/ground/gcs/src/libs/osgearth/utils/utility.cpp b/ground/gcs/src/libs/osgearth/utils/utility.cpp index 82981be2d..66f860420 100644 --- a/ground/gcs/src/libs/osgearth/utils/utility.cpp +++ b/ground/gcs/src/libs/osgearth/utils/utility.cpp @@ -69,9 +69,11 @@ #include "osgQtQuick/ga/OSGEarthManipulator.hpp" #include "osgQtQuick/ga/OSGGeoTransformManipulator.hpp" +#include #include #include #include +#include #include #endif // USE_OSGEARTH @@ -454,18 +456,20 @@ QString getUsageString(osgViewer::CompositeViewer *viewer) } #ifdef USE_OSGEARTH -osgEarth::GeoPoint toGeoPoint(const osgEarth::SpatialReference *srs, const QVector3D &position) +osgEarth::GeoPoint createGeoPoint(const QVector3D &position, osgEarth::MapNode *mapNode) { + const osgEarth::SpatialReference *srs = NULL; + + if (mapNode) { + srs = mapNode->getTerrain()->getSRS(); + } else { + qWarning() << "Utility::createGeoPoint - null map node"; + srs = osgEarth::SpatialReference::get("wgs84"); + } osgEarth::GeoPoint geoPoint(srs, position.x(), position.y(), position.z(), osgEarth::ALTMODE_ABSOLUTE); - return geoPoint; } -osgEarth::GeoPoint toGeoPoint(const QVector3D &position) -{ - return toGeoPoint(osgEarth::SpatialReference::get("wgs84"), position); -} - bool clampGeoPoint(osgEarth::GeoPoint &geoPoint, float offset, osgEarth::MapNode *mapNode) { if (!mapNode) { @@ -477,9 +481,18 @@ bool clampGeoPoint(osgEarth::GeoPoint &geoPoint, float offset, osgEarth::MapNode osgEarth::ElevationQuery eq(mapNode->getMap()); // qDebug() << "Utility::clampGeoPoint - SRS :" << QString::fromStdString(mapNode->getMap()->getSRS()->getName()); - bool clamped = false; double elevation; - if (eq.getElevation(geoPoint, elevation, 0.0)) { + bool gotElevation; +#if OSGEARTH_VERSION_LESS_THAN(2, 9, 0) + gotElevation = eq.getElevation(geoPoint, elevation, 0.0); +#else + const double resolution = 0.0; + double actualResolution; + elevation = eq.getElevation(geoPoint, resolution, &actualResolution); + gotElevation = (elevation != NO_DATA_VALUE); +#endif + bool clamped = false; + if (gotElevation) { clamped = ((geoPoint.z() - offset) < elevation); if (clamped) { // qDebug() << "Utility::clampGeoPoint - clamping" << geoPoint.z() - offset << "/" << elevation; diff --git a/ground/gcs/src/libs/osgearth/utils/utility.h b/ground/gcs/src/libs/osgearth/utils/utility.h index 2f7124847..4de014ec8 100644 --- a/ground/gcs/src/libs/osgearth/utils/utility.h +++ b/ground/gcs/src/libs/osgearth/utils/utility.h @@ -145,8 +145,7 @@ QString getUsageString(osgViewer::Viewer *viewer); QString getUsageString(osgViewer::CompositeViewer *viewer); #ifdef USE_OSGEARTH -osgEarth::GeoPoint toGeoPoint(const QVector3D &position); -osgEarth::GeoPoint toGeoPoint(const osgEarth::SpatialReference *srs, const QVector3D &position); +osgEarth::GeoPoint createGeoPoint(const QVector3D &position, osgEarth::MapNode *mapNode); bool clampGeoPoint(osgEarth::GeoPoint &geoPoint, float offset, osgEarth::MapNode *mapNode); void capabilitiesInfo(const osgEarth::Capabilities & caps); #endif