Struct geo_rasterize::Rasterizer [−][src]
pub struct Rasterizer<Label> { /* fields omitted */ }
Expand description
Rasterizer rasterizes shapes like BinaryRasterizer but instead
of making a boolean array, it produces an array of some generic
type (Label
) that implements Copy and
Add though typically you’d use a numeric type.
You can call new or use LabelBuilder to
construct Rasterizer instances. Constructing one requires a
width
, height
and optional geo_to_pix
transform in addition
to background
which specifies the default Label
value used to
fill the raster array. And you can provide a MergeAlgorithm
value to specify what the rasterizer should do when two different
shapes fill the same pixel. If you don’t supply anything, the
rasterizer will use Replace by default.
use geo::{Geometry, Line, Point};
use ndarray::array;
let point = Point::new(3, 4);
let line = Line::new((0, 3), (3, 0));
let mut rasterizer = LabelBuilder::background(0).width(4).height(5).build()?;
rasterizer.rasterize(&point, 7)?;
rasterizer.rasterize(&line, 3)?;
let pixels = rasterizer.finish();
assert_eq!(
pixels.mapv(|v| v as u8),
array![
[0, 0, 3, 0],
[0, 3, 3, 0],
[3, 3, 0, 0],
[3, 0, 0, 0],
[0, 0, 0, 7]
]
);
Implementations
pub fn new(
width: usize,
height: usize,
geo_to_pix: Option<Transform>,
algorithm: MergeAlgorithm,
background: Label
) -> Self
Retrieve the transform.
pub fn rasterize<Coord, InputShape, ShapeAsF64>(
&mut self,
shape: &InputShape,
foreground: Label
) -> Result<()> where
InputShape: MapCoords<Coord, f64, Output = ShapeAsF64>,
ShapeAsF64: Rasterize<Label> + for<'a> CoordsIter<'a, Scalar = f64> + MapCoordsInplace<f64>,
Coord: Into<f64> + Copy + Debug + Num + NumCast + PartialOrd,
pub fn rasterize<Coord, InputShape, ShapeAsF64>(
&mut self,
shape: &InputShape,
foreground: Label
) -> Result<()> where
InputShape: MapCoords<Coord, f64, Output = ShapeAsF64>,
ShapeAsF64: Rasterize<Label> + for<'a> CoordsIter<'a, Scalar = f64> + MapCoordsInplace<f64>,
Coord: Into<f64> + Copy + Debug + Num + NumCast + PartialOrd,
Rasterize one shape, which can be any type that geo provides
using any coordinate numeric type that can be converted into
f64
.
Trait Implementations
Auto Trait Implementations
impl<Label> RefUnwindSafe for Rasterizer<Label> where
Label: RefUnwindSafe,
impl<Label> Send for Rasterizer<Label> where
Label: Send,
impl<Label> Sync for Rasterizer<Label> where
Label: Sync,
impl<Label> Unpin for Rasterizer<Label> where
Label: Unpin,
impl<Label> UnwindSafe for Rasterizer<Label> where
Label: UnwindSafe + RefUnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more