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