debug_initialmap loads from raw_data. remove the complicated serialization stuff from InitialMap.

This commit is contained in:
Dustin Carlino 2019-06-11 17:15:17 -07:00
parent d9474494e7
commit 290c274661
3 changed files with 14 additions and 61 deletions

View File

@ -1,7 +1,7 @@
use abstutil::{find_next_file, find_prev_file, read_binary, Timer}; use abstutil::Timer;
use ezgui::{Color, EventCtx, EventLoopMode, GfxCtx, Key, Text, GUI}; use ezgui::{Color, EventCtx, EventLoopMode, GfxCtx, Key, Text, GUI};
use geom::{Distance, Polygon}; use geom::{Distance, Polygon};
use map_model::raw_data::{StableIntersectionID, StableRoadID, InitialMap}; use map_model::raw_data::{InitialMap, StableIntersectionID, StableRoadID};
use std::collections::HashSet; use std::collections::HashSet;
use std::{env, process}; use std::{env, process};
use viewer::World; use viewer::World;
@ -12,7 +12,6 @@ const MIN_ROAD_LENGTH: Distance = Distance::const_meters(13.0);
struct UI { struct UI {
world: World<ID>, world: World<ID>,
data: InitialMap, data: InitialMap,
filename: String,
// TODO Or, if these are common things, the World could also hold this state. // TODO Or, if these are common things, the World could also hold this state.
selected: Option<ID>, selected: Option<ID>,
hide: HashSet<ID>, hide: HashSet<ID>,
@ -21,27 +20,25 @@ struct UI {
impl UI { impl UI {
fn new(filename: &str, ctx: &mut EventCtx) -> UI { fn new(filename: &str, ctx: &mut EventCtx) -> UI {
let data: InitialMap = let mut timer = Timer::new(&format!("load {}", filename));
read_binary(filename, &mut Timer::new("load InitialMap")).unwrap(); let raw: map_model::raw_data::Map = abstutil::read_binary(filename, &mut timer).unwrap();
let gps_bounds = raw.get_gps_bounds();
let data = InitialMap::new(
filename.to_string(),
&raw,
&gps_bounds,
&gps_bounds.to_bounds(),
&mut timer,
);
let world = initial_map_to_world(&data, ctx); let world = initial_map_to_world(&data, ctx);
UI { UI {
world, world,
data, data,
filename: filename.to_string(),
selected: None, selected: None,
hide: HashSet::new(), hide: HashSet::new(),
osd: Text::new(), osd: Text::new(),
} }
} }
fn load_different(&mut self, filename: String, ctx: &mut EventCtx) {
let data: InitialMap =
read_binary(&filename, &mut Timer::new("load InitialMap")).unwrap();
self.world = initial_map_to_world(&data, ctx);
self.selected = None;
self.filename = filename;
self.hide.clear();
}
} }
impl GUI for UI { impl GUI for UI {
@ -56,17 +53,6 @@ impl GUI for UI {
process::exit(0); process::exit(0);
} }
if let Some(prev) = find_prev_file(self.filename.clone()) {
if ctx.input.key_pressed(Key::Comma, "load previous map") {
self.load_different(prev, ctx);
}
}
if let Some(next) = find_next_file(self.filename.clone()) {
if ctx.input.key_pressed(Key::Dot, "load next map") {
self.load_different(next, ctx);
}
}
if let Some(id) = self.selected { if let Some(id) = self.selected {
if ctx.input.key_pressed(Key::H, "hide this") { if ctx.input.key_pressed(Key::H, "hide this") {
self.hide.insert(id); self.hide.insert(id);
@ -75,7 +61,7 @@ impl GUI for UI {
} }
if let Some(ID::HalfRoad(r, _)) = self.selected { if let Some(ID::HalfRoad(r, _)) = self.selected {
if ctx.input.key_pressed(Key::M, "merge") { if ctx.input.key_pressed(Key::M, "merge") {
self.data.merge(r); self.data.merge_road(r);
self.world = initial_map_to_world(&self.data, ctx); self.world = initial_map_to_world(&self.data, ctx);
self.selected = None; self.selected = None;
} }
@ -177,10 +163,5 @@ fn initial_map_to_world(data: &InitialMap, ctx: &mut EventCtx) -> World<ID> {
); );
} }
if let Some(id) = data.focus_on {
ctx.canvas
.center_on_map_pt(w.get_center(ID::Intersection(id)));
}
w w
} }

View File

@ -73,8 +73,6 @@ pub fn merge(
(r.src_i, r.dst_i) (r.src_i, r.dst_i)
}; };
// Show what we're about to delete
map.save(Some(delete_i));
map.roads.remove(&merge_road); map.roads.remove(&merge_road);
map.intersections.remove(&delete_i); map.intersections.remove(&delete_i);
map.intersections map.intersections
@ -140,13 +138,9 @@ pub fn merge(
} }
} }
} }
// Show the reset road geometry
map.save(None);
let mut i = map.intersections.get_mut(&keep_i).unwrap(); let mut i = map.intersections.get_mut(&keep_i).unwrap();
i.polygon = geometry::intersection_polygon(i, &mut map.roads, timer); i.polygon = geometry::intersection_polygon(i, &mut map.roads, timer);
// Show the final results of fixing this area
map.save(None);
keep_i keep_i
} }

