Remove plotly
Git/crates.io version of plotly had some bugs which were patched locally. But this added extra maintenance and I haven't used the plotly renderer for some time. So, remove plotly & reintegrate it only when we need it.
This commit is contained in:
102
src/render.rs
102
src/render.rs
@@ -1,4 +1,4 @@
|
||||
use crate::geom::{Index, Meters, Vec2, Vec3, Vec3u};
|
||||
use crate::geom::{Meters, Vec2, Vec3};
|
||||
use crate::real::ToFloat as _;
|
||||
use crate::sim::{GenericSim, Sample, StaticSim};
|
||||
use crate::meas::{self, AbstractMeasurement};
|
||||
@@ -7,7 +7,6 @@ use crossterm::style::{style, Color, PrintStyledContent};
|
||||
use font8x8::{BASIC_FONTS, GREEK_FONTS, UnicodeFonts as _};
|
||||
use log::trace;
|
||||
use num::integer::Integer;
|
||||
use plotly;
|
||||
use image::{RgbImage, Rgb};
|
||||
use imageproc::{pixelops, drawing};
|
||||
use rayon::prelude::*;
|
||||
@@ -493,105 +492,6 @@ impl<S: GenericSim> Renderer<S> for Y4MRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PlotlyRenderer {
|
||||
out_base: String,
|
||||
}
|
||||
|
||||
fn add_scatter(plot: &mut plotly::Plot, xv: &mut Vec<u32>, yv: &mut Vec<u32>, zv: &mut Vec<u32>, colors: &mut Vec<plotly::Rgba>) {
|
||||
let xv = std::mem::replace(xv, Vec::new());
|
||||
let yv = std::mem::replace(yv, Vec::new());
|
||||
let zv = std::mem::replace(zv, Vec::new());
|
||||
let colors = std::mem::replace(colors, Vec::new());
|
||||
let scatter = plotly::Scatter::new3(xv, yv, zv)
|
||||
.mode(plotly::common::Mode::Markers)
|
||||
.marker(plotly::common::Marker::new()
|
||||
.opacity(0.01)
|
||||
//.size_array(sizes)
|
||||
//.opacity_array(opacities)
|
||||
.color_array(colors)
|
||||
);
|
||||
plot.add_trace(scatter);
|
||||
}
|
||||
|
||||
impl PlotlyRenderer {
|
||||
pub fn new(out_base: &str) -> Self {
|
||||
Self {
|
||||
out_base: out_base.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: GenericSim> Renderer<S> for PlotlyRenderer {
|
||||
fn render_z_slice(&self, state: &S, z: u32, measurements: &[Box<dyn AbstractMeasurement>], config: RenderConfig) {
|
||||
default_render_z_slice(self, state, z, measurements, config)
|
||||
}
|
||||
fn render(&self, state: &S, _meas: &[Box<dyn AbstractMeasurement>], _config: RenderConfig) {
|
||||
use plotly::{ImageFormat, Plot, Rgba};
|
||||
// use plotly::common::Marker;
|
||||
use plotly::layout::{AspectMode, Axis, Layout, LayoutScene};
|
||||
let mut plot = Plot::new();
|
||||
let scene = LayoutScene::new()
|
||||
.x_axis(Axis::new().range(vec![0, state.width() as i32]))
|
||||
.y_axis(Axis::new().range(vec![0, state.height() as i32]))
|
||||
.z_axis(Axis::new().range(vec![0, state.depth() as i32]))
|
||||
.aspect_mode(AspectMode::Cube);
|
||||
let layout = Layout::new()
|
||||
.scene(scene);
|
||||
plot.set_layout(layout);
|
||||
|
||||
let mut xv = Vec::new();
|
||||
let mut yv = Vec::new();
|
||||
let mut zv = Vec::new();
|
||||
// let mut opacities = Vec::new();
|
||||
let mut colors = Vec::new();
|
||||
for z in 0..state.depth() {
|
||||
if xv.len() >= 120000 {
|
||||
add_scatter(&mut plot, &mut xv, &mut yv, &mut zv, &mut colors);
|
||||
}
|
||||
for y in 0..state.height() {
|
||||
for x in 0..state.width() {
|
||||
// if x%5 == 0 || y%5 == 0 || z%5 == 0 {
|
||||
// continue;
|
||||
// }
|
||||
let cell = (state as &dyn GenericSim).get(Index(Vec3u::new(x, y, z)));
|
||||
xv.push(x);
|
||||
yv.push(y);
|
||||
zv.push(z);
|
||||
// opacities.push((cell.e().mag() * 0.1).min(1.0) as f64)
|
||||
let is_vacuum = cell.conductivity() == Vec3::zero() && cell.m() == Vec3::zero();
|
||||
let mat = cell.conductivity().mag().to_f32() + if is_vacuum {
|
||||
0.0
|
||||
} else {
|
||||
5.0
|
||||
};
|
||||
//let g = scale_unsigned_to_u8(mat, 10.0);
|
||||
//let r = scale_unsigned_to_u8(cell.m().mag(), 100.0);
|
||||
//let b = scale_unsigned_to_u8(cell.e().mag(), 1e2);
|
||||
let r = scale_unsigned_to_u8(cell.m().mag().to_f32(), 100.0);
|
||||
let g = scale_unsigned_to_u8(cell.e().mag().to_f32(), 1e2);
|
||||
let b = scale_unsigned_to_u8(mat, 10.0);
|
||||
let alpha = 1.0;
|
||||
colors.push(Rgba::new(r, g, b, alpha));
|
||||
}
|
||||
}
|
||||
// let scatter = plotly::Scatter::new3(xv, yv, zv)
|
||||
// .mode(plotly::common::Mode::Markers)
|
||||
// .marker(plotly::common::Marker::new()
|
||||
// //.opacity(0.2)
|
||||
// //.size_array(sizes)
|
||||
// //.opacity_array(opacities)
|
||||
// .color_array(colors)
|
||||
// );
|
||||
// plot.add_trace(scatter);
|
||||
}
|
||||
add_scatter(&mut plot, &mut xv, &mut yv, &mut zv, &mut colors);
|
||||
|
||||
let name = format!("{}{}", self.out_base, state.step_no());
|
||||
let (im_w, im_h) = im_size(state, 2048, 2048);
|
||||
plot.save(&*name, ImageFormat::PNG, im_w as _, im_h as _, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
struct MultiRendererElement<S> {
|
||||
step_frequency: u64,
|
||||
renderer: Box<dyn Renderer<S>>,
|
||||
|
Reference in New Issue
Block a user