GCC Code Coverage Report


Directory: ./
File: lib/geogram/points/nn_search.cpp
Date: 2026-09-07 02:25:23
Exec Total Coverage
Lines: 19 42 45.2%
Functions: 4 9 44.4%
Branches: 13 40 32.5%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2000-2022 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40 #include <geogram/points/nn_search.h>
41 #include <geogram/points/kd_tree.h>
42 #include <geogram/basic/command_line.h>
43 #include <geogram/basic/logger.h>
44
45 /****************************************************************************/
46
47 namespace GEO {
48
49 173 NearestNeighborSearch::NearestNeighborSearch(
50 coord_index_t dimension
51 173 ) :
52 173 dimension_(dimension),
53 173 nb_points_(0),
54 173 stride_(0),
55 173 points_(nullptr),
56 173 exact_(true) {
57 173 }
58
59 void NearestNeighborSearch::get_nearest_neighbors(
60 index_t nb_neighbors,
61 const double* query_point,
62 index_t* neighbors,
63 double* neighbors_sq_dist,
64 KeepInitialValues
65 ) const {
66 get_nearest_neighbors(
67 nb_neighbors,
68 query_point,
69 neighbors,
70 neighbors_sq_dist
71 );
72 }
73
74 void NearestNeighborSearch::get_nearest_neighbors(
75 index_t nb_neighbors,
76 index_t query_point,
77 index_t* neighbors,
78 double* neighbors_sq_dist
79 ) const {
80 get_nearest_neighbors(
81 nb_neighbors,
82 point_ptr(query_point),
83 neighbors,
84 neighbors_sq_dist
85 );
86 }
87
88 void NearestNeighborSearch::set_points(
89 index_t nb_points, const double* points
90 ) {
91 nb_points_ = nb_points;
92 points_ = points;
93 stride_ = dimension_;
94 }
95
96 bool NearestNeighborSearch::stride_supported() const {
97 return false;
98 }
99
100 void NearestNeighborSearch::set_points(
101 index_t nb_points, const double* points, index_t stride
102 ) {
103 if(stride == index_t(dimension())) {
104 set_points(nb_points, points);
105 return;
106 }
107 geo_assert(stride_supported());
108 nb_points_ = nb_points;
109 points_ = points;
110 stride_ = stride;
111 }
112
113 3 void NearestNeighborSearch::set_exact(bool x) {
114 3 exact_ = x;
115 3 }
116
117 346 NearestNeighborSearch::~NearestNeighborSearch() {
118 346 }
119
120 173 NearestNeighborSearch* NearestNeighborSearch::create(
121 coord_index_t dimension, const std::string& name_in
122 ) {
123
4/6
✓ Branch 0 taken 102 times.
✓ Branch 1 taken 71 times.
✓ Branch 3 taken 102 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 102 times.
✗ Branch 7 not taken.
377 geo_register_NearestNeighborSearch_creator(
124 BalancedKdTree, "BNN"
125 );
126
127
4/6
✓ Branch 0 taken 102 times.
✓ Branch 1 taken 71 times.
✓ Branch 3 taken 102 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 102 times.
✗ Branch 7 not taken.
377 geo_register_NearestNeighborSearch_creator(
128 AdaptiveKdTree, "CNN"
129 );
130
131 std::string name = name_in;
132
2/2
✓ Branch 0 taken 109 times.
✓ Branch 1 taken 64 times.
173 if(name == "default") {
133
2/4
✓ Branch 1 taken 109 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 109 times.
✗ Branch 5 not taken.
218 name = CmdLine::get_arg("algo:nn_search");
134 }
135
136 NearestNeighborSearch* nns =
137 NearestNeighborSearchFactory::create_object(name, dimension);
138
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 173 times.
173 if(nns != nullptr) {
139 return nns;
140 }
141
142 Logger::warn("NNSearch")
143 << "Could not create NNSearch algorithm: " << name
144 << std::endl
145 << "Falling back to BNN"
146 << std::endl;
147
148 return new BalancedKdTree(dimension);
149 }
150 }
151