Zivid C++ API 2.5.0+19fa6891-1
Defining the Future of 3D Machine Vision
FrameInfo.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-2021 (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{
120 {
121 public:
124
126 static constexpr const char *path{ "" };
127
129 static constexpr const char *name{ "FrameInfo" };
130
132 static constexpr const char *description{ R"description(Various information for a frame)description" };
133
134 static constexpr size_t version{ 2 };
135
136#ifndef NO_DOC
137 template<size_t>
138 struct Version;
139
140 using LatestVersion = Zivid::FrameInfo;
141
142 // Short identifier. This value is not guaranteed to be universally unique
143 // Todo(ZIVID-2808): Move this to internal DataModelExt header
144 static constexpr std::array<uint8_t, 3> binaryId{ 'f', 'i', 'f' };
145
146#endif
147
150 {
151 public:
154
156 static constexpr const char *path{ "SoftwareVersion" };
157
159 static constexpr const char *name{ "SoftwareVersion" };
160
162 static constexpr const char *description{
163 R"description(The version information for installed software at the time of image capture)description"
164 };
165
168 {
169 public:
172
174 static constexpr const char *path{ "SoftwareVersion/Core" };
175
177 static constexpr const char *name{ "Core" };
178
180 static constexpr const char *description{ R"description(Core version)description" };
181
183 using ValueType = std::string;
184
187 {
188 return { 0, std::numeric_limits<ValueType::size_type>::max() };
189 }
190
192 Core() = default;
193
195 explicit Core(std::string value)
196 : m_value{ std::move(value) }
197 {}
198
200 const std::string &value() const;
201
203 std::string toString() const;
204
206 bool operator==(const Core &other) const
207 {
208 return m_value == other.m_value;
209 }
210
212 bool operator!=(const Core &other) const
213 {
214 return m_value != other.m_value;
215 }
216
218 bool operator<(const Core &other) const
219 {
220 return m_value < other.m_value;
221 }
222
224 bool operator>(const Core &other) const
225 {
226 return m_value > other.m_value;
227 }
228
230 friend std::ostream &operator<<(std::ostream &stream, const Core &value)
231 {
232 return stream << value.toString();
233 }
234
235 private:
236 void setFromString(const std::string &value);
237
238 std::string m_value{ "No-version" };
239
240 friend struct DataModel::Detail::Befriend<Core>;
241 };
242
243 using Descendants = std::tuple<FrameInfo::SoftwareVersion::Core>;
244
247
259#ifndef NO_DOC
260 template<typename... Args,
261 typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0,
262 typename std::enable_if<
263 Zivid::Detail::TypeTraits::AllArgsAreInTuple<Descendants,
264 typename std::decay<Args>::type...>::value,
265 int>::type = 0>
266#else
267 template<typename... Args>
268#endif
269 explicit SoftwareVersion(Args &&...args)
270 {
271 using namespace Zivid::Detail::TypeTraits;
272
273 static_assert(AllArgsDecayedAreUnique<Args...>::value,
274 "Found duplicate types among the arguments passed to SoftwareVersion(...). "
275 "Types should be listed at most once.");
276
277 set(std::forward<Args>(args)...);
278 }
279
290#ifndef NO_DOC
291 template<typename... Args, typename std::enable_if<sizeof...(Args) >= 2, int>::type = 0>
292#else
293 template<typename... Args>
294#endif
295 void set(Args &&...args)
296 {
297 using namespace Zivid::Detail::TypeTraits;
298
299 using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
300 static_assert(AllArgsAreDescendantNodes::value,
301 "All arguments passed to set(...) must be descendant nodes.");
302
303 static_assert(AllArgsDecayedAreUnique<Args...>::value,
304 "Found duplicate types among the arguments passed to set(...). "
305 "Types should be listed at most once.");
306
307 Zivid::DataModel::Detail::invokeSetWithEachArgument(*this, std::forward<Args>(args)...);
308 }
309
321#ifndef NO_DOC
322 template<typename... Args, typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0>
323#else
324 template<typename... Args>
325#endif
326 SoftwareVersion copyWith(Args &&...args) const
327 {
328 using namespace Zivid::Detail::TypeTraits;
329
330 using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
331 static_assert(AllArgsAreDescendantNodes::value,
332 "All arguments passed to copyWith(...) must be descendant nodes.");
333
334 static_assert(AllArgsDecayedAreUnique<Args...>::value,
335 "Found duplicate types among the arguments passed to copyWith(...). "
336 "Types should be listed at most once.");
337
338 auto copy{ *this };
339 copy.set(std::forward<Args>(args)...);
340 return copy;
341 }
342
344 const Core &core() const
345 {
346 return m_core;
347 }
348
351 {
352 return m_core;
353 }
354
356 SoftwareVersion &set(const Core &value)
357 {
358 m_core = value;
359 return *this;
360 }
361
362 template<typename T,
363 typename std::enable_if<std::is_same<T, FrameInfo::SoftwareVersion::Core>::value, int>::type = 0>
365 {
366 return m_core;
367 }
368
369 template<size_t i, typename std::enable_if<i == 0, int>::type = 0>
371 {
372 return m_core;
373 }
374
376 template<typename F>
377 void forEach(const F &f) const
378 {
379 f(m_core);
380 }
381
383 template<typename F>
384 void forEach(const F &f)
385 {
386 f(m_core);
387 }
388
390 bool operator==(const SoftwareVersion &other) const;
391
393 bool operator!=(const SoftwareVersion &other) const;
394
396 std::string toString() const;
397
399 friend std::ostream &operator<<(std::ostream &stream, const SoftwareVersion &value)
400 {
401 return stream << value.toString();
402 }
403
404 private:
405 void setFromString(const std::string &value);
406
407 void setFromString(const std::string &fullPath, const std::string &value);
408
409 std::string getString(const std::string &fullPath) const;
410
411 Core m_core;
412
413 friend struct DataModel::Detail::Befriend<SoftwareVersion>;
414 };
415
418 {
419 public:
422
424 static constexpr const char *path{ "TimeStamp" };
425
427 static constexpr const char *name{ "TimeStamp" };
428
430 static constexpr const char *description{ R"description(The time of frame capture)description" };
431
433 using ValueType = std::chrono::system_clock::time_point;
434
437 {
438 return { std::chrono::system_clock::time_point::min(), std::chrono::system_clock::time_point::max() };
439 }
440
442 TimeStamp() = default;
443
445 explicit constexpr TimeStamp(std::chrono::system_clock::time_point value)
446 : m_value{ value }
447 {}
448
450 std::chrono::system_clock::time_point value() const;
451
453 std::string toString() const;
454
456 bool operator==(const TimeStamp &other) const
457 {
458 return m_value == other.m_value;
459 }
460
462 bool operator!=(const TimeStamp &other) const
463 {
464 return m_value != other.m_value;
465 }
466
468 bool operator<(const TimeStamp &other) const
469 {
470 return m_value < other.m_value;
471 }
472
474 bool operator>(const TimeStamp &other) const
475 {
476 return m_value > other.m_value;
477 }
478
480 friend std::ostream &operator<<(std::ostream &stream, const TimeStamp &value)
481 {
482 return stream << value.toString();
483 }
484
485 private:
486 void setFromString(const std::string &value);
487
488 std::chrono::system_clock::time_point m_value{};
489
490 friend struct DataModel::Detail::Befriend<TimeStamp>;
491 };
492
494 std::tuple<FrameInfo::SoftwareVersion, FrameInfo::SoftwareVersion::Core, FrameInfo::TimeStamp>;
495
498
500 explicit FrameInfo(const std::string &fileName);
501
515#ifndef NO_DOC
516 template<
517 typename... Args,
518 typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0,
519 typename std::enable_if<
520 Zivid::Detail::TypeTraits::AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>::value,
521 int>::type = 0>
522#else
523 template<typename... Args>
524#endif
525 explicit FrameInfo(Args &&...args)
526 {
527 using namespace Zivid::Detail::TypeTraits;
528
529 static_assert(AllArgsDecayedAreUnique<Args...>::value,
530 "Found duplicate types among the arguments passed to FrameInfo(...). "
531 "Types should be listed at most once.");
532
533 set(std::forward<Args>(args)...);
534 }
535
548#ifndef NO_DOC
549 template<typename... Args, typename std::enable_if<sizeof...(Args) >= 2, int>::type = 0>
550#else
551 template<typename... Args>
552#endif
553 void set(Args &&...args)
554 {
555 using namespace Zivid::Detail::TypeTraits;
556
557 using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
558 static_assert(AllArgsAreDescendantNodes::value,
559 "All arguments passed to set(...) must be descendant nodes.");
560
561 static_assert(AllArgsDecayedAreUnique<Args...>::value,
562 "Found duplicate types among the arguments passed to set(...). "
563 "Types should be listed at most once.");
564
565 Zivid::DataModel::Detail::invokeSetWithEachArgument(*this, std::forward<Args>(args)...);
566 }
567
581#ifndef NO_DOC
582 template<typename... Args, typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0>
583#else
584 template<typename... Args>
585#endif
586 FrameInfo copyWith(Args &&...args) const
587 {
588 using namespace Zivid::Detail::TypeTraits;
589
590 using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
591 static_assert(AllArgsAreDescendantNodes::value,
592 "All arguments passed to copyWith(...) must be descendant nodes.");
593
594 static_assert(AllArgsDecayedAreUnique<Args...>::value,
595 "Found duplicate types among the arguments passed to copyWith(...). "
596 "Types should be listed at most once.");
597
598 auto copy{ *this };
599 copy.set(std::forward<Args>(args)...);
600 return copy;
601 }
602
605 {
606 return m_softwareVersion;
607 }
608
611 {
612 return m_softwareVersion;
613 }
614
617 {
618 m_softwareVersion = value;
619 return *this;
620 }
621
624 {
625 m_softwareVersion.set(value);
626 return *this;
627 }
628
630 const TimeStamp &timeStamp() const
631 {
632 return m_timeStamp;
633 }
634
637 {
638 return m_timeStamp;
639 }
640
642 FrameInfo &set(const TimeStamp &value)
643 {
644 m_timeStamp = value;
645 return *this;
646 }
647
648 template<typename T, typename std::enable_if<std::is_same<T, FrameInfo::SoftwareVersion>::value, int>::type = 0>
650 {
651 return m_softwareVersion;
652 }
653
654 template<typename T,
655 typename std::enable_if<std::is_same<T, FrameInfo::SoftwareVersion::Core>::value, int>::type = 0>
657 {
658 return m_softwareVersion.get<FrameInfo::SoftwareVersion::Core>();
659 }
660
661 template<typename T, typename std::enable_if<std::is_same<T, FrameInfo::TimeStamp>::value, int>::type = 0>
663 {
664 return m_timeStamp;
665 }
666
667 template<size_t i, typename std::enable_if<i == 0, int>::type = 0>
669 {
670 return m_softwareVersion;
671 }
672
673 template<size_t i, typename std::enable_if<i == 1, int>::type = 0>
675 {
676 return m_timeStamp;
677 }
678
680 template<typename F>
681 void forEach(const F &f) const
682 {
683 f(m_softwareVersion);
684 f(m_timeStamp);
685 }
686
688 template<typename F>
689 void forEach(const F &f)
690 {
691 f(m_softwareVersion);
692 f(m_timeStamp);
693 }
694
696 bool operator==(const FrameInfo &other) const;
697
699 bool operator!=(const FrameInfo &other) const;
700
702 std::string toString() const;
703
705 friend std::ostream &operator<<(std::ostream &stream, const FrameInfo &value)
706 {
707 return stream << value.toString();
708 }
709
711 void save(const std::string &fileName) const;
712
714 void load(const std::string &fileName);
715
716 private:
717 void setFromString(const std::string &value);
718
719 void setFromString(const std::string &fullPath, const std::string &value);
720
721 std::string getString(const std::string &fullPath) const;
722
723 SoftwareVersion m_softwareVersion;
724 TimeStamp m_timeStamp;
725
726 friend struct DataModel::Detail::Befriend<FrameInfo>;
727 };
728
729#ifndef NO_DOC
730 template<>
731 struct FrameInfo::Version<2>
732 {
733 using Type = FrameInfo;
734 };
735#endif
736
737} // namespace Zivid
738
739#ifdef _MSC_VER
740# pragma warning(pop)
741#endif
742
743#ifndef NO_DOC
744# if !(defined(_MSC_VER) && (_MSC_VER <= 1900))
745namespace std // NOLINT
746{
747 template<>
748 struct tuple_size<Zivid::FrameInfo::SoftwareVersion> : integral_constant<size_t, 1>
749 {};
750
751 template<size_t i>
752 struct tuple_element<i, Zivid::FrameInfo::SoftwareVersion>
753 {
754 static_assert(i < tuple_size<Zivid::FrameInfo::SoftwareVersion>::value, "Index must be less than 1");
755
756 using type // NOLINT
757 = decltype(declval<Zivid::FrameInfo::SoftwareVersion>().get<i>());
758 };
759
760 template<>
761 struct tuple_size<Zivid::FrameInfo> : integral_constant<size_t, 2>
762 {};
763
764 template<size_t i>
765 struct tuple_element<i, Zivid::FrameInfo>
766 {
767 static_assert(i < tuple_size<Zivid::FrameInfo>::value, "Index must be less than 2");
768
769 using type // NOLINT
770 = decltype(declval<Zivid::FrameInfo>().get<i>());
771 };
772
773} // namespace std
774# endif
775#endif
#define ZIVID_CORE_EXPORT
Definition: CoreExport.h:101
Core version
Definition: FrameInfo.h:168
std::string toString() const
Get the value as string
const std::string & value() const
Get the value
bool operator!=(const Core &other) const
Comparison operator
Definition: FrameInfo.h:212
Core(std::string value)
Constructor
Definition: FrameInfo.h:195
bool operator==(const Core &other) const
Comparison operator
Definition: FrameInfo.h:206
Core()=default
Default constructor
bool operator>(const Core &other) const
Comparison operator
Definition: FrameInfo.h:224
bool operator<(const Core &other) const
Comparison operator
Definition: FrameInfo.h:218
friend std::ostream & operator<<(std::ostream &stream, const Core &value)
Operator to serialize the value to a stream
Definition: FrameInfo.h:230
std::string ValueType
The type of the underlying value
Definition: FrameInfo.h:183
static constexpr Range< ValueType::size_type > validSize()
The valid sizes for Core
Definition: FrameInfo.h:186
The version information for installed software at the time of image capture
Definition: FrameInfo.h:150
const Core & core() const
Get Core
Definition: FrameInfo.h:344
friend std::ostream & operator<<(std::ostream &stream, const SoftwareVersion &value)
Operator to send the value as string to a stream
Definition: FrameInfo.h:399
bool operator!=(const SoftwareVersion &other) const
Inequality operator
bool operator==(const SoftwareVersion &other) const
Equality operator
void forEach(const F &f)
Run the given function on each direct member with the value of the member as parameter
Definition: FrameInfo.h:384
SoftwareVersion()
Default constructor
const FrameInfo::SoftwareVersion::Core & get() const
Definition: FrameInfo.h:364
SoftwareVersion copyWith(Args &&...args) const
Returns a copy of this object with the given argument(s) set to the new value(s)
Definition: FrameInfo.h:326
Core & core()
Get Core
Definition: FrameInfo.h:350
SoftwareVersion(Args &&...args)
Constructor taking variadic number of arguments
Definition: FrameInfo.h:269
void forEach(const F &f) const
Run the given function on each direct member with the value of the member as parameter
Definition: FrameInfo.h:377
void set(Args &&...args)
Set multiple arguments
Definition: FrameInfo.h:295
std::tuple< FrameInfo::SoftwareVersion::Core > Descendants
Definition: FrameInfo.h:243
SoftwareVersion & set(const Core &value)
Set Core
Definition: FrameInfo.h:356
std::string toString() const
Get the value as string
The time of frame capture
Definition: FrameInfo.h:418
std::chrono::system_clock::time_point value() const
Get the value
bool operator>(const TimeStamp &other) const
Comparison operator
Definition: FrameInfo.h:474
bool operator<(const TimeStamp &other) const
Comparison operator
Definition: FrameInfo.h:468
static constexpr Range< std::chrono::system_clock::time_point > validRange()
The range of valid values for TimeStamp
Definition: FrameInfo.h:436
std::string toString() const
Get the value as string
friend std::ostream & operator<<(std::ostream &stream, const TimeStamp &value)
Operator to serialize the value to a stream
Definition: FrameInfo.h:480
TimeStamp()=default
Default constructor
constexpr TimeStamp(std::chrono::system_clock::time_point value)
Constructor
Definition: FrameInfo.h:445
bool operator!=(const TimeStamp &other) const
Comparison operator
Definition: FrameInfo.h:462
bool operator==(const TimeStamp &other) const
Comparison operator
Definition: FrameInfo.h:456
std::chrono::system_clock::time_point ValueType
The type of the underlying value
Definition: FrameInfo.h:433
Various information for a frame
Definition: FrameInfo.h:120
TimeStamp & timeStamp()
Get TimeStamp
Definition: FrameInfo.h:636
std::string toString() const
Get the value as string
void forEach(const F &f) const
Run the given function on each direct member with the value of the member as parameter
Definition: FrameInfo.h:681
const FrameInfo::SoftwareVersion::Core & get() const
Definition: FrameInfo.h:656
FrameInfo()
Default constructor
void set(Args &&...args)
Set multiple arguments
Definition: FrameInfo.h:553
void save(const std::string &fileName) const
Save to the given file
const TimeStamp & timeStamp() const
Get TimeStamp
Definition: FrameInfo.h:630
SoftwareVersion & softwareVersion()
Get SoftwareVersion
Definition: FrameInfo.h:610
FrameInfo(const std::string &fileName)
Construct FrameInfo by loading from file
const FrameInfo::SoftwareVersion & get() const
Definition: FrameInfo.h:649
friend std::ostream & operator<<(std::ostream &stream, const FrameInfo &value)
Operator to send the value as string to a stream
Definition: FrameInfo.h:705
FrameInfo & set(const TimeStamp &value)
Set TimeStamp
Definition: FrameInfo.h:642
FrameInfo(Args &&...args)
Constructor taking variadic number of arguments
Definition: FrameInfo.h:525
const FrameInfo::TimeStamp & get() const
Definition: FrameInfo.h:662
const SoftwareVersion & softwareVersion() const
Get SoftwareVersion
Definition: FrameInfo.h:604
FrameInfo & set(const SoftwareVersion &value)
Set SoftwareVersion
Definition: FrameInfo.h:616
FrameInfo & set(const SoftwareVersion::Core &value)
Set SoftwareVersion::Core
Definition: FrameInfo.h:623
bool operator!=(const FrameInfo &other) const
Inequality operator
std::tuple< FrameInfo::SoftwareVersion, FrameInfo::SoftwareVersion::Core, FrameInfo::TimeStamp > Descendants
Definition: FrameInfo.h:494
void forEach(const F &f)
Run the given function on each direct member with the value of the member as parameter
Definition: FrameInfo.h:689
bool operator==(const FrameInfo &other) const
Equality operator
void load(const std::string &fileName)
Load from the given file
FrameInfo copyWith(Args &&...args) const
Returns a copy of this object with the given argument(s) set to the new value(s)
Definition: FrameInfo.h:586
Class describing a range of values for a given type T
Definition: Range.h:102
NodeType
Definition: NodeType.h:100
The main Zivid namespace. All Zivid code is found here
Definition: Application.h:99