Rendering now mostly uses the GenericSim
This commit is contained in:
@@ -2,7 +2,8 @@ use ansi_term::Color::RGB;
|
||||
use crate::geom::Point;
|
||||
use crate::{flt::{Flt, Real}, Material as _, SimSnapshot, SimState};
|
||||
use crate::mat;
|
||||
use crate::sim::Cell;
|
||||
use crate::sim::{Cell, GenericSim};
|
||||
use crate::vec3::Vec3;
|
||||
use crate::meas::AbstractMeasurement;
|
||||
use font8x8::{BASIC_FONTS, GREEK_FONTS, UnicodeFonts as _};
|
||||
use log::trace;
|
||||
@@ -54,12 +55,12 @@ fn scale_vector(x: Point, typical_mag: Flt) -> Point {
|
||||
|
||||
struct RenderSteps<'a> {
|
||||
im: RgbImage,
|
||||
sim: &'a SimSnapshot,
|
||||
sim: &'a dyn GenericSim,
|
||||
meas: &'a [Box<dyn AbstractMeasurement>],
|
||||
}
|
||||
|
||||
impl<'a> RenderSteps<'a> {
|
||||
fn render(state: &'a SimSnapshot, measurements: &'a [Box<dyn AbstractMeasurement>]) -> RgbImage {
|
||||
fn render(state: &'a dyn GenericSim, measurements: &'a [Box<dyn AbstractMeasurement>]) -> RgbImage {
|
||||
let width = 768;
|
||||
let height = width * state.height() / state.width();
|
||||
let mut me = Self::new(state, measurements, width, height);
|
||||
@@ -75,7 +76,7 @@ impl<'a> RenderSteps<'a> {
|
||||
me.render_measurements();
|
||||
me.im
|
||||
}
|
||||
fn new(sim: &'a SimSnapshot, meas: &'a [Box<dyn AbstractMeasurement>], width: u32, height: u32) -> Self {
|
||||
fn new(sim: &'a dyn GenericSim, meas: &'a [Box<dyn AbstractMeasurement>], width: u32, height: u32) -> Self {
|
||||
RenderSteps {
|
||||
im: RgbImage::new(width, height),
|
||||
sim,
|
||||
@@ -83,10 +84,12 @@ impl<'a> RenderSteps<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_at_px(&self, x_px: u32, y_px: u32) -> &Cell {
|
||||
let x_sim = x_px * self.sim.width() / self.im.width();
|
||||
let y_sim = y_px * self.sim.height() / self.im.height();
|
||||
self.sim.get((x_sim, y_sim).into())
|
||||
fn get_at_px(&self, x_px: u32, y_px: u32) -> Cell {
|
||||
let x_prop = x_px as Flt / self.im.width() as Flt;
|
||||
let x_m = x_prop * (self.sim.width() as Flt * self.sim.feature_size());
|
||||
let y_prop = y_px as Flt / self.im.height() as Flt;
|
||||
let y_m = y_prop * (self.sim.height() as Flt * self.sim.feature_size());
|
||||
self.sim.sample(Vec3::new(x_m, y_m, 0.0))
|
||||
}
|
||||
|
||||
////////////// Ex/Ey/Bz configuration ////////////
|
||||
@@ -132,7 +135,7 @@ impl<'a> RenderSteps<'a> {
|
||||
for y in 0..h {
|
||||
for x in 0..w {
|
||||
let cell = self.get_at_px(x, y);
|
||||
let value = measure(cell);
|
||||
let value = measure(&cell);
|
||||
let scaled = if signed {
|
||||
scale_signed_to_u8(value, typical)
|
||||
} else {
|
||||
@@ -176,7 +179,7 @@ impl<'a> RenderSteps<'a> {
|
||||
let yend = (ystart + size).min(h);
|
||||
for y in ystart..yend {
|
||||
for x in xstart..xend {
|
||||
field += measure(self.get_at_px(x, y));
|
||||
field += measure(&self.get_at_px(x, y));
|
||||
}
|
||||
}
|
||||
let xw = xend - xstart;
|
||||
|
Reference in New Issue
Block a user