File: filter_slicetime.cpp

package info (click to toggle)
odin 2.0.5-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,196 kB
  • sloc: cpp: 62,638; sh: 4,541; makefile: 779
file content (69 lines) | stat: -rw-r--r-- 1,984 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "filter_slicetime.h"

void FilterSliceTime::init(){

  sliceorderstr.set_description("space-separated list of slice indices in order of acquisition");
  append_arg(sliceorderstr,"sliceorderstr");

}

bool FilterSliceTime::process(Data<float,4>& data, Protocol& prot) const {
  Log<Filter> odinlog(c_label(),"process");

  Range all=Range::all();

  TinyVector<int,4> shape=data.shape();

  int nrep=shape(0);
  int nslices=shape(1);

  if(nrep<=1) return true;

  ivector sliceorder;
  if(sliceorderstr=="") {
    // try protocol
    LDRbase* soptr=prot.get_parameter("SliceOrder");
    if(soptr) {
      iarray* sovec=0;
      sovec=soptr->cast(sovec);
      if(sovec) {
        sliceorder=(*sovec);
      }
    }
  } else {
    svector toks=tokens(sliceorderstr);
    sliceorder.resize(toks.size());
    for(unsigned int i=0; i<toks.size(); i++) sliceorder[i]=atoi(toks[i].c_str());
  }

  ODINLOG(odinlog,normalDebug) << "sliceorderstr=" << sliceorderstr << STD_endl;
  ODINLOG(odinlog,normalDebug) << "sliceorder=" << sliceorder.printbody() << STD_endl;

  if(int(sliceorder.size())!=nslices) {
    ODINLOG(odinlog,errorLog) << "size mismatch: nslices/sliceorder.size()=" << nslices << "/" << sliceorder.printbody() << STD_endl;
    return false;
  }

  dvector sliceshift(nslices); sliceshift=0.0;
  for(int islice=0; islice<nslices; islice++) {
    sliceshift[sliceorder[islice]]=secureDivision(islice,nslices);
  }
  ODINLOG(odinlog,normalDebug) << "sliceshift=" << sliceshift.printbody() << STD_endl;


  Data<float,1> tcourse(nrep);
  TinyVector<float,1> subpixel_shift;

  for(int islice=0; islice<nslices; islice++) {
    for(int iphase=0; iphase<shape(2); iphase++) {
      for(int iread=0; iread<shape(3); iread++) {
        tcourse(all)=data(all,islice,iphase,iread);
        subpixel_shift(0)=sliceshift[islice];
        tcourse.congrid(tcourse.shape(), &subpixel_shift);
        data(all,islice,iphase,iread)=tcourse(all);
      }
    }
  }

  return true;
}