Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.14.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Dtype.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 <cstring>
30 #include <string>
31 
32 #include "open3d/Macro.h"
33 #include "open3d/core/Dispatch.h"
34 #include "open3d/utility/Logging.h"
35 
36 namespace open3d {
37 namespace core {
38 
40 public:
41  static const Dtype Undefined;
42  static const Dtype Float32;
43  static const Dtype Float64;
44  static const Dtype Int8;
45  static const Dtype Int16;
46  static const Dtype Int32;
47  static const Dtype Int64;
48  static const Dtype UInt8;
49  static const Dtype UInt16;
50  static const Dtype UInt32;
51  static const Dtype UInt64;
52  static const Dtype Bool;
53 
54 public:
55  enum class DtypeCode {
56  Undefined,
57  Bool, // Needed to distinguish bool from uint8_t.
58  Int,
59  UInt,
60  Float,
61  Object,
62  };
63 
64  Dtype() : Dtype(DtypeCode::Undefined, 1, "Undefined") {}
65 
66  explicit Dtype(DtypeCode dtype_code,
67  int64_t byte_size,
68  const std::string &name);
69 
72  template <typename T>
73  static inline const Dtype FromType() {
74  utility::LogError("Unsupported data for Dtype::FromType.");
75  }
76 
77  int64_t ByteSize() const { return byte_size_; }
78 
79  DtypeCode GetDtypeCode() const { return dtype_code_; }
80 
81  bool IsObject() const { return dtype_code_ == DtypeCode::Object; }
82 
83  std::string ToString() const { return name_; }
84 
85  bool operator==(const Dtype &other) const;
86 
87  bool operator!=(const Dtype &other) const;
88 
89 private:
90  static constexpr size_t max_name_len_ = 16;
91  DtypeCode dtype_code_;
92  int64_t byte_size_;
93  char name_[max_name_len_]; // MSVC warns if std::string is exported to DLL.
94 };
95 
96 OPEN3D_API extern const Dtype Undefined;
97 OPEN3D_API extern const Dtype Float32;
98 OPEN3D_API extern const Dtype Float64;
99 OPEN3D_API extern const Dtype Int8;
100 OPEN3D_API extern const Dtype Int16;
101 OPEN3D_API extern const Dtype Int32;
102 OPEN3D_API extern const Dtype Int64;
103 OPEN3D_API extern const Dtype UInt8;
104 OPEN3D_API extern const Dtype UInt16;
105 OPEN3D_API extern const Dtype UInt32;
106 OPEN3D_API extern const Dtype UInt64;
107 OPEN3D_API extern const Dtype Bool;
108 
109 template <>
110 inline const Dtype Dtype::FromType<float>() {
111  return Dtype::Float32;
112 }
113 
114 template <>
115 inline const Dtype Dtype::FromType<double>() {
116  return Dtype::Float64;
117 }
118 
119 template <>
120 inline const Dtype Dtype::FromType<int8_t>() {
121  return Dtype::Int8;
122 }
123 
124 template <>
125 inline const Dtype Dtype::FromType<int16_t>() {
126  return Dtype::Int16;
127 }
128 
129 template <>
130 inline const Dtype Dtype::FromType<int32_t>() {
131  return Dtype::Int32;
132 }
133 
134 template <>
135 inline const Dtype Dtype::FromType<int64_t>() {
136  return Dtype::Int64;
137 }
138 
139 template <>
140 inline const Dtype Dtype::FromType<uint8_t>() {
141  return Dtype::UInt8;
142 }
143 
144 template <>
145 inline const Dtype Dtype::FromType<uint16_t>() {
146  return Dtype::UInt16;
147 }
148 
149 template <>
150 inline const Dtype Dtype::FromType<uint32_t>() {
151  return Dtype::UInt32;
152 }
153 
154 template <>
155 inline const Dtype Dtype::FromType<uint64_t>() {
156  return Dtype::UInt64;
157 }
158 
159 template <>
160 inline const Dtype Dtype::FromType<bool>() {
161  return Dtype::Bool;
162 }
163 
164 } // namespace core
165 } // namespace open3d
const Dtype UInt8
Definition: Dtype.cpp:67
Dtype()
Definition: Dtype.h:64
const Dtype Bool
Definition: Dtype.cpp:71
const Dtype Int64
Definition: Dtype.cpp:66
Definition: Dtype.h:39
static const Dtype FromType()
Definition: Dtype.h:73
const Dtype UInt64
Definition: Dtype.cpp:70
DtypeCode
Definition: Dtype.h:55
bool operator==(const PointXYZ A, const PointXYZ B)
Definition: Cloud.h:176
static const Dtype Int8
Definition: Dtype.h:44
const Dtype Float32
Definition: Dtype.cpp:61
constexpr bool operator!=(const optional< T > &x, const optional< T > &y)
Definition: Optional.h:650
std::string ToString() const
Definition: Dtype.h:83
static const Dtype UInt8
Definition: Dtype.h:48
static const Dtype Int32
Definition: Dtype.h:46
const Dtype Undefined
Definition: Dtype.cpp:60
const Dtype Int32
Definition: Dtype.cpp:65
const Dtype UInt16
Definition: Dtype.cpp:68
static const Dtype UInt32
Definition: Dtype.h:50
static const Dtype Undefined
Definition: Dtype.h:41
static const Dtype UInt16
Definition: Dtype.h:49
static const Dtype Float32
Definition: Dtype.h:42
static const Dtype Int64
Definition: Dtype.h:47
#define OPEN3D_API
Definition: Macro.h:50
Definition: PinholeCameraIntrinsic.cpp:35
const Dtype Int16
Definition: Dtype.cpp:64
int64_t ByteSize() const
Definition: Dtype.h:77
const Dtype UInt32
Definition: Dtype.cpp:69
static const Dtype Int16
Definition: Dtype.h:45
const Dtype Int8
Definition: Dtype.cpp:63
const Dtype Float64
Definition: Dtype.cpp:62
static const Dtype Bool
Definition: Dtype.h:52
static const Dtype UInt64
Definition: Dtype.h:51
bool IsObject() const
Definition: Dtype.h:81
DtypeCode GetDtypeCode() const
Definition: Dtype.h:79
static const Dtype Float64
Definition: Dtype.h:43
#define LogError(...)
Definition: Logging.h:72
std::string name
Definition: FilePCD.cpp:58