ODIN
reco.h
1 /***************************************************************************
2  reco.h - Parameters for image reconstruction
3  -------------------
4  begin : Thu May 06 2004
5  copyright : (C) 2000-2021 by Thies H. Jochimsen
6  email : thies@jochimsen.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef RECO_H
19 #define RECO_H
20 
21 #include <tjutils/tjvallist.h>
22 
23 #include <odinpara/protocol.h>
24 
25 
31 // some limits
32 #define MAX_NUMOF_READOUT_SHAPES 10
33 #define MAX_NUMOF_KSPACE_TRAJS 10
34 #define MAX_NUMOF_ADC_WEIGHTING_VECTORS 10
35 
36 #define PROTOCOL_BLOCK_LABEL "Protocol"
37 
44 enum recoFlags {
45  recoLastInChunkBit =1,
46  recoReflectBit =2,
47  recoEpiNavPolarityBit =4,
48  recoAllBits =255
49 };
50 
51 
53 
74 enum recoDim { userdef=0, te, dti, average, cycle, slice, line3d, line, echo, epi, templtype, navigator, freq, channel, readout, repetition, n_recoDims};
75 static const char* recoDimLabel[]={"userdef", "te","dti","average","cycle","slice","line3d","line","echo","epi","templtype","navigator","freq","channel","readout","repetition"};
76 AVOID_CC_WARNING(recoDimLabel)
77 static const int n_recoIndexDims=templtype+1; // only the first dims are required for indexing of ADCs, the remaining are used only by odinreco
78 
79 
81 
82 
91 enum templateType {no_template=0, phasecorr_template, fieldmap_template, grappa_template, n_templateTypes};
92 static const char templateTypeChar[]={'N', 'P', 'F', 'G'};
93 
95 
96 
103 enum navigatorType {no_navigator=0, epi_navigator, n_navigatorTypes};
104 static const char navigatorTypeChar[]={'n', 'e'};
105 
106 
108 
109 
114 struct kSpaceCoord {
115 
116  kSpaceCoord() {reset2defaults();}
117 
118  // for STD_list
119  bool operator == (const kSpaceCoord& ri) const;
120  bool operator < (const kSpaceCoord& ri) const;
121 
122 
123  static int string2index(const STD_string& str, recoDim dim);
124  static STD_string index2string(int index, recoDim dim, int numof=0);
125 
126  STD_string printcoord(const unsigned short* numof_cache) const;
127 // friend STD_ostream& operator << (STD_ostream& s,const kSpaceCoord& kcoord) { return s << kcoord.printcoord();}
128  bool parsecoord(const STD_string& str);
129  void reset2defaults();
130 
131  static STD_string print_header(const unsigned short* numof_cache);
132 
133 
134  mutable unsigned int number; // unique index of the ADC
135  unsigned int reps; // number of times this ADC is repeated
136  unsigned short adcSize; // size with oversampling
137  unsigned char channels; // coil channels
138  unsigned short preDiscard; // points to discard at the beginning of an ADC
139  unsigned short postDiscard; // points to discard at the end of an ADC
140  unsigned short concat; // number of concatenated acquisition this ADC is composed of
141  float oversampling; // oversampling factor
142  float relcenter; // relative position of k-space center
143 
144  short readoutIndex; // index of the readout shape to be used for ramp-sampling correction, -1 if none
145  short trajIndex; // index of the used k-space trajectory, -1 if none
146  short weightIndex; // index of the used ADC weighting vector, -1 if none
147  short dtIndex; // index of the dwell time used
148 
149  unsigned short index[n_recoIndexDims]; // multi-dimensional reco index to locate ADC in k-space
150 
151  unsigned char flags; // recoFlags
152 
153 
154 
155  private:
156  friend class LDRkSpaceCoords;
157 
158  static void assign_parsepos(const STD_string& header);
159 
160 
161  static int parsepos_number;
162  static int parsepos_reps;
163  static int parsepos_adcSize;
164  static int parsepos_channels;
165  static int parsepos_preDiscard;
166  static int parsepos_postDiscard;
167  static int parsepos_concat;
168  static int parsepos_oversampling;
169  static int parsepos_relcenter;
170  static int parsepos_readoutIndex;
171  static int parsepos_trajIndex;
172  static int parsepos_weightIndex;
173  static int parsepos_dtIndex;
174  static int parsepos_index[n_recoIndexDims];
175  static int parsepos_lastinchunk;
176  static int parsepos_reflect;
177  static int max_parsepos;
178 
179 };
180 
182 
183 
188 class LDRkSpaceCoords : public LDRbase {
189 
190  enum LDRkSpaceCoords_state {coords_in_list, has_vec_cache, has_vec_alloc};
191 
192  public:
193  LDRkSpaceCoords();
194  ~LDRkSpaceCoords() {clear();}
195 
196  unsigned int size() const {create_vec_cache(); return vec_cache.size();}
197 
198  const kSpaceCoord& operator [] (unsigned int i) const {create_vec_cache(); return *(vec_cache[i]);}
199 
200  void clear(); // clear list before retrieving k-space ordering from sequence
201 
202  LDRkSpaceCoords& append_coord(const kSpaceCoord& coord);
203 
204  private:
205  friend class RecoPars;
206 
207  void create_vec_cache() const;
208 
209  // overwriting virtual functions from LDRbase
210  bool parsevalstring(const STD_string& parstring, const LDRserBase* ser=0);
211  STD_string printvalstring(const LDRserBase* ser=0) const;
212  STD_ostream& print2stream(STD_ostream& os, const LDRserBase& serializer) const;
213  STD_string get_typeInfo(bool parx_equivtype=false) const {return "kSpaceCoords";}
214  LDRbase* create_copy() const {return new LDRkSpaceCoords(*this);}
215 
216  mutable STD_list<kSpaceCoord> coordlist;
217 
218  mutable LDRkSpaceCoords_state state;
219  mutable STD_vector<kSpaceCoord*> vec_cache; // use pointers for better performance
220  mutable unsigned short numof_cache[n_recoIndexDims];
221 };
222 
224 
229 struct RecoValList : public ValList<int> {
230  RecoValList(const STD_string& object_label="unnamedRecoValList", unsigned int repetitions=1) : ValList<int>(object_label,repetitions) {}
231 };
232 
234 
239 class LDRrecoValList : public RecoValList, public LDRbase {
240 
241  public:
242  LDRrecoValList(const STD_string& ldrlabel="unnamedLDRrecoValList");
243  LDRrecoValList(const LDRrecoValList& jdrvl) {LDRrecoValList::operator = (jdrvl);}
244  LDRrecoValList& operator = (const LDRrecoValList& jdrvl);
245 
246  LDRrecoValList& operator = (const RecoValList& rvl); // for assignment from get_recovallist in SeqMethod
247 
248  // overwriting virtual functions from LDRbase
249  bool parsevalstring(const STD_string& parstring, const LDRserBase* ser=0);
250  STD_string printvalstring(const LDRserBase* ser=0) const;
251  STD_ostream& print2stream(STD_ostream& os, const LDRserBase& serializer) const;
252  STD_string get_typeInfo(bool parx_equivtype=false) const {return "RecoValList";}
253  LDRbase* create_copy() const {return new LDRrecoValList(*this);}
254 
255 };
256 
257 
259 
260 
261 
265 class RecoPars : public LDRblock {
266 
267  public:
268 
272  RecoPars(const STD_string& label="unnamedRecoPars");
273 
277  RecoPars(const RecoPars& sr);
278 
283 
287  const Protocol& get_protocol() const {return prot;}
288 
292  const LDRkSpaceCoords& get_kSpaceCoords() const {return kSpaceCoords;}
293 
297  const STD_string& get_DataFormat() const {return DataFormat;}
298 
302  bool is_LittleEndian() const {return LittleEndian;}
303 
307  const STD_string& get_RawFile() const {return RawFile;}
308 
312  unsigned int get_RawHeaderSize() const {return RawHeaderSize;}
313 
317  const fvector& get_RelativeOffset() const {return RelativeOffset;}
318 
322  const STD_string& get_ImageProc() const {return ImageProc;}
323 
327  const dvector& get_DimValues(recoDim dim) const {return DimValues[dim];}
328 
332  fvector get_ChannelScales() const {return ChannelScaling;}
333 
337  double get_DwellTime(unsigned int i) const;
338 
339 
345  int get_NumOfAdcChunks() const;
346 
347 
351  RecoPars& set_DimValues(recoDim dim, const dvector& vals);
352 
353 
357  int append_readout_shape(const fvector& shape, unsigned int dstsize);
358 
362  int append_kspace_traj(const farray& kspace_traj);
363 
367  int append_adc_weight_vec(const cvector& weightvec);
368 
372  int append_dwell_time(double dt);
373 
374 
378  void get_ReadoutShape(unsigned int i, fvector& shape, unsigned int& dstsize) const;
379 
380 
384  unsigned int numof_kSpaceTraj() const;
385 
389  const farray& get_kSpaceTraj(unsigned int i) const;
390 
391 
395  const cvector& get_AdcWeightVector(unsigned int i) const;
396 
397 
403  LONGEST_INT get_TotalNumOfSamples(bool discard=false) const;
404 
408  unsigned int numof_adcs() const {return kSpaceOrdering.size();}
409 
413  const kSpaceCoord& get_kSpaceCoord(unsigned int i) const;
414 
418  RecoPars& set_Recipe(const STD_string& recipe) {Recipe=recipe; return *this;}
419 
423  STD_string get_Recipe() const {return Recipe;}
424 
430  RecoPars& set_PostProc3D(const STD_string& recipe) {PostProc3D=recipe; return *this;}
431 
437  STD_string get_PostProc3D() const {return PostProc3D;}
438 
443  RecoPars& set_PreProc3D(const STD_string& recipe) {PreProc3D=recipe; return *this;}
444 
449  STD_string get_PreProc3D() const {return PreProc3D;}
450 
454  RecoPars& set_CmdLineOpts(const STD_string& opts) {CmdLineOpts=opts; return *this;}
455 
460  STD_string get_CmdLineOpts() const {return CmdLineOpts;}
461 
462 
463  private:
464  friend class SeqAcq;
465  friend class SeqEpiDriverParavision;
466  friend class SeqMethod;
467 
468  void common_init();
469 
470  void reset();
471  void create_cache() const;
472 
473  void append_all_members();
474 
475  Protocol prot;
476 
477  LDRstring DataFormat;
478  LDRbool LittleEndian;
479  LDRstring RawFile;
480  LDRint RawHeaderSize;
481  LDRtriple RelativeOffset;
482  LDRstring ImageProc;
483  LDRfloatArr ChannelScaling;
484  LDRdoubleArr DwellTime;
485  LDRfloatArr ReadoutShape[MAX_NUMOF_READOUT_SHAPES];
486  LDRintArr ReadoutDstSize;
487  LDRfloatArr kSpaceTraj[MAX_NUMOF_KSPACE_TRAJS];
488  LDRcomplexArr AdcWeightVector[MAX_NUMOF_ADC_WEIGHTING_VECTORS];
489  LDRdoubleArr DimValues[n_recoIndexDims];
490  LDRstring Recipe;
491  LDRstring PreProc3D;
492  LDRstring PostProc3D;
493  LDRstring CmdLineOpts;
494 
495  LDRkSpaceCoords kSpaceCoords;
496  LDRrecoValList kSpaceOrdering;
497 
498  mutable STD_vector<int> kSpaceOrdering_cache; // fast cache of ADC indices
499  mutable bool cache_is_up2date;
500 
501 };
502 
503 
504 
507 
508 
509 
513 class CoilSensitivity : public LDRblock {
514 
515  public:
516 
520  CoilSensitivity(const STD_string& label="unnamedCoilSensitivity");
521 
526 
531 
532 
537  CoilSensitivity& set_sensitivity_map(const carray& sens_map, float FOVx, float FOVy, float FOVz);
538 
543  STD_complex get_sensitivity_value(unsigned int channel, float x, float y, float z) const;
544 
548  unsigned int get_numof_channels() const {return SensitivityMap.get_extent()[0];}
549 
550 
551  private:
552  void append_all_members();
553 
554  LDRtriple FOV;
555  LDRcomplexArr SensitivityMap;
556 };
557 
558 
560 
561 
562 
568 #endif
unsigned int get_numof_channels() const
Definition: reco.h:548
CoilSensitivity & set_sensitivity_map(const carray &sens_map, float FOVx, float FOVy, float FOVz)
CoilSensitivity(const CoilSensitivity &cs)
CoilSensitivity & operator=(const CoilSensitivity &cs)
CoilSensitivity(const STD_string &label="unnamedCoilSensitivity")
STD_complex get_sensitivity_value(unsigned int channel, float x, float y, float z) const
STD_string printvalstring(const LDRserBase *ser=0) const
Definition: ldrblock.h:232
STD_ostream & print2stream(STD_ostream &os, const LDRserBase &serializer) const
LDRbase * create_copy() const
Definition: ldrblock.h:233
STD_string get_typeInfo(bool parx_equivtype=false) const
Definition: ldrblock.h:234
bool parsevalstring(const STD_string &, const LDRserBase *ser=0)
Definition: ldrblock.h:230
STD_string get_typeInfo(bool parx_equivtype=false) const
Definition: reco.h:252
LDRbase * create_copy() const
Definition: reco.h:253
bool parsevalstring(const STD_string &parstring, const LDRserBase *ser=0)
STD_ostream & print2stream(STD_ostream &os, const LDRserBase &serializer) const
STD_string printvalstring(const LDRserBase *ser=0) const
Protocol proxy.
Definition: protocol.h:33
Definition: reco.h:265
const cvector & get_AdcWeightVector(unsigned int i) const
STD_string get_PreProc3D() const
Definition: reco.h:449
int get_NumOfAdcChunks() const
RecoPars & set_DimValues(recoDim dim, const dvector &vals)
unsigned int numof_adcs() const
Definition: reco.h:408
fvector get_ChannelScales() const
Definition: reco.h:332
const farray & get_kSpaceTraj(unsigned int i) const
const dvector & get_DimValues(recoDim dim) const
Definition: reco.h:327
const fvector & get_RelativeOffset() const
Definition: reco.h:317
int append_readout_shape(const fvector &shape, unsigned int dstsize)
int append_kspace_traj(const farray &kspace_traj)
STD_string get_CmdLineOpts() const
Definition: reco.h:460
RecoPars & operator=(const RecoPars &sr)
RecoPars & set_CmdLineOpts(const STD_string &opts)
Definition: reco.h:454
RecoPars(const RecoPars &sr)
int append_dwell_time(double dt)
STD_string get_Recipe() const
Definition: reco.h:423
bool is_LittleEndian() const
Definition: reco.h:302
const Protocol & get_protocol() const
Definition: reco.h:287
STD_string get_PostProc3D() const
Definition: reco.h:437
int append_adc_weight_vec(const cvector &weightvec)
const STD_string & get_ImageProc() const
Definition: reco.h:322
RecoPars & set_Recipe(const STD_string &recipe)
Definition: reco.h:418
LONGEST_INT get_TotalNumOfSamples(bool discard=false) const
RecoPars(const STD_string &label="unnamedRecoPars")
const LDRkSpaceCoords & get_kSpaceCoords() const
Definition: reco.h:292
double get_DwellTime(unsigned int i) const
unsigned int get_RawHeaderSize() const
Definition: reco.h:312
const kSpaceCoord & get_kSpaceCoord(unsigned int i) const
void get_ReadoutShape(unsigned int i, fvector &shape, unsigned int &dstsize) const
const STD_string & get_RawFile() const
Definition: reco.h:307
RecoPars & set_PreProc3D(const STD_string &recipe)
Definition: reco.h:443
const STD_string & get_DataFormat() const
Definition: reco.h:297
RecoPars & set_PostProc3D(const STD_string &recipe)
Definition: reco.h:430
unsigned int numof_kSpaceTraj() const
Acquisition.
Definition: seqacq.h:206
Base class for methods (sequences)
Definition: seqmeth.h:155
unsigned int size() const
Definition: tjvallist.h:140
const ndim & get_extent() const
recoDim
Definition: reco.h:74
templateType
Definition: reco.h:91
navigatorType
Definition: reco.h:103
recoFlags
Definition: reco.h:44