SnakeWorker.h 3.2 KB
Newer Older
Valentin Platzgummer's avatar
Valentin Platzgummer committed
1 2 3 4 5 6
#pragma once

#include <QObject>
#include <QVariant>
#include <QThread>
#include <QVector>
Valentin Platzgummer's avatar
Valentin Platzgummer committed
7 8
#include <QGeoCoordinate>
#include <vector>
Valentin Platzgummer's avatar
Valentin Platzgummer committed
9

Valentin Platzgummer's avatar
Valentin Platzgummer committed
10 11
#include "GeoPolygonArray.h"
#include "PolygonArray.h"
Valentin Platzgummer's avatar
Valentin Platzgummer committed
12 13 14 15 16


typedef QList<QVariant> QVariantList;

typedef struct Result{
Valentin Platzgummer's avatar
Valentin Platzgummer committed
17
    QVector<QGeoCoordinate> waypoints;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
18 19
    GeoPolygonArray         tiles;
    PolygonArray            tilesLocal;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
20 21
    QVariantList            tileCenterPoints;
    QGeoCoordinate          origin;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
22 23 24
    QVector<unsigned long>  arrivalPathIdx;
    QVector<unsigned long>  returnPathIdx;
    bool                    success;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
25
    QString                 errorMessage;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
26 27

    void clear();
Valentin Platzgummer's avatar
Valentin Platzgummer committed
28 29 30 31 32 33 34
}WorkerResult_t;

class SnakeWorker : public QThread{
    Q_OBJECT

public:
    SnakeWorker(QObject *parent = nullptr);
35
    ~SnakeWorker() override;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
36 37


Valentin Platzgummer's avatar
Valentin Platzgummer committed
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
    template<template<class, class...> class Container>
    void setMeasurementArea     (const Container<QGeoCoordinate>  &measurementArea);
    template<template<class, class...> class Container>
    void setServiceArea         (const Container<QGeoCoordinate>  &serviceArea);
    template<template<class, class...> class Container>
    void setCorridor            (const Container<QGeoCoordinate>  &corridor);
    template<template<class, class...> class Container, class IntType>
    void setProgress            (const Container<IntType>  &progress);

    WorkerResult_t &result();

    double lineDistance() const;
    void setLineDistance(double lineDistance);

    double minTransectLength() const;
    void setMinTransectLength(double minTransectLength);

    double minTileArea() const;
    void setMinTileArea(double minTileArea);

    double tileHeight() const;
    void setTileHeight(double tileHeight);

    double tileWidth() const;
    void setTileWidth(double tileWidth);
63

Valentin Platzgummer's avatar
Valentin Platzgummer committed
64 65 66 67
protected:
    void run() override;

private:
Valentin Platzgummer's avatar
Valentin Platzgummer committed
68 69 70 71 72 73 74 75 76 77 78 79 80
    bool precondition() const;


    std::vector<QGeoCoordinate> _mArea;
    std::vector<QGeoCoordinate> _sArea;
    std::vector<QGeoCoordinate> _corridor;
    std::vector<int>            _progress;
    double                      _lineDistance;
    double                      _minTransectLength;
    double                      _tileWidth;
    double                      _tileHeight;
    double                      _minTileArea;
    WorkerResult_t              _result;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
81 82
};

Valentin Platzgummer's avatar
Valentin Platzgummer committed
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 108 109 110 111 112 113 114 115 116 117 118 119
template<template<class, class...> class Container>
void SnakeWorker::setCorridor(const Container<QGeoCoordinate> &corridor)
{
    _corridor.clear();
    for (auto vertex : corridor) {
        _corridor.push_back(vertex);
    }
}

template<template<class, class...> class Container>
void SnakeWorker::setMeasurementArea(const Container<QGeoCoordinate> &measurementArea)
{
    _mArea.clear();
    for (auto vertex : measurementArea) {
        _mArea.push_back(vertex);
    }
}

template<template<class, class...> class Container>
void SnakeWorker::setServiceArea(const Container<QGeoCoordinate> &serviceArea)
{
    _sArea.clear();
    for (auto vertex : serviceArea) {
        _sArea.push_back(vertex);
    }
}

template<template<class, class...> class Container, class IntType>
void SnakeWorker::setProgress(const Container<IntType> &progress)
{
    _progress.clear();
    for (auto p : progress) {
        assert(p >= -1 && p <= 100);
        _progress.push_back(p);
    }
}