SIRF  3.4.0
gadget_lib.h
Go to the documentation of this file.
1 /*
2 SyneRBI Synergistic Image Reconstruction Framework (SIRF)
3 Copyright 2015 - 2019 Rutherford Appleton Laboratory STFC
4 Copyright 2019 University College London
5 
6 This is software developed for the Collaborative Computational
7 Project in Synergistic Reconstruction for Biomedical Imaging (formerly CCP PETMR)
8 (http://www.ccpsynerbi.ac.uk/).
9 
10 Licensed under the Apache License, Version 2.0 (the "License");
11 you may not use this file except in compliance with the License.
12 You may obtain a copy of the License at
13 http://www.apache.org/licenses/LICENSE-2.0
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19 
20 */
21 
32 #ifndef GADGETS_LIBRARY
33 #define GADGETS_LIBRARY
34 
35 #include <map>
36 //#include <boost/algorithm/string.hpp>
37 
38 #include "sirf/common/iequals.h"
39 
40 namespace sirf {
41 
45  class aGadget {
46  public:
47  virtual void set_property(const char* prop, const char* value) = 0;
48  virtual std::string value_of(const char* prop) = 0;
49  virtual std::string vxml(const std::string& label) const = 0;
50  std::string xml(const std::string& label = "") const
51  {
52  return vxml(label);
53  }
54  };
55 
59  class Gadget : public aGadget {
60  public:
61  Gadget(std::string name, std::string dll, std::string cl) :
62  gadget_(name), dll_(dll)
63  {
64  class_ = cl;
65  //add_property("pass_on_undesired_data", "true");
66  }
67  virtual void set_property(const char* prop, const char* value)
68  {
69  par_[prop] = value;
70  }
71  virtual std::string value_of(const char* prop)
72  {
73  return par_[prop];
74  }
75  void add_property(const char* prop, const char* value)
76  {
77  par_[prop] = value;
78  }
79  virtual std::string vxml(const std::string& label) const
80  {
81  std::string xml_script("<gadget>\n");
82  if (label.size() > 1)
83  xml_script += " <name>" + label + ':' + gadget_ + "</name>\n";
84  else
85  xml_script += " <name>" + gadget_ + "</name>\n";
86  xml_script += " <dll>" + dll_ + "</dll>\n";
87  xml_script += " <classname>" + class_ + "</classname>\n";
88 #if defined(_MSC_VER) && _MSC_VER < 1900
89  std::map<std::string, std::string>::const_iterator it;
90 #else
91  typename std::map<std::string, std::string>::const_iterator it;
92 #endif
93  for (it = par_.begin(); it != par_.end(); ++it) {
94  xml_script += " <property>\n";
95  xml_script += " <name>" + it->first + "</name>\n"; \
96  xml_script += " <value>" + it->second + "</value>\n"; \
97  xml_script += " </property>\n";
98  }
99  xml_script += "</gadget>\n";
100  return xml_script;
101  }
102  protected:
103  std::string gadget_;
104  std::string dll_;
105  std::string class_;
106  std::map<std::string, std::string> par_;
107  };
108 
113  class IsmrmrdAcqMsgReader : public aGadget {
114  public:
115  static const char* class_name()
116  {
117  return "GadgetIsmrmrdAcquisitionMessageReader";
118  }
119  virtual void set_property(const char* prop, const char* value) {}
120  virtual std::string value_of(const char* prop)
121  {
122  return std::string("");
123  }
124  virtual std::string vxml(const std::string& label) const {
125  std::string xml_script("<reader>\n");
126  xml_script += " <slot>1008</slot>\n";
127  xml_script += " <dll>gadgetron_mricore</dll>\n";
128  xml_script +=
129  " <classname>GadgetIsmrmrdAcquisitionMessageReader</classname>\n";
130  xml_script += "</reader>\n";
131  return xml_script;
132  }
133  };
134 
139  class IsmrmrdAcqMsgWriter : public aGadget {
140  public:
141  static const char* class_name()
142  {
143  return "GadgetIsmrmrdAcquisitionMessageWriter";
144  }
145  virtual void set_property(const char* prop, const char* value) {}
146  virtual std::string value_of(const char* prop)
147  {
148  return std::string("");
149  }
150  virtual std::string vxml(const std::string& label) const {
151  std::string xml_script("<writer>\n");
152  xml_script += " <slot>1008</slot>\n";
153  xml_script += " <dll>gadgetron_mricore</dll>\n";
154  xml_script +=
155  " <classname>GadgetIsmrmrdAcquisitionMessageWriter</classname>\n";
156  xml_script += "</writer>\n";
157  return xml_script;
158  }
159  };
160 
164  class IsmrmrdImgMsgReader : public aGadget {
165  public:
166  static const char* class_name()
167  {
168  return "MRIImageReader";
169  }
170  virtual void set_property(const char* prop, const char* value) {}
171  virtual std::string value_of(const char* prop)
172  {
173  return std::string("");
174  }
175  virtual std::string vxml(const std::string& label) const {
176  std::string xml_script("<reader>\n");
177  xml_script += " <slot>1022</slot>\n";
178  xml_script += " <dll>gadgetron_mricore</dll>\n";
179  xml_script +=
180  " <classname>MRIImageReader</classname>\n";
181  xml_script += "</reader>\n";
182  return xml_script;
183  }
184  };
185 
186  class ImageMessageWriter : public aGadget {
187 
188  };
192  //class IsmrmrdImgMsgWriter : public aGadget {
194  public:
195  static const char* class_name()
196  {
197  return "MRIImageWriter";
198  }
199  virtual void set_property(const char* prop, const char* value) {}
200  virtual std::string value_of(const char* prop)
201  {
202  return std::string("");
203  }
204  virtual std::string vxml(const std::string& label) const {
205  std::string xml_script("<writer>\n");
206  xml_script += " <slot>1022</slot>\n";
207  xml_script += " <dll>gadgetron_mricore</dll>\n";
208  xml_script += " <classname>MRIImageWriter</classname>\n";
209  xml_script += "</writer>\n";
210  return xml_script;
211  }
212  };
213 
218  public:
219  static const char* class_name()
220  {
221  return "DicomImageWriter";
222  }
223  virtual void set_property(const char* prop, const char* value) {}
224  virtual std::string value_of(const char* prop)
225  {
226  return std::string("");
227  }
228  virtual std::string vxml(const std::string& label) const {
229  std::string xml_script("<writer>\n");
230  xml_script += " <slot>1018</slot>\n";
231  xml_script += " <dll>gadgetron_dicom</dll>\n";
232  xml_script += " <classname>DicomImageWriter</classname>\n";
233  xml_script += "</writer>\n";
234  return xml_script;
235  }
236  };
237 
238  class NoiseAdjustGadget : public Gadget {
239  public:
241  Gadget("NoiseAdjust", "gadgetron_mricore", "NoiseAdjustGadget")
242  {}
243  static const char* class_name()
244  {
245  return "NoiseAdjustGadget";
246  }
247  };
248 
249  class PCACoilGadget : public Gadget {
250  public:
251  PCACoilGadget() :
252  Gadget("PCACoil", "gadgetron_mricore", "PCACoilGadget")
253  {}
254  static const char* class_name()
255  {
256  return "PCACoilGadget";
257  }
258  };
259 
260  class CoilReductionGadget : public Gadget {
261  public:
263  Gadget("CoilReduction", "gadgetron_mricore", "CoilReductionGadget")
264  {
265  add_property("coil_mask", "");
266  add_property("coils_out", "128");
267  }
268  static const char* class_name()
269  {
270  return "CoilReductionGadget";
271  }
272  };
273 
275  public:
277  Gadget("AsymmetricEcho", "gadgetron_mricore",
278  "AsymmetricEchoAdjustROGadget")
279  {}
280  static const char* class_name()
281  {
282  return "AsymmetricEchoAdjustROGadget";
283  }
284  };
285 
287  public:
289  Gadget("RemoveROOversampling", "gadgetron_mricore",
290  "RemoveROOversamplingGadget")
291  {}
292  static const char* class_name()
293  {
294  return "RemoveROOversamplingGadget";
295  }
296  };
297 
299  public:
301  Gadget("AccTrig", "gadgetron_mricore", "AcquisitionAccumulateTriggerGadget")
302  {
303  add_property("trigger_dimension", "repetition");
304  add_property("sorting_dimension", "slice");
305  }
306  static const char* class_name()
307  {
308  return "AcquisitionAccumulateTriggerGadget";
309  }
310  };
311 
312  class BucketToBufferGadget : public Gadget {
313  public:
315  Gadget("Buff", "gadgetron_mricore", "BucketToBufferGadget")
316  {
317  add_property("N_dimension", "");
318  add_property("S_dimension", "");
319  add_property("split_slices", "true");
320  add_property("ignore_segment", "true");
321  add_property("verbose", "true");
322  }
323  static const char* class_name()
324  {
325  return "BucketToBufferGadget";
326  }
327  };
328 
330  public:
332  Gadget("PrepRef", "gadgetron_mricore",
333  "GenericReconCartesianReferencePrepGadget")
334  {
335  add_property("debug_folder", "");
336  add_property("perform_timing", "true");
337  add_property("verbose", "true");
338  add_property("average_all_ref_N", "true");
339  add_property("average_all_ref_S", "true");
340  add_property("prepare_ref_always", "true");
341  }
342  static const char* class_name()
343  {
344  return "GenericReconCartesianReferencePrepGadget";
345  }
346  };
347 
348  class SimpleReconGadget : public Gadget {
349  public:
351  Gadget("SimpleRecon", "gadgetron_mricore", "SimpleReconGadget")
352  {}
353  static const char* class_name()
354  {
355  return "SimpleReconGadget";
356  }
357  };
358 
360  public:
362  Gadget("Recon", "gadgetron_mricore", "GenericReconCartesianFFTGadget")
363  {
364  add_property("image_series","0");
365  add_property("coil_map_algorithm","Inati");
366  add_property("debug_folder","");
367  add_property("perform_timing","true");
368  add_property("verbose","true");
369  }
370  static const char* class_name()
371  {
372  return "GenericReconCartesianFFTGadget";
373  }
374  };
375 
377  public:
379  Gadget("CartesianGrappa", "gadgetron_mricore",
380  "GenericReconCartesianGrappaGadget")
381  {
382  add_property("image_series", "0");
383  add_property("coil_map_algorithm", "Inati");
384  add_property("downstream_coil_compression", "true");
385  add_property("downstream_coil_compression_thres", "0.01");
386  add_property("downstream_coil_compression_num_modesKept", "0");
387  add_property("send_out_gfactor", "true");
388  add_property("debug_folder", "");
389  add_property("perform_timing", "true");
390  add_property("verbose", "true");
391  }
392  static const char* class_name()
393  {
394  return "GenericReconCartesianGrappaGadget";
395  }
396  };
397 
399  public:
401  Gadget("FOVAdjustment", "gadgetron_mricore",
402  "GenericReconFieldOfViewAdjustmentGadget")
403  {
404  add_property("debug_folder", "");
405  add_property("perform_timing", "false");
406  add_property("verbose", "false");
407  }
408  static const char* class_name()
409  {
410  return "GenericReconFieldOfViewAdjustmentGadget";
411  }
412  };
413 
415  public:
417  Gadget("Scaling", "gadgetron_mricore",
418  "GenericReconImageArrayScalingGadget")
419  {
420  add_property("perform_timing", "false");
421  add_property("verbose", "false");
422  add_property("min_intensity_value", "64");
423  add_property("max_intensity_value", "4095");
424  add_property("scalingFactor", "10.0");
425  add_property("use_constant_scalingFactor", "true");
426  add_property("scalingFactor_dedicated", "100.0");
427  add_property("auto_scaling_only_once", "true");
428  }
429  static const char* class_name()
430  {
431  return "GenericReconImageArrayScalingGadget";
432  }
433  };
434 
435  class FatWaterGadget : public Gadget {
436  public:
437  FatWaterGadget() :
438  Gadget("FatWater", "gadgetron_fatwater", "FatWaterGadget")
439  {}
440  static const char* class_name()
441  {
442  return "FatWaterGadget";
443  }
444  };
445 
446  class ImageArraySplitGadget : public Gadget {
447  public:
449  Gadget("ImageArraySplit", "gadgetron_mricore", "ImageArraySplitGadget")
450  {}
451  static const char* class_name()
452  {
453  return "ImageArraySplitGadget";
454  }
455  };
456 
458  public:
460  Gadget("PhysioInterpolation", "gadgetron_mricore", "PhysioInterpolationGadget")
461  {
462  add_property("phases", "30");
463  add_property("mode", "0");
464  add_property("first_beat_on_trigger", "true");
465  add_property("interp_method", "BSpline");
466  }
467  static const char* class_name()
468  {
469  return "PhysioInterpolationGadget";
470  }
471  };
472 
473  class GPURadialPrepGadget : public Gadget {
474  public:
475  GPURadialPrepGadget(std::string name, std::string dll, std::string cl) :
476  Gadget(name, dll, cl)
477  {
478  add_property("mode", "0");
479  add_property("deviceno", "0");
480  add_property("profiles_per_frame", "0");
481  add_property("rotations_per_reconstruction", "0");
482  add_property("frames_per_rotation", "0");
483  add_property("buffer_frames_per_rotation", "0");
484  add_property("buffer_length_in_rotations", "1");
485  add_property("buffer_using_solver", "false");
486  add_property("buffer_convolution_kernel_width", "5.5");
487  add_property("buffer_convolution_oversampling_factor", "1.25");
488  add_property("reconstruction_os_factor_x", "1.0");
489  add_property("reconstruction_os_factor_y", "1.0");
490  add_property("output_timing", "false");
491  }
492 /*
493  static const char* class_name()
494  {
495  return "GPUSenseGadget";
496  }
497 */
498  };
499 
501  public:
503  GPURadialPrepGadget("gpuRadialSensePrepGadget", "gadgetron_gpuradial", "gpuRadialSensePrepGadget")
504  {}
505  static const char* class_name()
506  {
507  return "GPURadialSensePrepGadget";
508  }
509  };
510 
511  class GPUSenseGadget : public Gadget {
512  public:
513  GPUSenseGadget(std::string name, std::string dll, std::string cl) :
514  Gadget(name, dll, cl)
515  {
516  add_property("deviceno", "0");
517  add_property("setno", "0");
518  add_property("sliceno", "0");
519  add_property("oversampling_factor", "1.5");
520  add_property("kernel_width", "5.5");
521  add_property("save_individual_frames", "true");
522  add_property("output_convergence", "false");
523  add_property("rotations_to_discard", "0");
524  add_property("output_timing", "false");
525  }
526 /*
527  static const char* class_name()
528  {
529  return "GPUSenseGadget";
530  }
531 */
532  };
533 
535  public:
536  GPUCGSenseGadget() :
537  GPUSenseGadget("gpuCgSenseGadget", "gadgetron_gpuparallelmri", "gpuCgSenseGadget")
538  {
539  add_property("kappa", "0.3");
540  add_property("number_of_iterations", "5");
541  add_property("cg_limit", "1e-6");
542  }
543  static const char* class_name()
544  {
545  return "GPUCGSenseGadget";
546  }
547  };
548 
549  class ExtractGadget : public Gadget {
550  public:
551  ExtractGadget() :
552  Gadget("Extract", "gadgetron_mricore", "ExtractGadget")
553  {
554  add_property("extract_mask", "0");
555  add_property("extract_magnitude", "true");
556  add_property("extract_real", "false");
557  add_property("extract_imag", "false");
558  add_property("extract_phase", "false");
559  }
560  static const char* class_name()
561  {
562  return "ExtractGadget";
563  }
564  };
565 
566  class AutoScaleGadget : public Gadget {
567  public:
568  AutoScaleGadget() :
569  Gadget("AutoScale", "gadgetron_mricore", "AutoScaleGadget")
570  {}
571  static const char* class_name()
572  {
573  return "AutoScaleGadget";
574  }
575  };
576 
577  class ComplexToFloatGadget : public Gadget {
578  public:
580  Gadget("ComplexToFloatAttrib", "gadgetron_mricore", "ComplexToFloatGadget")
581  {}
582  static const char* class_name()
583  {
584  return "ComplexToFloatGadget";
585  }
586  };
587 
588  class FloatToFixPointGadget : public Gadget {
589  public:
590  FloatToFixPointGadget(std::string name, // = "FloatToFixPoint",
591  std::string dll, // = "gadgetron_mricore",
592  std::string cl, // = "FloatToFixPointGadget",
593  std::string max_int) : // = "32767") :
594  Gadget(name, dll, cl)
595  {
596  add_property("min_intensity", "0");
597  add_property("max_intensity", max_int.c_str());
598  add_property("intensity_offset", "0");
599  }
600 /*
601  static const char* class_name()
602  {
603  return "FloatToFixPointGadget";
604  }
605 */
606  };
607 
609  public:
611  FloatToFixPointGadget("FloatToShort", "gadgetron_mricore", "FloatToUShortGadget", "65535")
612  {}
613  static const char* class_name()
614  {
615  return "FloatToUShortGadget";
616  }
617  };
618 
620  public:
622  FloatToFixPointGadget("FloatToShortAttrib", "gadgetron_mricore",
623  "FloatToShortGadget", "32767")
624  {}
625  static const char* class_name()
626  {
627  return "FloatToShortGadget";
628  }
629  };
630 /*
631  class FloatToShortGadget : public Gadget {
632  public:
633  FloatToShortGadget() :
634  Gadget("FloatToShortAttrib", "gadgetron_mricore",
635  "FloatToShortGadget")
636  {
637  add_property("min_intensity", "0");
638  add_property("max_intensity", "32767");
639  add_property("intensity_offset", "0");
640  }
641  static const char* class_name()
642  {
643  return "FloatToShortGadget";
644  }
645  };
646 */
647  class ImageFinishGadget : public Gadget {
648  public:
650  Gadget("ImageFinish", "gadgetron_mricore", "ImageFinishGadget")
651  {}
652  static const char* class_name()
653  {
654  return "ImageFinishGadget";
655  }
656  };
657 
658  class DicomFinishGadget : public Gadget {
659  public:
661  Gadget("DicomFinish", "gadgetron_dicom", "DicomFinishGadget")
662  {}
663  static const char* class_name()
664  {
665  return "DicomFinishGadget";
666  }
667  };
668 
670  public:
672  Gadget("AcquisitionFinish", "gadgetron_mricore", "AcquisitionFinishGadget")
673  {}
674  static const char* class_name()
675  {
676  return "AcquisitionFinishGadget";
677  }
678  };
679 
684  class SimpleReconGadgetSet : public aGadget {
685  public:
686  static const char* class_name()
687  {
688  return "SimpleReconGadgetSet";
689  }
690  virtual void set_property(const char* prop, const char* value)
691  {
692  if (sirf::iequals(prop, "trigger_dimension") ||
693  sirf::iequals(prop, "sorting_dimension"))
694  aat_.set_property(prop, value);
695  else if (sirf::iequals(prop, "n_dimension") ||
696  sirf::iequals(prop, "s_dimension") ||
697  sirf::iequals(prop, "split_slices"))
698  bb_.set_property(prop, value);
699  else
700  THROW("unknown gadget parameter");
701  }
702  virtual std::string value_of(const char* prop)
703  {
704  if (sirf::iequals(prop, "trigger_dimension") ||
705  sirf::iequals(prop, "sorting_dimension"))
706  return aat_.value_of(prop);
707  else if (sirf::iequals(prop, "n_dimension") ||
708  sirf::iequals(prop, "s_dimension") ||
709  sirf::iequals(prop, "split_slices"))
710  return bb_.value_of(prop);
711  THROW("unknown gadget parameter");
712  }
713  virtual std::string vxml(const std::string& label) const
714  {
715  std::string xml_script;
716  xml_script += aat_.xml();
717  xml_script += bb_.xml();
718  xml_script += sr_.xml();
719  xml_script += ias_.xml();
720  return xml_script;
721  }
722  private:
725  SimpleReconGadget sr_;
727  };
728 
729 }
730 
731 #endif
Definition: gadget_lib.h:534
Class for a gadget xml-definition generator.
Definition: gadget_lib.h:59
Class for GadgetIsmrmrdAcquisitionMessageWriter gadget xml-definition generator.
Definition: gadget_lib.h:139
bool iequals(const std::string &a, const std::string &b)
Case insensitive string comparison, replaces boost::iequals.
Definition: iequals.cpp:7
Class for xml-definition generator for a simple fully sumpled reconstruction gadget set...
Definition: gadget_lib.h:684
Definition: gadget_lib.h:298
Case insensitive string comparison sirf::iequals.
Definition: gadget_lib.h:457
Definition: gadget_lib.h:312
Abstract base class for a gadget xml-definition generator.
Definition: gadget_lib.h:45
Definition: gadget_lib.h:577
Definition: gadget_lib.h:446
Definition: gadget_lib.h:249
Definition: gadget_lib.h:435
Class for DicomImageWriter gadget xml-definition generator.
Definition: gadget_lib.h:217
Definition: gadget_lib.h:274
Definition: gadget_lib.h:473
Definition: gadget_lib.h:511
Definition: gadget_lib.h:549
Definition: gadget_lib.h:238
Definition: gadget_lib.h:647
Definition: gadget_lib.h:376
Definition: gadget_lib.h:260
Class for MRIImageReader gadget xml-definition generator.
Definition: gadget_lib.h:164
Definition: gadget_lib.h:286
Definition: gadget_lib.h:608
Definition: gadget_lib.h:566
Abstract data container.
Definition: GeometricalInfo.cpp:141
Definition: gadget_lib.h:186
Definition: gadget_lib.h:669
Class for MRIImageWriter gadget xml-definition generator.
Definition: gadget_lib.h:193
Definition: gadget_lib.h:414
Definition: gadget_lib.h:348
Definition: gadget_lib.h:359
Class for GadgetIsmrmrdAcquisitionMessageReader gadget xml-definition generator.
Definition: gadget_lib.h:113
Definition: gadget_lib.h:658
Definition: gadget_lib.h:588
Definition: gadget_lib.h:500
Definition: gadget_lib.h:619