WPOCT Software Developer's Kit (SDK)
SDK For using Wasatch Photonics OCT Spectrometers
ScanProcessor.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <boost/signals2.hpp>
9 #include <boost/bind.hpp>
10 
11 #include <vector>
12 #include <mutex>
13 #include <atomic>
14 
15 #include "IWPOCTConverter.h"
16 #include "WPFFT.h"
17 #include "OCTTypeDefs.h"
18 
19 // Forward class declarations.
20 struct IWPOCTConverter;
21 struct IWPOCTInOutData;
22 
23 class GPUManager;
24 class Background;
25 class Dispersion;
26 class Resampler;
27 class Averager;
28 class MovingAverage;
29 
32 {
33 public:
34  ScanProcessor();
35  ScanProcessor(IWPOCTConverter* scanConverter);
36  ScanProcessor(IWPOCTConverter* scanConverter, int width, int height);
37 
38  virtual ~ScanProcessor();
39 
40  // Events
41  boost::signals2::signal<void(int width, int height)> SignalWidthHeightChanged;
42 
43  // Getters
44  size_t GetProcessedDataSizeBytes () { return _outputDataSize; }
45  size_t GetProcessedDataSizeNative () { return _outputDataSize / sizeof(float); }
46 
47  int GetHeight () { return _height; }
48  int GetWidth () { return _width; }
49  int GetHalfHeight () { return _halfHeight; }
50  int GetDepth () { return _depth; }
51 
52  float GetAutoScaleMin () { return _autoScaleMin; }
53  float GetAutoScaleMax () { return _autoScaleMax; }
54  int GetAScanAverage ();
55 
56  static size_t GetPreFFTDataSize () { return _preFFT1DataSize; }
57 
58  bool IsConvertingImage () const { return _convertingImage; }
59  IWPOCTConverter::ErrorCode GetLastError() const { return _lastError; }
60 
61  static bool GetShiftUpLines () { return _shiftUpLines; }
62  static int GetTopLinesToIgnore () { return _topLinesToIgnore; }
63  static int GetBotLinesToIgnore () { return _botLinesToIgnore; }
64  static bool GetOutputLogValues () { return _outputLogValues; }
65  static bool GetUseAutoContrast () { return _useAutoContrast; }
66  static bool GetUseScaling () { return _useScaling; }
67  static bool GetUseApodization () { return _useApodization; }
68 
69  static float GetAutoScaleUserMin () { return _userAutoScaleMin; }
70  static float GetAutoScaleUserMax () { return _userAutoScaleMax; }
71 
72  static bool GetUseMovingAverage ();
73  static int GetMovingAverageWindowSize ();
74 
75 
76  bool GetIsZeroPad () const { return _isZeroPad; }
77 
78  Dispersion* GetDispersion () const { return _dispersion; }
79  std::vector<float> GetDispersionCoefficients ();
80 
81  void AdjustForBackground (const U16* raw, SGL *&inputData);
82 
83  // Setters
84  void SetAutoScaleMin (float value) { _autoScaleMin = value; }
85  void SetAutoScaleMax (float value) { _autoScaleMax = value; }
86  bool SetAScanAverage (int value);
87 
88  static void SetShiftUpLines (bool value) { _shiftUpLines = value; }
89  static bool SetTopLinesToIgnore (int value)
90  {
91  if (value < 0)
92  return false;
93  _topLinesToIgnore = value;
94  return true;
95  }
96  static bool SetBotLinesToIgnore (int value)
97  {
98  if (value < 0)
99  return false;
100  _botLinesToIgnore = value;
101  return true;
102  }
103  static bool SetOutputLogValues (bool value) { _outputLogValues = value; return true; }
104  static bool SetUseAutoContrast (bool value)
105  {
106  if (_useScaling || !value)
107  {
108  _useAutoContrast = value;
109  return true;
110  }
111  else
112  {
113  return false;
114  }
115  }
116 
117  static bool SetUseScaling (bool value) { _useScaling = value; return true; }
118  static bool SetUseApodization (bool value) { _useApodization = value; return true; }
119 
120  static void SetAutoScaleUserMin (float value) { _userAutoScaleMin = value; }
121  static void SetAutoScaleUserMax (float value) { _userAutoScaleMax = value; }
122 
123  // Setters for displaying a moving average.
124  static bool SetUseMovingAverage (bool value);
125  static bool SetMovingAverageWindowSize (int value);
126  static bool ResetMovingAverage ();
127 
128  void SetIsZeroPad (bool value) { _isZeroPad = value; }
129 
130  bool SetWidth (int value)
131  {
132  if (value <= 0)
133  return false;
134 
135  if (_width != value)
136  {
137  _width = value;
138  OnWidthHeightChanged(_width, _height);
139  }
140  return true;
141  }
142 
143  bool SetHeight (int value)
144  {
145  if (value <= 0)
146  return false;
147 
148  if (_height != value)
149  {
150  _height = value;
151  _halfHeight = _height / 2;
152  SetScaleStep();
153  SetNoiseStep();
154  OnWidthHeightChanged(_width, _height);
155  }
156  return true;
157  }
158 
159  bool SetWidthAndHeight (int width, int height)
160  {
161  if (width <= 0 || height <= 0)
162  return false;
163 
164  if (_width != width || _height != height)
165  {
166  // Don't call SetHeight and SetWidth to avoid calling OnWidthHeightChanged twice.
167  _width = width;
168  _height = height;
169  _halfHeight = _height / 2;
170  SetScaleStep();
171  SetNoiseStep();
172  OnWidthHeightChanged(width, height);
173  }
174  return true;
175  }
176 
177  void SetDepth (int value) { _depth = value; }
178 
179  int ComputeForDispersion (const unsigned short* inData, float* interim, float*& outData);
180  bool CalcDispersionCoefficients (const unsigned short* inData, int width, int height,
181  float* coefficients);
182  bool SetDispersionOptimizationParameters(int numCoefficients, int maxIterations,
183  float* initialGuesses, int startLine,
184  int stopLine, int offset);
185 
186  virtual GPUManager* GetGPUManager () { return nullptr; }
187 
188  virtual bool ComputeIntensity (IWPOCTInOutData* inOutData);
189  virtual bool ComputeIntensity (const unsigned short* inData, float* outIntensity);
190 
191  virtual bool ComputePhaseIntensity (IWPOCTInOutData* inOutData, bool outputPhase);
192  virtual bool ComputePhaseIntensity (const unsigned short* inData, float* outIntensity,
193  float* outPhase, bool outputPhase);
194 
195  virtual int GetFFTLength () const { return 0; }
196  virtual void SetScaleType (int sMethod) { }
197  virtual bool SetDispersionCoefficients(const float* dispersionCoeffients, int length);
198 
199  bool UpdateBackgroundImage ();
200  bool GetBackgroundImage (float* buffer, int size);
201  bool SetBackgroundImage (float* buffer, int size);
202 
203 protected:
204  IWPOCTConverter* _scanConverter;
205 
206  int _width;
207  int _height;
208  int _halfHeight;
209  int _depth;
210 
211  static int _scaleType;
212  static int _refCount;
213 
214  float _minNoise, _maxNoise, _noiseStep;
215  float _minScale, _maxScale, _scaleStep;
216  bool _isZeroPad;
217  IWPOCTConverter::ErrorCode _lastError;
218 
219  static std::atomic<int> _topLinesToIgnore;
220  static std::atomic<int> _botLinesToIgnore;
221  static std::atomic<bool> _outputLogValues;
222  static std::atomic<bool> _useAutoContrast;
223  static std::atomic<bool> _useScaling;
224  static std::atomic<bool> _useApodization;
225  static std::atomic<bool> _shiftUpLines;
226 
227  bool _memAllocated;
228  bool _initialized;
229 
230  bool _testCPU;
231  bool _filenameSet;
232  bool _padInit;
233  float _autoScaleMin, _autoScaleMax;
234  std::atomic<bool> _convertingImage;
235 
236  //static std::mutex _mutexAnalyticPhase;
237  //static std::mutex _mutexZeroPad;
238  //static std::mutex _mutexAssembleIntensity;
239  //static std::mutex _mutexAssembleIntensityNoiseScale;
240  //static std::mutex _mutexContrastScale;
241 
242  static std::atomic<float> _userAutoScaleMax, _userAutoScaleMin;
243  static MovingAverage* _movingAverage;
244 
245  float* _dummyFloat;
246 
247  Background* _background;
248  Dispersion* _dispersion;
249  Resampler* _resampler;
250  Averager* _averager;
251  WPFFT* _fft;
252 
253  //Buffer sizes
254  size_t _outputDataSize;
255  static size_t _preFFT1DataSize;
256 
257  void Init();
258 
259  void SetScale (float minScale, float maxScale);
260  void SetNoiseStep ();
261  void SetScaleStep ();
262  void SetZeroPadRunFFT ();
263 
264  void RunAssembly (bool withPhase);
265 
266  virtual void CalcMemoryNeeded () { }
267  virtual void ComputeFFT (WPFFT::FFTType type) { }
268  virtual void CorrectDispersion () { }
269  virtual int PerformAveraging () { return -1; }
270  virtual int ApplyHanningAndFringe () { return 0; }
271 
272  virtual int InitStorage ();
273  virtual void ReleaseStorage ();
274 
275  virtual void InitInOutArrays ();
276  virtual void ReleaseInOutArrays () { }
277 
278  virtual void InitHelpers ();
279  virtual void ReleaseHelpers ();
280 
281  virtual int CreateAnalyticPhase () { return 0; }
282  virtual int AssembleIntensity (bool withPhase) { return 0; }
283  virtual int AssembleIntensityNoiseScale () { return 0; }
284 
285  virtual int ZeroPad () { return 0; }
286 
287  virtual int ContrastScale () { return 0; }
288 
289  virtual int TransferOutputAndPhase (float* outData, float* phaseData, bool outputPhase ) { return 0; }
290  virtual int TransferOutputAndInterim (float*& outData, float* interim) { return -1; }
291 
292  virtual void OnWidthHeightChanged (int width, int height);
293 
294 private:
295  void SetupMovingAverage();
296 
297 };
Interface of the IWPOCTConverter struct.
typedefs used across UtensilConverter
Interface of the WPFFT class.
Definition: Averager.h:17
Definition: Background.h:18
Definition: Dispersion.h:18
Definition: GPUManager.h:13
Class for calculating a moving average. The window size is configurable.
Definition: MovingAverage.h:17
Definition: Resampler.h:22
Class that processes scans.
Definition: ScanProcessor.h:32
int ComputeForDispersion(const unsigned short *inData, float *interim, float *&outData)
Use this for Dispersion Compensation.
Definition: ScanProcessor.cpp:285
virtual bool SetDispersionCoefficients(const float *dispersionCoeffients, int length)
Set the dispersion coefficients.
Definition: ScanProcessor.cpp:223
Definition: WPFFT.h:16
FFTType
Lists the different types of FFTs available.
Definition: WPFFT.h:22
Class to convert data obtained from a line scan camera into meaningful 2D OCT image data.
Definition: IWPOCTConverter.h:56
ErrorCode
The following are error codes that are used within the converter object.
Definition: IWPOCTConverter.h:61
The data object contains pointers to input and output data.
Definition: IWPOCTInOutData.h:14