X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNavaids%2FPositionedOctree.cxx;h=781fee8f220c17999b96aa4e6ce90da00f4bd75f;hb=11c00afaec8836a5f52bcf8832ff2d50e2f11523;hp=479ee99c83486cb753ecfd89d2720fab6ff8e283;hpb=08d82294bde72a2b8bbafeda030e4fce5780df24;p=flightgear.git diff --git a/src/Navaids/PositionedOctree.cxx b/src/Navaids/PositionedOctree.cxx index 479ee99c8..781fee8f2 100644 --- a/src/Navaids/PositionedOctree.cxx +++ b/src/Navaids/PositionedOctree.cxx @@ -37,6 +37,7 @@ #include #include +#include namespace flightgear { @@ -67,22 +68,6 @@ void Leaf::visit(const SGVec3d& aPos, double aCutoff, for (; it != end; ++it) { FGPositioned* p = cache->loadById(it->second); - if (!intersects(_box, p->cart())) { - // see http://code.google.com/p/flightgear-bugs/issues/detail?id=905 - - SG_LOG(SG_GENERAL, SG_WARN, "XXXXXXXXX bad spatial index for " << it->second - << "; " << p->ident() << " of type " << - FGPositioned::nameForType(p->type())); - SG_LOG(SG_GENERAL, SG_WARN, "\tgeodetic location:" << p->geod()); - SG_LOG(SG_GENERAL, SG_WARN, "\tcartesian location:" << p->cart()); - - SG_LOG(SG_GENERAL, SG_WARN, "leaf box:" << - _box.getMin() << " x " << _box.getMax()); - - throw sg_exception("Bad spatial index data"); - } - - double d = dist(aPos, p->cart()); if (d > aCutoff) { continue; @@ -238,7 +223,7 @@ int Branch::childMask() const return result; } -void findNearestN(const SGVec3d& aPos, unsigned int aN, double aCutoffM, FGPositioned::Filter* aFilter, FGPositioned::List& aResults) +bool findNearestN(const SGVec3d& aPos, unsigned int aN, double aCutoffM, FGPositioned::Filter* aFilter, FGPositioned::List& aResults, int aCutoffMsec) { aResults.clear(); FindNearestPQueue pq; @@ -246,13 +231,17 @@ void findNearestN(const SGVec3d& aPos, unsigned int aN, double aCutoffM, FGPosit pq.push(Ordered(global_spatialOctree, 0)); double cut = aCutoffM; - while (!pq.empty()) { + SGTimeStamp tm; + tm.stamp(); + + while (!pq.empty() && (tm.elapsedMSec() < aCutoffMsec)) { if (!results.empty()) { // terminate the search if we have sufficent results, and we are // sure no node still on the queue contains a closer match double furthestResultOrder = results.back().order(); - // std::cout << "furthest result:" << furthestResultOrder << ", top node order:" << pq.top().order() << std::endl; if ((results.size() >= aN) && (furthestResultOrder < pq.top().order())) { + // clear the PQ to mark this has 'full results' instead of partial + pq = FindNearestPQueue(); break; } } @@ -260,7 +249,6 @@ void findNearestN(const SGVec3d& aPos, unsigned int aN, double aCutoffM, FGPosit Node* nd = pq.top().get(); pq.pop(); -// std::cout << "visiting:" << std::oct << nd->guid() << "(" << std::dec << nd->guid() << ")" << std::endl; nd->visit(aPos, cut, aFilter, results, pq); } // of queue iteration @@ -272,9 +260,11 @@ void findNearestN(const SGVec3d& aPos, unsigned int aN, double aCutoffM, FGPosit for (unsigned int r=0; r(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(); @@ -295,6 +288,8 @@ void findAllWithinRange(const SGVec3d& aPos, double aRangeM, FGPositioned::Filte for (unsigned int r=0; r