Open3D (C++ API)  0.17.0
Dispatch.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include "open3d/core/Dtype.h"
11 #include "open3d/utility/Logging.h"
12 
30 #define DISPATCH_DTYPE_TO_TEMPLATE(DTYPE, ...) \
31  [&] { \
32  if (DTYPE == open3d::core::Float32) { \
33  using scalar_t = float; \
34  return __VA_ARGS__(); \
35  } else if (DTYPE == open3d::core::Float64) { \
36  using scalar_t = double; \
37  return __VA_ARGS__(); \
38  } else if (DTYPE == open3d::core::Int8) { \
39  using scalar_t = int8_t; \
40  return __VA_ARGS__(); \
41  } else if (DTYPE == open3d::core::Int16) { \
42  using scalar_t = int16_t; \
43  return __VA_ARGS__(); \
44  } else if (DTYPE == open3d::core::Int32) { \
45  using scalar_t = int32_t; \
46  return __VA_ARGS__(); \
47  } else if (DTYPE == open3d::core::Int64) { \
48  using scalar_t = int64_t; \
49  return __VA_ARGS__(); \
50  } else if (DTYPE == open3d::core::UInt8) { \
51  using scalar_t = uint8_t; \
52  return __VA_ARGS__(); \
53  } else if (DTYPE == open3d::core::UInt16) { \
54  using scalar_t = uint16_t; \
55  return __VA_ARGS__(); \
56  } else if (DTYPE == open3d::core::UInt32) { \
57  using scalar_t = uint32_t; \
58  return __VA_ARGS__(); \
59  } else if (DTYPE == open3d::core::UInt64) { \
60  using scalar_t = uint64_t; \
61  return __VA_ARGS__(); \
62  } else { \
63  open3d::utility::LogError("Unsupported data type."); \
64  } \
65  }()
66 
67 #define DISPATCH_DTYPE_TO_TEMPLATE_WITH_BOOL(DTYPE, ...) \
68  [&] { \
69  if (DTYPE == open3d::core::Bool) { \
70  using scalar_t = bool; \
71  return __VA_ARGS__(); \
72  } else { \
73  DISPATCH_DTYPE_TO_TEMPLATE(DTYPE, __VA_ARGS__); \
74  } \
75  }()
76 
77 #define DISPATCH_FLOAT_DTYPE_TO_TEMPLATE(DTYPE, ...) \
78  [&] { \
79  if (DTYPE == open3d::core::Float32) { \
80  using scalar_t = float; \
81  return __VA_ARGS__(); \
82  } else if (DTYPE == open3d::core::Float64) { \
83  using scalar_t = double; \
84  return __VA_ARGS__(); \
85  } else { \
86  open3d::utility::LogError("Unsupported data type."); \
87  } \
88  }()
89 
90 #define DISPATCH_FLOAT_INT_DTYPE_TO_TEMPLATE(FDTYPE, IDTYPE, ...) \
91  [&] { \
92  if (FDTYPE == open3d::core::Float32 && \
93  IDTYPE == open3d::core::Int32) { \
94  using scalar_t = float; \
95  using int_t = int32_t; \
96  return __VA_ARGS__(); \
97  } else if (FDTYPE == open3d::core::Float32 && \
98  IDTYPE == open3d::core::Int64) { \
99  using scalar_t = float; \
100  using int_t = int64_t; \
101  return __VA_ARGS__(); \
102  } else if (FDTYPE == open3d::core::Float64 && \
103  IDTYPE == open3d::core::Int32) { \
104  using scalar_t = double; \
105  using int_t = int32_t; \
106  return __VA_ARGS__(); \
107  } else if (FDTYPE == open3d::core::Float64 && \
108  IDTYPE == open3d::core::Int64) { \
109  using scalar_t = double; \
110  using int_t = int64_t; \
111  return __VA_ARGS__(); \
112  } else { \
113  open3d::utility::LogError("Unsupported data type."); \
114  } \
115  }()