libvisiontransfer  10.8.0
deviceparameters.h
1 /*******************************************************************************
2  * Copyright (c) 2024 Allied Vision Technologies GmbH
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *******************************************************************************/
14 
15 #ifndef VISIONTRANSFER_DEVICEPARAMETERS_H
16 #define VISIONTRANSFER_DEVICEPARAMETERS_H
17 
18 #include "visiontransfer/common.h"
19 #include "visiontransfer/types.h"
20 #include "visiontransfer/deviceinfo.h"
21 #include "visiontransfer/parameterinfo.h"
22 #if VISIONTRANSFER_CPLUSPLUS_VERSION >= 201103L
23 #include "visiontransfer/parameter.h"
24 #include "visiontransfer/parameterset.h"
25 #include <functional>
26 #include <set>
27 #endif
28 
29 #include <map>
30 
31 namespace visiontransfer {
32 
52 class VT_EXPORT DeviceParameters {
53 
54 private:
55  // We follow the pimpl idiom
56  class Pimpl;
57  Pimpl* pimpl;
58 
59 public:
67  DeviceParameters(const DeviceInfo& device);
68 
78  DeviceParameters(const char* address, const char* service = "7683");
79 
80  ~DeviceParameters();
81 
90  bool isConnected() const;
91 
92  // Processing settings
93 
97  enum OperationMode {
99  PASS_THROUGH = 0,
100 
102  RECTIFY = 1,
103 
105  STEREO_MATCHING = 2
106  };
107 
114  OperationMode getOperationMode() {
115  return static_cast<OperationMode>(readIntParameter("operation_mode"));
116  }
117 
124  void setOperationMode(OperationMode mode) {
125  writeIntParameter("operation_mode", static_cast<int>(mode));
126  }
127 
131  int getDisparityOffset() {
132  return readIntParameter("disparity_offset");
133  }
134 
140  void setDisparityOffset(int offset) {
141  writeIntParameter("disparity_offset", offset);
142  }
143 
144  // Algorithmic settings
145 
149  int getStereoMatchingP1Edge() {
150  return readIntParameter("sgm_p1_edge");
151  }
152 
158  void setStereoMatchingP1Edge(int p1) {
159  writeIntParameter("sgm_p1_edge", p1);
160  }
161 
165  int getStereoMatchingP1NoEdge() {
166  return readIntParameter("sgm_p1_no_edge");
167  }
168 
174  void setStereoMatchingP1NoEdge(int p1) {
175  writeIntParameter("sgm_p1_no_edge", p1);
176  }
177 
181  int getStereoMatchingP2Edge() {
182  return readIntParameter("sgm_p2_edge");
183  }
184 
190  void setStereoMatchingP2Edge(int p2) {
191  writeIntParameter("sgm_p2_edge", p2);
192  }
193 
197  int getStereoMatchingP2NoEdge() {
198  return readIntParameter("sgm_p2_no_edge");
199  }
200 
206  void setStereoMatchingP2NoEdge(int p2) {
207  writeIntParameter("sgm_p2_no_edge", p2);
208  }
209 
213  int getStereoMatchingEdgeSensitivity() {
214  return readIntParameter("sgm_edge_sensitivity");
215  }
216 
222  void setStereoMatchingEdgeSensitivity(int sensitivity) {
223  writeIntParameter("sgm_edge_sensitivity", sensitivity);
224  }
225 
230  bool getMaskBorderPixelsEnabled() {
231  return readBoolParameter("mask_border_pixels_enabled");
232  }
233 
238  void setMaskBorderPixelsEnabled(bool enabled) {
239  writeBoolParameter("mask_border_pixels_enabled", enabled);
240  }
241 
245  bool getConsistencyCheckEnabled() {
246  return readBoolParameter("consistency_check_enabled");
247  }
248 
252  void setConsistencyCheckEnabled(bool enabled) {
253  writeBoolParameter("consistency_check_enabled", enabled);
254  }
255 
259  int getConsistencyCheckSensitivity() {
260  return readIntParameter("consistency_check_sensitivity");
261  }
262 
268  void setConsistencyCheckSensitivity(int sensitivity) {
269  writeIntParameter("consistency_check_sensitivity", sensitivity);
270  }
271 
275  bool getUniquenessCheckEnabled() {
276  return readBoolParameter("uniqueness_check_enabled");
277  }
278 
282  void setUniquenessCheckEnabled(bool enabled) {
283  writeBoolParameter("uniqueness_check_enabled", enabled);
284  }
285 
289  int getUniquenessCheckSensitivity() {
290  return readIntParameter("uniqueness_check_sensitivity");
291  }
292 
298  void setUniquenessCheckSensitivity(int sensitivity) {
299  writeIntParameter("uniqueness_check_sensitivity", sensitivity);
300  }
301 
305  bool getTextureFilterEnabled() {
306  return readBoolParameter("texture_filter_enabled");
307  }
308 
312  void setTextureFilterEnabled(bool enabled) {
313  writeBoolParameter("texture_filter_enabled", enabled);
314  }
315 
319  int getTextureFilterSensitivity() {
320  return readIntParameter("texture_filter_sensitivity");
321  }
322 
328  void setTextureFilterSensitivity(int sensitivity) {
329  writeIntParameter("texture_filter_sensitivity", sensitivity);
330  }
331 
335  bool getGapInterpolationEnabled() {
336  return readBoolParameter("gap_interpolation_enabled");
337  }
338 
342  void setGapInterpolationEnabled(bool enabled) {
343  writeBoolParameter("gap_interpolation_enabled", enabled);
344  }
345 
349  bool getNoiseReductionEnabled() {
350  return readBoolParameter("noise_reduction_enabled");
351  }
352 
356  void setNoiseReductionEnabled(bool enabled) {
357  writeBoolParameter("noise_reduction_enabled", enabled);
358  }
359 
363  int getSpeckleFilterIterations() {
364  return readIntParameter("speckle_filter_iterations");
365  }
366 
370  void setSpeckleFilterIterations(int iter) {
371  writeIntParameter("speckle_filter_iterations", iter);
372  }
373 
374  // Exposure and gain settings
375 
379  enum AutoMode {
381  AUTO_EXPOSURE_AND_GAIN = 0,
382 
384  AUTO_EXPOSURE_MANUAL_GAIN = 1,
385 
387  MANUAL_EXPOSURE_AUTO_GAIN = 2,
388 
390  MANUAL_EXPOSURE_MANUAL_GAIN = 3
391  };
392 
397  AutoMode getAutoMode() {
398  return static_cast<AutoMode>(readIntParameter("auto_exposure_mode"));
399  }
400 
405  void setAutoMode(AutoMode mode) {
406  writeIntParameter("auto_exposure_mode", static_cast<int>(mode));
407  }
408 
416  double getAutoTargetIntensity() {
417  return readDoubleParameter("auto_target_intensity");
418  }
419 
427  void setAutoTargetIntensity(double intensity) {
428  writeDoubleParameter("auto_target_intensity", intensity);
429  }
430 
438  double getAutoTargetIntensityThirdCamera() {
439  return readDoubleParameter("auto_target_intensity_color");
440  }
441 
449  void setAutoTargetIntensityThirdCamera(double intensity) {
450  writeDoubleParameter("auto_target_intensity_color", intensity);
451  }
452 
460  double getAutoIntensityDelta() {
461  return readDoubleParameter("auto_intensity_delta");
462  }
463 
471  void setAutoIntensityDelta(double delta) {
472  writeDoubleParameter("auto_intensity_delta", delta);
473  }
474 
479  enum TargetFrame {
481  LEFT_FRAME = 0,
482 
484  RIGHT_FRAME = 1,
485 
487  BOTH_FRAMES = 2,
488  };
489 
494  TargetFrame getAutoTargetFrame() {
495  return static_cast<TargetFrame>(readIntParameter("auto_target_frame"));
496  }
497 
502  void setAutoTargetFrame(TargetFrame target) {
503  writeIntParameter("auto_target_frame", static_cast<int>(target));
504  }
505 
513  int getAutoSkippedFrames() {
514  return readIntParameter("auto_skipped_frames");
515  }
516 
524  void setAutoSkippedFrames(int skipped) {
525  writeIntParameter("auto_skipped_frames", skipped);
526  }
527 
532  double getAutoMaxExposureTime() {
533  return readDoubleParameter("auto_maximum_exposure_time");
534  }
535 
540  void setAutoMaxExposureTime(double time) {
541  writeDoubleParameter("auto_maximum_exposure_time", time);
542  }
543 
548  double getAutoMaxGain() {
549  return readDoubleParameter("auto_maximum_gain");
550  }
551 
556  void setAutoMaxGain(double gain) {
557  writeDoubleParameter("auto_maximum_gain", gain);
558  }
559 
564  double getAutoMaxGainThirdCamera() {
565  return readDoubleParameter("auto_maximum_gain_color");
566  }
567 
572  void setAutoMaxGainThirdCamera(double gain) {
573  writeDoubleParameter("auto_maximum_gain_color", gain);
574  }
575 
585  double getManualExposureTime() {
586  return readDoubleParameter("manual_exposure_time");
587  }
588 
598  void setManualExposureTime(double time) {
599  writeDoubleParameter("manual_exposure_time", time);
600  }
601 
611  double getManualExposureTimeThirdCamera() {
612  return readDoubleParameter("manual_exposure_time_color");
613  }
614 
624  void setManualExposureTimeThirdCamera(double time) {
625  writeDoubleParameter("manual_exposure_time_color", time);
626  }
627 
637  double getManualGain() {
638  return readDoubleParameter("manual_gain");
639  }
640 
650  void setManualGain(double gain) {
651  writeDoubleParameter("manual_gain", gain);
652  }
653 
663  double getManualGainThirdCamera() {
664  return readDoubleParameter("manual_gain_color");
665  }
666 
676  void setManualGainThirdCamera(double gain) {
677  writeDoubleParameter("manual_gain_color", gain);
678  }
679 
683  bool getAutoROIEnabled() {
684  return readBoolParameter("auto_exposure_roi_enabled");
685  }
686 
690  void setAutoROIEnabled(bool enabled) {
691  writeBoolParameter("auto_exposure_roi_enabled", enabled);
692  }
693 
707  void getAutoROI(int& x, int& y, int& width, int& height) {
708  x = readIntParameter("auto_exposure_roi_x");
709  y = readIntParameter("auto_exposure_roi_y");
710  width = readIntParameter("auto_exposure_roi_width");
711  height = readIntParameter("auto_exposure_roi_height");
712  }
713 
727  void setAutoROI(int x, int y, int width, int height) {
728  writeIntParameter("auto_exposure_roi_x", x);
729  writeIntParameter("auto_exposure_roi_y", y);
730  writeIntParameter("auto_exposure_roi_width", width);
731  writeIntParameter("auto_exposure_roi_height", height);
732  }
733 
734  // Gamma settings
735 
741  double getGamma() {
742  return readDoubleParameter("gamma");
743  }
744 
750  void setGamma(double gamma) {
751  writeDoubleParameter("gamma", gamma);
752  }
753 
759  double getGammaThirdCamera() {
760  return readDoubleParameter("gamma_color");
761  }
762 
768  void setGammaThirdCamera(double gamma) {
769  writeDoubleParameter("gamma_color", gamma);
770  }
771 
772 
773 
774  // Trigger and pairing settings
775 
782  int getMaxFrameTimeDifference() {
783  return readIntParameter("max_frame_time_difference_ms");
784  }
785 
792  void setMaxFrameTimeDifference(int diffMs) {
793  writeIntParameter("max_frame_time_difference_ms", diffMs);
794  }
795 
800  double getTriggerFrequency() {
801  return readDoubleParameter("trigger_frequency");
802  }
803 
808  void setTriggerFrequency(double freq) {
809  writeDoubleParameter("trigger_frequency", freq);
810  }
811 
815  bool getTrigger0Enabled() {
816  return readBoolParameter("trigger_0_enabled");
817  }
818 
822  void setTrigger0Enabled(bool enabled) {
823  writeBoolParameter("trigger_0_enabled", enabled);
824  }
825 
829  bool getTrigger0Constant() {
830  return readBoolParameter("trigger_0_constant");
831  }
832 
836  void setTrigger0Constant(bool on) {
837  writeBoolParameter("trigger_0_constant", on);
838  }
839 
844  bool getTrigger0Polarity() {
845  return readBoolParameter("trigger_0_polarity");
846  }
847 
852  void setTrigger0Polarity(bool invert) {
853  writeBoolParameter("trigger_0_polarity", invert);
854  }
855 
859  bool getTrigger1Enabled() {
860  return readBoolParameter("trigger_1_enabled");
861  }
862 
866  void setTrigger1Enabled(bool enabled) {
867  writeBoolParameter("trigger_1_enabled", enabled);
868  }
869 
873  bool getTrigger1Constant() {
874  return readBoolParameter("trigger_1_constant");
875  }
876 
880  void setTrigger1Constant(bool on) {
881  writeBoolParameter("trigger_1_constant", on);
882  }
883 
888  bool getTrigger1Polarity() {
889  return readBoolParameter("trigger_1_polarity");
890  }
891 
896  void setTrigger1Polarity(bool invert) {
897  writeBoolParameter("trigger_1_polarity", invert);
898  }
899 
907  double getTrigger0PulseWidth(int pulse=0) {
908  switch(pulse) {
909  case 0: return readDoubleParameter("trigger_0_pulse_width");
910  case 1: return readDoubleParameter("trigger_0b_pulse_width");
911  case 2: return readDoubleParameter("trigger_0c_pulse_width");
912  case 3: return readDoubleParameter("trigger_0d_pulse_width");
913  case 4: return readDoubleParameter("trigger_0e_pulse_width");
914  case 5: return readDoubleParameter("trigger_0f_pulse_width");
915  case 6: return readDoubleParameter("trigger_0g_pulse_width");
916  case 7: return readDoubleParameter("trigger_0h_pulse_width");
917  default: return -1;
918  }
919  }
920 
928  void setTrigger0PulseWidth(double width, int pulse=0) {
929  switch(pulse) {
930  case 0: writeDoubleParameter("trigger_0_pulse_width", width);break;
931  case 1: writeDoubleParameter("trigger_0b_pulse_width", width);break;
932  case 2: writeDoubleParameter("trigger_0c_pulse_width", width);break;
933  case 3: writeDoubleParameter("trigger_0d_pulse_width", width);break;
934  case 4: writeDoubleParameter("trigger_0e_pulse_width", width);break;
935  case 5: writeDoubleParameter("trigger_0f_pulse_width", width);break;
936  case 6: writeDoubleParameter("trigger_0g_pulse_width", width);break;
937  case 7: writeDoubleParameter("trigger_0h_pulse_width", width);break;
938  default: return;
939  }
940  }
941 
949  double getTrigger1PulseWidth(int pulse=0) {
950  switch(pulse) {
951  case 0: return readDoubleParameter("trigger_1_pulse_width");
952  case 1: return readDoubleParameter("trigger_1b_pulse_width");
953  case 2: return readDoubleParameter("trigger_1c_pulse_width");
954  case 3: return readDoubleParameter("trigger_1d_pulse_width");
955  case 4: return readDoubleParameter("trigger_1e_pulse_width");
956  case 5: return readDoubleParameter("trigger_1f_pulse_width");
957  case 6: return readDoubleParameter("trigger_1g_pulse_width");
958  case 7: return readDoubleParameter("trigger_1h_pulse_width");
959  default: return -1;
960  }
961  }
962 
970  void setTrigger1PulseWidth(double width, int pulse=0) {
971  switch(pulse) {
972  case 0: writeDoubleParameter("trigger_1_pulse_width", width);break;
973  case 1: writeDoubleParameter("trigger_1b_pulse_width", width);break;
974  case 2: writeDoubleParameter("trigger_1c_pulse_width", width);break;
975  case 3: writeDoubleParameter("trigger_1d_pulse_width", width);break;
976  case 4: writeDoubleParameter("trigger_1e_pulse_width", width);break;
977  case 5: writeDoubleParameter("trigger_1f_pulse_width", width);break;
978  case 6: writeDoubleParameter("trigger_1g_pulse_width", width);break;
979  case 7: writeDoubleParameter("trigger_1h_pulse_width", width);break;
980  default: return;
981  }
982  }
983 
988  double getTrigger1Offset() {
989  return readDoubleParameter("trigger_1_offset");
990  }
991 
996  void setTrigger1Offset(double offset) {
997  writeDoubleParameter("trigger_1_offset", offset);
998  }
999 
1003  enum TriggerInputMode {
1005  INTERNAL = 0,
1006 
1008  EXTERNAL = 1,
1009 
1011  SOFTWARE = 2
1012  };
1013 
1017  TriggerInputMode getTriggerInputMode() {
1018  return static_cast<TriggerInputMode>(readIntParameter("trigger_input"));
1019  }
1028  void setTriggerInputMode(TriggerInputMode mode) {
1029  writeIntParameter("trigger_input", static_cast<int>(mode));
1030  }
1031 
1045  int getSkippedTriggerCount() {
1046  return readIntParameter("RT_skipped_trigger_count");
1047  }
1048 
1049  // Auto calibration parameters
1050 
1054  bool getAutoRecalibrationEnabled() {
1055  return readBoolParameter("auto_recalibration_enabled");
1056  }
1057 
1061  void setAutoRecalibrationEnabled(bool enabled) {
1062  writeBoolParameter("auto_recalibration_enabled", enabled);
1063  }
1064 
1068  bool getSaveAutoRecalibration() {
1069  return readBoolParameter("auto_recalibration_permanent");
1070  }
1071 
1075  void setSaveAutoRecalibration(bool save) {
1076  writeBoolParameter("auto_recalibration_permanent", save);
1077  }
1083  bool getSubpixelOptimizationROIEnabled() {
1084  return readBoolParameter("subpixel_optimization_roi_enabled");
1085  }
1086 
1091  void setSubpixelOptimizationROIEnabled(bool enabled) {
1092  writeBoolParameter("subpixel_optimization_roi_enabled", enabled);
1093  }
1094 
1108  void getSubpixelOptimizationROI(int& x, int& y, int& width, int& height) {
1109  x = readIntParameter("subpixel_optimization_roi_x");
1110  y = readIntParameter("subpixel_optimization_roi_y");
1111  width = readIntParameter("subpixel_optimization_roi_width");
1112  height = readIntParameter("subpixel_optimization_roi_height");
1113  }
1114 
1128  void setSubpixelOptimizationROI(int x, int y, int width, int height) {
1129  writeIntParameter("subpixel_optimization_roi_x", x);
1130  writeIntParameter("subpixel_optimization_roi_y", y);
1131  writeIntParameter("subpixel_optimization_roi_width", width);
1132  writeIntParameter("subpixel_optimization_roi_height", height);
1133  }
1134 
1138  void reboot() {
1139  writeBoolParameterUnguarded("reboot", true);
1140  }
1141 
1146  void triggerNow() {
1147  writeBoolParameterUnguarded("trigger_now", true);
1148  }
1149 
1159  DEPRECATED("Use getParameterSet() instead")
1160  std::map<std::string, ParameterInfo> getAllParameters();
1161 
1169  template<typename T>
1170  DEPRECATED("Use setParameter() instead")
1171  void setNamedParameter(const std::string& name, T value);
1172 
1176  template<typename T>
1177  void setParameter(const std::string& name, T value);
1178 
1187  template<typename T>
1188  DEPRECATED("Use getParameter() instead")
1189  T getNamedParameter(const std::string& name);
1190 
1210  void saveParameter(const char* uid, bool blockingCall=true);
1211 
1212 #if VISIONTRANSFER_CPLUSPLUS_VERSION >= 201103L
1213 
1217  bool hasParameter(const std::string& name) const;
1218 
1229  visiontransfer::param::Parameter getParameter(const std::string& name) const;
1230 
1242  visiontransfer::param::ParameterSet getParameterSet() const;
1243 
1264  visiontransfer::param::Parameter pollParameter(const std::string& name, bool blockingCall=true);
1265 
1285  void setParameterUpdateCallback(std::function<void(const std::string& uid)> callback, bool threaded=true);
1286 
1296  void setConnectionStateChangeCallback(std::function<void(visiontransfer::ConnectionState)> callback);
1297 
1310  class VT_EXPORT TransactionLock {
1311  private:
1312  Pimpl* pimpl;
1313  public:
1314  TransactionLock(Pimpl* pimpl);
1315  ~TransactionLock();
1341  void commitAndWait(int maxWaitMilliseconds=1000);
1342  };
1343  friend class TransactionLock;
1344 
1346  std::unique_ptr<TransactionLock> transactionLock();
1347 
1351  void saveParameter(const std::string& uid, bool blockingCall=true);
1352 
1356  void saveParameter(const visiontransfer::param::Parameter& param, bool blockingCall=true);
1357 
1363  void saveParameters(const std::vector<std::string>& uids, bool blockingCall=true);
1364 
1370  void saveParameters(const std::set<std::string>& uids, bool blockingCall=true);
1371 
1377  void saveParameters(std::initializer_list<std::string> uids, bool blockingCall=true);
1378 
1379 #endif
1380 
1381 private:
1382  // This class cannot be copied
1383  DeviceParameters(const DeviceParameters& other);
1384  DeviceParameters& operator=(const DeviceParameters& other);
1385 
1386  // Generic functions for reading parameters
1387  int readIntParameter(const char* id);
1388  double readDoubleParameter(const char* id);
1389  bool readBoolParameter(const char* id);
1390 
1391  // Generic functions for writing parameters
1392  void writeIntParameter(const char* id, int value);
1393  void writeDoubleParameter(const char* id, double value);
1394  void writeBoolParameter(const char* id, bool value);
1395  // Unguarded version used for sending real-time commands (omit reply handshake)
1396  void writeBoolParameterUnguarded(const char* id, bool value);
1397 
1398 };
1399 
1400 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1401 // For source compatibility
1402 DEPRECATED("Use DeviceParameters instead.")
1403 typedef DeviceParameters SceneScanParameters;
1404 #endif
1405 
1406 } // namespace
1407 
1408 #endif
visiontransfer::DeviceParameters::TriggerInputMode
TriggerInputMode
Trigger input modes supported by Nerian stereo devices.
Definition: deviceparameters.h:1027
visiontransfer::DeviceParameters::TransactionLock
A (thread-local) parameter transaction lock for queued writes. [C++11]
Definition: deviceparameters.h:1334
visiontransfer::DeviceParameters::TargetFrame
TargetFrame
Possible options for the target frame selection of the automatic exposure and gain control.
Definition: deviceparameters.h:503
visiontransfer::DeviceParameters
Allows for configuration of the parameters of a Nerian stereo device through a network connection.
Definition: deviceparameters.h:64
visiontransfer::param::ParameterSet
Definition: parameterset.h:59
visiontransfer::param::Parameter
Definition: parameter.h:71
visiontransfer::DeviceParameters::AutoMode
AutoMode
Possible modes of the automatic exposure and gain control.
Definition: deviceparameters.h:403
Allied Vision