Struct libreda_pnr::metrics::placement_density::DensityMap
source · pub struct DensityMap<F, Z> {
pub dimension: Rect<F>,
pub data: Array2<Z>,
}Expand description
Pixelized representation of the cell locations. Cells are drawn to the DensityMap like to a rasterized image. The 2D array is the input to the FFT based electrostatic force computation.
Use DensityMap::new() and DensityMap::from_data() to create a DensityMap struct.
F: Data type of coordinates.Z: Data type of values.
Example
use libreda_pnr::db;
use libreda_pnr::metrics::placement_density::DensityMap;
// Create a 'bin image' for accumulating densities.
let mut c = DensityMap::new(
db::Rect::new((0.0, 0.0), (10.0, 10.0)),
(10, 10)
);
// Draw a rectangle to the density image.
let r = db::Rect::new((1.0, 1.0), (2.0, 3.0));
c.draw_rect(&r, 1.0);
// Query the density.
assert_eq!(c.density_at((1.5, 1.5).into()), 1.);
// Directly access the density bins.
// The indices may not coincide with the coordinates!
// Here this is only the case because of the very specific dimension of the density map.
assert_eq!(c.data[[0, 0]], 0.0);
assert_eq!(c.data[[1, 1]], 1.0);
assert_eq!(c.data[[2, 3]], 0.0);
Fields§
§dimension: Rect<F>Offset and dimension of the drawable DensityMap.
data: Array2<Z>Raster data of the DensityMap. Hold the sum of values, not densities.
Implementations§
source§impl<F, Z> DensityMap<F, Z>where
F: Copy,
impl<F, Z> DensityMap<F, Z>where F: Copy,
sourcepub fn get_data_ref(&self) -> &Array2<Z>
pub fn get_data_ref(&self) -> &Array2<Z>
Get reference to underlying data array.
sourcepub fn get_data_ref_mut(&mut self) -> &mut Array2<Z>
pub fn get_data_ref_mut(&mut self) -> &mut Array2<Z>
Get mutable reference to underlying data array.
source§impl<F, Z> DensityMap<F, Z>where
F: Copy + Num + PartialOrd + FromPrimitive + ToPrimitive,
Z: Copy + Div<F, Output = Z>,
impl<F, Z> DensityMap<F, Z>where F: Copy + Num + PartialOrd + FromPrimitive + ToPrimitive, Z: Copy + Div<F, Output = Z>,
sourcepub fn density_at(&self, p: Point<F>) -> Z
pub fn density_at(&self, p: Point<F>) -> Z
Read the density at a given coordinate p.
The values are interpolated by the ‘nearest neighbour’ strategy.
Panics
Panics when the point p is outside of the defined area of the density map.
sourcepub fn get_density_at(&self, p: Point<F>) -> Option<Z>
pub fn get_density_at(&self, p: Point<F>) -> Option<Z>
Read the density at a given coordinate p.
The values are interpolated by the ‘nearest neighbour’ strategy.
Returns None if p is outside of the defined region.
source§impl<F, Z> DensityMap<F, Z>where
F: Copy + Num + FromPrimitive + ToPrimitive + PartialOrd,
Z: Copy,
impl<F, Z> DensityMap<F, Z>where F: Copy + Num + FromPrimitive + ToPrimitive + PartialOrd, Z: Copy,
sourcepub fn bin_dimension(&self) -> (F, F)
pub fn bin_dimension(&self) -> (F, F)
Get real dimension (width, height) of a bin.
sourcepub fn coordinates_to_indices(&self, p: Point<F>) -> (usize, usize)
pub fn coordinates_to_indices(&self, p: Point<F>) -> (usize, usize)
Convert a coordinate into array indices.
sourcepub fn value_at(&self, p: Point<F>) -> Z
pub fn value_at(&self, p: Point<F>) -> Z
Read the accumulated value at a given coordinate p.
The values are interpolated by the ‘nearest neighbour’ strategy.
Panics
Panics when the point p is outside of the defined area of the density map.
get_value_at() returns an Option instead of panicking.
sourcepub fn get_value_at(&self, p: Point<F>) -> Option<Z>
pub fn get_value_at(&self, p: Point<F>) -> Option<Z>
Read the accumulated value at a given coordinate p.
The values are interpolated by the ‘nearest neighbour’ strategy.
Returns None if p is outside of the map region.
source§impl<F, Z> DensityMap<F, Z>where
F: Copy + Num + PartialOrd + FromPrimitive + ToPrimitive,
Z: Num + AddAssign + Copy + Clone + Mul<F, Output = Z>,
impl<F, Z> DensityMap<F, Z>where F: Copy + Num + PartialOrd + FromPrimitive + ToPrimitive, Z: Num + AddAssign + Copy + Clone + Mul<F, Output = Z>,
sourcepub fn new(r: Rect<F>, (w, h): (usize, usize)) -> Self
pub fn new(r: Rect<F>, (w, h): (usize, usize)) -> Self
Create an all-zero wxh array.
r defines the spanned region in the euclidean plane.
sourcepub fn from_data(r: Rect<F>, data: Array2<Z>) -> Self
pub fn from_data(r: Rect<F>, data: Array2<Z>) -> Self
Create a DensityMap from existing data.
r defines the spanned region in the euclidean plane.
sourcefn bin_lower_left_corner(&self, (x, y): (usize, usize)) -> Point<F>
fn bin_lower_left_corner(&self, (x, y): (usize, usize)) -> Point<F>
Get the location of the lower left corner of bin with index [x, y].
sourcepub fn bin_center(&self, (x, y): (usize, usize)) -> Point<F>
pub fn bin_center(&self, (x, y): (usize, usize)) -> Point<F>
Get the location of the center of bin with index [x, y].
sourcepub fn get_bin_shape(&self, (x, y): (usize, usize)) -> Rect<F>
pub fn get_bin_shape(&self, (x, y): (usize, usize)) -> Rect<F>
Get the rectangle shape of the bin at index (i, j).
source§impl<F, Z> DensityMap<F, Z>where
F: Copy + Num + PartialOrd + FromPrimitive + ToPrimitive,
Z: Num + AddAssign + Copy + Clone + Mul<F, Output = Z> + FromPrimitive,
impl<F, Z> DensityMap<F, Z>where F: Copy + Num + PartialOrd + FromPrimitive + ToPrimitive, Z: Num + AddAssign + Copy + Clone + Mul<F, Output = Z> + FromPrimitive,
sourcepub fn downsample(&self, reduction_factor: usize) -> Self
pub fn downsample(&self, reduction_factor: usize) -> Self
Create a density map with lower resolution.
Down-sampling is done by creating n*n bins. Therefore the reduction_factor must
divide the number of bins in both x and y direction.