Skip to content

Commit

Permalink
多くの変換ログを log crate → Feedback に移行する (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciscorn authored Mar 13, 2024
1 parent 8db4aac commit 560a689
Show file tree
Hide file tree
Showing 21 changed files with 68 additions and 47 deletions.
2 changes: 1 addition & 1 deletion app/src/routes/LoadingAnimation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
{/if}

<span
class="inline-flex items-center rounded-md bg-gray-400/10 px-2 py-1 text-xs font-medium text-gray-400 ring-1 ring-inset ring-gray-400/20"
class="inline-flex items-center rounded-md bg-gray-400/10 px-1 py-0.5 text-xs font-medium text-gray-400 ring-1 ring-inset ring-gray-400/20"
>{data.source}</span
>

Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/sink/cesiumtiles/gltf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub fn write_gltf_glb<W: Write>(
.into_iter()
.map(|img| {
feedback.ensure_not_canceled()?;
Ok(img.to_gltf(&mut gltf_buffer_views, &mut bin_content)?)
Ok(img.to_gltf(feedback, &mut gltf_buffer_views, &mut bin_content)?)
})
.collect::<Result<Vec<Image>, PipelineError>>()?;

Expand Down
13 changes: 8 additions & 5 deletions nusamai/src/sink/cesiumtiles/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use nusamai_gltf_json::{BufferView, MimeType};
use serde::{Deserialize, Serialize};
use url::Url;

use crate::pipeline::Feedback;

#[derive(Debug, Serialize, Clone, PartialEq, Deserialize)]
pub struct Material {
pub base_color: [f32; 4],
Expand Down Expand Up @@ -79,12 +81,13 @@ pub struct Image {
impl Image {
pub fn to_gltf(
&self,
feedback: &Feedback,
buffer_views: &mut Vec<BufferView>,
bin_content: &mut Vec<u8>,
) -> std::io::Result<nusamai_gltf_json::Image> {
if let Ok(path) = self.uri.to_file_path() {
// NOTE: temporary implementation
let (content, mime_type) = load_image(&path)?;
let (content, mime_type) = load_image(feedback, &path)?;

buffer_views.push(BufferView {
name: Some("image".to_string()),
Expand All @@ -110,15 +113,15 @@ impl Image {
}

// NOTE: temporary implementation
fn load_image(path: &Path) -> std::io::Result<(Vec<u8>, MimeType)> {
fn load_image(feedback: &Feedback, path: &Path) -> std::io::Result<(Vec<u8>, MimeType)> {
if let Some(ext) = path.extension() {
match ext.to_str() {
Some("tif" | "tiff" | "png") => {
log::info!("Decoding image: {:?}", path);
feedback.info(format!("Decoding image: {:?}", path));
let t = Instant::now();
let image = image::open(path)
.map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidData, err))?;
log::debug!("Image decoding took {:?}", t.elapsed());
feedback.info(format!("Image decoding took {:?}", t.elapsed()));

let mut writer = std::io::Cursor::new(Vec::new());
let encoder = image::codecs::png::PngEncoder::new(&mut writer);
Expand All @@ -128,7 +131,7 @@ fn load_image(path: &Path) -> std::io::Result<(Vec<u8>, MimeType)> {
Ok((writer.into_inner(), MimeType::ImagePng))
}
Some("jpg" | "jpeg") => {
log::info!("Embedding a jpeg as is: {:?}", path);
feedback.info(format!("Embedding a jpeg as is: {:?}", path));
Ok((std::fs::read(path)?, MimeType::ImageJpeg))
}
_ => {
Expand Down
9 changes: 5 additions & 4 deletions nusamai/src/sink/cesiumtiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct SerializedSlicedFeature {
impl DataSink for CesiumTilesSink {
fn make_requirements(&self) -> DataRequirements {
DataRequirements {
use_appearance: true,
// use_appearance: true,
resolve_appearance: true,
key_value: crate::transformer::KeyValueSpec::JsonifyObjects,
..Default::default()
Expand Down Expand Up @@ -281,9 +281,10 @@ fn tile_writing_stage(
};

let geom_error = tiling::geometric_error(tile_zoom, tile_y);
log::info!(
feedback.info(
format!(
"tile: z={tile_zoom}, x={tile_x}, y={tile_y} (lng: [{min_lng} => {max_lng}], lat: [{min_lat} => {max_lat}) geometricError: {geom_error}"
);
));
let content_path = {
let normalized_typename = typename.replace(':', "_");
format!("{tile_zoom}/{tile_x}/{tile_y}_{normalized_typename}.glb")
Expand Down Expand Up @@ -350,7 +351,7 @@ fn tile_writing_stage(

// Encode properties
if metadata_encoder.add_feature(&typename, &feature.attributes).is_err() {
log::warn!("Failed to encode feature attributes");
feedback.warn("Failed to encode feature attributes".to_string());
continue
}

Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/sink/gltf/gltf_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ pub fn write_gltf_glb<W: Write>(
.into_iter()
.map(|img| {
feedback.ensure_not_canceled()?;
Ok(img.to_gltf(&mut gltf_buffer_views, &mut bin_content)?)
Ok(img.to_gltf(feedback, &mut gltf_buffer_views, &mut bin_content)?)
})
.collect::<Result<Vec<Image>, PipelineError>>()?;

Expand Down
14 changes: 8 additions & 6 deletions nusamai/src/sink/gltf/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use url::Url;

use nusamai_gltf_json::MimeType;

use crate::pipeline::Feedback;

#[derive(Debug, Serialize, Clone, PartialEq, Deserialize)]
pub struct Material {
pub base_color: [f32; 4],
Expand Down Expand Up @@ -81,12 +83,13 @@ pub struct Image {
impl Image {
pub fn to_gltf(
&self,
feedback: &Feedback,
buffer_views: &mut Vec<BufferView>,
bin_content: &mut Vec<u8>,
) -> std::io::Result<nusamai_gltf_json::Image> {
if let Ok(path) = self.uri.to_file_path() {
// NOTE: temporary implementation
let (content, mime_type) = load_image(&path)?;
let (content, mime_type) = load_image(feedback, &path)?;

buffer_views.push(BufferView {
byte_offset: bin_content.len() as u32,
Expand All @@ -111,15 +114,15 @@ impl Image {
}

// NOTE: temporary implementation
fn load_image(path: &Path) -> std::io::Result<(Vec<u8>, MimeType)> {
fn load_image(feedback: &Feedback, path: &Path) -> std::io::Result<(Vec<u8>, MimeType)> {
if let Some(ext) = path.extension() {
match ext.to_str() {
Some("tif" | "tiff" | "png") => {
log::info!("Decoding image: {:?}", path);
feedback.info(format!("Decoding image: {:?}", path));
let t = Instant::now();
let image = image::open(path)
.map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidData, err))?;
log::debug!("Image decoding took {:?}", t.elapsed());
feedback.debug(format!("Image decoding took {:?}", t.elapsed()));

let t = Instant::now();
let mut writer = std::io::Cursor::new(Vec::new());
Expand All @@ -133,12 +136,11 @@ fn load_image(path: &Path) -> std::io::Result<(Vec<u8>, MimeType)> {
Ok((writer.into_inner(), MimeType::ImagePng))
}
Some("jpg" | "jpeg") => {
log::info!("Embedding a jpeg as is: {:?}", path);
feedback.info(format!("Embedding a jpeg as is: {:?}", path));
Ok((std::fs::read(path)?, MimeType::ImageJpeg))
}
_ => {
let err = format!("Unsupported image format: {:?}", path);
log::error!("{}", err);
Err(std::io::Error::new(std::io::ErrorKind::InvalidData, err))
}
}
Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/sink/gltf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl DataSink for GltfSink {
.add_feature(&typename, &feature.attributes)
.is_err()
{
log::warn!("Failed to encode feature attributes");
feedback.warn("Failed to encode feature attributes".to_string());
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions nusamai/src/sink/gpkg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ impl GpkgSink {
}
ObjectStereotype::Object { id: obj_id } => {
// TODO: implement (you will also need the corresponding TypeDef::Object in the schema)
log::warn!(
feedback.warn(format!(
"ObjectStereotype::Object is not supported yet: id = {}",
obj_id
);
));
}
}

Expand Down
9 changes: 5 additions & 4 deletions nusamai/src/sink/noop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ impl DataSink for NoopSink {

self.num_features += 1;
self.num_vertices += parcel.entity.geometry_store.read().unwrap().vertices.len();

// log::info!("feature: {:?}", parcel.entity.root);
}

feedback.ensure_not_canceled()?;
log::info!("total number of features: {:#?}", self.num_features);
log::info!("total vertices: {}", self.num_vertices);
feedback.info(format!(
"total number of features: {:#?}",
self.num_features
));
feedback.info(format!("total vertices: {}", self.num_vertices));

Ok(())
}
Expand Down
7 changes: 3 additions & 4 deletions nusamai/src/sink/serde/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,10 @@ impl DataSink for SerdeSink {
self.features_written += 1;
self.bytes_written += 4 + compressed.len();
}
log::info!(
feedback.info(format!(
"Wrote {} features ({} bytes)",
self.features_written,
self.bytes_written
);
self.features_written, self.bytes_written
));
Ok(())
},
);
Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/transformer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub trait Transformer: Send {

pub trait Transform: Send {
/// Transform each entity
fn transform(&mut self, entity: Entity, out: &mut Vec<Entity>);
fn transform(&mut self, feedback: &Feedback, entity: Entity, out: &mut Vec<Entity>);
/// Transform the schema
fn transform_schema(&self, schema: &mut Schema);
}
2 changes: 1 addition & 1 deletion nusamai/src/transformer/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<T: TransformBuilder> Transformer for MultiThreadTransformer<T> {
feedback.ensure_not_canceled()?;

// Apply transform to entity
transform.transform(parcel.entity, buf);
transform.transform(feedback, parcel.entity, buf);

for entity in buf.drain(..) {
if downstream.send(Parcel { entity }).is_err() {
Expand Down
12 changes: 6 additions & 6 deletions nusamai/src/transformer/transform/appearance.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! Apply appearance to geometries
use crate::transformer::Transform;
use crate::{pipeline::feedback, transformer::Transform};

use feedback::Feedback;
use nusamai_citygml::schema::Schema;
use nusamai_geometry::MultiPolygon;
use nusamai_plateau::Entity;
Expand All @@ -10,7 +11,7 @@ use nusamai_plateau::Entity;
pub struct ApplyAppearanceTransform {}

impl Transform for ApplyAppearanceTransform {
fn transform(&mut self, entity: Entity, out: &mut Vec<Entity>) {
fn transform(&mut self, feedback: &Feedback, entity: Entity, out: &mut Vec<Entity>) {
{
let app = entity.appearance_store.read().unwrap();
let theme = {
Expand Down Expand Up @@ -73,11 +74,10 @@ impl Transform for ApplyAppearanceTransform {
}
Some((_, uv)) if uv.len() != ring.len() => {
// invalid texture found
log::warn!(
feedback.warn(format!(
"Length of UVs does not match length of ring: {:?} {:?}",
ring,
uv
);
ring, uv
));
add_dummy_texture();
}
_ => {
Expand Down
3 changes: 2 additions & 1 deletion nusamai/src/transformer/transform/attrname.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::pipeline::Feedback;
use crate::transformer::Transform;

use hashbrown::HashMap;
Expand Down Expand Up @@ -58,7 +59,7 @@ impl EditFieldNamesTransform {
}

impl Transform for EditFieldNamesTransform {
fn transform(&mut self, mut entity: Entity, out: &mut Vec<Entity>) {
fn transform(&mut self, _feedback: &Feedback, mut entity: Entity, out: &mut Vec<Entity>) {
self.edit_tree(&mut entity.root);
out.push(entity);
}
Expand Down
3 changes: 2 additions & 1 deletion nusamai/src/transformer/transform/dots.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::pipeline::Feedback;
use crate::transformer::Transform;

use nusamai_citygml::object::{Map, Value};
Expand All @@ -11,7 +12,7 @@ pub struct DotNotationTransform {
}

impl Transform for DotNotationTransform {
fn transform(&mut self, mut entity: Entity, out: &mut Vec<Entity>) {
fn transform(&mut self, _feedback: &Feedback, mut entity: Entity, out: &mut Vec<Entity>) {
if let Value::Object(mut obj) = entity.root {
let mut new_attrs = Default::default();
let path = &mut self.path_buf;
Expand Down
3 changes: 2 additions & 1 deletion nusamai/src/transformer/transform/flatten.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::{Arc, RwLock};

use crate::pipeline::Feedback;
use crate::transformer::Transform;

use nusamai_citygml::object::{Map, Object, ObjectStereotype, Value};
Expand Down Expand Up @@ -89,7 +90,7 @@ impl FlattenTreeTransform {
}

impl Transform for FlattenTreeTransform {
fn transform(&mut self, entity: Entity, out: &mut Vec<Entity>) {
fn transform(&mut self, _feedback: &Feedback, entity: Entity, out: &mut Vec<Entity>) {
let geom_store = entity.geometry_store;
let appearance_store = entity.appearance_store;
self.flatten_entity(entity.root, &geom_store, &appearance_store, out, &None);
Expand Down
3 changes: 2 additions & 1 deletion nusamai/src/transformer/transform/geommerge.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::pipeline::Feedback;
use crate::transformer::Transform;

use hashbrown::HashSet;
Expand All @@ -23,7 +24,7 @@ impl GeometricMergedownTransform {
}

impl Transform for GeometricMergedownTransform {
fn transform(&mut self, mut entity: Entity, out: &mut Vec<Entity>) {
fn transform(&mut self, _feedback: &Feedback, mut entity: Entity, out: &mut Vec<Entity>) {
if let Value::Object(obj) = &mut entity.root {
self.collect_all_geoms(obj);
if let ObjectStereotype::Feature { geometries, .. } = &mut obj.stereotype {
Expand Down
3 changes: 2 additions & 1 deletion nusamai/src/transformer/transform/jsonify.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::pipeline::Feedback;
use crate::transformer::Transform;

use nusamai_citygml::object::Value;
Expand Down Expand Up @@ -26,7 +27,7 @@ impl Default for JsonifyTransform {
}

impl Transform for JsonifyTransform {
fn transform(&mut self, mut entity: Entity, out: &mut Vec<Entity>) {
fn transform(&mut self, _feedback: &Feedback, mut entity: Entity, out: &mut Vec<Entity>) {
if let Value::Object(obj) = &mut entity.root {
let mut attrs = nusamai_citygml::object::Map::default();
for (key, value) in obj.attributes.drain(..) {
Expand Down
3 changes: 2 additions & 1 deletion nusamai/src/transformer/transform/lods.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::ops::{BitAnd, BitAndAssign, BitOrAssign};

use crate::pipeline::Feedback;
use crate::transformer::Transform;

use nusamai_citygml::object::{ObjectStereotype, Value};
Expand All @@ -26,7 +27,7 @@ impl FilterLodTransform {

/// Transform to filter and split the LODs
impl Transform for FilterLodTransform {
fn transform(&mut self, mut entity: Entity, out: &mut Vec<Entity>) {
fn transform(&mut self, _feedback: &Feedback, mut entity: Entity, out: &mut Vec<Entity>) {
let lods = find_lods(&entity.root) & self.mask;

let target_lod = match self.mode {
Expand Down
Loading

0 comments on commit 560a689

Please sign in to comment.