Skip to content

Commit

Permalink
feat(engine): add transform_offset method to geometry types and updat…
Browse files Browse the repository at this point in the history
…e example workflow (#661)
  • Loading branch information
miseyu authored Nov 28, 2024
1 parent b6f3c6a commit 0e9fb17
Show file tree
Hide file tree
Showing 29 changed files with 571 additions and 21 deletions.
12 changes: 6 additions & 6 deletions engine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ reearth-flow-storage = { path = "runtime/storage" }
reearth-flow-telemetry = { path = "runtime/telemetry" }
reearth-flow-types = { path = "runtime/types" }

nusamai-citygml = { git = "https://github.com/reearth/plateau-gis-converter", tag = "v0.5.2", features = ["serde", "serde_json"] }
nusamai-gltf = { git = "https://github.com/reearth/plateau-gis-converter", tag = "v0.5.2" }
nusamai-plateau = { git = "https://github.com/reearth/plateau-gis-converter", tag = "v0.5.2", features = ["serde"] }
nusamai-projection = { git = "https://github.com/reearth/plateau-gis-converter", tag = "v0.5.2" }
nusamai-citygml = { git = "https://github.com/reearth/plateau-gis-converter", tag = "v0.6.0", features = ["serde", "serde_json"] }
nusamai-gltf = { git = "https://github.com/reearth/plateau-gis-converter", tag = "v0.6.0" }
nusamai-plateau = { git = "https://github.com/reearth/plateau-gis-converter", tag = "v0.6.0", features = ["serde"] }
nusamai-projection = { git = "https://github.com/reearth/plateau-gis-converter", tag = "v0.6.0" }

Inflector = "0.11.4"
ahash = "0.8.11"
Expand Down
75 changes: 75 additions & 0 deletions engine/docs/mdbook/src/action.md
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,38 @@ Transforms features by expressions
### Category
* Feature

## FeatureTypeFilter
### Type
* processor
### Description
Filters features by feature type
### Parameters
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "FeatureTypeFilter",
"type": "object",
"required": [
"targetTypes"
],
"properties": {
"targetTypes": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
```
### Input Ports
* default
### Output Ports
* default
* unfiltered
### Category
* Feature

## FilePathExtractor
### Type
* source
Expand Down Expand Up @@ -2142,6 +2174,49 @@ noop sink
### Category
* Noop

## Offsetter
### Type
* processor
### Description
Adds offsets to the feature's coordinates.
### Parameters
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "OffsetterParam",
"type": "object",
"properties": {
"offsetX": {
"type": [
"number",
"null"
],
"format": "double"
},
"offsetY": {
"type": [
"number",
"null"
],
"format": "double"
},
"offsetZ": {
"type": [
"number",
"null"
],
"format": "double"
}
}
}
```
### Input Ports
* default
### Output Ports
* default
### Category
* Geometry

## OrientationExtractor
### Type
* processor
Expand Down
1 change: 1 addition & 0 deletions engine/runtime/action-processor/src/feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pub(crate) mod reader;
pub(crate) mod rhai;
pub(crate) mod sorter;
pub(crate) mod transformer;
pub(crate) mod type_filter;
2 changes: 2 additions & 0 deletions engine/runtime/action-processor/src/feature/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use super::{
counter::FeatureCounterFactory, filter::FeatureFilterFactory,
list_exploder::ListExploderFactory, merger::FeatureMergerFactory, reader::FeatureReaderFactory,
rhai::RhaiCallerFactory, sorter::FeatureSorterFactory, transformer::FeatureTransformerFactory,
type_filter::FeatureTypeFilterFactory,
};

pub static ACTION_FACTORY_MAPPINGS: Lazy<HashMap<String, NodeKind>> = Lazy::new(|| {
Expand All @@ -19,6 +20,7 @@ pub static ACTION_FACTORY_MAPPINGS: Lazy<HashMap<String, NodeKind>> = Lazy::new(
Box::<FeatureReaderFactory>::default(),
Box::<RhaiCallerFactory>::default(),
Box::<ListExploderFactory>::default(),
Box::<FeatureTypeFilterFactory>::default(),
];
factories
.into_iter()
Expand Down
113 changes: 113 additions & 0 deletions engine/runtime/action-processor/src/feature/type_filter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
use std::collections::HashMap;

use once_cell::sync::Lazy;
use reearth_flow_runtime::{
channels::ProcessorChannelForwarder,
errors::BoxedError,
event::EventHub,
executor_operation::{ExecutorContext, NodeContext},
node::{Port, Processor, ProcessorFactory, DEFAULT_PORT},
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::Value;

use super::errors::FeatureProcessorError;

pub static UNFILTERED_PORT: Lazy<Port> = Lazy::new(|| Port::new("unfiltered"));

#[derive(Debug, Clone, Default)]
pub struct FeatureTypeFilterFactory;

impl ProcessorFactory for FeatureTypeFilterFactory {
fn name(&self) -> &str {
"FeatureTypeFilter"
}

fn description(&self) -> &str {
"Filters features by feature type"
}

fn parameter_schema(&self) -> Option<schemars::schema::RootSchema> {
Some(schemars::schema_for!(FeatureTypeFilter))
}

fn categories(&self) -> &[&'static str] {
&["Feature"]
}

fn get_input_ports(&self) -> Vec<Port> {
vec![DEFAULT_PORT.clone()]
}

fn get_output_ports(&self) -> Vec<Port> {
vec![DEFAULT_PORT.clone(), UNFILTERED_PORT.clone()]
}

fn build(
&self,
_ctx: NodeContext,
_event_hub: EventHub,
_action: String,
with: Option<HashMap<String, Value>>,
) -> Result<Box<dyn Processor>, BoxedError> {
let process: FeatureTypeFilter = if let Some(with) = with {
let value: Value = serde_json::to_value(with).map_err(|e| {
FeatureProcessorError::TransformerFactory(format!(
"Failed to serialize `with` parameter: {}",
e
))
})?;
serde_json::from_value(value).map_err(|e| {
FeatureProcessorError::TransformerFactory(format!(
"Failed to deserialize `with` parameter: {}",
e
))
})?
} else {
return Err(FeatureProcessorError::TransformerFactory(
"Missing required parameter `with`".to_string(),
)
.into());
};
Ok(Box::new(process))
}
}

#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct FeatureTypeFilter {
target_types: Vec<String>,
}

impl Processor for FeatureTypeFilter {
fn process(
&mut self,
ctx: ExecutorContext,
fw: &mut dyn ProcessorChannelForwarder,
) -> Result<(), BoxedError> {
let feature = &ctx.feature;
let Some(feature_type) = feature.feature_type() else {
fw.send(ctx.new_with_feature_and_port(feature.clone(), UNFILTERED_PORT.clone()));
return Ok(());
};
if self.target_types.contains(&feature_type) {
fw.send(ctx.new_with_feature_and_port(feature.clone(), DEFAULT_PORT.clone()));
} else {
fw.send(ctx.new_with_feature_and_port(feature.clone(), UNFILTERED_PORT.clone()));
}
Ok(())
}

fn finish(
&self,
_ctx: NodeContext,
_fw: &mut dyn ProcessorChannelForwarder,
) -> Result<(), BoxedError> {
Ok(())
}

fn name(&self) -> &str {
"FeatureTypeFilter"
}
}
1 change: 1 addition & 0 deletions engine/runtime/action-processor/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub(crate) mod horizontal_reprojector;
pub(crate) mod line_on_line_overlayer;
pub(crate) mod lod_filter;
pub(crate) mod mapping;
pub(crate) mod offsetter;
pub(crate) mod orientation_extractor;
pub(crate) mod planarity_filter;
pub(crate) mod refiner;
Expand Down
4 changes: 4 additions & 0 deletions engine/runtime/action-processor/src/geometry/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ pub(super) enum GeometryProcessorError {
GeometryLodFilterFactory(String),
#[error("GeometryLodFilter error: {0}")]
GeometryLodFilter(String),
#[error("Offsetter Factory error: {0}")]
OffsetterFactory(String),
#[error("Offsetter error: {0}")]
Offsetter(String),
}

pub(super) type Result<T, E = GeometryProcessorError> = std::result::Result<T, E>;
6 changes: 4 additions & 2 deletions engine/runtime/action-processor/src/geometry/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ use super::{
extruder::ExtruderFactory, filter::GeometryFilterFactory, hole_counter::HoleCounterFactory,
hole_extractor::HoleExtractorFactory, horizontal_reprojector::HorizontalReprojectorFactory,
line_on_line_overlayer::LineOnLineOverlayerFactory, lod_filter::GeometryLodFilterFactory,
orientation_extractor::OrientationExtractorFactory, planarity_filter::PlanarityFilterFactory,
refiner::RefinerFactory, replacer::GeometryReplacerFactory, splitter::GeometrySplitterFactory,
offsetter::OffsetterFactory, orientation_extractor::OrientationExtractorFactory,
planarity_filter::PlanarityFilterFactory, refiner::RefinerFactory,
replacer::GeometryReplacerFactory, splitter::GeometrySplitterFactory,
three_dimension_box_replacer::ThreeDimensionBoxReplacerFactory,
three_dimension_rotator::ThreeDimensionRotatorFactory,
two_dimension_forcer::TwoDimensionForcerFactory, validator::GeometryValidatorFactory,
Expand Down Expand Up @@ -58,6 +59,7 @@ pub static ACTION_FACTORY_MAPPINGS: Lazy<HashMap<String, NodeKind>> = Lazy::new(
Box::<DimensionFilterFactory>::default(),
Box::<CityGmlGeometryLodFilterFactory>::default(),
Box::<GeometryLodFilterFactory>::default(),
Box::<OffsetterFactory>::default(),
];
factories
.into_iter()
Expand Down
Loading

0 comments on commit 0e9fb17

Please sign in to comment.