Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OPOSSUM
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
phelix
rust
OPOSSUM
Commits
3adfba33
Commit
3adfba33
authored
1 year ago
by
Udo Eisenbarth
Browse files
Options
Downloads
Patches
Plain Diff
IdealFIlter: Add filter_type to properties.
parent
bfa75023
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/nodes/ideal_filter.rs
+18
-11
18 additions, 11 deletions
src/nodes/ideal_filter.rs
src/properties.rs
+9
-1
9 additions, 1 deletion
src/properties.rs
with
27 additions
and
12 deletions
src/nodes/ideal_filter.rs
+
18
−
11
View file @
3adfba33
#![warn(missing_docs)]
use
serde_derive
::{
Serialize
,
Deserialize
};
use
crate
::
analyzer
::
AnalyzerType
;
use
crate
::
dottable
::
Dottable
;
use
crate
::
error
::
OpossumError
;
use
crate
::
lightdata
::{
DataEnergy
,
LightData
};
use
crate
::
optic_ports
::
OpticPorts
;
use
crate
::
optical
::{
LightResult
,
Optical
};
use
crate
::
properties
::{
Properties
,
Property
};
use
crate
::
properties
::{
Properties
,
Property
,
Proptype
};
use
crate
::
spectrum
::
Spectrum
;
use
std
::
collections
::
HashMap
;
type
Result
<
T
>
=
std
::
result
::
Result
<
T
,
OpossumError
>
;
/// Config data for an [`IdealFilter`].
#[derive(Debug,
Clone)]
#[derive(Debug,
Clone
,
Serialize,
Deserialize
)]
pub
enum
FilterType
{
/// a fixed (wavelength-independant) transmission value. Must be between 0.0 and 1.0
Constant
(
f64
),
...
...
@@ -28,7 +30,6 @@ pub enum FilterType {
/// - Outputs
/// - `rear`
pub
struct
IdealFilter
{
filter_type
:
FilterType
,
props
:
Properties
,
}
...
...
@@ -36,13 +37,13 @@ fn create_default_props() -> Properties {
let
mut
props
=
Properties
::
default
();
props
.set
(
"name"
,
"ideal filter"
.into
());
props
.set
(
"inverted"
,
false
.into
());
props
.set
(
"filter type"
,
FilterType
::
Constant
(
1.0
)
.into
());
props
}
impl
Default
for
IdealFilter
{
fn
default
()
->
Self
{
Self
{
filter_type
:
FilterType
::
Constant
(
1.0
),
props
:
create_default_props
(),
}
}
...
...
@@ -62,14 +63,20 @@ impl IdealFilter {
));
}
}
let
mut
props
=
create_default_props
();
props
.set
(
"filter type"
,
filter_type
.into
());
Ok
(
Self
{
filter_type
,
props
:
create_default_props
(),
props
:
props
,
})
}
/// Returns the filter type of this [`IdealFilter`].
pub
fn
filter_type
(
&
self
)
->
FilterType
{
self
.filter_type
.clone
()
let
filter_type
=
self
.props
.get
(
"filter type"
)
.unwrap
()
.prop
.clone
();
if
let
Proptype
::
FilterType
(
filter_type
)
=
filter_type
{
filter_type
}
else
{
panic!
(
"wrong data type"
)
}
}
/// Sets a constant transmission value for this [`IdealFilter`].
///
...
...
@@ -79,7 +86,7 @@ impl IdealFilter {
/// 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
(
0.0
..=
1.0
)
.contains
(
&
transmission
)
{
self
.filter
_
type
=
FilterType
::
Constant
(
transmission
);
self
.
props
.set
(
"
filter
type
"
,
FilterType
::
Constant
(
transmission
)
.into
())
;
Ok
(())
}
else
{
Err
(
OpossumError
::
Other
(
...
...
@@ -95,7 +102,7 @@ impl IdealFilter {
/// This function will return an error if an optical density < 0.0 was given.
pub
fn
set_optical_density
(
&
mut
self
,
density
:
f64
)
->
Result
<
()
>
{
if
density
>=
0.0
{
self
.filter
_
type
=
FilterType
::
Constant
(
f64
::
powf
(
10.0
,
-
1.0
*
density
));
self
.
props
.set
(
"
filter
type
"
,
FilterType
::
Constant
(
f64
::
powf
(
10.0
,
-
1.0
*
density
))
.into
())
;
Ok
(())
}
else
{
Err
(
OpossumError
::
Other
(
"optical densitiy must be >=0"
.into
()))
...
...
@@ -105,7 +112,7 @@ impl IdealFilter {
///
/// This functions `None` if the filter type is not [`FilterType::Constant`].
pub
fn
optical_density
(
&
self
)
->
Option
<
f64
>
{
match
self
.filter_type
{
match
self
.filter_type
()
{
FilterType
::
Constant
(
t
)
=>
Some
(
-
1.0
*
f64
::
log10
(
t
)),
_
=>
None
,
}
...
...
@@ -116,7 +123,7 @@ impl IdealFilter {
match
input
{
LightData
::
Energy
(
e
)
=>
{
let
mut
out_spec
=
e
.spectrum
.clone
();
match
&
self
.filter_type
{
match
&
self
.filter_type
()
{
FilterType
::
Constant
(
t
)
=>
{
if
out_spec
.scale_vertical
(
*
t
)
.is_ok
()
{
let
light_data
=
...
...
This diff is collapsed.
Click to expand it.
src/properties.rs
+
9
−
1
View file @
3adfba33
use
serde_derive
::{
Deserialize
,
Serialize
};
use
std
::
collections
::
HashMap
;
use
crate
::{
error
::
OpossumError
,
lightdata
::
LightData
,
optical
::
OpticGraph
};
use
crate
::{
error
::
OpossumError
,
lightdata
::
LightData
,
optical
::
OpticGraph
,
nodes
::
FilterType
};
#[derive(Default,
Serialize,
Deserialize,
Debug,
Clone)]
pub
struct
Properties
{
...
...
@@ -77,6 +77,13 @@ impl From<i32> for Property {
}
}
}
impl
From
<
FilterType
>
for
Property
{
fn
from
(
value
:
FilterType
)
->
Self
{
Property
{
prop
:
Proptype
::
FilterType
(
value
),
}
}
}
#[non_exhaustive]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
pub
enum
Proptype
{
...
...
@@ -86,4 +93,5 @@ pub enum Proptype {
Bool
(
bool
),
LightData
(
Option
<
LightData
>
),
OpticGraph
(
OpticGraph
),
FilterType
(
FilterType
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment