ISMRMRD
ISMRM Raw Data Format
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 
11 #include <cstddef>
12 #include <new> //For std::badalloc
13 #include <stdexcept> //For std::length_error
14 #include <stdio.h>
15 #include <string.h>
16 #include <iostream>
17 #include <string>
18 #include <vector>
19 
33 namespace ISMRMRD
34 {
35 
36  template <typename T> class Optional
37  {
38  public:
39  Optional()
40  : present_(false)
41  {
42 
43  }
44 
45  Optional(const T&v) {
46  present_ = true;
47  value_ = v;
48  }
49 
50  Optional& operator=(const Optional& o) {
51  present_ = o.present_;
52  if (present_)
53  value_ = o.value_;
54  return *this;
55  }
56 
57  Optional& operator=(const T& v) {
58  present_ = true;
59  value_ = v;
60  return *this;
61  }
62 
63  T* operator->() {
64  return &value_;
65  }
66 
67  T& operator*() {
68  return value_;
69  }
70 
71  const T* operator->() const {
72  return &value_;
73  }
74 
75  const T& operator*() const {
76  return value_;
77  }
78 
79  operator bool() const {
80  return present_;
81  }
82 
83  bool is_present() const {
84  return present_;
85  }
86 
87  bool has_value() const noexcept {
88  return present_;
89  }
90 
91 
92  T &value() &{
93  if (!present_) {
94  throw std::runtime_error("Access optional value, which has not been set");
95  }
96  return value_;
97  }
98 
99 
100  const T &value() const &{
101  if (!present_) {
102  throw std::runtime_error("Access optional value, which has not been set");
103  }
104  return value_;
105  }
106 
107  T &&value() &&{
108  if (!present_) {
109  throw std::runtime_error("Access optional value, which has not been set");
110  }
111  return std::move(value_);
112  }
113 
114  const T &&value() const &&{
115  if (!present_) {
116  throw std::runtime_error("Access optional value, which has not been set");
117  }
118  return std::move(value_);
119  }
120 
121  T &get() & {
122  return this->value();
123  }
124 
125  T&& get()&&{
126  return this->value();
127  }
128  const T &get() const & {
129  return this->value();
130  }
131 
132  const T&& get() const &&{
133  return this->value();
134  }
135  template<class U>
136  T value_or(U &&default_value) const &{
137  return bool(*this) ? **this : static_cast<T>(std::forward<U>(default_value));
138  }
139 
140  template<class U>
141  T value_or(U &&default_value) &&{
142  return bool(*this) ? std::move(**this) : static_cast<T>(std::forward<U>(default_value));
143  }
144 
145 
146 
147 
148  T& operator()() {
149  return value();
150 }
151 
152  void set(const T& v) {
153  present_ = true;
154  value_ = v;
155  }
156 
157  protected:
158  bool present_;
159  T value_;
160 
161  };
162 
164  {
165  float x;
166  float y;
167  float z;
168  };
169 
171  {
172  Optional<std::string> patientName;
173  Optional<float> patientWeight_kg;
174  Optional<std::string> patientID;
175  Optional<std::string> patientBirthdate;
176  Optional<std::string> patientGender;
177  };
178 
180  {
181  Optional<std::string> studyDate;
182  Optional<std::string> studyTime;
183  Optional<std::string> studyID;
184  Optional<long> accessionNumber;
185  Optional<std::string> referringPhysicianName;
186  Optional<std::string> studyDescription;
187  Optional<std::string> studyInstanceUID;
188  };
189 
191  {
192  std::string dependencyType;
193  std::string measurementID;
194  };
195 
197  {
198  std::string referencedSOPInstanceUID;
199  };
200 
202  {
203  Optional<std::string> measurementID;
204  Optional<std::string> seriesDate;
205  Optional<std::string> seriesTime;
206  std::string patientPosition;
207  Optional<threeDimensionalFloat> relativeTablePosition;
208  Optional<long int> initialSeriesNumber;
209  Optional<std::string> protocolName;
210  Optional<std::string> seriesDescription;
211  std::vector<MeasurementDependency> measurementDependency;
212  Optional<std::string> seriesInstanceUIDRoot;
213  Optional<std::string> frameOfReferenceUID;
214  std::vector<ReferencedImageSequence> referencedImageSequence;
215  };
216 
217  struct CoilLabel
218  {
219  unsigned short coilNumber;
220  std::string coilName;
221  };
222 
224  {
225  Optional<std::string> systemVendor;
226  Optional<std::string> systemModel;
227  Optional<float> systemFieldStrength_T;
228  Optional<float> relativeReceiverNoiseBandwidth;
229  Optional<unsigned short> receiverChannels;
230  std::vector<CoilLabel> coilLabel;
231  Optional<std::string> institutionName;
232  Optional<std::string> stationName;
233  Optional<std::string> deviceID;
234  };
235 
236 
238  {
239  long int H1resonanceFrequency_Hz;
240  };
241 
242  struct MatrixSize
243  {
244  MatrixSize()
245  : x(1)
246  , y(1)
247  , z(1)
248  {
249 
250  }
251 
252  MatrixSize(unsigned short x, unsigned short y)
253  : x(x)
254  , y(y)
255  , z(1)
256  {
257 
258  }
259 
260  MatrixSize(unsigned short x, unsigned short y, unsigned short z)
261  : x(x)
262  , y(y)
263  , z(z)
264  {
265 
266  }
267 
268  unsigned short x;
269  unsigned short y;
270  unsigned short z;
271  };
272 
274  {
275  float x;
276  float y;
277  float z;
278  };
279 
281  {
282  MatrixSize matrixSize;
283  FieldOfView_mm fieldOfView_mm;
284  };
285 
286 
287  struct Limit
288  {
289  Limit()
290  : minimum(0)
291  , maximum(0)
292  , center(0)
293  {
294 
295  }
296 
297  Limit(unsigned short minimum, unsigned short maximum, unsigned short center)
298  : minimum(minimum)
299  , maximum(maximum)
300  , center(center)
301  {
302 
303  }
304 
305  unsigned short minimum;
306  unsigned short maximum;
307  unsigned short center;
308  };
309 
311  {
312  Optional<Limit> kspace_encoding_step_0;
313  Optional<Limit> kspace_encoding_step_1;
314  Optional<Limit> kspace_encoding_step_2;
315  Optional<Limit> average;
316  Optional<Limit> slice;
317  Optional<Limit> contrast;
318  Optional<Limit> phase;
319  Optional<Limit> repetition;
320  Optional<Limit> set;
321  Optional<Limit> segment;
322  };
323 
324 
326  {
327  std::string name;
328  long value;
329  };
330 
332  {
333  std::string name;
334  double value;
335  };
336 
338 
339  {
340  std::string name;
341  std::string value;
342  };
343 
345  {
346  std::vector<UserParameterLong> userParameterLong;
347  std::vector<UserParameterDouble> userParameterDouble;
348  std::vector<UserParameterString> userParameterString;
349  std::vector<UserParameterString> userParameterBase64;
350  };
351 
353  {
354  std::string identifier;
355  std::vector<UserParameterLong> userParameterLong;
356  std::vector<UserParameterDouble> userParameterDouble;
357  Optional<std::string> comment;
358  };
359 
361  {
362  unsigned short kspace_encoding_step_1;
363  unsigned short kspace_encoding_step_2;
364  };
365 
367  {
368  AccelerationFactor accelerationFactor;
369  Optional<std::string> calibrationMode;
370  Optional<std::string> interleavingDimension;
371  };
372 
373  enum class TrajectoryType {
374  CARTESIAN,
375  EPI,
376  RADIAL,
377  GOLDENANGLE,
378  SPIRAL,
379  OTHER
380  };
381 
382  struct Encoding
383  {
384  EncodingSpace encodedSpace;
385  EncodingSpace reconSpace;
386  EncodingLimits encodingLimits;
387  TrajectoryType trajectory;
388  Optional<TrajectoryDescription> trajectoryDescription;
389  Optional<ParallelImaging> parallelImaging;
390  Optional<long> echoTrainLength;
391  };
392 
394  {
398  Optional<std::vector<float> > flipAngle_deg;
399  Optional<std::string> sequence_type;
400  Optional<std::vector<float> > echo_spacing;
401  };
402 
403  enum class WaveformType {
404  ECG,
405  PULSE,
406  RESPIRATORY,
407  TRIGGER,
408  GRADIENTWAVEFORM,
409  OTHER
410  };
411 
412 
414  std::string waveformName;
415  WaveformType waveformType;
416  Optional<UserParameters> userParameters;
417  };
418 
420  {
421  Optional<long> version;
422  Optional<SubjectInformation> subjectInformation;
423  Optional<StudyInformation> studyInformation;
424  Optional<MeasurementInformation> measurementInformation;
425  Optional<AcquisitionSystemInformation> acquisitionSystemInformation;
426  ExperimentalConditions experimentalConditions;
427  std::vector<Encoding> encoding;
428  Optional<SequenceParameters> sequenceParameters;
429  Optional<UserParameters> userParameters;
430  std::vector<WaveformInformation> waveformInformation;
431  };
432 
433 
434  EXPORTISMRMRD void deserialize(const char* xml, IsmrmrdHeader& h);
435  EXPORTISMRMRD void serialize(const IsmrmrdHeader& h, std::ostream& o);
436 
439 }
440 
441 #endif //ISMRMRDXML_H
Definition: xml.h:37
Definition: xml.h:361
Definition: xml.h:218
Definition: xml.h:383
Definition: xml.h:311
Definition: xml.h:281
Definition: xml.h:238
Definition: xml.h:274
Definition: xml.h:420
Definition: xml.h:288
Definition: xml.h:243
Definition: xml.h:191
Definition: xml.h:202
Definition: xml.h:367
Definition: xml.h:394
Definition: xml.h:180
Definition: xml.h:171
Definition: xml.h:353
Definition: xml.h:332
Definition: xml.h:326
Definition: xml.h:339
Definition: xml.h:345
Definition: xml.h:413
Definition: xml.h:164