14 #include "tensorflow/core/framework/op.h"
15 #include "tensorflow/core/framework/op_kernel.h"
16 #include "tensorflow/core/lib/core/errors.h"
20 namespace voxelize_opkernel {
22 class OutputAllocator {
26 void AllocVoxelCoords(
int32_t** ptr, int64_t rows, int64_t cols) {
27 using namespace tensorflow;
30 TensorShape shape({rows, cols});
31 OP_REQUIRES_OK(
context,
context->allocate_output(0, shape, &tensor));
32 auto flat_tensor = tensor->flat<
int32_t>();
33 *ptr = flat_tensor.data();
36 void AllocVoxelPointIndices(int64_t** ptr, int64_t num) {
37 using namespace tensorflow;
40 TensorShape shape({num});
41 OP_REQUIRES_OK(
context,
context->allocate_output(1, shape, &tensor));
42 auto flat_tensor = tensor->flat<int64_t>();
43 *ptr = (int64_t*)flat_tensor.data();
46 void AllocVoxelPointRowSplits(int64_t** ptr, int64_t num) {
47 using namespace tensorflow;
50 TensorShape shape({num});
51 OP_REQUIRES_OK(
context,
context->allocate_output(2, shape, &tensor));
52 auto flat_tensor = tensor->flat<int64_t>();
53 *ptr = (int64_t*)flat_tensor.data();
56 void AllocVoxelBatchSplits(int64_t** ptr, int64_t num) {
57 using namespace tensorflow;
60 TensorShape shape({num});
61 OP_REQUIRES_OK(
context,
context->allocate_output(3, shape, &tensor));
62 auto flat_tensor = tensor->flat<int64_t>();
63 *ptr = (int64_t*)flat_tensor.data();
67 tensorflow::OpKernelContext*
context;
71 class VoxelizeOpKernel :
public tensorflow::OpKernel {
73 explicit VoxelizeOpKernel(tensorflow::OpKernelConstruction* construction)
74 : OpKernel(construction) {
75 OP_REQUIRES_OK(construction,
76 construction->GetAttr(
"max_points_per_voxel",
77 &max_points_per_voxel));
78 OP_REQUIRES_OK(construction,
79 construction->GetAttr(
"max_voxels", &max_voxels));
82 void Compute(tensorflow::OpKernelContext*
context)
override {
83 using namespace tensorflow;
85 const Tensor& row_splits =
context->input(1);
86 const Tensor& voxel_size =
context->input(2);
87 const Tensor& points_range_min =
context->input(3);
88 const Tensor& points_range_max =
context->input(4);
92 Dim num_points(
"num_points");
99 context, ndim.value() > 0 && ndim.value() < 9,
100 absl::InvalidArgumentError(
101 "the number of dimensions must be in [1,..,8]"));
104 Kernel(
context,
points, row_splits, voxel_size, points_range_min,
109 virtual void Kernel(tensorflow::OpKernelContext*
context,
110 const tensorflow::Tensor&
points,
111 const tensorflow::Tensor& row_splits,
112 const tensorflow::Tensor& voxel_size,
113 const tensorflow::Tensor& points_range_min,
114 const tensorflow::Tensor& points_range_max) = 0;
117 int64_t max_points_per_voxel;
#define CHECK_SHAPE(tensor,...)
Definition: TorchHelper.h:190
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