bd_pr_search.cpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------
00002 // File:                        bd_pr_search.cpp
00003 // Programmer:          David Mount
00004 // Description:         Priority search for bd-trees
00005 // Last modified:       01/04/05 (Version 1.0)
00006 //----------------------------------------------------------------------
00007 // Copyright (c) 1997-2005 University of Maryland and Sunil Arya and
00008 // David Mount.  All Rights Reserved.
00009 // 
00010 // This software and related documentation is part of the Approximate
00011 // Nearest Neighbor Library (ANN).  This software is provided under
00012 // the provisions of the Lesser GNU Public License (LGPL).  See the
00013 // file ../ReadMe.txt for further information.
00014 // 
00015 // The University of Maryland (U.M.) and the authors make no
00016 // representations about the suitability or fitness of this software for
00017 // any purpose.  It is provided "as is" without express or implied
00018 // warranty.
00019 //----------------------------------------------------------------------
00020 //History:
00021 //      Revision 0.1  03/04/98
00022 //              Initial release
00023 //----------------------------------------------------------------------
00024 
00025 #include "bd_tree.h"                                    // bd-tree declarations
00026 #include "kd_pr_search.h"                               // kd priority search declarations
00027 
00028 //----------------------------------------------------------------------
00029 //      Approximate priority searching for bd-trees.
00030 //              See the file kd_pr_search.cc for general information on the
00031 //              approximate nearest neighbor priority search algorithm.  Here
00032 //              we include the extensions for shrinking nodes.
00033 //----------------------------------------------------------------------
00034 
00035 //----------------------------------------------------------------------
00036 //      bd_shrink::ann_search - search a shrinking node
00037 //----------------------------------------------------------------------
00038 
00039 void ANNbd_shrink::ann_pri_search(ANNdist box_dist)
00040 {
00041         ANNdist inner_dist = 0;                                         // distance to inner box
00042         for (int i = 0; i < n_bnds; i++) {                      // is query point in the box?
00043                 if (bnds[i].out(ANNprQ)) {                              // outside this bounding side?
00044                                                                                                 // add to inner distance
00045                         inner_dist = (ANNdist) ANN_SUM(inner_dist, bnds[i].dist(ANNprQ));
00046                 }
00047         }
00048         if (inner_dist <= box_dist) {                           // if inner box is closer
00049                 if (child[ANN_OUT] != KD_TRIVIAL)               // enqueue outer if not trivial
00050                         ANNprBoxPQ->insert(box_dist,child[ANN_OUT]);
00051                                                                                                 // continue with inner child
00052                 child[ANN_IN]->ann_pri_search(inner_dist);
00053         }
00054         else {                                                                          // if outer box is closer
00055                 if (child[ANN_IN] != KD_TRIVIAL)                // enqueue inner if not trivial
00056                         ANNprBoxPQ->insert(inner_dist,child[ANN_IN]);
00057                                                                                                 // continue with outer child
00058                 child[ANN_OUT]->ann_pri_search(box_dist);
00059         }
00060         ANN_FLOP(3*n_bnds)                                                      // increment floating ops
00061         ANN_SHR(1)                                                                      // one more shrinking node
00062 }

Generated on Wed Nov 23 18:59:57 2011 for FreeCAD by  doxygen 1.6.1