Zivid C++ API 2.13.1+18e79e79-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
65#include "Zivid/Range.h"
66
67#ifdef _MSC_VER
68# pragma warning(push)
69# pragma warning(disable : 4251) // "X needs to have dll-interface to be used by clients of class Y."
70#endif
71
72namespace Zivid
73{
74 namespace CaptureAssistant
75 {
76
80
81 // NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding)
83 {
84 public:
86 static constexpr DataModel::NodeType nodeType = DataModel::NodeType::group;
87
89 static constexpr const char *path{ "" };
90
92 static constexpr const char *name{ "SuggestSettingsParameters" };
93
95 static constexpr const char *description{
96 R"description(Used to specify a constraint on the total capture time for the settings suggested by the Capture Assistant, and
97optionally specify the ambient light frequency.
98)description"
99 };
100
101 static constexpr size_t version{ 1 };
102
103#ifndef NO_DOC
104 template<size_t>
105 struct Version;
106
108
109 // Short identifier. This value is not guaranteed to be universally unique
110 // Todo(ZIVID-2808): Move this to internal DataModelExt header
111 static constexpr std::array<uint8_t, 3> binaryId{ 's', 's', 'p' };
112
113#endif
114
122
123 // NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding)
125 {
126 public:
128 static constexpr DataModel::NodeType nodeType = DataModel::NodeType::leafValue;
129
131 static constexpr const char *path{ "AmbientLightFrequency" };
132
134 static constexpr const char *name{ "AmbientLightFrequency" };
135
137 static constexpr const char *description{
138 R"description(Adapt suggested settings to the ambient light frequency. This can be used to avoid artifacts in the point
139cloud due to AC powered ambient light being mixed in with the camera's projector light.
140
141Select your power grid frequency. 60 Hz is typically used in Japan, Americas, Taiwan, South Korea, and the
142Philippines. 50 Hz is the normal in rest of the world. If ambient light is unproblematic, turn off for
143optimal performance.
144)description"
145 };
146
148 enum class ValueType
149 {
150 none,
151 hz50,
152 hz60
153 };
157
159 static std::set<ValueType> validValues()
160 {
161 return { ValueType::none, ValueType::hz50, ValueType::hz60 };
162 }
163
166
168 explicit constexpr AmbientLightFrequency(ValueType value)
169 : m_value{ verifyValue(value) }
170 {}
171
174
176 std::string toString() const;
177
179 friend std::ostream &operator<<(std::ostream &stream, const AmbientLightFrequency::ValueType &value)
180 {
181 return stream << AmbientLightFrequency{ value }.toString();
182 }
183
185 bool operator==(const AmbientLightFrequency &other) const
186 {
187 return m_value == other.m_value;
188 }
189
191 bool operator!=(const AmbientLightFrequency &other) const
192 {
193 return m_value != other.m_value;
194 }
195
197 friend std::ostream &operator<<(std::ostream &stream, const AmbientLightFrequency &value)
198 {
199 return stream << value.toString();
200 }
201
202 private:
203 void setFromString(const std::string &value);
204
205 constexpr ValueType static verifyValue(const ValueType &value)
206 {
207 return value == ValueType::none || value == ValueType::hz50 || value == ValueType::hz60
208 ? value
209 : throw std::invalid_argument{
210 "Invalid value: AmbientLightFrequency{ "
211 + std::to_string(static_cast<std::underlying_type<ValueType>::type>(value)) + " }"
212 };
213 }
214
215 ValueType m_value{ ValueType::none };
216
217 friend struct DataModel::Detail::Befriend<AmbientLightFrequency>;
218 };
219
224
225 // NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding)
227 {
228 public:
230 static constexpr DataModel::NodeType nodeType = DataModel::NodeType::leafValue;
231
233 static constexpr const char *path{ "MaxCaptureTime" };
234
236 static constexpr const char *name{ "MaxCaptureTime" };
237
239 static constexpr const char *description{
240 R"description(Capture time budget. This budget assumes a high-end computer meeting Zivid's recommendations. The actual
241capture time may differ, based on your computer's performance and (for Zivid 2 and 2+) your network connection
242speed.
243)description"
244 };
245
247 using ValueType = std::chrono::milliseconds;
248
251 {
252 return { std::chrono::milliseconds{ 200 }, std::chrono::milliseconds{ 10000 } };
253 }
254
256 MaxCaptureTime() = default;
257
259 explicit constexpr MaxCaptureTime(std::chrono::milliseconds value)
260 : m_value{ verifyValue(value) }
261 {}
262
264 std::chrono::milliseconds value() const;
265
267 std::string toString() const;
268
270 bool operator==(const MaxCaptureTime &other) const
271 {
272 return m_value == other.m_value;
273 }
274
276 bool operator!=(const MaxCaptureTime &other) const
277 {
278 return m_value != other.m_value;
279 }
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
344
350 std::string serialize() const;
351
364#ifndef NO_DOC
365 template<
366 typename... Args,
367 typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0,
368 typename std::enable_if<
369 Zivid::Detail::TypeTraits::AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>::
370 value,
371 int>::type = 0>
372#else
373 template<typename... Args>
374#endif
375 explicit SuggestSettingsParameters(Args &&...args)
376 {
377 using namespace Zivid::Detail::TypeTraits;
378
379 static_assert(
380 AllArgsDecayedAreUnique<Args...>::value,
381 "Found duplicate types among the arguments passed to SuggestSettingsParameters(...). "
382 "Types should be listed at most once.");
383
384 set(std::forward<Args>(args)...);
385 }
386
398#ifndef NO_DOC
399 template<typename... Args, typename std::enable_if<sizeof...(Args) >= 2, int>::type = 0>
400#else
401 template<typename... Args>
402#endif
403 void set(Args &&...args)
404 {
405 using namespace Zivid::Detail::TypeTraits;
406
407 using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
408 static_assert(
409 AllArgsAreDescendantNodes::value, "All arguments passed to set(...) must be descendant nodes.");
410
411 static_assert(
412 AllArgsDecayedAreUnique<Args...>::value,
413 "Found duplicate types among the arguments passed to set(...). "
414 "Types should be listed at most once.");
415
416 Zivid::DataModel::Detail::invokeSetWithEachArgument(*this, std::forward<Args>(args)...);
417 }
418
431#ifndef NO_DOC
432 template<typename... Args, typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0>
433#else
434 template<typename... Args>
435#endif
437 {
438 using namespace Zivid::Detail::TypeTraits;
439
440 using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
441 static_assert(
442 AllArgsAreDescendantNodes::value,
443 "All arguments passed to copyWith(...) must be descendant nodes.");
444
445 static_assert(
446 AllArgsDecayedAreUnique<Args...>::value,
447 "Found duplicate types among the arguments passed to copyWith(...). "
448 "Types should be listed at most once.");
449
450 auto copy{ *this };
451 copy.set(std::forward<Args>(args)...);
452 return copy;
453 }
454
457 {
458 return m_ambientLightFrequency;
459 }
460
463 {
464 return m_ambientLightFrequency;
465 }
466
469 {
470 m_ambientLightFrequency = value;
471 return *this;
472 }
473
476 {
477 return m_maxCaptureTime;
478 }
479
482 {
483 return m_maxCaptureTime;
484 }
485
488 {
489 m_maxCaptureTime = value;
490 return *this;
491 }
492
493 template<
494 typename T,
495 typename std::enable_if<std::is_same<T, SuggestSettingsParameters::AmbientLightFrequency>::value, int>::
496 type = 0>
498 {
499 return m_ambientLightFrequency;
500 }
501
502 template<
503 typename T,
504 typename std::enable_if<std::is_same<T, SuggestSettingsParameters::MaxCaptureTime>::value, int>::type =
505 0>
507 {
508 return m_maxCaptureTime;
509 }
510
511 template<size_t i, typename std::enable_if<i == 0, int>::type = 0>
513 {
514 return m_ambientLightFrequency;
515 }
516
517 template<size_t i, typename std::enable_if<i == 1, int>::type = 0>
519 {
520 return m_maxCaptureTime;
521 }
522
524 template<typename F>
525 void forEach(const F &f) const
526 {
527 f(m_ambientLightFrequency);
528 f(m_maxCaptureTime);
529 }
530
532 template<typename F>
533 void forEach(const F &f)
534 {
535 f(m_ambientLightFrequency);
536 f(m_maxCaptureTime);
537 }
538
540 bool operator==(const SuggestSettingsParameters &other) const;
541
543 bool operator!=(const SuggestSettingsParameters &other) const;
544
546 std::string toString() const;
547
549 friend std::ostream &operator<<(std::ostream &stream, const SuggestSettingsParameters &value)
550 {
551 return stream << value.toString();
552 }
553
555 void save(const std::string &fileName) const;
556
558 void load(const std::string &fileName);
559
560 private:
561 void setFromString(const std::string &value);
562
563 void setFromString(const std::string &fullPath, const std::string &value);
564
565 std::string getString(const std::string &fullPath) const;
566
567 AmbientLightFrequency m_ambientLightFrequency;
568 MaxCaptureTime m_maxCaptureTime;
569
570 friend struct DataModel::Detail::Befriend<SuggestSettingsParameters>;
571 };
572
573#ifndef NO_DOC
575 namespace Detail
576 {
577 ZIVID_CORE_EXPORT void save(const SuggestSettingsParameters &dataModel, std::ostream &ostream);
578 ZIVID_CORE_EXPORT void load(SuggestSettingsParameters &dataModel, std::istream &istream);
579 } // namespace Detail
580#endif
581
582#ifndef NO_DOC
583 template<>
584 struct SuggestSettingsParameters::Version<1>
585 {
586 using Type = SuggestSettingsParameters;
587 };
588#endif
589
590 } // namespace CaptureAssistant
591} // namespace Zivid
592
593#ifdef _MSC_VER
594# pragma warning(pop)
595#endif
596
597#ifndef NO_DOC
598# if !(defined(_MSC_VER) && (_MSC_VER <= 1900))
599namespace std // NOLINT
600{
601
602 template<>
603 struct tuple_size<Zivid::CaptureAssistant::SuggestSettingsParameters> : integral_constant<size_t, 2>
604 {};
605
606 template<size_t i>
607 struct tuple_element<i, Zivid::CaptureAssistant::SuggestSettingsParameters>
608 {
609 static_assert(
610 i < tuple_size<Zivid::CaptureAssistant::SuggestSettingsParameters>::value,
611 "Index must be less than 2");
612
613 using type // NOLINT
614 = decltype(declval<Zivid::CaptureAssistant::SuggestSettingsParameters>().get<i>());
615 };
616
617} // namespace std
618# endif
619#endif
620
621// If we have access to the DataModel library, automatically include internal DataModel
622// header. This header is necessary for serialization and deserialization.
623#if defined(__has_include) && !defined(NO_DOC)
624# if __has_include( \
625 "Zivid/CaptureAssistant/SuggestSettingsParametersInternal.h") \
626 && __has_include("Zivid/DataModelNodeMetaData.h")
627# include "Zivid/CaptureAssistant/SuggestSettingsParametersInternal.h"
628# endif
629#endif
#define ZIVID_NODISCARD
Definition Attributes.h:49
#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:125
constexpr AmbientLightFrequency(ValueType value)
Constructor.
Definition SuggestSettingsParameters.h:168
static std::set< ValueType > validValues()
All valid values of AmbientLightFrequency.
Definition SuggestSettingsParameters.h:159
static const AmbientLightFrequency none
none
Definition SuggestSettingsParameters.h:154
bool operator==(const AmbientLightFrequency &other) const
Comparison operator.
Definition SuggestSettingsParameters.h:185
static const AmbientLightFrequency hz60
hz60
Definition SuggestSettingsParameters.h:156
friend std::ostream & operator<<(std::ostream &stream, const AmbientLightFrequency::ValueType &value)
Operator to serialize ValueType to a stream.
Definition SuggestSettingsParameters.h:179
bool operator!=(const AmbientLightFrequency &other) const
Comparison operator.
Definition SuggestSettingsParameters.h:191
static const AmbientLightFrequency hz50
hz50
Definition SuggestSettingsParameters.h:155
friend std::ostream & operator<<(std::ostream &stream, const AmbientLightFrequency &value)
Operator to serialize the value to a stream.
Definition SuggestSettingsParameters.h:197
ValueType
The type of the underlying value.
Definition SuggestSettingsParameters.h:149
Capture time budget. This budget assumes a high-end computer meeting Zivid's recommendations....
Definition SuggestSettingsParameters.h:227
bool operator>(const MaxCaptureTime &other) const
Comparison operator.
Definition SuggestSettingsParameters.h:288
bool operator==(const MaxCaptureTime &other) const
Comparison operator.
Definition SuggestSettingsParameters.h:270
bool operator<(const MaxCaptureTime &other) const
Comparison operator.
Definition SuggestSettingsParameters.h:282
static constexpr Range< std::chrono::milliseconds > validRange()
The range of valid values for MaxCaptureTime.
Definition SuggestSettingsParameters.h:250
constexpr MaxCaptureTime(std::chrono::milliseconds value)
Constructor.
Definition SuggestSettingsParameters.h:259
bool operator>=(const MaxCaptureTime &other) const
Comparison operator.
Definition SuggestSettingsParameters.h:300
bool operator<=(const MaxCaptureTime &other) const
Comparison operator.
Definition SuggestSettingsParameters.h:294
bool operator!=(const MaxCaptureTime &other) const
Comparison operator.
Definition SuggestSettingsParameters.h:276
std::chrono::milliseconds ValueType
The type of the underlying value.
Definition SuggestSettingsParameters.h:247
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:83
static ZIVID_NODISCARD SuggestSettingsParameters fromSerialized(const std::string &value)
Construct a new SuggestSettingsParameters instance from a previously serialized string.
SuggestSettingsParameters & set(const MaxCaptureTime &value)
Set MaxCaptureTime.
Definition SuggestSettingsParameters.h:487
void save(const std::string &fileName) const
Save to the given file.
void set(Args &&...args)
Set multiple arguments.
Definition SuggestSettingsParameters.h:403
std::string serialize() const
Serialize to a string.
std::tuple< SuggestSettingsParameters::AmbientLightFrequency, SuggestSettingsParameters::MaxCaptureTime > Descendants
Definition SuggestSettingsParameters.h:329
const AmbientLightFrequency & ambientLightFrequency() const
Get AmbientLightFrequency.
Definition SuggestSettingsParameters.h:456
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:436
AmbientLightFrequency & ambientLightFrequency()
Get AmbientLightFrequency.
Definition SuggestSettingsParameters.h:462
MaxCaptureTime & maxCaptureTime()
Get MaxCaptureTime.
Definition SuggestSettingsParameters.h:481
bool operator!=(const SuggestSettingsParameters &other) const
Inequality operator.
const SuggestSettingsParameters::MaxCaptureTime & get() const
Definition SuggestSettingsParameters.h:506
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:525
void forEach(const F &f)
Run the given function on each direct member with the value of the member as parameter.
Definition SuggestSettingsParameters.h:533
const MaxCaptureTime & maxCaptureTime() const
Get MaxCaptureTime.
Definition SuggestSettingsParameters.h:475
SuggestSettingsParameters & set(const AmbientLightFrequency &value)
Set AmbientLightFrequency.
Definition SuggestSettingsParameters.h:468
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:549
void load(const std::string &fileName)
Load from the given file.
const SuggestSettingsParameters::AmbientLightFrequency & get() const
Definition SuggestSettingsParameters.h:497
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:56