IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18334


Ignore:
Timestamp:
Jun 26, 2008, 12:44:37 PM (18 years ago)
Author:
Paul Price
Message:

Adding psTreeNearestWithin

Location:
trunk/psLib/src/types
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/psTree.c

    r18317 r18334  
    461461}
    462462
    463 
    464 // Given an arbitrary point, return the index of the nearest neighbour
    465 long psTreeNearest(const psTree *tree, const psVector *coords)
     463// Return the index of the nearest neighbour to given coordinates, within some radius
     464// This is the engine for psTreeNearest() and psTreeNearestWithin()
     465static inline long treeNearestWithin(const psTree *tree, // Tree
     466                                     const psVector *coords, // Coordinates of interest
     467                                     double bestDistance // Distance (radius-squared) to best point
     468    );
    466469{
    467470#if 1 // Might be in a tight loop
     
    475478    psTreeNode *leaf = psTreeLeaf(tree, coords); // Leaf containing the point of interest
    476479    long bestIndex = -1;                // Index of best point
    477     double bestDistance = INFINITY;     // Distance to best point
    478480    treeLeafSearchNearest(&bestIndex, &bestDistance, tree, leaf, coords);
    479481
     
    515517}
    516518
     519// Given an arbitrary point, return the index of the nearest neighbour
     520long psTreeNearest(const psTree *tree, const psVector *coords)
     521{
     522    return treeNearestWithin(tree, coords, INFINITY);
     523}
     524
     525
     526long psTreeNearestWithin(const psTree *tree, const psVector *coords, double radius)
     527{
     528    return treeNearestWithin(tree, coords, PS_SQR(radius));
     529}
     530
     531
    517532// Search a leaf node for points within radius squared
    518533static inline long treeLeafSearchWithin(double radius2, // Radius squared to search
  • trunk/psLib/src/types/psTree.h

    r18317 r18334  
    8989                   );
    9090
     91/// Return the index of the nearest neighbour to given coordinates, but within some radius
     92long psTreeNearestWithin(const psTree *tree,  ///< Tree
     93                         const psVector *coords ///< Coordinates of interest
     94                         double radius  ///< Radius of interest
     95                         );
     96
    9197/// Return the number of points within some radius of given coordinates
    9298long psTreeWithin(const psTree *tree,   ///< Tree
Note: See TracChangeset for help on using the changeset viewer.