speed up building creation by doing sidewalk finding in bulk

This commit is contained in:
Dustin Carlino 2018-09-08 13:08:38 -07:00
parent 630f6504f4
commit f3982282de
5 changed files with 51 additions and 39 deletions

View File

@ -92,6 +92,7 @@ impl UI {
kml: Option<String>,
window_size: Size,
) -> UI {
flame::start("setup");
let (map, edits, control_map, sim) = sim::load(
load,
scenario_name,
@ -109,6 +110,7 @@ impl UI {
let (draw_map, center_pt) = render::DrawMap::new(&map, &control_map, extra_shapes);
flame::end("draw_map");
flame::end("setup");
flame::dump_stdout();
let steepness_viz = SteepnessVisualizer::new(&map);

View File

@ -85,6 +85,12 @@ impl fmt::Display for Pt2D {
}
}
impl From<HashablePt2D> for Pt2D {
fn from(pt: HashablePt2D) -> Self {
Pt2D::new(pt.x(), pt.y())
}
}
// This isn't opinionated about what the (x, y) represents -- could be lat/lon or world space.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub struct HashablePt2D {

View File

@ -5,25 +5,48 @@ use raw_data;
use std::collections::HashSet;
use {Building, BuildingID, FrontPath, Lane};
pub(crate) fn make_building(
b: &raw_data::Building,
id: BuildingID,
pub(crate) fn make_all_buildings(
results: &mut Vec<Building>,
input: &Vec<raw_data::Building>,
bounds: &Bounds,
lanes: &Vec<Lane>,
) -> Building {
// TODO consume data, so we dont have to clone tags?
let points = b.points
.iter()
.map(|coord| Pt2D::from_gps(coord, bounds))
.collect();
let front_path = find_front_path(id, &points, lanes);
) {
let mut pts_per_bldg: Vec<Vec<Pt2D>> = Vec::new();
let mut center_per_bldg: Vec<HashablePt2D> = Vec::new();
let mut query: HashSet<HashablePt2D> = HashSet::new();
for b in input {
let pts = b.points
.iter()
.map(|coord| Pt2D::from_gps(coord, bounds))
.collect();
let center: HashablePt2D = geometry::center(&pts).into();
pts_per_bldg.push(pts);
center_per_bldg.push(center);
query.insert(center);
}
Building {
points,
front_path,
id,
osm_way_id: b.osm_way_id,
osm_tags: b.osm_tags.clone(),
let sidewalk_pts = find_sidewalk_points(query, lanes);
for (idx, points) in pts_per_bldg.into_iter().enumerate() {
let id = BuildingID(idx);
let bldg_center = center_per_bldg[idx];
let (sidewalk, dist_along) = sidewalk_pts[&bldg_center];
let (sidewalk_pt, _) = lanes[sidewalk.0].dist_along(dist_along);
let line = trim_front_path(&points, Line::new(bldg_center.into(), sidewalk_pt));
results.push(Building {
id,
points,
osm_tags: input[idx].osm_tags.clone(),
osm_way_id: input[idx].osm_way_id,
front_path: FrontPath {
bldg: id,
sidewalk: sidewalk,
line,
dist_along_sidewalk: dist_along,
},
});
}
}
@ -37,20 +60,3 @@ fn trim_front_path(bldg_points: &Vec<Pt2D>, path: Line) -> Line {
path
}
}
fn find_front_path(bldg: BuildingID, bldg_points: &Vec<Pt2D>, lanes: &Vec<Lane>) -> FrontPath {
let bldg_center = geometry::center(bldg_points);
let mut query: HashSet<HashablePt2D> = HashSet::new();
query.insert(bldg_center.into());
let sidewalk_pts = find_sidewalk_points(query, lanes);
let (sidewalk, dist_along) = sidewalk_pts.values().next().unwrap();
let (sidewalk_pt, _) = lanes[sidewalk.0].dist_along(*dist_along);
let line = trim_front_path(bldg_points, Line::new(bldg_center, sidewalk_pt));
FrontPath {
bldg,
sidewalk: *sidewalk,
line,
dist_along_sidewalk: *dist_along,
}
}

View File

@ -5,7 +5,7 @@ mod sidewalk_finder;
mod trim_lines;
mod turns;
pub(crate) use self::buildings::make_building;
pub(crate) use self::buildings::make_all_buildings;
pub(crate) use self::bus_stops::make_bus_stops;
pub(crate) use self::lanes::get_lane_specs;
pub(crate) use self::trim_lines::trim_lines;

View File

@ -172,11 +172,9 @@ impl Map {
{
let _guard = flame::start_guard(format!("make {} buildings", data.buildings.len()));
for (idx, b) in data.buildings.iter().enumerate() {
let id = BuildingID(idx);
let bldg = make::make_building(b, id, &bounds, &m.lanes);
m.lanes[bldg.front_path.sidewalk.0].building_paths.push(id);
m.buildings.push(bldg);
make::make_all_buildings(&mut m.buildings, &data.buildings, &bounds, &m.lanes);
for b in &m.buildings {
m.lanes[b.front_path.sidewalk.0].building_paths.push(b.id);
}
}