Skip to content

Commit

Permalink
フラット化transformerのオプション指定を再構成 (#284)
Browse files Browse the repository at this point in the history
#283 の一部

- TreeFlattening transformerのオプションを再構成しました
- (合わせて、前の実装だと `All`, `AllExceptThematicSurfaces`
で同じ動作になってしまっていたところが直りました)

***

- feature, data, object と3種類に対して、それぞれフラット化のオプションを指定したい
  - featureはall, dataはnone, objectはallなど
  - 直交で選択肢が増える
  - `AllFeaturesExceptThematicSurfacesAndAllData` などとしたくない
  - enumをネストさせてみました
- flatteningのオプションが定義される場所
  - `flatten.rs`
  - これが、 `builder.rs` から再度外へ提示される
  - なので、sinkから使えるようになる

***

- 実際の、Data, Objectのflattening処理は、この次のPRで行う予定です
- その前にまずは、この構成・方向性について、みていただけますでしょうか!

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit


- **新機能**
    - ツリーの平坦化オプションを特定し、柔軟なデータ変換を実現
    - 異なる平坦化オプションに関する新しい列挙型を導入しました

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Taku Fukada <[email protected]>
  • Loading branch information
sorami and ciscorn authored Feb 20, 2024
1 parent f79f65f commit c394d44
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 35 deletions.
6 changes: 6 additions & 0 deletions nusamai/src/sink/gpkg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ impl GpkgSink {
impl DataSink for GpkgSink {
fn make_transform_requirements(&self) -> transformer::Requirements {
transformer::Requirements {
tree_flattening: transformer::TreeFlatteningSpec::Flatten {
// TODO: set properly after the flattening transformer is implemented
feature: transformer::FeatureFlatteningOption::None,
data: transformer::DataFlatteningOption::None,
object: transformer::ObjectFlatteningOption::None,
},
..Default::default()
}
}
Expand Down
25 changes: 15 additions & 10 deletions nusamai/src/transformer/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ impl From<Requirements> for Request {
}

pub enum TreeFlatteningSpec {
/// No feature flattening
/// No flattening at all
None,
/// Flatten all features except thematic surfaces
AllExceptThematicSurfaces,
/// Flatten all features
All,
// Flatten with the given options
Flatten {
feature: FeatureFlatteningOption,
data: DataFlatteningOption,
object: ObjectFlatteningOption,
},
}

pub enum MergedownSpec {
Expand Down Expand Up @@ -112,11 +114,14 @@ impl TransformBuilder for NusamaiTransformBuilder {

match self.request.tree_flattening {
TreeFlatteningSpec::None => {}
TreeFlatteningSpec::AllExceptThematicSurfaces => {
transforms.push(Box::new(FlattenTreeTransform::new()));
}
TreeFlatteningSpec::All => {
transforms.push(Box::new(FlattenTreeTransform::new()));
TreeFlatteningSpec::Flatten {
feature,
data,
object,
} => {
transforms.push(Box::new(FlattenTreeTransform::with_options(
feature, data, object,
)));
}
}

Expand Down
3 changes: 3 additions & 0 deletions nusamai/src/transformer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ pub mod transform;

pub use builder::*;
pub use runner::*;
pub use transform::{
DataFlatteningOption, FeatureFlatteningOption, ObjectFlatteningOption,
};

use crate::pipeline::{Feedback, Parcel, Receiver, Result, Sender};

Expand Down
102 changes: 78 additions & 24 deletions nusamai/src/transformer/transform/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,83 @@ use nusamai_citygml::GeometryStore;
use nusamai_plateau::appearance::AppearanceStore;
use nusamai_plateau::Entity;

#[derive(Default)]
pub struct FlattenTreeTransform {
split_thematic_surfaces: bool,
split_data_stereotype: bool,
split_object_stereotype: bool,
feature: FeatureFlatteningOption,
data: DataFlatteningOption,
object: ObjectFlatteningOption,
}

/// Flattening option for the "feature" stereotype
// TODO: Use this to implement flattening process
#[derive(Debug, Copy, Clone)]
pub enum FeatureFlatteningOption {
/// No feature flattening
None,
/// Flatten all features except thematic surfaces
AllExceptThematicSurfaces,
/// Flatten all features
All,
}

/// Flattening option for the "data" stereotype
// TODO: Use this to implement flattening process
#[derive(Debug, Copy, Clone)]
pub enum DataFlatteningOption {
/// No data flattening
None,
/// Flatten top-level data (i.e., data that is not a child of another data)
TopLevelOnly,
/// Flatten all data
All,
}

/// Flattening option for the "object" stereotype
// TODO: Use this to implement flattening process
#[derive(Debug, Copy, Clone)]
pub enum ObjectFlatteningOption {
/// No object flattening
None,
/// Flatten all objects
All,
}

impl Default for FlattenTreeTransform {
fn default() -> Self {
Self {
feature: FeatureFlatteningOption::None,
data: DataFlatteningOption::None,
object: ObjectFlatteningOption::None,
}
}
}

impl FlattenTreeTransform {
pub fn with_split_thematic_surfaces(mut self, split: bool) -> Self {
self.split_thematic_surfaces = split;
self
pub fn new() -> Self {
Default::default()
}

pub fn with_options(
feature: FeatureFlatteningOption,
data: DataFlatteningOption,
object: ObjectFlatteningOption,
) -> Self {
Self {
feature,
data,
object,
}
}

pub fn set_feature_option(&mut self, option: FeatureFlatteningOption) {
self.feature = option;
}

pub fn with_split_data_stereotype(mut self, split: bool) -> Self {
self.split_data_stereotype = split;
self
pub fn set_data_option(&mut self, option: DataFlatteningOption) {
self.data = option;
}

pub fn with_split_object_stereotype(mut self, split: bool) -> Self {
self.split_object_stereotype = split;
self
pub fn set_object_option(&mut self, option: ObjectFlatteningOption) {
self.object = option;
}
}

Expand Down Expand Up @@ -69,10 +125,6 @@ struct Parent {
}

impl FlattenTreeTransform {
pub fn new() -> Self {
Default::default()
}

fn flatten_feature(
&self,
value: Value,
Expand Down Expand Up @@ -143,13 +195,15 @@ impl FlattenTreeTransform {

fn is_split_target(&self, obj: &Object) -> bool {
if let ObjectStereotype::Feature { .. } = &obj.stereotype {
if self.split_thematic_surfaces {
true
} else {
!obj.typename.ends_with("Surface")
&& !obj.typename.ends_with(":Window")
&& !obj.typename.ends_with(":Door")
&& !obj.typename.ends_with("TrafficArea")
match self.feature {
FeatureFlatteningOption::None => false,
FeatureFlatteningOption::All => true,
FeatureFlatteningOption::AllExceptThematicSurfaces => {
!obj.typename.ends_with("Surface")
&& !obj.typename.ends_with(":Window")
&& !obj.typename.ends_with(":Door")
&& !obj.typename.ends_with("TrafficArea")
}
}
} else {
false
Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/transformer/transform/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod appearance;
mod attrname;
mod dots;
mod flatten;
pub mod flatten;
mod geommerge;
mod jsonify;
mod lods;
Expand Down

0 comments on commit c394d44

Please sign in to comment.