v2.0.0
Loading...
Searching...
No Matches
bids_coordinate_system.cpp
Go to the documentation of this file.
1//=============================================================================================================
34
35//=============================================================================================================
36// INCLUDES
37//=============================================================================================================
38
40
41//=============================================================================================================
42// QT INCLUDES
43//=============================================================================================================
44
45#include <QFile>
46#include <QJsonDocument>
47#include <QJsonObject>
48#include <QDebug>
49
50//=============================================================================================================
51// USED NAMESPACES
52//=============================================================================================================
53
54using namespace BIDSLIB;
55
56//=============================================================================================================
57// STATIC METHODS
58//=============================================================================================================
59
61{
63
64 QFile file(sFilePath);
65 if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
66 qWarning() << "[BidsCoordinateSystem::readJson] Cannot open" << sFilePath;
67 return cs;
68 }
69
70 QJsonParseError error;
71 QJsonDocument doc = QJsonDocument::fromJson(file.readAll(), &error);
72 file.close();
73
74 if(error.error != QJsonParseError::NoError) {
75 qWarning() << "[BidsCoordinateSystem::readJson] Parse error in" << sFilePath
76 << ":" << error.errorString();
77 return cs;
78 }
79
80 QJsonObject json = doc.object();
81 cs.system = json.value(QStringLiteral("iEEGCoordinateSystem")).toString();
82 cs.units = json.value(QStringLiteral("iEEGCoordinateUnits")).toString();
83 cs.description = json.value(QStringLiteral("iEEGCoordinateSystemDescription")).toString();
84 cs.processingDescription = json.value(QStringLiteral("iEEGCoordinateProcessingDescription")).toString();
85 cs.associatedImagePath = json.value(QStringLiteral("IntendedFor")).toString();
86
87 return cs;
88}
89
90//=============================================================================================================
91
92bool BidsCoordinateSystem::writeJson(const QString& sFilePath,
93 const BidsCoordinateSystem& cs)
94{
95 QJsonObject json;
96
97 json[QStringLiteral("iEEGCoordinateSystem")] = cs.system;
98 json[QStringLiteral("iEEGCoordinateUnits")] = cs.units;
99
100 if(!cs.description.isEmpty())
101 json[QStringLiteral("iEEGCoordinateSystemDescription")] = cs.description;
102 if(!cs.processingDescription.isEmpty())
103 json[QStringLiteral("iEEGCoordinateProcessingDescription")] = cs.processingDescription;
104 if(!cs.associatedImagePath.isEmpty())
105 json[QStringLiteral("IntendedFor")] = cs.associatedImagePath;
106
107 QFile file(sFilePath);
108 if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
109 qWarning() << "[BidsCoordinateSystem::writeJson] Cannot open" << sFilePath << "for writing";
110 return false;
111 }
112
113 file.write(QJsonDocument(json).toJson(QJsonDocument::Indented));
114 file.close();
115 return true;
116}
BidsCoordinateSystem struct — iEEG coordinate system from *_coordsystem.json.
BIDS dataset reading, writing, path construction, and sidecar metadata handling for iEEG/EEG/MEG.
Coordinate system metadata from *_coordsystem.json.
static bool writeJson(const QString &sFilePath, const BidsCoordinateSystem &cs)
Write a BIDS *_coordsystem.json file.
static BidsCoordinateSystem readJson(const QString &sFilePath)
Read a BIDS *_coordsystem.json file.