@Override public void findNeighbor(P target, int searchN, FastQueue<KdTreeResult> results) { this.searchN = searchN; this.neighbors = results; _findClosest(target); }
public KdForestBbfSearch(int numberOfTrees, int maxNodesSearched, KdTreeDistance<P> distance , AxisSplitter<P> splitter) { this.forest = new KdTree[ numberOfTrees ]; this.splitter = splitter; this.search1 = new KdTreeSearch1Bbf<>(distance,maxNodesSearched); this.searchN = new KdTreeSearchNBbf<>(distance,maxNodesSearched); this.constructor = new KdTreeConstructor<P>(memory,splitter); }
@Override public void findNearest(P point, double maxDistance, int numNeighbors, FastQueue<NnData<P>> results) { results.reset(); if( maxDistance <= 0 ) searchN.setMaxDistance(Double.MAX_VALUE); else searchN.setMaxDistance(maxDistance); found.reset(); searchN.findNeighbor(point, numNeighbors, found); for( int i = 0; i < found.size; i++ ) { KdTreeResult k = found.get(i); NnData<P> r = results.grow(); r.point = (P)k.node.point; r.index = k.node.index; r.distance = k.distance; } } }
@Override public void setPoints(List<P> points , boolean trackIndicies ) { if( forest[0] != null ) { for( int i = 0; i < forest.length; i++ ) memory.recycleGraph(forest[i]); } for( int i = 0; i < forest.length; i++ ) forest[i] = constructor.construct(points,trackIndicies); search1.setTrees(forest); searchN.setTrees(forest); }
public KdForestBbfSearch(int numberOfTrees, int maxNodesSearched, KdTreeDistance<P> distance , AxisSplitter<P> splitter) { this.forest = new KdTree[ numberOfTrees ]; this.splitter = splitter; this.search1 = new KdTreeSearch1Bbf<>(distance,maxNodesSearched); this.searchN = new KdTreeSearchNBbf<>(distance,maxNodesSearched); this.constructor = new KdTreeConstructor<P>(memory,splitter); }
@Override public void findNearest(P point, double maxDistance, int numNeighbors, FastQueue<NnData<P>> results) { results.reset(); if( maxDistance <= 0 ) searchN.setMaxDistance(Double.MAX_VALUE); else searchN.setMaxDistance(maxDistance); found.reset(); searchN.findNeighbor(point, numNeighbors, found); for( int i = 0; i < found.size; i++ ) { KdTreeResult k = found.get(i); NnData<P> r = results.grow(); r.point = (P)k.node.point; r.index = k.node.index; r.distance = k.distance; } } }
@Override public void setPoints(List<P> points , boolean trackIndicies ) { if( forest[0] != null ) { for( int i = 0; i < forest.length; i++ ) memory.recycleGraph(forest[i]); } for( int i = 0; i < forest.length; i++ ) forest[i] = constructor.construct(points,trackIndicies); search1.setTrees(forest); searchN.setTrees(forest); }
/** * Performs an approximate {@link NearestNeighbor} search using K-D tree. Node are searched in Best-Bin-First * order. Distance measure is Euclidean squared. * * @see KdTreeNearestNeighbor * @see KdTreeSearch1Bbf * @see AxisSplitterMedian * * @param maxNodesSearched Maximum number of nodes it will search. Controls speed and accuracy. * @param <P> Point type. * @param distance Specifies how distance is computed between two points. * @return {@link NearestNeighbor} implementation */ public static <P> NearestNeighbor<P> kdtree( KdTreeDistance<P> distance , int maxNodesSearched ) { return new KdTreeNearestNeighbor<P>(new KdTreeSearch1Bbf<>(distance,maxNodesSearched), new KdTreeSearchNBbf<>(distance,maxNodesSearched),new AxisSplitterMedian<>(distance)); }
@Override public void findNeighbor(P target, int searchN, FastQueue<KdTreeResult> results) { this.searchN = searchN; this.neighbors = results; _findClosest(target); }
/** * Performs an approximate {@link NearestNeighbor} search using K-D tree. Node are searched in Best-Bin-First * order. Distance measure is Euclidean squared. * * @see KdTreeNearestNeighbor * @see KdTreeSearch1Bbf * @see AxisSplitterMedian * * @param maxNodesSearched Maximum number of nodes it will search. Controls speed and accuracy. * @param <P> Point type. * @param distance Specifies how distance is computed between two points. * @return {@link NearestNeighbor} implementation */ public static <P> NearestNeighbor<P> kdtree( KdTreeDistance<P> distance , int maxNodesSearched ) { return new KdTreeNearestNeighbor<P>(new KdTreeSearch1Bbf<>(distance,maxNodesSearched), new KdTreeSearchNBbf<>(distance,maxNodesSearched),new AxisSplitterMedian<>(distance)); }
@Override public KdTreeSearchN<double[]> createAlg() { // specify so many max nodes that it will be optimal return new KdTreeSearchNBbf<>(new KdTreeEuclideanSq_F64(2),10000); }