29 #include <unordered_map> 65 const double* intrinsic_ptr = intrinsics.
GetDataPtr<
double>();
66 const double* extrinsic_ptr = extrinsics.
GetDataPtr<
double>();
67 for (
int i = 0; i < 3; ++i) {
68 for (
int j = 0; j < 4; ++j) {
69 extrinsic_[i][j] = extrinsic_ptr[i * 4 + j];
73 fx_ = intrinsic_ptr[0 * 3 + 0];
74 fy_ = intrinsic_ptr[1 * 3 + 1];
75 cx_ = intrinsic_ptr[0 * 3 + 2];
76 cy_ = intrinsic_ptr[1 * 3 + 2];
91 *x_out = x_in * extrinsic_[0][0] + y_in * extrinsic_[0][1] +
92 z_in * extrinsic_[0][2] + extrinsic_[0][3];
93 *y_out = x_in * extrinsic_[1][0] + y_in * extrinsic_[1][1] +
94 z_in * extrinsic_[1][2] + extrinsic_[1][3];
95 *z_out = x_in * extrinsic_[2][0] + y_in * extrinsic_[2][1] +
96 z_in * extrinsic_[2][2] + extrinsic_[2][3];
105 float* z_out)
const {
110 *x_out = x_in * extrinsic_[0][0] + y_in * extrinsic_[0][1] +
111 z_in * extrinsic_[0][2];
112 *y_out = x_in * extrinsic_[1][0] + y_in * extrinsic_[1][1] +
113 z_in * extrinsic_[1][2];
114 *z_out = x_in * extrinsic_[2][0] + y_in * extrinsic_[2][1] +
115 z_in * extrinsic_[2][2];
123 float* v_out)
const {
124 float inv_z = 1.0f / z_in;
125 *u_out = fx_ * x_in * inv_z + cx_;
126 *v_out = fy_ * y_in * inv_z + cy_;
135 float* z_out)
const {
136 *x_out = (u_in - cx_) * d_in / fx_;
137 *y_out = (v_in - cy_) * d_in / fy_;
149 *x = extrinsic_[0][3];
150 *y = extrinsic_[1][3];
151 *z = extrinsic_[2][3];
155 float extrinsic_[3][4];
179 template <
typename index_t>
191 "[TArrayIndexer] Only support contiguous tensors for " 192 "general operations.");
197 if (active_dims > MAX_RESOLUTION_DIMS || active_dims > n) {
199 "[TArrayIndexer] Tensor shape too large, only <= {} and " 200 "<= {} array dim is supported, but received {}.",
201 MAX_RESOLUTION_DIMS, n, active_dims);
205 active_dims_ = active_dims;
206 for (
index_t i = 0; i < active_dims_; ++i) {
207 shape_[i] = shape[i];
211 for (
index_t i = active_dims_; i < n; ++i) {
212 element_byte_size_ *= shape[i];
219 ptr_ =
const_cast<void*
>(ndarray.
GetDataPtr());
225 if (n > MAX_RESOLUTION_DIMS) {
227 "[TArrayIndexer] SizeVector too large, only <= {} is " 228 "supported, but received {}.",
229 MAX_RESOLUTION_DIMS, n);
232 for (
index_t i = 0; i < active_dims_; ++i) {
233 shape_[i] = shape[i];
242 element_byte_size_ = 0;
250 for (
index_t i = 0; i < active_dims_; ++i) {
251 num_elems *= shape_[i];
260 *workload = y_in * shape_[1] + x_in;
268 *workload = (z_in * shape_[1] + y_in) * shape_[2] + x_in;
277 *workload = ((t_in * shape_[1] + z_in) * shape_[2] + y_in) * shape_[3] +
285 *x_out = workload % shape_[1];
286 *y_out = workload / shape_[1];
294 *x_out = workload % shape_[2];
295 workload = (workload - *x_out) / shape_[2];
296 *y_out = workload % shape_[1];
297 *z_out = workload / shape_[1];
306 *x_out = workload % shape_[3];
307 workload = (workload - *x_out) / shape_[3];
308 *y_out = workload % shape_[2];
309 workload = (workload - *y_out) / shape_[2];
310 *z_out = workload % shape_[1];
311 *t_out = workload / shape_[1];
315 return y >= 0 && x >= 0 && y <= shape_[0] - 1.0f &&
316 x <= shape_[1] - 1.0f;
319 return z >= 0 && y >= 0 && x >= 0 && z <= shape_[0] - 1.0f &&
320 y <= shape_[1] - 1.0f && x <= shape_[2] - 1.0f;
326 return t >= 0 && z >= 0 && y >= 0 && x >= 0 && t <= shape_[0] - 1.0f &&
327 z <= shape_[1] - 1.0f && y <= shape_[2] - 1.0f &&
328 x <= shape_[3] - 1.0f;
337 template <
typename T>
339 return static_cast<T*
>(
static_cast<void*
>(
static_cast<uint8_t*
>(ptr_) +
340 x * element_byte_size_));
343 template <
typename T>
346 CoordToWorkload(x, y, &workload);
347 return static_cast<T*
>(
static_cast<void*
>(
348 static_cast<uint8_t*
>(ptr_) + workload * element_byte_size_));
351 template <
typename T>
356 CoordToWorkload(x, y, z, &workload);
357 return static_cast<T*
>(
static_cast<void*
>(
358 static_cast<uint8_t*
>(ptr_) + workload * element_byte_size_));
361 template <
typename T>
367 CoordToWorkload(x, y, z, t, &workload);
368 return static_cast<T*
>(
static_cast<void*
>(
369 static_cast<uint8_t*
>(ptr_) + workload * element_byte_size_));
OPEN3D_HOST_DEVICE index_t GetShape(int i) const
Definition: GeometryIndexer.h:331
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:301
TArrayIndexer()
Definition: GeometryIndexer.h:182
Definition: GeometryIndexer.h:180
int64_t NumDims() const
Definition: Tensor.h:1102
OPEN3D_HOST_DEVICE index_t NumElements()
Definition: GeometryIndexer.h:248
OPEN3D_HOST_DEVICE T * GetDataPtr(index_t x, index_t y) const
Definition: GeometryIndexer.h:344
TArrayIndexer(const core::Tensor &ndarray, index_t active_dims)
Definition: GeometryIndexer.h:188
OPEN3D_HOST_DEVICE void * GetDataPtr() const
Definition: GeometryIndexer.h:335
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:272
OPEN3D_HOST_DEVICE T * GetDataPtr(index_t x) const
Definition: GeometryIndexer.h:338
const int64_t MAX_RESOLUTION_DIMS
Definition: GeometryIndexer.h:177
TArrayIndexer(const core::SizeVector &shape)
Only used for simple shapes.
Definition: GeometryIndexer.h:223
OPEN3D_HOST_DEVICE T * GetDataPtr(index_t x, index_t y, index_t z, index_t t) const
Definition: GeometryIndexer.h:362
OPEN3D_HOST_DEVICE void CoordToWorkload(index_t x_in, index_t y_in, index_t *workload) const
2D coordinate => workload
Definition: GeometryIndexer.h:257
Definition: SizeVector.h:79
Dtype GetDtype() const
Definition: Tensor.h:1094
#define AssertTensorShape(tensor,...)
Definition: TensorCheck.h:77
OPEN3D_HOST_DEVICE bool InBoundary(float x, float y, float z, float t) const
Definition: GeometryIndexer.h:322
#define OPEN3D_HOST_DEVICE
Definition: CUDAUtils.h:63
int32_t index_t
Definition: NanoFlannImpl.h:43
bool IsContiguous() const
Definition: Tensor.h:966
OPEN3D_HOST_DEVICE T * GetDataPtr(index_t x, index_t y, index_t z) const
Definition: GeometryIndexer.h:352
#define AssertTensorDtype(tensor,...)
Definition: TensorCheck.h:40
#define AssertTensorDevice(tensor,...)
Definition: TensorCheck.h:62
OPEN3D_HOST_DEVICE index_t ElementByteSize()
Definition: GeometryIndexer.h:246
SizeVector GetShape() const
Definition: Tensor.h:1057
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:290
Definition: PinholeCameraIntrinsic.cpp:35
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:264
OPEN3D_HOST_DEVICE bool InBoundary(float x, float y, float z) const
Definition: GeometryIndexer.h:318
int64_t ByteSize() const
Definition: Dtype.h:77
const Dtype Float64
Definition: Dtype.cpp:62
T * GetDataPtr()
Definition: Tensor.h:1074
OPEN3D_HOST_DEVICE bool InBoundary(float x, float y) const
Definition: GeometryIndexer.h:314
#define LogError(...)
Definition: Logging.h:72
OPEN3D_HOST_DEVICE void WorkloadToCoord(index_t workload, index_t *x_out, index_t *y_out) const
Workload => 2D coordinate.
Definition: GeometryIndexer.h:282