Exemplo n.º 1
0
void scan_airspaces(const AircraftState state,
                    const Airspaces& airspaces,
                    const AirspaceAircraftPerformance& perf,
                    bool do_report,
                    const GeoPoint &target)
{
    const fixed range(20000.0);

    Directory::Create(Path(_T("output/results")));

    {
        AirspaceVisitorPrint pvisitor("output/results/res-bb-range.txt",
                                      do_report);
        for (const auto &i : airspaces.QueryWithinRange(state.location, range)) {
            const AbstractAirspace &airspace = i.GetAirspace();
            pvisitor.Visit(airspace);
        }
    }

    {
        AirspaceVisitorClosest pvisitor("output/results/res-bb-closest.txt",
                                        airspaces.GetProjection(), state, perf);
        for (const auto &i : airspaces.QueryWithinRange(state.location, range)) {
            const AbstractAirspace &airspace = i.GetAirspace();
            pvisitor.Visit(airspace);
        }
    }

    {
        AirspaceVisitorPrint pvi("output/results/res-bb-inside.txt",
                                 do_report);
        for (const auto &a : airspaces.QueryInside(state))
            pvi.Visit(a.GetAirspace());
    }

    {
        AirspaceIntersectionVisitorPrint ivisitor("output/results/res-bb-intersects.txt",
                "output/results/res-bb-intersected.txt",
                "output/results/res-bb-intercepts.txt",
                do_report,
                state, perf);
        airspaces.VisitIntersecting(state.location, target, ivisitor);
    }

    {
        const auto *as = FindSoonestAirspace(airspaces, state, perf,
                                             AirspacePredicateTrue());
        if (do_report) {
            std::ofstream fout("output/results/res-bb-sortedsoonest.txt");
            if (as) {
                fout << *as << "\n";
            } else {
                fout << "# no soonest found\n";
            }
        }
    }
}
Exemplo n.º 2
0
AirspaceSelectInfoVector
FilterAirspaces(const Airspaces &airspaces, const GeoPoint &location,
                const AirspaceFilterData &filter)
{
  AirspaceFilterVisitor visitor(location, airspaces.GetProjection(), filter);

  if (!negative(filter.distance))
    airspaces.VisitWithinRange(location, filter.distance, visitor);
  else
    for (const auto &i : airspaces)
      visitor.Visit(i.GetAirspace());

  if (filter.direction.IsNegative() && negative(filter.distance))
    SortByName(visitor.result);
  else
    SortByDistance(visitor.result, location, airspaces.GetProjection());

  return visitor.result;
}
Exemplo n.º 3
0
gcc_pure
static NearestAirspace
FindHorizontal(const GeoPoint &location,
               const Airspaces &airspace_database,
               const AirspacePredicate &predicate)
{
  const auto &projection = airspace_database.GetProjection();
  return FindMinimum(airspace_database, location, 30000, predicate,
                     [&location, &projection](const AbstractAirspace &airspace){
                       return CalculateNearestAirspaceHorizontal(location, projection, airspace);
                     },
                     CompareNearestAirspace());
}
Exemplo n.º 4
0
void scan_airspaces(const AircraftState state, 
                    const Airspaces& airspaces,
                    const AirspaceAircraftPerformance& perf,
                    bool do_report,
                    const GeoPoint &target) 
{
  const fixed range(20000.0);

  Directory::Create(Path(_T("output/results")));

  {
    AirspaceVisitorPrint pvisitor("output/results/res-bb-range.txt",
                                  do_report);
    airspaces.VisitWithinRange(state.location, range, pvisitor);
  }

  {
    AirspaceVisitorClosest pvisitor("output/results/res-bb-closest.txt",
                                    airspaces.GetProjection(), state, perf);
    airspaces.VisitWithinRange(state.location, range, pvisitor);
  }

  {
    const std::vector<Airspace> vi = airspaces.FindInside(state);
    AirspaceVisitorPrint pvi("output/results/res-bb-inside.txt",
                             do_report);
    std::for_each(vi.begin(), vi.end(), CallVisitor<AirspaceVisitor>(pvi));
  }
  
  {
    AirspaceIntersectionVisitorPrint ivisitor("output/results/res-bb-intersects.txt",
                                              "output/results/res-bb-intersected.txt",
                                              "output/results/res-bb-intercepts.txt",
                                              do_report,
                                              state, perf);
    airspaces.VisitIntersecting(state.location, target, ivisitor);
  }

  {
    const auto *as = FindSoonestAirspace(airspaces, state, perf,
                                         AirspacePredicateTrue());
    if (do_report) {
      std::ofstream fout("output/results/res-bb-sortedsoonest.txt");
      if (as) {
        fout << *as << "\n";
      } else {
        fout << "# no soonest found\n";
      }
    }
  }
}
Exemplo n.º 5
0
void
AirspaceNearestSort::populate_queue(const Airspaces &airspaces,
                                    const fixed range)
{
  AirspacesInterface::AirspaceVector vectors =
    airspaces.ScanRange(m_location,
                        range,
                        m_condition);

  for (const Airspace &airspace : vectors) {
    const AbstractAirspace &as = airspace.GetAirspace();
    const AirspaceInterceptSolution ais =
      solve_intercept(as, airspaces.GetProjection());
    const fixed value = metric(ais);
    if (!negative(value))
      m_q.push(std::make_pair(value,
                              std::make_pair(ais, &as)));
  }
}
Exemplo n.º 6
0
void 
AirspaceNearestSort::populate_queue(const Airspaces &airspaces,
                                    const fixed range)
{
  AirspacesInterface::AirspaceVector vectors = 
    airspaces.ScanRange(m_location,
                         range,
                         m_condition);

  for (auto v = vectors.begin(); v != vectors.end(); ++v) {
    const AbstractAirspace *as = v->get_airspace();
    if (as != NULL) {
      const AirspaceInterceptSolution ais =
        solve_intercept(*as, airspaces.GetProjection());
      const fixed value = metric(ais);
      if (!negative(value)) {
        m_q.push(std::make_pair(m_reverse? -value:value, std::make_pair(ais, *v)));
      }
    }
  }
}
Exemplo n.º 7
0
gcc_pure
NearestAirspace
NearestAirspace::FindHorizontal(const MoreData &basic,
                                const ProtectedAirspaceWarningManager &airspace_warnings,
                                const Airspaces &airspace_database)
{
  if (!basic.location_available)
    /* can't check for airspaces without a GPS fix */
    return NearestAirspace();

  /* find the nearest airspace */
  //consider only active airspaces
  const WrapAirspacePredicate<ActiveAirspacePredicate> active_predicate(&airspace_warnings);
  const WrapAirspacePredicate<OutsideAirspacePredicate> outside_predicate(AGeoPoint(basic.location, RoughAltitude(0)));
  const AndAirspacePredicate outside_and_active_predicate(active_predicate, outside_predicate);
  const Airspace *airspace;

  //if altitude is available, filter airspaces in same height as airplane
  if (basic.NavAltitudeAvailable()) {
    /* check altitude; hard-coded margin of 50m (for now) */
    WrapAirspacePredicate<AirspacePredicateHeightRange> height_range_predicate(RoughAltitude(basic.nav_altitude-fixed(50)),
                                                                               RoughAltitude(basic.nav_altitude+fixed(50)));
     AndAirspacePredicate and_predicate(outside_and_active_predicate, height_range_predicate);
     airspace = airspace_database.FindNearest(basic.location, and_predicate);
  } else //only filter outside and active
    airspace = airspace_database.FindNearest(basic.location, outside_and_active_predicate);

  if (airspace == nullptr)
    return NearestAirspace();

  const AbstractAirspace &as = airspace->GetAirspace();

  /* calculate distance to the nearest point */
  const GeoPoint closest = as.ClosestPoint(basic.location,
                                           airspace_database.GetProjection());
  return NearestAirspace(as, basic.location.Distance(closest));
}
Exemplo n.º 8
0
void scan_airspaces(const AircraftState state,
                    const Airspaces& airspaces,
                    const AirspaceAircraftPerformance& perf,
                    bool do_report,
                    const GeoPoint &target)
{
    const fixed range(20000.0);

    Directory::Create(_T("output/results"));
    AirspaceVisitorPrint pvn("output/results/res-bb-nearest.txt",
                             do_report);
    const Airspace *nearest = airspaces.FindNearest(state.location);
    if (nearest != nullptr) {
        AirspaceVisitor &v = pvn;
        v.Visit(*nearest);
    }

    {
        AirspaceVisitorPrint pvisitor("output/results/res-bb-range.txt",
                                      do_report);
        airspaces.VisitWithinRange(state.location, range, pvisitor);
    }

    {
        AirspaceVisitorClosest pvisitor("output/results/res-bb-closest.txt",
                                        airspaces.GetProjection(), state, perf);
        airspaces.VisitWithinRange(state.location, range, pvisitor);
    }

    {
        const std::vector<Airspace> vi = airspaces.FindInside(state);
        AirspaceVisitorPrint pvi("output/results/res-bb-inside.txt",
                                 do_report);
        std::for_each(vi.begin(), vi.end(), CallVisitor<AirspaceVisitor>(pvi));
    }

    {
        AirspaceIntersectionVisitorPrint ivisitor("output/results/res-bb-intersects.txt",
                "output/results/res-bb-intersected.txt",
                "output/results/res-bb-intercepts.txt",
                do_report,
                state, perf);
        airspaces.VisitIntersecting(state.location, target, ivisitor);
    }

    {
        AirspaceNearestSort ans(state.location);
        const AbstractAirspace* as = ans.find_nearest(airspaces, range);
        if (do_report) {
            std::ofstream fout("output/results/res-bb-sortednearest.txt");
            if (as) {
                fout << *as << "\n";
            } else {
                fout << "# no nearest found\n";
            }
        }
    }

    {
        AirspaceSoonestSort ans(state, perf);
        const AbstractAirspace* as = ans.find_nearest(airspaces);
        if (do_report) {
            std::ofstream fout("output/results/res-bb-sortedsoonest.txt");
            if (as) {
                fout << *as << "\n";
            } else {
                fout << "# no soonest found\n";
            }
        }
    }
}