planning
static_interpolation.planning
Classes:
| Name | Description |
|---|---|
InterpolationPlan |
Dataclass containing all precomputed arrays and information needed to perform the interpolation. |
InterpolationPlanner |
Planner that creates InterpolationPlan instances. |
Functions:
| Name | Description |
|---|---|
cubic_kernel |
Cubic interpolation kernel (Keys / Catmull–Rom-like with a = -0.5). |
linear_kernel |
Linear interpolation kernel. |
pixels_on_line_segment |
Return the integer grid cells crossed by a 2D line segment. |
poly_area |
Calculate the area of a polygon using the shoelace formula. |
quad_bounding_box |
Computes the bounding box of a quad. |
clipped_area_quad_unit_square |
Compute the intersection area of a convex quad with the unit square. |
point_in_convex_quad |
Test whether a point lies inside or on the boundary of a convex quadrilateral. |
InterpolationPlan
[source]
dataclass
Dataclass containing all precomputed arrays and information needed to perform the interpolation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weight_indices
|
NDArray
|
(M,), data indice associated to a specific weight. |
required |
weight_values
|
NDArray
|
(M,), weight values. |
required |
n_weights_per_sample
|
NDArray
|
(n_valid,), number of weight_indices,weight_values used for the interpolation at a given sampling point. |
required |
valid_sample_ids
|
NDArray
|
(n_valid,) Flattened indices of sample points whose mapped coordinates lie on a data plane. |
required |
valid_sample_mask
|
NDArray
|
(n_samples,) Boolean mask whose true values indicate sampling points are mapped onto a data plane. (np.nonzero(valid_sample_mask)[0]==valid_sample_ids) |
required |
out_shape
|
tuple[int, ...]
|
Shape of the fineal interpolated image. |
required |
mean_fill_indices
|
None | NDArray
|
3x3 neighbor indices of each pixel on each data plane. |
required |
nearest_data_id
|
None | NDArray
|
(n_valid,) pixel index of the nearest data point for each sampling point. |
required |
InterpolationPlanner
[source]
Bases: InterpolationPlannerBase
Planner that creates InterpolationPlan instances. Currently supports linear and cubic interpolation.
Methods:
| Name | Description |
|---|---|
build |
Creates InterpolationPlan instances. |
build(mapped_grid, layout, policy)
[source]
Creates InterpolationPlan instances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapped_grid
|
SamplingGrid
|
sampling grid with points in pixel coordinates. |
required |
layout
|
ImageLayout
|
Pixel panel layout. |
required |
policy
|
InterpolationPolicy
|
Interpolation options. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
InterpolationPlan |
InterpolationPlan
|
Finished interpolation plan. |
cubic_kernel(t)
[source]
Cubic interpolation kernel (Keys / Catmull–Rom-like with a = -0.5).
Parameters t (float): scalar distance
Returns float: Kernel value at t
linear_kernel(t)
[source]
Linear interpolation kernel.
Parameters t (float): scalar distance
Returns float: Kernel value at t.
pixels_on_line_segment(x0, y0, x1, y1)
[source]
Return the integer grid cells crossed by a 2D line segment.
Uses the Amanatides-Woo voxel traversal algorithm in 2D to compute the
sequence of grid cells intersected by the open line segment from
(x0, y0) to (x1, y1).
The function applies an open-segment convention by nudging both endpoints
inward by one ULP using np.nextafter. This avoids ambiguous inclusion of
cells when the segment lies exactly on grid boundaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x0
|
float
|
X-coordinate of the segment start point. |
required |
y0
|
float
|
Y-coordinate of the segment start point. |
required |
x1
|
float
|
X-coordinate of the segment end point. |
required |
y1
|
float
|
Y-coordinate of the segment end point. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[int64]
|
A NumPy array of shape |
NDArray[int64]
|
contains the |
NDArray[int64]
|
order. |
Notes
- If the segment is degenerate (start and end points are identical), an empty array is returned.
- If the entire segment lies exactly on a vertical or horizontal grid boundary, an empty array is returned because no cell interior is hit.
poly_area(poly)
[source]
Calculate the area of a polygon using the shoelace formula.
\[ 2A = \begin{vmatrix}
x_1 & x_2 \\
y_1 & y_2
\end{vmatrix} + \begin{vmatrix}
x_2 & x_3 \\
y_2 & y_3
\end{vmatrix} + \ldots + \begin{vmatrix}
x_{n} & x_1 \\
y_{n} & y_1
\end{vmatrix} \]
The vertices must be ordered consecutively along the polygon boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poly
|
NDArray[float64]
|
A 2D array of shape (n, 2) where each row represents the (x, y) coordinates of a vertex. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The area of the polygon. |
quad_bounding_box(quad)
[source]
Computes the bounding box of a quad.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quad
|
ndarray
|
An array of shape (4, 2) containing quad vertices in clockwise (CW) or counter-clockwise (CCW) order. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ndarray |
An array of shape (4,) storing the bounding box in the format [min_x, max_x, min_y, max_y]. |
clipped_area_quad_unit_square(quad, buf0, buf1)
[source]
Compute the intersection area of a convex quad with the unit square.
The input vertices in "quad" must be ordered consecutively along the boundary of the quadrilateral. Temporary scratch buffers are used to store intermediate polygon vertices during clipping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quad
|
NDArray[float64]
|
A |
required |
buf0
|
NDArray[float64]
|
A scratch array of shape |
required |
buf1
|
NDArray[float64]
|
A scratch array of shape |
required |
Returns:
| Type | Description |
|---|---|
float
|
The area of the intersection between the quadrilateral and the unit |
float
|
square as a non-negative |
Notes
- Returns
0.0if the quadrilateral lies entirely outside the unit square. - Returns the quadrilateral area directly if the quadrilateral lies entirely inside the unit square.
- The scratch buffers are modified in place.
- Because clipping a convex quadrilateral against the unit square can produce up to 8 vertices, the scratch buffers must be large enough to hold at least 8 points.
point_in_convex_quad(px, py, quad)
[source]
Test whether a point lies inside or on the boundary of a convex quadrilateral.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
px
|
X-coordinate of the point. |
required | |
py
|
Y-coordinate of the point. |
required | |
quad
|
A |
required |
Returns:
| Type | Description |
|---|---|
|
|
|
|
otherwise |
Notes
- The quadrilateral is assumed to be convex.
- The vertex order may be either CW or CCW, but must be consistent.
- No numerical tolerance is applied; sign checks are performed using exact floating-point comparisons.