Example #1
0
bool NetworkDetails::isCandidateMatch(ConstNetworkVertexPtr v1, ConstNetworkVertexPtr v2)
{
  Meters ce = max(getSearchRadius(v1), getSearchRadius(v2));

  double d = EuclideanDistanceExtractor().distance(*_map, v1->getElement(), v2->getElement());
  return d <= ce;
}
Example #2
0
bool NetworkDetails::isCandidateMatch(ConstNetworkEdgePtr e1, ConstNetworkEdgePtr e2)
{
  Meters ce1 = getSearchRadius(e1);
  Meters ce2 = getSearchRadius(e2);
  Meters ce = sqrt(ce1 * ce1 + ce2 * ce2);

  assert(e1->getMembers().size() == 1 && e2->getMembers().size() == 1);

  ConstElementPtr ep1 = e1->getMembers()[0];
  ConstElementPtr ep2 = e2->getMembers()[0];

  double d = EuclideanDistanceExtractor().distance(*_map, ep1, ep2);
  bool result = d <= ce;

  double hd = HausdorffDistanceExtractor().distance(*_map, ep1, ep2);
  result = result && hd <= ce;

  AngleHistogramExtractor ahe;
  ahe.setSmoothing(toRadians(20.0));
  double ah = ahe.extract(*_map, ep1, ep2);
  result = result && ah >= 0.5;

  return result;
}
  void checkForMatch(const shared_ptr<const Element>& e)
  {
    HandleScope handleScope;
    Context::Scope context_scope(_script->getContext());

    auto_ptr<Envelope> env(e->getEnvelope(_map));
    //if _searchRadius is unchanged, don't use it as an auto-calculated search radius value and
    //expand the search envelope based on the element's circular error and map worst circular error
    //instead
    if (_searchRadius == -1.0)
    {
      env->expandBy(_candidateDistanceSigma * _worstCircularError + getSearchRadius(e));
    }
    else
    {
      env->expandBy(_candidateDistanceSigma * _searchRadius);
    }

    // find other nearby candidates
    set<ElementId> neighbors = _map->findElements(*env);
    ElementId from(e->getElementType(), e->getId());

    _elementsEvaluated++;
    int neighborCount = 0;

    for (set<ElementId>::const_iterator it = neighbors.begin(); it != neighbors.end(); ++it)
    {
      ConstElementPtr e2 = _map->getElement(*it);
      if ((e->getStatus() != e2->getStatus() || from < *it) && isMatchCandidate(e2))
      {
        // score each candidate and push it on the result vector
        ScriptMatch* m = new ScriptMatch(_script, getPlugin(), _map, from, *it, _mt);
        // if we're confident this is a miss
        if (m->getType() == MatchType::Miss)
        {
          delete m;
        }
        else
        {
          _result.push_back(m);
          neighborCount++;
        }
      }
    }

    _neighborCountSum += neighborCount;
    _neighborCountMax = std::max(_neighborCountMax, neighborCount);
  }