12 #include "tensorflow/core/framework/op.h"
13 #include "tensorflow/core/framework/op_kernel.h"
14 #include "tensorflow/core/lib/core/errors.h"
18 namespace voxelize_opkernel {
20 class OutputAllocator {
24 void AllocVoxelCoords(
int32_t** ptr, int64_t rows, int64_t cols) {
25 using namespace tensorflow;
28 TensorShape shape({rows, cols});
29 OP_REQUIRES_OK(
context,
context->allocate_output(0, shape, &tensor));
30 auto flat_tensor = tensor->flat<
int32_t>();
31 *ptr = flat_tensor.data();
34 void AllocVoxelPointIndices(int64_t** ptr, int64_t num) {
35 using namespace tensorflow;
38 TensorShape shape({num});
39 OP_REQUIRES_OK(
context,
context->allocate_output(1, shape, &tensor));
40 auto flat_tensor = tensor->flat<int64>();
41 *ptr = (int64_t*)flat_tensor.data();
44 void AllocVoxelPointRowSplits(int64_t** ptr, int64_t num) {
45 using namespace tensorflow;
48 TensorShape shape({num});
49 OP_REQUIRES_OK(
context,
context->allocate_output(2, shape, &tensor));
50 auto flat_tensor = tensor->flat<int64>();
51 *ptr = (int64_t*)flat_tensor.data();
54 void AllocVoxelBatchSplits(int64_t** ptr, int64_t num) {
55 using namespace tensorflow;
58 TensorShape shape({num});
59 OP_REQUIRES_OK(
context,
context->allocate_output(3, shape, &tensor));
60 auto flat_tensor = tensor->flat<int64>();
61 *ptr = (int64_t*)flat_tensor.data();
65 tensorflow::OpKernelContext*
context;
69 class VoxelizeOpKernel :
public tensorflow::OpKernel {
71 explicit VoxelizeOpKernel(tensorflow::OpKernelConstruction* construction)
72 : OpKernel(construction) {
73 OP_REQUIRES_OK(construction,
74 construction->GetAttr(
"max_points_per_voxel",
75 &max_points_per_voxel));
76 OP_REQUIRES_OK(construction,
77 construction->GetAttr(
"max_voxels", &max_voxels));
80 void Compute(tensorflow::OpKernelContext*
context)
override {
81 using namespace tensorflow;
83 const Tensor& row_splits =
context->input(1);
84 const Tensor& voxel_size =
context->input(2);
85 const Tensor& points_range_min =
context->input(3);
86 const Tensor& points_range_max =
context->input(4);
90 Dim num_points(
"num_points");
97 context, ndim.value() > 0 && ndim.value() < 9,
98 errors::InvalidArgument(
99 "the number of dimensions must be in [1,..,8]"));
102 Kernel(
context,
points, row_splits, voxel_size, points_range_min,
107 virtual void Kernel(tensorflow::OpKernelContext*
context,
108 const tensorflow::Tensor&
points,
109 const tensorflow::Tensor& row_splits,
110 const tensorflow::Tensor& voxel_size,
111 const tensorflow::Tensor& points_range_min,
112 const tensorflow::Tensor& points_range_max) = 0;
115 tensorflow::int64 max_points_per_voxel;
116 tensorflow::int64 max_voxels;
#define CHECK_SHAPE(tensor,...)
Definition: TorchHelper.h:186
ImGuiContext * context
Definition: Window.cpp:76
Class for dimensions for which the value should be inferred.
Definition: ShapeChecking.h:50
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t int32_t
Definition: K4aPlugin.cpp:395
Definition: ShapeChecking.h:16