WPOCT Software Developer's Kit (SDK)
SDK For using Wasatch Photonics OCT Spectrometers
WPCamera.h
Go to the documentation of this file.
1 #pragma once
2 
8 #include <atomic>
9 #include <string>
10 #include <vector>
11 #include <fstream>
12 #include <ctime>
13 #include <mutex>
14 
15 #include "IWPOCTCamera.h"
16 
17 using namespace std;
18 
24 class WPCamera : public IWPOCTCamera
25 {
26 public:
28  WPCamera();
29 
31  virtual ~WPCamera();
32 
33  // Events
34 
35  // Getters
36  bool IsInitialized () const override;
37  bool IsOpened () const override;
38  bool IsAcquiring () const override;
39  bool AreParametersSet() const override;
40 
41  IWPOCTCamera::ErrorCode GetLastError() const override;
42  IWPOCTCamera::CurrentStates GetCurrentState() const override;
43 
45  int GetScanWidth () const override { return _scanWidth; }
46 
48  int GetScanHeight () const override { return _scanHeight; }
49 
51  bool GetScanWidthAndHeight (int* width, int* height) const override
52  {
53  bool result = true;
54  try
55  {
56  if (width)
57  {
58  *width = (int)_scanWidth;
59  }
60  else
61  {
62  result = false;
63  }
64  if (height)
65  {
66  *height = (int)_scanHeight;
67  }
68  else
69  {
70  result = false;
71  }
72  }
73  catch (exception&)
74  {
75  result = false;
76  }
77  return result;
78  }
79 
81  int GetNumBuffers () const override { return _numBuffers; }
82 
84  int GetLinesLost () const override { return _linesLost; }
85 
87  int GetTriggersMissed () const override { return _triggersMissed; }
88 
90  long long GetImageSize () const { return (size_t)_scanHeight * (int)_scanWidth; }
91 
93  int GetCameraType () const override { return _cameraType; }
94 
96  int GetAcquisitionTimeout() const override { return _acquisitionTimeout; }
97 
99  int GetResourceIndex () const override { return _resourceIndex; }
100 
102  const char* GetCameraFileName() const override { return _cameraFileName.c_str(); }
103 
104  // Setters
105 
107  bool SetScanHeight (int value) override
108  {
109  _scanHeight = value;
110  return true;
111  }
112 
114  bool SetNumBuffers (int value) override { _numBuffers = value; return true; }
115 
117  bool SetCameraFileName (const char* name) override { _cameraFileName = name; return true; }
118 
120  bool SetAcquisitionTimeout (int value) override { _acquisitionTimeout = (value <= 0 ? -1 : value); return true; }
121 
123  bool SetResourceIndex (int value) override { _resourceIndex = value; return true; }
124 
125  // Write consecutive image acquisitions to disk.
126  //bool WriteFramesToDiskAdjustBuffers(const char* baseFilePath, int numFrames, bool keepMemoryAllocated);
127 
129  bool AcquireFramesWriteToDisk (const char* baseFilePath, int numFrames, bool keepMemoryAllocated) override;
130 
132  bool AcquireWriteFramesToMemory (unsigned short** data, int numFrames) override;
133 
135  bool AcquireWriteFramesToMemory (unsigned short* data, int numFrames) override;
136 
137 protected:
138 
139  int _id;
140 
142  unsigned int _scanWidth;
143 
145  unsigned int _scanHeight;
146 
148  std::atomic<ErrorCode> _lastError;
149  std::atomic<CurrentStates> _currentState;
150 
151  int _numBuffers;
152  std::atomic<int> _linesLost;
153  std::atomic<int> _triggersMissed;
154  std::atomic<int> _acquisitionTimeout;
155  std::atomic<bool> _acquiringSeries;
156  std::atomic<bool> _abortAcquisition;
157 
159  std::atomic<long> _dongleVal;
160 
161  int _resourceIndex;
162  CameraType _cameraType;
163  vector<unsigned short> _acquisitionData;
164 
165  std::string _cameraFileName;
166  std::string _seriesBaseFileName;
167 
168  virtual bool DeleteResources() { return true; }
169 
170  void OutputDebugMsg(const wchar_t* str) const
171  {
172 #ifdef _DEBUG
173  // Only call OutputDebugString when in debug as this call has some overhead.
174  OutputDebugString( str );
175 #endif
176  }
177 
178  void OutputDebugMsg(const char* str) const
179  {
180 #ifdef _DEBUG
181  // Only call OutputDebugString when in debug as this call has some overhead.
182  OutputDebugStringA( str );
183 #endif
184  }
185 
186  string FormSeriesBaseFileName (const char* baseFilePath);
187  string FormSeriesFinalFileName (size_t index, const char* extension);
188  string GetFilledDigits (int number, int totalDigits);
189 
190  template <typename T>
191  static bool SaveMemoryToBinFile(const char* fname, long long size, const T* data)
192  {
193  bool result = false;
194  ofstream fout;
195 
196  try
197  {
198  fout.open(fname, ios::out | ios::binary);
199  if (fout.good())
200  {
201  fout.write((char*)data, size * sizeof(T));
202  if (fout.good())
203  {
204  result = true;
205  }
206  fout.close();
207  }
208  }
209  catch (exception& )
210  {
211  result = false;
212  }
213  return result;
214  }
215 
216 private:
217  std::mutex _mutexTimeCheck;
218 
219  static std::atomic<bool> _id0Taken;
220  static std::atomic<double> _timeCheckInterval;
221  static std::atomic<clock_t> _startTime;
222 
224  void Init();
225 };
std::string GetFilledDigits(int number, size_t totalDigits)
Gets the string prefixed with zeros so the string is a certain length.
Definition: Helper.cpp:61
Interface of the IWPOCTCamera class.
Class that converts a scanned image from one format to another.
Definition: WPCamera.h:25
bool SetScanHeight(int value) override
Set the height of an image.
Definition: WPCamera.h:107
int GetScanWidth() const override
Get the width of an image.
Definition: WPCamera.h:45
int GetAcquisitionTimeout() const override
Get the acquisition timeout in milliseconds.
Definition: WPCamera.h:96
bool SetResourceIndex(int value) override
Set the resource index of the frame grabber.
Definition: WPCamera.h:123
int GetLinesLost() const override
Get the number of lines lost in the last frame.
Definition: WPCamera.h:84
bool GetScanWidthAndHeight(int *width, int *height) const override
Get the width and height of a scan.
Definition: WPCamera.h:51
std::atomic< ErrorCode > _lastError
The most recent error code.
Definition: WPCamera.h:148
long long GetImageSize() const
Get the size of an image.
Definition: WPCamera.h:90
int GetTriggersMissed() const override
Get the number of triggers missed in the last frame.
Definition: WPCamera.h:87
int GetResourceIndex() const override
Get the resource index of the frame grabber.
Definition: WPCamera.h:99
int GetScanHeight() const override
Get the height of an image.
Definition: WPCamera.h:48
bool SetCameraFileName(const char *name) override
Set the name of the camera configuration file.
Definition: WPCamera.h:117
unsigned int _scanWidth
The width of an scan.
Definition: WPCamera.h:142
const char * GetCameraFileName() const override
Get the name of the camera configuration file.
Definition: WPCamera.h:102
int GetNumBuffers() const override
Get the number of image buffers.
Definition: WPCamera.h:81
unsigned int _scanHeight
The height of an scan.
Definition: WPCamera.h:145
bool SetAcquisitionTimeout(int value) override
Set the acquisition timeout in milliseconds.
Definition: WPCamera.h:120
int GetCameraType() const override
Get the camera type.
Definition: WPCamera.h:93
bool SetNumBuffers(int value) override
Set the number of image buffers.
Definition: WPCamera.h:114
std::atomic< long > _dongleVal
Dongle check return value.
Definition: WPCamera.h:159
Definition: IWPOCTCamera.h:79
CameraType
The following are the camera types that are used in GetOCTCamera and GetCameraType.
Definition: IWPOCTCamera.h:115
CurrentStates
Current states of the camera (more than one can be active) The following are status codes that are us...
Definition: IWPOCTCamera.h:129
ErrorCode
The following are error codes that are used within the camera.
Definition: IWPOCTCamera.h:85