Skip to content

Commit ff28e63

Browse files
committed
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...
1 parent 4c9c3c2 commit ff28e63

4 files changed

Lines changed: 54 additions & 50 deletions

File tree

ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.cpp

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,32 +117,30 @@ struct OSGGeoTransformNode::Hidden : public QObject {
117117
} else {
118118
qWarning() << "OSGGeoTransformNode::updatePosition - scene node is not valid";
119119
}
120-
121-
// TODO factorize this logic to utility (same logic is found elsewhere)
122-
osgEarth::GeoPoint geoPoint;
123120
if (mapNode) {
124-
geoPoint = osgQtQuick::toGeoPoint(mapNode->getTerrain()->getSRS(), position);
125-
} else {
126-
qWarning() << "OSGGeoTransformNode::onChildNodeChanged - no map node";
127-
geoPoint = osgQtQuick::toGeoPoint(position);
128-
}
129-
if (clampToTerrain && mapNode) {
130-
// get "size" of model
131-
// TODO this should be done once only...
132-
osg::ComputeBoundsVisitor cbv;
133-
transform->accept(cbv);
134-
const osg::BoundingBox & bbox = cbv.getBoundingBox();
135-
offset = bbox.radius();
136-
137-
// qDebug() << "OSGGeoTransformNode::updateNode - offset" << offset;
138-
139-
// clamp model to terrain if needed
140-
intoTerrain = clampGeoPoint(geoPoint, offset, mapNode);
141-
} else if (clampToTerrain) {
142-
qWarning() << "OSGGeoTransformNode::onChildNodeChanged - cannot clamp without map node";
121+
osgEarth::GeoPoint geoPoint = createGeoPoint(position, mapNode);
122+
if (clampToTerrain) {
123+
// get "size" of model
124+
// TODO this should be done once only...
125+
#if 0
126+
osg::ComputeBoundsVisitor cbv;
127+
transform->accept(cbv);
128+
const osg::BoundingBox & bbox = cbv.getBoundingBox();
129+
offset = bbox.radius();
130+
#else
131+
const osg::BoundingSphere & boundingSphere = transform->getBound();
132+
offset = boundingSphere.radius();
133+
#endif
134+
// clamp model to terrain if needed
135+
intoTerrain = clampGeoPoint(geoPoint, offset, mapNode);
136+
if (intoTerrain) {
137+
qDebug() << "OSGGeoTransformNode::updateNode - into terrain" << offset;
138+
}
139+
} else if (clampToTerrain) {
140+
qWarning() << "OSGGeoTransformNode::onChildNodeChanged - cannot clamp without map node";
141+
}
142+
transform->setPosition(geoPoint);
143143
}
144-
145-
transform->setPosition(geoPoint);
146144
}
147145

148146
private slots:

ground/gcs/src/libs/osgearth/osgQtQuick/ga/OSGGeoTransformManipulator.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,27 +155,21 @@ struct OSGGeoTransformManipulator::Hidden : public QObject {
155155

156156
if (sceneNode && sceneNode->node()) {
157157
mapNode = osgEarth::MapNode::findMapNode(sceneNode->node());
158-
if (!mapNode) {
159-
qWarning() << "OSGGeoTransformManipulator::updatePosition - manipulator node does not contain a map node";
160-
}
161158
} else {
162159
qWarning() << "OSGGeoTransformManipulator::updatePosition - scene node is null";
163160
}
164-
165-
osgEarth::GeoPoint geoPoint;
166161
if (mapNode) {
167-
geoPoint = osgQtQuick::toGeoPoint(mapNode->getTerrain()->getSRS(), position);
162+
osgEarth::GeoPoint geoPoint = osgQtQuick::createGeoPoint(position, mapNode);
163+
if (clampToTerrain) {
164+
// clamp model to terrain if needed
165+
intoTerrain = osgQtQuick::clampGeoPoint(geoPoint, 0, mapNode);
166+
} else if (clampToTerrain) {
167+
qWarning() << "OSGGeoTransformManipulator::updatePosition - cannot clamp without map node";
168+
}
169+
geoPoint.createLocalToWorld(cameraPosition);
168170
} else {
169-
geoPoint = osgQtQuick::toGeoPoint(position);
171+
qWarning() << "OSGGeoTransformManipulator::updatePosition - scene node does not contain a map node";
170172
}
171-
if (clampToTerrain && mapNode) {
172-
// clamp model to terrain if needed
173-
intoTerrain = osgQtQuick::clampGeoPoint(geoPoint, 0, mapNode);
174-
} else if (clampToTerrain) {
175-
qWarning() << "OSGGeoTransformManipulator::updatePosition - cannot clamp without map node";
176-
}
177-
178-
geoPoint.createLocalToWorld(cameraPosition);
179173
}
180174

