Zivid C++ API 2.11.1+de9b5dae-1
SuggestSettingsParameters.h
Go to the documentation of this file.
1/*******************************************************************************
2 * This file is part of the Zivid API
3 *
4 * Copyright 2015-2024 (C) Zivid AS
5 * All rights reserved.
6 *
7 * Zivid Software License, v1.0
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * 3. Neither the name of Zivid AS nor the names of its contributors may be used
20 * to endorse or promote products derived from this software without specific
21 * prior written permission.
22 *
23 * 4. This software, with or without modification, must not be used with any
24 * other 3D camera than from Zivid AS.
25 *
26 * 5. Any software provided in binary form under this license must not be
27 * reverse engineered, decompiled, modified and/or disassembled.
28 *
29 * THIS SOFTWARE IS PROVIDED BY ZIVID AS "AS IS" AND ANY EXPRESS OR IMPLIED
30 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31 * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
32 * DISCLAIMED. IN NO EVENT SHALL ZIVID AS OR CONTRIBUTORS BE LIABLE FOR ANY
33 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
36 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Contact: Zivid Customer Success Team <customersuccess@zivid.com>
41 * Info: http://www.zivid.com
42 ******************************************************************************/
43
44#pragma once
45
46#include <array>
47#include <chrono>
48#include <cmath>
49#include <ctime>
50#include <iomanip>
51#include <memory>
52#include <set>
53#include <sstream>
54#include <string>
55#include <tuple>
56#include <utility>
57#include <vector>
58
64#include "Zivid/Range.h"
65
66#ifdef _MSC_VER
67# pragma warning(push)
68# pragma warning(disable : 4251) // "X needs to have dll-interface to be used by clients of class Y."
69#endif
70
71namespace Zivid
72{
73 namespace CaptureAssistant
74 {
75
79
80 // NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding)
82 {
83 public:
85 static constexpr DataModel::NodeType nodeType = DataModel::NodeType::group;
86
88 static constexpr const char *path{ "" };
89
91 static constexpr const char *name{ "SuggestSettingsParameters" };
92
94 static constexpr const char *description{
95 R"description(Used to specify a constraint on the total capture time for the settings suggested by the Capture Assistant, and
96optionally specify the ambient light frequency.
97)description"
98 };
99
100 static constexpr size_t version{ 1 };
101
102#ifndef NO_DOC
103 template<size_t>
104 struct Version;
105
107
108 // Short identifier. This value is not guaranteed to be universally unique
109 // Todo(ZIVID-2808): Move this to internal DataModelExt header
110 static constexpr std::array<uint8_t, 3> binaryId{ 's', 's', 'p' };
111
112#endif
113
121
122 // NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding)
124 {
125 public:
127 static constexpr DataModel::NodeType nodeType = DataModel::NodeType::leafValue;
128
130 static constexpr const char *path{ "AmbientLightFrequency" };
131
133 static constexpr const char *name{ "AmbientLightFrequency" };
134
136 static constexpr const char *description{
137 R"description(Adapt suggested settings to the ambient light frequency. This can be used to avoid artifacts in the point
138cloud due to AC powered ambient light being mixed in with the camera's projector light.
139
140Select your power grid frequency. 60 Hz is typically used in Japan, Americas, Taiwan, South Korea, and the
141Philippines. 50 Hz is the normal in rest of the world. If ambient light is unproblematic, turn off for
142optimal performance.
143)description"
144 };
145
147 enum class ValueType
148 {
149 none,
150 hz50,
151 hz60
152 };
156
158 static std::set<ValueType> validValues()
159 {
160 return { ValueType::none, ValueType::hz50, ValueType::hz60 };
161 }
162
165
167 explicit constexpr AmbientLightFrequency(ValueType value)
168 : m_value{ verifyValue(value) }
169 {}
170
173
175 std::string toString() const;
176
178 friend std::ostream &operator<<(std::ostream &stream, const AmbientLightFrequency::ValueType &value)
179 {
180 return stream << AmbientLightFrequency{ value }.toString();
181 }
182
184 bool operator==(const AmbientLightFrequency &other) const
185 {
186 return m_value == other.m_value;
187 }
188
190 bool operator!=(const AmbientLightFrequency &other) const
191 {
192 return m_value != other.m_value;
193 }
194
196 friend std::ostream &operator<<(std::ostream &stream, const AmbientLightFrequency &value)
197 {
198 return stream << value.toString();
199 }
200
201 private:
202 void setFromString(const std::string &value);
203
204 constexpr ValueType static verifyValue(const ValueType &value)
205 {
206 return value == ValueType::none || value == ValueType::hz50 || value == ValueType::hz60
207 ? value
208 : throw std::invalid_argument{
209 "Invalid value: AmbientLightFrequency{ "
210 + std::to_string(static_cast<std::underlying_type<ValueType>::type>(value)) + " }"
211 };
212 }
213
214 ValueType m_value{ ValueType::none };
215
216 friend struct DataModel::Detail::Befriend<AmbientLightFrequency>;
217 };
218
223
224 // NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding)
226 {
227 public:
229 static constexpr DataModel::NodeType nodeType = DataModel::NodeType::leafValue;
230
232 static constexpr const char *path{ "MaxCaptureTime" };
233
235 static constexpr const char *name{ "MaxCaptureTime" };
236
238 static constexpr const char *description{
239 R"description(Capture time budget. This budget assumes a high-end computer meeting Zivid's recommendations. The actual
240capture time may differ, based on your computer's performance and (for Zivid 2 and 2+) your network connection
241speed.
242)description"
243 };
244
246 using ValueType = std::chrono::milliseconds;
247
250 {
251 return { std::chrono::milliseconds{ 200 }, std::chrono::milliseconds{ 10000 } };
252 }
253
255 MaxCaptureTime() = default;
256
258 explicit constexpr MaxCaptureTime(std::chrono::milliseconds value)
259 : m_value{ verifyValue(value) }
260 {}
261
263 std::chrono::milliseconds value() const;
264
266 std::string toString() const;
267
269 bool operator==(const MaxCaptureTime &other) const
270 {
271 return m_value == other.m_value;
272 }
273
275 bool operator!=(const MaxCaptureTime &other) const
276 {
277 return m_value != other.m_value;
278 }
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
329 std::tuple<SuggestSettingsParameters::AmbientLightFrequency, SuggestSettingsParameters::MaxCaptureTime>;
330
333
335 explicit SuggestSettingsParameters(const std::string &fileName);
336
349#ifndef NO_DOC
350 template<
351 typename... Args,
352 typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0,
353 typename std::enable_if<
354 Zivid::Detail::TypeTraits::AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>::
355 value,
356 int>::type = 0>
357#else
358 template<typename... Args>
359#endif
360 explicit SuggestSettingsParameters(Args &&...args)
361 {
362 using namespace Zivid::Detail::TypeTraits;
363
364 static_assert(
365 AllArgsDecayedAreUnique<Args...>::value,
366 "Found duplicate types among the arguments passed to SuggestSettingsParameters(...). "
367 "Types should be listed at most once.");
368
369 set(std::forward<Args>(args)...);
370 }
371
383#ifndef NO_DOC
384 template<typename... Args, typename std::enable_if<sizeof...(Args) >= 2, int>::type = 0>
385#else
386 template<typename... Args>
387#endif
388 void set(Args &&...args)
389 {
390 using namespace Zivid::Detail::TypeTraits;
391
392 using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
393 static_assert(
394 AllArgsAreDescendantNodes::value, "All arguments passed to set(...) must be descendant nodes.");
395
396 static_assert(
397 AllArgsDecayedAreUnique<Args...>::value,
398 "Found duplicate types among the arguments passed to set(...). "
399 "Types should be listed at most once.");
400
401 Zivid::DataModel::Detail::invokeSetWithEachArgument(*this, std::forward<Args>(args)...);
402 }
403
416#ifndef NO_DOC
417 template<typename... Args, typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0>
418#else
419 template<typename... Args>
420#endif
422 {
423 using namespace Zivid::Detail::TypeTraits;
424
425 using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
426 static_assert(
427 AllArgsAreDescendantNodes::value,
428 "All arguments passed to copyWith(...) must be descendant nodes.");
429
430 static_assert(
431 AllArgsDecayedAreUnique<Args...>::value,
432 "Found duplicate types among the arguments passed to copyWith(...). "
433 "Types should be listed at most once.");
434
435 auto copy{ *this };
436 copy.set(std::forward<Args>(args)...);
437 return copy;
438 }
439
442 {
443 return m_ambientLightFrequency;
444 }
445
448 {
449 return m_ambientLightFrequency;
450 }
451
454 {
455 m_ambientLightFrequency = value;
456 return *this;
457 }
458
461 {
462 return m_maxCaptureTime;
463 }
464
467 {
468 return m_maxCaptureTime;
469 }
470
473 {
474 m_maxCaptureTime = value;
475 return *this;
476 }
477
478 template<
479 typename T,
480 typename std::enable_if<std::is_same<T, SuggestSettingsParameters::AmbientLightFrequency>::value, int>::
481 type = 0>
483 {
484 return m_ambientLightFrequency;
485 }
486
487 template<
488 typename T,
489 typename std::enable_if<std::is_same<T, SuggestSettingsParameters::MaxCaptureTime>::value, int>::type =
490 0>
492 {
493 return m_maxCaptureTime;
494 }
495
496 template<size_t i, typename std::enable_if<i == 0, int>::type = 0>
498 {
499 return m_ambientLightFrequency;
500 }
501
502 template<size_t i, typename std::enable_if<i == 1, int>::type = 0>
504 {
505 return m_maxCaptureTime;
506 }
507
509 template<typename F>
510 void forEach(const F &f) const
511 {
512 f(m_ambientLightFrequency);
513 f(m_maxCaptureTime);
514 }
515
517 template<typename F>
518 void forEach(const F &f)
519 {
520 f(m_ambientLightFrequency);
521 f(m_maxCaptureTime);
522 }
523
525 bool operator==(const SuggestSettingsParameters &other) const;
526
528 bool operator!=(const SuggestSettingsParameters &other) const;
529
531 std::string toString() const;
532
534 friend std::ostream &operator<<(std::ostream &stream, const SuggestSettingsParameters &value)
535 {
536 return stream << value.toString();
537 }
538
540 void save(const std::string &fileName) const;
541
543 void load(const std::string &fileName);
544
545 private:
546 void setFromString(const std::string &value);
547
548 void setFromString(const std::string &fullPath, const std::string &value);
549
550 std::string getString(const std::string &fullPath) const;
551
552 AmbientLightFrequency m_ambientLightFrequency;
553 MaxCaptureTime m_maxCaptureTime;
554
555 friend struct DataModel::Detail::Befriend<SuggestSettingsParameters>;
556 };
557
558#ifndef NO_DOC
560 namespace Detail
561 {
562 ZIVID_CORE_EXPORT void save(const SuggestSettingsParameters &dataModel, std::ostream &ostream);
563 ZIVID_CORE_EXPORT void load(SuggestSettingsParameters &dataModel, std::istream &istream);
564 } // namespace Detail
565#endif
566
567#ifndef NO_DOC
568 template<>
569 struct SuggestSettingsParameters::Version<1>
570 {
571 using Type = SuggestSettingsParameters;
572 };
573#endif
574
575 } // namespace CaptureAssistant
576} // namespace Zivid
577
578#ifdef _MSC_VER
579# pragma warning(pop)
580#endif
581
582#ifndef NO_DOC
583# if !(defined(_MSC_VER) && (_MSC_VER <= 1900))
584namespace std // NOLINT
585{
586
587 template<>
588 struct tuple_size<Zivid::CaptureAssistant::SuggestSettingsParameters> : integral_constant<size_t, 2>
589 {};
590
591 template<size_t i>
592 struct tuple_element<i, Zivid::CaptureAssistant::SuggestSettingsParameters>
593 {
594 static_assert(
595 i < tuple_size<Zivid::CaptureAssistant::SuggestSettingsParameters>::value,
596 "Index must be less than 2");
597
598 using type // NOLINT
599 = decltype(declval<Zivid::CaptureAssistant::SuggestSettingsParameters>().get<i>());
600 };
601
602} // namespace std
603# endif
604#endif
605
606// If we have access to the DataModel library, automatically include internal DataModel
607// header. This header is necessary for serialization and deserialization.
608#if defined(__has_include) && !defined(NO_DOC)
609# if __has_include( \
610 "Zivid/CaptureAssistant/SuggestSettingsParametersInternal.h") \
611 && __has_include("Zivid/DataModelNodeMetaData.h")
612# include "Zivid/CaptureAssistant/SuggestSettingsParametersInternal.h"
613# endif
614#endif
#define ZIVID_CORE_EXPORT
Definition CoreExport.h:56
Adapt suggested settings to the ambient light frequency. This can be used to avoid artifacts in the p...
Definition SuggestSettingsParameters.h:124
constexpr AmbientLightFrequency(ValueType value)
Constructor.
Definition SuggestSettingsParameters.h:167
static std::set< ValueType > validValues()
All valid values of AmbientLightFrequency.
Definition SuggestSettingsParameters.h:158
static const AmbientLightFrequency none
none
Definition SuggestSettingsParameters.h:153
bool operator==(const AmbientLightFrequency &other) const
Comparison operator.
Definition SuggestSettingsParameters.h:184
static const AmbientLightFrequency hz60
hz60
Definition SuggestSettingsParameters.h:155
friend std::ostream & operator<<(std::ostream &stream, const AmbientLightFrequency::ValueType &value)
Operator to serialize ValueType to a stream.
Definition SuggestSettingsParameters.h:178
bool operator!=(const AmbientLightFrequency &other) const
Comparison operator.
Definition SuggestSettingsParameters.h:190
static const AmbientLightFrequency hz50
hz50
Definition SuggestSettingsParameters.h:154
friend std::ostream & operator<<(std::ostream &stream, const AmbientLightFrequency &value)
Operator to serialize the value to a stream.
Definition SuggestSettingsParameters.h:196
ValueType
The type of the underlying value.
Definition SuggestSettingsParameters.h:148
Capture time budget. This budget assumes a high-end computer meeting Zivid's recommendations....
Definition SuggestSettingsParameters.h:226
bool operator>(const MaxCaptureTime &other) const
Comparison operator.
Definition SuggestSettingsParameters.h:287
bool operator==(const MaxCaptureTime &other) const
Comparison operator.
Definition SuggestSettingsParameters.h:269
bool operator<(const MaxCaptureTime &other) const
Comparison operator.
Definition SuggestSettingsParameters.h:281
static constexpr Range< std::chrono::milliseconds > validRange()
The range of valid values for MaxCaptureTime.
Definition SuggestSettingsParameters.h:249
constexpr MaxCaptureTime(std::chrono::milliseconds value)
Constructor.
Definition SuggestSettingsParameters.h:258
bool operator>=(const MaxCaptureTime &other) const
Comparison operator.
Definition SuggestSettingsParameters.h:299
bool operator<=(const MaxCaptureTime &other) const
Comparison operator.
Definition SuggestSettingsParameters.h:293
bool operator!=(const MaxCaptureTime &other) const
Comparison operator.
Definition SuggestSettingsParameters.h:275
std::chrono::milliseconds ValueType
The type of the underlying value.
Definition SuggestSettingsParameters.h:246
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:82
std::tuple< SuggestSettingsParameters::AmbientLightFrequency, SuggestSettingsParameters::MaxCaptureTime > Descendants
Definition SuggestSettingsParameters.h:329
SuggestSettingsParameters & set(const MaxCaptureTime &value)
Set MaxCaptureTime.
Definition SuggestSettingsParameters.h:472
void save(const std::string &fileName) const
Save to the given file.
void set(Args &&...args)
Set multiple arguments.
Definition SuggestSettingsParameters.h:388
const AmbientLightFrequency & ambientLightFrequency() const
Get AmbientLightFrequency.
Definition SuggestSettingsParameters.h:441
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:421
AmbientLightFrequency & ambientLightFrequency()
Get AmbientLightFrequency.
Definition SuggestSettingsParameters.h:447
MaxCaptureTime & maxCaptureTime()
Get MaxCaptureTime.
Definition SuggestSettingsParameters.h:466
bool operator!=(const SuggestSettingsParameters &other) const
Inequality operator.
const SuggestSettingsParameters::MaxCaptureTime & get() const
Definition SuggestSettingsParameters.h:491
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:510
void forEach(const F &f)
Run the given function on each direct member with the value of the member as parameter.
Definition SuggestSettingsParameters.h:518
const MaxCaptureTime & maxCaptureTime() const
Get MaxCaptureTime.
Definition SuggestSettingsParameters.h:460
SuggestSettingsParameters & set(const AmbientLightFrequency &value)
Set AmbientLightFrequency.
Definition SuggestSettingsParameters.h:453
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:534
void load(const std::string &fileName)
Load from the given file.
const SuggestSettingsParameters::AmbientLightFrequency & get() const
Definition SuggestSettingsParameters.h:482
Class describing a range of values for a given type T.
Definition Range.h:73
NodeType
Definition NodeType.h:55
The main Zivid namespace. All Zivid code is found here.
Definition Application.h:54