Zivid C++ API 2.14.0+e4a0c4a9-1
SceneConditions.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
76
77 // NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding)
79 {
80 public:
82 static constexpr DataModel::NodeType nodeType = DataModel::NodeType::group;
83
85 static constexpr const char *path{ "" };
86
88 static constexpr const char *name{ "SceneConditions" };
89
91 static constexpr const char *description{
92 R"description(A description of the ambient conditions detected by the camera.
93)description"
94 };
95
96 static constexpr size_t version{ 1 };
97
98#ifndef NO_DOC
99 template<size_t>
100 struct Version;
101
102 using LatestVersion = Zivid::SceneConditions;
103
104 // Short identifier. This value is not guaranteed to be universally unique
105 // Todo(ZIVID-2808): Move this to internal DataModelExt header
106 static constexpr std::array<uint8_t, 3> binaryId{ 'c', 's', 'c' };
107
108#endif
109
112
113 // NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding)
115 {
116 public:
118 static constexpr DataModel::NodeType nodeType = DataModel::NodeType::group;
119
121 static constexpr const char *path{ "AmbientLight" };
122
124 static constexpr const char *name{ "AmbientLight" };
125
127 static constexpr const char *description{ R"description(The ambient light detected by the camera.
128)description" };
129
139
140 // NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding)
142 {
143 public:
145 static constexpr DataModel::NodeType nodeType = DataModel::NodeType::leafValue;
146
148 static constexpr const char *path{ "AmbientLight/FlickerClassification" };
149
151 static constexpr const char *name{ "FlickerClassification" };
152
154 static constexpr const char *description{
155 R"description(A classification of the detected ambient light flicker, if any.
156The values `grid50hz` and `grid60hz` indicate that ambient
157light matching a 50 Hz or 60 Hz power grid was detected in the
158scene. In those cases it is recommended to use Ambient Light
159Adaptation for better point cloud quality. The value
160`unknownFlicker` indicates that some significant time-varying
161ambient light was detected, but it did not match the
162characteristics of a standard power grid.
163)description"
164 };
165
167 enum class ValueType
168 {
169 noFlicker,
170 unknownFlicker,
171 grid50hz,
172 grid60hz
173 };
178
180 static std::set<ValueType> validValues()
181 {
182 return {
183 ValueType::noFlicker, ValueType::unknownFlicker, ValueType::grid50hz, ValueType::grid60hz
184 };
185 }
186
189
191 explicit constexpr FlickerClassification(ValueType value)
192 : m_value{ verifyValue(value) }
193 {}
194
197
199 std::string toString() const;
200
202 friend std::ostream &operator<<(std::ostream &stream, const FlickerClassification::ValueType &value)
203 {
204 return stream << FlickerClassification{ value }.toString();
205 }
206
208 bool operator==(const FlickerClassification &other) const
209 {
210 return m_value == other.m_value;
211 }
212
214 bool operator!=(const FlickerClassification &other) const
215 {
216 return m_value != other.m_value;
217 }
218
220 friend std::ostream &operator<<(std::ostream &stream, const FlickerClassification &value)
221 {
222 return stream << value.toString();
223 }
224
225 private:
226 void setFromString(const std::string &value);
227
228 constexpr ValueType static verifyValue(const ValueType &value)
229 {
230 return value == ValueType::noFlicker || value == ValueType::unknownFlicker
231 || value == ValueType::grid50hz || value == ValueType::grid60hz
232 ? value
233 : throw std::invalid_argument{
234 "Invalid value: FlickerClassification{ "
235 + std::to_string(static_cast<std::underlying_type<ValueType>::type>(value)) + " }"
236 };
237 }
238
239 ValueType m_value{ ValueType::unknownFlicker };
240
241 friend struct DataModel::Detail::Befriend<FlickerClassification>;
242 };
243
244 using Descendants = std::tuple<SceneConditions::AmbientLight::FlickerClassification>;
245
248
260#ifndef NO_DOC
261 template<
262 typename... Args,
263 typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0,
264 typename std::enable_if<
265 Zivid::Detail::TypeTraits::AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>::
266 value,
267 int>::type = 0>
268#else
269 template<typename... Args>
270#endif
271 explicit AmbientLight(Args &&...args)
272 {
273 using namespace Zivid::Detail::TypeTraits;
274
275 static_assert(
276 AllArgsDecayedAreUnique<Args...>::value,
277 "Found duplicate types among the arguments passed to AmbientLight(...). "
278 "Types should be listed at most once.");
279
280 set(std::forward<Args>(args)...);
281 }
282
293#ifndef NO_DOC
294 template<typename... Args, typename std::enable_if<sizeof...(Args) >= 2, int>::type = 0>
295#else
296 template<typename... Args>
297#endif
298 void set(Args &&...args)
299 {
300 using namespace Zivid::Detail::TypeTraits;
301
302 using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
303 static_assert(
304 AllArgsAreDescendantNodes::value, "All arguments passed to set(...) must be descendant nodes.");
305
306 static_assert(
307 AllArgsDecayedAreUnique<Args...>::value,
308 "Found duplicate types among the arguments passed to set(...). "
309 "Types should be listed at most once.");
310
311 Zivid::DataModel::Detail::invokeSetWithEachArgument(*this, std::forward<Args>(args)...);
312 }
313
325#ifndef NO_DOC
326 template<typename... Args, typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0>
327#else
328 template<typename... Args>
329#endif
330 AmbientLight copyWith(Args &&...args) const
331 {
332 using namespace Zivid::Detail::TypeTraits;
333
334 using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
335 static_assert(
336 AllArgsAreDescendantNodes::value,
337 "All arguments passed to copyWith(...) must be descendant nodes.");
338
339 static_assert(
340 AllArgsDecayedAreUnique<Args...>::value,
341 "Found duplicate types among the arguments passed to copyWith(...). "
342 "Types should be listed at most once.");
343
344 auto copy{ *this };
345 copy.set(std::forward<Args>(args)...);
346 return copy;
347 }
348
351 {
352 return m_flickerClassification;
353 }
354
357 {
358 return m_flickerClassification;
359 }
360
363 {
364 m_flickerClassification = value;
365 return *this;
366 }
367
368 template<
369 typename T,
370 typename std::enable_if<
371 std::is_same<T, SceneConditions::AmbientLight::FlickerClassification>::value,
372 int>::type = 0>
374 {
375 return m_flickerClassification;
376 }
377
378 template<size_t i, typename std::enable_if<i == 0, int>::type = 0>
380 {
381 return m_flickerClassification;
382 }
383
385 template<typename F>
386 void forEach(const F &f) const
387 {
388 f(m_flickerClassification);
389 }
390
392 template<typename F>
393 void forEach(const F &f)
394 {
395 f(m_flickerClassification);
396 }
397
399 bool operator==(const AmbientLight &other) const;
400
402 bool operator!=(const AmbientLight &other) const;
403
405 std::string toString() const;
406
408 friend std::ostream &operator<<(std::ostream &stream, const AmbientLight &value)
409 {
410 return stream << value.toString();
411 }
412
413 private:
414 void setFromString(const std::string &value);
415
416 void setFromString(const std::string &fullPath, const std::string &value);
417
418 std::string getString(const std::string &fullPath) const;
419
420 FlickerClassification m_flickerClassification;
421
422 friend struct DataModel::Detail::Befriend<AmbientLight>;
423 };
424
426 std::tuple<SceneConditions::AmbientLight, SceneConditions::AmbientLight::FlickerClassification>;
427
430
432 explicit SceneConditions(const std::string &fileName);
433
439 [[nodiscard]] static SceneConditions fromSerialized(const std::string &value);
440
446 std::string serialize() const;
447
460#ifndef NO_DOC
461 template<
462 typename... Args,
463 typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0,
464 typename std::enable_if<
465 Zivid::Detail::TypeTraits::AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>::value,
466 int>::type = 0>
467#else
468 template<typename... Args>
469#endif
470 explicit SceneConditions(Args &&...args)
471 {
472 using namespace Zivid::Detail::TypeTraits;
473
474 static_assert(
475 AllArgsDecayedAreUnique<Args...>::value,
476 "Found duplicate types among the arguments passed to SceneConditions(...). "
477 "Types should be listed at most once.");
478
479 set(std::forward<Args>(args)...);
480 }
481
493#ifndef NO_DOC
494 template<typename... Args, typename std::enable_if<sizeof...(Args) >= 2, int>::type = 0>
495#else
496 template<typename... Args>
497#endif
498 void set(Args &&...args)
499 {
500 using namespace Zivid::Detail::TypeTraits;
501
502 using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
503 static_assert(
504 AllArgsAreDescendantNodes::value, "All arguments passed to set(...) must be descendant nodes.");
505
506 static_assert(
507 AllArgsDecayedAreUnique<Args...>::value,
508 "Found duplicate types among the arguments passed to set(...). "
509 "Types should be listed at most once.");
510
511 Zivid::DataModel::Detail::invokeSetWithEachArgument(*this, std::forward<Args>(args)...);
512 }
513
526#ifndef NO_DOC
527 template<typename... Args, typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0>
528#else
529 template<typename... Args>
530#endif
531 SceneConditions copyWith(Args &&...args) const
532 {
533 using namespace Zivid::Detail::TypeTraits;
534
535 using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
536 static_assert(
537 AllArgsAreDescendantNodes::value, "All arguments passed to copyWith(...) must be descendant nodes.");
538
539 static_assert(
540 AllArgsDecayedAreUnique<Args...>::value,
541 "Found duplicate types among the arguments passed to copyWith(...). "
542 "Types should be listed at most once.");
543
544 auto copy{ *this };
545 copy.set(std::forward<Args>(args)...);
546 return copy;
547 }
548
551 {
552 return m_ambientLight;
553 }
554
557 {
558 return m_ambientLight;
559 }
560
563 {
564 m_ambientLight = value;
565 return *this;
566 }
567
570 {
571 m_ambientLight.set(value);
572 return *this;
573 }
574
575 template<
576 typename T,
577 typename std::enable_if<std::is_same<T, SceneConditions::AmbientLight>::value, int>::type = 0>
579 {
580 return m_ambientLight;
581 }
582
583 template<
584 typename T,
585 typename std::enable_if<std::is_same<T, SceneConditions::AmbientLight::FlickerClassification>::value, int>::
586 type = 0>
588 {
589 return m_ambientLight.get<SceneConditions::AmbientLight::FlickerClassification>();
590 }
591
592 template<size_t i, typename std::enable_if<i == 0, int>::type = 0>
594 {
595 return m_ambientLight;
596 }
597
599 template<typename F>
600 void forEach(const F &f) const
601 {
602 f(m_ambientLight);
603 }
604
606 template<typename F>
607 void forEach(const F &f)
608 {
609 f(m_ambientLight);
610 }
611
613 bool operator==(const SceneConditions &other) const;
614
616 bool operator!=(const SceneConditions &other) const;
617
619 std::string toString() const;
620
622 friend std::ostream &operator<<(std::ostream &stream, const SceneConditions &value)
623 {
624 return stream << value.toString();
625 }
626
628 void save(const std::string &fileName) const;
629
631 void load(const std::string &fileName);
632
633 private:
634 void setFromString(const std::string &value);
635
636 void setFromString(const std::string &fullPath, const std::string &value);
637
638 std::string getString(const std::string &fullPath) const;
639
640 AmbientLight m_ambientLight;
641
642 friend struct DataModel::Detail::Befriend<SceneConditions>;
643 };
644
645#ifndef NO_DOC
646 template<>
647 struct SceneConditions::Version<1>
648 {
649 using Type = SceneConditions;
650 };
651#endif
652
653} // namespace Zivid
654
655#ifndef NO_DOC
657namespace Zivid::Detail
658{
659
660 ZIVID_CORE_EXPORT void save(const Zivid::SceneConditions &dataModel, std::ostream &ostream);
661 ZIVID_CORE_EXPORT void load(Zivid::SceneConditions &dataModel, std::istream &istream);
662
663 ZIVID_CORE_EXPORT std::vector<uint8_t> serializeToBinaryVector(const Zivid::SceneConditions &source);
664 ZIVID_CORE_EXPORT void deserializeFromBinaryVector(Zivid::SceneConditions &dest, const std::vector<uint8_t> &data);
665
666} // namespace Zivid::Detail
667#endif
668
669#ifdef _MSC_VER
670# pragma warning(pop)
671#endif
672
673#ifndef NO_DOC
674# if !(defined(_MSC_VER) && (_MSC_VER <= 1900))
675namespace std // NOLINT
676{
677
678 template<>
679 struct tuple_size<Zivid::SceneConditions::AmbientLight> : integral_constant<size_t, 1>
680 {};
681
682 template<size_t i>
683 struct tuple_element<i, Zivid::SceneConditions::AmbientLight>
684 {
685 static_assert(i < tuple_size<Zivid::SceneConditions::AmbientLight>::value, "Index must be less than 1");
686
687 using type // NOLINT
688 = decltype(declval<Zivid::SceneConditions::AmbientLight>().get<i>());
689 };
690
691 template<>
692 struct tuple_size<Zivid::SceneConditions> : integral_constant<size_t, 1>
693 {};
694
695 template<size_t i>
696 struct tuple_element<i, Zivid::SceneConditions>
697 {
698 static_assert(i < tuple_size<Zivid::SceneConditions>::value, "Index must be less than 1");
699
700 using type // NOLINT
701 = decltype(declval<Zivid::SceneConditions>().get<i>());
702 };
703
704} // namespace std
705# endif
706#endif
707
708// If we have access to the DataModel library, automatically include internal DataModel
709// header. This header is necessary for serialization and deserialization.
710#if defined(__has_include) && !defined(NO_DOC)
711# if __has_include("Zivid/SceneConditionsInternal.h") && __has_include("Zivid/DataModelNodeMetaData.h")
712# include "Zivid/SceneConditionsInternal.h"
713# endif
714#endif
#define ZIVID_CORE_EXPORT
Definition CoreExport.h:56
A classification of the detected ambient light flicker, if any. The values grid50hz and grid60hz indi...
Definition SceneConditions.h:142
bool operator==(const FlickerClassification &other) const
Comparison operator.
Definition SceneConditions.h:208
static const FlickerClassification grid50hz
grid50hz
Definition SceneConditions.h:176
std::string toString() const
Get the value as string.
friend std::ostream & operator<<(std::ostream &stream, const FlickerClassification &value)
Operator to serialize the value to a stream.
Definition SceneConditions.h:220
static std::set< ValueType > validValues()
All valid values of FlickerClassification.
Definition SceneConditions.h:180
bool operator!=(const FlickerClassification &other) const
Comparison operator.
Definition SceneConditions.h:214
ValueType
The type of the underlying value.
Definition SceneConditions.h:168
static const FlickerClassification noFlicker
noFlicker
Definition SceneConditions.h:174
static const FlickerClassification grid60hz
grid60hz
Definition SceneConditions.h:177
friend std::ostream & operator<<(std::ostream &stream, const FlickerClassification::ValueType &value)
Operator to serialize ValueType to a stream.
Definition SceneConditions.h:202
static const FlickerClassification unknownFlicker
unknownFlicker
Definition SceneConditions.h:175
constexpr FlickerClassification(ValueType value)
Constructor.
Definition SceneConditions.h:191
The ambient light detected by the camera.
Definition SceneConditions.h:115
void forEach(const F &f) const
Run the given function on each direct member with the value of the member as parameter.
Definition SceneConditions.h:386
AmbientLight copyWith(Args &&...args) const
Returns a copy of this object with the given argument(s) set to the new value(s)
Definition SceneConditions.h:330
const SceneConditions::AmbientLight::FlickerClassification & get() const
Definition SceneConditions.h:373
std::string toString() const
Get the value as string.
AmbientLight & set(const FlickerClassification &value)
Set FlickerClassification.
Definition SceneConditions.h:362
FlickerClassification & flickerClassification()
Get FlickerClassification.
Definition SceneConditions.h:356
std::tuple< SceneConditions::AmbientLight::FlickerClassification > Descendants
Definition SceneConditions.h:244
bool operator!=(const AmbientLight &other) const
Inequality operator.
const FlickerClassification & flickerClassification() const
Get FlickerClassification.
Definition SceneConditions.h:350
void forEach(const F &f)
Run the given function on each direct member with the value of the member as parameter.
Definition SceneConditions.h:393
AmbientLight()
Default constructor.
friend std::ostream & operator<<(std::ostream &stream, const AmbientLight &value)
Operator to send the value as string to a stream.
Definition SceneConditions.h:408
bool operator==(const AmbientLight &other) const
Equality operator.
void set(Args &&...args)
Set multiple arguments.
Definition SceneConditions.h:298
A description of the ambient conditions detected by the camera.
Definition SceneConditions.h:79
void forEach(const F &f)
Run the given function on each direct member with the value of the member as parameter.
Definition SceneConditions.h:607
const SceneConditions::AmbientLight::FlickerClassification & get() const
Definition SceneConditions.h:587
static SceneConditions fromSerialized(const std::string &value)
Construct a new SceneConditions instance from a previously serialized string.
void load(const std::string &fileName)
Load from the given file.
SceneConditions(const std::string &fileName)
Construct SceneConditions by loading from file.
std::tuple< SceneConditions::AmbientLight, SceneConditions::AmbientLight::FlickerClassification > Descendants
Definition SceneConditions.h:425
bool operator==(const SceneConditions &other) const
Equality operator.
void set(Args &&...args)
Set multiple arguments.
Definition SceneConditions.h:498
friend std::ostream & operator<<(std::ostream &stream, const SceneConditions &value)
Operator to send the value as string to a stream.
Definition SceneConditions.h:622
const SceneConditions::AmbientLight & get() const
Definition SceneConditions.h:578
SceneConditions copyWith(Args &&...args) const
Returns a copy of this object with the given argument(s) set to the new value(s)
Definition SceneConditions.h:531
AmbientLight & ambientLight()
Get AmbientLight.
Definition SceneConditions.h:556
SceneConditions & set(const AmbientLight &value)
Set AmbientLight.
Definition SceneConditions.h:562
SceneConditions(Args &&...args)
Constructor taking variadic number of arguments.
Definition SceneConditions.h:470
SceneConditions()
Default constructor.
void forEach(const F &f) const
Run the given function on each direct member with the value of the member as parameter.
Definition SceneConditions.h:600
bool operator!=(const SceneConditions &other) const
Inequality operator.
SceneConditions & set(const AmbientLight::FlickerClassification &value)
Set AmbientLight::FlickerClassification.
Definition SceneConditions.h:569
std::string toString() const
Get the value as string.
void save(const std::string &fileName) const
Save to the given file.
const AmbientLight & ambientLight() const
Get AmbientLight.
Definition SceneConditions.h:550
std::string serialize() const
Serialize to a string.
NodeType
Definition NodeType.h:49
Definition EnvironmentInfo.h:74
The main Zivid namespace. All Zivid code is found here.
Definition Application.h:84