Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.16.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TensorKey.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 "open3d/utility/Logging.h"
31 
32 namespace open3d {
33 namespace core {
34 
35 // Avoids circular include.
36 class Tensor;
37 
38 // Same as utility::nullopt. Provides a similar Python slicing API.
40 
45 class TensorKey {
46 public:
56  static TensorKey Index(int64_t index);
57 
72 
84  static TensorKey IndexTensor(const Tensor& index_tensor);
85 
86  enum class TensorKeyMode { Index, Slice, IndexTensor };
88 
90  TensorKeyMode GetMode() const;
91 
93  std::string ToString() const;
94 
95 public:
98  int64_t GetIndex() const;
99 
102  int64_t GetStart() const;
103 
106  int64_t GetStop() const;
107 
110  int64_t GetStep() const;
111 
123  TensorKey InstantiateDimSize(int64_t dim_size) const;
124 
127  Tensor GetIndexTensor() const;
128 
129 private:
130  class Impl;
131  class IndexImpl;
132  class SliceImpl;
133  class IndexTensorImpl;
134  std::shared_ptr<Impl> impl_;
135  TensorKey(const std::shared_ptr<Impl>& impl);
136 };
137 
138 } // namespace core
139 } // namespace open3d
Definition: Optional.h:168
TensorKey InstantiateDimSize(int64_t dim_size) const
Definition: TensorKey.cpp:195
TensorKey is used to represent single index, slice or advanced indexing on a Tensor.
Definition: TensorKey.h:45
int64_t GetIndex() const
Definition: TensorKey.cpp:166
std::string ToString() const
Convert TensorKey to a string representation.
Definition: TensorKey.cpp:150
static TensorKey Slice(utility::optional< int64_t > start, utility::optional< int64_t > stop, utility::optional< int64_t > step)
Definition: TensorKey.cpp:156
int64_t GetStop() const
Definition: TensorKey.cpp:181
static TensorKey Index(int64_t index)
Definition: TensorKey.cpp:152
TensorKeyMode
Definition: TensorKey.h:86
Definition: Optional.h:167
int64_t GetStep() const
Definition: TensorKey.cpp:188
Definition: TensorKey.cpp:64
TensorKeyMode GetMode() const
Returns TensorKey mode.
Definition: TensorKey.cpp:148
static TensorKey IndexTensor(const Tensor &index_tensor)
Definition: TensorKey.cpp:162
Definition: TensorKey.cpp:38
Definition: PinholeCameraIntrinsic.cpp:35
Definition: Tensor.h:51
~TensorKey()
Definition: TensorKey.h:87
Definition: TensorKey.cpp:130
Tensor GetIndexTensor() const
Definition: TensorKey.cpp:204
Definition: TensorKey.cpp:49
int64_t GetStart() const
Definition: TensorKey.cpp:174
constexpr utility::nullopt_t None
Definition: TensorKey.h:39