Zivid C++ API  2.3.1+1a22cbf1-1
Defining the Future of 3D Machine Vision
SuggestSettingsParameters.h
Go to the documentation of this file.
1 
2 /*******************************************************************************
3  * This file is part of the Zivid 3D Camera API
4  *
5  * Copyright 2015-2022 (C) Zivid AS
6  * All rights reserved.
7  *
8  * Zivid Software License, v1.0
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright notice,
17  * this list of conditions and the following disclaimer in the documentation
18  * and/or other materials provided with the distribution.
19  *
20  * 3. Neither the name of Zivid AS nor the names of its contributors may be used
21  * to endorse or promote products derived from this software without specific
22  * prior written permission.
23  *
24  * 4. This software, with or without modification, must not be used with any
25  * other 3D camera than from Zivid AS.
26  *
27  * 5. Any software provided in binary form under this license must not be
28  * reverse engineered, decompiled, modified and/or disassembled.
29  *
30  * THIS SOFTWARE IS PROVIDED BY ZIVID AS "AS IS" AND ANY EXPRESS OR IMPLIED
31  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
32  * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
33  * DISCLAIMED. IN NO EVENT SHALL ZIVID AS OR CONTRIBUTORS BE LIABLE FOR ANY
34  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
37  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Contact: Zivid Customer Success Team <customersuccess@zivid.com>
42  * Info: http://www.zivid.com
43  ******************************************************************************/
44 
45 #pragma once
46 
47 #include <array>
48 #include <chrono>
49 #include <cmath>
50 #include <ctime>
51 #include <iomanip>
52 #include <memory>
53 #include <set>
54 #include <sstream>
55 #include <string>
56 #include <tuple>
57 #include <utility>
58 #include <vector>
59 
62 #include "Zivid/DataModel/Traits.h"
65 #include "Zivid/Range.h"
66 
67 #ifdef _MSC_VER
68 # pragma warning(push)
69 # pragma warning(disable : 4251) // "X needs to have dll-interface to be used by clients of class Y."
70 #endif
71 
72 namespace Zivid
73 {
74  namespace CaptureAssistant
75  {
78  {
79  public:
81  static constexpr DataModel::NodeType nodeType = DataModel::NodeType::group;
82 
84  static constexpr const char *path{ "" };
85 
87  static constexpr const char *name{ "SuggestSettingsParameters" };
88 
90  static constexpr const char *description{
91  R"description(Used to specify a constraint on the total capture time for the settings suggested by the Capture Assistant, and optionally specify the ambient light frequency. The capture time constraint assumes a computer meeting Zivid's recommended minimum compute power.)description"
92  };
93 
94  static constexpr size_t version{ 1 };
95 
96 #ifndef NO_DOC
97  template<size_t>
98  struct Version;
99 
101 
102  // Short identifier. This value is not guaranteed to be universally unique
103  // Todo(ZIVID-2808): Move this to internal DataModelExt header
104  static constexpr std::array<uint8_t, 3> binaryId{ 's', 's', 'p' };
105 
106 #endif
107 
110  {
111  public:
114 
116  static constexpr const char *path{ "AmbientLightFrequency" };
117 
119  static constexpr const char *name{ "AmbientLightFrequency" };
120 
122  static constexpr const char *description{ R"description(Ambient light frequency)description" };
123 
125  enum class ValueType
126  {
127  none,
128  hz50,
129  hz60
130  };
134 
136  static std::set<ValueType> validValues()
137  {
138  return { ValueType::none, ValueType::hz50, ValueType::hz60 };
139  }
140 
143 
145  explicit constexpr AmbientLightFrequency(ValueType value)
146  : m_value{ verifyValue(value) }
147  {}
148 
150  ValueType value() const;
151 
153  std::string toString() const;
154 
156  friend std::ostream &operator<<(std::ostream &stream, const AmbientLightFrequency::ValueType &value)
157  {
158  return stream << AmbientLightFrequency{ value }.toString();
159  }
160 
162  bool operator==(const AmbientLightFrequency &other) const
163  {
164  return m_value == other.m_value;
165  }
166 
168  bool operator!=(const AmbientLightFrequency &other) const
169  {
170  return m_value != other.m_value;
171  }
172 
174  friend std::ostream &operator<<(std::ostream &stream, const AmbientLightFrequency &value)
175  {
176  return stream << value.toString();
177  }
178 
179  private:
180  void setFromString(const std::string &value);
181 
182  constexpr ValueType verifyValue(const ValueType &value) const
183  {
184  return value == ValueType::none || value == ValueType::hz50 || value == ValueType::hz60
185  ? value
186  : throw std::invalid_argument{
187  "Invalid value: AmbientLightFrequency{ "
188  + std::to_string(static_cast<std::underlying_type<ValueType>::type>(value)) + " }"
189  };
190  }
191 
192  ValueType m_value{ ValueType::none };
193 
194  friend struct DataModel::Detail::Befriend<AmbientLightFrequency>;
195  };
196 
199  {
200  public:
203 
205  static constexpr const char *path{ "MaxCaptureTime" };
206 
208  static constexpr const char *name{ "MaxCaptureTime" };
209 
211  static constexpr const char *description{ R"description(Capture time budget)description" };
212 
214  using ValueType = std::chrono::milliseconds;
215 
218  {
219  return { std::chrono::milliseconds{ 200 }, std::chrono::milliseconds{ 10000 } };
220  }
221 
223  MaxCaptureTime() = default;
224 
226  explicit constexpr MaxCaptureTime(std::chrono::milliseconds value)
227  : m_value{ verifyValue(value) }
228  {}
229 
231  std::chrono::milliseconds value() const;
232 
234  std::string toString() const;
235 
237  bool operator==(const MaxCaptureTime &other) const
238  {
239  return m_value == other.m_value;
240  }
241 
243  bool operator!=(const MaxCaptureTime &other) const
244  {
245  return m_value != other.m_value;
246  }
247 
249  bool operator<(const MaxCaptureTime &other) const
250  {
251  return m_value < other.m_value;
252  }
253 
255  bool operator>(const MaxCaptureTime &other) const
256  {
257  return m_value > other.m_value;
258  }
259 
261  friend std::ostream &operator<<(std::ostream &stream, const MaxCaptureTime &value)
262  {
263  return stream << value.toString();
264  }
265 
266  private:
267  void setFromString(const std::string &value);
268 
269  constexpr ValueType verifyValue(const ValueType &value) const
270  {
271  return validRange().isInRange(value)
272  ? value
273  : throw std::out_of_range{ "MaxCaptureTime{ " + std::to_string(value.count())
274  + " } is not in range ["
275  + std::to_string(validRange().min().count()) + ", "
276  + std::to_string(validRange().max().count()) + "]" };
277  }
278 
279  std::chrono::milliseconds m_value{ 1200 };
280 
281  friend struct DataModel::Detail::Befriend<MaxCaptureTime>;
282  };
283 
284  using Descendants =
285  std::tuple<SuggestSettingsParameters::AmbientLightFrequency, SuggestSettingsParameters::MaxCaptureTime>;
286 
289 
291  explicit SuggestSettingsParameters(const std::string &fileName);
292 
305 #ifndef NO_DOC
306  template<typename... Args,
307  typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0,
308  typename std::enable_if<
309  Zivid::Detail::TypeTraits::AllArgsAreInTuple<Descendants,
310  typename std::decay<Args>::type...>::value,
311  int>::type = 0>
312 #else
313  template<typename... Args>
314 #endif
315  explicit SuggestSettingsParameters(Args &&...args)
316  {
317  using namespace Zivid::Detail::TypeTraits;
318 
319  static_assert(AllArgsDecayedAreUnique<Args...>::value,
320  "Found duplicate types among the arguments passed to SuggestSettingsParameters(...). "
321  "Types should be listed at most once.");
322 
323  set(std::forward<Args>(args)...);
324  }
325 
337 #ifndef NO_DOC
338  template<typename... Args, typename std::enable_if<sizeof...(Args) >= 2, int>::type = 0>
339 #else
340  template<typename... Args>
341 #endif
342  void set(Args &&...args)
343  {
344  using namespace Zivid::Detail::TypeTraits;
345 
346  using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
347  static_assert(AllArgsAreDescendantNodes::value,
348  "All arguments passed to set(...) must be descendant nodes.");
349 
350  static_assert(AllArgsDecayedAreUnique<Args...>::value,
351  "Found duplicate types among the arguments passed to set(...). "
352  "Types should be listed at most once.");
353 
354  Zivid::DataModel::Detail::invokeSetWithEachArgument(*this, std::forward<Args>(args)...);
355  }
356 
369 #ifndef NO_DOC
370  template<typename... Args, typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0>
371 #else
372  template<typename... Args>
373 #endif
374  SuggestSettingsParameters copyWith(Args &&...args) const
375  {
376  using namespace Zivid::Detail::TypeTraits;
377 
378  using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
379  static_assert(AllArgsAreDescendantNodes::value,
380  "All arguments passed to copyWith(...) must be descendant nodes.");
381 
382  static_assert(AllArgsDecayedAreUnique<Args...>::value,
383  "Found duplicate types among the arguments passed to copyWith(...). "
384  "Types should be listed at most once.");
385 
386  auto copy{ *this };
387  copy.set(std::forward<Args>(args)...);
388  return copy;
389  }
390 
393  {
394  return m_ambientLightFrequency;
395  }
396 
399  {
400  return m_ambientLightFrequency;
401  }
402 
405  {
406  m_ambientLightFrequency = value;
407  return *this;
408  }
409 
412  {
413  return m_maxCaptureTime;
414  }
415 
418  {
419  return m_maxCaptureTime;
420  }
421 
424  {
425  m_maxCaptureTime = value;
426  return *this;
427  }
428 
429  template<typename T,
430  typename std::enable_if<std::is_same<T, SuggestSettingsParameters::AmbientLightFrequency>::value,
431  int>::type = 0>
433  {
434  return m_ambientLightFrequency;
435  }
436 
437  template<typename T,
438  typename std::enable_if<std::is_same<T, SuggestSettingsParameters::MaxCaptureTime>::value,
439  int>::type = 0>
441  {
442  return m_maxCaptureTime;
443  }
444 
445  template<size_t i, typename std::enable_if<i == 0, int>::type = 0>
447  {
448  return m_ambientLightFrequency;
449  }
450 
451  template<size_t i, typename std::enable_if<i == 1, int>::type = 0>
453  {
454  return m_maxCaptureTime;
455  }
456 
458  template<typename F>
459  void forEach(const F &f) const
460  {
461  f(m_ambientLightFrequency);
462  f(m_maxCaptureTime);
463  }
464 
466  template<typename F>
467  void forEach(const F &f)
468  {
469  f(m_ambientLightFrequency);
470  f(m_maxCaptureTime);
471  }
472 
474  bool operator==(const SuggestSettingsParameters &other) const;
475 
477  bool operator!=(const SuggestSettingsParameters &other) const;
478 
480  std::string toString() const;
481 
483  friend std::ostream &operator<<(std::ostream &stream, const SuggestSettingsParameters &value)
484  {
485  return stream << value.toString();
486  }
487 
489  void save(const std::string &fileName) const;
490 
492  void load(const std::string &fileName);
493 
494  private:
495  void setFromString(const std::string &value);
496 
497  void setFromString(const std::string &fullPath, const std::string &value);
498 
499  std::string getString(const std::string &fullPath) const;
500 
501  AmbientLightFrequency m_ambientLightFrequency;
502  MaxCaptureTime m_maxCaptureTime;
503 
504  friend struct DataModel::Detail::Befriend<SuggestSettingsParameters>;
505  };
506 
507 #ifndef NO_DOC
508  template<>
509  struct SuggestSettingsParameters::Version<1>
510  {
511  using Type = SuggestSettingsParameters;
512  };
513 #endif
514 
515  } // namespace CaptureAssistant
516 } // namespace Zivid
517 
518 #ifdef _MSC_VER
519 # pragma warning(pop)
520 #endif
521 
522 #ifndef NO_DOC
523 # if !(defined(_MSC_VER) && (_MSC_VER <= 1900))
524 namespace std // NOLINT
525 {
526  template<>
527  struct tuple_size<Zivid::CaptureAssistant::SuggestSettingsParameters> : integral_constant<size_t, 2>
528  {};
529 
530  template<size_t i>
531  struct tuple_element<i, Zivid::CaptureAssistant::SuggestSettingsParameters>
532  {
533  static_assert(i < tuple_size<Zivid::CaptureAssistant::SuggestSettingsParameters>::value,
534  "Index must be less than 2");
535 
536  using type // NOLINT
537  = decltype(declval<Zivid::CaptureAssistant::SuggestSettingsParameters>().get<i>());
538  };
539 
540 } // namespace std
541 # endif
542 #endif
#define ZIVID_CORE_EXPORT
Definition: CoreExport.h:57
Ambient light frequency
Definition: SuggestSettingsParameters.h:110
friend std::ostream & operator<<(std::ostream &stream, const AmbientLightFrequency::ValueType &value)
Operator to serialize ValueType to a stream
Definition: SuggestSettingsParameters.h:156
constexpr AmbientLightFrequency(ValueType value)
Constructor
Definition: SuggestSettingsParameters.h:145
static const AmbientLightFrequency none
none
Definition: SuggestSettingsParameters.h:131
bool operator==(const AmbientLightFrequency &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:162
static std::set< ValueType > validValues()
All valid values of AmbientLightFrequency
Definition: SuggestSettingsParameters.h:136
static const AmbientLightFrequency hz60
hz60
Definition: SuggestSettingsParameters.h:133
friend std::ostream & operator<<(std::ostream &stream, const AmbientLightFrequency &value)
Operator to serialize the value to a stream
Definition: SuggestSettingsParameters.h:174
bool operator!=(const AmbientLightFrequency &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:168
static const AmbientLightFrequency hz50
hz50
Definition: SuggestSettingsParameters.h:132
ValueType
The type of the underlying value
Definition: SuggestSettingsParameters.h:126
Capture time budget
Definition: SuggestSettingsParameters.h:199
bool operator>(const MaxCaptureTime &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:255
bool operator==(const MaxCaptureTime &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:237
bool operator<(const MaxCaptureTime &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:249
static constexpr Range< std::chrono::milliseconds > validRange()
The range of valid values for MaxCaptureTime
Definition: SuggestSettingsParameters.h:217
constexpr MaxCaptureTime(std::chrono::milliseconds value)
Constructor
Definition: SuggestSettingsParameters.h:226
bool operator!=(const MaxCaptureTime &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:243
std::chrono::milliseconds ValueType
The type of the underlying value
Definition: SuggestSettingsParameters.h:214
std::string toString() const
Get the value as string
friend std::ostream & operator<<(std::ostream &stream, const MaxCaptureTime &value)
Operator to serialize the value to a stream
Definition: SuggestSettingsParameters.h:261
std::chrono::milliseconds value() const
Get the value
Used to specify a constraint on the total capture time for the settings suggested by the Capture Assi...
Definition: SuggestSettingsParameters.h:78
std::tuple< SuggestSettingsParameters::AmbientLightFrequency, SuggestSettingsParameters::MaxCaptureTime > Descendants
Definition: SuggestSettingsParameters.h:285
const MaxCaptureTime & maxCaptureTime() const
Get MaxCaptureTime
Definition: SuggestSettingsParameters.h:411
friend std::ostream & operator<<(std::ostream &stream, const SuggestSettingsParameters &value)
Operator to send the value as string to a stream
Definition: SuggestSettingsParameters.h:483
MaxCaptureTime & maxCaptureTime()
Get MaxCaptureTime
Definition: SuggestSettingsParameters.h:417
SuggestSettingsParameters & set(const AmbientLightFrequency &value)
Set AmbientLightFrequency
Definition: SuggestSettingsParameters.h:404
void save(const std::string &fileName) const
Save to the given file
AmbientLightFrequency & ambientLightFrequency()
Get AmbientLightFrequency
Definition: SuggestSettingsParameters.h:398
void set(Args &&...args)
Set multiple arguments
Definition: SuggestSettingsParameters.h:342
const SuggestSettingsParameters::MaxCaptureTime & get() const
Definition: SuggestSettingsParameters.h:440
SuggestSettingsParameters copyWith(Args &&...args) const
Returns a copy of this object with the given argument(s) set to the new value(s)
Definition: SuggestSettingsParameters.h:374
SuggestSettingsParameters(Args &&...args)
Constructor taking variadic number of arguments
Definition: SuggestSettingsParameters.h:315
bool operator!=(const SuggestSettingsParameters &other) const
Inequality operator
SuggestSettingsParameters & set(const MaxCaptureTime &value)
Set MaxCaptureTime
Definition: SuggestSettingsParameters.h:423
bool operator==(const SuggestSettingsParameters &other) const
Equality operator
SuggestSettingsParameters(const std::string &fileName)
Construct SuggestSettingsParameters by loading from file
void forEach(const F &f) const
Run the given function on each direct member with the value of the member as parameter
Definition: SuggestSettingsParameters.h:459
void forEach(const F &f)
Run the given function on each direct member with the value of the member as parameter
Definition: SuggestSettingsParameters.h:467
const AmbientLightFrequency & ambientLightFrequency() const
Get AmbientLightFrequency
Definition: SuggestSettingsParameters.h:392
std::string toString() const
Get the value as string
const SuggestSettingsParameters::AmbientLightFrequency & get() const
Definition: SuggestSettingsParameters.h:432
void load(const std::string &fileName)
Load from the given file
Class describing a range of values for a given type T
Definition: Range.h:58
NodeType
Definition: NodeType.h:56
Ret validRange(const CameraInfo &cameraInfo)
Definition: SettingsInfo.h:158
The main Zivid namespace. All Zivid code is found here
Definition: Application.h:55