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

Implement analyze fn for RefNode.

Various doc work
parent 410db2ae
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,9 @@ use std::fmt::Debug;
type Result<T> = std::result::Result<T, OpossumError>;
#[derive(Default)]
/// This node rerpresents an universal detector. Any [`LightData`] coming in will be stored internally for later display / export. So far it only has one input (in1).
/// This node represents an universal detector.
///
/// Any [`LightData`] coming in will be stored internally for later display / export. So far it only has one input (in1).
pub struct Detector {
light_data: Option<LightData>,
}
......
......@@ -11,7 +11,9 @@ use petgraph::prelude::{DiGraph, EdgeIndex, NodeIndex};
type Result<T> = std::result::Result<T, OpossumError>;
#[derive(Default, Debug)]
/// A node that represents a group of other [`OpticNode`]s. These subnodes are arranged in its own subgraph. All unconnected input and output ports of this subgraph form the ports of this [`NodeGroup`].
/// A node that represents a group of other [`OpticNode`]s arranges in a subgraph.
///
/// All unconnected input and output ports of this subgraph form the ports of this [`NodeGroup`].
pub struct NodeGroup {
g: DiGraph<OpticNode, Light>,
}
......
......@@ -8,9 +8,12 @@ use std::collections::HashMap;
type Result<T> = std::result::Result<T, OpossumError>;
/// Config data for an [`IdealFilter`].
#[derive(Debug, Clone)]
pub enum FilterType {
/// a fixed (wavelength-independant) transmission value. Must be between 0.0 and 1.0
Constant(f64),
/// filter based on given transmission spectrum.
Spectrum(Spectrum),
}
#[derive(Debug)]
......@@ -20,15 +23,18 @@ pub struct IdealFilter {
}
impl IdealFilter {
/// Creates a new [`IdealFilter`] with a given energy transmission factor.
/// Creates a new [`IdealFilter`] with a given [`FilterType`].
///
/// # Errors
///
/// This function will return an error if a transmission factor > 1.0 is given (This would be an amplifiying filter :-) ).
/// This function will return an [`OpossumError::Other`] if the filter type is
/// [`FilterType::Constant`] and the transmission factor is outside the interval [0.0; 1.0].
pub fn new(filter_type: FilterType) -> Result<Self> {
if let FilterType::Constant(transmission) = filter_type {
if !(0.0..=1.0).contains(&transmission) {
return Err(OpossumError::Other("attenuation must be <= 1.0".into()));
return Err(OpossumError::Other(
"attenuation must be in interval [0.0; 1.0]".into(),
));
}
}
Ok(Self { filter_type })
......@@ -37,21 +43,25 @@ impl IdealFilter {
pub fn filter_type(&self) -> FilterType {
self.filter_type.clone()
}
/// Sets the transmission of this [`IdealFilter`].
/// Sets a constant transmission value for this [`IdealFilter`].
///
/// This implicitly sets the filter type to [`FilterType::Constant`].
/// # Errors
///
/// This function will return an error if a transmission factor > 1.0 is given (This would be an amplifiying filter :-) ).
pub fn set_transmission(&mut self, transmission: f64) -> Result<()> {
if transmission <= 1.0 {
if (0.0..=1.0).contains(&transmission) {
self.filter_type = FilterType::Constant(transmission);
Ok(())
} else {
Err(OpossumError::Other("attenuation must be <=1.0".into()))
Err(OpossumError::Other(
"attenuation must be in interval [0.0; 1.0]".into(),
))
}
}
/// Sets the transmission of this [`IdealFilter`] expressed as optical density.
///
/// This implicitly sets the filter type to [`FilterType::Constant`].
/// # Errors
///
/// This function will return an error if an optical density < 0.0 was given.
......@@ -102,7 +112,6 @@ impl IdealFilter {
}
impl Optical for IdealFilter {
/// Returns "dummy" as node type.
fn node_type(&self) -> &str {
"ideal filter"
}
......
use std::cell::RefCell;
use std::rc::{Rc, Weak};
use crate::optic_node::{Dottable, OpticNode, Optical};
use crate::analyzer::AnalyzerType;
use crate::error::OpossumError;
use crate::optic_node::{Dottable, LightResult, OpticNode, Optical};
use crate::optic_ports::OpticPorts;
type Result<T> = std::result::Result<T, OpossumError>;
#[derive(Debug)]
/// A virtual component referring to another existing component. This node type is necessary in order to model resonators (loops) or double-pass systems.
/// A virtual component referring to another existing component.
///
/// This node type is necessary in order to model resonators (loops) or double-pass systems.
pub struct NodeReference {
reference: Weak<RefCell<OpticNode>>,
}
impl NodeReference {
/// Create new [`OpticNode`] (of type [`NodeReference`]) from another existing [`OpticNode`].
pub fn from_node(node: Rc<RefCell<OpticNode>>) -> OpticNode {
let node_ref = Self {
reference: Rc::downgrade(&node),
......@@ -27,6 +34,18 @@ impl Optical for NodeReference {
fn ports(&self) -> OpticPorts {
self.reference.upgrade().unwrap().borrow().ports().clone()
}
fn analyze(
&mut self,
incoming_data: LightResult,
analyzer_type: &AnalyzerType,
) -> Result<LightResult> {
self.reference
.upgrade()
.unwrap()
.borrow_mut()
.analyze(incoming_data, analyzer_type)
}
}
impl Dottable for NodeReference {
......
......@@ -10,7 +10,9 @@ use crate::{
type Result<T> = std::result::Result<T, OpossumError>;
/// This node represents a source of light. Hence it has only one output port (out1) and no input ports. Source nodes usually are the first nodes of an optic scenery.
/// This node represents a source of light.
///
/// Hence it has only one output port (out1) and no input ports. Source nodes usually are the first nodes of an optic scenery.
#[derive(Default)]
pub struct Source {
light_data: Option<LightData>,
......
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