29 #include <unordered_map> 63 const double* intrinsic_ptr = intrinsics.
GetDataPtr<
double>();
64 const double* extrinsic_ptr = extrinsics.
GetDataPtr<
double>();
65 for (
int i = 0; i < 3; ++i) {
66 for (
int j = 0; j < 4; ++j) {
67 extrinsic_[i][j] = extrinsic_ptr[i * 4 + j];
71 fx_ = intrinsic_ptr[0 * 3 + 0];
72 fy_ = intrinsic_ptr[1 * 3 + 1];
73 cx_ = intrinsic_ptr[0 * 3 + 2];
74 cy_ = intrinsic_ptr[1 * 3 + 2];
89 *x_out = x_in * extrinsic_[0][0] + y_in * extrinsic_[0][1] +
90 z_in * extrinsic_[0][2] + extrinsic_[0][3];
91 *y_out = x_in * extrinsic_[1][0] + y_in * extrinsic_[1][1] +
92 z_in * extrinsic_[1][2] + extrinsic_[1][3];
93 *z_out = x_in * extrinsic_[2][0] + y_in * extrinsic_[2][1] +
94 z_in * extrinsic_[2][2] + extrinsic_[2][3];
103 float* z_out)
const {
108 *x_out = x_in * extrinsic_[0][0] + y_in * extrinsic_[0][1] +
109 z_in * extrinsic_[0][2];
110 *y_out = x_in * extrinsic_[1][0] + y_in * extrinsic_[1][1] +
111 z_in * extrinsic_[1][2];
112 *z_out = x_in * extrinsic_[2][0] + y_in * extrinsic_[2][1] +
113 z_in * extrinsic_[2][2];
121 float* v_out)
const {
122 float inv_z = 1.0f / z_in;
123 *u_out = fx_ * x_in * inv_z + cx_;
124 *v_out = fy_ * y_in * inv_z + cy_;
133 float* z_out)
const {
134 *x_out = (u_in - cx_) * d_in / fx_;
135 *y_out = (v_in - cy_) * d_in / fy_;
145 float extrinsic_[3][4];
179 "[NDArrayIndexer] Only support contiguous tensors for " 180 "general operations.");
185 if (active_dims > MAX_RESOLUTION_DIMS || active_dims > n) {
187 "[NDArrayIndexer] Tensor shape too large, only <= {} and " 188 "<= {} array dim is supported, but received {}.",
189 MAX_RESOLUTION_DIMS, n, active_dims);
193 active_dims_ = active_dims;
194 for (int64_t i = 0; i < active_dims_; ++i) {
195 shape_[i] = shape[i];
199 for (int64_t i = active_dims_; i < n; ++i) {
200 element_byte_size_ *= shape[i];
207 ptr_ =
const_cast<void*
>(ndarray.
GetDataPtr());
212 int64_t n =
static_cast<int64_t
>(shape.size());
213 if (n > MAX_RESOLUTION_DIMS) {
215 "[NDArrayIndexer] SizeVector too large, only <= {} is " 216 "supported, but received {}.",
217 MAX_RESOLUTION_DIMS, n);
220 for (int64_t i = 0; i < active_dims_; ++i) {
221 shape_[i] = shape[i];
230 element_byte_size_ = 0;
237 int64_t num_elems = 1;
238 for (int64_t i = 0; i < active_dims_; ++i) {
239 num_elems *= shape_[i];
247 int64_t* workload)
const {
248 *workload = y_in * shape_[1] + x_in;
255 int64_t* workload)
const {
256 *workload = (z_in * shape_[1] + y_in) * shape_[2] + x_in;
264 int64_t* workload)
const {
265 *workload = ((t_in * shape_[1] + z_in) * shape_[2] + y_in) * shape_[3] +
272 int64_t* y_out)
const {
273 *x_out = workload % shape_[1];
274 *y_out = workload / shape_[1];
281 int64_t* z_out)
const {
282 *x_out = workload % shape_[2];
283 workload = (workload - *x_out) / shape_[2];
284 *y_out = workload % shape_[1];
285 *z_out = workload / shape_[1];
293 int64_t* t_out)
const {
294 *x_out = workload % shape_[3];
295 workload = (workload - *x_out) / shape_[3];
296 *y_out = workload % shape_[2];
297 workload = (workload - *y_out) / shape_[2];
298 *z_out = workload % shape_[1];
299 *t_out = workload / shape_[1];
303 return y >= 0 && x >= 0 && y <= shape_[0] - 1.0f &&
304 x <= shape_[1] - 1.0f;
307 return z >= 0 && y >= 0 && x >= 0 && z <= shape_[0] - 1.0f &&
308 y <= shape_[1] - 1.0f && x <= shape_[2] - 1.0f;
314 return t >= 0 && z >= 0 && y >= 0 && x >= 0 && t <= shape_[0] - 1.0f &&
315 z <= shape_[1] - 1.0f && y <= shape_[2] - 1.0f &&
316 x <= shape_[3] - 1.0f;
323 template <
typename T>
325 return static_cast<T*
>(
static_cast<void*
>(
static_cast<uint8_t*
>(ptr_) +
326 x * element_byte_size_));
329 template <
typename T>
332 CoordToWorkload(x, y, &workload);
333 return static_cast<T*
>(
static_cast<void*
>(
334 static_cast<uint8_t*
>(ptr_) + workload * element_byte_size_));
337 template <
typename T>
342 CoordToWorkload(x, y, z, &workload);
343 return static_cast<T*
>(
static_cast<void*
>(
344 static_cast<uint8_t*
>(ptr_) + workload * element_byte_size_));
347 template <
typename T>
353 CoordToWorkload(x, y, z, t, &workload);
354 return static_cast<T*
>(
static_cast<void*
>(
355 static_cast<uint8_t*
>(ptr_) + workload * element_byte_size_));
360 int64_t element_byte_size_;
361 int64_t active_dims_;
OPEN3D_HOST_DEVICE void CoordToWorkload(int64_t x_in, int64_t y_in, int64_t z_in, int64_t t_in, int64_t *workload) const
4D coordinate => workload
Definition: GeometryIndexer.h:260
int64_t NumDims() const
Definition: Tensor.h:1033
NDArrayIndexer(const core::Tensor &ndarray, int64_t active_dims)
Definition: GeometryIndexer.h:176
Definition: GeometryIndexer.h:168
OPEN3D_HOST_DEVICE void WorkloadToCoord(int64_t workload, int64_t *x_out, int64_t *y_out, int64_t *z_out) const
Workload => 3D coordinate.
Definition: GeometryIndexer.h:278
const int64_t MAX_RESOLUTION_DIMS
Definition: GeometryIndexer.h:167
OPEN3D_HOST_DEVICE void CoordToWorkload(int64_t x_in, int64_t y_in, int64_t z_in, int64_t *workload) const
3D coordinate => workload
Definition: GeometryIndexer.h:252
NDArrayIndexer()
Definition: GeometryIndexer.h:170
Definition: SizeVector.h:102
#define LogError(...)
Definition: Console.h:79
Dtype GetDtype() const
Definition: Tensor.h:1025
OPEN3D_HOST_DEVICE T * GetDataPtr(int64_t x, int64_t y, int64_t z, int64_t t) const
Definition: GeometryIndexer.h:348
OPEN3D_HOST_DEVICE void WorkloadToCoord(int64_t workload, int64_t *x_out, int64_t *y_out, int64_t *z_out, int64_t *t_out) const
Workload => 4D coordinate.
Definition: GeometryIndexer.h:289
OPEN3D_HOST_DEVICE T * GetDataPtr(int64_t x) const
Definition: GeometryIndexer.h:324
#define OPEN3D_HOST_DEVICE
Definition: CUDAUtils.h:56
OPEN3D_HOST_DEVICE int64_t GetShape(int i) const
Definition: GeometryIndexer.h:319
bool IsContiguous() const
Definition: Tensor.h:897
OPEN3D_HOST_DEVICE T * GetDataPtr(int64_t x, int64_t y) const
Definition: GeometryIndexer.h:330
OPEN3D_HOST_DEVICE T * GetDataPtr(int64_t x, int64_t y, int64_t z) const
Definition: GeometryIndexer.h:338
void AssertDtype(const Dtype &expected_dtype, const std::string &error_msg="") const
Assert that the Tensor has the specified dtype.
Definition: Tensor.cpp:1534
OPEN3D_HOST_DEVICE bool InBoundary(float x, float y, float z) const
Definition: GeometryIndexer.h:306
SizeVector GetShape() const
Definition: Tensor.h:988
OPEN3D_HOST_DEVICE bool InBoundary(float x, float y, float z, float t) const
Definition: GeometryIndexer.h:310
Definition: PinholeCameraIntrinsic.cpp:35
OPEN3D_HOST_DEVICE void WorkloadToCoord(int64_t workload, int64_t *x_out, int64_t *y_out) const
Workload => 2D coordinate.
Definition: GeometryIndexer.h:270
int64_t ByteSize() const
Definition: Dtype.h:75
NDArrayIndexer(const core::SizeVector &shape)
Only used for simple shapes.
Definition: GeometryIndexer.h:211
OPEN3D_HOST_DEVICE int64_t ElementByteSize()
Definition: GeometryIndexer.h:234
T * GetDataPtr()
Definition: Tensor.h:1005
void AssertDevice(const Device &expected_device, const std::string &error_msg="") const
Assert that the Tensor has the specified device.
Definition: Tensor.cpp:1518
OPEN3D_HOST_DEVICE bool InBoundary(float x, float y) const
Definition: GeometryIndexer.h:302
OPEN3D_HOST_DEVICE int64_t NumElements()
Definition: GeometryIndexer.h:236
static const Dtype Float64
Definition: Dtype.h:43
OPEN3D_HOST_DEVICE void CoordToWorkload(int64_t x_in, int64_t y_in, int64_t *workload) const
2D coordinate => workload
Definition: GeometryIndexer.h:245
void AssertShape(const SizeVector &expected_shape, const std::string &error_msg="") const
Assert that the Tensor has the specified shape.
Definition: Tensor.cpp:1498