feat: add Intensity Transformer
This commit is contained in:
parent
22d7d3c718
commit
2c0d5cd13f
27
src/conf.rs
27
src/conf.rs
@ -10,7 +10,7 @@ pub struct Conf {
|
||||
pub redis_url: String,
|
||||
pub dac: DacFamily,
|
||||
#[serde(default)]
|
||||
pub transformers: Vec<TransformConf>
|
||||
pub transformers: Vec<TransformConf>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
@ -25,12 +25,12 @@ pub enum DacFamily {
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct HeliosConf {
|
||||
pub id: u8
|
||||
pub id: u8,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct EtherDreamConf {
|
||||
pub ip: String
|
||||
pub ip: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
@ -51,6 +51,8 @@ pub enum TransformConf {
|
||||
Homography(transformer::Homography),
|
||||
#[serde(rename = "helios_to_etherdream")]
|
||||
HeliosToEtherdream(transformer::HeliosToEtherdream),
|
||||
#[serde(rename = "intensity")]
|
||||
Intensity(transformer::Intensity),
|
||||
}
|
||||
|
||||
|
||||
@ -68,14 +70,15 @@ impl Conf {
|
||||
let mut v = vec![];
|
||||
for t in &self.transformers {
|
||||
let t: Box<dyn transformer::Transformers> = match t {
|
||||
TransformConf::Translate(t) => Box::new(*t),
|
||||
TransformConf::Replicate(r) => Box::new(*r),
|
||||
TransformConf::Rotate(r) => Box::new(*r),
|
||||
TransformConf::FlipH(r) => Box::new(*r),
|
||||
TransformConf::FlipV(r) => Box::new(*r),
|
||||
TransformConf::Grid(r) => Box::new(*r),
|
||||
TransformConf::Homography(r) => Box::new(*r),
|
||||
TransformConf::HeliosToEtherdream(r) => Box::new(*r),
|
||||
TransformConf::Homography(r) => Box::new(*r),
|
||||
TransformConf::Intensity(r) => Box::new(*r),
|
||||
TransformConf::Replicate(r) => Box::new(*r),
|
||||
TransformConf::Rotate(r) => Box::new(*r),
|
||||
TransformConf::Translate(t) => Box::new(*t),
|
||||
};
|
||||
v.push(t);
|
||||
}
|
||||
@ -90,10 +93,12 @@ impl Conf {
|
||||
redis_url: "redis://127.0.0.1:6379/".to_string(),
|
||||
dac: DacFamily::Helios(HeliosConf { id: 0 }),
|
||||
transformers: vec![
|
||||
TransformConf::Translate(transformer::Translate { x: 2000.0,
|
||||
y: 2000.0 } ),
|
||||
TransformConf::Replicate(transformer::Replicate::Until(48))
|
||||
]
|
||||
TransformConf::Translate(transformer::Translate {
|
||||
x: 2000.0,
|
||||
y: 2000.0,
|
||||
}),
|
||||
TransformConf::Replicate(transformer::Replicate::Until(48)),
|
||||
],
|
||||
};
|
||||
let s = toml::to_string(&conf).unwrap();
|
||||
println!("{}", s);
|
||||
|
12
src/point.rs
12
src/point.rs
@ -1,4 +1,5 @@
|
||||
use ether_dream::protocol::DacPoint;
|
||||
use std::ops::Mul;
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq)]
|
||||
@ -14,6 +15,17 @@ pub struct Color {
|
||||
pub g: u8,
|
||||
pub b: u8,
|
||||
}
|
||||
impl Mul<u8> for Color {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(self, rhs: u8) -> Self {
|
||||
Self{
|
||||
r: (255 * self.r as u16 / rhs as u16) as u8,
|
||||
g: (255 * self.g as u16 / rhs as u16) as u8,
|
||||
b: (255 * self.b as u16 / rhs as u16) as u8,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Color> for u32 {
|
||||
fn from(value: Color) -> Self {
|
||||
|
@ -1,12 +1,12 @@
|
||||
//pub mod common;
|
||||
mod translate;
|
||||
mod replicate;
|
||||
mod rotate;
|
||||
mod flip_horizontal;
|
||||
mod flip_vertical;
|
||||
mod grid;
|
||||
mod homography;
|
||||
mod helios_to_etherdream;
|
||||
mod homography;
|
||||
mod intensity;
|
||||
mod replicate;
|
||||
mod rotate;
|
||||
mod translate;
|
||||
|
||||
use crate::point::Point;
|
||||
use crate::worldstate::WorldState;
|
||||
@ -20,6 +20,7 @@ pub use flip_vertical::FlipVertical;
|
||||
pub use grid::Grid;
|
||||
pub use self::homography::Homography;
|
||||
pub use helios_to_etherdream::HeliosToEtherdream;
|
||||
pub use intensity::Intensity;
|
||||
|
||||
pub trait Transformers {
|
||||
fn apply(
|
||||
|
28
src/transformer/intensity.rs
Normal file
28
src/transformer/intensity.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use log::debug;
|
||||
use crate::transformer::Transformers;
|
||||
use crate::point::Point;
|
||||
use crate::worldstate::WorldState;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
/// Converts helios Geometry to Helios
|
||||
#[allow(dead_code)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
|
||||
pub struct Intensity {
|
||||
}
|
||||
|
||||
impl Transformers for Intensity {
|
||||
fn apply(&self, point_list: &[Point], ws: &WorldState) -> Vec<Point> {
|
||||
// debug!("list helios {:?}", point_list);
|
||||
let out = point_list.iter().map(|pt| {
|
||||
Point {
|
||||
x: pt.x,
|
||||
y: pt.y,
|
||||
color: pt.color * ws.intensity
|
||||
}
|
||||
}).collect();
|
||||
debug!("list intensity {:?}", out);
|
||||
out
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user