Zivid C++ API 2.6.1+6cec8609-3
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-2022 (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
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
116namespace Zivid
117{
118 namespace CaptureAssistant
119 {
120
123 {
124 public:
127
129 static constexpr const char *path{ "" };
130
132 static constexpr const char *name{ "SuggestSettingsParameters" };
133
135 static constexpr const char *description{
136 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"
137 };
138
139 static constexpr size_t version{ 1 };
140
141#ifndef NO_DOC
142 template<size_t>
143 struct Version;
144
146
147 // Short identifier. This value is not guaranteed to be universally unique
148 // Todo(ZIVID-2808): Move this to internal DataModelExt header
149 static constexpr std::array<uint8_t, 3> binaryId{ 's', 's', 'p' };
150
151#endif
152
155 {
156 public:
159
161 static constexpr const char *path{ "AmbientLightFrequency" };
162
164 static constexpr const char *name{ "AmbientLightFrequency" };
165
167 static constexpr const char *description{ R"description(Ambient light frequency)description" };
168
170 enum class ValueType
171 {
172 none,
173 hz50,
174 hz60
175 };
179
181 static std::set<ValueType> validValues()
182 {
183 return { ValueType::none, ValueType::hz50, ValueType::hz60 };
184 }
185
188
190 explicit constexpr AmbientLightFrequency(ValueType value)
191 : m_value{ verifyValue(value) }
192 {}
193
196
198 std::string toString() const;
199
201 friend std::ostream &operator<<(std::ostream &stream, const AmbientLightFrequency::ValueType &value)
202 {
203 return stream << AmbientLightFrequency{ value }.toString();
204 }
205
207 bool operator==(const AmbientLightFrequency &other) const
208 {
209 return m_value == other.m_value;
210 }
211
213 bool operator!=(const AmbientLightFrequency &other) const
214 {
215 return m_value != other.m_value;
216 }
217
219 friend std::ostream &operator<<(std::ostream &stream, const AmbientLightFrequency &value)
220 {
221 return stream << value.toString();
222 }
223
224 private:
225 void setFromString(const std::string &value);
226
227 constexpr ValueType static verifyValue(const ValueType &value)
228 {
229 return value == ValueType::none || value == ValueType::hz50 || value == ValueType::hz60
230 ? value
231 : throw std::invalid_argument{
232 "Invalid value: AmbientLightFrequency{ "
233 + std::to_string(static_cast<std::underlying_type<ValueType>::type>(value)) + " }"
234 };
235 }
236
237 ValueType m_value{ ValueType::none };
238
239 friend struct DataModel::Detail::Befriend<AmbientLightFrequency>;
240 };
241
244 {
245 public:
248
250 static constexpr const char *path{ "MaxCaptureTime" };
251
253 static constexpr const char *name{ "MaxCaptureTime" };
254
256 static constexpr const char *description{ R"description(Capture time budget)description" };
257
259 using ValueType = std::chrono::milliseconds;
260
263 {
264 return { std::chrono::milliseconds{ 200 }, std::chrono::milliseconds{ 10000 } };
265 }
266
268 MaxCaptureTime() = default;
269
271 explicit constexpr MaxCaptureTime(std::chrono::milliseconds value)
272 : m_value{ verifyValue(value) }
273 {}
274
276 std::chrono::milliseconds value() const;
277
279 std::string toString() const;
280
282 bool operator==(const MaxCaptureTime &other) const
283 {
284 return m_value == other.m_value;
285 }
286
288 bool operator!=(const MaxCaptureTime &other) const
289 {
290 return m_value != other.m_value;
291 }
292
294 bool operator<(const MaxCaptureTime &other) const
295 {
296 return m_value < other.m_value;
297 }
298
300 bool operator>(const MaxCaptureTime &other) const
301 {
302 return m_value > other.m_value;
303 }
304
306 friend std::ostream &operator<<(std::ostream &stream, const MaxCaptureTime &value)
307 {
308 return stream << value.toString();
309 }
310
311 private:
312 void setFromString(const std::string &value);
313
314 constexpr ValueType static verifyValue(const ValueType &value)
315 {
316 return validRange().isInRange(value)
317 ? value
318 : throw std::out_of_range{ "MaxCaptureTime{ " + std::to_string(value.count())
319 + " } is not in range ["
320 + std::to_string(validRange().min().count()) + ", "
321 + std::to_string(validRange().max().count()) + "]" };
322 }
323
324 std::chrono::milliseconds m_value{ 1200 };
325
326 friend struct DataModel::Detail::Befriend<MaxCaptureTime>;
327 };
328
330 std::tuple<SuggestSettingsParameters::AmbientLightFrequency, SuggestSettingsParameters::MaxCaptureTime>;
331
334
336 explicit SuggestSettingsParameters(const std::string &fileName);
337
350#ifndef NO_DOC
351 template<
352 typename... Args,
353 typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0,
354 typename std::enable_if<
355 Zivid::Detail::TypeTraits::AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>::
356 value,
357 int>::type = 0>
358#else
359 template<typename... Args>
360#endif
361 explicit SuggestSettingsParameters(Args &&...args)
362 {
363 using namespace Zivid::Detail::TypeTraits;
364
365 static_assert(
366 AllArgsDecayedAreUnique<Args...>::value,
367 "Found duplicate types among the arguments passed to SuggestSettingsParameters(...). "
368 "Types should be listed at most once.");
369
370 set(std::forward<Args>(args)...);
371 }
372
384#ifndef NO_DOC
385 template<typename... Args, typename std::enable_if<sizeof...(Args) >= 2, int>::type = 0>
386#else
387 template<typename... Args>
388#endif
389 void set(Args &&...args)
390 {
391 using namespace Zivid::Detail::TypeTraits;
392
393 using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
394 static_assert(
395 AllArgsAreDescendantNodes::value, "All arguments passed to set(...) must be descendant nodes.");
396
397 static_assert(
398 AllArgsDecayedAreUnique<Args...>::value,
399 "Found duplicate types among the arguments passed to set(...). "
400 "Types should be listed at most once.");
401
402 Zivid::DataModel::Detail::invokeSetWithEachArgument(*this, std::forward<Args>(args)...);
403 }
404
417#ifndef NO_DOC
418 template<typename... Args, typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0>
419#else
420 template<typename... Args>
421#endif
423 {
424 using namespace Zivid::Detail::TypeTraits;
425
426 using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
427 static_assert(
428 AllArgsAreDescendantNodes::value,
429 "All arguments passed to copyWith(...) must be descendant nodes.");
430
431 static_assert(
432 AllArgsDecayedAreUnique<Args...>::value,
433 "Found duplicate types among the arguments passed to copyWith(...). "
434 "Types should be listed at most once.");
435
436 auto copy{ *this };
437 copy.set(std::forward<Args>(args)...);
438 return copy;
439 }
440
443 {
444 return m_ambientLightFrequency;
445 }
446
449 {
450 return m_ambientLightFrequency;
451 }
452
455 {
456 m_ambientLightFrequency = value;
457 return *this;
458 }
459
462 {
463 return m_maxCaptureTime;
464 }
465
468 {
469 return m_maxCaptureTime;
470 }
471
474 {
475 m_maxCaptureTime = value;
476 return *this;
477 }
478
479 template<
480 typename T,
481 typename std::enable_if<std::is_same<T, SuggestSettingsParameters::AmbientLightFrequency>::value, int>::
482 type = 0>
484 {
485 return m_ambientLightFrequency;
486 }
487
488 template<
489 typename T,
490 typename std::enable_if<std::is_same<T, SuggestSettingsParameters::MaxCaptureTime>::value, int>::type =
491 0>
493 {
494 return m_maxCaptureTime;
495 }
496
497 template<size_t i, typename std::enable_if<i == 0, int>::type = 0>
499 {
500 return m_ambientLightFrequency;
501 }
502
503 template<size_t i, typename std::enable_if<i == 1, int>::type = 0>
505 {
506 return m_maxCaptureTime;
507 }
508
510 template<typename F>
511 void forEach(const F &f) const
512 {
513 f(m_ambientLightFrequency);
514 f(m_maxCaptureTime);
515 }
516
518 template<typename F>
519 void forEach(const F &f)
520 {
521 f(m_ambientLightFrequency);
522 f(m_maxCaptureTime);
523 }
524
526 bool operator==(const SuggestSettingsParameters &other) const;
527
529 bool operator!=(const SuggestSettingsParameters &other) const;
530
532 std::string toString() const;
533
535 friend std::ostream &operator<<(std::ostream &stream, const SuggestSettingsParameters &value)
536 {
537 return stream << value.toString();
538 }
539
541 void save(const std::string &fileName) const;
542
544 void load(const std::string &fileName);
545
546 private:
547 void setFromString(const std::string &value);
548
549 void setFromString(const std::string &fullPath, const std::string &value);
550
551 std::string getString(const std::string &fullPath) const;
552
553 AmbientLightFrequency m_ambientLightFrequency;
554 MaxCaptureTime m_maxCaptureTime;
555
556 friend struct DataModel::Detail::Befriend<SuggestSettingsParameters>;
557 };
558
559#ifndef NO_DOC
560 template<>
561 struct SuggestSettingsParameters::Version<1>
562 {
563 using Type = SuggestSettingsParameters;
564 };
565#endif
566
567 } // namespace CaptureAssistant
568} // namespace Zivid
569
570#ifdef _MSC_VER
571# pragma warning(pop)
572#endif
573
574#ifndef NO_DOC
575# if !(defined(_MSC_VER) && (_MSC_VER <= 1900))
576namespace std // NOLINT
577{
578
579 template<>
580 struct tuple_size<Zivid::CaptureAssistant::SuggestSettingsParameters> : integral_constant<size_t, 2>
581 {};
582
583 template<size_t i>
584 struct tuple_element<i, Zivid::CaptureAssistant::SuggestSettingsParameters>
585 {
586 static_assert(
587 i < tuple_size<Zivid::CaptureAssistant::SuggestSettingsParameters>::value,
588 "Index must be less than 2");
589
590 using type // NOLINT
591 = decltype(declval<Zivid::CaptureAssistant::SuggestSettingsParameters>().get<i>());
592 };
593
594} // namespace std
595# endif
596#endif
597
598// If we have access to the DataModel library, automatically include internal DataModel
599// header. This header is necessary for serialization and deserialization.
600#if defined(__has_include) && !defined(NO_DOC)
601# if __has_include( \
602 "Zivid/CaptureAssistant/SuggestSettingsParametersInternal.h") \
603 && __has_include("Zivid/DataModelSerializationMetaData.h")
604# include "Zivid/CaptureAssistant/SuggestSettingsParametersInternal.h"
605# endif
606#endif
#define ZIVID_CORE_EXPORT
Definition: CoreExport.h:101
Ambient light frequency
Definition: SuggestSettingsParameters.h:155
constexpr AmbientLightFrequency(ValueType value)
Constructor
Definition: SuggestSettingsParameters.h:190
static std::set< ValueType > validValues()
All valid values of AmbientLightFrequency
Definition: SuggestSettingsParameters.h:181
static const AmbientLightFrequency none
none
Definition: SuggestSettingsParameters.h:176
bool operator==(const AmbientLightFrequency &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:207
static const AmbientLightFrequency hz60
hz60
Definition: SuggestSettingsParameters.h:178
friend std::ostream & operator<<(std::ostream &stream, const AmbientLightFrequency::ValueType &value)
Operator to serialize ValueType to a stream
Definition: SuggestSettingsParameters.h:201
bool operator!=(const AmbientLightFrequency &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:213
static const AmbientLightFrequency hz50
hz50
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:219
ValueType
The type of the underlying value
Definition: SuggestSettingsParameters.h:171
Capture time budget
Definition: SuggestSettingsParameters.h:244
bool operator>(const MaxCaptureTime &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:300
bool operator==(const MaxCaptureTime &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:282
bool operator<(const MaxCaptureTime &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:294
static constexpr Range< std::chrono::milliseconds > validRange()
The range of valid values for MaxCaptureTime
Definition: SuggestSettingsParameters.h:262
constexpr MaxCaptureTime(std::chrono::milliseconds value)
Constructor
Definition: SuggestSettingsParameters.h:271
bool operator!=(const MaxCaptureTime &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:288
std::chrono::milliseconds ValueType
The type of the underlying value
Definition: SuggestSettingsParameters.h:259
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:306
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:123
std::tuple< SuggestSettingsParameters::AmbientLightFrequency, SuggestSettingsParameters::MaxCaptureTime > Descendants
Definition: SuggestSettingsParameters.h:330
SuggestSettingsParameters & set(const MaxCaptureTime &value)
Set MaxCaptureTime
Definition: SuggestSettingsParameters.h:473
void save(const std::string &fileName) const
Save to the given file
void set(Args &&...args)
Set multiple arguments
Definition: SuggestSettingsParameters.h:389
const AmbientLightFrequency & ambientLightFrequency() const
Get AmbientLightFrequency
Definition: SuggestSettingsParameters.h:442
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:422
SuggestSettingsParameters(Args &&...args)
Constructor taking variadic number of arguments
Definition: SuggestSettingsParameters.h:361
AmbientLightFrequency & ambientLightFrequency()
Get AmbientLightFrequency
Definition: SuggestSettingsParameters.h:448
MaxCaptureTime & maxCaptureTime()
Get MaxCaptureTime
Definition: SuggestSettingsParameters.h:467
bool operator!=(const SuggestSettingsParameters &other) const
Inequality operator
const SuggestSettingsParameters::MaxCaptureTime & get() const
Definition: SuggestSettingsParameters.h:492
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:511
void forEach(const F &f)
Run the given function on each direct member with the value of the member as parameter
Definition: SuggestSettingsParameters.h:519
const MaxCaptureTime & maxCaptureTime() const
Get MaxCaptureTime
Definition: SuggestSettingsParameters.h:461
SuggestSettingsParameters & set(const AmbientLightFrequency &value)
Set AmbientLightFrequency
Definition: SuggestSettingsParameters.h:454
std::string toString() const
Get the value as string
friend std::ostream & operator<<(std::ostream &stream, const SuggestSettingsParameters &value)
Operator to send the value as string to a stream
Definition: SuggestSettingsParameters.h:535
void load(const std::string &fileName)
Load from the given file
const SuggestSettingsParameters::AmbientLightFrequency & get() const
Definition: SuggestSettingsParameters.h:483
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:203
The main Zivid namespace. All Zivid code is found here
Definition: Application.h:99