index.h
1 /***************************************************************************
2  index.h - description
3  -------------------
4  begin : Mon Jan 27 2007
5  copyright : (C) 2000-2015 by Thies 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 RECOINDEX_H
19 #define RECOINDEX_H
20 
21 #include <odinreco/odinreco.h>
22 
23 #include <odindata/gridding.h>
24 
35 class RecoIndex {
36 
37  public:
38 
48  enum indexMode {separate=0, ignore, single, collected, any};
49 
50 
54  RecoIndex(unsigned short v=0) : mode(separate), val(v), numof(1) {}
55 
59  RecoIndex& operator = (unsigned short v) {val=v; return *this;}
60 
64  bool operator < (const RecoIndex& ri) const {
65  // comparison makes sense only in 'separate' mode.
66  if( mode==separate && ri.mode==separate ) {
67  return val < ri.val;
68  }
69  return false; // equal or ignored when comparing
70  }
71 
75  operator unsigned short () const {if(mode==single) return 0; return val;} // return zero index in single mode for numof=1
76 
80  RecoIndex& set_mode(indexMode m) {mode=m; return *this;}
81 
85  indexMode get_mode() const {return indexMode(mode);}
86 
90  bool compatible(const RecoIndex& ri) const {
91  if(mode==any || ri.mode==any) return true;
92  if(mode==collected && ri.mode!=collected) return false;
93  if(mode!=collected && ri.mode==collected) return false;
94  if(mode==single && ri.mode==single && val!=ri.val) return false;
95  return true;
96  }
97 
98 
102  bool prep_count(const RecoIndex& mask) {
103  if(mask.mode==single) {
104  if(val!=mask.val) return false;
105  }
106  mode=mask.mode;
107  return true;
108  }
109 
110 
114  RecoIndex& set_numof(unsigned short n) {numof=n; return *this;}
115 
119  unsigned short get_numof() const {if(mode==single) return 1; return numof;}
120 
121 
128  enum printMode {brief=0, all, filename};
129 
133  STD_string print(recoDim dim, printMode printmode=brief) const;
134 
135 
136  private:
137 
138  unsigned char mode;
139  unsigned short val;
140  unsigned short numof;
141 
142 
143 
144 };
145 
147 
148 
149 typedef Data<GriddingPoint<3> ,2> KspaceTraj; // dimension is (nsegments, npoints)
150 
151 typedef STD_pair<Data<float,1>, int> ReadoutShape; // shape and target grid size
152 
153 
154 
158 struct RecoCoord {
159 
160 
164  RecoCoord() {common_init();}
165 
166 
170  bool operator < (const RecoCoord& rc) const {
171  for(int i=0; i<n_recoDims; i++) {
172  bool rc_larger= index[i]<rc.index[i];
173  bool rc_smaller=rc.index[i]<index[i];
174  if(rc_larger || rc_smaller) return rc_larger; // return immediately if different
175  }
176  return false;
177  }
178 
179 
183  bool operator == (const RecoCoord& rc) const {
184  return !((*this)<rc || rc<(*this));
185  }
186 
187 
191  bool compatible(const RecoCoord& rc) const {
192  for(int i=0; i<n_recoDims; i++) {
193  if(!index[i].compatible(rc.index[i])) return false;
194  }
195  return true;
196  }
197 
198 
202  bool prep_count(const RecoCoord& mask) {
203  for(int i=0; i<n_recoDims; i++) {
204  if(!index[i].prep_count(mask.index[i])) return false;
205  }
206  return true;
207  }
208 
209 
213  STD_string print(RecoIndex::printMode printmode=RecoIndex::brief) const;
214 
215 
219  static RecoCoord any() {
220  RecoCoord result;
221  result.set_uniform_mode(RecoIndex::any);
222  return result;
223  }
224 
225 
230  for(int i=0; i<n_recoDims; i++) index[i].set_mode(m);
231  return *this;
232  }
233 
234 
238  RecoCoord& set_mode(RecoIndex::indexMode m, recoDim d1=n_recoDims, recoDim d2=n_recoDims, recoDim d3=n_recoDims, recoDim d4=n_recoDims, recoDim d5=n_recoDims, recoDim d6=n_recoDims, recoDim d7=n_recoDims, recoDim d8=n_recoDims) {
239  if(d1<n_recoDims) index[d1].set_mode(m);
240  if(d2<n_recoDims) index[d2].set_mode(m);
241  if(d3<n_recoDims) index[d3].set_mode(m);
242  if(d4<n_recoDims) index[d4].set_mode(m);
243  if(d5<n_recoDims) index[d5].set_mode(m);
244  if(d6<n_recoDims) index[d6].set_mode(m);
245  if(d7<n_recoDims) index[d7].set_mode(m);
246  if(d8<n_recoDims) index[d8].set_mode(m);
247  return *this;
248  }
249 
250 
254  static RecoCoord coord_with_mode(RecoIndex::indexMode m, recoDim d1=n_recoDims, recoDim d2=n_recoDims, recoDim d3=n_recoDims, recoDim d4=n_recoDims, recoDim d5=n_recoDims, recoDim d6=n_recoDims, recoDim d7=n_recoDims, recoDim d8=n_recoDims) {
255  RecoCoord result;
256  result.set_mode(m,d1,d2,d3,d4,d5,d6,d7,d8);
257  return result;
258  }
259 
263  unsigned short numof(recoDim dim) const {return index[dim].get_numof();}
264 
265 
269  RecoIndex index[n_recoDims];
270 
271 
275  unsigned char flags;
276 
277 
282  const ReadoutShape* readoutShape;
283 
284 
290 
295 
296 
300  double dwellTime;
301 
306 
311 
315  unsigned short adcstart;
316 
320  unsigned short adcend;
321 
326 
331  unsigned short echopos;
332 
336  unsigned short echotrain;
337 
338 
339  private:
340  void common_init() {
341  flags=0;
342  readoutShape=0;
343  kspaceTraj=0;
344  weightVec=0;
345  dwellTime=0.0;
346  overSamplingFactor=1.0;
347  relCenterPos=0.5;
348  adcstart=0;
349  adcend=0;
350  gridScaleFactor=1.0;
351  echopos=0;
352  echotrain=0;
353  index[readout].set_mode(RecoIndex::collected); // readout is already collected for ADCs
354  }
355 
356 };
357 
358 
360 
364 typedef STD_map<RecoCoord, UInt> CoordCountMap;
365 
367 
371 template<unsigned int Ndim, recoDim d1=n_recoDims, recoDim d2=n_recoDims, recoDim d3=n_recoDims, recoDim d4=n_recoDims, recoDim d5=n_recoDims, recoDim d6=n_recoDims>
372 struct RecoDim {
373 
377  static unsigned int dim() {return Ndim;}
378 
382  static RecoCoord preset_coord(RecoIndex::indexMode m) {return RecoCoord::coord_with_mode(m, d1, d2, d3, d4, d5, d6);}
383 
387  static void modify(RecoIndex::indexMode m, RecoCoord& coord) {coord.set_mode(m, d1, d2, d3, d4, d5, d6);}
388 
392  static void create_index(const RecoCoord& coord, TinyVector<int,Ndim>& index) {
393  unsigned int idim=0;
394  if(d1!=n_recoDims) {index(idim)=coord.index[d1]; idim++;}
395  if(d2!=n_recoDims) {index(idim)=coord.index[d2]; idim++;}
396  if(d3!=n_recoDims) {index(idim)=coord.index[d3]; idim++;}
397  if(d4!=n_recoDims) {index(idim)=coord.index[d4]; idim++;}
398  if(d5!=n_recoDims) {index(idim)=coord.index[d5]; idim++;}
399  if(d6!=n_recoDims) {index(idim)=coord.index[d6]; idim++;}
400  }
401 
405  static void create_shape(const RecoCoord& coord, TinyVector<int,Ndim>& shape) {
406  unsigned int idim=0;
407  if(d1!=n_recoDims) {shape(idim)=coord.numof(d1); idim++;}
408  if(d2!=n_recoDims) {shape(idim)=coord.numof(d2); idim++;}
409  if(d3!=n_recoDims) {shape(idim)=coord.numof(d3); idim++;}
410  if(d4!=n_recoDims) {shape(idim)=coord.numof(d4); idim++;}
411  if(d5!=n_recoDims) {shape(idim)=coord.numof(d5); idim++;}
412  if(d6!=n_recoDims) {shape(idim)=coord.numof(d6); idim++;}
413  }
414 
415 
419  static void set_index(const TinyVector<int,Ndim>& index, RecoCoord& coord) {
420  unsigned int idim=0;
421  if(d1!=n_recoDims) {coord.index[d1]=index(idim); idim++;}
422  if(d2!=n_recoDims) {coord.index[d2]=index(idim); idim++;}
423  if(d3!=n_recoDims) {coord.index[d3]=index(idim); idim++;}
424  if(d4!=n_recoDims) {coord.index[d4]=index(idim); idim++;}
425  if(d5!=n_recoDims) {coord.index[d5]=index(idim); idim++;}
426  if(d6!=n_recoDims) {coord.index[d6]=index(idim); idim++;}
427  }
428 
429 };
430 
431 
432 
433 
434 
439 #endif
440 
static void create_shape(const RecoCoord &coord, TinyVector< int, Ndim > &shape)
Definition: index.h:405
bool operator==(const TinyVector< T, N_rank > &t1, const TinyVector< T, N_rank > &t2)
Definition: utils.h:129
bool compatible(const RecoCoord &rc) const
Definition: index.h:191
RecoIndex & set_numof(unsigned short n)
Definition: index.h:114
unsigned short echopos
Definition: index.h:331
RecoIndex & operator=(unsigned short v)
Definition: index.h:59
float relCenterPos
Definition: index.h:310
indexMode
Definition: index.h:48
bool prep_count(const RecoIndex &mask)
Definition: index.h:102
RecoCoord & set_mode(RecoIndex::indexMode m, recoDim d1=n_recoDims, recoDim d2=n_recoDims, recoDim d3=n_recoDims, recoDim d4=n_recoDims, recoDim d5=n_recoDims, recoDim d6=n_recoDims, recoDim d7=n_recoDims, recoDim d8=n_recoDims)
Definition: index.h:238
printMode
Definition: index.h:128
static RecoCoord preset_coord(RecoIndex::indexMode m)
Definition: index.h:382
const KspaceTraj * kspaceTraj
Definition: index.h:289
unsigned short get_numof() const
Definition: index.h:119
RecoIndex & set_mode(indexMode m)
Definition: index.h:80
static RecoCoord any()
Definition: index.h:219
double dwellTime
Definition: index.h:300
static RecoCoord coord_with_mode(RecoIndex::indexMode m, recoDim d1=n_recoDims, recoDim d2=n_recoDims, recoDim d3=n_recoDims, recoDim d4=n_recoDims, recoDim d5=n_recoDims, recoDim d6=n_recoDims, recoDim d7=n_recoDims, recoDim d8=n_recoDims)
Definition: index.h:254
unsigned char flags
Definition: index.h:275
unsigned short numof(recoDim dim) const
Definition: index.h:263
RecoCoord & set_uniform_mode(RecoIndex::indexMode m)
Definition: index.h:229
const ReadoutShape * readoutShape
Definition: index.h:282
Definition: index.h:372
STD_map< RecoCoord, UInt > CoordCountMap
Definition: index.h:364
bool operator<(const RecoIndex &ri) const
Definition: index.h:64
RecoCoord()
Definition: index.h:164
static void set_index(const TinyVector< int, Ndim > &index, RecoCoord &coord)
Definition: index.h:419
unsigned short echotrain
Definition: index.h:336
RecoIndex index[n_recoDims]
Definition: index.h:269
static void create_index(const RecoCoord &coord, TinyVector< int, Ndim > &index)
Definition: index.h:392
unsigned short adcstart
Definition: index.h:315
static unsigned int dim()
Definition: index.h:377
float gridScaleFactor
Definition: index.h:325
RecoIndex(unsigned short v=0)
Definition: index.h:54
bool prep_count(const RecoCoord &mask)
Definition: index.h:202
unsigned short adcend
Definition: index.h:320
indexMode get_mode() const
Definition: index.h:85
const ComplexData< 1 > * weightVec
Definition: index.h:294
float overSamplingFactor
Definition: index.h:305
bool compatible(const RecoIndex &ri) const
Definition: index.h:90
static void modify(RecoIndex::indexMode m, RecoCoord &coord)
Definition: index.h:387
STD_string print(recoDim dim, printMode printmode=brief) const
recoDim
Definition: reco.h:74