label synthetic intersections

This commit is contained in:
Dustin Carlino 2018-12-10 15:50:06 -08:00
parent dbfd410b0a
commit e76dede109
8 changed files with 62 additions and 12 deletions

View File

@ -8,7 +8,8 @@
"x": 375.2584876887879, "x": 375.2584876887879,
"y": 394.4733648122756 "y": 394.4733648122756
}, },
"intersection_type": "StopSign" "intersection_type": "StopSign",
"label": "west"
} }
], ],
[ [
@ -18,7 +19,8 @@
"x": 426.5473937988281, "x": 426.5473937988281,
"y": 394.67230224609377 "y": 394.67230224609377
}, },
"intersection_type": "TrafficSignal" "intersection_type": "TrafficSignal",
"label": null
} }
], ],
[ [
@ -28,7 +30,8 @@
"x": 426.9548681897562, "x": 426.9548681897562,
"y": 338.6898394428313 "y": 338.6898394428313
}, },
"intersection_type": "StopSign" "intersection_type": "StopSign",
"label": null
} }
], ],
[ [
@ -38,7 +41,8 @@
"x": 481.2515387041076, "x": 481.2515387041076,
"y": 338.6877104503858 "y": 338.6877104503858
}, },
"intersection_type": "StopSign" "intersection_type": "StopSign",
"label": "east"
} }
], ],
[ [
@ -48,7 +52,8 @@
"x": 426.9279815253348, "x": 426.9279815253348,
"y": 456.09920803179929 "y": 456.09920803179929
}, },
"intersection_type": "Border" "intersection_type": "Border",
"label": "south"
} }
], ],
[ [
@ -58,7 +63,8 @@
"x": 427.35826112518097, "x": 427.35826112518097,
"y": 285.7304272008598 "y": 285.7304272008598
}, },
"intersection_type": "StopSign" "intersection_type": "StopSign",
"label": "north"
} }
] ]
], ],

View File

@ -8,7 +8,8 @@
"x": 288.5454406738281, "x": 288.5454406738281,
"y": 486.2385864257813 "y": 486.2385864257813
}, },
"intersection_type": "StopSign" "intersection_type": "StopSign",
"label": null
} }
], ],
[ [
@ -18,7 +19,8 @@
"x": 512.0357055664063, "x": 512.0357055664063,
"y": 486.63079833984377 "y": 486.63079833984377
}, },
"intersection_type": "StopSign" "intersection_type": "StopSign",
"label": null
} }
] ]
], ],

View File

@ -36,6 +36,7 @@ pub struct Intersection {
pub elevation: si::Meter<f64>, pub elevation: si::Meter<f64>,
pub intersection_type: IntersectionType, pub intersection_type: IntersectionType,
pub label: Option<String>,
// Note that a lane may belong to both incoming_lanes and outgoing_lanes. // Note that a lane may belong to both incoming_lanes and outgoing_lanes.
// TODO narrow down when and why. is it just sidewalks in weird cases? // TODO narrow down when and why. is it just sidewalks in weird cases?

View File

@ -109,6 +109,7 @@ impl Map {
elevation: i.elevation, elevation: i.elevation,
// Might change later // Might change later
intersection_type: i.intersection_type, intersection_type: i.intersection_type,
label: i.label.clone(),
incoming_lanes: Vec::new(), incoming_lanes: Vec::new(),
outgoing_lanes: Vec::new(), outgoing_lanes: Vec::new(),
roads: BTreeSet::new(), roads: BTreeSet::new(),
@ -626,6 +627,15 @@ impl Map {
} }
// TODO reconsider names, or put somewhere else? // TODO reconsider names, or put somewhere else?
pub fn intersection(&self, label: &str) -> IntersectionID {
for i in &self.intersections {
if i.label == Some(label.to_string()) {
return i.id;
}
}
panic!("No intersection has label {}", label);
}
pub fn bldg(&self, label: &str) -> BuildingID { pub fn bldg(&self, label: &str) -> BuildingID {
for b in &self.buildings { for b in &self.buildings {
if b.osm_tags.get("label") == Some(&label.to_string()) { if b.osm_tags.get("label") == Some(&label.to_string()) {

View File

@ -88,6 +88,7 @@ pub struct Intersection {
pub elevation: si::Meter<f64>, pub elevation: si::Meter<f64>,
// A raw Intersection can be forced into being a Border. // A raw Intersection can be forced into being a Border.
pub intersection_type: IntersectionType, pub intersection_type: IntersectionType,
pub label: Option<String>,
} }
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)] #[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]

View File

@ -152,9 +152,7 @@ impl IntersectionSimState {
p.debug = true; p.debug = true;
println!("{}", abstutil::to_json(map.get_traffic_signal(id))); println!("{}", abstutil::to_json(map.get_traffic_signal(id)));
} }
IntersectionPolicy::Border => { IntersectionPolicy::Border => {}
println!("{} has no IntersectionPolicy since it's a border", id);
}
}; };
} }
} }

