feat: add Intensity Transformer

This commit is contained in:
alban 2023-07-24 18:53:19 +02:00
parent 22d7d3c718
commit 2c0d5cd13f
4 changed files with 123 additions and 77 deletions

View File

@ -1,6 +1,6 @@
use config::Config; use config::Config;
use serde::{Serialize,Deserialize}; use serde::{Serialize, Deserialize};
use crate::errors::{LJError,LJResult}; use crate::errors::{LJError, LJResult};
use crate::transformer; use crate::transformer;
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
@ -10,7 +10,7 @@ pub struct Conf {
pub redis_url: String, pub redis_url: String,
pub dac: DacFamily, pub dac: DacFamily,
#[serde(default)] #[serde(default)]
pub transformers: Vec<TransformConf> pub transformers: Vec<TransformConf>,
} }
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
@ -25,12 +25,12 @@ pub enum DacFamily {
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub struct HeliosConf { pub struct HeliosConf {
pub id: u8 pub id: u8,
} }
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub struct EtherDreamConf { pub struct EtherDreamConf {
pub ip: String pub ip: String,
} }
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
@ -51,6 +51,8 @@ pub enum TransformConf {
Homography(transformer::Homography), Homography(transformer::Homography),
#[serde(rename = "helios_to_etherdream")] #[serde(rename = "helios_to_etherdream")]
HeliosToEtherdream(transformer::HeliosToEtherdream), HeliosToEtherdream(transformer::HeliosToEtherdream),
#[serde(rename = "intensity")]
Intensity(transformer::Intensity),
} }
@ -60,22 +62,23 @@ impl Conf {
.add_source(config::File::with_name(path)) .add_source(config::File::with_name(path))
.build()?; .build()?;
let conf : Conf = settings.try_deserialize().map_err(LJError::Config)?; let conf: Conf = settings.try_deserialize().map_err(LJError::Config)?;
Ok(conf) Ok(conf)
} }
pub fn get_transformers(&self) -> Vec<Box<dyn transformer::Transformers>> { pub fn get_transformers(&self) -> Vec<Box<dyn transformer::Transformers>> {
let mut v = vec![]; let mut v = vec![];
for t in &self.transformers { for t in &self.transformers {
let t : Box<dyn transformer::Transformers> = match t { 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::FlipH(r) => Box::new(*r),
TransformConf::FlipV(r) => Box::new(*r), TransformConf::FlipV(r) => Box::new(*r),
TransformConf::Grid(r) => Box::new(*r), TransformConf::Grid(r) => Box::new(*r),
TransformConf::Homography(r) => Box::new(*r),
TransformConf::HeliosToEtherdream(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); v.push(t);
} }
@ -90,10 +93,12 @@ impl Conf {
redis_url: "redis://127.0.0.1:6379/".to_string(), redis_url: "redis://127.0.0.1:6379/".to_string(),
dac: DacFamily::Helios(HeliosConf { id: 0 }), dac: DacFamily::Helios(HeliosConf { id: 0 }),
transformers: vec![ transformers: vec![
TransformConf::Translate(transformer::Translate { x: 2000.0, TransformConf::Translate(transformer::Translate {
y: 2000.0 } ), x: 2000.0,
TransformConf::Replicate(transformer::Replicate::Until(48)) y: 2000.0,
] }),
TransformConf::Replicate(transformer::Replicate::Until(48)),
],
}; };
let s = toml::to_string(&conf).unwrap(); let s = toml::to_string(&conf).unwrap();
println!("{}", s); println!("{}", s);

View File

@ -1,4 +1,5 @@
use ether_dream::protocol::DacPoint; use ether_dream::protocol::DacPoint;
use std::ops::Mul;
#[derive(Debug, Clone, Copy, Default, PartialEq)] #[derive(Debug, Clone, Copy, Default, PartialEq)]
@ -14,6 +15,17 @@ pub struct Color {
pub g: u8, pub g: u8,
pub b: 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 { impl From<Color> for u32 {
fn from(value: Color) -> Self { fn from(value: Color) -> Self {

View File

@ -1,12 +1,12 @@
//pub mod common;
mod translate;
mod replicate;
mod rotate;
mod flip_horizontal; mod flip_horizontal;
mod flip_vertical; mod flip_vertical;
mod grid; mod grid;
mod homography;
mod helios_to_etherdream; mod helios_to_etherdream;
mod homography;
mod intensity;
mod replicate;
mod rotate;
mod translate;
use crate::point::Point; use crate::point::Point;
use crate::worldstate::WorldState; use crate::worldstate::WorldState;
@ -20,6 +20,7 @@ pub use flip_vertical::FlipVertical;
pub use grid::Grid; pub use grid::Grid;
pub use self::homography::Homography; pub use self::homography::Homography;
pub use helios_to_etherdream::HeliosToEtherdream; pub use helios_to_etherdream::HeliosToEtherdream;
pub use intensity::Intensity;
pub trait Transformers { pub trait Transformers {
fn apply( fn apply(

View 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
}
}