diff --git a/Cargo.toml b/Cargo.toml index c052c7a8b..cde508569 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,9 @@ members = [ "nusamai-mvt", ] resolver = "2" + +[profile.dev] +opt-level = 1 + +[profile.dev.package."*"] +opt-level = 2 diff --git a/nusamai-plateau/citygml/src/geometric.rs b/nusamai-plateau/citygml/src/geometric.rs index ef85bfa2d..9b04f4722 100644 --- a/nusamai-plateau/citygml/src/geometric.rs +++ b/nusamai-plateau/citygml/src/geometric.rs @@ -37,8 +37,8 @@ pub type GeometryRef = Vec; #[derive(Debug, Default)] pub struct Geometries { pub vertices: Vec<[f64; 3]>, - pub polygons: MultiPolygon<'static, 1, u32>, - pub linestrings: MultiLineString<'static, 1, u32>, + pub multipolygons: MultiPolygon<'static, 1, u32>, + pub multilinestrings: MultiLineString<'static, 1, u32>, } /// Store for collecting vertices and polygons from GML. @@ -81,8 +81,8 @@ impl GeometryCollector { } Geometries { vertices, - polygons: self.multi_polygon.clone(), - linestrings: self.multi_linestring.clone(), + multipolygons: self.multi_polygon.clone(), + multilinestrings: self.multi_linestring.clone(), } } diff --git a/nusamai-plateau/citygml/src/parser.rs b/nusamai-plateau/citygml/src/parser.rs index a8478ebaf..74f449a6c 100644 --- a/nusamai-plateau/citygml/src/parser.rs +++ b/nusamai-plateau/citygml/src/parser.rs @@ -315,10 +315,10 @@ impl SubTreeReader<'_, R> { self.parse_composite_surface()?; GeometryType::Surface } - // (Bound(GML_NS), b"OrientableSurface") => ... - // (Bound(GML_NS), b"Polygon") => ... - // (Bound(GML_NS), b"TriangulatedSurface") => ... - // (Bound(GML_NS), b"Tin") => ... + (Bound(GML_NS), b"OrientableSurface") => todo!(), + (Bound(GML_NS), b"Polygon") => todo!(), + (Bound(GML_NS), b"TriangulatedSurface") => todo!(), + (Bound(GML_NS), b"Tin") => todo!(), _ => { return Err(ParseError::SchemaViolation(format!( "Unexpected element <{}>", diff --git a/nusamai-plateau/examples/parse.rs b/nusamai-plateau/examples/parse.rs index a15dec949..24dab2bba 100644 --- a/nusamai-plateau/examples/parse.rs +++ b/nusamai-plateau/examples/parse.rs @@ -122,6 +122,7 @@ fn main() { println!("elapsed time parsing: {:?}", parsing_time); total_parsing_time += parsing_time; } + println!("total parsing time: {:?}", total_parsing_time); } diff --git a/nusamai-plateau/tests/data/53393680_bldg_6697_lod4.2_op.gml.zst b/nusamai-plateau/tests/data/53393680_bldg_6697_lod4.2_op.gml.zst new file mode 100755 index 000000000..7f7ba45e6 Binary files /dev/null and b/nusamai-plateau/tests/data/53393680_bldg_6697_lod4.2_op.gml.zst differ diff --git a/nusamai-plateau/tests/test_simple.rs b/nusamai-plateau/tests/test_simple.rs new file mode 100644 index 000000000..288969fca --- /dev/null +++ b/nusamai-plateau/tests/test_simple.rs @@ -0,0 +1,70 @@ +use std::io::BufRead; + +use citygml::{CityGMLElement, CityGMLReader, ParseError, SubTreeReader}; +use nusamai_plateau::models::CityObject; + +#[derive(Default, Debug)] +struct Counter { + city_objects: usize, + appearances: usize, + multipolygons: usize, +} + +fn example_toplevel_dispatcher( + st: &mut SubTreeReader, +) -> Result { + let mut counter = Counter::default(); + + match st.parse_children(|st| match st.current_path() { + b"core:cityObjectMember" => { + let mut cityobj: CityObject = Default::default(); + cityobj.parse(st)?; + let geometries = st.collect_geometries(); + counter.city_objects += 1; + counter.multipolygons += geometries.multipolygons.len(); + Ok(()) + } + b"gml:boundedBy" => { + st.skip_current_element()?; + Ok(()) + } + b"app:appearanceMember" => { + st.skip_current_element()?; + counter.appearances += 1; + Ok(()) + } + other => Err(ParseError::SchemaViolation(format!( + "Unrecognized element {}", + String::from_utf8_lossy(other) + ))), + }) { + Ok(_) => Ok(counter), + Err(e) => { + println!("Err: {:?}", e); + Err(e) + } + } +} + +#[test] +fn simple_read() { + let reader = std::io::BufReader::new( + zstd::stream::Decoder::new( + std::fs::File::open("./tests/data/53393680_bldg_6697_lod4.2_op.gml.zst").unwrap(), + ) + .unwrap(), + ); + + let mut xml_reader = quick_xml::NsReader::from_reader(reader); + match CityGMLReader::new().start_root(&mut xml_reader) { + Ok(mut st) => match example_toplevel_dispatcher(&mut st) { + Ok(counter) => { + assert_eq!(counter.city_objects, 1527); + assert_eq!(counter.multipolygons, 196148); + assert_eq!(counter.appearances, 1); + } + Err(e) => panic!("Err: {:?}", e), + }, + Err(e) => panic!("Err: {:?}", e), + }; +}