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
00307 float relCenterPos;
00308
00312 unsigned short adcstart;
00313
00317 unsigned short adcend;
00318
00322 float gridScaleFactor;
00323
00328 unsigned short echopos;
00329
00333 unsigned short echotrain;
00334
00335
00336 private:
00337 void common_init() {
00338 flags=0;
00339 readoutShape=0;
00340 kspaceTraj=0;
00341 weightVec=0;
00342 dwellTime=0.0;
00343 overSamplingFactor=1.0;
00344 relCenterPos=0.5;
00345 adcstart=0;
00346 adcend=0;
00347 gridScaleFactor=1.0;
00348 echopos=0;
00349 echotrain=0;
00350 index[readout].set_mode(RecoIndex::collected);
00351 }
00352
00353 };
00354
00355
00357
00361 typedef STD_map<RecoCoord, UInt> CoordCountMap;
00362
00364
00368 template<unsigned int Ndim, recoDim d1=n_recoDims, recoDim d2=n_recoDims, recoDim d3=n_recoDims, recoDim d4=n_recoDims, recoDim d5=n_recoDims>
00369 struct RecoDim {
00370
00374 static unsigned int dim() {return Ndim;}
00375
00379 static RecoCoord preset_coord(RecoIndex::indexMode m) {return RecoCoord::coord_with_mode(m, d1, d2, d3, d4, d5);}
00380
00384 static void modify(RecoIndex::indexMode m, RecoCoord& coord) {coord.set_mode(m, d1, d2, d3, d4, d5);}
00385
00389 static void create_index(const RecoCoord& coord, TinyVector<int,Ndim>& index) {
00390 unsigned int idim=0;
00391 if(d1!=n_recoDims) {index(idim)=coord.index[d1]; idim++;}
00392 if(d2!=n_recoDims) {index(idim)=coord.index[d2]; idim++;}
00393 if(d3!=n_recoDims) {index(idim)=coord.index[d3]; idim++;}
00394 if(d4!=n_recoDims) {index(idim)=coord.index[d4]; idim++;}
00395 if(d5!=n_recoDims) {index(idim)=coord.index[d5]; idim++;}
00396 }
00397
00401 static void create_shape(const RecoCoord& coord, TinyVector<int,Ndim>& shape) {
00402 unsigned int idim=0;
00403 if(d1!=n_recoDims) {shape(idim)=coord.numof(d1); idim++;}
00404 if(d2!=n_recoDims) {shape(idim)=coord.numof(d2); idim++;}
00405 if(d3!=n_recoDims) {shape(idim)=coord.numof(d3); idim++;}
00406 if(d4!=n_recoDims) {shape(idim)=coord.numof(d4); idim++;}
00407 if(d5!=n_recoDims) {shape(idim)=coord.numof(d5); idim++;}
00408 }
00409
00410
00414 static void set_index(const TinyVector<int,Ndim>& index, RecoCoord& coord) {
00415 unsigned int idim=0;
00416 if(d1!=n_recoDims) {coord.index[d1]=index(idim); idim++;}
00417 if(d2!=n_recoDims) {coord.index[d2]=index(idim); idim++;}
00418 if(d3!=n_recoDims) {coord.index[d3]=index(idim); idim++;}
00419 if(d4!=n_recoDims) {coord.index[d4]=index(idim); idim++;}
00420 if(d5!=n_recoDims) {coord.index[d5]=index(idim); idim++;}
00421 }
00422
00423 };
00424
00425
00426
00427
00428
00433 #endif
00434