ODIN
ldrfunction.h
1 /***************************************************************************
2  ldrfunction.h - description
3  -------------------
4  begin : Mon Jun 24 2002
5  copyright : (C) 2000-2021 by Thies H. 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 #ifndef LDRFUNCTION_H
18 #define LDRFUNCTION_H
19 
20 #include <odinpara/ldrblock.h>
21 
27 enum funcType {shapeFunc=0, trajFunc, filterFunc};
28 
39 enum funcMode {zeroDeeMode=0,oneDeeMode,twoDeeMode,n_dimModes};
40 
42 
43 class OdinPulse; // forward declaration
44 
46 
52 struct kspace_coord {
53 
54  kspace_coord() : index(-1), traj_s(0.0), kx(0), ky(0), kz(0), Gx(0), Gy(0), Gz(0), denscomp(1.0) {}
55 
59  mutable int index;
60 
64  float traj_s;
65 
69  float kx;
70 
74  float ky;
75 
79  float kz;
80 
84  float Gx;
85 
89  float Gy;
90 
94  float Gz;
95 
99  float denscomp;
100 };
101 
102 
104 
105 struct shape_info {
106 
107  shape_info() : ref_x_pos(0), ref_y_pos(0), ref_z_pos(0), adiabatic(false), fixed_size(-1), spatial_extent(0.0) {}
108 
109  float ref_x_pos; // Reference position to adjust flip angle
110  float ref_y_pos;
111  float ref_z_pos;
112  bool adiabatic; // Whether pulse is adiabatic
113  int fixed_size; // Pulse has fixed size (for imported pulses)
114  float spatial_extent;
115 };
116 
118 
119 struct traj_info {
120 
121  traj_info() : rel_center(0), max_kspace_step(0) {}
122 
123  float rel_center;
124  float max_kspace_step;
125 
126 };
127 
129 
130 class LDRfunctionPlugIn : public LDRblock {
131 
132  public:
133  LDRfunctionPlugIn(const STD_string& funclabel) : LDRblock(funclabel) {}
134 
135  LDRfunctionPlugIn(const LDRfunctionPlugIn& jfp) : LDRblock(jfp) {}
136 
137  virtual ~LDRfunctionPlugIn() {}
138 
139  LDRfunctionPlugIn& operator = (const LDRfunctionPlugIn& jfp) {LDRblock::operator = (jfp); return *this;}
140 
141  LDRfunctionPlugIn& register_function(funcType type, funcMode mode);
142 
143  // virtual functions for pulse shapes
144  virtual void init_shape() {}
145  virtual STD_complex calculate_shape(const kspace_coord& coord ) const {return STD_complex(0.0);}
146  virtual STD_complex calculate_shape(float s, float Tp) const {return STD_complex(0.0);}
147  virtual const shape_info& get_shape_properties() const {return shape_info_retval;}
148 
149 
150  // virtual functions for pulse trajectories
151  virtual void init_trajectory(OdinPulse* pls) {}
152  virtual const kspace_coord& calculate_traj(float s) const {return coord_retval;}
153  virtual const traj_info& get_traj_properties() const {return traj_info_retval;}
154 
155  // virtual functions for filters
156  virtual float calculate_filter(float rel_kradius) const {return 0;}
157 
158 
159 
160  // virtual constructor
161  virtual LDRfunctionPlugIn* clone() const = 0;
162 
163  // local statics do not work on IDEA
164  static kspace_coord coord_retval;
165 // static shape_vals shape_retval;
166  static shape_info shape_info_retval;
167  static traj_info traj_info_retval;
168 
169 };
170 
171 
173 
174 // Wrapper to bundle LDRfunctionPlugIn and funcType/funcMode together so it can be inserted into lists
175 // multiple times with different funcTypes and funcModes
176 struct LDRfunctionEntry {
177 
178  LDRfunctionEntry(LDRfunctionPlugIn* func_plugin, funcType func_type, funcMode func_mode)
179  : plugin(func_plugin), type(func_type), mode(func_mode) {}
180 
181  LDRfunctionPlugIn* plugin;
182 
183  const funcType type;
184  const funcMode mode;
185 
186  bool operator == (const LDRfunctionEntry& jfe) const;
187  bool operator < (const LDRfunctionEntry& jfe) const;
188 
189 };
190 
192 
193 
194 class LDRfunction : public LDRbase, public StaticHandler<LDRfunction> {
195 
196  public:
197 
198  ~LDRfunction() {new_plugin(0);}
199 
200  LDRfunction& set_function_mode(funcMode newmode);
201  funcMode get_function_mode() const {return mode;}
202 
203  const STD_string& get_function_label(unsigned int index) const;
204  LDRfunction& set_function(const STD_string& funclabel);
205  LDRfunction& set_function(unsigned int index);
206  unsigned int get_function_index() const;
207 
208  LDRblock* get_funcpars_block();
209 
210  LDRfunction& set_funcpars(const svector& funcpars);
211  LDRfunction& set_funcpars(const STD_string& funcpars) {STD_string tt(funcpars); parsevalstring(tt); return *this;}
212  svector get_funcpars() const;
213 
214  bool set_parameter(const STD_string& parameter_label, const STD_string& value);
215  STD_string get_parameter(const STD_string& parameter_label) const;
216 
217  STD_string get_function_name() const;
218 
219  const STD_string& get_funcdescription() const;
220 
221 
222  // overwriting virtual functions from LDRbase
223  LDRfunction* cast(LDRfunction*) {return this;}
224  bool parsevalstring(const STD_string& parstring, const LDRserBase* ser=0);
225  STD_string printvalstring(const LDRserBase* ser=0) const;
226  svector get_alternatives() const;
227  STD_string get_typeInfo(bool parx_equivtype=false) const {return "function";}
228  LDRbase* create_copy() const {return new LDRfunction(*this);}
229 
230 
231  // stuff for StaticHandler
232  static void init_static();
233  static void destroy_static();
234 
235 
236  protected:
237 
238  // Make it impossible to create/use instance of LDRfunction directly
239  LDRfunction(funcType function_type, const STD_string& ldrlabel);
240  LDRfunction(const LDRfunction& jf);
241  LDRfunction& operator = (const LDRfunction& jf);
242 
243  funcMode mode;
244  LDRfunctionPlugIn* allocated_function;
245 
246  private:
247  friend class LDRfunctionPlugIn;
248 
249 
250 
251 
252  void new_plugin(LDRfunctionPlugIn* pi);
253 
254  const funcType type;
255 
256 
257  static STD_list<LDRfunctionEntry>* registered_functions;
258 
259 };
260 
261 
265 #endif
266 
267 
LDRblock & operator=(const LDRblock &block)
Advandced RF pulses.
Definition: odinpulse.h:122
funcMode
Definition: ldrfunction.h:39
bool operator==(const TinyVector< T, N_rank > &t1, const TinyVector< T, N_rank > &t2)
Definition: utils.h:129
bool operator<(const STD_complex &c1, const STD_complex &c2)
Definition: tjcomplex.h:61
float traj_s
Definition: ldrfunction.h:64
float denscomp
Definition: ldrfunction.h:99