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  const Optional& operator=(const Optional& o) {
48  present_ = o.present_;
49  if (present_)
50  value_ = o.value_;
51  return *this;
52  }
53 
54  const Optional& operator=(const T& v) {
55  present_ = true;
56  value_ = v;
57  return *this;
58  }
59 
60  const T* operator->() const {
61  return &value_;
62  }
63 
64  const T& operator*() const {
65  return value_;
66  }
67 
68  operator bool() const {
69  return present_;
70  }
71 
72  bool is_present() const {
73  return present_;
74  }
75 
76  T& get() {
77  if (!present_) {
78  throw std::runtime_error("Access optional value, which has not been set");
79  }
80  return value_;
81  }
82 
83  T& operator()() {
84  return get();
85  }
86 
87  void set(const T& v) {
88  present_ = true;
89  value_ = v;
90  }
91 
92  protected:
93  bool present_;
94  T value_;
95 
96  };
97 
99  {
100  Optional<std::string> patientName;
101  Optional<float> patientWeight_kg;
102  Optional<std::string> patientID;
103  Optional<std::string> patientBirthdate;
104  Optional<std::string> patientGender;
105  };
106 
108  {
109  Optional<std::string> studyDate;
110  Optional<std::string> studyTime;
111  Optional<std::string> studyID;
112  Optional<long> accessionNumber;
113  Optional<std::string> referringPhysicianName;
114  Optional<std::string> studyDescription;
115  Optional<std::string> studyInstanceUID;
116  };
117 
119  {
120  std::string dependencyType;
121  std::string measurementID;
122  };
123 
125  {
126  std::string referencedSOPInstanceUID;
127  };
128 
130  {
131  Optional<std::string> measurementID;
132  Optional<std::string> seriesDate;
133  Optional<std::string> seriesTime;
134  std::string patientPosition;
135  Optional<long int> initialSeriesNumber;
136  Optional<std::string> protocolName;
137  Optional<std::string> seriesDescription;
138  std::vector<MeasurementDependency> measurementDependency;
139  Optional<std::string> seriesInstanceUIDRoot;
140  Optional<std::string> frameOfReferenceUID;
141  std::vector<ReferencedImageSequence> referencedImageSequence;
142  };
143 
144  struct CoilLabel
145  {
146  unsigned short coilNumber;
147  std::string coilName;
148  };
149 
151  {
152  Optional<std::string> systemVendor;
153  Optional<std::string> systemModel;
154  Optional<float> systemFieldStrength_T;
155  Optional<float> relativeReceiverNoiseBandwidth;
156  Optional<unsigned short> receiverChannels;
157  std::vector<CoilLabel> coilLabel;
158  Optional<std::string> institutionName;
159  Optional<std::string> stationName;
160  };
161 
162 
164  {
165  long int H1resonanceFrequency_Hz;
166  };
167 
168  struct MatrixSize
169  {
170  MatrixSize()
171  : x(1)
172  , y(1)
173  , z(1)
174  {
175 
176  }
177 
178  MatrixSize(unsigned short x, unsigned short y)
179  : x(x)
180  , y(y)
181  , z(1)
182  {
183 
184  }
185 
186  MatrixSize(unsigned short x, unsigned short y, unsigned short z)
187  : x(x)
188  , y(y)
189  , z(z)
190  {
191 
192  }
193 
194  unsigned short x;
195  unsigned short y;
196  unsigned short z;
197  };
198 
200  {
201  float x;
202  float y;
203  float z;
204  };
205 
207  {
208  MatrixSize matrixSize;
209  FieldOfView_mm fieldOfView_mm;
210  };
211 
212 
213  struct Limit
214  {
215  Limit()
216  : minimum(0)
217  , maximum(0)
218  , center(0)
219  {
220 
221  }
222 
223  Limit(unsigned short minimum, unsigned short maximum, unsigned short center)
224  : minimum(minimum)
225  , maximum(maximum)
226  , center(center)
227  {
228 
229  }
230 
231  unsigned short minimum;
232  unsigned short maximum;
233  unsigned short center;
234  };
235 
237  {
238  Optional<Limit> kspace_encoding_step_0;
239  Optional<Limit> kspace_encoding_step_1;
240  Optional<Limit> kspace_encoding_step_2;
241  Optional<Limit> average;
242  Optional<Limit> slice;
243  Optional<Limit> contrast;
244  Optional<Limit> phase;
245  Optional<Limit> repetition;
246  Optional<Limit> set;
247  Optional<Limit> segment;
248  };
249 
250 
252  {
253  std::string name;
254  long value;
255  };
256 
258  {
259  std::string name;
260  double value;
261  };
262 
264 
265  {
266  std::string name;
267  std::string value;
268  };
269 
271  {
272  std::vector<UserParameterLong> userParameterLong;
273  std::vector<UserParameterDouble> userParameterDouble;
274  std::vector<UserParameterString> userParameterString;
275  std::vector<UserParameterString> userParameterBase64;
276  };
277 
279  {
280  std::string identifier;
281  std::vector<UserParameterLong> userParameterLong;
282  std::vector<UserParameterDouble> userParameterDouble;
283  Optional<std::string> comment;
284  };
285 
287  {
288  unsigned short kspace_encoding_step_1;
289  unsigned short kspace_encoding_step_2;
290  };
291 
293  {
294  AccelerationFactor accelerationFactor;
295  Optional<std::string> calibrationMode;
296  Optional<std::string> interleavingDimension;
297  };
298 
299  enum class TrajectoryType {
300  CARTESIAN,
301  EPI,
302  RADIAL,
303  GOLDENANGLE,
304  SPIRAL,
305  OTHER
306  };
307 
308  struct Encoding
309  {
310  EncodingSpace encodedSpace;
311  EncodingSpace reconSpace;
312  EncodingLimits encodingLimits;
313  TrajectoryType trajectory;
314  Optional<TrajectoryDescription> trajectoryDescription;
315  Optional<ParallelImaging> parallelImaging;
316  Optional<long> echoTrainLength;
317  };
318 
320  {
324  Optional<std::vector<float> > flipAngle_deg;
325  Optional<std::string> sequence_type;
326  Optional<std::vector<float> > echo_spacing;
327  };
328 
329  enum class WaveformType {
330  ECG,
331  PULSE,
332  RESPIRATORY,
333  TRIGGER,
334  GRADIENTWAVEFORM,
335  OTHER
336  };
337 
338 
340  std::string waveformName;
341  WaveformType waveformType;
342  Optional<UserParameters> userParameters;
343  };
344 
346  {
347  Optional<long> version;
348  Optional<SubjectInformation> subjectInformation;
349  Optional<StudyInformation> studyInformation;
350  Optional<MeasurementInformation> measurementInformation;
351  Optional<AcquisitionSystemInformation> acquisitionSystemInformation;
352  ExperimentalConditions experimentalConditions;
353  std::vector<Encoding> encoding;
354  Optional<SequenceParameters> sequenceParameters;
355  Optional<UserParameters> userParameters;
356  std::vector<WaveformInformation> waveformInformation;
357  };
358 
359 
360 
361  EXPORTISMRMRD void deserialize(const char* xml, IsmrmrdHeader& h);
362  EXPORTISMRMRD void serialize(const IsmrmrdHeader& h, std::ostream& o);
363 }
364 
366 #endif //ISMRMRDXML_H
Definition: xml.h:292
Definition: xml.h:168
Definition: xml.h:129
Definition: xml.h:213
Definition: xml.h:286
Definition: xml.h:270
Definition: xml.h:107
Definition: xml.h:308
Definition: xml.h:163
Definition: xml.h:345
Definition: xml.h:278
Definition: xml.h:263
Definition: xml.h:236
Definition: dataset.h:17
Definition: xml.h:257
Definition: xml.h:319
Definition: xml.h:118
Definition: xml.h:33
Definition: xml.h:251
Definition: xml.h:199
Definition: xml.h:144
Definition: xml.h:339
Definition: xml.h:206
Definition: xml.h:98