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