29 #include <unordered_map> 49 extrinsic.AssertShape({4, 4});
53 for (
int i = 0; i < 3; ++i) {
54 for (
int j = 0; j < 4; ++j) {
55 extrinsic_[i][j] = extrinsic[i][j].Item<
float>();
59 fx_ = intrinsic[0][0].
Item<
float>();
60 fy_ = intrinsic[1][1].
Item<
float>();
61 cx_ = intrinsic[0][2].
Item<
float>();
62 cy_ = intrinsic[1][2].
Item<
float>();
78 *x_out = x_in * extrinsic_[0][0] + y_in * extrinsic_[0][1] +
79 z_in * extrinsic_[0][2] + extrinsic_[0][3];
80 *y_out = x_in * extrinsic_[1][0] + y_in * extrinsic_[1][1] +
81 z_in * extrinsic_[1][2] + extrinsic_[1][3];
82 *z_out = x_in * extrinsic_[2][0] + y_in * extrinsic_[2][1] +
83 z_in * extrinsic_[2][2] + extrinsic_[2][3];
92 float inv_z = 1.0f / z_in;
93 *u_out = fx_ * x_in * inv_z + cx_;
94 *v_out = fy_ * y_in * inv_z + cy_;
103 float* z_out)
const {
104 *x_out = (u_in - cx_) * d_in / fx_;
105 *y_out = (v_in - cy_) * d_in / fy_;
110 float extrinsic_[3][4];
144 "[NDArrayIndexer] Only support contiguous tensors for " 145 "general operations.");
150 if (active_dims > MAX_RESOLUTION_DIMS || active_dims > n) {
152 "[NDArrayIndexer] Tensor shape too large, only <= {} is " 153 "supported, but received {}.",
154 MAX_RESOLUTION_DIMS, active_dims);
158 active_dims_ = active_dims;
159 for (int64_t i = 0; i < active_dims_; ++i) {
160 shape_[i] = shape[i];
164 for (int64_t i = active_dims_; i < n; ++i) {
165 element_byte_size_ *= shape[i];
167 ptr_ =
const_cast<void*
>(ndarray.
GetDataPtr());
172 int64_t n =
static_cast<int64_t
>(shape.size());
173 if (n > MAX_RESOLUTION_DIMS) {
175 "[NDArrayIndexer] SizeVector too large, only <= {} is " 176 "supported, but received {}.",
177 MAX_RESOLUTION_DIMS, n);
180 for (int64_t i = 0; i < active_dims_; ++i) {
181 shape_[i] = shape[i];
185 element_byte_size_ = 0;
192 int64_t num_elems = 1;
193 for (int64_t i = 0; i < active_dims_; ++i) {
194 num_elems *= shape_[i];
202 int64_t* workload)
const {
203 *workload = y_in * shape_[1] + x_in;
210 int64_t* workload)
const {
211 *workload = (z_in * shape_[1] + y_in) * shape_[2] + x_in;
219 int64_t* workload)
const {
220 *workload = ((t_in * shape_[1] + z_in) * shape_[2] + y_in) * shape_[3] +
227 int64_t* y_out)
const {
228 *x_out = workload % shape_[1];
229 *y_out = workload / shape_[1];
236 int64_t* z_out)
const {
237 *x_out = workload % shape_[2];
238 workload = (workload - *x_out) / shape_[2];
239 *y_out = workload % shape_[1];
240 *z_out = workload / shape_[1];
248 int64_t* t_out)
const {
249 *x_out = workload % shape_[3];
250 workload = (workload - *x_out) / shape_[3];
251 *y_out = workload % shape_[2];
252 workload = (workload - *y_out) / shape_[2];
253 *z_out = workload % shape_[1];
254 *t_out = workload / shape_[1];
258 return y >= 0 && x >= 0 && y <= shape_[0] - 1.0f &&
259 x <= shape_[1] - 1.0f;
262 return z >= 0 && y >= 0 && x >= 0 && z <= shape_[0] - 1.0f &&
263 y <= shape_[1] - 1.0f && x <= shape_[2] - 1.0f;
269 return t >= 0 && z >= 0 && y >= 0 && x >= 0 && t <= shape_[0] - 1.0f &&
270 z <= shape_[1] - 1.0f && y <= shape_[2] - 1.0f &&
271 x <= shape_[3] - 1.0f;
279 return static_cast<void*
>(
static_cast<uint8_t*
>(ptr_) +
280 x * element_byte_size_);
286 CoordToWorkload(x, y, &workload);
287 return static_cast<void*
>(
static_cast<uint8_t*
>(ptr_) +
288 workload * element_byte_size_);
294 CoordToWorkload(x, y, z, &workload);
295 return static_cast<void*
>(
static_cast<uint8_t*
>(ptr_) +
296 workload * element_byte_size_);
303 CoordToWorkload(x, y, z, t, &workload);
304 return static_cast<void*
>(
static_cast<uint8_t*
>(ptr_) +
305 workload * element_byte_size_);
310 int64_t element_byte_size_;
311 int64_t active_dims_;
OPEN3D_HOST_DEVICE bool InBoundary(float x, float y, float z) const
Definition: GeneralIndexer.h:261
OPEN3D_HOST_DEVICE void CoordToWorkload(int64_t x_in, int64_t y_in, int64_t *workload) const
2D coordinate => workload
Definition: GeneralIndexer.h:200
NDArrayIndexer()
Definition: GeneralIndexer.h:135
int64_t NumDims() const
Definition: Tensor.h:973
void AssertDtype(const Dtype &expected_dtype) const
Assert that the Tensor has the specified dtype.
Definition: Tensor.cpp:1268
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: GeneralIndexer.h:244
void * GetDataPtr()
Definition: Tensor.h:961
void LogError(const char *format, const Args &... args)
Definition: Console.h:176
NDArrayIndexer(const SizeVector &shape)
Only used for simple shapes.
Definition: GeneralIndexer.h:171
OPEN3D_HOST_DEVICE bool InBoundary(float x, float y, float z, float t) const
Definition: GeneralIndexer.h:265
Definition: GeneralIndexer.h:133
Definition: SizeVector.h:102
OPEN3D_HOST_DEVICE void WorkloadToCoord(int64_t workload, int64_t *x_out, int64_t *y_out) const
Workload => 2D coordinate.
Definition: GeneralIndexer.h:225
Dtype GetDtype() const
Definition: Tensor.h:965
OPEN3D_HOST_DEVICE void * GetDataPtrFromCoord(int64_t x) const
Definition: GeneralIndexer.h:278
#define OPEN3D_HOST_DEVICE
Definition: CUDAUtils.h:54
OPEN3D_HOST_DEVICE void * GetDataPtrFromCoord(int64_t x, int64_t y, int64_t z) const
Definition: GeneralIndexer.h:290
bool IsContiguous() const
Definition: Tensor.h:912
OPEN3D_HOST_DEVICE int64_t ElementByteSize()
Definition: GeneralIndexer.h:189
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: GeneralIndexer.h:207
static const Dtype Float32
Definition: Dtype.h:42
OPEN3D_HOST_DEVICE int64_t GetShape(int i) const
Definition: GeneralIndexer.h:274
OPEN3D_HOST_DEVICE void * GetDataPtrFromCoord(int64_t x, int64_t y) const
Definition: GeneralIndexer.h:283
NDArrayIndexer(const Tensor &ndarray, int64_t active_dims)
Definition: GeneralIndexer.h:141
SizeVector GetShape() const
Definition: Tensor.h:945
OPEN3D_HOST_DEVICE int64_t NumElements()
Definition: GeneralIndexer.h:191
Definition: PinholeCameraIntrinsic.cpp:35
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: GeneralIndexer.h:215
OPEN3D_HOST_DEVICE bool InBoundary(float x, float y) const
Definition: GeneralIndexer.h:257
int64_t ByteSize() const
Definition: Dtype.h:71
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: GeneralIndexer.h:233
const int64_t MAX_RESOLUTION_DIMS
Definition: GeneralIndexer.h:132
static Tensor Eye(int64_t n, Dtype dtype, const Device &device)
Create a identity matrix of size n x n.
Definition: Tensor.cpp:194
void AssertShape(const SizeVector &expected_shape) const
Assert that the Tensor has the specified shape.
Definition: Tensor.cpp:1249
T Item() const
Definition: Tensor.h:446
OPEN3D_HOST_DEVICE void * GetDataPtrFromCoord(int64_t x, int64_t y, int64_t z, int64_t t) const
Definition: GeneralIndexer.h:298