Open3D (C++ API)  0.18.0+601516a
SizeVector.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <cstddef>
11 #include <string>
12 #include <vector>
13 
16 
17 namespace open3d {
18 namespace core {
19 
20 class SizeVector;
21 
31 class DynamicSizeVector : public SmallVector<utility::optional<int64_t>, 4> {
32 public:
35 
37  const std::initializer_list<utility::optional<int64_t>>& dim_sizes);
38 
39  DynamicSizeVector(const std::vector<utility::optional<int64_t>>& dim_sizes);
40 
42 
43  explicit DynamicSizeVector(int64_t n, int64_t initial_value = 0);
44 
45  template <class InputIterator>
46  DynamicSizeVector(InputIterator first, InputIterator last)
47  : super_t(first, last) {}
48 
49  DynamicSizeVector(const SizeVector& dim_sizes);
50 
51  SizeVector ToSizeVector() const;
52 
54 
56 
57  std::string ToString() const;
58 
59  bool IsDynamic() const;
60 
61  // required for pybind
62  void shrink_to_fit() {}
63 };
64 
69 class SizeVector : public SmallVector<int64_t, 4> {
70 public:
73 
74  SizeVector(const std::initializer_list<int64_t>& dim_sizes);
75 
76  SizeVector(const std::vector<int64_t>& dim_sizes);
77 
78  SizeVector(const SizeVector& other);
79 
80  explicit SizeVector(int64_t n, int64_t initial_value = 0);
81 
82  template <class InputIterator>
83  SizeVector(InputIterator first, InputIterator last)
84  : super_t(first, last) {}
85 
86  SizeVector& operator=(const SizeVector& v);
87 
89 
90  int64_t NumElements() const;
91 
92  int64_t GetLength() const;
93 
94  std::string ToString() const;
95 
96  void AssertCompatible(const DynamicSizeVector& dsv,
97  const std::string msg = "") const;
98 
99  bool IsCompatible(const DynamicSizeVector& dsv) const;
100 
101  operator std::vector<int64_t>() const {
102  return std::vector<int64_t>(begin(), end());
103  }
104 
105  // required for pybind
106  void shrink_to_fit() {}
107 };
108 
109 } // namespace core
110 } // namespace open3d
Definition: SizeVector.h:31
DynamicSizeVector(InputIterator first, InputIterator last)
Definition: SizeVector.h:46
bool IsDynamic() const
Definition: SizeVector.cpp:81
SizeVector ToSizeVector() const
Definition: SizeVector.cpp:40
DynamicSizeVector & operator=(const DynamicSizeVector &v)
Definition: SizeVector.cpp:51
void shrink_to_fit()
Definition: SizeVector.h:62
std::string ToString() const
Definition: SizeVector.cpp:61
DynamicSizeVector()
Definition: SizeVector.h:34
Definition: SizeVector.h:69
bool IsCompatible(const DynamicSizeVector &dsv) const
Definition: SizeVector.cpp:149
void shrink_to_fit()
Definition: SizeVector.h:106
void AssertCompatible(const DynamicSizeVector &dsv, const std::string msg="") const
Definition: SizeVector.cpp:136
SizeVector()
Definition: SizeVector.h:72
int64_t NumElements() const
Definition: SizeVector.cpp:108
SizeVector(InputIterator first, InputIterator last)
Definition: SizeVector.h:83
SizeVector & operator=(const SizeVector &v)
Definition: SizeVector.cpp:98
int64_t GetLength() const
Definition: SizeVector.cpp:124
std::string ToString() const
Definition: SizeVector.cpp:132
Definition: SmallVector.h:1261
iterator begin()
Definition: SmallVector.h:301
iterator end()
Definition: SmallVector.h:303
Definition: PinholeCameraIntrinsic.cpp:16