ODIN
filter_range.h
1 /***************************************************************************
2  filter_range.h - description
3  -------------------
4  begin : Tue Jan 29 2008
5  copyright : (C) 2000-2021 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 FILTER_RANGE_H
19 #define FILTER_RANGE_H
20 
21 #include <odindata/filter_step.h>
22 
23 
24 bool str2range(const STD_string& str, Range& range, int srcsize);
25 STD_string str2range_usage();
26 
27 
28 template<int Dir>
29 class FilterRange : public FilterStep {
30 
31  LDRstring range;
32 
33  STD_string label() const {return STD_string(1,STD_string(dataDimLabel[Dir])[0])+"range";} // Use only 1st letter
34  STD_string description() const {return "Select range in "+STD_string(dataDimLabel[Dir])+" direction";}
35 
36  bool process(Data<float,4>& data, Protocol& prot) const {
37  Range all=Range::all();
38 
39  Range rng[4];
40  for(int i=0; i<4; i++) rng[i]=Range::all();
41 
42  if(!str2range(range,rng[Dir],data.extent(Dir))) return false;
43 
44  TinyVector<int,4> newshape=data.shape();
45  int oldsize=newshape(Dir);
46 
47  newshape(Dir)=rng[Dir].length();
48 
49 
50  float fovfraction=secureDivision(rng[Dir].last()-rng[Dir].first()+1, oldsize);
51 
52  float offsetfactor=secureDivision(0.5*(rng[Dir].first()+rng[Dir].last()), oldsize)-0.5;
53 
54  Data<float,4> data_copy(data.copy());
55  data.resize(newshape);
56  data(all,all,all,all)=data_copy(rng[timeDim],rng[sliceDim],rng[phaseDim],rng[readDim]);
57 
58  // adapt protocol
59  int stride=rng[Dir].stride();
60  if(Dir==timeDim) {
61  prot.seqpars.set_NumOfRepetitions(newshape(timeDim));
62  if(stride>1) prot.seqpars.set_RepetitionTime(prot.seqpars.get_RepetitionTime()*stride);
63 
64  } else {
65 
66  direction geodir=direction(3-Dir);
67  prot.geometry.set_offset(geodir,prot.geometry.get_offset(geodir)+offsetfactor*prot.geometry.get_FOV(geodir));
68  prot.geometry.set_FOV(geodir,fovfraction*prot.geometry.get_FOV(geodir));
69  prot.seqpars.set_MatrixSize(geodir,newshape(Dir));
70 
71  if(Dir==sliceDim) {
72  if(prot.geometry.get_Mode()==slicepack) {
73  prot.geometry.set_nSlices(newshape(sliceDim));
74  if(stride>1) prot.geometry.set_sliceDistance(prot.geometry.get_sliceDistance()*stride);
75  prot.seqpars.set_MatrixSize(sliceDirection,1);
76  }
77  }
78  }
79 
80  return true;
81  }
82 
83  FilterStep* allocate() const {return new FilterRange<Dir>();}
84 
85  void init() {
86  range.set_description(str2range_usage());
87  append_arg(range,"range");
88  }
89 };
90 
91 #endif
virtual bool process(Data< float, 4 > &data, Protocol &prot) const
Geometry & set_nSlices(unsigned int nslices)
double get_offset(direction dir) const
Geometry & set_sliceDistance(double dist)
Geometry & set_offset(direction dir, double offset)
double get_sliceDistance() const
Definition: geometry.h:252
Geometry & set_FOV(direction dir, double fov)
geometryMode get_Mode() const
Definition: geometry.h:206
double get_FOV(direction dir) const
Protocol proxy.
Definition: protocol.h:33
SeqPars seqpars
Definition: protocol.h:88
Geometry geometry
Definition: protocol.h:83
SeqPars & set_RepetitionTime(double time, parameterMode parmode=edit)
SeqPars & set_MatrixSize(direction dir, unsigned int size, parameterMode parmode=edit)
SeqPars & set_NumOfRepetitions(unsigned int times, parameterMode parmode=edit)
double get_RepetitionTime() const
Definition: seqpars.h:68
virtual FilterStep * allocate() const=0
void append_arg(LDRbase &arg, const STD_string &arglabel)
Definition: step_code.h:76
virtual STD_string description() const=0
virtual void init()=0
virtual STD_string label() const=0
direction
Definition: odinpara.h:41
double secureDivision(double numerator, double denominator)