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,

source

pub fn get_data(self) -> Array2<Z>

Consume this object and return the underlying data array.

source

pub fn get_data_ref(&self) -> &Array2<Z>

Get reference to underlying data array.

source

pub fn get_data_ref_mut(&mut self) -> &mut Array2<Z>

Get mutable reference to underlying data array.

source

pub fn dimension(&self) -> Rect<F>

Get the area of the DensityMap as a rectangle.

source

fn num_bins(&self) -> (usize, usize)

Get the number of bins in x and y direction.

source§

impl<F, Z> DensityMap<F, Z>where F: Copy + Num + PartialOrd + FromPrimitive + ToPrimitive, Z: Copy + Div<F, Output = Z>,

source

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.

source

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,

source

pub fn bin_dimension(&self) -> (F, F)

Get real dimension (width, height) of a bin.

source

pub fn bin_area(&self) -> F

Get the area of a bin.

source

pub fn coordinates_to_indices(&self, p: Point<F>) -> (usize, usize)

Convert a coordinate into array indices.

source

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.

source

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>,

source

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.

source

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.

source

pub fn clear(&mut self)

Set all values to zero.

source

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].

source

pub fn bin_center(&self, (x, y): (usize, usize)) -> Point<F>

Get the location of the center of bin with index [x, y].

source

pub fn get_bin_shape(&self, (x, y): (usize, usize)) -> Rect<F>

Get the rectangle shape of the bin at index (i, j).

source

pub fn draw_rect(&mut self, r: &Rect<F>, value: Z)

Draw the rectangle r to the DensityMap by adding the value to all bins that interact with r. If a bin overlaps only partially with r then a*value is added to it where a is the fraction of the overlap.

source§

impl<F, Z> DensityMap<F, Z>where F: Copy + Num + PartialOrd + FromPrimitive + ToPrimitive, Z: Num + AddAssign + Copy + Clone + Mul<F, Output = Z> + FromPrimitive,

source

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.

Trait Implementations§

source§

impl<F: Clone, Z: Clone> Clone for DensityMap<F, Z>

source§

fn clone(&self) -> DensityMap<F, Z>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<F, Z> RefUnwindSafe for DensityMap<F, Z>where F: RefUnwindSafe, Z: RefUnwindSafe,

§

impl<F, Z> Send for DensityMap<F, Z>where F: Send, Z: Send,

§

impl<F, Z> Sync for DensityMap<F, Z>where F: Sync, Z: Sync,

§

impl<F, Z> Unpin for DensityMap<F, Z>where F: Unpin,

§

impl<F, Z> UnwindSafe for DensityMap<F, Z>where F: UnwindSafe, Z: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.