Constructor
new DensityFunction2D(data, stride)
Note: For performance reasons, if data is a 1d-array it is destroyed in the process of building the density
function.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
data |
|||
stride |
0 | the width of the 2d function. only needed if data is a 1d-array |
- Source:
Methods
(static) fromImageData2D(imageData, rgbaToDensity) → {DensityFunction2D}
Creates a basic DensityFunction2D from an ImageData instance.
Pixel data is mapped to a float value and scaled to the range [0,1]
Parameters:
Name | Type | Description |
---|---|---|
imageData |
an ImageData instance (e.g. from CanvasRenderingContext2D.getImageData()). | |
rgbaToDensity |
(optional) maps 4 positive integers (r,g,b,a) to a float value |
- Source:
Returns:
- Type
- DensityFunction2D
(static) machBandingFromImageData2D(imageData, quantization, weight, blurRadius, rgbaToDensity, debugDiv) → {DensityFunction2D}
Creates a DensityFunction2D with artificial contours from an ImageData instance.
The contours are created as follows:
Φ' = Φ + 2w (C - G_dxd * C - 0.5), if C - G_dxd * C > 0.5
Φ' = Φ + 2w (C - G_dxd * C - 1.0), if C - G_dxd * C <= 0.5
where...
...Φ is the original density function (i.e. the ImageData,
...w is a weight controlling the strength of the contouring effect (w ∈ [0, 1])
...C is a quantized version of Φ
...G_dxd is a Gaussian blur kernel with radius d
See: Görtler et al. Stippling of 2D Scalar Fields
Parameters:
Name | Type | Default | Description |
---|---|---|---|
imageData |
an ImageData instance (e.g. from CanvasImageData.getImageData). | ||
quantization |
5 | a positive integer (quantization will be equal steps of size 1/quantization) or an array of quantization steps | |
weight |
0.5 | (optional) a float in range [0,1], determines the strength of the contours. Default: 0.5 | |
blurRadius |
4 | (optional) the radius of the Gaussian blur applied to imageData. Default: 4 | |
rgbaToDensity |
(optional) maps 4 positive integers (r,g,b,a) to a float value. Default: rgbaToLuminance | ||
debugDiv |
mapDiv | (optional) a string, the id of a div that should be used to display intermediate results. Default: undefined |
- Source:
Returns:
- Type
- DensityFunction2D
(async) areaDensity(polygon) → {Promise.<number>}
Returns the accumulated density within a given polygon on this 2D density function.
Parameters:
Name | Type | Description |
---|---|---|
polygon |
a polygon given as array of points (i.e.: [[x1,y1], [x2,y2], ... , [xN, yN]]) |
- Source:
Returns:
the accumulated density within the given polygon on this 2D density function.
- Type
- Promise.<number>
assignDensity(stipples, voronoi)
Assigns density values to each element in a given array of Stipple instances based on the accumulated
density in their corresponding Voronoi regions.
Parameters:
Name | Type | Description |
---|---|---|
stipples |
an array of Stipple instances. | |
voronoi |
the Voronoi regions for the given stipples - must be in the same order. |
- Source:
Returns:
Stipple[]
density(x, y) → {number}
Returns the density at a point given as x & y coordinates on this 2D density function.
Parameters:
Name | Type | Description |
---|---|---|
x |
the x coordinate | |
y |
the y coordinate |
- Source:
Returns:
the density at the given point
- Type
- number