Skip to content
Snippets Groups Projects
Commit c8f16094 authored by Udo Eisenbarth's avatar Udo Eisenbarth :speech_balloon:
Browse files

Add output port to detector node.

Update documentation.
parent ad4c4a27
No related branches found
No related tags found
1 merge request!2Resolve "Add outgoing port to detector node"
Pipeline #7296 canceled
......@@ -4,6 +4,7 @@ use crate::{
optic_node::{Dottable, LightResult, Optical},
optic_ports::OpticPorts,
};
use std::collections::HashMap;
use std::fmt::Debug;
type Result<T> = std::result::Result<T, OpossumError>;
......@@ -17,17 +18,21 @@ type Result<T> = std::result::Result<T, OpossumError>;
/// - Inputs
/// - `in1`
/// - Outputs
/// - none
/// - `out1`
///
/// During analysis, the output port contains a replica of the input port similar to a [`Dummy`](crate::nodes::Dummy) node. This way,
/// different dectector nodes can be "stacked" or used somewhere in between arbitrary optic nodes.
pub struct Detector {
light_data: Option<LightData>,
}
impl Optical for Detector {
fn node_type(&self) -> &str {
"light sink: detector"
"detector"
}
fn ports(&self) -> OpticPorts {
let mut ports = OpticPorts::new();
ports.add_input("in1").unwrap();
ports.add_output("out1").unwrap();
ports
}
fn analyze(
......@@ -35,14 +40,12 @@ impl Optical for Detector {
incoming_data: LightResult,
_analyzer_type: &crate::analyzer::AnalyzerType,
) -> Result<LightResult> {
let data = incoming_data
.into_iter()
.filter(|data| data.0 == "in1")
.last();
if let Some(data) = data {
self.light_data = data.1;
if let Some(data) = incoming_data.get("in1") {
self.light_data = data.clone();
Ok(HashMap::from([("out1".into(), data.clone())]))
} else {
Ok(HashMap::from([("out2".into(), None)]))
}
Ok(LightResult::default())
}
fn export_data(&self, file_name: &str) {
if let Some(data) = &self.light_data {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment