Skip to content

Commit

Permalink
chore(worker): Update orientation extractor processor (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
miseyu authored Sep 12, 2024
1 parent 97cdf93 commit 7ceef33
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 57 deletions.
108 changes: 56 additions & 52 deletions worker/crates/action-processor/src/geometry/orientation_extractor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{HashMap, HashSet};
use std::collections::HashMap;

use reearth_flow_geometry::algorithm::winding_order::Winding;
use reearth_flow_geometry::types::geometry::Geometry3D;
Expand Down Expand Up @@ -125,45 +125,42 @@ impl Processor for OrientationExtractor {
);
fw.send(ctx.new_with_feature_and_port(feature, DEFAULT_PORT.clone()));
}
GeometryValue::FlowGeometry2D(geometry) => {
match geometry {
Geometry2D::Polygon(polygon) => {
let mut feature = feature.clone();
let ring_winding_orders = polygon
.rings()
.iter()
.map(|ring| ring.winding_order())
.collect::<Vec<_>>();
let result = detect_orientation_by_ring_winding_orders(ring_winding_orders);
feature.attributes.insert(
self.output_attribute.clone(),
AttributeValue::String(result.to_string()),
);
fw.send(ctx.new_with_feature_and_port(feature, DEFAULT_PORT.clone()));
}
Geometry2D::MultiPolygon(polygons) => {
let mut feature = feature.clone();
let ring_winding_orders = polygons
.iter()
.flat_map(|polygon| {
polygon
.rings()
.iter()
.map(|ring| ring.winding_order())
.collect::<Vec<_>>()
})
.collect::<Vec<_>>();
let result = detect_orientation_by_ring_winding_orders(ring_winding_orders);
feature.attributes.insert(
self.output_attribute.clone(),
AttributeValue::String(result.to_string()),
);
fw.send(ctx.new_with_feature_and_port(feature, DEFAULT_PORT.clone()));
}
_ => unimplemented!(),
GeometryValue::FlowGeometry2D(geometry) => match geometry {
Geometry2D::Polygon(polygon) => {
let mut feature = feature.clone();
let ring_winding_orders = polygon
.rings()
.iter()
.map(|ring| ring.winding_order())
.collect::<Vec<_>>();
let result = detect_orientation_by_ring_winding_orders(ring_winding_orders);
feature.attributes.insert(
self.output_attribute.clone(),
AttributeValue::String(result.to_string()),
);
fw.send(ctx.new_with_feature_and_port(feature, DEFAULT_PORT.clone()));
}
fw.send(ctx.new_with_feature_and_port(feature.clone(), DEFAULT_PORT.clone()));
}
Geometry2D::MultiPolygon(polygons) => {
let mut feature = feature.clone();
let ring_winding_orders = polygons
.iter()
.flat_map(|polygon| {
polygon
.rings()
.iter()
.map(|ring| ring.winding_order())
.collect::<Vec<_>>()
})
.collect::<Vec<_>>();
let result = detect_orientation_by_ring_winding_orders(ring_winding_orders);
feature.attributes.insert(
self.output_attribute.clone(),
AttributeValue::String(result.to_string()),
);
fw.send(ctx.new_with_feature_and_port(feature, DEFAULT_PORT.clone()));
}
_ => unimplemented!(),
},
GeometryValue::FlowGeometry3D(geometry) => match geometry {
Geometry3D::Polygon(polygon) => {
let mut feature = feature.clone();
Expand Down Expand Up @@ -221,22 +218,29 @@ impl Processor for OrientationExtractor {
fn detect_orientation_by_ring_winding_orders(
ring_winding_orders: Vec<Option<WindingOrder>>,
) -> WindingOrderResult {
if ring_winding_orders
if ring_winding_orders.is_empty() {
return NO_ORIENTATION;
}
if !ring_winding_orders
.iter()
.all(|winding_order| winding_order.is_some())
{
let set: HashSet<_> = ring_winding_orders.iter().cloned().collect();
if set.len() == 1 {
let winding_order = ring_winding_orders[0].unwrap();
match winding_order {
WindingOrder::Clockwise => CLOCKWISE_ORIENTATION,
WindingOrder::CounterClockwise => COUNTER_CLOCKWISE_ORIENTATION,
WindingOrder::None => NO_ORIENTATION,
}
} else {
INVALID_ORIENTATION
return INVALID_ORIENTATION;
}
let ring_winding_orders = ring_winding_orders.iter().flatten().collect::<Vec<_>>();
for ring_winding_order in ring_winding_orders.iter() {
let orientation = match ring_winding_order {
WindingOrder::Clockwise => CLOCKWISE_ORIENTATION,
WindingOrder::CounterClockwise => COUNTER_CLOCKWISE_ORIENTATION,
WindingOrder::None => NO_ORIENTATION,
};
if orientation == NO_ORIENTATION {
return orientation;
}
} else {
INVALID_ORIENTATION
}
match ring_winding_orders.first().unwrap() {
WindingOrder::Clockwise => CLOCKWISE_ORIENTATION,
WindingOrder::CounterClockwise => COUNTER_CLOCKWISE_ORIENTATION,
WindingOrder::None => NO_ORIENTATION,
}
}
1 change: 1 addition & 0 deletions worker/crates/action-processor/src/geometry/replacer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ impl Processor for GeometryReplacer {
let decoded = base64_decode(dump)?;
let geometry: Geometry = serde_json::from_str(&decoded)?;
feature.geometry = Some(geometry);
feature.attributes.remove(&self.source_attribute);
fw.send(ctx.new_with_feature_and_port(feature, DEFAULT_PORT.clone()));
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion worker/examples/plateau/example_feature_transformer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod helper;

fn main() {
helper::execute("quality-check/02-bldg/c_bldg_01.yml");
helper::execute("quality-check/02-bldg/workflow.yml");
}
73 changes: 73 additions & 0 deletions worker/examples/plateau/testdata/graphs/surface_validator_2d.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,82 @@ nodes:
with:
routingPort: default

- id: 8a1e6f15-67c6-45ae-a1dc-8e4ae3217574
name: GeometryExtractor
type: action
action: GeometryExtractor
with:
outputAttribute: dumpGeometry

- id: 923a0c9f-ab74-4935-819d-fe254d0cfc12
name: TwoDimensionForcer
type: action
action: TwoDimensionForcer

- id: 0361e205-4d43-442d-b004-2ea981dbca84
name: OrientationExtractor
type: action
action: OrientationExtractor
with:
outputAttribute: outerOrientation

- id: 27cd7ebf-7d16-4a1c-ac27-02eddb61a7b9
name: FeatureFilterByOrientation
type: action
action: FeatureFilter
with:
conditions:
- expr: |
env.get("__value").outerOrientation != "clockwise"
outputPort: inCorrectOrientation
- id: 6a005159-a30d-4a30-8cca-ebea4e89c351
name: GeometryReplacer
type: action
action: GeometryReplacer
with:
sourceAttribute: dumpGeometry

- id: 516e430a-8416-4f21-98cc-8b421ea76ad6
name: InCorrectOrientationRouter
type: action
action: Router
with:
routingPort: inCorrectOrientation

edges:
- id: 1919452e-36db-4f28-9c60-679073fb85bf
from: 6a141be1-ee08-4cc4-9c0a-c3f8cad6679f
to: 722b4540-d606-438f-b4cc-fd55eeaeeb42
fromPort: default
toPort: default
- id: 273ad558-f7a8-4dc0-9882-7b7ae1f9b58d
from: 6a141be1-ee08-4cc4-9c0a-c3f8cad6679f
to: 8a1e6f15-67c6-45ae-a1dc-8e4ae3217574
fromPort: default
toPort: default
- id: 61d65610-a843-4971-ad71-d5c754057343
from: 8a1e6f15-67c6-45ae-a1dc-8e4ae3217574
to: 923a0c9f-ab74-4935-819d-fe254d0cfc12
fromPort: default
toPort: default
- id: e53448ae-1183-466f-8b7d-8e42ec1c742f
from: 923a0c9f-ab74-4935-819d-fe254d0cfc12
to: 0361e205-4d43-442d-b004-2ea981dbca84
fromPort: default
toPort: default
- id: 78ce97f6-a91d-432a-928a-4da1361bb06f
from: 0361e205-4d43-442d-b004-2ea981dbca84
to: 27cd7ebf-7d16-4a1c-ac27-02eddb61a7b9
fromPort: default
toPort: default
- id: 7bace900-8f44-45f6-b07b-c936b5cf4263
from: 27cd7ebf-7d16-4a1c-ac27-02eddb61a7b9
to: 6a005159-a30d-4a30-8cca-ebea4e89c351
fromPort: inCorrectOrientation
toPort: default
- id: 244ba77c-f169-48e6-82e3-2c2b60a8f072
from: 6a005159-a30d-4a30-8cca-ebea4e89c351
to: 516e430a-8416-4f21-98cc-8b421ea76ad6
fromPort: default
toPort: default
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,9 @@ graphs:
subGraphId: f4e71783-0b7d-4d4a-9377-cf8d7f061f3b

- id: 923d550b-fe20-4b31-b988-213e13f4cfa6
name: Echo-L-7-8-9-11-13
name: Noop-L-7-8-9-11-13
type: action
action: EchoSink
action: NoopSink

edges:
- id: 2c9f5fa9-40bb-4692-b157-815f583172b6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ graphs:
method: count

- id: 5ffe00f3-4554-4fc9-91c7-f7d272691cc4
name: EchoFeatureTypeExtractor
name: NoopFeatureTypeExtractor
type: action
action: EchoSink
action: NoopSink

- id: 24825ad1-d005-4a45-b9bf-cbb605b86626
name: FeatureFilterByRwy
Expand Down

0 comments on commit 7ceef33

Please sign in to comment.