cellular_raza_concepts/plotting.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
use plotters::backend::DrawingBackend;
use plotters::coord::cartesian::Cartesian2d;
use plotters::coord::types::RangedCoordf64;
use plotters::prelude::BitMapBackend;
use plotters::prelude::DrawingArea;
use plotters::prelude::SVGBackend;
use crate::errors::DrawingError;
/// Creates a new plotting root which can then be drawn upon.
pub trait CreatePlottingRoot //, E>
// E: std::error::Error + std::marker::Sync + std::marker::Send,
{
/// Creates a bitmap plotting root.
fn create_bitmap_root<'a, T>(
&self,
image_size: u32,
filename: &'a T,
) -> Result<
DrawingArea<BitMapBackend<'a>, Cartesian2d<RangedCoordf64, RangedCoordf64>>,
DrawingError,
>
where
T: AsRef<std::path::Path> + ?Sized;
// TODO implement this as well
/* fn create_svg_root<'a>(
&self,
image_size: u32,
filename: &'a String,
) -> Result<
DrawingArea<SVGBackend<'a>, Cartesian2d<RangedCoordf64, RangedCoordf64>>,
DrawingError,
>;*/
}
/// Allows elements of the simulation such as cells and voxels to draw themselves onto a plotting root.
/// Typically, voxels will draw first and cells afterwards.
pub trait PlotSelf {
/// Define which elements to draw when plotting the element itself.
fn plot_self<Db>(
&self,
root: &mut DrawingArea<Db, Cartesian2d<RangedCoordf64, RangedCoordf64>>,
) -> Result<(), DrawingError>
where
Db: DrawingBackend;
/// Overload for backend to have a purely bitmap function.
/// User are not expected to change this function.
fn plot_self_bitmap(
&self,
root: &mut DrawingArea<BitMapBackend, Cartesian2d<RangedCoordf64, RangedCoordf64>>,
) -> Result<(), DrawingError> {
self.plot_self(root)
}
/// Overload for backend to have a purely bitmap function.
/// User are not expected to change this function.
fn plot_self_svg(
&self,
root: &mut DrawingArea<SVGBackend, Cartesian2d<RangedCoordf64, RangedCoordf64>>,
) -> Result<(), DrawingError> {
self.plot_self(root)
}
}
use crate::cell::CellAgentBox;
use serde::{Deserialize, Serialize};
impl<Cel> PlotSelf for CellAgentBox<Cel>
where
Cel: PlotSelf + Serialize + for<'a> Deserialize<'a>,
{
fn plot_self<Db>(
&self,
root: &mut DrawingArea<Db, Cartesian2d<RangedCoordf64, RangedCoordf64>>,
) -> Result<(), DrawingError>
where
Db: DrawingBackend,
{
self.cell.plot_self(root)
}
}