00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef RECOINDEX_H
00019 #define RECOINDEX_H
00020
00021 #include <odinreco/odinreco.h>
00022
00023 #include <odindata/gridding.h>
00024
00035 class RecoIndex {
00036
00037 public:
00038
00048 enum indexMode {separate=0, ignore, single, collected, any};
00049
00050
00054 RecoIndex(unsigned short v=0) : mode(separate), val(v), numof(1) {}
00055
00059 RecoIndex& operator = (unsigned short v) {val=v; return *this;}
00060
00064 bool operator < (const RecoIndex& ri) const {
00065
00066 if( mode==separate && ri.mode==separate ) {
00067 return val < ri.val;
00068 }
00069 return false;
00070 }
00071
00075 operator unsigned short () const {if(mode==single) return 0; return val;}
00076
00080 RecoIndex& set_mode(indexMode m) {mode=m; return *this;}
00081
00085 indexMode get_mode() const {return indexMode(mode);}
00086
00090 bool compatible(const RecoIndex& ri) const {
00091 if(mode==any || ri.mode==any) return true;
00092 if(mode==collected && ri.mode!=collected) return false;
00093 if(mode!=collected && ri.mode==collected) return false;
00094 if(mode==single && ri.mode==single && val!=ri.val) return false;
00095 return true;
00096 }
00097
00098
00102 bool prep_count(const RecoIndex& mask) {
00103 if(mask.mode==single) {
00104 if(val!=mask.val) return false;
00105 }
00106 mode=mask.mode;
00107 return true;
00108 }
00109
00110
00114 RecoIndex& set_numof(unsigned short n) {numof=n; return *this;}
00115
00119 unsigned short get_numof() const {if(mode==single) return 1; return numof;}
00120
00121
00128 enum printMode {brief=0, all, filename};
00129
00133 STD_string print(recoDim dim, printMode printmode=brief) const;
00134
00135
00136 private:
00137
00138 unsigned char mode;
00139 unsigned short val;
00140 unsigned short numof;
00141
00142
00143
00144 };
00145
00147
00148
00149 typedef Data<GriddingPoint<3> ,2> KspaceTraj;
00150
00151 typedef STD_pair<Data<float,1>, int> ReadoutShape;
00152
00153
00154
00158 struct RecoCoord {
00159
00160
00164 RecoCoord() {common_init();}
00165
00166
00170 bool operator < (const RecoCoord& rc) const {
00171 for(int i=0; i<n_recoDims; i++) {
00172 bool rc_larger= index[i]<rc.index[i];
00173 bool rc_smaller=rc.index[i]<index[i];
00174 if(rc_larger || rc_smaller) return rc_larger;
00175 }
00176 return false;
00177 }
00178
00179
00183 bool operator == (const RecoCoord& rc) const {
00184 return !((*this)<rc || rc<(*this));
00185 }
00186
00187
00191 bool compatible(const RecoCoord& rc) const {
00192 for(int i=0; i<n_recoDims; i++) {
00193 if(!index[i].compatible(rc.index[i])) return false;
00194 }
00195 return true;
00196 }
00197
00198
00202 bool prep_count(const RecoCoord& mask) {
00203 for(int i=0; i<n_recoDims; i++) {
00204 if(!index[i].prep_count(mask.index[i])) return false;
00205 }
00206 return true;
00207 }
00208
00209
00213 STD_string print(RecoIndex::printMode printmode=RecoIndex::brief) const;
00214
00215
00219 static RecoCoord any() {
00220 RecoCoord result;
00221 result.set_uniform_mode(RecoIndex::any);
00222 return result;
00223 }
00224
00225
00229 RecoCoord& set_uniform_mode(RecoIndex::indexMode m) {
00230 for(int i=0; i<n_recoDims; i++) index[i].set_mode(m);
00231 return *this;
00232 }
00233
00234
00238 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) {
00239 if(d1<n_recoDims) index[d1].set_mode(m);
00240 if(d2<n_recoDims) index[d2].set_mode(m);
00241 if(d3<n_recoDims) index[d3].set_mode(m);
00242 if(d4<n_recoDims) index[d4].set_mode(m);
00243 if(d5<n_recoDims) index[d5].set_mode(m);
00244 return *this;
00245 }
00246
00247
00251 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) {
00252 RecoCoord result;
00253 result.set_mode(m,d1,d2,d3,d4,d5);
00254 return result;
00255 }
00256
00260 unsigned short numof(recoDim dim) const {return index[dim].get_numof();}
00261
00262
00266 RecoIndex index[n_recoDims];
00267
00268
00272 unsigned char flags;
00273
00274
00279 const ReadoutShape* readoutShape;
00280
00281
00286 const KspaceTraj* kspaceTraj;
00287
00291 const ComplexData<1>* weightVec;
00292
00293
00297 double dwellTime;
00298
00302 float overSamplingFactor;
00303
00308 unsigned short echopos;
00309
00313 unsigned short echotrain;
00314
00315
00316 private:
00317 void common_init() {
00318 flags=0;
00319 readoutShape=0;
00320 kspaceTraj=0;
00321 weightVec=0;
00322 dwellTime=0.0;
00323 overSamplingFactor=1.0;
00324 echopos=0;
00325 echotrain=0;
00326 index[readout].set_mode(RecoIndex::collected);
00327 }
00328
00329 };
00330
00331
00333
00337 typedef STD_map<RecoCoord, UInt> CoordCountMap;
00338
00340
00344 template<unsigned int Ndim, recoDim d1=n_recoDims, recoDim d2=n_recoDims, recoDim d3=n_recoDims, recoDim d4=n_recoDims, recoDim d5=n_recoDims>
00345 struct RecoDim {
00346
00350 static unsigned int dim() {return Ndim;}
00351
00355 static RecoCoord preset_coord(RecoIndex::indexMode m) {return RecoCoord::coord_with_mode(m, d1, d2, d3, d4, d5);}
00356
00360 static void modify(RecoIndex::indexMode m, RecoCoord& coord) {coord.set_mode(m, d1, d2, d3, d4, d5);}
00361
00365 static void create_index(const RecoCoord& coord, TinyVector<int,Ndim>& index) {
00366 unsigned int idim=0;
00367 if(d1!=n_recoDims) {index(idim)=coord.index[d1]; idim++;}
00368 if(d2!=n_recoDims) {index(idim)=coord.index[d2]; idim++;}
00369 if(d3!=n_recoDims) {index(idim)=coord.index[d3]; idim++;}
00370 if(d4!=n_recoDims) {index(idim)=coord.index[d4]; idim++;}
00371 if(d5!=n_recoDims) {index(idim)=coord.index[d5]; idim++;}
00372 }
00373
00377 static void create_shape(const RecoCoord& coord, TinyVector<int,Ndim>& shape) {
00378 unsigned int idim=0;
00379 if(d1!=n_recoDims) {shape(idim)=coord.numof(d1); idim++;}
00380 if(d2!=n_recoDims) {shape(idim)=coord.numof(d2); idim++;}
00381 if(d3!=n_recoDims) {shape(idim)=coord.numof(d3); idim++;}
00382 if(d4!=n_recoDims) {shape(idim)=coord.numof(d4); idim++;}
00383 if(d5!=n_recoDims) {shape(idim)=coord.numof(d5); idim++;}
00384 }
00385
00386
00390 static void set_index(const TinyVector<int,Ndim>& index, RecoCoord& coord) {
00391 unsigned int idim=0;
00392 if(d1!=n_recoDims) {coord.index[d1]=index(idim); idim++;}
00393 if(d2!=n_recoDims) {coord.index[d2]=index(idim); idim++;}
00394 if(d3!=n_recoDims) {coord.index[d3]=index(idim); idim++;}
00395 if(d4!=n_recoDims) {coord.index[d4]=index(idim); idim++;}
00396 if(d5!=n_recoDims) {coord.index[d5]=index(idim); idim++;}
00397 }
00398
00399 };
00400
00401
00402
00403
00404
00409 #endif
00410