Open3D (C++ API)  0.11.0
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 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/Console.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 Int32;
45  static const Dtype Int64;
46  static const Dtype UInt8;
47  static const Dtype UInt16;
48  static const Dtype Bool;
49 
50 public:
51  enum class DtypeCode {
52  Undefined,
53  Bool, // Needed to distinguish bool from uint8_t.
54  Int,
55  UInt,
56  Float,
57  Object,
58  };
59 
60  Dtype() : Dtype(DtypeCode::Undefined, 1, "Undefined") {}
61 
62  Dtype(DtypeCode dtype_code, int64_t byte_size, const std::string &name);
63 
66  template <typename T>
67  static inline const Dtype FromType() {
68  utility::LogError("Unsupported data for Dtype::FromType.");
69  }
70 
71  int64_t ByteSize() const { return byte_size_; }
72 
73  DtypeCode GetDtypeCode() const { return dtype_code_; }
74 
75  bool IsObject() const { return dtype_code_ == DtypeCode::Object; }
76 
77  std::string ToString() const { return name_; }
78 
79  bool operator==(const Dtype &other) const;
80 
81  bool operator!=(const Dtype &other) const;
82 
83 private:
84  static constexpr size_t max_name_len_ = 16;
85  DtypeCode dtype_code_;
86  int64_t byte_size_;
87  char name_[max_name_len_]; // MSVC warns if std::string is exported to DLL.
88 };
89 
90 template <>
91 inline const Dtype Dtype::FromType<float>() {
92  return Dtype::Float32;
93 }
94 
95 template <>
96 inline const Dtype Dtype::FromType<double>() {
97  return Dtype::Float64;
98 }
99 
100 template <>
101 inline const Dtype Dtype::FromType<int32_t>() {
102  return Dtype::Int32;
103 }
104 
105 template <>
106 inline const Dtype Dtype::FromType<int64_t>() {
107  return Dtype::Int64;
108 }
109 
110 template <>
111 inline const Dtype Dtype::FromType<uint8_t>() {
112  return Dtype::UInt8;
113 }
114 
115 template <>
116 inline const Dtype Dtype::FromType<uint16_t>() {
117  return Dtype::UInt16;
118 }
119 
120 template <>
121 inline const Dtype Dtype::FromType<bool>() {
122  return Dtype::Bool;
123 }
124 
125 } // namespace core
126 } // namespace open3d
Dtype()
Definition: Dtype.h:60
FN_SPECIFIERS bool operator!=(const MiniVec< T, N > &a, const MiniVec< T, N > &b)
Definition: MiniVec.h:101
Definition: Dtype.h:39
static const Dtype FromType()
Definition: Dtype.h:67
void LogError(const char *format, const Args &... args)
Definition: Console.h:176
DtypeCode
Definition: Dtype.h:51
bool operator==(const PointXYZ A, const PointXYZ B)
Definition: Cloud.h:151
std::string ToString() const
Definition: Dtype.h:77
static const Dtype UInt8
Definition: Dtype.h:46
static const Dtype Int32
Definition: Dtype.h:44
static const Dtype Undefined
Definition: Dtype.h:41
static const Dtype UInt16
Definition: Dtype.h:47
static const Dtype Float32
Definition: Dtype.h:42
static const Dtype Int64
Definition: Dtype.h:45
#define OPEN3D_API
Definition: Macro.h:43
Definition: PinholeCameraIntrinsic.cpp:35
std::string name
Definition: FilePCD.cpp:58
int64_t ByteSize() const
Definition: Dtype.h:71
static const Dtype Bool
Definition: Dtype.h:48
bool IsObject() const
Definition: Dtype.h:75
DtypeCode GetDtypeCode() const
Definition: Dtype.h:73
static const Dtype Float64
Definition: Dtype.h:43