CameraCalc.h 7.33 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

#pragma once

#include "CameraSpec.h"
13
#include "SettingsFact.h"
14 15 16 17 18 19 20 21

class Vehicle;

class CameraCalc : public CameraSpec
{
    Q_OBJECT

public:
22
    CameraCalc(Vehicle* vehicle, const QString& settingsGroup, QObject* parent = nullptr);
23

24 25
    Q_PROPERTY(QString          customCameraName            READ customCameraName                                               CONSTANT)                                   ///< Camera name for custom camera setting
    Q_PROPERTY(QString          manualCameraName            READ manualCameraName                                               CONSTANT)                                   ///< Camera name for manual camera setting
26 27 28
    Q_PROPERTY(bool             isManualCamera              READ isManualCamera                                                 NOTIFY isManualCameraChanged)
    Q_PROPERTY(bool             isCustomCamera              READ isCustomCamera                                                 NOTIFY isCustomCameraChanged)
    Q_PROPERTY(Fact*            cameraName                  READ cameraName                                                     CONSTANT)
29 30 31 32 33 34 35 36
    Q_PROPERTY(Fact*            valueSetIsDistance          READ valueSetIsDistance                                             CONSTANT)                                   ///< true: distance specified, resolution calculated
    Q_PROPERTY(Fact*            distanceToSurface           READ distanceToSurface                                              CONSTANT)                                   ///< Distance to surface for image foot print calculation
    Q_PROPERTY(Fact*            imageDensity                READ imageDensity                                                   CONSTANT)                                   ///< Image density on surface (cm/px)
    Q_PROPERTY(Fact*            frontalOverlap              READ frontalOverlap                                                 CONSTANT)
    Q_PROPERTY(Fact*            sideOverlap                 READ sideOverlap                                                    CONSTANT)
    Q_PROPERTY(Fact*            adjustedFootprintSide       READ adjustedFootprintSide                                          CONSTANT)                                   ///< Side footprint adjusted down for overlap
    Q_PROPERTY(Fact*            adjustedFootprintFrontal    READ adjustedFootprintFrontal                                       CONSTANT)                                   ///< Frontal footprint adjusted down for overlap
    Q_PROPERTY(bool             distanceToSurfaceRelative   READ distanceToSurfaceRelative WRITE setDistanceToSurfaceRelative   NOTIFY distanceToSurfaceRelativeChanged)
37 38

    // The following values are calculated from the camera properties
39 40
    Q_PROPERTY(double imageFootprintSide    READ imageFootprintSide     NOTIFY imageFootprintSideChanged)       ///< Size of image size side in meters
    Q_PROPERTY(double imageFootprintFrontal READ imageFootprintFrontal  NOTIFY imageFootprintFrontalChanged)    ///< Size of image size frontal in meters
41

42 43
    static QString customCameraName(void);
    static QString manualCameraName(void);
44

45
    Fact* cameraName                (void) { return &_cameraNameFact; }
46 47 48 49 50 51 52 53
    Fact* valueSetIsDistance        (void) { return &_valueSetIsDistanceFact; }
    Fact* distanceToSurface         (void) { return &_distanceToSurfaceFact; }
    Fact* imageDensity              (void) { return &_imageDensityFact; }
    Fact* frontalOverlap            (void) { return &_frontalOverlapFact; }
    Fact* sideOverlap               (void) { return &_sideOverlapFact; }
    Fact* adjustedFootprintSide     (void) { return &_adjustedFootprintSideFact; }
    Fact* adjustedFootprintFrontal  (void) { return &_adjustedFootprintFrontalFact; }

54 55 56 57 58 59 60 61
    const Fact* valueSetIsDistance          (void) const { return &_valueSetIsDistanceFact; }
    const Fact* distanceToSurface           (void) const { return &_distanceToSurfaceFact; }
    const Fact* imageDensity                (void) const { return &_imageDensityFact; }
    const Fact* frontalOverlap              (void) const { return &_frontalOverlapFact; }
    const Fact* sideOverlap                 (void) const { return &_sideOverlapFact; }
    const Fact* adjustedFootprintSide       (void) const { return &_adjustedFootprintSideFact; }
    const Fact* adjustedFootprintFrontal    (void) const { return &_adjustedFootprintFrontalFact; }

62
    bool    dirty                       (void) const { return _dirty; }
63 64
    bool    isManualCamera              (void) const { return _cameraNameFact.rawValue().toString() == manualCameraName(); }
    bool    isCustomCamera              (void) const { return _cameraNameFact.rawValue().toString() == customCameraName(); }
65 66 67
    double  imageFootprintSide          (void) const { return _imageFootprintSide; }
    double  imageFootprintFrontal       (void) const { return _imageFootprintFrontal; }
    bool    distanceToSurfaceRelative   (void) const { return _distanceToSurfaceRelative; }
68

69 70
    void setDirty                       (bool dirty);
    void setDistanceToSurfaceRelative   (bool distanceToSurfaceRelative);
71 72

    void save(QJsonObject& json) const;
Don Gagne's avatar
Don Gagne committed
73
    bool load(const QJsonObject& json, QString& errorString);
74

75 76 77 78 79 80 81 82 83 84
    static const char* cameraNameName;
    static const char* valueSetIsDistanceName;
    static const char* distanceToSurfaceName;
    static const char* distanceToSurfaceRelativeName;
    static const char* imageDensityName;
    static const char* frontalOverlapName;
    static const char* sideOverlapName;
    static const char* adjustedFootprintSideName;
    static const char* adjustedFootprintFrontalName;

85
signals:
86 87 88 89
    void dirtyChanged                       (bool dirty);
    void imageFootprintSideChanged          (double imageFootprintSide);
    void imageFootprintFrontalChanged       (double imageFootprintFrontal);
    void distanceToSurfaceRelativeChanged   (bool distanceToSurfaceRelative);
90 91
    void isManualCameraChanged              (void);
    void isCustomCameraChanged              (void);
92 93

private slots:
94 95
    void _recalcTriggerDistance             (void);
    void _adjustDistanceToSurfaceRelative   (void);
96
    void _setDirty                          (void);
97
    void _cameraNameChanged                 (void);
98 99 100 101 102

private:
    Vehicle*        _vehicle;
    bool            _dirty;
    bool            _disableRecalc;
103
    bool            _distanceToSurfaceRelative;
104 105 106

    QMap<QString, FactMetaData*> _metaDataMap;

107 108 109 110 111 112 113 114
    SettingsFact _cameraNameFact;
    SettingsFact _valueSetIsDistanceFact;
    SettingsFact _distanceToSurfaceFact;
    SettingsFact _imageDensityFact;
    SettingsFact _frontalOverlapFact;
    SettingsFact _sideOverlapFact;
    SettingsFact _adjustedFootprintSideFact;
    SettingsFact _adjustedFootprintFrontalFact;
115 116 117 118 119 120

    double _imageFootprintSide;
    double _imageFootprintFrontal;

    QVariantList _knownCameraList;

121 122 123 124 125 126 127 128
    // The following are deprecated usage and only included in order to convert older formats

    enum CameraSpecType {
        CameraSpecNone,
        CameraSpecCustom,
        CameraSpecKnown
    };

129
    static const char* _jsonCameraSpecTypeKey;
130
};