Open3D (C++ API)  0.12.0
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 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/Console.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();
57  FaissIndex(const Tensor &dataset_points);
58  ~FaissIndex();
59  FaissIndex(const FaissIndex &) = delete;
60  FaissIndex &operator=(const FaissIndex &) = delete;
61 
62 public:
63  // dataset_points must be float32.
64  bool SetTensorData(const Tensor &dataset_points) override;
65 
66  bool SetTensorData(const Tensor &dataset_points, double radius) override {
68  "FaissIndex::SetTensorData with radius not implemented.");
69  }
70 
71  // query_points must be float32.
72  std::pair<Tensor, Tensor> SearchKnn(const Tensor &query_points,
73  int knn) const override;
74 
75  std::tuple<Tensor, Tensor, Tensor> SearchRadius(
76  const Tensor &query_points, const Tensor &radii) const override {
77  utility::LogError("FaissIndex::SearchHybrid not implemented.");
78  }
79 
80  std::tuple<Tensor, Tensor, Tensor> SearchRadius(
81  const Tensor &query_points, double radius) const override {
82  utility::LogError("FaissIndex::SearchHybrid not implemented.");
83  }
84 
85  // query_points must be float32.
86  std::pair<Tensor, Tensor> SearchHybrid(const Tensor &query_points,
87  float radius,
88  int max_knn) const override;
89 
90 protected:
91  std::unique_ptr<faiss::Index> index;
92 #ifdef BUILD_CUDA_MODULE
93  std::unique_ptr<faiss::gpu::StandardGpuResources> res;
94 #endif
95 };
96 
97 } // namespace nns
98 } // namespace core
99 } // namespace open3d
std::tuple< Tensor, Tensor, Tensor > SearchRadius(const Tensor &query_points, double radius) const override
Definition: FaissIndex.h:80
Definition: FaissIndex.h:36
Definition: NNSIndex.h:40
void LogError(const char *format, const Args &... args)
Definition: Console.h:176
std::unique_ptr< faiss::Index > index
Definition: FaissIndex.h:91
bool SetTensorData(const Tensor &dataset_points, double radius) override
Definition: FaissIndex.h:66
Definition: PinholeCameraIntrinsic.cpp:35
Definition: Tensor.h:48
std::tuple< Tensor, Tensor, Tensor > SearchRadius(const Tensor &query_points, const Tensor &radii) const override
Definition: FaissIndex.h:75
Faiss for nearest neighbor search.
Definition: FaissIndex.h:50