Open3D (C++ API)  0.19.0
Loading...
Searching...
No Matches
Dtype.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 <cstring>
11#include <string>
12
13#include "open3d/Macro.h"
16
17namespace open3d {
18namespace core {
19
21public:
22 static const Dtype Undefined;
23 static const Dtype Float32;
24 static const Dtype Float64;
25 static const Dtype Int8;
26 static const Dtype Int16;
27 static const Dtype Int32;
28 static const Dtype Int64;
29 static const Dtype UInt8;
30 static const Dtype UInt16;
31 static const Dtype UInt32;
32 static const Dtype UInt64;
33 static const Dtype Bool;
34
35public:
36 enum class DtypeCode {
38 Bool, // Needed to distinguish bool from uint8_t.
39 Int,
40 UInt,
41 Float,
42 Object,
43 };
44
45 Dtype() : Dtype(DtypeCode::Undefined, 1, "Undefined") {}
46
47 explicit Dtype(DtypeCode dtype_code,
48 int64_t byte_size,
49 const std::string &name);
50
53 template <typename T>
54 static inline const Dtype FromType() {
55 utility::LogError("Unsupported data for Dtype::FromType.");
56 }
57
58 int64_t ByteSize() const { return byte_size_; }
59
60 DtypeCode GetDtypeCode() const { return dtype_code_; }
61
62 bool IsObject() const { return dtype_code_ == DtypeCode::Object; }
63
64 std::string ToString() const { return name_; }
65
66 bool operator==(const Dtype &other) const;
67
68 bool operator!=(const Dtype &other) const;
69
70private:
71 static constexpr size_t max_name_len_ = 16;
72 DtypeCode dtype_code_;
73 int64_t byte_size_;
74 char name_[max_name_len_]; // MSVC warns if std::string is exported to DLL.
75};
76
77OPEN3D_API extern const Dtype Undefined;
78OPEN3D_API extern const Dtype Float32;
79OPEN3D_API extern const Dtype Float64;
80OPEN3D_API extern const Dtype Int8;
81OPEN3D_API extern const Dtype Int16;
82OPEN3D_API extern const Dtype Int32;
83OPEN3D_API extern const Dtype Int64;
84OPEN3D_API extern const Dtype UInt8;
85OPEN3D_API extern const Dtype UInt16;
86OPEN3D_API extern const Dtype UInt32;
87OPEN3D_API extern const Dtype UInt64;
88OPEN3D_API extern const Dtype Bool;
89
90template <>
92 return Dtype::Float32;
93}
94
95template <>
97 return Dtype::Float64;
98}
99
100template <>
102 return Dtype::Int8;
103}
104
105template <>
107 return Dtype::Int16;
108}
109
110template <>
112 return Dtype::Int32;
113}
114
115template <>
117 return Dtype::Int64;
118}
119
120template <>
122 return Dtype::UInt8;
123}
124
125template <>
127 return Dtype::UInt16;
128}
129
130template <>
132 return Dtype::UInt32;
133}
134
135template <>
137 return Dtype::UInt64;
138}
139
140template <>
142 return Dtype::Bool;
143}
144
145} // namespace core
146} // namespace open3d
#define OPEN3D_API
Definition Macro.h:34
Definition Dtype.h:20
static const Dtype UInt8
Definition Dtype.h:29
static const Dtype Bool
Definition Dtype.h:33
static const Dtype Int16
Definition Dtype.h:26
DtypeCode GetDtypeCode() const
Definition Dtype.h:60
static const Dtype UInt32
Definition Dtype.h:31
static const Dtype Float64
Definition Dtype.h:24
Dtype()
Definition Dtype.h:45
static const Dtype Int32
Definition Dtype.h:27
static const Dtype UInt16
Definition Dtype.h:30
std::string ToString() const
Definition Dtype.h:64
static const Dtype UInt64
Definition Dtype.h:32
static const Dtype Float32
Definition Dtype.h:23
bool IsObject() const
Definition Dtype.h:62
static const Dtype Undefined
Definition Dtype.h:22
int64_t ByteSize() const
Definition Dtype.h:58
static const Dtype Int8
Definition Dtype.h:25
static const Dtype FromType()
Definition Dtype.h:54
DtypeCode
Definition Dtype.h:36
static const Dtype Int64
Definition Dtype.h:28
std::string name
Definition FilePCD.cpp:39
const Dtype UInt32
Definition Dtype.cpp:50
const Dtype Int64
Definition Dtype.cpp:47
const Dtype UInt16
Definition Dtype.cpp:49
const Dtype Bool
Definition Dtype.cpp:52
const Dtype Int32
Definition Dtype.cpp:46
const Dtype Int16
Definition Dtype.cpp:45
const Dtype Undefined
Definition Dtype.cpp:41
const Dtype UInt8
Definition Dtype.cpp:48
const Dtype Float64
Definition Dtype.cpp:43
const Dtype UInt64
Definition Dtype.cpp:51
const Dtype Int8
Definition Dtype.cpp:44
const Dtype Float32
Definition Dtype.cpp:42
Definition PinholeCameraIntrinsic.cpp:16