import raw map to synthetic

This commit is contained in:
Dustin Carlino 2019-01-14 14:36:46 -08:00
parent 6d4e958ea5
commit 09a3aed407
5 changed files with 73 additions and 7 deletions

View File

@ -3,3 +3,5 @@
Find packages to upgrade: `cargo outdated -R`
Diff screencaps: http://www.imagemagick.org/Usage/compare/#methods
Cross-compilation: https://github.com/rust-embedded/cross

View File

@ -235,8 +235,7 @@ impl<S: UIState> GUI<RenderingHints> for UI<S> {
// TODO a plugin should do this, even though it's such a tiny thing
if input.unimportant_key_pressed(Key::F1, "take screenshot") {
let bounds = self.state.get_state().primary.map.get_bounds();
assert_eq!(bounds.min_x, 0.0);
assert_eq!(bounds.min_y, 0.0);
assert!(bounds.min_x == 0.0 && bounds.min_y == 0.0);
hints.mode = EventLoopMode::ScreenCaptureEverything {
zoom: 3.0,
max_x: bounds.max_x,

View File

@ -74,7 +74,7 @@ impl Event {
return Event::MouseWheelScroll(pair[1]);
}
if let Some(pair) = ev.resize_args() {
return Event::WindowResized(f64::from(pair[0]), f64::from(pair[1]));
return Event::WindowResized(pair[0], pair[1]);
}
if let Some(has) = ev.cursor_args() {
if has {

View File

@ -26,7 +26,11 @@ enum State {
impl UI {
fn new(load: Option<&String>) -> UI {
let model: Model = if let Some(path) = load {
abstutil::read_json(path).expect(&format!("Couldn't load {}", path))
if path.contains("raw_maps/") {
Model::import(path)
} else {
abstutil::read_json(path).expect(&format!("Couldn't load {}", path))
}
} else {
Model::new()
};

View File

@ -1,10 +1,10 @@
use abstutil::{deserialize_btreemap, serialize_btreemap, write_json};
use abstutil::{deserialize_btreemap, read_binary, serialize_btreemap, write_json, Timer};
use dimensioned::si;
use ezgui::{Canvas, Color, GfxCtx, Text};
use geom::{Circle, LonLat, PolyLine, Polygon, Pt2D};
use geom::{Circle, HashablePt2D, LonLat, PolyLine, Polygon, Pt2D};
use map_model::{raw_data, IntersectionType, LaneType, RoadSpec, LANE_THICKNESS};
use serde_derive::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::collections::{BTreeMap, HashMap};
use std::mem;
const INTERSECTION_RADIUS: f64 = 10.0;
@ -291,6 +291,67 @@ impl Model {
abstutil::write_binary(&path, &map).expect(&format!("Saving {} failed", path));
println!("Exported {}", path);
}
// TODO Directly use raw_data and get rid of Model? Might be more maintainable long-term.
pub fn import(path: &str) -> Model {
let data: raw_data::Map = read_binary(path, &mut Timer::new("load raw map")).unwrap();
let gps_bounds = data.get_gps_bounds();
let mut m = Model::new();
let mut pt_to_intersection: HashMap<HashablePt2D, IntersectionID> = HashMap::new();
for (idx, i) in data.intersections.iter().enumerate() {
let center = Pt2D::from_gps(i.point, &gps_bounds).unwrap();
m.intersections.insert(
idx,
Intersection {
center,
intersection_type: i.intersection_type,
label: i.label.clone(),
},
);
pt_to_intersection.insert(center.into(), idx);
}
for r in &data.roads {
let i1 = pt_to_intersection[&Pt2D::from_gps(r.points[0], &gps_bounds).unwrap().into()];
let i2 = pt_to_intersection[&Pt2D::from_gps(*r.points.last().unwrap(), &gps_bounds)
.unwrap()
.into()];
m.roads.insert(
(i1, i2),
Road {
i1,
i2,
// TODO Do better
lanes: RoadSpec {
fwd: vec![LaneType::Driving, LaneType::Parking, LaneType::Sidewalk],
back: vec![LaneType::Driving, LaneType::Parking, LaneType::Sidewalk],
},
// TODO nope
fwd_label: None,
back_label: None,
},
);
}
for (idx, b) in data.buildings.iter().enumerate() {
m.buildings.insert(
idx,
Building {
label: None,
center: Pt2D::center(
&b.points
.iter()
.map(|pt| Pt2D::from_gps(*pt, &gps_bounds).unwrap())
.collect(),
),
},
);
}
m
}
}
impl Model {