Open3D (C++ API)  0.13.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
BallQueryOpKernel.h
Go to the documentation of this file.
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2020 www.open3d.org
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 // IN THE SOFTWARE.
22 // ----------------------------------------------------------------------------
23 #pragma once
24 
25 #include "../TensorFlowHelper.h"
26 #include "tensorflow/core/framework/op.h"
27 #include "tensorflow/core/framework/op_kernel.h"
28 #include "tensorflow/core/lib/core/errors.h"
29 
30 class BallQueryOpKernel : public tensorflow::OpKernel {
31 public:
32  explicit BallQueryOpKernel(tensorflow::OpKernelConstruction* construction)
33  : OpKernel(construction) {
34  using namespace tensorflow;
35 
36  OP_REQUIRES_OK(construction,
37  construction->GetAttr("nsample", &nsample));
38  OP_REQUIRES_OK(construction, construction->GetAttr("radius", &radius));
39  OP_REQUIRES(
40  construction, nsample > 0,
41  errors::InvalidArgument("BallQuery expects positive nsample"));
42  }
43 
44  void Compute(tensorflow::OpKernelContext* context) override {
45  using namespace tensorflow;
46 
47  const Tensor& inp_tensor = context->input(0);
48  OP_REQUIRES(
49  context,
50  inp_tensor.dims() == 3 && inp_tensor.shape().dim_size(2) == 3,
51  errors::InvalidArgument("BallQuery expects "
52  "(batch_size,num_points,3) inp shape"));
53  int batch_size = inp_tensor.shape().dim_size(0);
54  int pts_size = inp_tensor.shape().dim_size(1);
55  auto inp_flat = inp_tensor.flat<float>();
56  const float* inp = &(inp_flat(0));
57 
58  const Tensor& center_tensor = context->input(1);
59  OP_REQUIRES(context,
60  center_tensor.dims() == 3 &&
61  center_tensor.shape().dim_size(2) == 3,
62  errors::InvalidArgument(
63  "BallQuery expects "
64  "(batch_size,num_points,3) center shape"));
65  int ball_size = center_tensor.shape().dim_size(1);
66  auto center_flat = center_tensor.flat<float>();
67  const float* center = &(center_flat(0));
68 
69  Tensor* out_tensor;
70  OP_REQUIRES_OK(context,
71  context->allocate_output(
72  0, TensorShape{batch_size, ball_size, nsample},
73  &out_tensor));
74  auto out_flat = out_tensor->flat<int>();
75  int* out = &(out_flat(0));
76 
77  Kernel(context, batch_size, pts_size, ball_size, radius, nsample,
78  center, inp, out);
79  }
80 
81  virtual void Kernel(tensorflow::OpKernelContext* context,
82  int b,
83  int n,
84  int m,
85  float radius,
86  int nsample,
87  const float* new_xyz,
88  const float* xyz,
89  int* idx) = 0;
90 
91 protected:
92  int nsample;
93  float radius;
94 };
virtual void Kernel(tensorflow::OpKernelContext *context, int b, int n, int m, float radius, int nsample, const float *new_xyz, const float *xyz, int *idx)=0
ImGuiContext * context
Definition: Window.cpp:95
int nsample
Definition: BallQueryOpKernel.h:92
float radius
Definition: BallQueryOpKernel.h:93
Definition: BallQueryOpKernel.h:30
BallQueryOpKernel(tensorflow::OpKernelConstruction *construction)
Definition: BallQueryOpKernel.h:32
void Compute(tensorflow::OpKernelContext *context) override
Definition: BallQueryOpKernel.h:44