ISMRMRD
ISMRM Raw Data Format
Loading...
Searching...
No Matches
xml.h
Go to the documentation of this file.
1
6#ifndef ISMRMRDXML_H
7#define ISMRMRDXML_H
8
9#include "ismrmrd/export.h"
10#include "ismrmrd.h"
11#include <cstddef>
12#include <new> //For std::badalloc
13#include <stdexcept> //For std::length_error
14#include <cstdint>
15#include <stdio.h>
16#include <string.h>
17#include <iostream>
18#include <string>
19#include <vector>
20#include <array>
21
35namespace ISMRMRD
36{
37
38 template <typename T> class Optional
39 {
40 public:
41 Optional()
42 : present_(false)
43 {
44
45 }
46
47 Optional(const T&v) {
48 present_ = true;
49 value_ = v;
50 }
51
52 Optional& operator=(const Optional& o) {
53 present_ = o.present_;
54 if (present_)
55 value_ = o.value_;
56 return *this;
57 }
58
59 Optional& operator=(const T& v) {
60 present_ = true;
61 value_ = v;
62 return *this;
63 }
64
65 T* operator->() {
66 return &value_;
67 }
68
69 T& operator*() {
70 return value_;
71 }
72
73 const T* operator->() const {
74 return &value_;
75 }
76
77 const T& operator*() const {
78 return value_;
79 }
80
81 operator bool() const {
82 return present_;
83 }
84
85 bool is_present() const {
86 return present_;
87 }
88
89 bool has_value() const noexcept {
90 return present_;
91 }
92
93
94 T &value() &{
95 if (!present_) {
96 throw std::runtime_error("Access optional value, which has not been set");
97 }
98 return value_;
99 }
100
101
102 const T &value() const &{
103 if (!present_) {
104 throw std::runtime_error("Access optional value, which has not been set");
105 }
106 return value_;
107 }
108
109 T &&value() &&{
110 if (!present_) {
111 throw std::runtime_error("Access optional value, which has not been set");
112 }
113 return std::move(value_);
114 }
115
116 const T &&value() const &&{
117 if (!present_) {
118 throw std::runtime_error("Access optional value, which has not been set");
119 }
120 return std::move(value_);
121 }
122
123 T &get() & {
124 return this->value();
125 }
126
127 T&& get()&&{
128 return this->value();
129 }
130 const T &get() const & {
131 return this->value();
132 }
133
134 const T&& get() const &&{
135 return this->value();
136 }
137 template<class U>
138 T value_or(U &&default_value) const &{
139 return bool(*this) ? **this : static_cast<T>(std::forward<U>(default_value));
140 }
141
142 template<class U>
143 T value_or(U &&default_value) &&{
144 return bool(*this) ? std::move(**this) : static_cast<T>(std::forward<U>(default_value));
145 }
146
147 bool operator==(const Optional<T>& other) const {
148 if (this->present_ && other.present_) return this->get() == *other;
149 if ((!this->present_) && (!other.present_)) return true;
150 return false;
151 }
152
153 bool operator==(const T& val) const {
154 if (this->present_) return this->get() == val;
155 return false;
156 }
157
158
159 T& operator()() {
160 return value();
161}
162
163 void set(const T& v) {
164 present_ = true;
165 value_ = v;
166 }
167
168 protected:
169 bool present_;
170 T value_;
171
172 };
173
175 {
176 float x;
177 float y;
178 float z;
179 };
180
182 {
183 Optional<std::string> patientName;
184 Optional<float> patientWeight_kg;
185 Optional<float> patientHeight_m;
186 Optional<std::string> patientID;
187 Optional<std::string> patientBirthdate;
188 Optional<std::string> patientGender;
189 };
190
192 {
193
194 Optional<std::string> studyDate;
195 Optional<std::string> studyTime;
196 Optional<std::string> studyID;
197 Optional<std::int64_t> accessionNumber;
198 Optional<std::string> referringPhysicianName;
199 Optional<std::string> studyDescription;
200 Optional<std::string> studyInstanceUID;
201 Optional<std::string> bodyPartExamined;
202 };
203
205 {
206
207 std::string dependencyType;
208 std::string measurementID;
209 };
210
212 {
213 std::string referencedSOPInstanceUID;
214 };
215
217 {
218 Optional<std::string> measurementID;
219 Optional<std::string> seriesDate;
220 Optional<std::string> seriesTime;
221 std::string patientPosition;
222 Optional<threeDimensionalFloat> relativeTablePosition;
223 Optional<std::int64_t> initialSeriesNumber;
224 Optional<std::string> protocolName;
225 Optional<std::string> sequenceName;
226 Optional<std::string> seriesDescription;
227 std::vector<MeasurementDependency> measurementDependency;
228 Optional<std::string> seriesInstanceUIDRoot;
229 Optional<std::string> frameOfReferenceUID;
230 std::vector<ReferencedImageSequence> referencedImageSequence;
231 };
232
234 {
235 std::uint16_t coilNumber;
236 std::string coilName;
237 };
238
240 {
241 Optional<std::string> systemVendor;
242 Optional<std::string> systemModel;
243 Optional<float> systemFieldStrength_T;
244 Optional<float> relativeReceiverNoiseBandwidth;
245 Optional<std::uint16_t> receiverChannels;
246 std::vector<CoilLabel> coilLabel;
247 Optional<std::string> institutionName;
248 Optional<std::string> stationName;
249 Optional<std::string> deviceID;
250 Optional<std::string> deviceSerialNumber;
251 };
252
253
255 {
256 std::int64_t H1resonanceFrequency_Hz;
257 };
258
260 {
261 MatrixSize()
262 : x(1)
263 , y(1)
264 , z(1)
265 {
266
267 }
268
269 MatrixSize(std::uint16_t x, std::uint16_t y)
270 : x(x)
271 , y(y)
272 , z(1)
273 {
274
275 }
276
277 MatrixSize(std::uint16_t x, std::uint16_t y, std::uint16_t z)
278 : x(x)
279 , y(y)
280 , z(z)
281 {
282
283 }
284
285 std::uint16_t x;
286 std::uint16_t y;
287 std::uint16_t z;
288 };
289
291 {
292 float x;
293 float y;
294 float z;
295 };
296
298 {
299 MatrixSize matrixSize;
300 FieldOfView_mm fieldOfView_mm;
301 };
302
303
304 struct Limit
305 {
306 Limit()
307 : minimum(0)
308 , maximum(0)
309 , center(0)
310 {
311
312 }
313
314 Limit(std::uint16_t minimum, std::uint16_t maximum, std::uint16_t center)
315 : minimum(minimum)
316 , maximum(maximum)
317 , center(center)
318 {
319
320 }
321
322 std::uint16_t minimum;
323 std::uint16_t maximum;
324 std::uint16_t center;
325 };
326
328 {
329 Optional<Limit> kspace_encoding_step_0;
330 Optional<Limit> kspace_encoding_step_1;
331 Optional<Limit> kspace_encoding_step_2;
332 Optional<Limit> average;
333 Optional<Limit> slice;
334 Optional<Limit> contrast;
335 Optional<Limit> phase;
336 Optional<Limit> repetition;
337 Optional<Limit> set;
338 Optional<Limit> segment;
339 std::array<Optional<Limit>,ISMRMRD_USER_INTS> user;
340 };
341
342
344 {
345 std::string name;
346 std::int64_t value;
347 };
348
350 {
351 std::string name;
352 double value;
353 };
354
356 {
357 std::string name;
358 std::string value;
359 };
360
362 {
363 std::vector<UserParameterLong> userParameterLong;
364 std::vector<UserParameterDouble> userParameterDouble;
365 std::vector<UserParameterString> userParameterString;
366 std::vector<UserParameterString> userParameterBase64;
367 };
368
370 {
371 std::string identifier;
372 std::vector<UserParameterLong> userParameterLong;
373 std::vector<UserParameterDouble> userParameterDouble;
374 std::vector<UserParameterString> userParameterString;
375 Optional<std::string> comment;
376 };
377
379 {
380 std::uint16_t kspace_encoding_step_1;
381 std::uint16_t kspace_encoding_step_2;
382 };
383
384
385 enum class TrajectoryType {
386 CARTESIAN,
387 EPI,
388 RADIAL,
389 GOLDENANGLE,
390 SPIRAL,
391 OTHER
392 };
393
394
395
396 enum class MultibandCalibrationType {
397 SEPARABLE2D,
398 FULL3D,
399 OTHER
400 };
401
403 std::vector<float> dZ;
404 };
405
406 struct Multiband{
407 std::vector<MultibandSpacing> spacing;
408 float deltaKz;
409 std::uint32_t multiband_factor;
410 MultibandCalibrationType calibration;
411 std::uint64_t calibration_encoding;
412 };
413
415 {
416 AccelerationFactor accelerationFactor;
417 Optional<std::string> calibrationMode;
418 Optional<std::string> interleavingDimension;
419 Optional<Multiband> multiband;
420 };
421
422 struct Encoding
423 {
424 EncodingSpace encodedSpace;
425 EncodingSpace reconSpace;
426 EncodingLimits encodingLimits;
427 TrajectoryType trajectory;
428 Optional<TrajectoryDescription> trajectoryDescription;
429 Optional<ParallelImaging> parallelImaging;
430 Optional<std::int64_t> echoTrainLength;
431 };
432
434 //In patient coordinate system. Unit vector
435 float rl;
436 float ap;
437 float fh;
438 };
439
440 enum class DiffusionDimension {
441 AVERAGE,
442 CONTRAST,
443 PHASE,
444 REPETITION,
445 SET,
446 SEGMENT,
447 USER_0,
448 USER_1,
449 USER_2,
450 USER_3,
451 USER_4,
452 USER_5,
453 USER_6,
454 USER_7
455 };
456
457 struct Diffusion {
458 float bvalue;
459 GradientDirection gradientDirection;
460 };
461
463 {
467 Optional<std::vector<float> > flipAngle_deg;
468 Optional<std::string> sequence_type;
469 Optional<std::vector<float> > echo_spacing;
470 Optional<DiffusionDimension> diffusionDimension;
472 Optional<std::string> diffusionScheme;
473 };
474
475 enum class WaveformType {
476 ECG,
477 PULSE,
478 RESPIRATORY,
479 TRIGGER,
480 GRADIENTWAVEFORM,
481 OTHER
482 };
483
484
486 std::string waveformName;
487 WaveformType waveformType;
488 Optional<UserParameters> userParameters;
489 };
490
492 {
494 Optional<SubjectInformation> subjectInformation;
495 Optional<StudyInformation> studyInformation;
496 Optional<MeasurementInformation> measurementInformation;
497 Optional<AcquisitionSystemInformation> acquisitionSystemInformation;
498 ExperimentalConditions experimentalConditions;
499 std::vector<Encoding> encoding;
500 Optional<SequenceParameters> sequenceParameters;
501 Optional<UserParameters> userParameters;
502 std::vector<WaveformInformation> waveformInformation;
503 };
504
505
506 EXPORTISMRMRD void deserialize(const char* xml, IsmrmrdHeader& h);
507 EXPORTISMRMRD void serialize(const IsmrmrdHeader& h, std::ostream& o);
508
509 EXPORTISMRMRD std::ostream& operator<<(std::ostream & os, const IsmrmrdHeader&);
510
511 EXPORTISMRMRD bool operator==(const IsmrmrdHeader&, const IsmrmrdHeader&);
512 EXPORTISMRMRD bool operator!=(const IsmrmrdHeader &lhs, const IsmrmrdHeader &rhs);
513 EXPORTISMRMRD bool operator==(const SubjectInformation &lhs, const SubjectInformation &rhs);
514 EXPORTISMRMRD bool operator!=(const SubjectInformation &lhs, const SubjectInformation &rhs);
515 EXPORTISMRMRD bool operator==(const StudyInformation &lhs, const StudyInformation &rhs);
516 EXPORTISMRMRD bool operator!=(const StudyInformation &lhs, const StudyInformation &rhs);
517 EXPORTISMRMRD bool operator==(const ReferencedImageSequence &lhs, const ReferencedImageSequence &rhs);
518 EXPORTISMRMRD bool operator!=(const ReferencedImageSequence &lhs, const ReferencedImageSequence &rhs);
519 EXPORTISMRMRD bool operator==(const MeasurementInformation &lhs, const MeasurementInformation &rhs);
520 EXPORTISMRMRD bool operator!=(const MeasurementInformation &lhs, const MeasurementInformation &rhs);
521 EXPORTISMRMRD bool operator==(const CoilLabel &lhs, const CoilLabel &rhs);
522 EXPORTISMRMRD bool operator!=(const CoilLabel &lhs, const CoilLabel &rhs);
523 EXPORTISMRMRD bool operator==(const AcquisitionSystemInformation &lhs, const AcquisitionSystemInformation &rhs);
524 EXPORTISMRMRD bool operator!=(const AcquisitionSystemInformation &lhs, const AcquisitionSystemInformation &rhs);
525 EXPORTISMRMRD bool operator==(const ExperimentalConditions &lhs, const ExperimentalConditions &rhs);
526 EXPORTISMRMRD bool operator!=(const ExperimentalConditions &lhs, const ExperimentalConditions &rhs);
527 EXPORTISMRMRD bool operator==(const MatrixSize &lhs, const MatrixSize &rhs);
528 EXPORTISMRMRD bool operator!=(const MatrixSize &lhs, const MatrixSize &rhs);
529 EXPORTISMRMRD bool operator==(const FieldOfView_mm &lhs, const FieldOfView_mm &rhs);
530 EXPORTISMRMRD bool operator!=(const FieldOfView_mm &lhs, const FieldOfView_mm &rhs);
531 EXPORTISMRMRD bool operator==(const EncodingSpace &lhs, const EncodingSpace &rhs);
532 EXPORTISMRMRD bool operator!=(const EncodingSpace &lhs, const EncodingSpace &rhs);
533 EXPORTISMRMRD bool operator==(const Limit &lhs, const Limit &rhs);
534 EXPORTISMRMRD bool operator!=(const Limit &lhs, const Limit &rhs);
535 EXPORTISMRMRD bool operator==(const EncodingLimits &lhs, const EncodingLimits &rhs);
536 EXPORTISMRMRD bool operator!=(const EncodingLimits &lhs, const EncodingLimits &rhs);
537 EXPORTISMRMRD bool operator==(const UserParameterLong &lhs, const UserParameterLong &rhs);
538 EXPORTISMRMRD bool operator!=(const UserParameterLong &lhs, const UserParameterLong &rhs);
539 EXPORTISMRMRD bool operator==(const UserParameterDouble &lhs, const UserParameterDouble &rhs);
540 EXPORTISMRMRD bool operator!=(const UserParameterDouble &lhs, const UserParameterDouble &rhs);
541 EXPORTISMRMRD bool operator==(const UserParameterString &lhs, const UserParameterString &rhs);
542 EXPORTISMRMRD bool operator!=(const UserParameterString &lhs, const UserParameterString &rhs);
543 EXPORTISMRMRD bool operator==(const UserParameters &lhs, const UserParameters &rhs);
544 EXPORTISMRMRD bool operator!=(const UserParameters &lhs, const UserParameters &rhs);
545 EXPORTISMRMRD bool operator==(const TrajectoryDescription &lhs, const TrajectoryDescription &rhs);
546 EXPORTISMRMRD bool operator!=(const TrajectoryDescription &lhs, const TrajectoryDescription &rhs);
547 EXPORTISMRMRD bool operator==(const AccelerationFactor &lhs, const AccelerationFactor &rhs);
548 EXPORTISMRMRD bool operator!=(const AccelerationFactor &lhs, const AccelerationFactor &rhs);
549 EXPORTISMRMRD bool operator==(const ParallelImaging &lhs, const ParallelImaging &rhs);
550 EXPORTISMRMRD bool operator!=(const ParallelImaging &lhs, const ParallelImaging &rhs);
551 EXPORTISMRMRD bool operator==(const Multiband &lhs, const Multiband &rhs);
552 EXPORTISMRMRD bool operator!=(const Multiband &lhs, const Multiband &rhs);
553 EXPORTISMRMRD bool operator==(const MultibandSpacing &lhs, const MultibandSpacing &rhs);
554 EXPORTISMRMRD bool operator!=(const MultibandSpacing &lhs, const MultibandSpacing &rhs);
555 EXPORTISMRMRD bool operator==(const Encoding &lhs, const Encoding &rhs);
556 EXPORTISMRMRD bool operator!=(const Encoding &lhs, const Encoding &rhs);
557 EXPORTISMRMRD bool operator==(const SequenceParameters &lhs, const SequenceParameters &rhs);
558 EXPORTISMRMRD bool operator!=(const SequenceParameters &lhs, const SequenceParameters &rhs);
559 EXPORTISMRMRD bool operator==(const WaveformInformation &lhs, const WaveformInformation &rhs);
560 EXPORTISMRMRD bool operator!=(const WaveformInformation &lhs, const WaveformInformation &rhs);
561 EXPORTISMRMRD bool operator==(const threeDimensionalFloat &lhs, const threeDimensionalFloat &rhs);
562 EXPORTISMRMRD bool operator!=(const threeDimensionalFloat &lhs, const threeDimensionalFloat &rhs);
563 EXPORTISMRMRD bool operator==(const MeasurementDependency &lhs, const MeasurementDependency &rhs);
564 EXPORTISMRMRD bool operator!=(const MeasurementDependency &lhs, const MeasurementDependency &rhs);
565 EXPORTISMRMRD bool operator==(const GradientDirection &lhs, const GradientDirection &rhs);
566 EXPORTISMRMRD bool operator!=(const GradientDirection &lhs, const GradientDirection &rhs);
567 EXPORTISMRMRD bool operator==(const Diffusion &lhs, const Diffusion &rhs);
568 EXPORTISMRMRD bool operator!=(const Diffusion &lhs, const Diffusion &rhs);
569
570
573}
574
575#endif //ISMRMRDXML_H
Definition xml.h:39
Definition xml.h:379
Definition xml.h:234
Definition xml.h:457
Definition xml.h:423
Definition xml.h:328
Definition xml.h:298
Definition xml.h:291
Definition xml.h:433
Definition xml.h:492
Definition xml.h:305
Definition xml.h:260
Definition xml.h:205
Definition xml.h:406
Definition xml.h:402
Definition xml.h:415
Definition xml.h:463
Definition xml.h:192
Definition xml.h:182
Definition xml.h:370
Definition xml.h:350
Definition xml.h:344
Definition xml.h:356
Definition xml.h:362
Definition xml.h:485
Definition xml.h:175