-
Notifications
You must be signed in to change notification settings - Fork 6
/
WANNClass.R
71 lines (71 loc) · 1.84 KB
/
WANNClass.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#' WANN objects encapsulating points/kd trees allowing repeated searches
#'
#' @details
#'
#' WANN objects will primarily be useful if you make repeated queries. You can
#' also delay building the k-d tree if you are not sure if the object in
#' question will be searched; the tree will automatically be built when it is
#' queried. You can also explicitly control when the tree is built or deleted
#' (for memory management). The tree is wrapped in an R reference class (R5)
#' object which imposes a significant performance penalty for building small
#' trees (< ~ 1000 points). Summarising, WANN objects provide experimental
#' functionality to:
#'
#' \itemize{
#'
#' \item keep ANN points in memory to avoid repeated copying
#'
#' \item keep the ANN k-d tree in memory to avoid repeated building
#'
#' \item separate building the k-d tree from allocating the points
#'
#' \item permit very fast self queries
#'
#' \item permit queries of the points from one ANN tree against a second tree
#'
#' }
#'
#' @description Methods for WANN objects include
#'
#' \itemize{
#'
#' \item \code{build_tree}
#'
#' \item \code{delete_tree}
#'
#' \item \code{getPoints}
#'
#' \item \code{querySelf}
#'
#' }
#' @name WANN-class
#' @aliases WANN
#' @exportClass WANN
#' @export WANN
#' @examples
#' p1=kcpoints[[1]]
#' w1=WANN(p1)
#'
#' # 2 neighbours since the first neighbour will be a self match of each point
#' k <- 2
#' # Find the exact nearest neighbors
#' epsilon <- 0.0
#'
#' w1sq=w1$querySelf(k, epsilon)
#' w1sq$nn.dists[,2]
#' w1$query(p1, k, epsilon)
#'
#' p2=kcpoints[[2]]
#' w1$query(p2, k, epsilon)
#' # equivalent to
#' nn2(p1, p2, k)
#'
#' # Fixed radius search
#' w1$query_FR(p1, k, radius = 1, epsilon)
#' # equivalent to
#' nn2(p1, p2, k, radius = 1)
#'
#' # Explicitly build or delete k-d tree
#' w1$build_tree()
#' w1$delete_tree()
WANN <- setRcppClass("WANN")