Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.14.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
FaissIndex.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 <vector>
30 
31 #include "open3d/core/Tensor.h"
33 #include "open3d/utility/Logging.h"
34 
35 // Forward declarations.
36 namespace faiss {
37 struct Index;
38 namespace gpu {
39 class StandardGpuResources;
40 }
41 } // namespace faiss
42 
43 namespace open3d {
44 namespace core {
45 namespace nns {
46 
50 class FaissIndex : public NNSIndex {
51 public:
53  FaissIndex();
58  FaissIndex(const Tensor &dataset_points);
59  ~FaissIndex();
60  FaissIndex(const FaissIndex &) = delete;
61  FaissIndex &operator=(const FaissIndex &) = delete;
62 
63 public:
64  // dataset_points must be float32.
65  bool SetTensorData(const Tensor &dataset_points) override;
66 
67  bool SetTensorData(const Tensor &dataset_points, double radius) override {
69  "FaissIndex::SetTensorData with radius not implemented.");
70  }
71 
80  std::pair<Tensor, Tensor> SearchKnn(const Tensor &query_points,
81  int knn) const override;
82 
93  std::tuple<Tensor, Tensor, Tensor> SearchRadius(const Tensor &query_points,
94  const Tensor &radii,
95  bool sort) const override {
96  utility::LogError("FaissIndex::SearchHybrid not implemented.");
97  }
98 
109  std::tuple<Tensor, Tensor, Tensor> SearchRadius(const Tensor &query_points,
110  double radius,
111  bool sort) const override {
112  utility::LogError("FaissIndex::SearchHybrid not implemented.");
113  }
114 
127  std::tuple<Tensor, Tensor, Tensor> SearchHybrid(const Tensor &query_points,
128  double radius,
129  int max_knn) const override;
130 
131 protected:
132  std::unique_ptr<faiss::Index> index;
133 #ifdef BUILD_CUDA_MODULE
134  std::unique_ptr<faiss::gpu::StandardGpuResources> res;
135 #endif
136 };
137 
138 } // namespace nns
139 } // namespace core
140 } // namespace open3d
Definition: FaissIndex.h:36
Definition: NNSIndex.h:40
std::unique_ptr< faiss::Index > index
Definition: FaissIndex.h:132
bool SetTensorData(const Tensor &dataset_points, double radius) override
Definition: FaissIndex.h:67
std::tuple< Tensor, Tensor, Tensor > SearchRadius(const Tensor &query_points, double radius, bool sort) const override
Definition: FaissIndex.h:109
Definition: PinholeCameraIntrinsic.cpp:35
Definition: Tensor.h:50
Faiss for nearest neighbor search.
Definition: FaissIndex.h:50
std::tuple< Tensor, Tensor, Tensor > SearchRadius(const Tensor &query_points, const Tensor &radii, bool sort) const override
Definition: FaissIndex.h:93
#define LogError(...)
Definition: Logging.h:72