Open3D (C++ API)  0.16.0
SizeVector.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// The MIT License (MIT)
5//
6// Copyright (c) 2018-2021 www.open3d.org
7//
8// Permission is hereby granted, free of charge, to any person obtaining a copy
9// of this software and associated documentation files (the "Software"), to deal
10// in the Software without restriction, including without limitation the rights
11// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12// copies of the Software, and to permit persons to whom the Software is
13// furnished to do so, subject to the following conditions:
14//
15// The above copyright notice and this permission notice shall be included in
16// all copies or substantial portions of the Software.
17//
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24// IN THE SOFTWARE.
25// ----------------------------------------------------------------------------
26
27#pragma once
28
29#include <cstddef>
30#include <string>
31#include <vector>
32
35
36namespace open3d {
37namespace core {
38
39class SizeVector;
40
50class DynamicSizeVector : public SmallVector<utility::optional<int64_t>, 4> {
51public:
54
56 const std::initializer_list<utility::optional<int64_t>>& dim_sizes);
57
58 DynamicSizeVector(const std::vector<utility::optional<int64_t>>& dim_sizes);
59
61
62 explicit DynamicSizeVector(int64_t n, int64_t initial_value = 0);
63
64 template <class InputIterator>
65 DynamicSizeVector(InputIterator first, InputIterator last)
66 : super_t(first, last) {}
67
68 DynamicSizeVector(const SizeVector& dim_sizes);
69
71
73
75
76 std::string ToString() const;
77
78 bool IsDynamic() const;
79
80 // required for pybind
81 void shrink_to_fit() {}
82};
83
88class SizeVector : public SmallVector<int64_t, 4> {
89public:
92
93 SizeVector(const std::initializer_list<int64_t>& dim_sizes);
94
95 SizeVector(const std::vector<int64_t>& dim_sizes);
96
97 SizeVector(const SizeVector& other);
98
99 explicit SizeVector(int64_t n, int64_t initial_value = 0);
100
101 template <class InputIterator>
102 SizeVector(InputIterator first, InputIterator last)
103 : super_t(first, last) {}
104
106
108
109 int64_t NumElements() const;
110
111 int64_t GetLength() const;
112
113 std::string ToString() const;
114
115 void AssertCompatible(const DynamicSizeVector& dsv,
116 const std::string msg = "") const;
117
118 bool IsCompatible(const DynamicSizeVector& dsv) const;
119
120 operator std::vector<int64_t>() const {
121 return std::vector<int64_t>(begin(), end());
122 }
123
124 // required for pybind
126};
127
128} // namespace core
129} // namespace open3d
Definition: SizeVector.h:50
DynamicSizeVector(InputIterator first, InputIterator last)
Definition: SizeVector.h:65
bool IsDynamic() const
Definition: SizeVector.cpp:100
SizeVector ToSizeVector() const
Definition: SizeVector.cpp:59
DynamicSizeVector & operator=(const DynamicSizeVector &v)
Definition: SizeVector.cpp:70
void shrink_to_fit()
Definition: SizeVector.h:81
std::string ToString() const
Definition: SizeVector.cpp:80
DynamicSizeVector()
Definition: SizeVector.h:53
Definition: SizeVector.h:88
bool IsCompatible(const DynamicSizeVector &dsv) const
Definition: SizeVector.cpp:168
void shrink_to_fit()
Definition: SizeVector.h:125
void AssertCompatible(const DynamicSizeVector &dsv, const std::string msg="") const
Definition: SizeVector.cpp:155
SizeVector()
Definition: SizeVector.h:91
int64_t NumElements() const
Definition: SizeVector.cpp:127
SizeVector(InputIterator first, InputIterator last)
Definition: SizeVector.h:102
SizeVector & operator=(const SizeVector &v)
Definition: SizeVector.cpp:117
int64_t GetLength() const
Definition: SizeVector.cpp:143
std::string ToString() const
Definition: SizeVector.cpp:151
Definition: SmallVector.h:1280
iterator begin()
Definition: SmallVector.h:320
iterator end()
Definition: SmallVector.h:322
Definition: PinholeCameraIntrinsic.cpp:35