View File

@ -20,6 +20,7 @@ enum State {
MovingBuilding(BuildingID), MovingBuilding(BuildingID),
LabelingBuilding(BuildingID, Wizard), LabelingBuilding(BuildingID, Wizard),
LabelingRoad((RoadID, Direction), Wizard), LabelingRoad((RoadID, Direction), Wizard),
LabelingIntersection(IntersectionID, Wizard),
CreatingRoad(IntersectionID), CreatingRoad(IntersectionID),
EditingRoad(RoadID, Wizard), EditingRoad(RoadID, Wizard),
SavingModel(Wizard), SavingModel(Wizard),
@ -80,6 +81,17 @@ impl GUI<Text> for UI {
self.state = State::Viewing; self.state = State::Viewing;
} }
} }
State::LabelingIntersection(id, ref mut wizard) => {
if let Some(label) = wizard.wrap(&mut input).input_string_prefilled(
"Label the intersection",
self.model.get_i_label(id).unwrap_or_else(String::new),
) {
self.model.set_i_label(id, label);
self.state = State::Viewing;
} else if wizard.aborted() {
self.state = State::Viewing;
}
}
State::CreatingRoad(i1) => { State::CreatingRoad(i1) => {
if input.key_pressed(Key::Escape, "stop defining road") { if input.key_pressed(Key::Escape, "stop defining road") {
self.state = State::Viewing; self.state = State::Viewing;
@ -124,6 +136,8 @@ impl GUI<Text> for UI {
self.model.remove_i(i); self.model.remove_i(i);
} else if input.key_pressed(Key::T, "toggle intersection type") { } else if input.key_pressed(Key::T, "toggle intersection type") {
self.model.toggle_i_type(i); self.model.toggle_i_type(i);
} else if input.key_pressed(Key::L, "label intersection") {
self.state = State::LabelingIntersection(i, Wizard::new());
} }
} else if let Some(b) = self.model.mouseover_building(cursor) { } else if let Some(b) = self.model.mouseover_building(cursor) {
if input.key_pressed(Key::LCtrl, "move building") { if input.key_pressed(Key::LCtrl, "move building") {
@ -185,6 +199,7 @@ impl GUI<Text> for UI {
} }
State::LabelingBuilding(_, ref wizard) State::LabelingBuilding(_, ref wizard)
| State::LabelingRoad(_, ref wizard) | State::LabelingRoad(_, ref wizard)
| State::LabelingIntersection(_, ref wizard)
| State::EditingRoad(_, ref wizard) | State::EditingRoad(_, ref wizard)
| State::SavingModel(ref wizard) => { | State::SavingModel(ref wizard) => {
wizard.draw(g, &self.canvas); wizard.draw(g, &self.canvas);

View File

@ -45,6 +45,7 @@ pub struct Model {
pub struct Intersection { pub struct Intersection {
center: Pt2D, center: Pt2D,
intersection_type: IntersectionType, intersection_type: IntersectionType,
label: Option<String>,
} }
impl Intersection { impl Intersection {
@ -200,6 +201,12 @@ impl Model {
} }
}; };
g.draw_circle(color, &i.circle()); g.draw_circle(color, &i.circle());
if let Some(ref label) = i.label {
let mut txt = Text::new();
txt.add_line(label.to_string());
canvas.draw_text_at(g, txt, i.center);
}
} }
for (id, b) in &self.buildings { for (id, b) in &self.buildings {
@ -261,6 +268,7 @@ impl Model {
point: pt(i.center), point: pt(i.center),
elevation: 0.0 * si::M, elevation: 0.0 * si::M,
intersection_type: i.intersection_type, intersection_type: i.intersection_type,
label: i.label.clone(),
}); });
} }
@ -294,6 +302,7 @@ impl Model {
Intersection { Intersection {
center, center,
intersection_type: IntersectionType::StopSign, intersection_type: IntersectionType::StopSign,
label: None,
}, },
); );
} }
@ -302,6 +311,14 @@ impl Model {
self.intersections.get_mut(&id).unwrap().center = center; self.intersections.get_mut(&id).unwrap().center = center;
} }
pub fn set_i_label(&mut self, id: IntersectionID, label: String) {
self.intersections.get_mut(&id).unwrap().label = Some(label);
}
pub fn get_i_label(&self, id: IntersectionID) -> Option<String> {
self.intersections[&id].label.clone()
}
pub fn toggle_i_type(&mut self, id: IntersectionID) { pub fn toggle_i_type(&mut self, id: IntersectionID) {
let i = self.intersections.get_mut(&id).unwrap(); let i = self.intersections.get_mut(&id).unwrap();
i.intersection_type = match i.intersection_type { i.intersection_type = match i.intersection_type {