Commit ed926c07 authored by Valentin Platzgummer's avatar Valentin Platzgummer

about to add Dijkstra

parent 29a10bab
...@@ -220,6 +220,7 @@ ...@@ -220,6 +220,7 @@
<file alias="QGroundControl/Controls/WimaGOperationAreaEditor.qml">src/WimaView/WimaGOperationAreaEditor.qml</file> <file alias="QGroundControl/Controls/WimaGOperationAreaEditor.qml">src/WimaView/WimaGOperationAreaEditor.qml</file>
<file alias="QGroundControl/Controls/WimaServiceAreaEditor.qml">src/WimaView/WimaServiceAreaEditor.qml</file> <file alias="QGroundControl/Controls/WimaServiceAreaEditor.qml">src/WimaView/WimaServiceAreaEditor.qml</file>
<file alias="QGroundControl/Controls/WimaVCorridorMapVisual.qml">src/WimaView/WimaVCorridorMapVisual.qml</file> <file alias="QGroundControl/Controls/WimaVCorridorMapVisual.qml">src/WimaView/WimaVCorridorMapVisual.qml</file>
<file alias="QGroundControl/Controls/WimaAreaMapVisual.qml">src/WimaView/WimaAreaMapVisual.qml</file>
</qresource> </qresource>
<qresource prefix="/json"> <qresource prefix="/json">
<file alias="APMMavlinkStreamRate.SettingsGroup.json">src/Settings/APMMavlinkStreamRate.SettingsGroup.json</file> <file alias="APMMavlinkStreamRate.SettingsGroup.json">src/Settings/APMMavlinkStreamRate.SettingsGroup.json</file>
......
...@@ -89,6 +89,7 @@ WimaMapVisual 1.0 WimaMapVisual.qml ...@@ -89,6 +89,7 @@ WimaMapVisual 1.0 WimaMapVisual.qml
WimaGOperationAreaMapVisual 1.0 WimaGOperationAreaMapVisual.qml WimaGOperationAreaMapVisual 1.0 WimaGOperationAreaMapVisual.qml
WimaGOperationAreaEditor 1.0 WimaGOperationAreaEditor.qml WimaGOperationAreaEditor 1.0 WimaGOperationAreaEditor.qml
WimaServiceAreaMapVisual 1.0 WimaServiceAreaMapVisual.qml WimaServiceAreaMapVisual 1.0 WimaServiceAreaMapVisual.qml
WimaAreaMapVisual 1.0 WimaAreaMapVisual.qml
WimaServiceAreaEditor 1.0 WimaServiceAreaEditor.qml WimaServiceAreaEditor 1.0 WimaServiceAreaEditor.qml
WimaVCorridorMapVisual 1.0 WimaVCorridorMapVisual.qml WimaVCorridorMapVisual 1.0 WimaVCorridorMapVisual.qml
WimaItemEditor 1.0 WimaItemEditor.qml WimaItemEditor 1.0 WimaItemEditor.qml
......
This diff is collapsed.
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <QLineF> #include <QLineF>
#include <QPointF> #include <QPointF>
#include "QGCGeo.h" #include "QGCGeo.h"
#include <QPair>
class WimaArea : public QGCMapPolygon //abstract base class for all WimaAreas class WimaArea : public QGCMapPolygon //abstract base class for all WimaAreas
{ {
...@@ -42,34 +43,41 @@ public: ...@@ -42,34 +43,41 @@ public:
template <class T> template <class T>
QList<T*>* splitArea (int numberOfFractions); // use QScopedPointer to store return value*/ QList<T*>* splitArea (int numberOfFractions); // use QScopedPointer to store return value*/
//iterates over all vertices in _polygon and returns the index of that one closest to coordinate //iterates over all vertices in _polygon and returns the index of that one closest to coordinate
int getClosestVertexIndex (QGeoCoordinate coordinate); int getClosestVertexIndex (QGeoCoordinate coordinate);
//iterates over all vertices in _polygon and returns that one closest to coordinate //iterates over all vertices in _polygon and returns that one closest to coordinate
QGeoCoordinate getClosestVertex (QGeoCoordinate coordinate); QGeoCoordinate getClosestVertex (QGeoCoordinate coordinate);
QGCMapPolygon* toQGCPolygon (WimaArea* poly); QGCMapPolygon* toQGCPolygon (WimaArea* poly);
WimaArea* joinPolygons (QList<WimaArea*>* polyList); static void join (QList<WimaArea*>* polyList, WimaArea* joinedPoly);
/// joins the poly1 and poly2 if possible, joins the polygons to form a simple polygon (no holes) /// joins the poly1 and poly2 if possible, joins the polygons to form a simple polygon (no holes)
/// see https://en.wikipedia.org/wiki/Simple_polygon /// see https://en.wikipedia.org/wiki/Simple_polygon
/// @return the joined polygon of poly1 and poly2 if possible, poly1 else /// @return the joined polygon of poly1 and poly2 if possible, poly1 else
WimaArea* joinPolygons (WimaArea* poly1, WimaArea* poly2); static void join (WimaArea* poly1, WimaArea* poly2, WimaArea* joinedPoly);
bool isDisjunct (QList<WimaArea*>* polyList); void join (WimaArea* poly);
bool isDisjunct (WimaArea* poly1, WimaArea* poly2); bool isDisjunct (QList<WimaArea*>* polyList);
bool isDisjunct (WimaArea* poly1, WimaArea* poly2);
/// calculates the next polygon vertex index /// calculates the next polygon vertex index
/// @return index + 1 if index < poly->count()-1 && index >= 0, or 0 if index == poly->count()-1, -1 else /// @return index + 1 if index < poly->count()-1 && index >= 0, or 0 if index == poly->count()-1, -1 else
int nextVertexIndex (int index); int nextVertexIndex (int index);
/// calculates the previous polygon vertex index /// calculates the previous polygon vertex index
/// @return index - 1 if index < poly->count() && index > 0, or poly->count()-1 if index == 0, -1 else /// @return index - 1 if index < poly->count() && index > 0, or poly->count()-1 if index == 0, -1 else
int previousVertexIndex (int index); int previousVertexIndex (int index);
/// checks if line1 and line2 intersect with each other, takes latitude and longitute into account only (height neglected) /// checks if line1 and line2 intersect with each other, takes latitude and longitute into account only (height neglected)
/// @param line1 line containing two coordinates, height not taken into account /// @param line1 line containing two coordinates, height not taken into account
/// @param line2 line containing two coordinates, height not taken into account /// @param line2 line containing two coordinates, height not taken into account
/// @return the intersection point if line1 intersects line2, nullptr else /// @param intersectionPt Coordinate item to store intersection pt. in.
QGeoCoordinate* intersects(QGCMapPolyline* line1, QGCMapPolyline* line2); /// @return false on error or no intersection, true else
static bool intersects(QGCMapPolyline* line1, QGCMapPolyline* line2, QGeoCoordinate* intersectionPt);
/// checks if line1 and poly intersect with each other, takes latitude and longitute into account only (height neglected) /// checks if line1 and poly intersect with each other, takes latitude and longitute into account only (height neglected)
/// @param line line containing two coordinates, height not taken into account /// @param line line containing two coordinates, height not taken into account
/// @return a list of intersection points and the two neares neighbours of poly to the intersection point if line intersects poly, or an empty list else. /// @param intersectionList Empty list to store intersection points in.
/// The first entry is the first intersec. pt. (if existing). The second and third entries are the nearest neighbours of the first intersec. pt. in poly /// @param neighbourList Empty list to store the indices of the neighbours (the two Vertices of poly with the smallest distance to the intersection pt.)
/// The fourth entry is the second intersec. pt. (if existing). The fifth and sixth entries are the nearest neighbours of the second intersec. pt. in poly /// @return false on error or no intersection, true else
QList<QGeoCoordinate>* intersects(QGCMapPolyline* line, WimaArea* poly); static bool intersects(QGCMapPolyline* line, WimaArea* poly, QList<QGeoCoordinate>* intersectionList, QList<QPair<int, int>>* neighbourlist);
/// calculates the distance between to geo coordinates, returns the distance if the path lies within the polygon and inf. else.
/// @return the distance if the path lies within the polygon and inf. else.
static double distInsidePoly(QGeoCoordinate *c1, QGeoCoordinate *c2, WimaArea *poly);
/// calculates the shortes path between two geo coordinates inside a polygon using the Dijkstra Algorithm
static void dijkstraPath(QGeoCoordinate *c1, QGeoCoordinate *c2, WimaArea *poly, QGCMapPolyline *dijkstraPath);
// Accurracy used to compute isDisjunct // Accurracy used to compute isDisjunct
static const double numericalAccuracy; static const double numericalAccuracy;
......
...@@ -73,55 +73,13 @@ void WimaController::addServiceArea() ...@@ -73,55 +73,13 @@ void WimaController::addServiceArea()
emit visualItemsChanged(); emit visualItemsChanged();
} }
bool WimaController::addVehicleCorridor(WimaGOperationArea *opArea, WimaServiceArea *serviceArea) void WimaController::addVehicleCorridor()
{ {
WimaVCorridor* corridor = nullptr; WimaVCorridor* corridor = new WimaVCorridor(this);
if (opArea != nullptr && serviceArea != nullptr){ _visualItems->append(corridor);
for (int i = 0; i < _visualItems->count(); i++) { int newIndex = _visualItems->count()-1;
corridor = qobject_cast<WimaVCorridor*>(_visualItems->get(i)); setCurrentPolygonIndex(newIndex);
if (corridor != nullptr){ emit visualItemsChanged();
if (corridor->serviceArea() == serviceArea && corridor->opArea() == opArea){
break;
}else {
corridor = nullptr;
}
}
}
bool newCorridorCreated = false;
if(corridor == nullptr){
corridor = new WimaVCorridor(opArea);
newCorridorCreated = true;
}else {
corridor->clear();
}
QList<QGeoCoordinate> opAreaPolyline = opArea->polyline()->coordinateList();
QList<QGeoCoordinate> serAreaPolyline = serviceArea->polyline()->coordinateList();
if (opAreaPolyline.size() > 1 && serAreaPolyline.size() > 1){
corridor->appendVertices(opAreaPolyline);
corridor->appendVertices(serAreaPolyline);
if (newCorridorCreated){
corridor->setServiceArea(serviceArea);
corridor->setOpArea(opArea);
serviceArea->setVehicleCorridor(corridor);
opArea->setVehicleCorridor(corridor);
_visualItems->append(corridor);
emit visualItemsChanged();
}
return true;
}else {
qWarning("WimaController::addVehicleCorridor(): OpArea or serviceArea polyline size <= 1!");
if (newCorridorCreated){
corridor->deleteLater();
}
return false;
}
}else {
return false;
}
} }
void WimaController::startMission() void WimaController::startMission()
...@@ -166,14 +124,23 @@ bool WimaController::updateMission() ...@@ -166,14 +124,23 @@ bool WimaController::updateMission()
} }
} }
// calc. vehicle corridor // pick first WimaVCorridor
if (opArea != nullptr && serArea != nullptr){ WimaVCorridor* corridor = nullptr;
if(!addVehicleCorridor(opArea, serArea)){ for (int i = 0; i < _visualItems->count(); i++) {
return false; WimaVCorridor* currentArea = qobject_cast<WimaVCorridor*>(_visualItems->get(i));
if (currentArea != nullptr){
corridor = currentArea;
break;
} }
}else{
return false;
} }
// join service area and op area
WimaArea* joinedArea = new WimaArea(this);
WimaArea::join(corridor, serArea, joinedArea);
joinedArea->join(opArea);
_visualItems->append(joinedArea);
// reset visual items // reset visual items
_missionController->removeAll(); _missionController->removeAll();
......
...@@ -50,7 +50,7 @@ public: ...@@ -50,7 +50,7 @@ public:
Q_INVOKABLE void removeArea(int index); Q_INVOKABLE void removeArea(int index);
Q_INVOKABLE void addServiceArea(); Q_INVOKABLE void addServiceArea();
/// @return true if a vehicle corridor was added sucessfully and false otherwise. /// @return true if a vehicle corridor was added sucessfully and false otherwise.
bool addVehicleCorridor(WimaGOperationArea* opArea, WimaServiceArea* serviceArea); Q_INVOKABLE void addVehicleCorridor();
Q_INVOKABLE void startMission(); Q_INVOKABLE void startMission();
Q_INVOKABLE void abortMission(); Q_INVOKABLE void abortMission();
......
/****************************************************************************
*
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
import QtQuick 2.3
import QtQuick.Controls 1.2
import QtLocation 5.3
import QtPositioning 5.3
import QGroundControl 1.0
import QGroundControl.ScreenTools 1.0
import QGroundControl.Palette 1.0
import QGroundControl.Controls 1.0
import QGroundControl.FlightMap 1.0
/// Wima Area visuals
Item {
id: _root
property var map ///< Map control to place item in
property var qgcView ///< QGCView to use for popping dialogs
property var areaItem: object
property var _polygon: areaItem
signal clicked(int sequenceNumber)
/// Add an initial 4 sided polygon if there is none
function _addInitialPolygon() {
if (_polygon.count < 3) {
// Initial polygon is inset to take 2/3rds space
var rect = Qt.rect(map.centerViewport.x, map.centerViewport.y, map.centerViewport.width, map.centerViewport.height)
rect.x += (rect.width * 0.25) / 2
rect.y += (rect.height * 0.25) / 2
rect.width *= 0.75
rect.height *= 0.75
var centerCoord = map.toCoordinate(Qt.point(rect.x + (rect.width / 2), rect.y + (rect.height / 2)), false /* clipToViewPort */)
var topLeftCoord = map.toCoordinate(Qt.point(rect.x, rect.y), false /* clipToViewPort */)
var topRightCoord = map.toCoordinate(Qt.point(rect.x + rect.width, rect.y), false /* clipToViewPort */)
var bottomLeftCoord = map.toCoordinate(Qt.point(rect.x, rect.y + rect.height), false /* clipToViewPort */)
var bottomRightCoord = map.toCoordinate(Qt.point(rect.x + rect.width, rect.y + rect.height), false /* clipToViewPort */)
// Adjust polygon to max size
var maxSize = 100
var halfWidthMeters = Math.min(topLeftCoord.distanceTo(topRightCoord), maxSize) / 2
var halfHeightMeters = Math.min(topLeftCoord.distanceTo(bottomLeftCoord), maxSize) / 2
topLeftCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, -90).atDistanceAndAzimuth(halfHeightMeters, 0)
topRightCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, 90).atDistanceAndAzimuth(halfHeightMeters, 0)
bottomLeftCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, -90).atDistanceAndAzimuth(halfHeightMeters, 180)
bottomRightCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, 90).atDistanceAndAzimuth(halfHeightMeters, 180)
_polygon.appendVertex(topLeftCoord)
_polygon.appendVertex(topRightCoord)
_polygon.appendVertex(bottomRightCoord)
_polygon.appendVertex(bottomLeftCoord)
}
}
Component.onCompleted: {
_addInitialPolygon()
}
Component.onDestruction: {
}
WimaMapPolygonVisuals {
qgcView: _root.qgcView
mapControl: map
mapPolygon: _polygon
borderWidth: 1
borderColor: "black"
interiorColor: "gray"
interiorOpacity: 0.25
}
}
...@@ -33,6 +33,7 @@ Item { ...@@ -33,6 +33,7 @@ Item {
property int borderWidth: 0 property int borderWidth: 0
property color borderColor: "black" property color borderColor: "black"
property bool initPolygon: false property bool initPolygon: false
property bool showVertexIndex: true
property var _polygonComponent property var _polygonComponent
property var _dragHandlesComponent property var _dragHandlesComponent
...@@ -417,6 +418,13 @@ Item { ...@@ -417,6 +418,13 @@ Item {
color: Qt.rgba(1,1,1,0.8) color: Qt.rgba(1,1,1,0.8)
border.color: Qt.rgba(0,0,0,0.25) border.color: Qt.rgba(0,0,0,0.25)
border.width: 1 border.width: 1
QGCLabel {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
color: "black"
text: showVertexIndex ? polygonVertex : ""
}
} }
} }
} }
......
...@@ -71,7 +71,7 @@ Item { ...@@ -71,7 +71,7 @@ Item {
Component.onCompleted: { Component.onCompleted: {
//_addInitialPolygon() _addInitialPolygon()
//_addInitialPolyline() //_addInitialPolyline()
} }
...@@ -85,7 +85,6 @@ Item { ...@@ -85,7 +85,6 @@ Item {
borderWidth: 1 borderWidth: 1
borderColor: "black" borderColor: "black"
interiorColor: "blue" interiorColor: "blue"
interactive: false
interiorOpacity: 0.2 interiorOpacity: 0.2
} }
......
...@@ -576,11 +576,15 @@ QGCView { ...@@ -576,11 +576,15 @@ QGCView {
dropPanelComponent: syncDropPanel dropPanelComponent: syncDropPanel
}, },
{ {
name: qsTr("Global Area"), name: qsTr("Global"),
iconSource: "/qmlimages/Target.svg" iconSource: "/qmlimages/Target.svg"
}, },
{ {
name: qsTr("Service Area"), name: qsTr("Service"),
iconSource: "/qmlimages/noFlyArea.svg"
},
{
name: qsTr("Corridor"),
iconSource: "/qmlimages/noFlyArea.svg" iconSource: "/qmlimages/noFlyArea.svg"
}, },
{ {
...@@ -621,16 +625,19 @@ QGCView { ...@@ -621,16 +625,19 @@ QGCView {
_addWaypointOnClick = false*/ _addWaypointOnClick = false*/
break break
case 3: case 3:
wimaController.addVehicleCorridor();
break
case 4:
/*if (_singleComplexItem) { /*if (_singleComplexItem) {
addComplexItem(_missionController.complexMissionItemNames[0]) addComplexItem(_missionController.complexMissionItemNames[0])
}*/ }*/
wimaController.updateMission(); wimaController.updateMission();
break break
case 5: case 6:
editorMap.zoomLevel += 0.5 editorMap.zoomLevel += 0.5
break break
case 6: case 7:
editorMap.zoomLevel -= 0.5 editorMap.zoomLevel -= 0.5
break break
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment