Open3D (C++ API)  0.13.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SamplingOpKernel.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 FurthestPointSamplingOpKernel : public tensorflow::OpKernel {
31 public:
33  tensorflow::OpKernelConstruction* construction)
34  : OpKernel(construction) {
35  using namespace tensorflow;
36 
37  OP_REQUIRES_OK(construction,
38  construction->GetAttr("sample_size", &sample_size));
39  OP_REQUIRES(construction, sample_size > 0,
40  errors::InvalidArgument(
41  "FurthestPointSampling expects positive npoint"));
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("FurthestPointSampling 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  Tensor* out_tensor;
59  OP_REQUIRES_OK(context, context->allocate_output(
60  0, TensorShape{batch_size, sample_size},
61  &out_tensor));
62  auto out_flat = out_tensor->flat<int>();
63  int* out = &(out_flat(0));
64 
65  Tensor temp_tensor;
66  OP_REQUIRES_OK(context,
67  context->allocate_temp(DataTypeToEnum<float>::value,
68  TensorShape{batch_size, pts_size},
69  &temp_tensor));
70  auto temp_flat = temp_tensor.flat<float>();
71  float* temp = &(temp_flat(0));
72 
73  Kernel(context, batch_size, pts_size, sample_size, inp, temp, out);
74  }
75 
76  virtual void Kernel(tensorflow::OpKernelContext* context,
77  int b,
78  int n,
79  int m,
80  const float* dataset,
81  float* temp,
82  int* idxs) = 0;
83 
84 protected:
86 };
Definition: SamplingOpKernel.h:30
virtual void Kernel(tensorflow::OpKernelContext *context, int b, int n, int m, const float *dataset, float *temp, int *idxs)=0
ImGuiContext * context
Definition: Window.cpp:95
int sample_size
Definition: SamplingOpKernel.h:85
FurthestPointSamplingOpKernel(tensorflow::OpKernelConstruction *construction)
Definition: SamplingOpKernel.h:32
void Compute(tensorflow::OpKernelContext *context) override
Definition: SamplingOpKernel.h:44