WPOCT Software Developer's Kit (SDK)
SDK For using Wasatch Photonics OCT Spectrometers
Resampler.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include "OCTTypeDefs.h"
9 #include <mutex>
10 
11 #include <boost/signals2.hpp>
12 #include <boost/algorithm/string/trim.hpp>
13 #include <boost/algorithm/string/split.hpp>
14 #include <boost/algorithm/string.hpp>
15 #include <boost/filesystem/operations.hpp>
16 
17 // Forward class declarations.
18 class WPScanConverter;
19 class ScanProcessor;
20 
21 class Resampler
22 {
23 public:
24  Resampler(WPScanConverter* converter, ScanProcessor* scanProcessor);
25  virtual ~Resampler();
26 
27  // Getters
28  int GetWindowingType () const { return _windowingType; }
29  bool GetPerformResample () const { return _performResample; }
30 
31  // Setters
32  void SetPerformResample (bool value) { _performResample = value; }
33 
34  virtual void InitGPUMethods (int programIndex) { }
35  virtual void OnWidthHeightChanged (int width, int height);
36  virtual void OnCalibrationFileChanged(const char* fileName);
37  virtual int NoResample () { return 0; }
38  virtual int Process () { return 0; }
39  virtual int ApplyHanningAndFringe (const float* inData, size_t dataSize) { return -1; }
40 
41 protected:
42  ScanProcessor* _scanProcessor;
43  WPScanConverter* _scanConverter;
44  bool _initialized;
45  bool _performResample;
47  int _height;
48  int _id;
49 
50 
51  // Calibration arrays.
52  std::vector<int> _li_fringe;
53  std::vector<SGL> _hann_win_fringe;
54  std::vector<SGL> _p_fringe;
55  std::vector<SGL> _calFringeArray;
56  std::map<SGL, int> _fringe_map;
57 
58  static std::mutex _mutexResample;
59  static string _calibrationFileName;
60  static int _numResamplerObjects;
61 
62  void SetCalibration ();
63  bool InitFringeCalibration (int win, int winPow);
64  void SetCalibrationFringeFile (const std::string &fname);
65 
66  void InitCalibration (int height);
67  void ReleaseCalibration ();
68 
69  virtual void InitStorage ();
70  virtual void ReleaseStorage ();
71 
72  virtual void SetHanningArray (float *hanning) { }
73  virtual void SetPFringeArray (float *pFringe) { }
74  virtual void SetLIFringeArray (int *liFringe) { }
75 
76 private:
77  bool _calibrationInitialized;
78  double _gaussianSigma;
79 
80  boost::signals2::connection _widthHeightConnection;
81  boost::signals2::connection _calibrationFileConnection;
82 
83  // Methods
84  void Init ();
85 
86  template<typename T>
87  static bool LoadFileToVector(int len, const char* fname, std::vector<T> *data_out, int &nItem)
88  {
89  if (FileUtils::FileExists(fname))
90  {
91  ifstream ifile(fname);
92  //ifile.exceptions ( ifstream::failbit | ifstream::badbit );
93  char charline[256];
94  string strline = "";
95  float dbl = 0;
96 
97  nItem = 0;
98  try
99  {
100  while (!ifile.getline(charline, 256).eof() && nItem < len)
101  {
102  strline.assign(charline);
103  boost::algorithm::trim(strline);
104 
105  vector<string> words;
106  boost::algorithm::split(words, strline, boost::is_any_of("\t ,"));
107 
108  // allow for comment or blank line
109  if (words[0].compare(0, 1, "#") == 0 || words.size() < 1) { continue; }
110 
111  for (size_t y = 0; y < words.size(); y++)
112  {
113  boost::algorithm::trim(words[y]);
114  if (words[y].size() == 0) { continue; }
115 
116  if (!FromString<float>(dbl, words[y], std::dec))
117  {
118  continue;
119  }
120  (*data_out)[nItem] = dbl;
121  nItem++;
122  }
123  }
124  ifile.close();
125  return true;
126  }
127  catch (ifstream::failure e)
128  {
129  //alert(" Problem with format of files");
130  //alert(e.what());
131  ifile.close();
132  return false;
133  }
134  }
135  else
136  {
137  return false;
138  }
139  }
140 };
typedefs used across UtensilConverter
Definition: Resampler.h:22
int _windowingType
0=none, 1 == hanning, 2== hamming, 3== gaussian
Definition: Resampler.h:46
void SetCalibrationFringeFile(const std::string &fname)
expect to have one number per line
Definition: Resampler.cpp:138
Class that processes scans.
Definition: ScanProcessor.h:32
Class that converts a scanned image from one format to another.
Definition: WPScanConverter.h:28