Basic support for plotly backend

NOTE: this requires you to clone `plotly`, copy the
`plotly_kaleido` folder to be adjacent to this one, and then run `cargo
build --release` from within that plotly_kaleido folder.
This commit is contained in:
2020-10-09 21:51:34 -07:00
parent f2ba6fdd1b
commit 1a9093315a
4 changed files with 47 additions and 12 deletions

View File

@@ -1,11 +1,13 @@
use ansi_term::Color::RGB;
use crate::geom::{Meters, Vec2, Vec3};
use crate::geom::{Index, Meters, Vec2, Vec3, Vec3u};
use crate::{flt::{Flt, Real}, Material as _};
use crate::mat;
use crate::sim::{Cell, GenericSim};
use crate::meas::AbstractMeasurement;
use font8x8::{BASIC_FONTS, GREEK_FONTS, UnicodeFonts as _};
use log::{trace, info};
use plotly::{Plot, ImageFormat};
use plotly::heat_map::HeatMap;
use image::{RgbImage, Rgb};
use imageproc::{pixelops, drawing};
use std::fs::File;
@@ -324,6 +326,33 @@ impl Renderer for Y4MRenderer {
}
}
pub struct PlotlyRenderer;
impl Renderer for PlotlyRenderer {
fn render(&mut self, state: &dyn GenericSim, measurements: &[Box<dyn AbstractMeasurement>]) {
let mut plot = Plot::new();
let mut xv = Vec::new();
let mut yv = Vec::new();
let mut zv = Vec::new();
for z in 0..state.depth() {
for y in 0..state.height() {
for x in 0..state.width() {
let cell = state.get(Index(Vec3u::new(x, y, z)));
if cell.e().mag() > 10.0 {
xv.push(x);
yv.push(y);
zv.push(z);
}
}
}
}
let heat_map = HeatMap::new(xv, yv, zv);
plot.add_trace(heat_map);
let name = format!("frame{}", state.step_no());
plot.save(&*name, ImageFormat::PNG, state.width() as _, state.height() as _, 1.0);
}
}
#[derive(Default)]
pub struct MultiRenderer {
renderers: Vec<Box<dyn Renderer>>,