@Override public void search( final RealLocalizable reference, final double radius, final boolean sortResults ) { assert radius >= 0; reference.localize( pos ); resultPoints.clear(); searchNode( tree.getRoot(), radius * radius ); if ( sortResults ) { Collections.sort( resultPoints, new Comparator< ValuePair< KDTreeNode< T >, Double > >() { @Override public int compare( final ValuePair< KDTreeNode< T >, Double > o1, final ValuePair< KDTreeNode< T >, Double > o2 ) { return Double.compare( o1.b, o2.b ); } } ); } }
final RadiusNeighborSearchOnKDTree< RealPoint > kd = new RadiusNeighborSearchOnKDTree< RealPoint >( kdTree ); final long kdSetupTime = System.currentTimeMillis() - start; System.out.println( "kdtree setup took: " + ( kdSetupTime ) + " ms." ); kd.search( t, radius, true ); final int neighbors = kd.numNeighbors(); final ArrayList< ValuePair< RealPoint, Double > > radiusExhaustive = findNeighborsRadiusExhaustive( points, t, radius, true ); if ( kd.getPosition( i ).getFloatPosition( d ) != radiusExhaustive.get( i ).a.getFloatPosition( d ) ) equal = false; System.out.println( "KD-Tree says: " + kd.getPosition( i ) ); System.out.println( "Exhaustive says: " + radiusExhaustive.get( i ).a ); if ( kd.getDistance( i ) == radiusExhaustive.get( i ).b ) System.out.println( "different points but same distance" ); else for ( final RealPoint t : testpoints ) kd.search( t, radius, true ); final int neighbors = kd.numNeighbors(); for ( int i = 0; i < neighbors; ++i ) kd.getSampler( i ).get().getClass();
@Override public void search( final RealLocalizable reference, final double radius, final boolean sortResults ) { assert radius >= 0; reference.localize( pos ); resultPoints.clear(); searchNode( tree.getRoot(), radius * radius ); if ( sortResults ) { Collections.sort( resultPoints, new Comparator< ValuePair< KDTreeNode< T >, Double > >() { @Override public int compare( final ValuePair< KDTreeNode< T >, Double > o1, final ValuePair< KDTreeNode< T >, Double > o2 ) { return Double.compare( o1.b, o2.b ); } } ); } }
protected void searchNode( final KDTreeNode< T > current, final double squRadius ) { // consider the current node final double squDistance = current.squDistanceTo( pos ); if ( squDistance <= squRadius ) { resultPoints.add( new ValuePair< KDTreeNode< T >, Double >( current, squDistance ) ); } final double axisDiff = pos[ current.getSplitDimension() ] - current.getSplitCoordinate(); final double axisSquDistance = axisDiff * axisDiff; final boolean leftIsNearBranch = axisDiff < 0; // search the near branch final KDTreeNode< T > nearChild = leftIsNearBranch ? current.left : current.right; final KDTreeNode< T > awayChild = leftIsNearBranch ? current.right : current.left; if ( nearChild != null ) searchNode( nearChild, squRadius ); // search the away branch - maybe if ( ( axisSquDistance <= squRadius ) && ( awayChild != null ) ) searchNode( awayChild, squRadius ); }
protected void searchNode( final KDTreeNode< T > current, final double squRadius ) { // consider the current node final double squDistance = current.squDistanceTo( pos ); if ( squDistance <= squRadius ) { resultPoints.add( new ValuePair< KDTreeNode< T >, Double >( current, squDistance ) ); } final double axisDiff = pos[ current.getSplitDimension() ] - current.getSplitCoordinate(); final double axisSquDistance = axisDiff * axisDiff; final boolean leftIsNearBranch = axisDiff < 0; // search the near branch final KDTreeNode< T > nearChild = leftIsNearBranch ? current.left : current.right; final KDTreeNode< T > awayChild = leftIsNearBranch ? current.right : current.left; if ( nearChild != null ) searchNode( nearChild, squRadius ); // search the away branch - maybe if ( ( axisSquDistance <= squRadius ) && ( awayChild != null ) ) searchNode( awayChild, squRadius ); }