181175
void updateAttitude()

ground/gcs/src/libs/osgearth/utils/utility.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@
6969
#include "osgQtQuick/ga/OSGEarthManipulator.hpp"
7070
#include "osgQtQuick/ga/OSGGeoTransformManipulator.hpp"
7171

72+
#include <osgEarth/Version>
7273
#include <osgEarth/Capabilities>
7374
#include <osgEarth/MapNode>
7475
#include <osgEarth/SpatialReference>
76+
#include <osgEarth/Terrain>
7577
#include <osgEarth/ElevationQuery>
7678
#endif // USE_OSGEARTH
7779

@@ -454,18 +456,20 @@ QString getUsageString(osgViewer::CompositeViewer *viewer)
454456
}
455457

456458
#ifdef USE_OSGEARTH
457-
osgEarth::GeoPoint toGeoPoint(const osgEarth::SpatialReference *srs, const QVector3D &position)
459+
osgEarth::GeoPoint createGeoPoint(const QVector3D &position, osgEarth::MapNode *mapNode)
458460
{
459-
osgEarth::GeoPoint geoPoint(srs, position.x(), position.y(), position.z(), osgEarth::ALTMODE_ABSOLUTE);
461+
const osgEarth::SpatialReference *srs = NULL;
460462

463+
if (mapNode) {
464+
srs = mapNode->getTerrain()->getSRS();
465+
} else {
466+
qWarning() << "Utility::createGeoPoint - null map node";
467+
srs = osgEarth::SpatialReference::get("wgs84");
468+
}
469+
osgEarth::GeoPoint geoPoint(srs, position.x(), position.y(), position.z(), osgEarth::ALTMODE_ABSOLUTE);
461470
return geoPoint;
462471
}
463472

464-
osgEarth::GeoPoint toGeoPoint(const QVector3D &position)
465-
{
466-
return toGeoPoint(osgEarth::SpatialReference::get("wgs84"), position);
467-
}
468-
469473
bool clampGeoPoint(osgEarth::GeoPoint &geoPoint, float offset, osgEarth::MapNode *mapNode)
470474
{
471475
if (!mapNode) {
@@ -477,9 +481,18 @@ bool clampGeoPoint(osgEarth::GeoPoint &geoPoint, float offset, osgEarth::MapNode
477481
osgEarth::ElevationQuery eq(mapNode->getMap());
478482
// qDebug() << "Utility::clampGeoPoint - SRS :" << QString::fromStdString(mapNode->getMap()->getSRS()->getName());
479483

480-
bool clamped = false;
481484
double elevation;
482-
if (eq.getElevation(geoPoint, elevation, 0.0)) {
485+
bool gotElevation;
486+
#if OSGEARTH_VERSION_LESS_THAN(2, 9, 0)
487+
gotElevation = eq.getElevation(geoPoint, elevation, 0.0);
488+
#else
489+
const double resolution = 0.0;
490+
double actualResolution;
491+
elevation = eq.getElevation(geoPoint, resolution, &actualResolution);
492+
gotElevation = (elevation != NO_DATA_VALUE);
493+
#endif
494+
bool clamped = false;
495+
if (gotElevation) {
483496
clamped = ((geoPoint.z() - offset) < elevation);
484497
if (clamped) {
485498
// qDebug() << "Utility::clampGeoPoint - clamping" << geoPoint.z() - offset << "/" << elevation;

ground/gcs/src/libs/osgearth/utils/utility.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ QString getUsageString(osgViewer::Viewer *viewer);
145145
QString getUsageString(osgViewer::CompositeViewer *viewer);
146146

147147
#ifdef USE_OSGEARTH
148-
osgEarth::GeoPoint toGeoPoint(const QVector3D &position);
149-
osgEarth::GeoPoint toGeoPoint(const osgEarth::SpatialReference *srs, const QVector3D &position);
148+
osgEarth::GeoPoint createGeoPoint(const QVector3D &position, osgEarth::MapNode *mapNode);
150149
bool clampGeoPoint(osgEarth::GeoPoint &geoPoint, float offset, osgEarth::MapNode *mapNode);
151150
void capabilitiesInfo(const osgEarth::Capabilities & caps);
152151
#endif

0 commit comments

Comments
 (0)