-
Notifications
You must be signed in to change notification settings - Fork 0
/
IDSPeak.h
294 lines (263 loc) · 9.64 KB
/
IDSPeak.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
///////////////////////////////////////////////////////////////////////////////
// FILE: IDSPeak.h
// PROJECT: Micro-Manager
// SUBSYSTEM: DeviceAdapters
//-----------------------------------------------------------------------------
// DESCRIPTION: Driver for IDS peak series of USB cameras
//
// Based on IDS peak SDK and Micromanager DemoCamera example
// tested with SDK version 2.5
// Requires Micro-manager Device API 71 or higher!
//
// AUTHOR: Lars Kool, Institut Pierre-Gilles de Gennes
//
// YEAR: 2023
//
// VERSION: 1.1
//
// LICENSE: This file is distributed under the BSD license.
// License text is included with the source distribution.
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES.
//
//LAST UPDATE: 09.10.2023 LK
#ifndef _IDSPeak_H_
#define _IDSPeak_H_
#include "DeviceBase.h"
#include "ImgBuffer.h"
#include "DeviceThreads.h"
#include <string>
#include <map>
#include <algorithm>
#include <stdint.h>
#include <future>
#include <ids_peak_comfort_c/ids_peak_comfort_c.h>
using namespace std;
#define EXPOSURE_MAX 1000000
////////////////////////////////////////
// Error codes
////////////////////////////////////////
#define ERR_LIBRARY_NOT_INIT 101
#define ERR_UNKNOWN_MODE 102
#define ERR_UNKNOWN_POSITION 103
#define ERR_IN_SEQUENCE 104
#define ERR_SEQUENCE_INACTIVE 105
#define ERR_STAGE_MOVING 106
#define HUB_NOT_AVAILABLE 107
#define ERR_MEM_ALLOC 108
#define ERR_ROI_INVALID 109
#define ERR_CAMERA_NOT_FOUND 110
#define ERR_DEVICE_NOT_AVAILABLE 111
#define ERR_NO_READ_ACCESS 112
#define ERR_ACQ_START 113
#define ERR_ACQ_FRAME 114
#define ERR_ACQ_RELEASE 115
#define ERR_ACQ_TIMEOUT 116
#define ERR_NO_WRITE_ACCESS 117
const char* NoHubError = "Parent Hub not defined.";
//////////////////////////////////////////////////////////////////////////////
// CIDSPeak class
//////////////////////////////////////////////////////////////////////////////
class MySequenceThread;
class CIDSPeak : public CCameraBase<CIDSPeak>
{
public:
CIDSPeak();
~CIDSPeak();
// MMDevice API
// ------------
int Initialize();
int Shutdown();
vector<peak_camera_handle> hCams;
peak_camera_handle hCam = PEAK_INVALID_HANDLE;
peak_status status = PEAK_STATUS_SUCCESS;
void GetName(char* name) const;
int CamID_;
// MMCamera API
// ------------
int SnapImage();
const unsigned char* GetImageBuffer();
unsigned GetImageWidth() const;
unsigned GetImageHeight() const;
unsigned GetImageBytesPerPixel() const;
unsigned GetBitDepth() const;
long GetImageBufferSize() const;
double GetExposure() const;
void SetExposure(double exp);
int SetROI(unsigned x, unsigned y, unsigned xSize, unsigned ySize);
int GetROI(unsigned& x, unsigned& y, unsigned& xSize, unsigned& ySize);
int ClearROI();
bool SupportsMultiROI();
bool IsMultiROISet();
int GetMultiROICount(unsigned& count);
int SetMultiROI(const unsigned* xs, const unsigned* ys,
const unsigned* widths, const unsigned* heights,
unsigned numROIs);
int GetMultiROI(unsigned* xs, unsigned* ys, unsigned* widths,
unsigned* heights, unsigned* length);
int PrepareSequenceAcqusition() { return DEVICE_OK; }
int StartSequenceAcquisition(double interval);
int StartSequenceAcquisition(long numImages, double interval_ms, bool stopOnOverflow);
int StopSequenceAcquisition();
int InsertImage();
int RunSequenceOnThread();
bool IsCapturing();
void OnThreadExiting() throw();
double GetNominalPixelSizeUm() const { return nominalPixelSizeUm_; }
double GetPixelSizeUm() const { return nominalPixelSizeUm_ * GetBinning(); }
int GetBinning() const;
int SetBinning(int bS);
int IsExposureSequenceable(bool& isSequenceable) const;
int GetExposureSequenceMaxLength(long& nrEvents) const;
int StartExposureSequence();
int StopExposureSequence();
int ClearExposureSequence();
int AddToExposureSequence(double exposureTime_ms);
int SendExposureSequence() const;
unsigned GetNumberOfComponents() const { return nComponents_; };
// action interface
// ----------------
int OnChangeCamera(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnModelName(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnSerialNumber(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnMaxExposure(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnBinning(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnPixelType(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnFrameRate(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnReadoutTime(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnCameraCCDXSize(MM::PropertyBase*, MM::ActionType);
int OnCameraCCDYSize(MM::PropertyBase*, MM::ActionType);
int OnTriggerDevice(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnSupportsMultiROI(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnMultiROIFillValue(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnCCDTemp(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnIsSequenceable(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnAutoWhiteBalance(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnGainMaster(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnGainRed(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnGainGreen(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnGainBlue(MM::PropertyBase* pProp, MM::ActionType eAct);
long GetCCDXSize() { return cameraCCDXSize_; }
long GetCCDYSize() { return cameraCCDYSize_; }
// My methods
int cleanExit();
peak_bool checkForSuccess(peak_status status, peak_bool continueExecution);
int getSensorInfo();
peak_status getGFAString(const char* featureName, char* stringValue);
peak_status getGFAInt(const char* featureName, int64_t* intValue);
peak_status getGFAfloat(const char* featureName, double* floatValue);
peak_status getTemperature(double* sensorTemp);
void initializeAutoWBConversion();
int transferBuffer(peak_frame_handle hFrame, ImgBuffer& img);
int updateAutoWhiteBalance();
int framerateSet(double framerate);
int cameraChanged();
bool isColorCamera();
private:
int SetAllowedBinning();
void GenerateEmptyImage(ImgBuffer& img);
int ResizeImageBuffer();
static const double nominalPixelSizeUm_;
string modelName_;
string serialNum_;
size_t nCameras_;
double exposureMin_;
double exposureMax_;
double exposureInc_;
double exposureCur_;
double framerateCur_;
double framerateMax_;
double framerateMin_;
double framerateInc_;
ImgBuffer img_;
bool stopOnOverFlow_;
bool initialized_;
double readoutUs_;
MM::MMTime readoutStartTime_;
string pixelType_;
int bitDepth_;
int significantBitDepth_;
int nComponents_;
unsigned roiX_;
unsigned roiY_;
unsigned roiInc_;
unsigned roiMinSizeX_;
unsigned roiMinSizeY_;
MM::MMTime sequenceStartTime_;
bool isSequenceable_;
long sequenceMaxLength_;
bool sequenceRunning_;
unsigned long sequenceIndex_;
double GetSequenceExposure();
std::vector<double> exposureSequence_;
long imageCounter_;
long binSize_;
long cameraCCDXSize_;
long cameraCCDYSize_;
double ccdT_;
std::string triggerDevice_;
map<int, string> peakTypeToString;
map<string, int> stringToPeakType;
peak_auto_feature_mode peakAutoWhiteBalance_;
map<int, string> peakAutoToString;
map<string, int> stringToPeakAuto;
double gainMaster_;
double gainRed_;
double gainGreen_;
double gainBlue_;
double gainMin_;
double gainMax_;
double gainInc_;
bool stopOnOverflow_;
bool supportsMultiROI_;
int multiROIFillValue_;
std::vector<unsigned> multiROIXs_;
std::vector<unsigned> multiROIYs_;
std::vector<unsigned> multiROIWidths_;
std::vector<unsigned> multiROIHeights_;
MMThreadLock imgPixelsLock_;
friend class MySequenceThread;
MySequenceThread* thd_;
std::future<void> fut_;
};
class MySequenceThread : public MMDeviceThreadBase
{
friend class CIDSPeak;
enum { default_numImages = 1, default_intervalMS = 100 };
public:
MySequenceThread(CIDSPeak* pCam);
~MySequenceThread();
void Stop();
void Start(long numImages, double intervalMs);
bool IsStopped();
void Suspend();
bool IsSuspended();
void Resume();
double GetIntervalMs() { return intervalMs_; }
//void SetIntervalMs(double intervalms);
void SetLength(long images) { numImages_ = images; }
long GetLength() const { return numImages_; }
long GetImageCounter() { return imageCounter_; }
MM::MMTime GetStartTime() { return startTime_; }
MM::MMTime GetActualDuration() { return actualDuration_; }
private:
int svc(void) throw();
double intervalMs_;
long numImages_;
long imageCounter_;
bool stop_;
bool suspend_;
CIDSPeak* camera_;
MM::MMTime startTime_;
MM::MMTime actualDuration_;
MM::MMTime lastFrameTime_;
MMThreadLock stopLock_;
MMThreadLock suspendLock_;
};
#endif //_IDSPeak_H_