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 "JsonHelper.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
40CameraMetaData::~CameraMetaData()
41{
42 qCDebug(CameraMetaDataLog) << this;
43}
44
45QList<CameraMetaData*> CameraMetaData::parseCameraMetaData()
46{
47 QList<CameraMetaData*> cameraList;
48
49 QString errorString;
50 int version = 0;
51 const QJsonObject jsonObject = JsonHelper::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<JsonHelper::KeyValidateInfo> rootKeyInfoList = {
58 { "cameraMetaData", QJsonValue::Array, true }
59 };
60 if (!JsonHelper::validateKeys(jsonObject, rootKeyInfoList, errorString)) {
61 qCWarning(CameraMetaDataLog) << errorString;
62 return cameraList;
63 }
64
65 static const QList<JsonHelper::KeyValidateInfo> cameraKeyInfoList = {
66 { "canonicalName", QJsonValue::String, true },
67 { "brand", QJsonValue::String, true },
68 { "model", QJsonValue::String, true },
69 { "sensorWidth", QJsonValue::Double, true },
70 { "sensorHeight", QJsonValue::Double, true },
71 { "imageWidth", QJsonValue::Double, true },
72 { "imageHeight", QJsonValue::Double, true },
73 { "focalLength", QJsonValue::Double, true },
74 { "landscape", QJsonValue::Bool, true },
75 { "fixedOrientation", QJsonValue::Bool, true },
76 { "minTriggerInterval", QJsonValue::Double, true },
77 { "deprecatedTranslatedName", QJsonValue::String, true },
78 };
79 const QJsonArray cameraInfo = jsonObject["cameraMetaData"].toArray();
80 for (const QJsonValue &jsonValue : cameraInfo) {
81 if (!jsonValue.isObject()) {
82 qCWarning(CameraMetaDataLog) << "Entry in CameraMetaData array is not object";
83 return cameraList;
84 }
85
86 const QJsonObject obj = jsonValue.toObject();
87 if (!JsonHelper::validateKeys(obj, cameraKeyInfoList, errorString)) {
88 qCWarning(CameraMetaDataLog) << errorString;
89 return cameraList;
90 }
91
92 const QString canonicalName = obj["canonicalName"].toString();
93 const QString brand = obj["brand"].toString();
94 const QString model = obj["model"].toString();
95 const double sensorWidth = obj["sensorWidth"].toDouble();
96 const double sensorHeight = obj["sensorHeight"].toDouble();
97 const double imageWidth = obj["imageWidth"].toDouble();
98 const double imageHeight = obj["imageHeight"].toDouble();
99 const double focalLength = obj["focalLength"].toDouble();
100 const bool landscape = obj["landscape"].toBool();
101 const bool fixedOrientation = obj["fixedOrientation"].toBool();
102 const double minTriggerInterval = obj["minTriggerInterval"].toDouble();
103 const QString deprecatedTranslatedName = obj["deprecatedTranslatedName"].toString();
104
105 CameraMetaData *metaData = new CameraMetaData(
106 canonicalName, brand, model, sensorWidth, sensorHeight,
107 imageWidth, imageHeight, focalLength, landscape,
108 fixedOrientation, minTriggerInterval, deprecatedTranslatedName);
109 cameraList.append(metaData);
110 }
111
112 return cameraList;
113}
QString errorString
#define QGC_LOGGING_CATEGORY(name, categoryStr)
Set of meta data which describes a camera available on the vehicle.
QJsonObject openInternalQGCJsonFile(const QString &jsonFilename, const QString &expectedFileType, int minSupportedVersion, int maxSupportedVersion, int &version, QString &errorString)
returned error string if validation fails
bool validateKeys(const QJsonObject &jsonObject, const QList< KeyValidateInfo > &keyInfo, QString &errorString)