41 #define LINEAR_SATURATE(elem_t, calc_t) \
42 elem_t limits[2] = {std::numeric_limits<elem_t>::min(), \
43 std::numeric_limits<elem_t>::max()}; \
44 calc_t c_scale = static_cast<calc_t>(scale); \
45 calc_t c_offset = static_cast<calc_t>(offset); \
46 DISPATCH_DTYPE_TO_TEMPLATE(src.GetDtype(), [&]() { \
48 src.GetDevice(), indexer.NumWorkloads(), \
49 [=] OPEN3D_DEVICE(int64_t workload_idx) { \
51 indexer.GetInputPtr<scalar_t>(0, workload_idx); \
52 auto dst_ptr = indexer.GetOutputPtr<elem_t>(workload_idx); \
53 calc_t out = static_cast<calc_t>(*src_ptr) * c_scale + \
55 out = out < limits[0] ? limits[0] : out; \
56 out = out > limits[1] ? limits[1] : out; \
57 *dst_ptr = static_cast<elem_t>(out); \
82 #undef LINEAR_SATURATE
86 void ClipTransformCUDA
99 int64_t rows = src.GetShape(0);
100 int64_t cols = dst.GetShape(1);
101 int64_t n = rows * cols;
104 core::ParallelFor(src.GetDevice(), n,
105 [=] OPEN3D_DEVICE(int64_t workload_idx) {
106 int64_t y = workload_idx / cols;
107 int64_t x = workload_idx % cols;
109 float in = static_cast<float>(
110 *src_indexer.GetDataPtr<scalar_t>(x, y));
111 float out = in / scale;
112 out = out <= min_value ? clip_fill : out;
113 out = out >= max_value ? clip_fill : out;
114 *dst_indexer.GetDataPtr<float>(x, y) = out;
122 void PyrDownDepthCUDA
129 float invalid_fill) {
136 int rows_down = dst_indexer.
GetShape(0);
137 int cols_down = dst_indexer.
GetShape(1);
138 int n = rows_down * cols_down;
142 const int gkernel_size = 5;
143 const int gkernel_size_2 = gkernel_size / 2;
144 const float gweights[3] = {0.375f, 0.25f, 0.0625f};
153 src.GetDevice(), n, [=]
OPEN3D_DEVICE(int64_t workload_idx) {
154 int y = workload_idx / cols_down;
155 int x = workload_idx % cols_down;
160 float v_center = *src_indexer.
GetDataPtr<
float>(x_src, y_src);
161 if (v_center == invalid_fill) {
162 *dst_indexer.
GetDataPtr<
float>(x, y) = invalid_fill;
166 int x_min = max(0, x_src - gkernel_size_2);
167 int y_min = max(0, y_src - gkernel_size_2);
169 int x_max = min(cols - 1, x_src + gkernel_size_2);
170 int y_max = min(rows - 1, y_src + gkernel_size_2);
174 for (
int yk = y_min; yk <= y_max; ++yk) {
175 for (
int xk = x_min; xk <= x_max; ++xk) {
176 float v = *src_indexer.
GetDataPtr<
float>(xk, yk);
177 int dy = abs(yk - y_src);
178 int dx = abs(xk - x_src);
180 if (v != invalid_fill &&
181 abs(v - v_center) < depth_diff) {
182 float w = gweights[dx] * gweights[dy];
190 w_sum == 0 ? invalid_fill : v_sum / w_sum;
195 void CreateVertexMapCUDA
202 float invalid_fill) {
208 int64_t rows = src.GetShape(0);
209 int64_t cols = src.GetShape(1);
210 int64_t n = rows * cols;
218 src.GetDevice(), n, [=]
OPEN3D_DEVICE(int64_t workload_idx) {
220 if (isinf(invalid_fill))
return isinf(v);
221 if (isnan(invalid_fill))
return isnan(v);
222 return v == invalid_fill;
225 int64_t y = workload_idx / cols;
226 int64_t x = workload_idx % cols;
228 float d = *src_indexer.
GetDataPtr<
float>(x, y);
230 float* vertex = dst_indexer.
GetDataPtr<
float>(x, y);
231 if (!is_invalid(d)) {
232 ti.
Unproject(
static_cast<float>(x),
static_cast<float>(y),
233 d, vertex + 0, vertex + 1, vertex + 2);
235 vertex[0] = invalid_fill;
236 vertex[1] = invalid_fill;
237 vertex[2] = invalid_fill;
242 void CreateNormalMapCUDA
250 int64_t rows = src_indexer.
GetShape(0);
251 int64_t cols = src_indexer.
GetShape(1);
252 int64_t n = rows * cols;
255 src.GetDevice(), n, [=]
OPEN3D_DEVICE(int64_t workload_idx) {
256 int64_t y = workload_idx / cols;
257 int64_t x = workload_idx % cols;
259 float* normal = dst_indexer.
GetDataPtr<
float>(x, y);
261 if (y < rows - 1 && x < cols - 1) {
262 float* v00 = src_indexer.
GetDataPtr<
float>(x, y);
263 float* v10 = src_indexer.
GetDataPtr<
float>(x + 1, y);
264 float* v01 = src_indexer.
GetDataPtr<
float>(x, y + 1);
266 if ((v00[0] == invalid_fill && v00[1] == invalid_fill &&
267 v00[2] == invalid_fill) ||
268 (v01[0] == invalid_fill && v01[1] == invalid_fill &&
269 v01[2] == invalid_fill) ||
270 (v10[0] == invalid_fill && v10[1] == invalid_fill &&
271 v10[2] == invalid_fill)) {
272 normal[0] = invalid_fill;
273 normal[1] = invalid_fill;
274 normal[2] = invalid_fill;
278 float dx0 = v01[0] - v00[0];
279 float dy0 = v01[1] - v00[1];
280 float dz0 = v01[2] - v00[2];
282 float dx1 = v10[0] - v00[0];
283 float dy1 = v10[1] - v00[1];
284 float dz1 = v10[2] - v00[2];
286 normal[0] = dy0 * dz1 - dz0 * dy1;
287 normal[1] = dz0 * dx1 - dx0 * dz1;
288 normal[2] = dx0 * dy1 - dy0 * dx1;
290 constexpr
float EPSILON = 1e-5f;
292 sqrt(normal[0] * normal[0] + normal[1] * normal[1] +
293 normal[2] * normal[2]);
294 normal_norm = std::max(normal_norm, EPSILON);
295 normal[0] /= normal_norm;
296 normal[1] /= normal_norm;
297 normal[2] /= normal_norm;
299 normal[0] = invalid_fill;
300 normal[1] = invalid_fill;
301 normal[2] = invalid_fill;
307 void ColorizeDepthCUDA
319 int64_t rows = src.GetShape(0);
320 int64_t cols = dst.GetShape(1);
321 int64_t n = rows * cols;
326 src.GetDevice(), n, [=] OPEN3D_DEVICE(int64_t workload_idx) {
327 int64_t y = workload_idx / cols;
328 int64_t x = workload_idx % cols;
330 float in = static_cast<float>(
331 *src_indexer.GetDataPtr<scalar_t>(x, y));
332 float out = in / scale;
333 out = out <= min_value ? min_value : out;
334 out = out >= max_value ? max_value : out;
337 static_cast<int>(inv_interval * (out - min_value));
338 uint8_t* out_ptr = dst_indexer.GetDataPtr<uint8_t>(x, y);
339 out_ptr[0] = turbo_srgb_bytes[idx][0];
340 out_ptr[1] = turbo_srgb_bytes[idx][1];
341 out_ptr[2] = turbo_srgb_bytes[idx][2];
#define OPEN3D_DEVICE
Definition: CUDAUtils.h:45
#define DISPATCH_DTYPE_TO_TEMPLATE(DTYPE,...)
Definition: Dispatch.h:30
std::shared_ptr< core::Tensor > image
Definition: FilamentRenderer.cpp:183
#define LINEAR_SATURATE(elem_t, calc_t)
Definition: Indexer.h:261
static Tensor Eye(int64_t n, Dtype dtype, const Device &device)
Create an identity matrix of size n x n.
Definition: Tensor.cpp:386
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:103
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
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t timeout_in_ms capture_handle capture_handle capture_handle image_handle temperature_c k4a_image_t image_handle uint8_t image_handle image_handle image_handle image_handle uint32_t
Definition: K4aPlugin.cpp:548
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t timeout_in_ms capture_handle capture_handle capture_handle image_handle temperature_c k4a_image_t image_handle uint8_t image_handle image_handle image_handle image_handle image_handle timestamp_usec white_balance image_handle k4a_device_configuration_t config device_handle char size_t serial_number_size bool int32_t int32_t max_value
Definition: K4aPlugin.cpp:649
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample uint64_t
Definition: K4aPlugin.cpp:343
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t timeout_in_ms capture_handle capture_handle capture_handle image_handle temperature_c k4a_image_t image_handle uint8_t image_handle image_handle image_handle image_handle image_handle timestamp_usec white_balance image_handle k4a_device_configuration_t config device_handle char size_t serial_number_size bool int32_t min_value
Definition: K4aPlugin.cpp:647
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t int32_t
Definition: K4aPlugin.cpp:395
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:90
void CreateNormalMapCPU(const core::Tensor &src, core::Tensor &dst, float invalid_fill)
Definition: ImageImpl.h:246
void ColorizeDepthCPU(const core::Tensor &src, core::Tensor &dst, float scale, float min_value, float max_value)
Definition: ImageImpl.h:311
void CreateVertexMapCPU(const core::Tensor &src, core::Tensor &dst, const core::Tensor &intrinsics, float invalid_fill)
Definition: ImageImpl.h:199
void PyrDownDepthCPU(const core::Tensor &src, core::Tensor &dst, float diff_threshold, float invalid_fill)
Definition: ImageImpl.h:126
void ToCPU(const core::Tensor &src, core::Tensor &dst, double scale, double offset)
Definition: ImageImpl.h:33
Definition: PinholeCameraIntrinsic.cpp:16