diff --git a/app/src-tauri/src/main.rs b/app/src-tauri/src/main.rs index c4f7cf0d..1b403987 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_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 = { @@ -312,16 +312,16 @@ 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); 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/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-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, 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/main.rs b/nusamai/src/main.rs index 13ce2715..c4e3554d 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, }; @@ -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| { @@ -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/option.rs b/nusamai/src/option.rs deleted file mode 100644 index 099004ce..00000000 --- a/nusamai/src/option.rs +++ /dev/null @@ -1,24 +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::lod_selection_without_texture(default_value), - ), - } -} - -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, - )), - } -} diff --git a/nusamai/src/sink/cesiumtiles/mod.rs b/nusamai/src/sink/cesiumtiles/mod.rs index f09bfd86..de23bae8 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_lod_config, TransformerSettings}, }; use utils::calculate_normal; @@ -108,9 +107,12 @@ impl DataSinkProvider for CesiumTilesSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_textured_lod_config("max_lod")); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); + settings.insert(use_lod_config( + "max_lod", + Some(&["textured_max_lod", "all_lod"]), + )); settings } @@ -137,7 +139,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, @@ -145,7 +147,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 ed4a0611..f277fbc1 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, TransformerSettings}, }; use super::option::output_parameter; @@ -46,9 +45,9 @@ impl DataSinkProvider for CzmlSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_lod_config("max_lod")); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); + settings.insert(use_lod_config("max_lod", None)); settings } @@ -66,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 0962c99d..a2eb5fd6 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, TransformerSettings}, }; use super::option::output_parameter; @@ -47,9 +46,9 @@ impl DataSinkProvider for GeoJsonSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_lod_config("max_lod")); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); + settings.insert(use_lod_config("max_lod", None)); settings } @@ -67,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 cb353b36..864e9914 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_lod_config, TransformerSettings}, }; use super::option::{limit_texture_resolution_parameter, output_parameter}; @@ -59,9 +58,9 @@ impl DataSinkProvider for GltfSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_textured_lod_config("max_lod")); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); + settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); settings } @@ -81,7 +80,7 @@ impl DataSinkProvider for GltfSinkProvider { pub struct GltfSink { output_path: PathBuf, - transform_settings: TransformerRegistry, + transform_settings: TransformerSettings, limit_texture_resolution: Option, } @@ -149,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 f8664c54..7fd51b7a 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, TransformerSettings}, }; use super::option::output_parameter; @@ -48,9 +47,9 @@ impl DataSinkProvider for GpkgSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_lod_config("max_lod")); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); + settings.insert(use_lod_config("max_lod", None)); settings } @@ -68,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 @@ -265,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 816d3174..75264ab2 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, TransformerSettings}, }; use super::option::output_parameter; @@ -45,9 +44,9 @@ impl DataSinkProvider for KmlSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_lod_config("max_lod")); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); + settings.insert(use_lod_config("max_lod", None)); settings } @@ -65,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 c3cb6449..87c100d6 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, TransformerSettings}, }; use block_colors::{DefaultBlockResolver, Voxel}; @@ -52,9 +51,9 @@ impl DataSinkProvider for MinecraftSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_lod_config("max_lod")); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); + settings.insert(use_lod_config("max_lod", None)); settings } @@ -71,7 +70,7 @@ impl DataSinkProvider for MinecraftSinkProvider { pub struct MinecraftSink { output_path: PathBuf, - transform_settings: TransformerRegistry, + transform_settings: TransformerSettings, } pub struct BoundingVolume { @@ -108,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 39204da7..4198a394 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, TransformerSettings}, }; use super::option::output_parameter; @@ -80,9 +79,9 @@ impl DataSinkProvider for MvtSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_lod_config("min_lod")); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); + settings.insert(use_lod_config("min_lod", None)); settings } @@ -103,7 +102,7 @@ impl DataSinkProvider for MvtSinkProvider { struct MvtSink { output_path: PathBuf, - transform_settings: TransformerRegistry, + transform_settings: TransformerSettings, mvt_options: MvtParams, } @@ -119,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 e9254e82..b1b1eae6 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_lod_config, TransformerSettings}, }; use super::option::{limit_texture_resolution_parameter, output_parameter}; @@ -72,9 +71,9 @@ impl DataSinkProvider for ObjSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_textured_lod_config("max_lod")); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); + settings.insert(use_lod_config("max_lod", Some(&["textured_max_lod"]))); settings } @@ -97,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, } @@ -177,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 bf3f966e..f27f31c2 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, TransformerSettings}, }; use super::option::output_parameter; @@ -55,9 +54,9 @@ impl DataSinkProvider for StanfordPlySinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_lod_config("max_lod")); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); + settings.insert(use_lod_config("max_lod", None)); settings } @@ -75,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 b632035e..8c792b1a 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, TransformerSettings}, }; use super::option::output_parameter; @@ -50,9 +49,9 @@ impl DataSinkProvider for ShapefileSinkProvider { params } - fn transformer_options(&self) -> TransformerRegistry { - let mut settings: TransformerRegistry = TransformerRegistry::new(); - settings.insert(use_lod_config("max_lod")); + fn transformer_options(&self) -> TransformerSettings { + let mut settings: TransformerSettings = TransformerSettings::new(); + settings.insert(use_lod_config("max_lod", None)); settings } @@ -70,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 5ba5ac6f..819dc311 100644 --- a/nusamai/src/transformer/mod.rs +++ b/nusamai/src/transformer/mod.rs @@ -3,14 +3,18 @@ mod builder; 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 rules::*; + pub use runner::*; +pub use selection::*; pub use setting::*; use thiserror::Error; pub use transform::{ diff --git a/nusamai/src/transformer/selection.rs b/nusamai/src/transformer/selection.rs new file mode 100644 index 00000000..f8346a3a --- /dev/null +++ b/nusamai/src/transformer/selection.rs @@ -0,0 +1,112 @@ +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 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"), + ]; + + 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 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) { + 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 9888c490..8c8a206c 100644 --- a/nusamai/src/transformer/setting.rs +++ b/nusamai/src/transformer/setting.rs @@ -1,92 +1,16 @@ 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 { - pub fn get_lod_selection_options() -> Vec<(&'static str, &'static str)> { - vec![ - ("最大LOD", "max_lod"), - ("最小LOD", "min_lod"), - ("テクスチャ付き最大LOD", "textured_max_lod"), - // This option will be used in 3dtiles sink. - ("すべてのLOD", "all_lod"), - ] - } - - pub fn lod_selection_with_texture(default_value: &str) -> Selection { - Selection::new(Self::get_lod_selection_options(), 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, + )), } } @@ -108,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/src/transformer/transform/lods.rs b/nusamai/src/transformer/transform/lods.rs index 9d226cd4..2fff7ee5 100644 --- a/nusamai/src/transformer/transform/lods.rs +++ b/nusamai/src/transformer/transform/lods.rs @@ -31,15 +31,16 @@ 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; 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); @@ -49,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; @@ -56,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); @@ -135,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 ); 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);