Zivid C++ API  2.3.1+1a22cbf1-1
Defining the Future of 3D Machine Vision
FrameInfo.h
Go to the documentation of this file.
1 
2 /*******************************************************************************
3  * This file is part of the Zivid 3D Camera API
4  *
5  * Copyright 2015-2022 (C) Zivid AS
6  * All rights reserved.
7  *
8  * Zivid Software License, v1.0
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright notice,
17  * this list of conditions and the following disclaimer in the documentation
18  * and/or other materials provided with the distribution.
19  *
20  * 3. Neither the name of Zivid AS nor the names of its contributors may be used
21  * to endorse or promote products derived from this software without specific
22  * prior written permission.
23  *
24  * 4. This software, with or without modification, must not be used with any
25  * other 3D camera than from Zivid AS.
26  *
27  * 5. Any software provided in binary form under this license must not be
28  * reverse engineered, decompiled, modified and/or disassembled.
29  *
30  * THIS SOFTWARE IS PROVIDED BY ZIVID AS "AS IS" AND ANY EXPRESS OR IMPLIED
31  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
32  * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
33  * DISCLAIMED. IN NO EVENT SHALL ZIVID AS OR CONTRIBUTORS BE LIABLE FOR ANY
34  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
37  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Contact: Zivid Customer Success Team <customersuccess@zivid.com>
42  * Info: http://www.zivid.com
43  ******************************************************************************/
44 
45 #pragma once
46 
47 #include <array>
48 #include <chrono>
49 #include <cmath>
50 #include <ctime>
51 #include <iomanip>
52 #include <memory>
53 #include <set>
54 #include <sstream>
55 #include <string>
56 #include <tuple>
57 #include <utility>
58 #include <vector>
59 
62 #include "Zivid/DataModel/Traits.h"
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 
72 namespace Zivid
73 {
76  {
77  public:
79  static constexpr DataModel::NodeType nodeType = DataModel::NodeType::group;
80 
82  static constexpr const char *path{ "" };
83 
85  static constexpr const char *name{ "FrameInfo" };
86 
88  static constexpr const char *description{ R"description(Various information for a frame)description" };
89 
90  static constexpr size_t version{ 2 };
91 
92 #ifndef NO_DOC
93  template<size_t>
94  struct Version;
95 
96  using LatestVersion = Zivid::FrameInfo;
97 
98  // Short identifier. This value is not guaranteed to be universally unique
99  // Todo(ZIVID-2808): Move this to internal DataModelExt header
100  static constexpr std::array<uint8_t, 3> binaryId{ 'f', 'i', 'f' };
101 
102 #endif
103 
106  {
107  public:
109  static constexpr DataModel::NodeType nodeType = DataModel::NodeType::group;
110 
112  static constexpr const char *path{ "SoftwareVersion" };
113 
115  static constexpr const char *name{ "SoftwareVersion" };
116 
118  static constexpr const char *description{
119  R"description(The version information for installed software at the time of image capture)description"
120  };
121 
124  {
125  public:
128 
130  static constexpr const char *path{ "SoftwareVersion/Core" };
131 
133  static constexpr const char *name{ "Core" };
134 
136  static constexpr const char *description{ R"description(Core version)description" };
137 
139  using ValueType = std::string;
140 
143  {
144  return { 0, std::numeric_limits<ValueType::size_type>::max() };
145  }
146 
148  Core() = default;
149 
151  explicit Core(std::string value)
152  : m_value{ std::move(value) }
153  {}
154 
156  const std::string &value() const;
157 
159  std::string toString() const;
160 
162  bool operator==(const Core &other) const
163  {
164  return m_value == other.m_value;
165  }
166 
168  bool operator!=(const Core &other) const
169  {
170  return m_value != other.m_value;
171  }
172 
174  bool operator<(const Core &other) const
175  {
176  return m_value < other.m_value;
177  }
178 
180  bool operator>(const Core &other) const
181  {
182  return m_value > other.m_value;
183  }
184 
186  friend std::ostream &operator<<(std::ostream &stream, const Core &value)
187  {
188  return stream << value.toString();
189  }
190 
191  private:
192  void setFromString(const std::string &value);
193 
194  std::string m_value{ "No-version" };
195 
196  friend struct DataModel::Detail::Befriend<Core>;
197  };
198 
199  using Descendants = std::tuple<FrameInfo::SoftwareVersion::Core>;
200 
203 
215 #ifndef NO_DOC
216  template<typename... Args,
217  typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0,
218  typename std::enable_if<
219  Zivid::Detail::TypeTraits::AllArgsAreInTuple<Descendants,
220  typename std::decay<Args>::type...>::value,
221  int>::type = 0>
222 #else
223  template<typename... Args>
224 #endif
225  explicit SoftwareVersion(Args &&...args)
226  {
227  using namespace Zivid::Detail::TypeTraits;
228 
229  static_assert(AllArgsDecayedAreUnique<Args...>::value,
230  "Found duplicate types among the arguments passed to SoftwareVersion(...). "
231  "Types should be listed at most once.");
232 
233  set(std::forward<Args>(args)...);
234  }
235 
246 #ifndef NO_DOC
247  template<typename... Args, typename std::enable_if<sizeof...(Args) >= 2, int>::type = 0>
248 #else
249  template<typename... Args>
250 #endif
251  void set(Args &&...args)
252  {
253  using namespace Zivid::Detail::TypeTraits;
254 
255  using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
256  static_assert(AllArgsAreDescendantNodes::value,
257  "All arguments passed to set(...) must be descendant nodes.");
258 
259  static_assert(AllArgsDecayedAreUnique<Args...>::value,
260  "Found duplicate types among the arguments passed to set(...). "
261  "Types should be listed at most once.");
262 
263  Zivid::DataModel::Detail::invokeSetWithEachArgument(*this, std::forward<Args>(args)...);
264  }
265 
277 #ifndef NO_DOC
278  template<typename... Args, typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0>
279 #else
280  template<typename... Args>
281 #endif
282  SoftwareVersion copyWith(Args &&...args) const
283  {
284  using namespace Zivid::Detail::TypeTraits;
285 
286  using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
287  static_assert(AllArgsAreDescendantNodes::value,
288  "All arguments passed to copyWith(...) must be descendant nodes.");
289 
290  static_assert(AllArgsDecayedAreUnique<Args...>::value,
291  "Found duplicate types among the arguments passed to copyWith(...). "
292  "Types should be listed at most once.");
293 
294  auto copy{ *this };
295  copy.set(std::forward<Args>(args)...);
296  return copy;
297  }
298 
300  const Core &core() const
301  {
302  return m_core;
303  }
304 
307  {
308  return m_core;
309  }
310 
312  SoftwareVersion &set(const Core &value)
313  {
314  m_core = value;
315  return *this;
316  }
317 
318  template<typename T,
319  typename std::enable_if<std::is_same<T, FrameInfo::SoftwareVersion::Core>::value, int>::type = 0>
321  {
322  return m_core;
323  }
324 
325  template<size_t i, typename std::enable_if<i == 0, int>::type = 0>
327  {
328  return m_core;
329  }
330 
332  template<typename F>
333  void forEach(const F &f) const
334  {
335  f(m_core);
336  }
337 
339  template<typename F>
340  void forEach(const F &f)
341  {
342  f(m_core);
343  }
344 
346  bool operator==(const SoftwareVersion &other) const;
347 
349  bool operator!=(const SoftwareVersion &other) const;
350 
352  std::string toString() const;
353 
355  friend std::ostream &operator<<(std::ostream &stream, const SoftwareVersion &value)
356  {
357  return stream << value.toString();
358  }
359 
360  private:
361  void setFromString(const std::string &value);
362 
363  void setFromString(const std::string &fullPath, const std::string &value);
364 
365  std::string getString(const std::string &fullPath) const;
366 
367  Core m_core;
368 
369  friend struct DataModel::Detail::Befriend<SoftwareVersion>;
370  };
371 
374  {
375  public:
378 
380  static constexpr const char *path{ "TimeStamp" };
381 
383  static constexpr const char *name{ "TimeStamp" };
384 
386  static constexpr const char *description{ R"description(The time of frame capture)description" };
387 
389  using ValueType = std::chrono::system_clock::time_point;
390 
393  {
394  return { std::chrono::system_clock::time_point::min(), std::chrono::system_clock::time_point::max() };
395  }
396 
398  TimeStamp() = default;
399 
401  explicit constexpr TimeStamp(std::chrono::system_clock::time_point value)
402  : m_value{ value }
403  {}
404 
406  std::chrono::system_clock::time_point value() const;
407 
409  std::string toString() const;
410 
412  bool operator==(const TimeStamp &other) const
413  {
414  return m_value == other.m_value;
415  }
416 
418  bool operator!=(const TimeStamp &other) const
419  {
420  return m_value != other.m_value;
421  }
422 
424  bool operator<(const TimeStamp &other) const
425  {
426  return m_value < other.m_value;
427  }
428 
430  bool operator>(const TimeStamp &other) const
431  {
432  return m_value > other.m_value;
433  }
434 
436  friend std::ostream &operator<<(std::ostream &stream, const TimeStamp &value)
437  {
438  return stream << value.toString();
439  }
440 
441  private:
442  void setFromString(const std::string &value);
443 
444  std::chrono::system_clock::time_point m_value{};
445 
446  friend struct DataModel::Detail::Befriend<TimeStamp>;
447  };
448 
449  using Descendants =
450  std::tuple<FrameInfo::SoftwareVersion, FrameInfo::SoftwareVersion::Core, FrameInfo::TimeStamp>;
451 
454 
456  explicit FrameInfo(const std::string &fileName);
457 
471 #ifndef NO_DOC
472  template<
473  typename... Args,
474  typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0,
475  typename std::enable_if<
476  Zivid::Detail::TypeTraits::AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>::value,
477  int>::type = 0>
478 #else
479  template<typename... Args>
480 #endif
481  explicit FrameInfo(Args &&...args)
482  {
483  using namespace Zivid::Detail::TypeTraits;
484 
485  static_assert(AllArgsDecayedAreUnique<Args...>::value,
486  "Found duplicate types among the arguments passed to FrameInfo(...). "
487  "Types should be listed at most once.");
488 
489  set(std::forward<Args>(args)...);
490  }
491 
504 #ifndef NO_DOC
505  template<typename... Args, typename std::enable_if<sizeof...(Args) >= 2, int>::type = 0>
506 #else
507  template<typename... Args>
508 #endif
509  void set(Args &&...args)
510  {
511  using namespace Zivid::Detail::TypeTraits;
512 
513  using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
514  static_assert(AllArgsAreDescendantNodes::value,
515  "All arguments passed to set(...) must be descendant nodes.");
516 
517  static_assert(AllArgsDecayedAreUnique<Args...>::value,
518  "Found duplicate types among the arguments passed to set(...). "
519  "Types should be listed at most once.");
520 
521  Zivid::DataModel::Detail::invokeSetWithEachArgument(*this, std::forward<Args>(args)...);
522  }
523 
537 #ifndef NO_DOC
538  template<typename... Args, typename std::enable_if<sizeof...(Args) >= 1, int>::type = 0>
539 #else
540  template<typename... Args>
541 #endif
542  FrameInfo copyWith(Args &&...args) const
543  {
544  using namespace Zivid::Detail::TypeTraits;
545 
546  using AllArgsAreDescendantNodes = AllArgsAreInTuple<Descendants, typename std::decay<Args>::type...>;
547  static_assert(AllArgsAreDescendantNodes::value,
548  "All arguments passed to copyWith(...) must be descendant nodes.");
549 
550  static_assert(AllArgsDecayedAreUnique<Args...>::value,
551  "Found duplicate types among the arguments passed to copyWith(...). "
552  "Types should be listed at most once.");
553 
554  auto copy{ *this };
555  copy.set(std::forward<Args>(args)...);
556  return copy;
557  }
558 
561  {
562  return m_softwareVersion;
563  }
564 
567  {
568  return m_softwareVersion;
569  }
570 
573  {
574  m_softwareVersion = value;
575  return *this;
576  }
577 
580  {
581  m_softwareVersion.set(value);
582  return *this;
583  }
584 
586  const TimeStamp &timeStamp() const
587  {
588  return m_timeStamp;
589  }
590 
593  {
594  return m_timeStamp;
595  }
596 
598  FrameInfo &set(const TimeStamp &value)
599  {
600  m_timeStamp = value;
601  return *this;
602  }
603 
604  template<typename T, typename std::enable_if<std::is_same<T, FrameInfo::SoftwareVersion>::value, int>::type = 0>
606  {
607  return m_softwareVersion;
608  }
609 
610  template<typename T,
611  typename std::enable_if<std::is_same<T, FrameInfo::SoftwareVersion::Core>::value, int>::type = 0>
613  {
614  return m_softwareVersion.get<FrameInfo::SoftwareVersion::Core>();
615  }
616 
617  template<typename T, typename std::enable_if<std::is_same<T, FrameInfo::TimeStamp>::value, int>::type = 0>
618  const FrameInfo::TimeStamp &get() const
619  {
620  return m_timeStamp;
621  }
622 
623  template<size_t i, typename std::enable_if<i == 0, int>::type = 0>
625  {
626  return m_softwareVersion;
627  }
628 
629  template<size_t i, typename std::enable_if<i == 1, int>::type = 0>
630  const FrameInfo::TimeStamp &get() const
631  {
632  return m_timeStamp;
633  }
634 
636  template<typename F>
637  void forEach(const F &f) const
638  {
639  f(m_softwareVersion);
640  f(m_timeStamp);
641  }
642 
644  template<typename F>
645  void forEach(const F &f)
646  {
647  f(m_softwareVersion);
648  f(m_timeStamp);
649  }
650 
652  bool operator==(const FrameInfo &other) const;
653 
655  bool operator!=(const FrameInfo &other) const;
656 
658  std::string toString() const;
659 
661  friend std::ostream &operator<<(std::ostream &stream, const FrameInfo &value)
662  {
663  return stream << value.toString();
664  }
665 
667  void save(const std::string &fileName) const;
668 
670  void load(const std::string &fileName);
671 
672  private:
673  void setFromString(const std::string &value);
674 
675  void setFromString(const std::string &fullPath, const std::string &value);
676 
677  std::string getString(const std::string &fullPath) const;
678 
679  SoftwareVersion m_softwareVersion;
680  TimeStamp m_timeStamp;
681 
682  friend struct DataModel::Detail::Befriend<FrameInfo>;
683  };
684 
685 #ifndef NO_DOC
686  template<>
687  struct FrameInfo::Version<2>
688  {
689  using Type = FrameInfo;
690  };
691 #endif
692 
693 } // namespace Zivid
694 
695 #ifdef _MSC_VER
696 # pragma warning(pop)
697 #endif
698 
699 #ifndef NO_DOC
700 # if !(defined(_MSC_VER) && (_MSC_VER <= 1900))
701 namespace std // NOLINT
702 {
703  template<>
704  struct tuple_size<Zivid::FrameInfo::SoftwareVersion> : integral_constant<size_t, 1>
705  {};
706 
707  template<size_t i>
708  struct tuple_element<i, Zivid::FrameInfo::SoftwareVersion>
709  {
710  static_assert(i < tuple_size<Zivid::FrameInfo::SoftwareVersion>::value, "Index must be less than 1");
711 
712  using type // NOLINT
713  = decltype(declval<Zivid::FrameInfo::SoftwareVersion>().get<i>());
714  };
715 
716  template<>
717  struct tuple_size<Zivid::FrameInfo> : integral_constant<size_t, 2>
718  {};
719 
720  template<size_t i>
721  struct tuple_element<i, Zivid::FrameInfo>
722  {
723  static_assert(i < tuple_size<Zivid::FrameInfo>::value, "Index must be less than 2");
724 
725  using type // NOLINT
726  = decltype(declval<Zivid::FrameInfo>().get<i>());
727  };
728 
729 } // namespace std
730 # endif
731 #endif
#define ZIVID_CORE_EXPORT
Definition: CoreExport.h:57
Core version
Definition: FrameInfo.h:124
std::string toString() const
Get the value as string
bool operator!=(const Core &other) const
Comparison operator
Definition: FrameInfo.h:168
Core(std::string value)
Constructor
Definition: FrameInfo.h:151
friend std::ostream & operator<<(std::ostream &stream, const Core &value)
Operator to serialize the value to a stream
Definition: FrameInfo.h:186
const std::string & value() const
Get the value
bool operator==(const Core &other) const
Comparison operator
Definition: FrameInfo.h:162
Core()=default
Default constructor
static constexpr Range< ValueType::size_type > validSize()
The valid sizes for Core
Definition: FrameInfo.h:142
bool operator>(const Core &other) const
Comparison operator
Definition: FrameInfo.h:180
bool operator<(const Core &other) const
Comparison operator
Definition: FrameInfo.h:174
std::string ValueType
The type of the underlying value
Definition: FrameInfo.h:139
The version information for installed software at the time of image capture
Definition: FrameInfo.h:106
SoftwareVersion & set(const Core &value)
Set Core
Definition: FrameInfo.h:312
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:340
SoftwareVersion()
Default constructor
const FrameInfo::SoftwareVersion::Core & get() const
Definition: FrameInfo.h:320
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:282
const Core & core() const
Get Core
Definition: FrameInfo.h:300
SoftwareVersion(Args &&...args)
Constructor taking variadic number of arguments
Definition: FrameInfo.h:225
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:333
Core & core()
Get Core
Definition: FrameInfo.h:306
void set(Args &&...args)
Set multiple arguments
Definition: FrameInfo.h:251
friend std::ostream & operator<<(std::ostream &stream, const SoftwareVersion &value)
Operator to send the value as string to a stream
Definition: FrameInfo.h:355
std::tuple< FrameInfo::SoftwareVersion::Core > Descendants
Definition: FrameInfo.h:199
std::string toString() const
Get the value as string
The time of frame capture
Definition: FrameInfo.h:374
std::chrono::system_clock::time_point value() const
Get the value
bool operator>(const TimeStamp &other) const
Comparison operator
Definition: FrameInfo.h:430
bool operator<(const TimeStamp &other) const
Comparison operator
Definition: FrameInfo.h:424
std::string toString() const
Get the value as string
TimeStamp()=default
Default constructor
constexpr TimeStamp(std::chrono::system_clock::time_point value)
Constructor
Definition: FrameInfo.h:401
bool operator!=(const TimeStamp &other) const
Comparison operator
Definition: FrameInfo.h:418
friend std::ostream & operator<<(std::ostream &stream, const TimeStamp &value)
Operator to serialize the value to a stream
Definition: FrameInfo.h:436
bool operator==(const TimeStamp &other) const
Comparison operator
Definition: FrameInfo.h:412
static constexpr Range< std::chrono::system_clock::time_point > validRange()
The range of valid values for TimeStamp
Definition: FrameInfo.h:392
std::chrono::system_clock::time_point ValueType
The type of the underlying value
Definition: FrameInfo.h:389
Various information for a frame
Definition: FrameInfo.h:76
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:637
FrameInfo()
Default constructor
FrameInfo & set(const SoftwareVersion::Core &value)
Set SoftwareVersion::Core
Definition: FrameInfo.h:579
void set(Args &&...args)
Set multiple arguments
Definition: FrameInfo.h:509
void save(const std::string &fileName) const
Save to the given file
const TimeStamp & timeStamp() const
Get TimeStamp
Definition: FrameInfo.h:586
SoftwareVersion & softwareVersion()
Get SoftwareVersion
Definition: FrameInfo.h:566
FrameInfo(const std::string &fileName)
Construct FrameInfo by loading from file
const FrameInfo::SoftwareVersion::Core & get() const
Definition: FrameInfo.h:612
FrameInfo(Args &&...args)
Constructor taking variadic number of arguments
Definition: FrameInfo.h:481
const FrameInfo::TimeStamp & get() const
Definition: FrameInfo.h:618
const SoftwareVersion & softwareVersion() const
Get SoftwareVersion
Definition: FrameInfo.h:560
friend std::ostream & operator<<(std::ostream &stream, const FrameInfo &value)
Operator to send the value as string to a stream
Definition: FrameInfo.h:661
TimeStamp & timeStamp()
Get TimeStamp
Definition: FrameInfo.h:592
const FrameInfo::SoftwareVersion & get() const
Definition: FrameInfo.h:605
FrameInfo & set(const SoftwareVersion &value)
Set SoftwareVersion
Definition: FrameInfo.h:572
FrameInfo & set(const TimeStamp &value)
Set TimeStamp
Definition: FrameInfo.h:598
bool operator!=(const FrameInfo &other) const
Inequality operator
std::tuple< FrameInfo::SoftwareVersion, FrameInfo::SoftwareVersion::Core, FrameInfo::TimeStamp > Descendants
Definition: FrameInfo.h:450
void forEach(const F &f)
Run the given function on each direct member with the value of the member as parameter
Definition: FrameInfo.h:645
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:542
Class describing a range of values for a given type T
Definition: Range.h:58
NodeType
Definition: NodeType.h:56
The main Zivid namespace. All Zivid code is found here
Definition: Application.h:55