viewer: add a render mode to display just the Material

This commit is contained in:
2022-07-29 16:28:58 -07:00
parent c5e2713b51
commit ba6ef3c5c2
2 changed files with 25 additions and 2 deletions

View File

@@ -12,6 +12,8 @@ use image::{RgbImage, Rgb};
use imageproc::{pixelops, drawing};
use rayon::prelude::*;
use serde::{Serialize, Deserialize};
use std::collections::hash_map::DefaultHasher;
use std::hash::Hasher;
use std::fs::{File, OpenOptions};
use std::io::{BufReader, BufWriter, Seek as _, SeekFrom, Write as _};
use std::path::{Path, PathBuf};
@@ -72,6 +74,7 @@ pub enum FieldDisplayMode {
EzBxy,
BCurrent,
M,
Material,
}
impl FieldDisplayMode {
@@ -81,17 +84,19 @@ impl FieldDisplayMode {
BzExy => EzBxy,
EzBxy => BCurrent,
BCurrent => M,
M => BzExy,
M => Material,
Material => BzExy,
}
}
pub fn prev(self) -> Self {
use FieldDisplayMode::*;
match self {
BzExy => M,
BzExy => Material,
EzBxy => BzExy,
BCurrent => EzBxy,
M => BCurrent,
Material => M,
}
}
}
@@ -176,6 +181,9 @@ impl<'a, S: AbstractSim> RenderSteps<'a, S> {
FieldDisplayMode::M => {
me.render_m(config.scale);
}
FieldDisplayMode::Material => {
me.render_mat(config.scale);
}
}
me.render_measurements();
me.im
@@ -232,6 +240,18 @@ impl<'a, S: AbstractSim> RenderSteps<'a, S> {
self.render_vector_field(Rgb([0xff, 0xff, 0xff]), 1.0e5 * scale, |cell| cell.m().xy().to_f32());
}
fn render_mat(&mut self, scale: f32) {
unsafe fn to_bytes<T>(d: &T) -> &[u8] {
std::slice::from_raw_parts(d as *const T as *const u8, std::mem::size_of::<T>())
}
self.render_scalar_field(scale, false, 1, |cell| {
let mut hasher = DefaultHasher::new();
let as_bytes = unsafe { to_bytes(cell.material()) };
std::hash::Hash::hash_slice(as_bytes, &mut hasher);
hasher.finish() as f32 / (-1i64 as u64 as f32)
});
}
fn render_vector_field<F>(&mut self, color: Rgb<u8>, typical: f32, measure: F)
where
F: Fn(&Sample<'_, S::Real, S::Material>) -> Vec2<f32>