10#include <unordered_map>
39 core::AssertTensorShape(intrinsics_cpu, {3, 3});
42 core::AssertTensorShape(extrinsics_cpu, {4, 4});
45 const double* intrinsic_ptr = intrinsics_cpu.
GetDataPtr<
double>();
46 const double* extrinsic_ptr = extrinsics_cpu.
GetDataPtr<
double>();
47 for (
int i = 0; i < 3; ++i) {
48 for (
int j = 0; j < 4; ++j) {
49 extrinsic_[i][j] = extrinsic_ptr[i * 4 + j];
53 fx_ = intrinsic_ptr[0 * 3 + 0];
54 fy_ = intrinsic_ptr[1 * 3 + 1];
55 cx_ = intrinsic_ptr[0 * 3 + 2];
56 cy_ = intrinsic_ptr[1 * 3 + 2];
71 *x_out = x_in * extrinsic_[0][0] + y_in * extrinsic_[0][1] +
72 z_in * extrinsic_[0][2] + extrinsic_[0][3];
73 *y_out = x_in * extrinsic_[1][0] + y_in * extrinsic_[1][1] +
74 z_in * extrinsic_[1][2] + extrinsic_[1][3];
75 *z_out = x_in * extrinsic_[2][0] + y_in * extrinsic_[2][1] +
76 z_in * extrinsic_[2][2] + extrinsic_[2][3];
90 *x_out = x_in * extrinsic_[0][0] + y_in * extrinsic_[0][1] +
91 z_in * extrinsic_[0][2];
92 *y_out = x_in * extrinsic_[1][0] + y_in * extrinsic_[1][1] +
93 z_in * extrinsic_[1][2];
94 *z_out = x_in * extrinsic_[2][0] + y_in * extrinsic_[2][1] +
95 z_in * extrinsic_[2][2];
103 float* v_out)
const {
104 float inv_z = 1.0f / z_in;
105 *u_out = fx_ * x_in * inv_z + cx_;
106 *v_out = fy_ * y_in * inv_z + cy_;
115 float* z_out)
const {
116 *x_out = (u_in - cx_) * d_in / fx_;
117 *y_out = (v_in - cy_) * d_in / fy_;
129 *
x = extrinsic_[0][3];
130 *
y = extrinsic_[1][3];
131 *
z = extrinsic_[2][3];
135 float extrinsic_[3][4];
159template <
typename index_t>
171 "Only support contiguous tensors for general operations.");
178 "Tensor shape too large, only <= {} and <= {} array dim is "
179 "supported, but received {}.",
184 active_dims_ = active_dims;
185 for (index_t i = 0; i < active_dims_; ++i) {
186 shape_[i] = shape[i];
190 for (index_t i = active_dims_; i < n; ++i) {
191 element_byte_size_ *= shape[i];
198 ptr_ =
const_cast<void*
>(ndarray.
GetDataPtr());
203 index_t n =
static_cast<index_t
>(shape.
size());
206 "SizeVector too large, only <= {} is supported, but "
211 for (index_t i = 0; i < active_dims_; ++i) {
212 shape_[i] = shape[i];
221 element_byte_size_ = 0;
228 index_t num_elems = 1;
229 for (index_t i = 0; i < active_dims_; ++i) {
230 num_elems *= shape_[i];
238 index_t* workload)
const {
239 *workload = y_in * shape_[1] + x_in;
246 index_t* workload)
const {
247 *workload = (z_in * shape_[1] + y_in) * shape_[2] + x_in;
255 index_t* workload)
const {
256 *workload = ((t_in * shape_[1] + z_in) * shape_[2] + y_in) * shape_[3] +
263 index_t* y_out)
const {
264 *x_out = workload % shape_[1];
265 *y_out = workload / shape_[1];
272 index_t* z_out)
const {
273 *x_out = workload % shape_[2];
274 workload = (workload - *x_out) / shape_[2];
275 *y_out = workload % shape_[1];
276 *z_out = workload / shape_[1];
284 index_t* t_out)
const {
285 *x_out = workload % shape_[3];
286 workload = (workload - *x_out) / shape_[3];
287 *y_out = workload % shape_[2];
288 workload = (workload - *y_out) / shape_[2];
289 *z_out = workload % shape_[1];
290 *t_out = workload / shape_[1];
294 return y >= 0 &&
x >= 0 &&
y <= shape_[0] - 1.0f &&
295 x <= shape_[1] - 1.0f;
298 return z >= 0 &&
y >= 0 &&
x >= 0 &&
z <= shape_[0] - 1.0f &&
299 y <= shape_[1] - 1.0f &&
x <= shape_[2] - 1.0f;
305 return t >= 0 &&
z >= 0 &&
y >= 0 &&
x >= 0 &&
t <= shape_[0] - 1.0f &&
306 z <= shape_[1] - 1.0f &&
y <= shape_[2] - 1.0f &&
307 x <= shape_[3] - 1.0f;
316 template <
typename T>
318 return static_cast<T*
>(
static_cast<void*
>(
static_cast<uint8_t*
>(ptr_) +
319 x * element_byte_size_));
322 template <
typename T>
326 return static_cast<T*
>(
static_cast<void*
>(
327 static_cast<uint8_t*
>(ptr_) + workload * element_byte_size_));
330 template <
typename T>
336 return static_cast<T*
>(
static_cast<void*
>(
337 static_cast<uint8_t*
>(ptr_) + workload * element_byte_size_));
340 template <
typename T>
347 return static_cast<T*
>(
static_cast<void*
>(
348 static_cast<uint8_t*
>(ptr_) + workload * element_byte_size_));
353 index_t element_byte_size_;
354 index_t active_dims_;
#define OPEN3D_HOST_DEVICE
Definition CUDAUtils.h:43
double t
Definition SurfaceReconstructionPoisson.cpp:175
int64_t ByteSize() const
Definition Dtype.h:58
Definition SizeVector.h:69
size_t size() const
Definition SmallVector.h:120
SizeVector GetShape() const
Definition Tensor.h:1186
T * GetDataPtr()
Definition Tensor.h:1203
Tensor Contiguous() const
Definition Tensor.cpp:817
int64_t NumDims() const
Definition Tensor.h:1231
bool IsContiguous() const
Definition Tensor.h:1093
Dtype GetDtype() const
Definition Tensor.h:1223
Tensor To(Dtype dtype, bool copy=false) const
Definition Tensor.cpp:784
Definition GeometryIndexer.h:160
OPEN3D_HOST_DEVICE void WorkloadToCoord(index_t workload, index_t *x_out, index_t *y_out, index_t *z_out, index_t *t_out) const
Workload => 4D coordinate.
Definition GeometryIndexer.h:280
OPEN3D_HOST_DEVICE bool InBoundary(float x, float y) const
Definition GeometryIndexer.h:293
TArrayIndexer()
Definition GeometryIndexer.h:162
OPEN3D_HOST_DEVICE T * GetDataPtr(index_t x, index_t y, index_t z, index_t t) const
Definition GeometryIndexer.h:341
OPEN3D_HOST_DEVICE void CoordToWorkload(index_t x_in, index_t y_in, index_t z_in, index_t t_in, index_t *workload) const
4D coordinate => workload
Definition GeometryIndexer.h:251
TArrayIndexer(const core::Tensor &ndarray, index_t active_dims)
Definition GeometryIndexer.h:168
OPEN3D_HOST_DEVICE void * GetDataPtr() const
Definition GeometryIndexer.h:314
OPEN3D_HOST_DEVICE void CoordToWorkload(index_t x_in, index_t y_in, index_t *workload) const
2D coordinate => workload
Definition GeometryIndexer.h:236
OPEN3D_HOST_DEVICE void WorkloadToCoord(index_t workload, index_t *x_out, index_t *y_out) const
Workload => 2D coordinate.
Definition GeometryIndexer.h:261
OPEN3D_HOST_DEVICE index_t ElementByteSize()
Definition GeometryIndexer.h:225
OPEN3D_HOST_DEVICE bool InBoundary(float x, float y, float z) const
Definition GeometryIndexer.h:297
OPEN3D_HOST_DEVICE void CoordToWorkload(index_t x_in, index_t y_in, index_t z_in, index_t *workload) const
3D coordinate => workload
Definition GeometryIndexer.h:243
OPEN3D_HOST_DEVICE T * GetDataPtr(index_t x) const
Definition GeometryIndexer.h:317
OPEN3D_HOST_DEVICE index_t GetShape(int i) const
Definition GeometryIndexer.h:310
OPEN3D_HOST_DEVICE T * GetDataPtr(index_t x, index_t y, index_t z) const
Definition GeometryIndexer.h:331
OPEN3D_HOST_DEVICE index_t NumElements()
Definition GeometryIndexer.h:227
OPEN3D_HOST_DEVICE T * GetDataPtr(index_t x, index_t y) const
Definition GeometryIndexer.h:323
OPEN3D_HOST_DEVICE bool InBoundary(float x, float y, float z, float t) const
Definition GeometryIndexer.h:301
OPEN3D_HOST_DEVICE void WorkloadToCoord(index_t workload, index_t *x_out, index_t *y_out, index_t *z_out) const
Workload => 3D coordinate.
Definition GeometryIndexer.h:269
TArrayIndexer(const core::SizeVector &shape)
Only used for simple shapes.
Definition GeometryIndexer.h:202
const Dtype Float64
Definition Dtype.cpp:43
const int64_t MAX_RESOLUTION_DIMS
Definition GeometryIndexer.h:157
Definition PinholeCameraIntrinsic.cpp:16