PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusAndorVideoSource.h
Go to the documentation of this file.
1 /*=Plus=header=begin======================================================
2  Program: Plus
3  Copyright (c) Laboratory for Percutaneous Surgery. All rights reserved.
4  See License.txt for details.
5 =========================================================Plus=header=end*/
6 
7 #ifndef __vtkPlusAndorVideoSource_h
8 #define __vtkPlusAndorVideoSource_h
9 
10 #include "vtkPlusDataCollectionExport.h"
11 #include "vtkPlusDevice.h"
12 #include "vtkMultiThreader.h"
13 #include "opencv2/imgproc.hpp"
14 #include "opencv2/imgcodecs.hpp"
15 
25 class vtkPlusDataCollectionExport vtkPlusAndorVideoSource: public vtkPlusDevice
26 {
27 public:
29  static vtkPlusAndorVideoSource* New();
31  virtual void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
32 
34  virtual bool IsTracker() const
35  {
36  return false;
37  }
38 
40  virtual PlusStatus ReadConfiguration(vtkXMLDataElement* config);
41 
43  virtual PlusStatus WriteConfiguration(vtkXMLDataElement* config);
44 
46  virtual PlusStatus NotifyConfigured();
47 
49  virtual std::string GetSdkVersion();
50 
54  enum ShutterMode : int
55  {
56  FullyAuto = 0,
57  PermanentlyOpen = 1,
58  PermanentlyClosed = 2,
59  OpenForFVBSeries = 4,
60  OpenForAnySeries = 5
61  };
62  PlusStatus SetShutter(ShutterMode shutter);
63  ShutterMode GetShutter();
64 
65  PlusStatus SetShutterClosingTimeMilliseconds(int closingTime);
66  PlusStatus SetShutterOpeningTimeMilliseconds(int openingTime);
67 
69  PlusStatus SetExposureTime(float exposureTime);
70  float GetExposureTime();
71 
73  PlusStatus SetHorizontalBins(int bins);
74  PlusStatus SetVerticalBins(int bins);
75 
77  PlusStatus SetHSSpeed(int type, int index);
78 
80  float GetHSSpeed();
81 
83  PlusStatus SetVSSpeedIndex(int index);
84  int GetVSSpeedIndex();
85 
87  float GetVSSpeed();
88 
90  PlusStatus SetPreAmpGainIndex(int preAmpGainIndex);
91  int GetPreAmpGainIndex();
92 
94  float GetPreAmpGain();
95 
103  enum AcquisitionMode : int
104  {
105  SingleScan = 1,
106  Accumulate = 2,
107  Kinetics = 3,
108  FastKinetics = 4,
109  RunTillAbort = 5
110  };
111  PlusStatus SetAcquisitionMode(AcquisitionMode acquisitionMode);
112  AcquisitionMode GetAcquisitionMode();
113 
115  enum ReadMode : int
116  {
117  FullVerticalBinning = 0,
118  MultiTrack = 1,
119  RandomTrack = 2,
120  SingleTrack = 3,
121  Image = 4
122  };
123  PlusStatus SetReadMode(ReadMode setReadMode);
124  ReadMode GetReadMode();
125 
135  enum TriggerMode : int
136  {
137  Internal = 0,
138  External = 1,
139  ExternalStart = 6,
140  ExternalExposure = 7,
141  ExternalFVBEM = 9,
142  SoftwareTrigger = 10,
143  ExternalChargeShifting = 12
144  };
145  PlusStatus SetTriggerMode(TriggerMode triggerMode);
146  TriggerMode GetTriggerMode();
147 
148  PlusStatus SetFrameFieldImageToReferenceTransform(std::array<float, 16> transform);
149  std::vector<double> GetSpacing();
150 
152  PlusStatus SetCoolTemperature(int coolTemp);
153  int GetCoolTemperature();
154 
156  PlusStatus SetSafeTemperature(int safeTemp);
157  int GetSafeTemperature();
158 
160  int GetCurrentTemperature(float* temperature);
161 
163  PlusStatus SetBadPixelCorrectionImage(const std::string badPixelFilePath);
165  {
166  return badPixelCorrection;
167  }
168  PlusStatus SetBiasDarkCorrectionImage(const std::string biasDarkFilePath);
170  {
171  return biasDarkCorrection;
172  }
173  PlusStatus SetFlatCorrectionImage(const std::string flatFilePath);
175  {
176  return flatCorrection;
177  }
178 
180  PlusStatus SetCameraIntrinsics(std::array<double, 9> intrinsics);
181  std::array<double, 9> GetCameraIntrinsics();
182  PlusStatus SetDistortionCoefficients(std::array<double, 4> coefficients);
183  std::array<double, 4> GetDistortionCoefficients();
184 
186  PlusStatus StartBLIFrameAcquisition(int binning, int vsSpeed, int hsSpeed, float exposureTime, int shutterCloseTime=0, int shutterOpenTime=0);
187 
189  PlusStatus StartGrayscaleFrameAcquisition(int binning, int vsSpeed, int hsSpeed, float exposureTime, int shutterCloseTime=0, int shutterOpenTime=0);
190 
192  PlusStatus StartCorrectionFrameAcquisition(std::string correctionFilePath, ShutterMode shutter, int binning, int vsSpeed, int hsSpeed, float exposureTime, int shutterCloseTime=0, int shutterOpenTime=0);
193 
195  PlusStatus AbortAcquisition();
196 
202  PlusStatus SetCoolerMode(int mode);
203  int GetCoolerMode();
204 
206  PlusStatus SetCoolerState(bool coolerState);
207  bool IsCoolerOn();
208 
212  PlusStatus SetRequireCoolTemp(bool RequireCoolTemp);
213  bool GetRequireCoolTemp();
214 
216  void WaitForCooldown();
217 
224  void WaitForWarmup();
225 
227  unsigned int checkStatus(unsigned int returnStatus, std::string functionName);
228 
230  void operator=(const vtkPlusAndorVideoSource&) = delete;
231 
233  PlusStatus SetUseCosmicRayCorrection(bool UseCosmicRayCorrection);
234  bool GetUseCosmicRayCorrection();
235 
237  unsigned int GetCCDStatus();
238 
240  bool IsCCDAcquiring();
241 
243  void PrepareAcquisition();
244 
245  bool WaitForAcquisitionWithTimeout(double maximumWaitTimeInSeconds, int sleepQuantumMilliseconds = 10);
246 
252  bool IsAcquisitionThreadRunning();
253 
254 protected:
257 
260 
262  virtual PlusStatus InternalConnect();
263 
265  virtual PlusStatus InternalDisconnect();
266 
269 
272 
274  PlusStatus InitializeAndorCamera();
275 
276  using DataSourceArray = std::vector<vtkPlusDataSource*>;
277 
279  void InitializePort(DataSourceArray& port);
280 
281  void AdjustBuffers(int horizontalBins, int verticalBins);
282  void AdjustSpacing(int horizontalBins, int verticalBins);
283 
285  void SetCustomFrameFields();
286 
288  PlusStatus AcquireFrame();
289 
291  void AddFrameToDataSource(DataSourceArray& ds);
292 
294  void FindBadCells(int binning);
295 
297  void CorrectBadPixels(int binning, cv::Mat& cvIMG);
298 
300  void ApplyCosmicRayCorrection(int binning, cv::Mat& floatImage);
301 
303  void ApplyFrameCorrections(int binning);
304 
305  static void* AcquireBLIFrameThread(vtkMultiThreader::ThreadInfo* info);
306  static void* AcquireGrayscaleFrameThread(vtkMultiThreader::ThreadInfo* info);
307  static void* AcquireCorrectionFrameThread(vtkMultiThreader::ThreadInfo* info);
308 
312  PlusStatus SetUseFrameCorrections(bool UseFrameCorrections);
313  bool GetUseFrameCorrections();
314 
316  void ResizeFlatCorrectionImage(int binning);
317 
322  {
323  StartGrayscaleFrameAcquisition(-1, -1, -1, -1);
324  return PLUS_SUCCESS;
325  }
326 
331  PlusStatus SetInitializeCoolerState(bool InitializeCoolerState);
332  bool InitializeCoolerState = true;
333 
337  bool RequireCoolTemp = true;
338 
339  PlusStatus TurnCoolerON();
340  PlusStatus TurnCoolerOFF();
341 
343  vtkPlusAndorVideoSource::ShutterMode Shutter = ShutterMode::FullyAuto;
344  int ShutterOpeningTimeMilliseconds = 0;
345  int ShutterClosingTimeMilliseconds = 0;
346  float ExposureTime = 1.0; // seconds
347  int HorizontalBins = 1;
348  int VerticalBins = 1;
349  int HSSpeed[2] = { 0, 1 }; // type, index
350  int VSSpeedIndex = 0;
351  int PreAmpGainIndex = 0;
352  bool UseFrameCorrections = true;
353  bool UseCosmicRayCorrection = true;
354 
356  float effectiveExpTime = 1.0; // seconds
357  int effectiveHBins = 1;
358  int effectiveVBins = 1;
359  int effectiveHSInd = 1; // index
360  int effectiveVSInd = 1; // index
361  vtkPlusAndorVideoSource::ShutterMode effectiveShutter = ShutterMode::FullyAuto;
362  int effectiveShutterOpeningTimeMilliseconds = 0;
363  int effectiveShutterClosingTimeMilliseconds = 0;
364 
365  // TODO: Need to handle differet cases for read/acquisiton modes?
366 
368  AcquisitionMode m_AcquisitionMode = AcquisitionMode::SingleScan;
369 
371  ReadMode m_ReadMode = ReadMode::Image;
372 
374  TriggerMode m_TriggerMode = TriggerMode::Internal;
375 
377  int CoolerMode = 0; // whether to return to ambient temperature on ShutDown
378  int CoolTemperature = -50;
379  int SafeTemperature = 5;
380  float CurrentTemperature = 0.123456789; // easy to spot as uninitialized
381 
382  FrameSizeType frameSize = {1024, 1024, 1};
383  std::vector<uint16_t> rawFrame;
384  double currentTime = UNDEFINED_TIMESTAMP;
385 
386  // {f_x}{0}{c_x}
387  // {0}{f_y}{c_y}
388  // {0}{0}{1}
389  double cameraIntrinsics[9] = { 0 };
390  double distortionCoefficients[4] = { 0 }; // k_1, k_2, p_1, p_2
391  std::string badPixelCorrection; //filepath to bad pixel image
392  std::string flatCorrection; // filepath to master flat image
393  std::string biasDarkCorrection; // filepath to master bias+dark image
394  std::string saveCorrectionPath; // filepath to save new correction images
395 
400 
401  double OutputSpacing[3] = { 0 };
402 
405  std::array<float, 16> imageToReferenceTransform = { 0 };
406 
407  igsioFieldMapType CustomFields;
408 
410  vtkMultiThreader* Threader = vtkMultiThreader::New();
411  int threadID = -1;
412 };
413 
414 #endif
std::vector< uint16_t > rawFrame
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
virtual PlusStatus InternalStopRecording()
Abstract interface for tracker and video devices.
Definition: vtkPlusDevice.h:60
Class for acquiring images from Andor cameras.
virtual bool IsTracker() const
Phidget_MeshMode mode
Definition: phidget22.h:1332
virtual PlusStatus InternalConnect()
igsioStatus PlusStatus
Definition: PlusCommon.h:40
virtual std::string GetSdkVersion()
int port
Definition: phidget22.h:2454
PlusStatus InternalUpdate() override
#define VTK_OVERRIDE
Definition: PlusCommon.h:49
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *)
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *)
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
virtual PlusStatus InternalStartRecording()
std::vector< vtkPlusDataSource * > DataSourceArray
virtual PlusStatus NotifyConfigured()
virtual PlusStatus InternalDisconnect()
double * temperature
Definition: phidget22.h:3821
static vtkPlusDevice * New()