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