11 , _coord1AMSLAlt (amslCoord1Alt)
12 , _coord2AMSLAlt (amslCoord2Alt)
13 , _queryTerrainData (queryTerrainData)
14 , _segmentType (segmentType)
16 _delayedTerrainPathQueryTimer.setSingleShot(
true);
17 _delayedTerrainPathQueryTimer.setInterval(200);
18 _delayedTerrainPathQueryTimer.callOnTimeout(
this, &FlightPathSegment::_sendTerrainPathQuery);
19 _updateTotalDistance();
21 qCDebug(FlightPathSegmentLog) <<
this <<
"new" << coord1 << coord2 << amslCoord1Alt << amslCoord2Alt << _totalDistance;
23 _sendTerrainPathQuery();
28 if (_coord1 != coordinate) {
31 _delayedTerrainPathQueryTimer.start();
32 _updateTotalDistance();
38 if (_coord2 != coordinate) {
41 _delayedTerrainPathQueryTimer.start();
42 _updateTotalDistance();
51 _updateTerrainCollision();
60 _updateTerrainCollision();
72void FlightPathSegment::_sendTerrainPathQuery(
void)
74 if (_queryTerrainData && _coord1.isValid() && _coord2.isValid()) {
75 qCDebug(FlightPathSegmentLog) <<
this <<
"_sendTerrainPathQuery";
77 if (_currentTerrainPathQuery) {
80 _currentTerrainPathQuery =
nullptr;
84 _amslTerrainHeights.clear();
86 _finalDistanceBetween = 0;
93 _currentTerrainPathQuery->
requestData(_coord1, _coord2);
99 qCDebug(FlightPathSegmentLog) <<
this <<
"_terrainDataReceived" << success << pathHeightInfo.
heights.count();
110 _amslTerrainHeights.clear();
111 for (
const double& amslTerrainHeight: pathHeightInfo.heights) {
112 _amslTerrainHeights.append(amslTerrainHeight);
117 _currentTerrainPathQuery->deleteLater();
118 _currentTerrainPathQuery =
nullptr;
120 _updateTerrainCollision();
123void FlightPathSegment::_updateTotalDistance(
void)
125 double newTotalDistance = 0;
126 if (_coord1.isValid() && _coord2.isValid()) {
127 newTotalDistance = _coord1.distanceTo(_coord2);
131 _totalDistance = newTotalDistance;
136void FlightPathSegment::_updateTerrainCollision(
void)
138 bool newTerrainCollision =
false;
141 double slope = (_coord2AMSLAlt - _coord1AMSLAlt) / _totalDistance;
142 double yIntercept = _coord1AMSLAlt;
145 for (
int i=0; i<_amslTerrainHeights.count(); i++) {
146 bool ignoreCollision =
false;
148 ignoreCollision =
true;
149 }
else if (_segmentType ==
SegmentTypeLand && x > _totalDistance - _collisionIgnoreMeters) {
150 ignoreCollision =
true;
153 if (!ignoreCollision) {
154 double y = _amslTerrainHeights[i].value<
double>();
155 if (y > (slope * x) + yIntercept) {
156 newTerrainCollision =
true;
161 if (i == _amslTerrainHeights.count() - 2) {
162 x += _finalDistanceBetween;
164 x += _distanceBetween;
169 qCDebug(FlightPathSegmentLog) <<
this <<
"_updateTerrainCollision new:old" << newTerrainCollision << _terrainCollision;
171 if (newTerrainCollision != _terrainCollision) {
172 _terrainCollision = newTerrainCollision;
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void terrainCollisionChanged(bool terrainCollision)
void totalDistanceChanged(double totalDistance)
void setCoordinate2(const QGeoCoordinate &coordinate)
void coord2AMSLAltChanged(void)
void finalDistanceBetweenChanged(double finalDistanceBetween)
@ SegmentTypeTerrainFrame
void coord1AMSLAltChanged(void)
QGeoCoordinate coordinate1 MEMBER _coord1 NOTIFY coordinate1Changed(QGeoCoordinate coordinate2 MEMBER _coord2 NOTIFY coordinate2Changed) 1(double coord1AMSLAlt MEMBER _coord1AMSLAlt NOTIFY coord1AMSLAltChanged) 1(double coord2AMSLAlt MEMBER _coord2AMSLAlt NOTIFY coord2AMSLAltChanged) 1(bool specialVisual READ specialVisual WRITE setSpecialVisual NOTIFY specialVisualChanged) 1(QVariantList amslTerrainHeights MEMBER _amslTerrainHeights NOTIFY amslTerrainHeightsChanged) 1(double distanceBetween MEMBER _distanceBetween NOTIFY distanceBetweenChanged) 1(double final DistanceBetween MEMBER _finalDistanceBetween NOTIFY final DistanceBetweenChanged) 1(double totalDistance MEMBER _totalDistance NOTIFY totalDistanceChanged) 1(bool terrainCollision MEMBER _terrainCollision NOTIFY terrainCollisionChanged) 1(SegmentType segmentType MEMBER _segmentType CONSTANT) QGeoCoordinate coordinate1(void) const
void setSpecialVisual(bool specialVisual)
void amslTerrainHeightsChanged(void)
bool specialVisual(void) const
void specialVisualChanged(bool specialVisual)
void coordinate2Changed(QGeoCoordinate coordinate)
void setCoord2AMSLAlt(double alt)
void distanceBetweenChanged(double distanceBetween)
void setCoord1AMSLAlt(double alt)
void setCoordinate1(const QGeoCoordinate &coordinate)
void terrainDataReceived(bool success, const TerrainPathQuery::PathHeightInfo_t &pathHeightInfo)
Signalled when terrain data comes back from server.
void requestData(const QGeoCoordinate &fromCoord, const QGeoCoordinate &toCoord)
bool fuzzyCompare(double value1, double value2)
Returns true if the two values are equal or close. Correctly handles 0 and NaN values.
double distanceBetween
Distance between each height value.
double finalDistanceBetween
Distance between final two height values.
QList< double > heights
Terrain heights along path.