28#if defined(__CUDACC__)
30#elif defined(SYCL_LANGUAGE_VERSION)
43#define LINEAR_SATURATE(elem_t, calc_t) \
44 elem_t limits[2] = {std::numeric_limits<elem_t>::min(), \
45 std::numeric_limits<elem_t>::max()}; \
46 calc_t c_scale = static_cast<calc_t>(scale); \
47 calc_t c_offset = static_cast<calc_t>(offset); \
48 DISPATCH_DTYPE_TO_TEMPLATE(src.GetDtype(), [&]() { \
50 src.GetDevice(), indexer.NumWorkloads(), \
51 [=] OPEN3D_DEVICE(int64_t workload_idx) { \
53 indexer.GetInputPtr<scalar_t>(0, workload_idx); \
54 auto dst_ptr = indexer.GetOutputPtr<elem_t>(workload_idx); \
55 calc_t out = static_cast<calc_t>(*src_ptr) * c_scale + \
57 out = out < limits[0] ? limits[0] : out; \
58 out = out > limits[1] ? limits[1] : out; \
59 *dst_ptr = static_cast<elem_t>(out); \
87#if defined(__CUDACC__)
89#elif defined(SYCL_LANGUAGE_VERSION)
103 int64_t rows = src.GetShape(0);
104 int64_t cols = dst.GetShape(1);
105 int64_t n = rows * cols;
108 core::ParallelFor(src.GetDevice(), n,
109 [=] OPEN3D_DEVICE(int64_t workload_idx) {
110 int64_t y = workload_idx / cols;
111 int64_t x = workload_idx % cols;
113 float in = static_cast<float>(
114 *src_indexer.GetDataPtr<scalar_t>(x, y));
115 float out = in / scale;
116 out = out <= min_value ? clip_fill : out;
117 out = out >= max_value ? clip_fill : out;
118 *dst_indexer.GetDataPtr<float>(x, y) = out;
125#if defined(__CUDACC__)
127#elif defined(SYCL_LANGUAGE_VERSION)
135 float invalid_fill) {
142 int rows_down = dst_indexer.
GetShape(0);
143 int cols_down = dst_indexer.
GetShape(1);
144 int n = rows_down * cols_down;
148 const int gkernel_size = 5;
149 const int gkernel_size_2 = gkernel_size / 2;
150 const float gweights[3] = {0.375f, 0.25f, 0.0625f};
159 src.GetDevice(), n, [=]
OPEN3D_DEVICE(int64_t workload_idx) {
160 int y = workload_idx / cols_down;
161 int x = workload_idx % cols_down;
166 float v_center = *src_indexer.
GetDataPtr<
float>(x_src, y_src);
167 if (v_center == invalid_fill) {
168 *dst_indexer.
GetDataPtr<
float>(x, y) = invalid_fill;
172 int x_min = max(0, x_src - gkernel_size_2);
173 int y_min = max(0, y_src - gkernel_size_2);
175 int x_max = min(cols - 1, x_src + gkernel_size_2);
176 int y_max = min(rows - 1, y_src + gkernel_size_2);
180 for (
int yk = y_min; yk <= y_max; ++yk) {
181 for (
int xk = x_min; xk <= x_max; ++xk) {
182 float v = *src_indexer.
GetDataPtr<
float>(xk, yk);
183 int dy = abs(yk - y_src);
184 int dx = abs(xk - x_src);
186 if (v != invalid_fill &&
187 abs(v - v_center) < depth_diff) {
188 float w = gweights[dx] * gweights[dy];
196 w_sum == 0 ? invalid_fill : v_sum / w_sum;
200#if defined(__CUDACC__)
201void CreateVertexMapCUDA
202#elif defined(SYCL_LANGUAGE_VERSION)
203void CreateVertexMapSYCL
210 float invalid_fill) {
216 int64_t rows = src.GetShape(0);
217 int64_t cols = src.GetShape(1);
218 int64_t n = rows * cols;
226 src.GetDevice(), n, [=]
OPEN3D_DEVICE(int64_t workload_idx) {
228 if (isinf(invalid_fill))
return isinf(v);
229 if (isnan(invalid_fill))
return isnan(v);
230 return v == invalid_fill;
233 int64_t y = workload_idx / cols;
234 int64_t x = workload_idx % cols;
236 float d = *src_indexer.
GetDataPtr<
float>(x, y);
238 float* vertex = dst_indexer.
GetDataPtr<
float>(x, y);
239 if (!is_invalid(d)) {
240 ti.
Unproject(
static_cast<float>(x),
static_cast<float>(y),
241 d, vertex + 0, vertex + 1, vertex + 2);
243 vertex[0] = invalid_fill;
244 vertex[1] = invalid_fill;
245 vertex[2] = invalid_fill;
249#if defined(__CUDACC__)
250void CreateNormalMapCUDA
251#elif defined(SYCL_LANGUAGE_VERSION)
252void CreateNormalMapSYCL
260 int64_t rows = src_indexer.
GetShape(0);
261 int64_t cols = src_indexer.
GetShape(1);
262 int64_t n = rows * cols;
265 src.GetDevice(), n, [=]
OPEN3D_DEVICE(int64_t workload_idx) {
266 int64_t y = workload_idx / cols;
267 int64_t x = workload_idx % cols;
269 float* normal = dst_indexer.
GetDataPtr<
float>(x, y);
271 if (y < rows - 1 && x < cols - 1) {
272 float* v00 = src_indexer.
GetDataPtr<
float>(x, y);
273 float* v10 = src_indexer.
GetDataPtr<
float>(x + 1, y);
274 float* v01 = src_indexer.
GetDataPtr<
float>(x, y + 1);
276 if ((v00[0] == invalid_fill && v00[1] == invalid_fill &&
277 v00[2] == invalid_fill) ||
278 (v01[0] == invalid_fill && v01[1] == invalid_fill &&
279 v01[2] == invalid_fill) ||
280 (v10[0] == invalid_fill && v10[1] == invalid_fill &&
281 v10[2] == invalid_fill)) {
282 normal[0] = invalid_fill;
283 normal[1] = invalid_fill;
284 normal[2] = invalid_fill;
288 float dx0 = v01[0] - v00[0];
289 float dy0 = v01[1] - v00[1];
290 float dz0 = v01[2] - v00[2];
292 float dx1 = v10[0] - v00[0];
293 float dy1 = v10[1] - v00[1];
294 float dz1 = v10[2] - v00[2];
296 normal[0] = dy0 * dz1 - dz0 * dy1;
297 normal[1] = dz0 * dx1 - dx0 * dz1;
298 normal[2] = dx0 * dy1 - dy0 * dx1;
300 constexpr float EPSILON = 1e-5f;
302 sqrt(normal[0] * normal[0] + normal[1] * normal[1] +
303 normal[2] * normal[2]);
304 normal_norm = std::max(normal_norm, EPSILON);
305 normal[0] /= normal_norm;
306 normal[1] /= normal_norm;
307 normal[2] /= normal_norm;
309 normal[0] = invalid_fill;
310 normal[1] = invalid_fill;
311 normal[2] = invalid_fill;
316#if defined(__CUDACC__)
317void ColorizeDepthCUDA
318#elif defined(SYCL_LANGUAGE_VERSION)
319void ColorizeDepthSYCL
331 int64_t rows = src.GetShape(0);
332 int64_t cols = dst.GetShape(1);
333 int64_t n = rows * cols;
335 float inv_interval = 255.0f / (max_value - min_value);
338 src.GetDevice(), n, [=] OPEN3D_DEVICE(int64_t workload_idx) {
339 int64_t y = workload_idx / cols;
340 int64_t x = workload_idx % cols;
342 float in = static_cast<float>(
343 *src_indexer.GetDataPtr<scalar_t>(x, y));
344 float out = in / scale;
345 out = out <= min_value ? min_value : out;
346 out = out >= max_value ? max_value : out;
349 static_cast<int>(inv_interval * (out - min_value));
350 uint8_t* out_ptr = dst_indexer.GetDataPtr<uint8_t>(x, y);
351 out_ptr[0] = turbo_srgb_bytes[idx][0];
352 out_ptr[1] = turbo_srgb_bytes[idx][1];
353 out_ptr[2] = turbo_srgb_bytes[idx][2];
#define OPEN3D_DEVICE
Definition CUDAUtils.h:44
#define DISPATCH_DTYPE_TO_TEMPLATE(DTYPE,...)
Definition Dispatch.h:30
std::shared_ptr< core::Tensor > image
Definition FilamentRenderer.cpp:328
#define LINEAR_SATURATE(elem_t, calc_t)
double t
Definition SurfaceReconstructionPoisson.cpp:172
Indexer indexer
Definition UnaryEWSYCL.cpp:34
static Tensor Eye(int64_t n, Dtype dtype, const Device &device)
Create an identity matrix of size n x n.
Definition Tensor.cpp:417
Definition GeometryIndexer.h:161
OPEN3D_HOST_DEVICE void * GetDataPtr() const
Definition GeometryIndexer.h:315
OPEN3D_HOST_DEVICE index_t GetShape(int i) const
Definition GeometryIndexer.h:311
const Dtype UInt32
Definition Dtype.cpp:50
const Dtype Int64
Definition Dtype.cpp:47
const Dtype UInt16
Definition Dtype.cpp:49
const Dtype Int32
Definition Dtype.cpp:46
const Dtype Int16
Definition Dtype.cpp:45
const Dtype UInt8
Definition Dtype.cpp:48
void ParallelFor(const Device &device, int64_t n, const func_t &func)
Definition ParallelFor.h:135
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
void ClipTransformCPU(const core::Tensor &src, core::Tensor &dst, float scale, float min_value, float max_value, float clip_fill=0.0f)
Definition ImageImpl.h:94
void CreateNormalMapCPU(const core::Tensor &src, core::Tensor &dst, float invalid_fill)
Definition ImageImpl.h:256
void ColorizeDepthCPU(const core::Tensor &src, core::Tensor &dst, float scale, float min_value, float max_value)
Definition ImageImpl.h:323
void CreateVertexMapCPU(const core::Tensor &src, core::Tensor &dst, const core::Tensor &intrinsics, float invalid_fill)
Definition ImageImpl.h:207
void PyrDownDepthCPU(const core::Tensor &src, core::Tensor &dst, float diff_threshold, float invalid_fill)
Definition ImageImpl.h:132
void ToCPU(const core::Tensor &src, core::Tensor &dst, double scale, double offset)
Definition ImageImpl.h:35
Definition PinholeCameraIntrinsic.cpp:16