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