Open3D (C++ API)  0.11.0
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 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/Console.h"
30 
31 namespace open3d {
32 namespace core {
33 
34 class Tensor; // Avoids circular include
35 
36 class NoneType {};
37 
38 extern NoneType None;
39 
54 class TensorKey {
55 public:
56  enum class TensorKeyMode { Index, Slice, IndexTensor };
57 
60  static TensorKey Index(int64_t index);
61 
64  static TensorKey Slice(int64_t start, int64_t stop, int64_t step);
65  static TensorKey Slice(int64_t start, int64_t stop, NoneType step);
66  static TensorKey Slice(int64_t start, NoneType stop, int64_t step);
67  static TensorKey Slice(int64_t start, NoneType stop, NoneType step);
68  static TensorKey Slice(NoneType start, int64_t stop, int64_t step);
69  static TensorKey Slice(NoneType start, int64_t stop, NoneType step);
70  static TensorKey Slice(NoneType start, NoneType stop, int64_t step);
71  static TensorKey Slice(NoneType start, NoneType stop, NoneType step);
72 
75  static TensorKey IndexTensor(const Tensor& index_tensor);
76 
78  TensorKeyMode GetMode() const { return mode_; }
79 
80  int64_t GetIndex() const {
81  AssertMode(TensorKeyMode::Index);
82  return index_;
83  }
84 
85  int64_t GetStart() const {
86  AssertMode(TensorKeyMode::Slice);
87  return start_;
88  }
89 
90  int64_t GetStop() const {
91  AssertMode(TensorKeyMode::Slice);
92  return stop_;
93  }
94 
95  int64_t GetStep() const {
96  AssertMode(TensorKeyMode::Slice);
97  return step_;
98  }
99 
100  bool GetStartIsNone() const {
101  AssertMode(TensorKeyMode::Slice);
102  return start_is_none_;
103  }
104 
105  bool GetStopIsNone() const {
106  AssertMode(TensorKeyMode::Slice);
107  return stop_is_none_;
108  }
109 
110  bool GetStepIsNone() const {
111  AssertMode(TensorKeyMode::Slice);
112  return step_is_none_;
113  }
114 
115  std::shared_ptr<Tensor> GetIndexTensor() const;
116 
125  TensorKey UpdateWithDimSize(int64_t dim_size) const;
126 
127 protected:
129  static TensorKey Slice(int64_t start,
130  int64_t stop,
131  int64_t step,
132  bool start_is_none,
133  bool stop_is_none,
134  bool step_is_none);
135 
139  int64_t index,
140  int64_t start,
141  int64_t stop,
142  int64_t step,
143  bool start_is_none,
144  bool stop_is_none,
145  bool step_is_none,
146  const Tensor& index_tensor);
147 
148  void AssertMode(TensorKeyMode mode) const {
149  if (mode != mode_) {
150  utility::LogError("Wrong TensorKeyMode.");
151  }
152  }
153 
156 
157 public:
159  int64_t index_ = 0;
160 
162  int64_t start_ = 0;
163  int64_t stop_ = 0;
164  int64_t step_ = 0;
165  bool start_is_none_ = false;
166  bool stop_is_none_ = false;
167  bool step_is_none_ = false;
168 
172  std::shared_ptr<Tensor> index_tensor_;
173 };
174 
175 } // namespace core
176 } // namespace open3d
void AssertMode(TensorKeyMode mode) const
Definition: TensorKey.h:148
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t timeout_in_ms capture_handle capture_handle capture_handle image_handle temperature_c k4a_image_t image_handle uint8_t image_handle image_handle image_handle image_handle image_handle timestamp_usec white_balance image_handle k4a_device_configuration_t config device_handle char size_t serial_number_size bool int32_t int32_t int32_t int32_t k4a_color_control_mode_t default_mode mode
Definition: K4aPlugin.cpp:677
NoneType None
Definition: TensorKey.cpp:35
Definition: TensorKey.h:54
bool GetStopIsNone() const
Definition: TensorKey.h:105
void LogError(const char *format, const Args &... args)
Definition: Console.h:176
int64_t GetIndex() const
Definition: TensorKey.h:80
TensorKeyMode GetMode() const
Getters will check the TensorKeyMode.
Definition: TensorKey.h:78
int64_t GetStop() const
Definition: TensorKey.h:90
Definition: TensorKey.h:36
TensorKeyMode
Definition: TensorKey.h:56
bool GetStartIsNone() const
Definition: TensorKey.h:100
int64_t GetStep() const
Definition: TensorKey.h:95
Definition: PinholeCameraIntrinsic.cpp:35
std::shared_ptr< Tensor > index_tensor_
Definition: TensorKey.h:172
Definition: Tensor.h:48
bool GetStepIsNone() const
Definition: TensorKey.h:110
TensorKeyMode mode_
Depending on the mode, some properties may or may not be used.
Definition: TensorKey.h:155
int64_t GetStart() const
Definition: TensorKey.h:85