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 "Only support contiguous tensors for general operations.");
196 if (active_dims > MAX_RESOLUTION_DIMS || active_dims > n) {
198 "Tensor shape too large, only <= {} and <= {} array dim is " 199 "supported, but received {}.",
200 MAX_RESOLUTION_DIMS, n, active_dims);
204 active_dims_ = active_dims;
205 for (
index_t i = 0; i < active_dims_; ++i) {
206 shape_[i] = shape[i];
210 for (
index_t i = active_dims_; i < n; ++i) {
211 element_byte_size_ *= shape[i];
218 ptr_ =
const_cast<void*
>(ndarray.
GetDataPtr());
224 if (n > MAX_RESOLUTION_DIMS) {
226 "SizeVector too large, only <= {} is supported, but " 228 MAX_RESOLUTION_DIMS, n);
231 for (
index_t i = 0; i < active_dims_; ++i) {
232 shape_[i] = shape[i];
241 element_byte_size_ = 0;
249 for (
index_t i = 0; i < active_dims_; ++i) {
250 num_elems *= shape_[i];
259 *workload = y_in * shape_[1] + x_in;
267 *workload = (z_in * shape_[1] + y_in) * shape_[2] + x_in;
276 *workload = ((t_in * shape_[1] + z_in) * shape_[2] + y_in) * shape_[3] +
284 *x_out = workload % shape_[1];
285 *y_out = workload / shape_[1];
293 *x_out = workload % shape_[2];
294 workload = (workload - *x_out) / shape_[2];
295 *y_out = workload % shape_[1];
296 *z_out = workload / shape_[1];
305 *x_out = workload % shape_[3];
306 workload = (workload - *x_out) / shape_[3];
307 *y_out = workload % shape_[2];
308 workload = (workload - *y_out) / shape_[2];
309 *z_out = workload % shape_[1];
310 *t_out = workload / shape_[1];
314 return y >= 0 && x >= 0 && y <= shape_[0] - 1.0f &&
315 x <= shape_[1] - 1.0f;
318 return z >= 0 && y >= 0 && x >= 0 && z <= shape_[0] - 1.0f &&
319 y <= shape_[1] - 1.0f && x <= shape_[2] - 1.0f;
325 return t >= 0 && z >= 0 && y >= 0 && x >= 0 && t <= shape_[0] - 1.0f &&
326 z <= shape_[1] - 1.0f && y <= shape_[2] - 1.0f &&
327 x <= shape_[3] - 1.0f;
336 template <
typename T>
338 return static_cast<T*
>(
static_cast<void*
>(
static_cast<uint8_t*
>(ptr_) +
339 x * element_byte_size_));
342 template <
typename T>
345 CoordToWorkload(x, y, &workload);
346 return static_cast<T*
>(
static_cast<void*
>(
347 static_cast<uint8_t*
>(ptr_) + workload * element_byte_size_));
350 template <
typename T>
355 CoordToWorkload(x, y, z, &workload);
356 return static_cast<T*
>(
static_cast<void*
>(
357 static_cast<uint8_t*
>(ptr_) + workload * element_byte_size_));
360 template <
typename T>
366 CoordToWorkload(x, y, z, t, &workload);
367 return static_cast<T*
>(
static_cast<void*
>(
368 static_cast<uint8_t*
>(ptr_) + workload * element_byte_size_));
OPEN3D_HOST_DEVICE index_t GetShape(int i) const
Definition: GeometryIndexer.h:330
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:300
TArrayIndexer()
Definition: GeometryIndexer.h:182
Definition: GeometryIndexer.h:180
int64_t NumDims() const
Definition: Tensor.h:1177
OPEN3D_HOST_DEVICE index_t NumElements()
Definition: GeometryIndexer.h:247
OPEN3D_HOST_DEVICE T * GetDataPtr(index_t x, index_t y) const
Definition: GeometryIndexer.h:343
TArrayIndexer(const core::Tensor &ndarray, index_t active_dims)
Definition: GeometryIndexer.h:188
OPEN3D_HOST_DEVICE void * GetDataPtr() const
Definition: GeometryIndexer.h:334
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:271
size_t size() const
Definition: SmallVector.h:138
OPEN3D_HOST_DEVICE T * GetDataPtr(index_t x) const
Definition: GeometryIndexer.h:337
const int64_t MAX_RESOLUTION_DIMS
Definition: GeometryIndexer.h:177
TArrayIndexer(const core::SizeVector &shape)
Only used for simple shapes.
Definition: GeometryIndexer.h:222
OPEN3D_HOST_DEVICE T * GetDataPtr(index_t x, index_t y, index_t z, index_t t) const
Definition: GeometryIndexer.h:361
OPEN3D_HOST_DEVICE void CoordToWorkload(index_t x_in, index_t y_in, index_t *workload) const
2D coordinate => workload
Definition: GeometryIndexer.h:256
Definition: SizeVector.h:88
Dtype GetDtype() const
Definition: Tensor.h:1169
#define AssertTensorShape(tensor,...)
Definition: TensorCheck.h:77
OPEN3D_HOST_DEVICE bool InBoundary(float x, float y, float z, float t) const
Definition: GeometryIndexer.h:321
#define OPEN3D_HOST_DEVICE
Definition: CUDAUtils.h:63
bool IsContiguous() const
Definition: Tensor.h:1041
OPEN3D_HOST_DEVICE T * GetDataPtr(index_t x, index_t y, index_t z) const
Definition: GeometryIndexer.h:351
#define AssertTensorDtype(tensor,...)
Definition: TensorCheck.h:40
int index_t
Definition: VoxelBlockGrid.h:41
#define AssertTensorDevice(tensor,...)
Definition: TensorCheck.h:62
OPEN3D_HOST_DEVICE index_t ElementByteSize()
Definition: GeometryIndexer.h:245
SizeVector GetShape() const
Definition: Tensor.h:1132
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:289
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:263
OPEN3D_HOST_DEVICE bool InBoundary(float x, float y, float z) const
Definition: GeometryIndexer.h:317
int64_t ByteSize() const
Definition: Dtype.h:77
const Dtype Float64
Definition: Dtype.cpp:62
T * GetDataPtr()
Definition: Tensor.h:1149
OPEN3D_HOST_DEVICE bool InBoundary(float x, float y) const
Definition: GeometryIndexer.h:313
#define LogError(...)
Definition: Logging.h:67
OPEN3D_HOST_DEVICE void WorkloadToCoord(index_t workload, index_t *x_out, index_t *y_out) const
Workload => 2D coordinate.
Definition: GeometryIndexer.h:281