CircularSurveyComplexItem.cc 5.84 KB
Newer Older
1 2 3 4 5 6
#include "CircularSurveyComplexItem.h"


const char* CircularSurveyComplexItem::settingsGroup =              "Survey";

CircularSurveyComplexItem::CircularSurveyComplexItem(Vehicle *vehicle, bool flyView, const QString &kmlOrShpFile, QObject *parent)
7 8 9 10 11 12 13 14
    :   TransectStyleComplexItem (vehicle, flyView, settingsGroup, parent)
    ,   _referencePoint(QGeoCoordinate(47.770859, 16.531076,0))

{

}

void CircularSurveyComplexItem::setRefPoint(const QGeoCoordinate &refPt)
15
{
16 17
    if (refPt != _referencePoint){
        _referencePoint = refPt;
18

19 20 21 22 23 24 25
        emit refPointChanged();
    }
}

QGeoCoordinate CircularSurveyComplexItem::refPoint() const
{
    return _referencePoint;
26 27 28 29
}

bool CircularSurveyComplexItem::load(const QJsonObject &complexObject, int sequenceNumber, QString &errorString)
{
30
    return false;
31 32 33 34
}

void CircularSurveyComplexItem::save(QJsonArray &planItems)
{
35

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
}

void CircularSurveyComplexItem::appendMissionItems(QList<MissionItem *> &items, QObject *missionItemParent)
{

}

void CircularSurveyComplexItem::applyNewAltitude(double newAltitude)
{

}

double CircularSurveyComplexItem::timeBetweenShots()
{
    return 1;
}

bool CircularSurveyComplexItem::readyForSave() const
{
    return false;
}

double CircularSurveyComplexItem::additionalTimeDelay() const
{
    return 0;
}

void CircularSurveyComplexItem::_rebuildTransectsPhase1()
{
65 66 67 68
    using namespace GeoUtilities;
    using namespace PolygonCalculus;
    using namespace PlanimetryCalculus;

69 70 71
    if ( _surveyAreaPolygon.count() < 3)
        return;

72
    _transects.clear();
73 74 75
    QPolygonF surveyPolygon = toQPolygonF(toCartesian2D(_surveyAreaPolygon.coordinateList(), _referencePoint));

    QVector<double> distances;
76 77
    for (const QPointF &p : surveyPolygon) distances.append(norm(p));

78 79

    double dalpha = 0.5/180*M_PI; // radiants
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    double dr = 30; // meter
    double r_min = dr; // meter
    double r_max = (*std::max_element(distances.begin(), distances.end())); // meter


    QPointF origin(0, 0);
    IntersectType type;
    if (!contains(surveyPolygon, origin, type)) {
        QVector<double> angles;
        for (const QPointF &p : surveyPolygon) angles.append(truncateAngle(angle(p)));

        // determine r_min by successive approximation
        double r = r_max;
        while ( r > r_min) {
            Circle circle(r, origin);

            if (!intersects(circle, surveyPolygon)) {
                r_min = r;
                break;
            }

            r -= dr;
        }
    }

    qWarning("r_min, r_max:");
    qWarning() << r_min;
    qWarning() << r_max;
108 109 110 111

    QList<QPolygonF> convexPolygons;
    decomposeToConvex(surveyPolygon, convexPolygons);

112
    QList<QList<QPointF>> fullPath;
113 114
    for (int i = 0; i < convexPolygons.size(); i++){
        const QPolygonF &polygon = convexPolygons[i];
115
        double r = r_min;
116

117 118
        QList<QList<QPointF>> currPolyPath;
        bool currentPolyPathUpdated = false;
119
        int direction = 1;
120
        while (r < r_max) {
121
            Circle circle(r, origin);
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
            QList<QPointFList> intersectPoints;
            QList<IntersectType> typeList;
            if (intersects(circle, polygon, intersectPoints, typeList)) {
                if (intersectPoints.size() >= 1) {
                    // continue here
                    QPointF p1 = intersectPoints.first()[0];
                    QPointF p2 = intersectPoints.first()[1];
                    double beta1 = angle(p1);
                    double beta2 = angle(p2);
                    double alpha1 = fmin(beta1, beta2);
                    double alpha2 = fmax(beta1, beta2);

                    QList<QPointF> sector = circle.approximateSektor(direction*dalpha, alpha1, alpha2);
                    QList<QPointF> sectorPath;
                    for ( const QPointF &p : sector) {
                        if (polygon.containsPoint(p, Qt::FillRule::OddEvenFill))
                            sectorPath.append(p);
                    }

                    if (sectorPath.size() > 0 ) {
                        if (direction == -1){
                            direction = 1;
                        } else
                            direction = -1;

                        // use shortestPath() here if necessary, could be a problem if dr >>
                        currPolyPath.append(sectorPath);
                        currentPolyPathUpdated = true;
                    }
                }
152 153 154 155 156
            }

            r += dr;
        }

157 158 159 160 161 162 163 164 165 166 167 168 169
        if (currentPolyPathUpdated) {
            if (fullPath.size() > 1) {
                QPointF start = fullPath.last().last();
                QPointF end = currPolyPath.last().first();
                QList<QPointF> path;
                if(!shortestPath(surveyPolygon, start, end, path))
                    return;
                path.removeFirst();
                path.removeLast();
                currPolyPath.last().append(path);
            }

            fullPath.append(currPolyPath);
170 171 172 173
        }

    }

174 175 176 177 178 179 180 181 182
    for ( const QList<QPointF> &transect : fullPath) {
        QList<QGeoCoordinate> geoPath = toGeo(transect, _referencePoint);
        QList<CoordInfo_t> transectList;
        for ( const QGeoCoordinate &coordinate : geoPath) {
            CoordInfo_t coordinfo = {coordinate, CoordTypeInterior};
            transectList.append(coordinfo);
        }
        _transects.append(transectList);
    }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
183

184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
}

void CircularSurveyComplexItem::_recalcComplexDistance()
{

}

void CircularSurveyComplexItem::_recalcCameraShots()
{

}

/*!
    \class CircularSurveyComplexItem
    \inmodule Wima

    \brief The \c CircularSurveyComplexItem class provides a survey mission item with circular transects around a point of interest.

    CircularSurveyComplexItem class provides a survey mission item with circular transects around a point of interest. Within the
    \c Wima module it's used to scan a defined area with constant angle (circular transects) to the base station (point of interest).

    \sa WimaArea
*/