Zivid C++ API 2.10.1+50b274e8-7
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-2023 (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
124
125 // NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding)
127 {
128 public:
131
133 static constexpr const char *path{ "" };
134
136 static constexpr const char *name{ "SuggestSettingsParameters" };
137
139 static constexpr const char *description{
140 R"description(Used to specify a constraint on the total capture time for the settings suggested by the Capture Assistant, and
141optionally specify the ambient light frequency.
142)description"
143 };
144
145 static constexpr size_t version{ 1 };
146
147#ifndef NO_DOC
148 template<size_t>
149 struct Version;
150
152
153 // Short identifier. This value is not guaranteed to be universally unique
154 // Todo(ZIVID-2808): Move this to internal DataModelExt header
155 static constexpr std::array<uint8_t, 3> binaryId{ 's', 's', 'p' };
156
157#endif
158
166
167 // NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding)
169 {
170 public:
173
175 static constexpr const char *path{ "AmbientLightFrequency" };
176
178 static constexpr const char *name{ "AmbientLightFrequency" };
179
181 static constexpr const char *description{
182 R"description(Adapt suggested settings to the ambient light frequency. This can be used to avoid artifacts in the point
183cloud due to AC powered ambient light being mixed in with the camera's projector light.
184
185Select your power grid frequency. 60 Hz is typically used in Japan, Americas, Taiwan, South Korea, and the
186Philippines. 50 Hz is the normal in rest of the world. If ambient light is unproblematic, turn off for
187optimal performance.
188)description"
189 };
190
192 enum class ValueType
193 {
194 none,
195 hz50,
196 hz60
197 };
201
203 static std::set<ValueType> validValues()
204 {
205 return { ValueType::none, ValueType::hz50, ValueType::hz60 };
206 }
207
210
212 explicit constexpr AmbientLightFrequency(ValueType value)
213 : m_value{ verifyValue(value) }
214 {}
215
218
220 std::string toString() const;
221
223 friend std::ostream &operator<<(std::ostream &stream, const AmbientLightFrequency::ValueType &value)
224 {
225 return stream << AmbientLightFrequency{ value }.toString();
226 }
227
229 bool operator==(const AmbientLightFrequency &other) const
230 {
231 return m_value == other.m_value;
232 }
233
235 bool operator!=(const AmbientLightFrequency &other) const
236 {
237 return m_value != other.m_value;
238 }
239
241 friend std::ostream &operator<<(std::ostream &stream, const AmbientLightFrequency &value)
242 {
243 return stream << value.toString();
244 }
245
246 private:
247 void setFromString(const std::string &value);
248
249 constexpr ValueType static verifyValue(const ValueType &value)
250 {
251 return value == ValueType::none || value == ValueType::hz50 || value == ValueType::hz60
252 ? value
253 : throw std::invalid_argument{
254 "Invalid value: AmbientLightFrequency{ "
255 + std::to_string(static_cast<std::underlying_type<ValueType>::type>(value)) + " }"
256 };
257 }
258
259 ValueType m_value{ ValueType::none };
260
261 friend struct DataModel::Detail::Befriend<AmbientLightFrequency>;
262 };
263
268
269 // NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding)
271 {
272 public:
275
277 static constexpr const char *path{ "MaxCaptureTime" };
278
280 static constexpr const char *name{ "MaxCaptureTime" };
281
283 static constexpr const char *description{
284 R"description(Capture time budget. This budget assumes a high-end computer meeting Zivid's recommendations. The actual
285capture time may differ, based on your computer's performance and (for Zivid 2 and 2+) your network connection
286speed.
287)description"
288 };
289
291 using ValueType = std::chrono::milliseconds;
292
295 {
296 return { std::chrono::milliseconds{ 200 }, std::chrono::milliseconds{ 10000 } };
297 }
298
300 MaxCaptureTime() = default;
301
303 explicit constexpr MaxCaptureTime(std::chrono::milliseconds value)
304 : m_value{ verifyValue(value) }
305 {}
306
308 std::chrono::milliseconds value() const;
309
311 std::string toString() const;
312
314 bool operator==(const MaxCaptureTime &other) const
315 {
316 return m_value == other.m_value;
317 }
318
320 bool operator!=(const MaxCaptureTime &other) const
321 {
322 return m_value != other.m_value;
323 }
324
326 bool operator<(const MaxCaptureTime &other) const
327 {
328 return m_value < other.m_value;
329 }
330
332 bool operator>(const MaxCaptureTime &other) const
333 {
334 return m_value > other.m_value;
335 }
336
338 bool operator<=(const MaxCaptureTime &other) const
339 {
340 return m_value <= other.m_value;
341 }
342
344 bool operator>=(const MaxCaptureTime &other) const
345 {
346 return m_value >= other.m_value;
347 }
348
350 friend std::ostream &operator<<(std::ostream &stream, const MaxCaptureTime &value)
351 {
352 return stream << value.toString();
353 }
354
355 private:
356 void setFromString(const std::string &value);
357
358 constexpr ValueType static verifyValue(const ValueType &value)
359 {
360 return validRange().isInRange(value)
361 ? value
362 : throw std::out_of_range{ "MaxCaptureTime{ " + std::to_string(value.count())
363 + " } is not in range ["
364 + std::to_string(validRange().min().count()) + ", "
365 + std::to_string(validRange().max().count()) + "]" };
366 }
367
368 std::chrono::milliseconds m_value{ 1200 };
369
370 friend struct DataModel::Detail::Befriend<MaxCaptureTime>;
371 };
372
374 std::tuple<SuggestSettingsParameters::AmbientLightFrequency, SuggestSettingsParameters::MaxCaptureTime>;
375
378
380 explicit SuggestSettingsParameters(const std::string &fileName);
381
394#ifndef NO_DOC
395 template<
396 typename... Args,
397 typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0,
398 typename std::enable_if<
399 Zivid::Detail::TypeTraits::AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>::
400 value,
401 int>::type = 0>
402#else
403 template<typename... Args>
404#endif
405 explicit SuggestSettingsParameters(Args &&...args)
406 {
407 using namespace Zivid::Detail::TypeTraits;
408
409 static_assert(
410 AllArgsDecayedAreUnique<Args...>::value,
411 "Found duplicate types among the arguments passed to SuggestSettingsParameters(...). "
412 "Types should be listed at most once.");
413
414 set(std::forward<Args>(args)...);
415 }
416
428#ifndef NO_DOC
429 template<typename... Args, typename std::enable_if<sizeof...(Args) >= 2, int>::type = 0>
430#else
431 template<typename... Args>
432#endif
433 void set(Args &&...args)
434 {
435 using namespace Zivid::Detail::TypeTraits;
436
437 using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
438 static_assert(
439 AllArgsAreDescendantNodes::value, "All arguments passed to set(...) must be descendant nodes.");
440
441 static_assert(
442 AllArgsDecayedAreUnique<Args...>::value,
443 "Found duplicate types among the arguments passed to set(...). "
444 "Types should be listed at most once.");
445
446 Zivid::DataModel::Detail::invokeSetWithEachArgument(*this, std::forward<Args>(args)...);
447 }
448
461#ifndef NO_DOC
462 template<typename... Args, typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0>
463#else
464 template<typename... Args>
465#endif
467 {
468 using namespace Zivid::Detail::TypeTraits;
469
470 using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
471 static_assert(
472 AllArgsAreDescendantNodes::value,
473 "All arguments passed to copyWith(...) must be descendant nodes.");
474
475 static_assert(
476 AllArgsDecayedAreUnique<Args...>::value,
477 "Found duplicate types among the arguments passed to copyWith(...). "
478 "Types should be listed at most once.");
479
480 auto copy{ *this };
481 copy.set(std::forward<Args>(args)...);
482 return copy;
483 }
484
487 {
488 return m_ambientLightFrequency;
489 }
490
493 {
494 return m_ambientLightFrequency;
495 }
496
499 {
500 m_ambientLightFrequency = value;
501 return *this;
502 }
503
506 {
507 return m_maxCaptureTime;
508 }
509
512 {
513 return m_maxCaptureTime;
514 }
515
518 {
519 m_maxCaptureTime = value;
520 return *this;
521 }
522
523 template<
524 typename T,
525 typename std::enable_if<std::is_same<T, SuggestSettingsParameters::AmbientLightFrequency>::value, int>::
526 type = 0>
528 {
529 return m_ambientLightFrequency;
530 }
531
532 template<
533 typename T,
534 typename std::enable_if<std::is_same<T, SuggestSettingsParameters::MaxCaptureTime>::value, int>::type =
535 0>
537 {
538 return m_maxCaptureTime;
539 }
540
541 template<size_t i, typename std::enable_if<i == 0, int>::type = 0>
543 {
544 return m_ambientLightFrequency;
545 }
546
547 template<size_t i, typename std::enable_if<i == 1, int>::type = 0>
549 {
550 return m_maxCaptureTime;
551 }
552
554 template<typename F>
555 void forEach(const F &f) const
556 {
557 f(m_ambientLightFrequency);
558 f(m_maxCaptureTime);
559 }
560
562 template<typename F>
563 void forEach(const F &f)
564 {
565 f(m_ambientLightFrequency);
566 f(m_maxCaptureTime);
567 }
568
570 bool operator==(const SuggestSettingsParameters &other) const;
571
573 bool operator!=(const SuggestSettingsParameters &other) const;
574
576 std::string toString() const;
577
579 friend std::ostream &operator<<(std::ostream &stream, const SuggestSettingsParameters &value)
580 {
581 return stream << value.toString();
582 }
583
585 void save(const std::string &fileName) const;
586
588 void load(const std::string &fileName);
589
590 private:
591 void setFromString(const std::string &value);
592
593 void setFromString(const std::string &fullPath, const std::string &value);
594
595 std::string getString(const std::string &fullPath) const;
596
597 AmbientLightFrequency m_ambientLightFrequency;
598 MaxCaptureTime m_maxCaptureTime;
599
600 friend struct DataModel::Detail::Befriend<SuggestSettingsParameters>;
601 };
602
603#ifndef NO_DOC
605 namespace Detail
606 {
607 ZIVID_CORE_EXPORT void save(const SuggestSettingsParameters &dataModel, std::ostream &ostream);
608 ZIVID_CORE_EXPORT void load(SuggestSettingsParameters &dataModel, std::istream &istream);
609 } // namespace Detail
610#endif
611
612#ifndef NO_DOC
613 template<>
614 struct SuggestSettingsParameters::Version<1>
615 {
616 using Type = SuggestSettingsParameters;
617 };
618#endif
619
620 } // namespace CaptureAssistant
621} // namespace Zivid
622
623#ifdef _MSC_VER
624# pragma warning(pop)
625#endif
626
627#ifndef NO_DOC
628# if !(defined(_MSC_VER) && (_MSC_VER <= 1900))
629namespace std // NOLINT
630{
631
632 template<>
633 struct tuple_size<Zivid::CaptureAssistant::SuggestSettingsParameters> : integral_constant<size_t, 2>
634 {};
635
636 template<size_t i>
637 struct tuple_element<i, Zivid::CaptureAssistant::SuggestSettingsParameters>
638 {
639 static_assert(
640 i < tuple_size<Zivid::CaptureAssistant::SuggestSettingsParameters>::value,
641 "Index must be less than 2");
642
643 using type // NOLINT
644 = decltype(declval<Zivid::CaptureAssistant::SuggestSettingsParameters>().get<i>());
645 };
646
647} // namespace std
648# endif
649#endif
650
651// If we have access to the DataModel library, automatically include internal DataModel
652// header. This header is necessary for serialization and deserialization.
653#if defined(__has_include) && !defined(NO_DOC)
654# if __has_include( \
655 "Zivid/CaptureAssistant/SuggestSettingsParametersInternal.h") \
656 && __has_include("Zivid/DataModelNodeMetaData.h")
657# include "Zivid/CaptureAssistant/SuggestSettingsParametersInternal.h"
658# endif
659#endif
#define ZIVID_CORE_EXPORT
Definition: CoreExport.h:101
Adapt suggested settings to the ambient light frequency. This can be used to avoid artifacts in the p...
Definition: SuggestSettingsParameters.h:169
constexpr AmbientLightFrequency(ValueType value)
Constructor
Definition: SuggestSettingsParameters.h:212
static std::set< ValueType > validValues()
All valid values of AmbientLightFrequency
Definition: SuggestSettingsParameters.h:203
static const AmbientLightFrequency none
none
Definition: SuggestSettingsParameters.h:198
bool operator==(const AmbientLightFrequency &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:229
static const AmbientLightFrequency hz60
hz60
Definition: SuggestSettingsParameters.h:200
friend std::ostream & operator<<(std::ostream &stream, const AmbientLightFrequency::ValueType &value)
Operator to serialize ValueType to a stream
Definition: SuggestSettingsParameters.h:223
bool operator!=(const AmbientLightFrequency &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:235
static const AmbientLightFrequency hz50
hz50
Definition: SuggestSettingsParameters.h:199
friend std::ostream & operator<<(std::ostream &stream, const AmbientLightFrequency &value)
Operator to serialize the value to a stream
Definition: SuggestSettingsParameters.h:241
ValueType
The type of the underlying value
Definition: SuggestSettingsParameters.h:193
Capture time budget. This budget assumes a high-end computer meeting Zivid's recommendations....
Definition: SuggestSettingsParameters.h:271
bool operator>(const MaxCaptureTime &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:332
bool operator==(const MaxCaptureTime &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:314
bool operator<(const MaxCaptureTime &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:326
static constexpr Range< std::chrono::milliseconds > validRange()
The range of valid values for MaxCaptureTime
Definition: SuggestSettingsParameters.h:294
constexpr MaxCaptureTime(std::chrono::milliseconds value)
Constructor
Definition: SuggestSettingsParameters.h:303
bool operator>=(const MaxCaptureTime &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:344
bool operator<=(const MaxCaptureTime &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:338
bool operator!=(const MaxCaptureTime &other) const
Comparison operator
Definition: SuggestSettingsParameters.h:320
std::chrono::milliseconds ValueType
The type of the underlying value
Definition: SuggestSettingsParameters.h:291
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:350
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:127
std::tuple< SuggestSettingsParameters::AmbientLightFrequency, SuggestSettingsParameters::MaxCaptureTime > Descendants
Definition: SuggestSettingsParameters.h:374
SuggestSettingsParameters & set(const MaxCaptureTime &value)
Set MaxCaptureTime
Definition: SuggestSettingsParameters.h:517
void save(const std::string &fileName) const
Save to the given file
void set(Args &&...args)
Set multiple arguments
Definition: SuggestSettingsParameters.h:433
const AmbientLightFrequency & ambientLightFrequency() const
Get AmbientLightFrequency
Definition: SuggestSettingsParameters.h:486
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:466
SuggestSettingsParameters(Args &&...args)
Constructor taking variadic number of arguments
Definition: SuggestSettingsParameters.h:405
AmbientLightFrequency & ambientLightFrequency()
Get AmbientLightFrequency
Definition: SuggestSettingsParameters.h:492
MaxCaptureTime & maxCaptureTime()
Get MaxCaptureTime
Definition: SuggestSettingsParameters.h:511
bool operator!=(const SuggestSettingsParameters &other) const
Inequality operator
const SuggestSettingsParameters::MaxCaptureTime & get() const
Definition: SuggestSettingsParameters.h:536
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:555
void forEach(const F &f)
Run the given function on each direct member with the value of the member as parameter
Definition: SuggestSettingsParameters.h:563
const MaxCaptureTime & maxCaptureTime() const
Get MaxCaptureTime
Definition: SuggestSettingsParameters.h:505
SuggestSettingsParameters & set(const AmbientLightFrequency &value)
Set AmbientLightFrequency
Definition: SuggestSettingsParameters.h:498
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:579
void load(const std::string &fileName)
Load from the given file
const SuggestSettingsParameters::AmbientLightFrequency & get() const
Definition: SuggestSettingsParameters.h:527
Class describing a range of values for a given type T
Definition: Range.h:118
NodeType
Definition: NodeType.h:100
Ret validRange(const CameraInfo &cameraInfo)
Definition: SettingsInfo.h:227
The main Zivid namespace. All Zivid code is found here
Definition: Application.h:99