]> git.mxchange.org Git - flightgear.git/blobdiff - src/Navaids/PositionedOctree.cxx
Support partial all-within-range spatial queries.
[flightgear.git] / src / Navaids / PositionedOctree.cxx
index 261deb8beb29227b54652eaee7b2a6597e1eb211..9f6908f831433d76a1c51126257c09baf333e0b9 100644 (file)
@@ -36,6 +36,8 @@
 #include <boost/foreach.hpp>
 
 #include <simgear/debug/logstream.hxx>
+#include <simgear/structure/exception.hxx>
+#include <simgear/timing/timestamp.hxx>
 
 namespace flightgear
 {
@@ -66,7 +68,6 @@ void Leaf::visit(const SGVec3d& aPos, double aCutoff,
   
   for (; it != end; ++it) {
     FGPositioned* p = cache->loadById(it->second);
-    assert(intersects(_box, p->cart()));
     double d = dist(aPos, p->cart());
     if (d > aCutoff) {
       continue;
@@ -258,7 +259,7 @@ void findNearestN(const SGVec3d& aPos, unsigned int aN, double aCutoffM, FGPosit
   }
 }
 
-void findAllWithinRange(const SGVec3d& aPos, double aRangeM, FGPositioned::Filter* aFilter, FGPositioned::List& aResults)
+bool findAllWithinRange(const SGVec3d& aPos, double aRangeM, FGPositioned::Filter* aFilter, FGPositioned::List& aResults, int aCutoffMsec)
 {
   aResults.clear();
   FindNearestPQueue pq;
@@ -266,7 +267,10 @@ void findAllWithinRange(const SGVec3d& aPos, double aRangeM, FGPositioned::Filte
   pq.push(Ordered<Node*>(global_spatialOctree, 0));
   double rng = aRangeM;
 
-  while (!pq.empty()) {
+  SGTimeStamp tm;
+  tm.stamp();
+  
+  while (!pq.empty() && (tm.elapsedMSec() < aCutoffMsec)) {
     Node* nd = pq.top().get();
     pq.pop();
   
@@ -279,6 +283,8 @@ void findAllWithinRange(const SGVec3d& aPos, double aRangeM, FGPositioned::Filte
   for (unsigned int r=0; r<numResults; ++r) {
     aResults[r] = results[r].get();
   }
+      
+  return !pq.empty();
 }
       
 } // of namespace Octree