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