SerializeRenderer: render to GenericSim
, not StaticSim
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::geom::Meters;
|
||||
use crate::real::ToFloat as _;
|
||||
use crate::cross::vec::{Vec2, Vec3};
|
||||
use crate::sim::{AbstractSim, Sample, StaticSim};
|
||||
use crate::sim::{AbstractSim, GenericSim, Sample};
|
||||
use crate::meas::{self, AbstractMeasurement};
|
||||
use crossterm::{cursor, QueueableCommand as _};
|
||||
use crossterm::style::{style, Color, PrintStyledContent, Stylize as _};
|
||||
@@ -562,7 +562,7 @@ impl<S: AbstractSim> Renderer<S> for MultiRenderer<S> {
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct SerializedFrame<S=StaticSim> {
|
||||
pub struct SerializedFrame<S> {
|
||||
pub state: S,
|
||||
/// although not generally necessary to load the sim, saving the measurements is beneficial for
|
||||
/// post-processing.
|
||||
@@ -570,20 +570,20 @@ pub struct SerializedFrame<S=StaticSim> {
|
||||
}
|
||||
|
||||
impl<S: AbstractSim> SerializedFrame<S> {
|
||||
pub fn to_static(self) -> SerializedFrame<StaticSim> {
|
||||
pub fn to_generic(self) -> SerializedFrame<GenericSim<S::Real>> {
|
||||
SerializedFrame {
|
||||
state: AbstractSim::to_static(&self.state),
|
||||
state: AbstractSim::to_generic(&self.state),
|
||||
measurements: self.measurements,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// this serializes the simulation state plus measurements to disk.
|
||||
/// it can either convert the state to a generic, material-agnostic format (static)
|
||||
/// it can either convert the state to a generic, material-agnostic format (generic)
|
||||
/// or dump it as-is.
|
||||
pub struct SerializerRenderer {
|
||||
fmt_str: String,
|
||||
prefer_static: bool,
|
||||
prefer_generic: bool,
|
||||
}
|
||||
|
||||
impl SerializerRenderer {
|
||||
@@ -592,16 +592,16 @@ impl SerializerRenderer {
|
||||
pub fn new(fmt_str: &str) -> Self {
|
||||
Self {
|
||||
fmt_str: fmt_str.into(),
|
||||
prefer_static: false,
|
||||
prefer_generic: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Same as `new`, but cast to StaticSim before serializing. This yields a file that's easier
|
||||
/// for post-processing, and may be smaller in size.
|
||||
pub fn new_static(fmt_str: &str) -> Self {
|
||||
/// Same as `new`, but cast to GenericSim before serializing. This yields a file that's easier
|
||||
/// for post-processing.
|
||||
pub fn new_generic(fmt_str: &str) -> Self {
|
||||
Self {
|
||||
fmt_str: fmt_str.into(),
|
||||
prefer_static: true,
|
||||
prefer_generic: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -629,8 +629,8 @@ impl<S: AbstractSim + Serialize> Renderer<S> for SerializerRenderer {
|
||||
default_render_z_slice(self, state, z, measurements, config)
|
||||
}
|
||||
fn render(&self, state: &S, measurements: &[&dyn AbstractMeasurement<S>], _config: RenderConfig) {
|
||||
if self.prefer_static {
|
||||
self.serialize(&state.to_static(), meas::eval_to_vec(state, measurements));
|
||||
if self.prefer_generic {
|
||||
self.serialize(&state.to_generic(), meas::eval_to_vec(state, measurements));
|
||||
} else {
|
||||
self.serialize(state, meas::eval_to_vec(state, measurements));
|
||||
}
|
||||
|
Reference in New Issue
Block a user