QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
CameraMetaData.cc
Go to the documentation of this file.
1#include "CameraMetaData.h"
2
3#include <QtCore/QJsonArray>
4#include <QtCore/QJsonDocument>
5#include <QtCore/QJsonObject>
6
7#include "JsonParsing.h"
9
10QGC_LOGGING_CATEGORY(CameraMetaDataLog, "Camera.CameraMetaData")
11
12CameraMetaData::CameraMetaData(const QString &canonicalName_,
13 const QString &brand_,
14 const QString &model_,
15 double sensorWidth_,
16 double sensorHeight_,
17 double imageWidth_,
18 double imageHeight_,
19 double focalLength_,
20 bool landscape_,
21 bool fixedOrientation_,
22 double minTriggerInterval_,
23 const QString &deprecatedTranslatedName_)
24 : canonicalName(canonicalName_)
25 , brand(brand_)
26 , model(model_)
27 , sensorWidth(sensorWidth_)
28 , sensorHeight(sensorHeight_)
29 , imageWidth(imageWidth_)
30 , imageHeight(imageHeight_)
31 , focalLength(focalLength_)
32 , landscape(landscape_)
33 , fixedOrientation(fixedOrientation_)
34 , minTriggerInterval(minTriggerInterval_)
35 , deprecatedTranslatedName(deprecatedTranslatedName_)
36{
37 qCDebug(CameraMetaDataLog) << this;
38}
39
41{
42 qCDebug(CameraMetaDataLog) << this;
43}
44
46{
47 QList<CameraMetaData*> cameraList;
48
49 QString errorString;
50 int version = 0;
51 const QJsonObject jsonObject = JsonParsing::openInternalQGCJsonFile(QStringLiteral(":/json/CameraMetaData.json"), "CameraMetaData", 1, 1, version, errorString);
52 if (!errorString.isEmpty()) {
53 qCWarning(CameraMetaDataLog) << "Internal Error:" << errorString;
54 return cameraList;
55 }
56
57 static const QList<JsonParsing::KeyValidateInfo> rootKeyInfoList = {
58 { JsonParsing::jsonFileTypeKey, QJsonValue::String, true }, // Standard header, validated by openInternalQGCJsonFile
59 { JsonParsing::jsonVersionKey, QJsonValue::Double, true }, // Standard header, validated by openInternalQGCJsonFile
60 { "comment", QJsonValue::String, false }, // Developer notes only, never parsed
61 { "cameraMetaData", QJsonValue::Array, true }
62 };
63 if (!JsonParsing::validateKeysStrict(jsonObject, rootKeyInfoList, errorString)) {
64 qCWarning(CameraMetaDataLog) << errorString;
65 return cameraList;
66 }
67
68 static const QList<JsonParsing::KeyValidateInfo> cameraKeyInfoList = {
69 { "comment", QJsonValue::String, false }, // Developer notes only, never parsed
70 { "canonicalName", QJsonValue::String, true },
71 { "brand", QJsonValue::String, true },
72 { "model", QJsonValue::String, true },
73 { "sensorWidth", QJsonValue::Double, true },
74 { "sensorHeight", QJsonValue::Double, true },
75 { "imageWidth", QJsonValue::Double, true },
76 { "imageHeight", QJsonValue::Double, true },
77 { "focalLength", QJsonValue::Double, true },
78 { "landscape", QJsonValue::Bool, true },
79 { "fixedOrientation", QJsonValue::Bool, true },
80 { "minTriggerInterval", QJsonValue::Double, true },
81 { "deprecatedTranslatedName", QJsonValue::String, true },
82 };
83 const QJsonArray cameraInfo = jsonObject["cameraMetaData"].toArray();
84 for (const QJsonValue &jsonValue : cameraInfo) {
85 if (!jsonValue.isObject()) {
86 qCWarning(CameraMetaDataLog) << "Entry in CameraMetaData array is not object";
87 return cameraList;
88 }
89
90 const QJsonObject obj = jsonValue.toObject();
91 if (!JsonParsing::validateKeysStrict(obj, cameraKeyInfoList, errorString)) {
92 qCWarning(CameraMetaDataLog) << errorString;
93 return cameraList;
94 }
95
96 const QString canonicalName = obj["canonicalName"].toString();
97 const QString brand = obj["brand"].toString();
98 const QString model = obj["model"].toString();
99 const double sensorWidth = obj["sensorWidth"].toDouble();
100 const double sensorHeight = obj["sensorHeight"].toDouble();
101 const double imageWidth = obj["imageWidth"].toDouble();
102 const double imageHeight = obj["imageHeight"].toDouble();
103 const double focalLength = obj["focalLength"].toDouble();
104 const bool landscape = obj["landscape"].toBool();
105 const bool fixedOrientation = obj["fixedOrientation"].toBool();
106 const double minTriggerInterval = obj["minTriggerInterval"].toDouble();
107 const QString deprecatedTranslatedName = obj["deprecatedTranslatedName"].toString();
108
109 CameraMetaData *metaData = new CameraMetaData(
113 cameraList.append(metaData);
114 }
115
116 return cameraList;
117}
QString errorString
#define QGC_LOGGING_CATEGORY(name, categoryStr)
Set of meta data which describes a camera available on the vehicle.
const double focalLength
Focal length in millimeters.
const QString brand
Camera brand. Used for grouping.
const double imageWidth
Image size in pixels.
const QString deprecatedTranslatedName
static QList< CameraMetaData * > parseCameraMetaData()
const double imageHeight
Image size in pixels.
const bool fixedOrientation
true: camera is in fixed orientation
const QString model
Camerar model.
const double minTriggerInterval
Minimum time in seconds between each photo taken, 0 for not specified.
const QString canonicalName
Canonical name saved in plan files. Not translated.
const bool landscape
true: camera is in landscape orientation
const double sensorWidth
Sensor size in millimeters.
const double sensorHeight
Sensor size in millimeters.
constexpr const char * jsonFileTypeKey
Definition JsonParsing.h:13
QJsonObject openInternalQGCJsonFile(const QString &jsonFilename, const QString &expectedFileType, int minSupportedVersion, int maxSupportedVersion, int &version, QString &errorString, const QStringList &defaultTranslateKeys, const QStringList &defaultArrayIDKeys)
bool validateKeysStrict(const QJsonObject &jsonObject, const QList< KeyValidateInfo > &keyInfo, QString &errorString)
Validates keys like validateKeys but also rejects any keys not listed in keyInfo.
constexpr const char * jsonVersionKey
Definition JsonParsing.h:12