From 8fb1dfddaa9d545f86316e8a11a728e54cc0c840 Mon Sep 17 00:00:00 2001 From: satoshi komatsu Date: Fri, 20 Dec 2024 17:05:03 +0900 Subject: [PATCH 1/9] Add a comment --- nusamai/src/transformer/transform/lods.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/nusamai/src/transformer/transform/lods.rs b/nusamai/src/transformer/transform/lods.rs index 9d226cd4..b29c4144 100644 --- a/nusamai/src/transformer/transform/lods.rs +++ b/nusamai/src/transformer/transform/lods.rs @@ -31,6 +31,7 @@ impl FilterLodTransform { /// Transform to filter and split the LODs impl Transform for FilterLodTransform { fn transform(&mut self, _feedback: &Feedback, mut entity: Entity, out: &mut Vec) { + // Extract the largest LOD with a texture. If there is no texture, extract the largest LOD. match self.mode { LodFilterMode::TexturedHighest => { let available_lods = find_lods(&entity.root) & self.mask; From 187bd789764f30931b3b94bb4d39298299ce4083 Mon Sep 17 00:00:00 2001 From: satoshi komatsu Date: Fri, 20 Dec 2024 17:21:19 +0900 Subject: [PATCH 2/9] Add a comment --- nusamai/src/transformer/transform/lods.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nusamai/src/transformer/transform/lods.rs b/nusamai/src/transformer/transform/lods.rs index b29c4144..38298317 100644 --- a/nusamai/src/transformer/transform/lods.rs +++ b/nusamai/src/transformer/transform/lods.rs @@ -37,10 +37,10 @@ impl Transform for FilterLodTransform { let available_lods = find_lods(&entity.root) & self.mask; let mut highest_textured_lod = None; - // Since the "maximum LOD" is decided from the beginning, if the texture does not exist, - // the maximum LOD can be returned immediately. + // The “maximum LOD” is set from the beginning. If the texture does not exist, the maximum LOD is returned immediately. let highest_available_lod = available_lods.highest_lod().unwrap_or(0); + // Creating a reverse-order iterator with ev for lod in (0..=highest_available_lod).rev() { if available_lods.0 & (1 << lod) != 0 { edit_tree(&mut entity.root, lod); @@ -50,6 +50,7 @@ impl Transform for FilterLodTransform { !appearance.textures.is_empty() }; + // If a LOD with the texture is found, save it and exit. if has_textures { highest_textured_lod = Some(lod); break; @@ -57,6 +58,8 @@ impl Transform for FilterLodTransform { } } + // If “highest_textured_lod” is not None, use “highest_textured_lod” + // If it is None, use ”highest_available_lod” if let Some(lod) = highest_textured_lod.or(Some(highest_available_lod)) { edit_tree(&mut entity.root, lod); out.push(entity); From b5d3c8731f98cd03ed62ba10234e63bba4eb4043 Mon Sep 17 00:00:00 2001 From: satoshi komatsu Date: Fri, 20 Dec 2024 17:45:59 +0900 Subject: [PATCH 3/9] Moving the option file --- nusamai/src/lib.rs | 1 - nusamai/src/sink/cesiumtiles/mod.rs | 3 +-- nusamai/src/sink/czml/mod.rs | 3 +-- nusamai/src/sink/geojson/mod.rs | 3 +-- nusamai/src/sink/gltf/mod.rs | 3 +-- nusamai/src/sink/gpkg/mod.rs | 3 +-- nusamai/src/sink/kml/mod.rs | 3 +-- nusamai/src/sink/minecraft/mod.rs | 3 +-- nusamai/src/sink/mvt/mod.rs | 3 +-- nusamai/src/sink/obj/mod.rs | 3 +-- nusamai/src/sink/ply/mod.rs | 3 +-- nusamai/src/sink/shapefile/mod.rs | 3 +-- nusamai/src/transformer/mod.rs | 2 ++ nusamai/src/{ => transformer}/option.rs | 0 14 files changed, 13 insertions(+), 23 deletions(-) rename nusamai/src/{ => transformer}/option.rs (100%) diff --git a/nusamai/src/lib.rs b/nusamai/src/lib.rs index 84d12c45..278e7066 100644 --- a/nusamai/src/lib.rs +++ b/nusamai/src/lib.rs @@ -1,4 +1,3 @@ -pub mod option; pub mod parameters; pub mod pipeline; pub mod sink; diff --git a/nusamai/src/sink/cesiumtiles/mod.rs b/nusamai/src/sink/cesiumtiles/mod.rs index f09bfd86..95120ec1 100644 --- a/nusamai/src/sink/cesiumtiles/mod.rs +++ b/nusamai/src/sink/cesiumtiles/mod.rs @@ -41,11 +41,10 @@ use url::Url; use crate::{ get_parameter_value, - option::use_textured_lod_config, parameters::*, pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, - transformer::TransformerRegistry, + transformer::{use_textured_lod_config, TransformerRegistry}, }; use utils::calculate_normal; diff --git a/nusamai/src/sink/czml/mod.rs b/nusamai/src/sink/czml/mod.rs index ed4a0611..3359f323 100644 --- a/nusamai/src/sink/czml/mod.rs +++ b/nusamai/src/sink/czml/mod.rs @@ -20,11 +20,10 @@ use rayon::prelude::*; use crate::{ get_parameter_value, - option::use_lod_config, parameters::*, pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, - transformer::TransformerRegistry, + transformer::{use_lod_config, TransformerRegistry}, }; use super::option::output_parameter; diff --git a/nusamai/src/sink/geojson/mod.rs b/nusamai/src/sink/geojson/mod.rs index 0962c99d..ddc406f9 100644 --- a/nusamai/src/sink/geojson/mod.rs +++ b/nusamai/src/sink/geojson/mod.rs @@ -20,12 +20,11 @@ use rayon::prelude::*; use crate::{ get_parameter_value, - option::use_lod_config, parameters::*, pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, transformer, - transformer::TransformerRegistry, + transformer::{use_lod_config, TransformerRegistry}, }; use super::option::output_parameter; diff --git a/nusamai/src/sink/gltf/mod.rs b/nusamai/src/sink/gltf/mod.rs index cb353b36..38984451 100644 --- a/nusamai/src/sink/gltf/mod.rs +++ b/nusamai/src/sink/gltf/mod.rs @@ -32,11 +32,10 @@ use url::Url; use crate::{ get_parameter_value, - option::use_textured_lod_config, parameters::*, pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{cesiumtiles::metadata, DataRequirements, DataSink, DataSinkProvider, SinkInfo}, - transformer::TransformerRegistry, + transformer::{use_textured_lod_config, TransformerRegistry}, }; use super::option::{limit_texture_resolution_parameter, output_parameter}; diff --git a/nusamai/src/sink/gpkg/mod.rs b/nusamai/src/sink/gpkg/mod.rs index f8664c54..766238c3 100644 --- a/nusamai/src/sink/gpkg/mod.rs +++ b/nusamai/src/sink/gpkg/mod.rs @@ -21,12 +21,11 @@ use url::Url; use crate::{ get_parameter_value, - option::use_lod_config, parameters::*, pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, transformer, - transformer::TransformerRegistry, + transformer::{use_lod_config, TransformerRegistry}, }; use super::option::output_parameter; diff --git a/nusamai/src/sink/kml/mod.rs b/nusamai/src/sink/kml/mod.rs index 816d3174..53de0355 100644 --- a/nusamai/src/sink/kml/mod.rs +++ b/nusamai/src/sink/kml/mod.rs @@ -20,11 +20,10 @@ use rayon::prelude::*; use crate::{ get_parameter_value, - option::use_lod_config, parameters::*, pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, - transformer::TransformerRegistry, + transformer::{use_lod_config, TransformerRegistry}, }; use super::option::output_parameter; diff --git a/nusamai/src/sink/minecraft/mod.rs b/nusamai/src/sink/minecraft/mod.rs index c3cb6449..47198b75 100644 --- a/nusamai/src/sink/minecraft/mod.rs +++ b/nusamai/src/sink/minecraft/mod.rs @@ -21,12 +21,11 @@ use nusamai_projection::etmerc::ExtendedTransverseMercatorProjection; use crate::{ get_parameter_value, - option::use_lod_config, parameters::*, pipeline::{Feedback, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, transformer, - transformer::TransformerRegistry, + transformer::{use_lod_config, TransformerRegistry}, }; use block_colors::{DefaultBlockResolver, Voxel}; diff --git a/nusamai/src/sink/mvt/mod.rs b/nusamai/src/sink/mvt/mod.rs index 39204da7..2ac95914 100644 --- a/nusamai/src/sink/mvt/mod.rs +++ b/nusamai/src/sink/mvt/mod.rs @@ -27,12 +27,11 @@ use tinymvt::{geometry::GeometryEncoder, tag::TagsEncoder, vector_tile}; use crate::{ get_parameter_value, - option::use_lod_config, parameters::*, pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, transformer, - transformer::TransformerRegistry, + transformer::{use_lod_config, TransformerRegistry}, }; use super::option::output_parameter; diff --git a/nusamai/src/sink/obj/mod.rs b/nusamai/src/sink/obj/mod.rs index e9254e82..9ef384f4 100644 --- a/nusamai/src/sink/obj/mod.rs +++ b/nusamai/src/sink/obj/mod.rs @@ -35,11 +35,10 @@ use nusamai_projection::cartesian::geodetic_to_geocentric; use crate::{ get_parameter_value, - option::use_textured_lod_config, parameters::*, pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, - transformer::TransformerRegistry, + transformer::{use_textured_lod_config, TransformerRegistry}, }; use super::option::{limit_texture_resolution_parameter, output_parameter}; diff --git a/nusamai/src/sink/ply/mod.rs b/nusamai/src/sink/ply/mod.rs index bf3f966e..870bce42 100644 --- a/nusamai/src/sink/ply/mod.rs +++ b/nusamai/src/sink/ply/mod.rs @@ -16,11 +16,10 @@ use rayon::prelude::*; use crate::{ get_parameter_value, - option::use_lod_config, parameters::*, pipeline::{Feedback, PipelineError, Receiver}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, - transformer::TransformerRegistry, + transformer::{use_lod_config, TransformerRegistry}, }; use super::option::output_parameter; diff --git a/nusamai/src/sink/shapefile/mod.rs b/nusamai/src/sink/shapefile/mod.rs index b632035e..e5925dce 100644 --- a/nusamai/src/sink/shapefile/mod.rs +++ b/nusamai/src/sink/shapefile/mod.rs @@ -24,12 +24,11 @@ use rayon::iter::{ParallelBridge, ParallelIterator}; use self::crs::ProjectionRepository; use crate::{ get_parameter_value, - option::use_lod_config, parameters::*, pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, transformer, - transformer::TransformerRegistry, + transformer::{use_lod_config, TransformerRegistry}, }; use super::option::output_parameter; diff --git a/nusamai/src/transformer/mod.rs b/nusamai/src/transformer/mod.rs index 5ba5ac6f..bf970c38 100644 --- a/nusamai/src/transformer/mod.rs +++ b/nusamai/src/transformer/mod.rs @@ -1,6 +1,7 @@ //! The transformer stage that preprocesses the attributes and geometry of the entities. mod builder; +mod option; mod rules; mod runner; mod setting; @@ -9,6 +10,7 @@ pub mod transform; pub use builder::*; use nusamai_citygml::schema::Schema; use nusamai_plateau::Entity; +pub use option::*; pub use rules::*; pub use runner::*; pub use setting::*; diff --git a/nusamai/src/option.rs b/nusamai/src/transformer/option.rs similarity index 100% rename from nusamai/src/option.rs rename to nusamai/src/transformer/option.rs From ea4dd340d4ffc02a9fafd87a2eb2e276188e9dbd Mon Sep 17 00:00:00 2001 From: satoshi komatsu Date: Mon, 23 Dec 2024 14:16:06 +0900 Subject: [PATCH 4/9] Deleting a Clone --- nusamai-plateau/src/entity.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nusamai-plateau/src/entity.rs b/nusamai-plateau/src/entity.rs index cbec2dfe..38198e25 100644 --- a/nusamai-plateau/src/entity.rs +++ b/nusamai-plateau/src/entity.rs @@ -5,7 +5,7 @@ use nusamai_citygml::{geometry::GeometryStore, object::Value}; use crate::appearance::AppearanceStore; /// City objects, features, objects or data -#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)] +#[derive(Debug, serde::Deserialize, serde::Serialize)] pub struct Entity { /// Attribute tree pub root: Value, From 44a823f872a9761a7242a832a7fd77b8c7d62e7e Mon Sep 17 00:00:00 2001 From: satoshi komatsu Date: Mon, 23 Dec 2024 15:39:55 +0900 Subject: [PATCH 5/9] Fix function to generate selections --- nusamai/src/sink/cesiumtiles/mod.rs | 4 +-- nusamai/src/sink/czml/mod.rs | 2 +- nusamai/src/sink/geojson/mod.rs | 2 +- nusamai/src/sink/gltf/mod.rs | 4 +-- nusamai/src/sink/gpkg/mod.rs | 2 +- nusamai/src/sink/kml/mod.rs | 2 +- nusamai/src/sink/minecraft/mod.rs | 2 +- nusamai/src/sink/mvt/mod.rs | 2 +- nusamai/src/sink/obj/mod.rs | 4 +-- nusamai/src/sink/ply/mod.rs | 2 +- nusamai/src/sink/shapefile/mod.rs | 2 +- nusamai/src/transformer/option.rs | 46 +++++++++++++++-------------- nusamai/src/transformer/setting.rs | 46 +++++++++++++++++++++-------- 13 files changed, 72 insertions(+), 48 deletions(-) diff --git a/nusamai/src/sink/cesiumtiles/mod.rs b/nusamai/src/sink/cesiumtiles/mod.rs index 95120ec1..5d29c48e 100644 --- a/nusamai/src/sink/cesiumtiles/mod.rs +++ b/nusamai/src/sink/cesiumtiles/mod.rs @@ -44,7 +44,7 @@ use crate::{ parameters::*, pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, - transformer::{use_textured_lod_config, TransformerRegistry}, + transformer::{use_lod_config, TransformerRegistry}, }; use utils::calculate_normal; @@ -109,7 +109,7 @@ impl DataSinkProvider for CesiumTilesSinkProvider { fn transformer_options(&self) -> TransformerRegistry { let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_textured_lod_config("max_lod")); + settings.insert(use_lod_config("max_lod", None)); settings } diff --git a/nusamai/src/sink/czml/mod.rs b/nusamai/src/sink/czml/mod.rs index 3359f323..dc56dc96 100644 --- a/nusamai/src/sink/czml/mod.rs +++ b/nusamai/src/sink/czml/mod.rs @@ -47,7 +47,7 @@ impl DataSinkProvider for CzmlSinkProvider { fn transformer_options(&self) -> TransformerRegistry { let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_lod_config("max_lod")); + settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); settings } diff --git a/nusamai/src/sink/geojson/mod.rs b/nusamai/src/sink/geojson/mod.rs index ddc406f9..1cc67a33 100644 --- a/nusamai/src/sink/geojson/mod.rs +++ b/nusamai/src/sink/geojson/mod.rs @@ -48,7 +48,7 @@ impl DataSinkProvider for GeoJsonSinkProvider { fn transformer_options(&self) -> TransformerRegistry { let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_lod_config("max_lod")); + settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); settings } diff --git a/nusamai/src/sink/gltf/mod.rs b/nusamai/src/sink/gltf/mod.rs index 38984451..2f04648e 100644 --- a/nusamai/src/sink/gltf/mod.rs +++ b/nusamai/src/sink/gltf/mod.rs @@ -35,7 +35,7 @@ use crate::{ parameters::*, pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{cesiumtiles::metadata, DataRequirements, DataSink, DataSinkProvider, SinkInfo}, - transformer::{use_textured_lod_config, TransformerRegistry}, + transformer::{use_lod_config, TransformerRegistry}, }; use super::option::{limit_texture_resolution_parameter, output_parameter}; @@ -60,7 +60,7 @@ impl DataSinkProvider for GltfSinkProvider { fn transformer_options(&self) -> TransformerRegistry { let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_textured_lod_config("max_lod")); + settings.insert(use_lod_config("max_lod", None)); settings } diff --git a/nusamai/src/sink/gpkg/mod.rs b/nusamai/src/sink/gpkg/mod.rs index 766238c3..e167ee57 100644 --- a/nusamai/src/sink/gpkg/mod.rs +++ b/nusamai/src/sink/gpkg/mod.rs @@ -49,7 +49,7 @@ impl DataSinkProvider for GpkgSinkProvider { fn transformer_options(&self) -> TransformerRegistry { let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_lod_config("max_lod")); + settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); settings } diff --git a/nusamai/src/sink/kml/mod.rs b/nusamai/src/sink/kml/mod.rs index 53de0355..8c8e5c9f 100644 --- a/nusamai/src/sink/kml/mod.rs +++ b/nusamai/src/sink/kml/mod.rs @@ -46,7 +46,7 @@ impl DataSinkProvider for KmlSinkProvider { fn transformer_options(&self) -> TransformerRegistry { let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_lod_config("max_lod")); + settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); settings } diff --git a/nusamai/src/sink/minecraft/mod.rs b/nusamai/src/sink/minecraft/mod.rs index 47198b75..4e648505 100644 --- a/nusamai/src/sink/minecraft/mod.rs +++ b/nusamai/src/sink/minecraft/mod.rs @@ -53,7 +53,7 @@ impl DataSinkProvider for MinecraftSinkProvider { fn transformer_options(&self) -> TransformerRegistry { let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_lod_config("max_lod")); + settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); settings } diff --git a/nusamai/src/sink/mvt/mod.rs b/nusamai/src/sink/mvt/mod.rs index 2ac95914..1741b824 100644 --- a/nusamai/src/sink/mvt/mod.rs +++ b/nusamai/src/sink/mvt/mod.rs @@ -81,7 +81,7 @@ impl DataSinkProvider for MvtSinkProvider { fn transformer_options(&self) -> TransformerRegistry { let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_lod_config("min_lod")); + settings.insert(use_lod_config("min_lod", Some(&["textured_max_lod"]))); settings } diff --git a/nusamai/src/sink/obj/mod.rs b/nusamai/src/sink/obj/mod.rs index 9ef384f4..f7dab019 100644 --- a/nusamai/src/sink/obj/mod.rs +++ b/nusamai/src/sink/obj/mod.rs @@ -38,7 +38,7 @@ use crate::{ parameters::*, pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, - transformer::{use_textured_lod_config, TransformerRegistry}, + transformer::{use_lod_config, TransformerRegistry}, }; use super::option::{limit_texture_resolution_parameter, output_parameter}; @@ -73,7 +73,7 @@ impl DataSinkProvider for ObjSinkProvider { fn transformer_options(&self) -> TransformerRegistry { let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_textured_lod_config("max_lod")); + settings.insert(use_lod_config("max_lod", None)); settings } diff --git a/nusamai/src/sink/ply/mod.rs b/nusamai/src/sink/ply/mod.rs index 870bce42..5ba49813 100644 --- a/nusamai/src/sink/ply/mod.rs +++ b/nusamai/src/sink/ply/mod.rs @@ -56,7 +56,7 @@ impl DataSinkProvider for StanfordPlySinkProvider { fn transformer_options(&self) -> TransformerRegistry { let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_lod_config("max_lod")); + settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); settings } diff --git a/nusamai/src/sink/shapefile/mod.rs b/nusamai/src/sink/shapefile/mod.rs index e5925dce..62e49abc 100644 --- a/nusamai/src/sink/shapefile/mod.rs +++ b/nusamai/src/sink/shapefile/mod.rs @@ -51,7 +51,7 @@ impl DataSinkProvider for ShapefileSinkProvider { fn transformer_options(&self) -> TransformerRegistry { let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_lod_config("max_lod")); + settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); settings } diff --git a/nusamai/src/transformer/option.rs b/nusamai/src/transformer/option.rs index 099004ce..8681a51d 100644 --- a/nusamai/src/transformer/option.rs +++ b/nusamai/src/transformer/option.rs @@ -1,24 +1,26 @@ -use crate::{ - transformer, - transformer::{LodSelection, TransformerConfig}, -}; +// use crate::{ +// transformer, +// transformer::{LodSelection, TransformerConfig}, +// }; -pub fn use_lod_config(default_value: &str) -> TransformerConfig { - TransformerConfig { - key: "use_lod".to_string(), - label: "出力LODの選択".to_string(), - parameter: transformer::ParameterType::Selection( - LodSelection::lod_selection_without_texture(default_value), - ), - } -} +// pub fn use_lod_config(default_value: &str) -> TransformerConfig { +// TransformerConfig { +// key: "use_lod".to_string(), +// label: "出力LODの選択".to_string(), +// parameter: transformer::ParameterType::Selection(LodSelection::create_lod_selection( +// default_value, +// Some(&["textured_max_lod"]), +// )), +// } +// } -pub fn use_textured_lod_config(default_value: &str) -> TransformerConfig { - TransformerConfig { - key: "use_lod".to_string(), - label: "出力LODの選択".to_string(), - parameter: transformer::ParameterType::Selection(LodSelection::lod_selection_with_texture( - default_value, - )), - } -} +// pub fn use_lod_config(default_value: &str) -> TransformerConfig { +// TransformerConfig { +// key: "use_lod".to_string(), +// label: "出力LODの選択".to_string(), +// parameter: transformer::ParameterType::Selection(LodSelection::create_lod_selection( +// default_value, +// None, +// )), +// } +// } diff --git a/nusamai/src/transformer/setting.rs b/nusamai/src/transformer/setting.rs index 9888c490..09911cff 100644 --- a/nusamai/src/transformer/setting.rs +++ b/nusamai/src/transformer/setting.rs @@ -67,29 +67,51 @@ impl Selection { pub struct LodSelection; impl LodSelection { - pub fn get_lod_selection_options() -> Vec<(&'static str, &'static str)> { - vec![ + /// Returns LOD selection options with an optional exclusion list. + pub fn get_lod_selection_options( + exclude: Option<&[&str]>, + ) -> Vec<(&'static str, &'static str)> { + let options = vec![ ("最大LOD", "max_lod"), ("最小LOD", "min_lod"), ("テクスチャ付き最大LOD", "textured_max_lod"), - // This option will be used in 3dtiles sink. ("すべてのLOD", "all_lod"), - ] + ]; + + // If `exclude` is provided, filter out matching options; otherwise, return all. + match exclude { + Some(exclude_list) => options + .into_iter() + .filter(|&(_, value)| !exclude_list.contains(&value)) + .collect(), + None => options, + } } - pub fn lod_selection_with_texture(default_value: &str) -> Selection { - Selection::new(Self::get_lod_selection_options(), default_value) - } + /// Creates a selection with a default value and optional exclusion list. + pub fn create_lod_selection(default_value: &str, exclude: Option<&[&str]>) -> Selection { + let options = Self::get_lod_selection_options(exclude); + + // Ensure the default value exists in the options + if !options.iter().any(|&(_, value)| value == default_value) { + panic!("Default value '{}' must be a valid option", default_value); + } - pub fn lod_selection_without_texture(default_value: &str) -> Selection { - let options = Self::get_lod_selection_options() - .into_iter() - .filter(|&(_, value)| value != "textured_max_lod") - .collect::>(); Selection::new(options, default_value) } } +pub fn use_lod_config(default_value: &str, exclude: Option<&[&str]>) -> TransformerConfig { + TransformerConfig { + key: "use_lod".to_string(), + label: "出力LODの選択".to_string(), + parameter: transformer::ParameterType::Selection(LodSelection::create_lod_selection( + default_value, + exclude, + )), + } +} + #[derive(Debug, Serialize, Deserialize, Clone)] pub enum ParameterType { String(String), From e93a8ce6db183493a968187ed6c040fcbe7441d4 Mon Sep 17 00:00:00 2001 From: satoshi komatsu Date: Mon, 23 Dec 2024 15:42:10 +0900 Subject: [PATCH 6/9] Delete Debug --- nusamai/src/transformer/transform/lods.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nusamai/src/transformer/transform/lods.rs b/nusamai/src/transformer/transform/lods.rs index 38298317..2fff7ee5 100644 --- a/nusamai/src/transformer/transform/lods.rs +++ b/nusamai/src/transformer/transform/lods.rs @@ -139,7 +139,7 @@ fn find_lods(value: &Value) -> LodMask { mask } -#[derive(Default, Clone, Copy, Debug)] +#[derive(Default, Clone, Copy)] pub struct LodMask( u8, // lods bit mask ); From 7bd518070655c327b170192418de8436c4aeeaed Mon Sep 17 00:00:00 2001 From: satoshi komatsu Date: Mon, 23 Dec 2024 16:38:32 +0900 Subject: [PATCH 7/9] Change of name --- app/src-tauri/src/main.rs | 6 +- app/src/lib/transformer.ts | 2 +- app/src/routes/+page.svelte | 4 +- app/src/routes/SettingSelector.svelte | 4 +- nusamai/src/main.rs | 4 +- nusamai/src/sink/cesiumtiles/mod.rs | 10 +-- nusamai/src/sink/czml/mod.rs | 10 +-- nusamai/src/sink/geojson/mod.rs | 10 +-- nusamai/src/sink/gltf/mod.rs | 10 +-- nusamai/src/sink/gpkg/mod.rs | 10 +-- nusamai/src/sink/kml/mod.rs | 10 +-- nusamai/src/sink/minecraft/mod.rs | 10 +-- nusamai/src/sink/mod.rs | 6 +- nusamai/src/sink/mvt/mod.rs | 10 +-- nusamai/src/sink/noop/mod.rs | 8 +- nusamai/src/sink/obj/mod.rs | 10 +-- nusamai/src/sink/ply/mod.rs | 10 +-- nusamai/src/sink/serde/mod.rs | 8 +- nusamai/src/sink/shapefile/mod.rs | 10 +-- nusamai/src/transformer/mod.rs | 6 +- nusamai/src/transformer/option.rs | 26 ------- nusamai/src/transformer/selection.rs | 100 +++++++++++++++++++++++++ nusamai/src/transformer/setting.rs | 104 +------------------------- nusamai/tests/pipeline.rs | 8 +- nusamai/tests/sink.rs | 4 +- 25 files changed, 189 insertions(+), 211 deletions(-) delete mode 100644 nusamai/src/transformer/option.rs create mode 100644 nusamai/src/transformer/selection.rs diff --git a/app/src-tauri/src/main.rs b/app/src-tauri/src/main.rs index c4f7cf0d..9e792e66 100644 --- a/app/src-tauri/src/main.rs +++ b/app/src-tauri/src/main.rs @@ -21,7 +21,7 @@ use nusamai::{ source::{citygml::CityGmlSourceProvider, DataSourceProvider}, transformer::{ self, MappingRules, MultiThreadTransformer, NusamaiTransformBuilder, TransformBuilder, - TransformerRegistry, + TransformerSettings, }, }; use nusamai_plateau::models::TopLevelCityObject; @@ -148,7 +148,7 @@ fn run_conversion( filetype: String, epsg: u16, rules_path: String, - transformer_registry: TransformerRegistry, + transformer_registry: TransformerSettings, sink_parameters: Parameters, tasks_state: tauri::State, app: tauri::AppHandle, @@ -312,7 +312,7 @@ fn cancel_conversion(tasks_state: tauri::State) { /// Get the transform options for a given sink type #[tauri::command] -fn get_transform(filetype: String) -> Result { +fn get_transform(filetype: String) -> Result { let sink_provider = select_sink_provider(&filetype).ok_or_else(|| { let msg = format!("Invalid sink type: {}", filetype); log::error!("{}", msg); diff --git a/app/src/lib/transformer.ts b/app/src/lib/transformer.ts index c734d69c..b20ed474 100644 --- a/app/src/lib/transformer.ts +++ b/app/src/lib/transformer.ts @@ -24,7 +24,7 @@ export interface BooleanConfig { type TransformerParameterType = boolean | SelectionConfig; -export type TransformerRegistry = { +export type TransformerSettings = { configs: Array>; }; diff --git a/app/src/routes/+page.svelte b/app/src/routes/+page.svelte index beb439af..787ffeff 100644 --- a/app/src/routes/+page.svelte +++ b/app/src/routes/+page.svelte @@ -3,7 +3,7 @@ import { invoke } from '@tauri-apps/api/core'; import { attachConsole } from '@tauri-apps/plugin-log'; import type { SinkParameters } from '$lib/sinkparams'; - import type { TransformerRegistry } from '$lib/transformer'; + import type { TransformerSettings } from '$lib/transformer'; import Icon from '@iconify/svelte'; import InputSelector from './InputSelector.svelte'; @@ -23,7 +23,7 @@ let isConvertButtonDisabled = true; $: isConvertButtonDisabled = !inputPaths.length || !outputPath || isRunning; - let transformerRegistry: TransformerRegistry; + let transformerRegistry: TransformerSettings; async function convertAndSave() { isRunning = true; diff --git a/app/src/routes/SettingSelector.svelte b/app/src/routes/SettingSelector.svelte index 2615abf6..84fa0992 100644 --- a/app/src/routes/SettingSelector.svelte +++ b/app/src/routes/SettingSelector.svelte @@ -2,7 +2,7 @@ import { filetypeOptions } from '$lib/settings'; import { invoke } from '@tauri-apps/api/core'; import type { SinkParameters } from '$lib/sinkparams'; - import type { TransformerRegistry } from '$lib/transformer'; + import type { TransformerSettings } from '$lib/transformer'; import Icon from '@iconify/svelte'; import { } from '@tauri-apps/api'; import SinkOptions from '$lib/components/SinkOptions.svelte'; @@ -13,7 +13,7 @@ import * as dialog from "@tauri-apps/plugin-dialog" export let epsg: number = 4979; export let rulesPath: string; export let sinkParameters: SinkParameters; - export let transformerRegistry: TransformerRegistry; + export let transformerRegistry: TransformerSettings; $: epsgOptions = filetypeOptions[filetype]?.epsg || []; $: disableEpsgOptions = epsgOptions.length < 2; diff --git a/nusamai/src/main.rs b/nusamai/src/main.rs index 13ce2715..b7ae58d9 100644 --- a/nusamai/src/main.rs +++ b/nusamai/src/main.rs @@ -13,7 +13,7 @@ use nusamai::{ source::{citygml::CityGmlSourceProvider, DataSource, DataSourceProvider}, transformer::{ self, MappingRules, MultiThreadTransformer, NusamaiTransformBuilder, ParameterType, - TransformBuilder, TransformerConfig, TransformerRegistry, + TransformBuilder, TransformerConfig, TransformerSettings, }, BUILTIN_SINKS, }; @@ -227,7 +227,7 @@ fn main() -> ExitCode { .collect(); let updated_transformer_registry = match update_result { - Ok(configs) => TransformerRegistry { configs }, + Ok(configs) => TransformerSettings { configs }, Err(error_message) => { log::error!("{}", error_message); return ExitCode::FAILURE; diff --git a/nusamai/src/sink/cesiumtiles/mod.rs b/nusamai/src/sink/cesiumtiles/mod.rs index 5d29c48e..048d6cfa 100644 --- a/nusamai/src/sink/cesiumtiles/mod.rs +++ b/nusamai/src/sink/cesiumtiles/mod.rs @@ -44,7 +44,7 @@ use crate::{ parameters::*, pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, - transformer::{use_lod_config, TransformerRegistry}, + transformer::{use_lod_config, TransformerSettings}, }; use utils::calculate_normal; @@ -107,8 +107,8 @@ impl DataSinkProvider for CesiumTilesSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); settings.insert(use_lod_config("max_lod", None)); settings @@ -136,7 +136,7 @@ impl DataSinkProvider for CesiumTilesSinkProvider { struct CesiumTilesSink { output_path: PathBuf, - transform_settings: TransformerRegistry, + transform_settings: TransformerSettings, limit_texture_resolution: Option, gzip_compress: Option, min_z: u8, @@ -144,7 +144,7 @@ struct CesiumTilesSink { } impl DataSink for CesiumTilesSink { - fn make_requirements(&mut self, properties: TransformerRegistry) -> DataRequirements { + fn make_requirements(&mut self, properties: TransformerSettings) -> DataRequirements { let default_requirements = DataRequirements { resolve_appearance: true, key_value: crate::transformer::KeyValueSpec::JsonifyObjects, diff --git a/nusamai/src/sink/czml/mod.rs b/nusamai/src/sink/czml/mod.rs index dc56dc96..365c288a 100644 --- a/nusamai/src/sink/czml/mod.rs +++ b/nusamai/src/sink/czml/mod.rs @@ -23,7 +23,7 @@ use crate::{ parameters::*, pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, - transformer::{use_lod_config, TransformerRegistry}, + transformer::{use_lod_config, TransformerSettings}, }; use super::option::output_parameter; @@ -45,8 +45,8 @@ impl DataSinkProvider for CzmlSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); settings @@ -65,11 +65,11 @@ impl DataSinkProvider for CzmlSinkProvider { pub struct CzmlSink { output_path: PathBuf, - transform_settings: TransformerRegistry, + transform_settings: TransformerSettings, } impl DataSink for CzmlSink { - fn make_requirements(&mut self, properties: TransformerRegistry) -> DataRequirements { + fn make_requirements(&mut self, properties: TransformerSettings) -> DataRequirements { let default_requirements = DataRequirements::default(); for config in properties.configs.iter() { diff --git a/nusamai/src/sink/geojson/mod.rs b/nusamai/src/sink/geojson/mod.rs index 1cc67a33..5007ee68 100644 --- a/nusamai/src/sink/geojson/mod.rs +++ b/nusamai/src/sink/geojson/mod.rs @@ -24,7 +24,7 @@ use crate::{ pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, transformer, - transformer::{use_lod_config, TransformerRegistry}, + transformer::{use_lod_config, TransformerSettings}, }; use super::option::output_parameter; @@ -46,8 +46,8 @@ impl DataSinkProvider for GeoJsonSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); settings @@ -66,11 +66,11 @@ impl DataSinkProvider for GeoJsonSinkProvider { pub struct GeoJsonSink { output_path: PathBuf, - transform_settings: TransformerRegistry, + transform_settings: TransformerSettings, } impl DataSink for GeoJsonSink { - fn make_requirements(&mut self, properties: TransformerRegistry) -> DataRequirements { + fn make_requirements(&mut self, properties: TransformerSettings) -> DataRequirements { let default_requirements = DataRequirements { tree_flattening: transformer::TreeFlatteningSpec::Flatten { feature: transformer::FeatureFlatteningOption::AllExceptThematicSurfaces, diff --git a/nusamai/src/sink/gltf/mod.rs b/nusamai/src/sink/gltf/mod.rs index 2f04648e..228a6f2d 100644 --- a/nusamai/src/sink/gltf/mod.rs +++ b/nusamai/src/sink/gltf/mod.rs @@ -35,7 +35,7 @@ use crate::{ parameters::*, pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{cesiumtiles::metadata, DataRequirements, DataSink, DataSinkProvider, SinkInfo}, - transformer::{use_lod_config, TransformerRegistry}, + transformer::{use_lod_config, TransformerSettings}, }; use super::option::{limit_texture_resolution_parameter, output_parameter}; @@ -58,8 +58,8 @@ impl DataSinkProvider for GltfSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); settings.insert(use_lod_config("max_lod", None)); settings @@ -80,7 +80,7 @@ impl DataSinkProvider for GltfSinkProvider { pub struct GltfSink { output_path: PathBuf, - transform_settings: TransformerRegistry, + transform_settings: TransformerSettings, limit_texture_resolution: Option, } @@ -148,7 +148,7 @@ pub struct PrimitiveInfo { pub type Primitives = HashMap; impl DataSink for GltfSink { - fn make_requirements(&mut self, properties: TransformerRegistry) -> DataRequirements { + fn make_requirements(&mut self, properties: TransformerSettings) -> DataRequirements { let default_requirements: DataRequirements = DataRequirements { resolve_appearance: true, key_value: crate::transformer::KeyValueSpec::JsonifyObjectsAndArrays, diff --git a/nusamai/src/sink/gpkg/mod.rs b/nusamai/src/sink/gpkg/mod.rs index e167ee57..ce7b421c 100644 --- a/nusamai/src/sink/gpkg/mod.rs +++ b/nusamai/src/sink/gpkg/mod.rs @@ -25,7 +25,7 @@ use crate::{ pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, transformer, - transformer::{use_lod_config, TransformerRegistry}, + transformer::{use_lod_config, TransformerSettings}, }; use super::option::output_parameter; @@ -47,8 +47,8 @@ impl DataSinkProvider for GpkgSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); settings @@ -67,7 +67,7 @@ impl DataSinkProvider for GpkgSinkProvider { pub struct GpkgSink { output_path: PathBuf, - transform_settings: TransformerRegistry, + transform_settings: TransformerSettings, } // An ephimeral container to wrap and pass the data in the pipeline @@ -264,7 +264,7 @@ impl GpkgSink { pub enum GpkgTransformOption {} impl DataSink for GpkgSink { - fn make_requirements(&mut self, properties: TransformerRegistry) -> DataRequirements { + fn make_requirements(&mut self, properties: TransformerSettings) -> DataRequirements { let default_requirements = DataRequirements { tree_flattening: transformer::TreeFlatteningSpec::Flatten { feature: transformer::FeatureFlatteningOption::AllExceptThematicSurfaces, diff --git a/nusamai/src/sink/kml/mod.rs b/nusamai/src/sink/kml/mod.rs index 8c8e5c9f..0c56656e 100644 --- a/nusamai/src/sink/kml/mod.rs +++ b/nusamai/src/sink/kml/mod.rs @@ -23,7 +23,7 @@ use crate::{ parameters::*, pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, - transformer::{use_lod_config, TransformerRegistry}, + transformer::{use_lod_config, TransformerSettings}, }; use super::option::output_parameter; @@ -44,8 +44,8 @@ impl DataSinkProvider for KmlSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); settings @@ -64,11 +64,11 @@ impl DataSinkProvider for KmlSinkProvider { pub struct KmlSink { output_path: PathBuf, - transform_settings: TransformerRegistry, + transform_settings: TransformerSettings, } impl DataSink for KmlSink { - fn make_requirements(&mut self, properties: TransformerRegistry) -> DataRequirements { + fn make_requirements(&mut self, properties: TransformerSettings) -> DataRequirements { let default_requirements = DataRequirements::default(); for config in properties.configs.iter() { diff --git a/nusamai/src/sink/minecraft/mod.rs b/nusamai/src/sink/minecraft/mod.rs index 4e648505..15c615ac 100644 --- a/nusamai/src/sink/minecraft/mod.rs +++ b/nusamai/src/sink/minecraft/mod.rs @@ -25,7 +25,7 @@ use crate::{ pipeline::{Feedback, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, transformer, - transformer::{use_lod_config, TransformerRegistry}, + transformer::{use_lod_config, TransformerSettings}, }; use block_colors::{DefaultBlockResolver, Voxel}; @@ -51,8 +51,8 @@ impl DataSinkProvider for MinecraftSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); settings @@ -70,7 +70,7 @@ impl DataSinkProvider for MinecraftSinkProvider { pub struct MinecraftSink { output_path: PathBuf, - transform_settings: TransformerRegistry, + transform_settings: TransformerSettings, } pub struct BoundingVolume { @@ -107,7 +107,7 @@ impl Default for BoundingVolume { } impl DataSink for MinecraftSink { - fn make_requirements(&mut self, properties: TransformerRegistry) -> DataRequirements { + fn make_requirements(&mut self, properties: TransformerSettings) -> DataRequirements { let default_requirements = DataRequirements { tree_flattening: transformer::TreeFlatteningSpec::Flatten { feature: transformer::FeatureFlatteningOption::AllExceptThematicSurfaces, diff --git a/nusamai/src/sink/mod.rs b/nusamai/src/sink/mod.rs index 1061fbfd..c2d91148 100644 --- a/nusamai/src/sink/mod.rs +++ b/nusamai/src/sink/mod.rs @@ -22,7 +22,7 @@ use nusamai_projection::crs; use crate::{ parameters::Parameters, pipeline::{Feedback, PipelineError, Receiver}, - transformer::{self, TransformerRegistry}, + transformer::{self, TransformerSettings}, }; pub struct SinkInfo { @@ -38,7 +38,7 @@ pub trait DataSinkProvider: Sync { fn sink_options(&self) -> Parameters; /// Gets the transform options of the sink. - fn transformer_options(&self) -> TransformerRegistry; + fn transformer_options(&self) -> TransformerSettings; /// Creates a sink instance. fn create(&self, config: &Parameters) -> Box; @@ -54,7 +54,7 @@ pub trait DataSink: Send { ) -> Result<(), PipelineError>; /// Make a transform requirements with options - fn make_requirements(&mut self, property: TransformerRegistry) -> DataRequirements; + fn make_requirements(&mut self, property: TransformerSettings) -> DataRequirements; } pub struct DataRequirements { diff --git a/nusamai/src/sink/mvt/mod.rs b/nusamai/src/sink/mvt/mod.rs index 1741b824..3f494c41 100644 --- a/nusamai/src/sink/mvt/mod.rs +++ b/nusamai/src/sink/mvt/mod.rs @@ -31,7 +31,7 @@ use crate::{ pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, transformer, - transformer::{use_lod_config, TransformerRegistry}, + transformer::{use_lod_config, TransformerSettings}, }; use super::option::output_parameter; @@ -79,8 +79,8 @@ impl DataSinkProvider for MvtSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); settings.insert(use_lod_config("min_lod", Some(&["textured_max_lod"]))); settings @@ -102,7 +102,7 @@ impl DataSinkProvider for MvtSinkProvider { struct MvtSink { output_path: PathBuf, - transform_settings: TransformerRegistry, + transform_settings: TransformerSettings, mvt_options: MvtParams, } @@ -118,7 +118,7 @@ struct SlicedFeature<'a> { } impl DataSink for MvtSink { - fn make_requirements(&mut self, properties: TransformerRegistry) -> DataRequirements { + fn make_requirements(&mut self, properties: TransformerSettings) -> DataRequirements { let default_requirements = DataRequirements { key_value: transformer::KeyValueSpec::DotNotation, lod_filter: transformer::LodFilterSpec { diff --git a/nusamai/src/sink/noop/mod.rs b/nusamai/src/sink/noop/mod.rs index 4859669e..6e39fe77 100644 --- a/nusamai/src/sink/noop/mod.rs +++ b/nusamai/src/sink/noop/mod.rs @@ -10,7 +10,7 @@ use crate::{ }, pipeline::{Feedback, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, - transformer::TransformerRegistry, + transformer::TransformerSettings, }; pub struct NoopSinkProvider {} @@ -56,8 +56,8 @@ impl DataSinkProvider for NoopSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let settings: TransformerRegistry = TransformerRegistry::new(); + fn transformer_options(&self) -> TransformerSettings { + let settings: TransformerSettings = TransformerSettings::new(); settings } @@ -69,7 +69,7 @@ pub struct NoopSink { } impl DataSink for NoopSink { - fn make_requirements(&mut self, _: TransformerRegistry) -> DataRequirements { + fn make_requirements(&mut self, _: TransformerSettings) -> DataRequirements { DataRequirements { ..Default::default() } diff --git a/nusamai/src/sink/obj/mod.rs b/nusamai/src/sink/obj/mod.rs index f7dab019..bd5adf4c 100644 --- a/nusamai/src/sink/obj/mod.rs +++ b/nusamai/src/sink/obj/mod.rs @@ -38,7 +38,7 @@ use crate::{ parameters::*, pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, - transformer::{use_lod_config, TransformerRegistry}, + transformer::{use_lod_config, TransformerSettings}, }; use super::option::{limit_texture_resolution_parameter, output_parameter}; @@ -71,8 +71,8 @@ impl DataSinkProvider for ObjSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); settings.insert(use_lod_config("max_lod", None)); settings @@ -96,7 +96,7 @@ impl DataSinkProvider for ObjSinkProvider { pub struct ObjSink { output_path: PathBuf, - transform_settings: TransformerRegistry, + transform_settings: TransformerSettings, obj_options: ObjParams, limit_texture_resolution: Option, } @@ -176,7 +176,7 @@ pub struct FeatureMaterial { } impl DataSink for ObjSink { - fn make_requirements(&mut self, properties: TransformerRegistry) -> DataRequirements { + fn make_requirements(&mut self, properties: TransformerSettings) -> DataRequirements { let default_requirements: DataRequirements = DataRequirements { resolve_appearance: true, key_value: crate::transformer::KeyValueSpec::JsonifyObjectsAndArrays, diff --git a/nusamai/src/sink/ply/mod.rs b/nusamai/src/sink/ply/mod.rs index 5ba49813..d4064b89 100644 --- a/nusamai/src/sink/ply/mod.rs +++ b/nusamai/src/sink/ply/mod.rs @@ -19,7 +19,7 @@ use crate::{ parameters::*, pipeline::{Feedback, PipelineError, Receiver}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, - transformer::{use_lod_config, TransformerRegistry}, + transformer::{use_lod_config, TransformerSettings}, }; use super::option::output_parameter; @@ -54,8 +54,8 @@ impl DataSinkProvider for StanfordPlySinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); settings @@ -74,11 +74,11 @@ impl DataSinkProvider for StanfordPlySinkProvider { pub struct StanfordPlySink { output_path: PathBuf, - transform_settings: TransformerRegistry, + transform_settings: TransformerSettings, } impl DataSink for StanfordPlySink { - fn make_requirements(&mut self, properties: TransformerRegistry) -> DataRequirements { + fn make_requirements(&mut self, properties: TransformerSettings) -> DataRequirements { let default_requirements = DataRequirements::default(); for config in properties.configs.iter() { diff --git a/nusamai/src/sink/serde/mod.rs b/nusamai/src/sink/serde/mod.rs index 93b3d5ca..4393a82c 100644 --- a/nusamai/src/sink/serde/mod.rs +++ b/nusamai/src/sink/serde/mod.rs @@ -16,7 +16,7 @@ use crate::{ parameters::*, pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, - transformer::TransformerRegistry, + transformer::TransformerSettings, }; use super::option::output_parameter; @@ -38,8 +38,8 @@ impl DataSinkProvider for SerdeSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let settings: TransformerRegistry = TransformerRegistry::new(); + fn transformer_options(&self) -> TransformerSettings { + let settings: TransformerSettings = TransformerSettings::new(); settings } @@ -62,7 +62,7 @@ pub struct SerdeSink { } impl DataSink for SerdeSink { - fn make_requirements(&mut self, _: TransformerRegistry) -> DataRequirements { + fn make_requirements(&mut self, _: TransformerSettings) -> DataRequirements { DataRequirements { ..Default::default() } diff --git a/nusamai/src/sink/shapefile/mod.rs b/nusamai/src/sink/shapefile/mod.rs index 62e49abc..575c98f5 100644 --- a/nusamai/src/sink/shapefile/mod.rs +++ b/nusamai/src/sink/shapefile/mod.rs @@ -28,7 +28,7 @@ use crate::{ pipeline::{Feedback, PipelineError, Receiver, Result}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, transformer, - transformer::{use_lod_config, TransformerRegistry}, + transformer::{use_lod_config, TransformerSettings}, }; use super::option::output_parameter; @@ -49,8 +49,8 @@ impl DataSinkProvider for ShapefileSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); settings @@ -69,11 +69,11 @@ impl DataSinkProvider for ShapefileSinkProvider { pub struct ShapefileSink { output_path: PathBuf, - transform_settings: TransformerRegistry, + transform_settings: TransformerSettings, } impl DataSink for ShapefileSink { - fn make_requirements(&mut self, properties: TransformerRegistry) -> DataRequirements { + fn make_requirements(&mut self, properties: TransformerSettings) -> DataRequirements { let default_requirements = DataRequirements { shorten_names_for_shapefile: true, tree_flattening: transformer::TreeFlatteningSpec::Flatten { diff --git a/nusamai/src/transformer/mod.rs b/nusamai/src/transformer/mod.rs index bf970c38..819dc311 100644 --- a/nusamai/src/transformer/mod.rs +++ b/nusamai/src/transformer/mod.rs @@ -1,18 +1,20 @@ //! The transformer stage that preprocesses the attributes and geometry of the entities. mod builder; -mod option; mod rules; mod runner; +mod selection; mod setting; + pub mod transform; pub use builder::*; use nusamai_citygml::schema::Schema; use nusamai_plateau::Entity; -pub use option::*; pub use rules::*; + pub use runner::*; +pub use selection::*; pub use setting::*; use thiserror::Error; pub use transform::{ diff --git a/nusamai/src/transformer/option.rs b/nusamai/src/transformer/option.rs deleted file mode 100644 index 8681a51d..00000000 --- a/nusamai/src/transformer/option.rs +++ /dev/null @@ -1,26 +0,0 @@ -// use crate::{ -// transformer, -// transformer::{LodSelection, TransformerConfig}, -// }; - -// pub fn use_lod_config(default_value: &str) -> TransformerConfig { -// TransformerConfig { -// key: "use_lod".to_string(), -// label: "出力LODの選択".to_string(), -// parameter: transformer::ParameterType::Selection(LodSelection::create_lod_selection( -// default_value, -// Some(&["textured_max_lod"]), -// )), -// } -// } - -// pub fn use_lod_config(default_value: &str) -> TransformerConfig { -// TransformerConfig { -// key: "use_lod".to_string(), -// label: "出力LODの選択".to_string(), -// parameter: transformer::ParameterType::Selection(LodSelection::create_lod_selection( -// default_value, -// None, -// )), -// } -// } diff --git a/nusamai/src/transformer/selection.rs b/nusamai/src/transformer/selection.rs new file mode 100644 index 00000000..6d0e4519 --- /dev/null +++ b/nusamai/src/transformer/selection.rs @@ -0,0 +1,100 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct SelectionOptions { + pub label: String, + pub value: String, +} + +impl SelectionOptions { + pub fn new(label: &str, value: &str) -> Self { + Self { + label: label.to_string(), + value: value.to_string(), + } + } + + pub fn get_label(&self) -> String { + self.label.clone() + } + + pub fn get_value(&self) -> String { + self.value.clone() + } +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct Selection { + pub options: Vec, + pub selected_value: String, +} + +impl Selection { + pub fn new(options: Vec<(&str, &str)>, selected_value: &str) -> Self { + let options: Vec = options + .into_iter() + .map(|(label, value)| SelectionOptions::new(label, value)) + .collect(); + + let valid_value = options.iter().any(|opt| opt.value == selected_value); + if !valid_value { + panic!("selected_value must be one of the options"); + } + + Self { + options, + selected_value: selected_value.to_string(), + } + } + + pub fn set_selected_value(&mut self, value: &str) -> Result<(), String> { + if self.options.iter().any(|opt| opt.value == value) { + self.selected_value = value.to_string(); + Ok(()) + } else { + Err("Invalid value".to_string()) + } + } + + pub fn get_options(&self) -> Vec { + self.options.clone() + } +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct LodSelection; + +impl LodSelection { + /// Returns LOD selection options with an optional exclusion list. + pub fn get_lod_selection_options( + exclude: Option<&[&str]>, + ) -> Vec<(&'static str, &'static str)> { + let options = vec![ + ("最大LOD", "max_lod"), + ("最小LOD", "min_lod"), + ("テクスチャ付き最大LOD", "textured_max_lod"), + ("すべてのLOD", "all_lod"), + ]; + + // If `exclude` is provided, filter out matching options; otherwise, return all. + match exclude { + Some(exclude_list) => options + .into_iter() + .filter(|&(_, value)| !exclude_list.contains(&value)) + .collect(), + None => options, + } + } + + /// Creates a selection with a default value and optional exclusion list. + pub fn create_lod_selection(default_value: &str, exclude: Option<&[&str]>) -> Selection { + let options = Self::get_lod_selection_options(exclude); + + // Ensure the default value exists in the options + if !options.iter().any(|&(_, value)| value == default_value) { + panic!("Default value '{}' must be a valid option", default_value); + } + + Selection::new(options, default_value) + } +} diff --git a/nusamai/src/transformer/setting.rs b/nusamai/src/transformer/setting.rs index 09911cff..8c8a206c 100644 --- a/nusamai/src/transformer/setting.rs +++ b/nusamai/src/transformer/setting.rs @@ -1,106 +1,8 @@ use serde::{Deserialize, Serialize}; +use crate::transformer::selection::{LodSelection, Selection}; use crate::{sink::DataRequirements, transformer}; -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct SelectionOptions { - pub label: String, - pub value: String, -} - -impl SelectionOptions { - pub fn new(label: &str, value: &str) -> Self { - Self { - label: label.to_string(), - value: value.to_string(), - } - } - - pub fn get_label(&self) -> String { - self.label.clone() - } - - pub fn get_value(&self) -> String { - self.value.clone() - } -} - -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct Selection { - pub options: Vec, - pub selected_value: String, -} - -impl Selection { - pub fn new(options: Vec<(&str, &str)>, selected_value: &str) -> Self { - let options: Vec = options - .into_iter() - .map(|(label, value)| SelectionOptions::new(label, value)) - .collect(); - - let valid_value = options.iter().any(|opt| opt.value == selected_value); - if !valid_value { - panic!("selected_value must be one of the options"); - } - - Self { - options, - selected_value: selected_value.to_string(), - } - } - - pub fn set_selected_value(&mut self, value: &str) -> Result<(), String> { - if self.options.iter().any(|opt| opt.value == value) { - self.selected_value = value.to_string(); - Ok(()) - } else { - Err("Invalid value".to_string()) - } - } - - pub fn get_options(&self) -> Vec { - self.options.clone() - } -} - -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct LodSelection; - -impl LodSelection { - /// Returns LOD selection options with an optional exclusion list. - pub fn get_lod_selection_options( - exclude: Option<&[&str]>, - ) -> Vec<(&'static str, &'static str)> { - let options = vec![ - ("最大LOD", "max_lod"), - ("最小LOD", "min_lod"), - ("テクスチャ付き最大LOD", "textured_max_lod"), - ("すべてのLOD", "all_lod"), - ]; - - // If `exclude` is provided, filter out matching options; otherwise, return all. - match exclude { - Some(exclude_list) => options - .into_iter() - .filter(|&(_, value)| !exclude_list.contains(&value)) - .collect(), - None => options, - } - } - - /// Creates a selection with a default value and optional exclusion list. - pub fn create_lod_selection(default_value: &str, exclude: Option<&[&str]>) -> Selection { - let options = Self::get_lod_selection_options(exclude); - - // Ensure the default value exists in the options - if !options.iter().any(|&(_, value)| value == default_value) { - panic!("Default value '{}' must be a valid option", default_value); - } - - Selection::new(options, default_value) - } -} - pub fn use_lod_config(default_value: &str, exclude: Option<&[&str]>) -> TransformerConfig { TransformerConfig { key: "use_lod".to_string(), @@ -130,11 +32,11 @@ pub struct TransformerConfig { // FIXME: 設計を見直す // FIXME: 意味のある名前に変える #[derive(Debug, Serialize, Deserialize, Clone, Default)] -pub struct TransformerRegistry { +pub struct TransformerSettings { pub configs: Vec, } -impl TransformerRegistry { +impl TransformerSettings { pub fn new() -> Self { Self { configs: vec![] } } diff --git a/nusamai/tests/pipeline.rs b/nusamai/tests/pipeline.rs index d421cf49..b46dff4e 100644 --- a/nusamai/tests/pipeline.rs +++ b/nusamai/tests/pipeline.rs @@ -5,7 +5,7 @@ use nusamai::{ pipeline::{self, Feedback, Parcel, Receiver, Result, Sender}, sink::{DataRequirements, DataSink, DataSinkProvider, SinkInfo}, source::{DataSource, DataSourceProvider, SourceInfo}, - transformer::{Transformer, TransformerRegistry}, + transformer::{Transformer, TransformerSettings}, }; use nusamai_citygml::schema::Schema; use nusamai_plateau::Entity; @@ -94,8 +94,8 @@ impl DataSinkProvider for DummySinkProvider { Parameters::default() } - fn transformer_options(&self) -> TransformerRegistry { - let options: TransformerRegistry = TransformerRegistry::new(); + fn transformer_options(&self) -> TransformerSettings { + let options: TransformerSettings = TransformerSettings::new(); options } } @@ -116,7 +116,7 @@ impl DataSink for DummySink { Ok(()) } - fn make_requirements(&mut self, _: TransformerRegistry) -> DataRequirements { + fn make_requirements(&mut self, _: TransformerSettings) -> DataRequirements { DataRequirements { ..Default::default() } diff --git a/nusamai/tests/sink.rs b/nusamai/tests/sink.rs index 77c0964d..957d49a1 100644 --- a/nusamai/tests/sink.rs +++ b/nusamai/tests/sink.rs @@ -4,7 +4,7 @@ use nusamai::{ sink::{self, DataSinkProvider}, source::{citygml::CityGmlSourceProvider, DataSourceProvider}, transformer::{ - MultiThreadTransformer, NusamaiTransformBuilder, TransformBuilder, TransformerRegistry, + MultiThreadTransformer, NusamaiTransformBuilder, TransformBuilder, TransformerSettings, }, }; use nusamai_citygml::CityGmlElement; @@ -53,7 +53,7 @@ pub(crate) fn simple_run_sink(sink_provider: S, output: Opt sink_provider.create(&sink_params) }; - let options: TransformerRegistry = TransformerRegistry::new(); + let options: TransformerSettings = TransformerSettings::new(); let (transformer, schema) = { let transform_req = sink.make_requirements(options); From ad8c63186a59f3efd718fb046690c903ae3c97d3 Mon Sep 17 00:00:00 2001 From: satoshi komatsu Date: Tue, 24 Dec 2024 16:44:50 +0900 Subject: [PATCH 8/9] Fixing use_lod_config --- nusamai/src/sink/cesiumtiles/mod.rs | 5 ++- nusamai/src/sink/czml/mod.rs | 2 +- nusamai/src/sink/geojson/mod.rs | 2 +- nusamai/src/sink/gltf/mod.rs | 2 +- nusamai/src/sink/gpkg/mod.rs | 2 +- nusamai/src/sink/kml/mod.rs | 2 +- nusamai/src/sink/minecraft/mod.rs | 2 +- nusamai/src/sink/mvt/mod.rs | 2 +- nusamai/src/sink/obj/mod.rs | 2 +- nusamai/src/sink/ply/mod.rs | 2 +- nusamai/src/sink/shapefile/mod.rs | 2 +- nusamai/src/transformer/selection.rs | 46 ++++++++++++++++++---------- 12 files changed, 43 insertions(+), 28 deletions(-) diff --git a/nusamai/src/sink/cesiumtiles/mod.rs b/nusamai/src/sink/cesiumtiles/mod.rs index 048d6cfa..de23bae8 100644 --- a/nusamai/src/sink/cesiumtiles/mod.rs +++ b/nusamai/src/sink/cesiumtiles/mod.rs @@ -109,7 +109,10 @@ impl DataSinkProvider for CesiumTilesSinkProvider { fn transformer_options(&self) -> TransformerSettings { let mut settings: TransformerSettings = TransformerSettings::new(); - settings.insert(use_lod_config("max_lod", None)); + settings.insert(use_lod_config( + "max_lod", + Some(&["textured_max_lod", "all_lod"]), + )); settings } diff --git a/nusamai/src/sink/czml/mod.rs b/nusamai/src/sink/czml/mod.rs index 365c288a..f277fbc1 100644 --- a/nusamai/src/sink/czml/mod.rs +++ b/nusamai/src/sink/czml/mod.rs @@ -47,7 +47,7 @@ impl DataSinkProvider for CzmlSinkProvider { fn transformer_options(&self) -> TransformerSettings { let mut settings: TransformerSettings = TransformerSettings::new(); - settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); + settings.insert(use_lod_config("max_lod", None)); settings } diff --git a/nusamai/src/sink/geojson/mod.rs b/nusamai/src/sink/geojson/mod.rs index 5007ee68..a2eb5fd6 100644 --- a/nusamai/src/sink/geojson/mod.rs +++ b/nusamai/src/sink/geojson/mod.rs @@ -48,7 +48,7 @@ impl DataSinkProvider for GeoJsonSinkProvider { fn transformer_options(&self) -> TransformerSettings { let mut settings: TransformerSettings = TransformerSettings::new(); - settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); + settings.insert(use_lod_config("max_lod", None)); settings } diff --git a/nusamai/src/sink/gltf/mod.rs b/nusamai/src/sink/gltf/mod.rs index 228a6f2d..864e9914 100644 --- a/nusamai/src/sink/gltf/mod.rs +++ b/nusamai/src/sink/gltf/mod.rs @@ -60,7 +60,7 @@ impl DataSinkProvider for GltfSinkProvider { fn transformer_options(&self) -> TransformerSettings { let mut settings: TransformerSettings = TransformerSettings::new(); - settings.insert(use_lod_config("max_lod", None)); + settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); settings } diff --git a/nusamai/src/sink/gpkg/mod.rs b/nusamai/src/sink/gpkg/mod.rs index ce7b421c..7fd51b7a 100644 --- a/nusamai/src/sink/gpkg/mod.rs +++ b/nusamai/src/sink/gpkg/mod.rs @@ -49,7 +49,7 @@ impl DataSinkProvider for GpkgSinkProvider { fn transformer_options(&self) -> TransformerSettings { let mut settings: TransformerSettings = TransformerSettings::new(); - settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); + settings.insert(use_lod_config("max_lod", None)); settings } diff --git a/nusamai/src/sink/kml/mod.rs b/nusamai/src/sink/kml/mod.rs index 0c56656e..75264ab2 100644 --- a/nusamai/src/sink/kml/mod.rs +++ b/nusamai/src/sink/kml/mod.rs @@ -46,7 +46,7 @@ impl DataSinkProvider for KmlSinkProvider { fn transformer_options(&self) -> TransformerSettings { let mut settings: TransformerSettings = TransformerSettings::new(); - settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); + settings.insert(use_lod_config("max_lod", None)); settings } diff --git a/nusamai/src/sink/minecraft/mod.rs b/nusamai/src/sink/minecraft/mod.rs index 15c615ac..87c100d6 100644 --- a/nusamai/src/sink/minecraft/mod.rs +++ b/nusamai/src/sink/minecraft/mod.rs @@ -53,7 +53,7 @@ impl DataSinkProvider for MinecraftSinkProvider { fn transformer_options(&self) -> TransformerSettings { let mut settings: TransformerSettings = TransformerSettings::new(); - settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); + settings.insert(use_lod_config("max_lod", None)); settings } diff --git a/nusamai/src/sink/mvt/mod.rs b/nusamai/src/sink/mvt/mod.rs index 3f494c41..4198a394 100644 --- a/nusamai/src/sink/mvt/mod.rs +++ b/nusamai/src/sink/mvt/mod.rs @@ -81,7 +81,7 @@ impl DataSinkProvider for MvtSinkProvider { fn transformer_options(&self) -> TransformerSettings { let mut settings: TransformerSettings = TransformerSettings::new(); - settings.insert(use_lod_config("min_lod", Some(&["textured_max_lod"]))); + settings.insert(use_lod_config("min_lod", None)); settings } diff --git a/nusamai/src/sink/obj/mod.rs b/nusamai/src/sink/obj/mod.rs index bd5adf4c..b1b1eae6 100644 --- a/nusamai/src/sink/obj/mod.rs +++ b/nusamai/src/sink/obj/mod.rs @@ -73,7 +73,7 @@ impl DataSinkProvider for ObjSinkProvider { fn transformer_options(&self) -> TransformerSettings { let mut settings: TransformerSettings = TransformerSettings::new(); - settings.insert(use_lod_config("max_lod", None)); + settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); settings } diff --git a/nusamai/src/sink/ply/mod.rs b/nusamai/src/sink/ply/mod.rs index d4064b89..f27f31c2 100644 --- a/nusamai/src/sink/ply/mod.rs +++ b/nusamai/src/sink/ply/mod.rs @@ -56,7 +56,7 @@ impl DataSinkProvider for StanfordPlySinkProvider { fn transformer_options(&self) -> TransformerSettings { let mut settings: TransformerSettings = TransformerSettings::new(); - settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); + settings.insert(use_lod_config("max_lod", None)); settings } diff --git a/nusamai/src/sink/shapefile/mod.rs b/nusamai/src/sink/shapefile/mod.rs index 575c98f5..8c792b1a 100644 --- a/nusamai/src/sink/shapefile/mod.rs +++ b/nusamai/src/sink/shapefile/mod.rs @@ -51,7 +51,7 @@ impl DataSinkProvider for ShapefileSinkProvider { fn transformer_options(&self) -> TransformerSettings { let mut settings: TransformerSettings = TransformerSettings::new(); - settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); + settings.insert(use_lod_config("max_lod", None)); settings } diff --git a/nusamai/src/transformer/selection.rs b/nusamai/src/transformer/selection.rs index 6d0e4519..f8346a3a 100644 --- a/nusamai/src/transformer/selection.rs +++ b/nusamai/src/transformer/selection.rs @@ -65,30 +65,42 @@ impl Selection { pub struct LodSelection; impl LodSelection { - /// Returns LOD selection options with an optional exclusion list. - pub fn get_lod_selection_options( - exclude: Option<&[&str]>, - ) -> Vec<(&'static str, &'static str)> { - let options = vec![ - ("最大LOD", "max_lod"), - ("最小LOD", "min_lod"), + /// Returns only the default LOD selection options. + fn get_default_lod_selection_options() -> Vec<(&'static str, &'static str)> { + vec![("最大LOD", "max_lod"), ("最小LOD", "min_lod")] + } + + /// Returns extended options based on the provided keys. + fn get_extended_options(keys: &[&str]) -> Vec<(&'static str, &'static str)> { + let all_extended_options = vec![ ("テクスチャ付き最大LOD", "textured_max_lod"), ("すべてのLOD", "all_lod"), ]; - // If `exclude` is provided, filter out matching options; otherwise, return all. - match exclude { - Some(exclude_list) => options - .into_iter() - .filter(|&(_, value)| !exclude_list.contains(&value)) - .collect(), - None => options, + all_extended_options + .into_iter() + .filter(|(_, value)| keys.contains(value)) + .collect() + } + + /// Returns LOD selection options, optionally including extended options. + fn get_lod_selection_options( + extended_keys: Option<&[&str]>, + ) -> Vec<(&'static str, &'static str)> { + let mut options = Self::get_default_lod_selection_options(); + + // Add the filtered extended options if provided + if let Some(keys) = extended_keys { + let extended_options = Self::get_extended_options(keys); + options.extend(extended_options); } + + options } - /// Creates a selection with a default value and optional exclusion list. - pub fn create_lod_selection(default_value: &str, exclude: Option<&[&str]>) -> Selection { - let options = Self::get_lod_selection_options(exclude); + /// Creates a selection with optional extended options. + pub fn create_lod_selection(default_value: &str, extended_keys: Option<&[&str]>) -> Selection { + let options = Self::get_lod_selection_options(extended_keys); // Ensure the default value exists in the options if !options.iter().any(|&(_, value)| value == default_value) { From 1035c15f003f0ec4785da7a2e223c3e84aee942c Mon Sep 17 00:00:00 2001 From: satoshi komatsu Date: Wed, 25 Dec 2024 16:33:04 +0900 Subject: [PATCH 9/9] Naming correction --- app/src-tauri/src/main.rs | 8 ++++---- nusamai/src/main.rs | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src-tauri/src/main.rs b/app/src-tauri/src/main.rs index 9e792e66..1b403987 100644 --- a/app/src-tauri/src/main.rs +++ b/app/src-tauri/src/main.rs @@ -148,7 +148,7 @@ fn run_conversion( filetype: String, epsg: u16, rules_path: String, - transformer_registry: TransformerSettings, + transformer_settings: TransformerSettings, sink_parameters: Parameters, tasks_state: tauri::State, app: tauri::AppHandle, @@ -206,7 +206,7 @@ fn run_conversion( sink_provider.create(&sink_params) }; - let mut requirements = sink.make_requirements(transformer_registry); + let mut requirements = sink.make_requirements(transformer_settings); requirements.set_output_epsg(epsg); let source = { @@ -319,9 +319,9 @@ fn get_transform(filetype: String) -> Result { Error::InvalidSetting(msg) })?; - let transformer_registry = sink_provider.transformer_options(); + let transformer_settings = sink_provider.transformer_options(); - Ok(transformer_registry) + Ok(transformer_settings) } /// Get the configurable parameters of the sink diff --git a/nusamai/src/main.rs b/nusamai/src/main.rs index b7ae58d9..c4e3554d 100644 --- a/nusamai/src/main.rs +++ b/nusamai/src/main.rs @@ -161,9 +161,9 @@ fn main() -> ExitCode { } let mut sink = sink_provider.create(&sink_params); - let transformer_registry = sink_provider.transformer_options(); + let transformer_settings = sink_provider.transformer_options(); - let valid_keys = transformer_registry.initialize_valid_keys(); + let valid_keys = transformer_settings.initialize_valid_keys(); // Check if the keys specified in args.transformopt are valid for (key, _) in &args.transformopt { @@ -183,7 +183,7 @@ fn main() -> ExitCode { } } - let update_result: Result, String> = transformer_registry + let update_result: Result, String> = transformer_settings .configs .into_iter() .map(|mut config| {