View File

@ -7,21 +7,16 @@ use crate::raw_data::{StableIntersectionID, StableRoadID};
use crate::{raw_data, LANE_THICKNESS}; use crate::{raw_data, LANE_THICKNESS};
use abstutil::Timer; use abstutil::Timer;
use geom::{Bounds, Distance, GPSBounds, PolyLine, Pt2D}; use geom::{Bounds, Distance, GPSBounds, PolyLine, Pt2D};
use serde_derive::{Deserialize, Serialize};
use std::collections::{BTreeMap, BTreeSet}; use std::collections::{BTreeMap, BTreeSet};
#[derive(Serialize, Deserialize)]
pub struct InitialMap { pub struct InitialMap {
pub roads: BTreeMap<StableRoadID, Road>, pub roads: BTreeMap<StableRoadID, Road>,
pub intersections: BTreeMap<StableIntersectionID, Intersection>, pub intersections: BTreeMap<StableIntersectionID, Intersection>,
pub name: String, pub name: String,
pub bounds: Bounds, pub bounds: Bounds,
pub focus_on: Option<StableIntersectionID>,
versions_saved: usize,
} }
#[derive(Serialize, Deserialize)]
pub struct Road { pub struct Road {
pub id: StableRoadID, pub id: StableRoadID,
pub src_i: StableIntersectionID, pub src_i: StableIntersectionID,
@ -45,7 +40,6 @@ impl Road {
} }
} }
#[derive(Serialize, Deserialize)]
pub struct Intersection { pub struct Intersection {
pub id: StableIntersectionID, pub id: StableIntersectionID,
pub polygon: Vec<Pt2D>, pub polygon: Vec<Pt2D>,
@ -65,8 +59,6 @@ impl InitialMap {
intersections: BTreeMap::new(), intersections: BTreeMap::new(),
name, name,
bounds: bounds.clone(), bounds: bounds.clone(),
focus_on: None,
versions_saved: 0,
}; };
for stable_id in data.intersections.keys() { for stable_id in data.intersections.keys() {
@ -153,21 +145,7 @@ impl InitialMap {
m m
} }
pub fn save(&mut self, focus_on: Option<StableIntersectionID>) { pub fn merge_road(&mut self, r: StableRoadID) {
if true {
return;
}
let path = format!("../initial_maps/{:03}.bin", self.versions_saved);
self.focus_on = focus_on;
self.versions_saved += 1;
abstutil::write_binary(&path, self).expect(&format!("Saving {} failed", path));
println!("Saved {}", path);
}
pub fn merge(
&mut self,
r: StableRoadID,
) {
merge::merge(self, r, &mut Timer::throwaway()); merge::merge(self, r, &mut Timer::throwaway());
} }
} }