Zivid C++ API 2.14.0+e4a0c4a9-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
342 [[nodiscard]] static SuggestSettingsParameters fromSerialized(const std::string &value);
343
349 std::string serialize() const;
350
363#ifndef NO_DOC
364 template<
365 typename... Args,
366 typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0,
367 typename std::enable_if<
368 Zivid::Detail::TypeTraits::AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>::
369 value,
370 int>::type = 0>
371#else
372 template<typename... Args>
373#endif
374 explicit SuggestSettingsParameters(Args &&...args)
375 {
376 using namespace Zivid::Detail::TypeTraits;
377
378 static_assert(
379 AllArgsDecayedAreUnique<Args...>::value,
380 "Found duplicate types among the arguments passed to SuggestSettingsParameters(...). "
381 "Types should be listed at most once.");
382
383 set(std::forward<Args>(args)...);
384 }
385
397#ifndef NO_DOC
398 template<typename... Args, typename std::enable_if<sizeof...(Args) >= 2, int>::type = 0>
399#else
400 template<typename... Args>
401#endif
402 void set(Args &&...args)
403 {
404 using namespace Zivid::Detail::TypeTraits;
405
406 using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
407 static_assert(
408 AllArgsAreDescendantNodes::value, "All arguments passed to set(...) must be descendant nodes.");
409
410 static_assert(
411 AllArgsDecayedAreUnique<Args...>::value,
412 "Found duplicate types among the arguments passed to set(...). "
413 "Types should be listed at most once.");
414
415 Zivid::DataModel::Detail::invokeSetWithEachArgument(*this, std::forward<Args>(args)...);
416 }
417
430#ifndef NO_DOC
431 template<typename... Args, typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0>
432#else
433 template<typename... Args>
434#endif
436 {
437 using namespace Zivid::Detail::TypeTraits;
438
439 using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
440 static_assert(
441 AllArgsAreDescendantNodes::value,
442 "All arguments passed to copyWith(...) must be descendant nodes.");
443
444 static_assert(
445 AllArgsDecayedAreUnique<Args...>::value,
446 "Found duplicate types among the arguments passed to copyWith(...). "
447 "Types should be listed at most once.");
448
449 auto copy{ *this };
450 copy.set(std::forward<Args>(args)...);
451 return copy;
452 }
453
456 {
457 return m_ambientLightFrequency;
458 }
459
462 {
463 return m_ambientLightFrequency;
464 }
465
468 {
469 m_ambientLightFrequency = value;
470 return *this;
471 }
472
475 {
476 return m_maxCaptureTime;
477 }
478
481 {
482 return m_maxCaptureTime;
483 }
484
487 {
488 m_maxCaptureTime = value;
489 return *this;
490 }
491
492 template<
493 typename T,
494 typename std::enable_if<std::is_same<T, SuggestSettingsParameters::AmbientLightFrequency>::value, int>::
495 type = 0>
497 {
498 return m_ambientLightFrequency;
499 }
500
501 template<
502 typename T,
503 typename std::enable_if<std::is_same<T, SuggestSettingsParameters::MaxCaptureTime>::value, int>::type =
504 0>
506 {
507 return m_maxCaptureTime;
508 }
509
510 template<size_t i, typename std::enable_if<i == 0, int>::type = 0>
512 {
513 return m_ambientLightFrequency;
514 }
515
516 template<size_t i, typename std::enable_if<i == 1, int>::type = 0>
518 {
519 return m_maxCaptureTime;
520 }
521
523 template<typename F>
524 void forEach(const F &f) const
525 {
526 f(m_ambientLightFrequency);
527 f(m_maxCaptureTime);
528 }
529
531 template<typename F>
532 void forEach(const F &f)
533 {
534 f(m_ambientLightFrequency);
535 f(m_maxCaptureTime);
536 }
537
539 bool operator==(const SuggestSettingsParameters &other) const;
540
542 bool operator!=(const SuggestSettingsParameters &other) const;
543
545 std::string toString() const;
546
548 friend std::ostream &operator<<(std::ostream &stream, const SuggestSettingsParameters &value)
549 {
550 return stream << value.toString();
551 }
552
554 void save(const std::string &fileName) const;
555
557 void load(const std::string &fileName);
558
559 private:
560 void setFromString(const std::string &value);
561
562 void setFromString(const std::string &fullPath, const std::string &value);
563
564 std::string getString(const std::string &fullPath) const;
565
566 AmbientLightFrequency m_ambientLightFrequency;
567 MaxCaptureTime m_maxCaptureTime;
568
569 friend struct DataModel::Detail::Befriend<SuggestSettingsParameters>;
570 };
571
572#ifndef NO_DOC
573 template<>
574 struct SuggestSettingsParameters::Version<1>
575 {
576 using Type = SuggestSettingsParameters;
577 };
578#endif
579
580 } // namespace CaptureAssistant
581} // namespace Zivid
582
583#ifndef NO_DOC
585namespace Zivid::Detail
586{
587
588 ZIVID_CORE_EXPORT void save(
590 std::ostream &ostream);
591 ZIVID_CORE_EXPORT void load(Zivid::CaptureAssistant::SuggestSettingsParameters &dataModel, std::istream &istream);
592
593 ZIVID_CORE_EXPORT std::vector<uint8_t> serializeToBinaryVector(
595 ZIVID_CORE_EXPORT void deserializeFromBinaryVector(
597 const std::vector<uint8_t> &data);
598
599} // namespace Zivid::Detail
600#endif
601
602#ifdef _MSC_VER
603# pragma warning(pop)
604#endif
605
606#ifndef NO_DOC
607# if !(defined(_MSC_VER) && (_MSC_VER <= 1900))
608namespace std // NOLINT
609{
610
611 template<>
612 struct tuple_size<Zivid::CaptureAssistant::SuggestSettingsParameters> : integral_constant<size_t, 2>
613 {};
614
615 template<size_t i>
616 struct tuple_element<i, Zivid::CaptureAssistant::SuggestSettingsParameters>
617 {
618 static_assert(
619 i < tuple_size<Zivid::CaptureAssistant::SuggestSettingsParameters>::value,
620 "Index must be less than 2");
621
622 using type // NOLINT
623 = decltype(declval<Zivid::CaptureAssistant::SuggestSettingsParameters>().get<i>());
624 };
625
626} // namespace std
627# endif
628#endif
629
630// If we have access to the DataModel library, automatically include internal DataModel
631// header. This header is necessary for serialization and deserialization.
632#if defined(__has_include) && !defined(NO_DOC)
633# if __has_include( \
634 "Zivid/CaptureAssistant/SuggestSettingsParametersInternal.h") \
635 && __has_include("Zivid/DataModelNodeMetaData.h")
636# include "Zivid/CaptureAssistant/SuggestSettingsParametersInternal.h"
637# endif
638#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
SuggestSettingsParameters & set(const MaxCaptureTime &value)
Set MaxCaptureTime.
Definition SuggestSettingsParameters.h:486
void save(const std::string &fileName) const
Save to the given file.
void set(Args &&...args)
Set multiple arguments.
Definition SuggestSettingsParameters.h:402
std::string serialize() const
Serialize to a string.
std::tuple< SuggestSettingsParameters::AmbientLightFrequency, SuggestSettingsParameters::MaxCaptureTime > Descendants
Definition SuggestSettingsParameters.h:328
const AmbientLightFrequency & ambientLightFrequency() const
Get AmbientLightFrequency.
Definition SuggestSettingsParameters.h:455
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:435
static SuggestSettingsParameters fromSerialized(const std::string &value)
Construct a new SuggestSettingsParameters instance from a previously serialized string.
AmbientLightFrequency & ambientLightFrequency()
Get AmbientLightFrequency.
Definition SuggestSettingsParameters.h:461
MaxCaptureTime & maxCaptureTime()
Get MaxCaptureTime.
Definition SuggestSettingsParameters.h:480
bool operator!=(const SuggestSettingsParameters &other) const
Inequality operator.
const SuggestSettingsParameters::MaxCaptureTime & get() const
Definition SuggestSettingsParameters.h:505
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:524
void forEach(const F &f)
Run the given function on each direct member with the value of the member as parameter.
Definition SuggestSettingsParameters.h:532
const MaxCaptureTime & maxCaptureTime() const
Get MaxCaptureTime.
Definition SuggestSettingsParameters.h:474
SuggestSettingsParameters & set(const AmbientLightFrequency &value)
Set AmbientLightFrequency.
Definition SuggestSettingsParameters.h:467
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:548
void load(const std::string &fileName)
Load from the given file.
const SuggestSettingsParameters::AmbientLightFrequency & get() const
Definition SuggestSettingsParameters.h:496
Class describing a range of values for a given type T.
Definition Range.h:75
NodeType
Definition NodeType.h:49
Definition EnvironmentInfo.h:74
The main Zivid namespace. All Zivid code is found here.
Definition Application.h:84