2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2019-03-18 11:22:48 +11:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup bli
|
2021-10-20 09:19:21 +11:00
|
|
|
* \brief A KD-tree for nearest neighbor search.
|
2019-03-18 11:22:48 +11:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "BLI_compiler_attrs.h"
|
2020-03-06 16:45:06 +01:00
|
|
|
#include "BLI_sys_types.h"
|
2019-03-18 11:22:48 +11:00
|
|
|
|
2019-09-14 09:59:42 -06:00
|
|
|
#define _BLI_CONCAT_AUX(MACRO_ARG1, MACRO_ARG2) MACRO_ARG1##MACRO_ARG2
|
|
|
|
|
#define _BLI_CONCAT(MACRO_ARG1, MACRO_ARG2) _BLI_CONCAT_AUX(MACRO_ARG1, MACRO_ARG2)
|
|
|
|
|
#define BLI_kdtree_nd_(id) _BLI_CONCAT(KDTREE_PREFIX_ID, _##id)
|
2019-03-18 11:22:48 +11:00
|
|
|
|
|
|
|
|
struct KDTree;
|
|
|
|
|
typedef struct KDTree KDTree;
|
|
|
|
|
|
|
|
|
|
typedef struct KDTreeNearest {
|
2019-04-17 06:17:24 +02:00
|
|
|
int index;
|
|
|
|
|
float dist;
|
|
|
|
|
float co[KD_DIMS];
|
2019-03-18 11:22:48 +11:00
|
|
|
} KDTreeNearest;
|
|
|
|
|
|
|
|
|
|
KDTree *BLI_kdtree_nd_(new)(unsigned int maxsize);
|
|
|
|
|
void BLI_kdtree_nd_(free)(KDTree *tree);
|
|
|
|
|
void BLI_kdtree_nd_(balance)(KDTree *tree) ATTR_NONNULL(1);
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void BLI_kdtree_nd_(insert)(KDTree *tree, int index, const float co[KD_DIMS]) ATTR_NONNULL(1, 3);
|
|
|
|
|
int BLI_kdtree_nd_(find_nearest)(const KDTree *tree,
|
|
|
|
|
const float co[KD_DIMS],
|
|
|
|
|
KDTreeNearest *r_nearest) ATTR_NONNULL(1, 2);
|
2019-03-18 11:22:48 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
int BLI_kdtree_nd_(find_nearest_n)(const KDTree *tree,
|
|
|
|
|
const float co[KD_DIMS],
|
|
|
|
|
KDTreeNearest *r_nearest,
|
2022-01-07 11:38:08 +11:00
|
|
|
uint nearest_len_capacity) ATTR_NONNULL(1, 2, 3);
|
2019-03-18 11:22:48 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
int BLI_kdtree_nd_(range_search)(const KDTree *tree,
|
|
|
|
|
const float co[KD_DIMS],
|
|
|
|
|
KDTreeNearest **r_nearest,
|
2022-01-07 11:38:08 +11:00
|
|
|
float range) ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT;
|
2019-03-18 11:22:48 +11:00
|
|
|
|
|
|
|
|
int BLI_kdtree_nd_(find_nearest_cb)(
|
2019-04-17 06:17:24 +02:00
|
|
|
const KDTree *tree,
|
|
|
|
|
const float co[KD_DIMS],
|
|
|
|
|
int (*filter_cb)(void *user_data, int index, const float co[KD_DIMS], float dist_sq),
|
|
|
|
|
void *user_data,
|
|
|
|
|
KDTreeNearest *r_nearest);
|
2019-03-18 11:22:48 +11:00
|
|
|
void BLI_kdtree_nd_(range_search_cb)(
|
2019-04-17 06:17:24 +02:00
|
|
|
const KDTree *tree,
|
|
|
|
|
const float co[KD_DIMS],
|
|
|
|
|
float range,
|
|
|
|
|
bool (*search_cb)(void *user_data, int index, const float co[KD_DIMS], float dist_sq),
|
|
|
|
|
void *user_data);
|
2019-03-18 11:22:48 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
int BLI_kdtree_nd_(calc_duplicates_fast)(const KDTree *tree,
|
2022-01-07 11:38:08 +11:00
|
|
|
float range,
|
2019-04-17 06:17:24 +02:00
|
|
|
bool use_index_order,
|
|
|
|
|
int *doubles);
|
2019-03-21 02:27:27 +11:00
|
|
|
|
|
|
|
|
int BLI_kdtree_nd_(deduplicate)(KDTree *tree);
|
|
|
|
|
|
2021-12-20 19:01:14 +11:00
|
|
|
/** Versions of find/range search that take a squared distance callback to support bias. */
|
2019-03-18 11:22:48 +11:00
|
|
|
int BLI_kdtree_nd_(find_nearest_n_with_len_squared_cb)(
|
2019-04-17 06:17:24 +02:00
|
|
|
const KDTree *tree,
|
|
|
|
|
const float co[KD_DIMS],
|
|
|
|
|
KDTreeNearest *r_nearest,
|
2022-01-07 11:38:08 +11:00
|
|
|
uint nearest_len_capacity,
|
2019-04-17 06:17:24 +02:00
|
|
|
float (*len_sq_fn)(const float co_search[KD_DIMS],
|
|
|
|
|
const float co_test[KD_DIMS],
|
|
|
|
|
const void *user_data),
|
|
|
|
|
const void *user_data) ATTR_NONNULL(1, 2, 3);
|
2019-03-18 11:22:48 +11:00
|
|
|
int BLI_kdtree_nd_(range_search_with_len_squared_cb)(
|
2019-04-17 06:17:24 +02:00
|
|
|
const KDTree *tree,
|
|
|
|
|
const float co[KD_DIMS],
|
|
|
|
|
KDTreeNearest **r_nearest,
|
2022-01-07 11:38:08 +11:00
|
|
|
float range,
|
2019-04-17 06:17:24 +02:00
|
|
|
float (*len_sq_fn)(const float co_search[KD_DIMS],
|
|
|
|
|
const float co_test[KD_DIMS],
|
|
|
|
|
const void *user_data),
|
|
|
|
|
const void *user_data) ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT;
|
2019-03-18 11:22:48 +11:00
|
|
|
|
2019-09-14 09:59:42 -06:00
|
|
|
#undef _BLI_CONCAT_AUX
|
|
|
|
|
#undef _BLI_CONCAT
|
2019-03-18 11:22:48 +11:00
|
|
|
#undef BLI_kdtree_nd_
|