mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-25 03:41:09 +03:00
very primitive building type classification, with coloring
This commit is contained in:
parent
606340e2db
commit
e186b24dac
@ -3,7 +3,7 @@ use crate::objects::{DrawCtx, ID};
|
||||
use crate::render::{RenderOptions, Renderable};
|
||||
use ezgui::{Color, Drawable, GfxCtx, Prerender};
|
||||
use geom::{Bounds, Distance, Line, Polygon, Pt2D};
|
||||
use map_model::{Building, BuildingID, LANE_THICKNESS};
|
||||
use map_model::{Building, BuildingID, BuildingType, LANE_THICKNESS};
|
||||
|
||||
pub struct DrawBuilding {
|
||||
pub id: BuildingID,
|
||||
@ -31,7 +31,17 @@ impl DrawBuilding {
|
||||
|
||||
let default_draw = prerender.upload_borrowed(vec![
|
||||
(
|
||||
cs.get_def("building", Color::rgba_f(0.7, 0.7, 0.7, 0.8)),
|
||||
match bldg.building_type {
|
||||
BuildingType::Residence => {
|
||||
cs.get_def("residential building", Color::rgb(218, 165, 32))
|
||||
}
|
||||
BuildingType::Business => {
|
||||
cs.get_def("business building", Color::rgb(210, 105, 30))
|
||||
}
|
||||
BuildingType::Unknown => {
|
||||
cs.get_def("unknown building", Color::rgb_f(0.7, 0.7, 0.7))
|
||||
}
|
||||
},
|
||||
&fill_polygon,
|
||||
),
|
||||
(cs.get_def("building path", Color::grey(0.6)), &front_path),
|
||||
@ -52,9 +62,6 @@ impl Renderable for DrawBuilding {
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, ctx: &DrawCtx) {
|
||||
// Buildings look better without boundaries, actually
|
||||
//g.draw_polygon(ctx.cs.get_def("building boundary", Color::rgb(0, 100, 0)), &self.boundary_polygon);
|
||||
|
||||
if let Some(c) = opts.color {
|
||||
g.draw_polygon_batch(vec![
|
||||
(c, &self.fill_polygon),
|
||||
|
@ -23,9 +23,17 @@ pub struct FrontPath {
|
||||
pub line: Line,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
||||
pub enum BuildingType {
|
||||
Residence,
|
||||
Business,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Building {
|
||||
pub id: BuildingID,
|
||||
pub building_type: BuildingType,
|
||||
pub points: Vec<Pt2D>,
|
||||
pub osm_tags: BTreeMap<String, String>,
|
||||
pub osm_way_id: i64,
|
||||
|
@ -21,7 +21,7 @@ mod traversable;
|
||||
mod turn;
|
||||
|
||||
pub use crate::area::{Area, AreaID, AreaType};
|
||||
pub use crate::building::{Building, BuildingID, FrontPath};
|
||||
pub use crate::building::{Building, BuildingID, BuildingType, FrontPath};
|
||||
pub use crate::bus_stop::{BusRoute, BusRouteID, BusStop, BusStopID};
|
||||
pub use crate::edits::{EditReason, MapEdits};
|
||||
pub use crate::find_closest::FindClosest;
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::make::sidewalk_finder::find_sidewalk_points;
|
||||
use crate::{raw_data, Building, BuildingID, FrontPath, Lane};
|
||||
use crate::{raw_data, Building, BuildingID, BuildingType, FrontPath, Lane};
|
||||
use abstutil::Timer;
|
||||
use geom::{Bounds, Distance, GPSBounds, HashablePt2D, Line, Pt2D};
|
||||
use std::collections::HashSet;
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
|
||||
pub fn make_all_buildings(
|
||||
results: &mut Vec<Building>,
|
||||
@ -48,6 +48,7 @@ pub fn make_all_buildings(
|
||||
let id = BuildingID(results.len());
|
||||
results.push(Building {
|
||||
id,
|
||||
building_type: classify(&input[idx].osm_tags),
|
||||
points,
|
||||
osm_tags: input[idx].osm_tags.clone(),
|
||||
osm_way_id: input[idx].osm_way_id,
|
||||
@ -83,3 +84,16 @@ fn trim_front_path(bldg_points: &Vec<Pt2D>, path: Line) -> Line {
|
||||
// Just give up
|
||||
path
|
||||
}
|
||||
|
||||
fn classify(tags: &BTreeMap<String, String>) -> BuildingType {
|
||||
if tags.contains_key(&"shop".to_string()) || tags.contains_key(&"amenity".to_string()) {
|
||||
return BuildingType::Business;
|
||||
}
|
||||
if tags.get("building") == Some(&"apartments".to_string()) {
|
||||
return BuildingType::Residence;
|
||||
}
|
||||
if tags.get("building") == Some(&"residential".to_string()) {
|
||||
return BuildingType::Residence;
|
||||
}
|
||||
return BuildingType::Unknown;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user