Open3D (C++ API)  0.11.0
RadiusSearchOpKernel.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"
27 #include "tensorflow/core/framework/op.h"
28 #include "tensorflow/core/framework/op_kernel.h"
29 #include "tensorflow/core/lib/core/errors.h"
30 
32 // namespace for code that is common for all kernels
33 namespace radius_search_opkernel {
34 
35 class RadiusSearchOpKernel : public tensorflow::OpKernel {
36 public:
37  explicit RadiusSearchOpKernel(
38  tensorflow::OpKernelConstruction* construction)
39  : OpKernel(construction) {
40  using namespace open3d::ml::impl;
41  using namespace tensorflow;
42  std::string metric_str;
43  OP_REQUIRES_OK(construction,
44  construction->GetAttr("metric", &metric_str));
45  if (metric_str == "L1")
46  metric = L1;
47  else
48  metric = L2;
49 
50  OP_REQUIRES_OK(construction,
51  construction->GetAttr("ignore_query_point",
52  &ignore_query_point));
53 
54  OP_REQUIRES_OK(construction, construction->GetAttr("return_distances",
55  &return_distances));
56  OP_REQUIRES_OK(construction,
57  construction->GetAttr("normalize_distances",
58  &normalize_distances));
59  }
60 
61  void Compute(tensorflow::OpKernelContext* context) override {
62  using namespace tensorflow;
63  static_assert(sizeof(int64) == sizeof(int64_t),
64  "int64 type is not compatible");
65 
66  const Tensor& points = context->input(0);
67  const Tensor& queries = context->input(1);
68  const Tensor& radii = context->input(2);
69  const Tensor& points_row_splits = context->input(3);
70  const Tensor& queries_row_splits = context->input(4);
71  {
72  using namespace open3d::ml::op_util;
73 
74  Dim num_points("num_points");
75  Dim num_queries("num_queries");
76  Dim batch_size("batch_size");
77  CHECK_SHAPE(context, points, num_points, 3);
78  CHECK_SHAPE(context, queries, num_queries, 3);
79  CHECK_SHAPE(context, radii, num_queries);
80  CHECK_SHAPE(context, points_row_splits, batch_size + 1);
81  CHECK_SHAPE(context, queries_row_splits, batch_size + 1);
82  }
83 
84  Tensor* query_neighbors_row_splits = 0;
85  TensorShape query_neighbors_row_splits_shape(
86  {queries.shape().dim_size(0) + 1});
87  OP_REQUIRES_OK(context, context->allocate_output(
88  1, query_neighbors_row_splits_shape,
89  &query_neighbors_row_splits));
90 
91  Kernel(context, points, queries, radii, points_row_splits,
92  queries_row_splits, *query_neighbors_row_splits);
93  }
94 
95  virtual void Kernel(tensorflow::OpKernelContext* context,
96  const tensorflow::Tensor& points,
97  const tensorflow::Tensor& queries,
98  const tensorflow::Tensor& radius,
99  const tensorflow::Tensor& points_row_splits,
100  const tensorflow::Tensor& queries_row_splits,
101  tensorflow::Tensor& query_neighbors_row_splits) = 0;
102 
103 protected:
105  bool ignore_query_point;
106  bool return_distances;
107  bool normalize_distances;
108 };
109 
110 } // namespace radius_search_opkernel
Definition: NanoFlannIndex.h:53
#define CHECK_SHAPE(tensor,...)
Definition: TorchHelper.h:204
Metric
Supported metrics.
Definition: NeighborSearchCommon.h:38
Class for dimensions for which the value should be inferred.
Definition: ShapeChecking.h:69
Definition: NanoFlannIndex.h:53
Definition: ContinuousConv.h:35
int points
Definition: FilePCD.cpp:73
Definition: ShapeChecking.h:35