Zivid C++ API  2.4.2+1a2e8cfb-1
Defining the Future of 3D Machine Vision
SuggestSettingsParameters.h
Go to the documentation of this file.
1 
2 
3 /*******************************************************************************
4 
5  * This file is part of the Zivid 3D Camera API
6 
7  *
8 
9  * Copyright 2015-2021 (C) Zivid AS
10 
11  * All rights reserved.
12 
13  *
14 
15  * Zivid Software License, v1.0
16 
17  *
18 
19  * Redistribution and use in source and binary forms, with or without
20 
21  * modification, are permitted provided that the following conditions are met:
22 
23  *
24 
25  * 1. Redistributions of source code must retain the above copyright notice,
26 
27  * this list of conditions and the following disclaimer.
28 
29  *
30 
31  * 2. Redistributions in binary form must reproduce the above copyright notice,
32 
33  * this list of conditions and the following disclaimer in the documentation
34 
35  * and/or other materials provided with the distribution.
36 
37  *
38 
39  * 3. Neither the name of Zivid AS nor the names of its contributors may be used
40 
41  * to endorse or promote products derived from this software without specific
42 
43  * prior written permission.
44 
45  *
46 
47  * 4. This software, with or without modification, must not be used with any
48 
49  * other 3D camera than from Zivid AS.
50 
51  *
52 
53  * 5. Any software provided in binary form under this license must not be
54 
55  * reverse engineered, decompiled, modified and/or disassembled.
56 
57  *
58 
59  * THIS SOFTWARE IS PROVIDED BY ZIVID AS "AS IS" AND ANY EXPRESS OR IMPLIED
60 
61  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
62 
63  * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
64 
65  * DISCLAIMED. IN NO EVENT SHALL ZIVID AS OR CONTRIBUTORS BE LIABLE FOR ANY
66 
67  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
68 
69  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
70 
71  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
72 
73  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
74 
75  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
76 
77  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
78 
79  *
80 
81  * Contact: Zivid Customer Success Team <customersuccess@zivid.com>
82 
83  * Info: http://www.zivid.com
84 
85  ******************************************************************************/
86 
87 
88 
89 #pragma once
90 
91 #include <array>
92 #include <chrono>
93 #include <cmath>
94 #include <ctime>
95 #include <iomanip>
96 #include <memory>
97 #include <set>
98 #include <sstream>
99 #include <string>
100 #include <tuple>
101 #include <utility>
102 #include <vector>
103 
106 #include "Zivid/DataModel/Traits.h"
107 #include "Zivid/Detail/CoreExport.h"
108 #include "Zivid/Detail/TypeTraits.h"
109 #include "Zivid/Range.h"
110 
111 #ifdef _MSC_VER
112 # pragma warning(push)
113 # pragma warning(disable : 4251) // "X needs to have dll-interface to be used by clients of class Y."
114 #endif
115 
116 namespace Zivid
117 {
118  namespace CaptureAssistant
119  {
122  {
123  public:
125  static constexpr DataModel::NodeType nodeType = DataModel::NodeType::group;
126 
128  static constexpr const char *path{ "" };
129 
131  static constexpr const char *name{ "SuggestSettingsParameters" };
132 
134  static constexpr const char *description{
135  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"
136  };
137 
138  static constexpr size_t version{ 1 };
139 
140 #ifndef NO_DOC
141  template<size_t>
142  struct Version;
143 
145 
146  // Short identifier. This value is not guaranteed to be universally unique
147  // Todo(ZIVID-2808): Move this to internal DataModelExt header
148  static constexpr std::array<uint8_t, 3> binaryId{ 's', 's', 'p' };
149 
150 #endif
151 
154  {
155  public:
158 
160  static constexpr const char *path{ "AmbientLightFrequency" };
161 
163  static constexpr const char *name{ "AmbientLightFrequency" };
164 
166  static constexpr const char *description{ R"description(Ambient light frequency)description" };
167 
169  enum class ValueType
170  {
171  none,
172  hz50,
173  hz60
174  };
178 
180  static std::set<ValueType> validValues()
181  {
182  return { ValueType::none, ValueType::hz50, ValueType::hz60 };
183  }
184 
187 
189  explicit constexpr AmbientLightFrequency(ValueType value)
190  : m_value{ verifyValue(value) }
191  {}
192 
194  ValueType value() const;
195 
197  std::string toString() const;
198 
200  friend std::ostream &operator<<(std::ostream &stream, const AmbientLightFrequency::ValueType &value)
201  {
202  return stream << AmbientLightFrequency{ value }.toString();
203  }
204 
206  bool operator==(const AmbientLightFrequency &other) const
207  {
208  return m_value == other.m_value;
209  }
210 
212  bool operator!=(const AmbientLightFrequency &other) const
213  {
214  return m_value != other.m_value;
215  }
216 
218  friend std::ostream &operator<<(std::ostream &stream, const AmbientLightFrequency &value)
219  {
220  return stream << value.toString();
221  }
222 
223  private:
224  void setFromString(const std::string &value);
225 
226  constexpr ValueType static verifyValue(const ValueType &value)
227  {
228  return value == ValueType::none || value == ValueType::hz50 || value == ValueType::hz60
229  ? value
230  : throw std::invalid_argument{
231  "Invalid value: AmbientLightFrequency{ "
232  + std::to_string(static_cast<std::underlying_type<ValueType>::type>(value)) + " }"
233  };
234  }
235 
236  ValueType m_value{ ValueType::none };
237 
238  friend struct DataModel::Detail::Befriend<AmbientLightFrequency>;
239  };
240 
243  {
244  public:
247 
249  static constexpr const char *path{ "MaxCaptureTime" };
250 
252  static constexpr const char *name{ "MaxCaptureTime" };
253 
255  static constexpr const char *description{ R"description(Capture time budget)description" };
256 
258  using ValueType = std::chrono::milliseconds;
259 
262  {
263  return { std::chrono::milliseconds{ 200 }, std::chrono::milliseconds{ 10000 } };
264  }
265 
267  MaxCaptureTime() = default;
268 
270  explicit constexpr MaxCaptureTime(std::chrono::milliseconds value)
271  : m_value{ verifyValue(value) }
272  {}
273 
275  std::chrono::milliseconds value() const;
276 
278  std::string toString() const;
279 
281  bool operator==(const MaxCaptureTime &other) const
282  {
283  return m_value == other.m_value;
284  }
285 
287  bool operator!=(const MaxCaptureTime &other) const
288  {
289  return m_value != other.m_value;
290  }
291 
293  bool operator<(const MaxCaptureTime &other) const
294  {
295  return m_value < other.m_value;
296  }
297 
299  bool operator>(const MaxCaptureTime &other) const
300  {
301  return m_value > other.m_value;
302  }
303 
305  friend std::ostream &operator<<(std::ostream &stream, const MaxCaptureTime &value)
306  {
307  return stream << value.toString();
308  }
309 
310  private:
311  void setFromString(const std::string &value);
312 
313  constexpr ValueType static verifyValue(const ValueType &value)
314  {
315  return validRange().isInRange(value)
316  ? value
317  : throw std::out_of_range{ "MaxCaptureTime{ " + std::to_string(value.count())
318  + " } is not in range ["
319  + std::to_string(validRange().min().count()) + ", "
320  + std::to_string(validRange().max().count()) + "]" };
321  }
322 
323  std::chrono::milliseconds m_value{ 1200 };
324 
325  friend struct DataModel::Detail::Befriend<MaxCaptureTime>;
326  };
327 
328  using Descendants =
329  std::tuple<SuggestSettingsParameters::AmbientLightFrequency, SuggestSettingsParameters::MaxCaptureTime>;
330 
333 
335  explicit SuggestSettingsParameters(const std::string &fileName);
336 
349 #ifndef NO_DOC
350  template<typename... Args,
351  typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0,
352  typename std::enable_if<
353  Zivid::Detail::TypeTraits::AllArgsAreInTuple<Descendants,
354  typename std::decay<Args>::type...>::value,
355  int>::type = 0>
356 #else
357  template<typename... Args>
358 #endif
359  explicit SuggestSettingsParameters(Args &&...args)
360  {
361  using namespace Zivid::Detail::TypeTraits;
362 
363  static_assert(AllArgsDecayedAreUnique<Args...>::value,
364  "Found duplicate types among the arguments passed to SuggestSettingsParameters(...). "
365  "Types should be listed at most once.");
366 
367  set(std::forward<Args>(args)...);
368  }
369 
381 #ifndef NO_DOC
382  template<typename... Args, typename std::enable_if<sizeof...(Args) >= 2, int>::type = 0>
383 #else
384  template<typename... Args>
385 #endif
386  void set(Args &&...args)
387  {
388  using namespace Zivid::Detail::TypeTraits;
389 
390  using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
391  static_assert(AllArgsAreDescendantNodes::value,
392  "All arguments passed to set(...) must be descendant nodes.");
393 
394  static_assert(AllArgsDecayedAreUnique<Args...>::value,
395  "Found duplicate types among the arguments passed to set(...). "
396  "Types should be listed at most once.");
397 
398  Zivid::DataModel::Detail::invokeSetWithEachArgument(*this, std::forward<Args>(args)...);
399  }
400 
413 #ifndef NO_DOC
414  template<typename... Args, typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0>
415 #else
416  template<typename... Args>
417 #endif
418  SuggestSettingsParameters copyWith(Args &&...args) const
419  {
420  using namespace Zivid::Detail::TypeTraits;
421 
422  using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
423  static_assert(AllArgsAreDescendantNodes::value,
424  "All arguments passed to copyWith(...) must be descendant nodes.");
425 
426  static_assert(AllArgsDecayedAreUnique<Args...>::value,
427  "Found duplicate types among the arguments passed to copyWith(...). "
428  "Types should be listed at most once.");
429 
430  auto copy{ *this };
431  copy.set(std::forward<Args>(args)...);
432  return copy;
433  }
434 
437  {
438  return m_ambientLightFrequency;
439  }
440 
443  {
444  return m_ambientLightFrequency;
445  }
446 
449  {
450  m_ambientLightFrequency = value;
451  return *this;
452  }
453 
456  {
457  return m_maxCaptureTime;
458  }
459 
462  {
463  return m_maxCaptureTime;
464  }
465 
468  {
469  m_maxCaptureTime = value;
470  return *this;
471  }
472 
473  template<typename T,
474  typename std::enable_if<std::is_same<T, SuggestSettingsParameters::AmbientLightFrequency>::value,
475  int>::type = 0>
477  {
478  return m_ambientLightFrequency;
479  }
480 
481  template<typename T,
482  typename std::enable_if<std::is_same<T, SuggestSettingsParameters::MaxCaptureTime>::value,
483  int>::type = 0>
485  {
486  return m_maxCaptureTime;
487  }
488 
489  template<size_t i, typename std::enable_if<i == 0, int>::type = 0>
491  {
492  return m_ambientLightFrequency;
493  }
494 
495  template<size_t i, typename std::enable_if<i == 1, int>::type = 0>
497  {
498  return m_maxCaptureTime;
499  }
500 
502  template<typename F>
503  void forEach(const F &f) const
504  {
505  f(m_ambientLightFrequency);
506  f(m_maxCaptureTime);
507  }
508 
510  template<typename F>
511  void forEach(const F &f)
512  {
513  f(m_ambientLightFrequency);
514  f(m_maxCaptureTime);
515  }
516 
518  bool operator==(const SuggestSettingsParameters &other) const;
519 
521  bool operator!=(const SuggestSettingsParameters &other) const;
522 
524  std::string toString() const;
525 
527  friend std::ostream &operator<<(std::ostream &stream, const SuggestSettingsParameters &value)
528  {
529  return stream << value.toString();
530  }
531 
533  void save(const std::string &fileName) const;
534 
536  void load(const std::string &fileName);
537 
538  private:
539  void setFromString(const std::string &value);
540 
541  void setFromString(const std::string &fullPath, const std::string &value);
542 
543  std::string getString(const std::string &fullPath) const;
544 
545  AmbientLightFrequency m_ambientLightFrequency;
546  MaxCaptureTime m_maxCaptureTime;
547 
548  friend struct DataModel::Detail::Befriend<SuggestSettingsParameters>;
549  };
550 
551 #ifndef NO_DOC
552  template<>
553  struct SuggestSettingsParameters::Version<1>
554  {
555  using Type = SuggestSettingsParameters;
556  };
557 #endif
558 
559  } // namespace CaptureAssistant
560 } // namespace Zivid
561 
562 #ifdef _MSC_VER
563 # pragma warning(pop)
564 #endif
565 
566 #ifndef NO_DOC
567 # if !(defined(_MSC_VER) && (_MSC_VER <= 1900))
568 namespace std // NOLINT
569 {
570  template<>
571  struct tuple_size<Zivid::CaptureAssistant::SuggestSettingsParameters> : integral_constant<size_t, 2>
572  {};
573 
574  template<size_t i>
575  struct tuple_element<i, Zivid::CaptureAssistant::SuggestSettingsParameters>
576  {
577  static_assert(i < tuple_size<Zivid::CaptureAssistant::SuggestSettingsParameters>::value,
578  "Index must be less than 2");
579 
580  using type // NOLINT
581  = decltype(declval<Zivid::CaptureAssistant::SuggestSettingsParameters>().get<i>());
582  };
583 
584 } // namespace std
585 # endif
586 #endif
#define ZIVID_CORE_EXPORT
Definition: CoreExport.h:101
Ambient light frequency
Definition: SuggestSettingsParameters.h:154
friend std::ostream & operator<<(std::ostream &stream, const AmbientLightFrequency::ValueType &value)
Operator to serialize ValueType to a stream
Definition: SuggestSettingsParameters.h:200
constexpr AmbientLightFrequency(ValueType value)
Constructor
Definition: SuggestSettingsParameters.h:189
static const AmbientLightFrequency none
none
Definition: SuggestSettingsParameters.h:175
bool operator==(const AmbientLightFrequency &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:206
static std::set< ValueType > validValues()
All valid values of AmbientLightFrequency
Definition: SuggestSettingsParameters.h:180
static const AmbientLightFrequency hz60
hz60
Definition: SuggestSettingsParameters.h:177
friend std::ostream & operator<<(std::ostream &stream, const AmbientLightFrequency &value)
Operator to serialize the value to a stream
Definition: SuggestSettingsParameters.h:218
bool operator!=(const AmbientLightFrequency &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:212
static const AmbientLightFrequency hz50
hz50
Definition: SuggestSettingsParameters.h:176
ValueType
The type of the underlying value
Definition: SuggestSettingsParameters.h:170
Capture time budget
Definition: SuggestSettingsParameters.h:243
bool operator>(const MaxCaptureTime &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:299
bool operator==(const MaxCaptureTime &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:281
bool operator<(const MaxCaptureTime &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:293
static constexpr Range< std::chrono::milliseconds > validRange()
The range of valid values for MaxCaptureTime
Definition: SuggestSettingsParameters.h:261
constexpr MaxCaptureTime(std::chrono::milliseconds value)
Constructor
Definition: SuggestSettingsParameters.h:270
bool operator!=(const MaxCaptureTime &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:287
std::chrono::milliseconds ValueType
The type of the underlying value
Definition: SuggestSettingsParameters.h:258
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:305
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:122
std::tuple< SuggestSettingsParameters::AmbientLightFrequency, SuggestSettingsParameters::MaxCaptureTime > Descendants
Definition: SuggestSettingsParameters.h:329
const MaxCaptureTime & maxCaptureTime() const
Get MaxCaptureTime
Definition: SuggestSettingsParameters.h:455
friend std::ostream & operator<<(std::ostream &stream, const SuggestSettingsParameters &value)
Operator to send the value as string to a stream
Definition: SuggestSettingsParameters.h:527
MaxCaptureTime & maxCaptureTime()
Get MaxCaptureTime
Definition: SuggestSettingsParameters.h:461
SuggestSettingsParameters & set(const AmbientLightFrequency &value)
Set AmbientLightFrequency
Definition: SuggestSettingsParameters.h:448
void save(const std::string &fileName) const
Save to the given file
AmbientLightFrequency & ambientLightFrequency()
Get AmbientLightFrequency
Definition: SuggestSettingsParameters.h:442
void set(Args &&...args)
Set multiple arguments
Definition: SuggestSettingsParameters.h:386
const SuggestSettingsParameters::MaxCaptureTime & get() const
Definition: SuggestSettingsParameters.h:484
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:418
SuggestSettingsParameters(Args &&...args)
Constructor taking variadic number of arguments
Definition: SuggestSettingsParameters.h:359
bool operator!=(const SuggestSettingsParameters &other) const
Inequality operator
SuggestSettingsParameters & set(const MaxCaptureTime &value)
Set MaxCaptureTime
Definition: SuggestSettingsParameters.h:467
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:503
void forEach(const F &f)
Run the given function on each direct member with the value of the member as parameter
Definition: SuggestSettingsParameters.h:511
const AmbientLightFrequency & ambientLightFrequency() const
Get AmbientLightFrequency
Definition: SuggestSettingsParameters.h:436
std::string toString() const
Get the value as string
const SuggestSettingsParameters::AmbientLightFrequency & get() const
Definition: SuggestSettingsParameters.h:476
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:102
NodeType
Definition: NodeType.h:100
Ret validRange(const CameraInfo &cameraInfo)
Definition: SettingsInfo.h:200
The main Zivid namespace. All Zivid code is found here
Definition: Application.h:99