Nearest Grid Surface Class
Implements nearest-neighbor interpolation on a rectilinear N-dimensional grid.
Definition
Namespace: Numerics.NET.Curves.Surfaces
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.1.0
C#
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.1.0
public sealed class NearestGridSurface : GridSurface- Inheritance
- Object → Surface → GridSurface → NearestGridSurface
Remarks
This surface performs nearest-neighbor interpolation by selecting the value at the closest grid point to the query point. The interpolated function is piecewise constant and discontinuous at cell boundaries.
Characteristics:
- Continuity: Discontinuous (piecewise constant)
- Smoothness: C-1 (no derivatives defined at boundaries)
- Performance: Fastest grid interpolation method, O(log N) per query via binary search
- Gradient: Zero everywhere except at measure-zero boundaries
When to use:
- Categorical or discrete data: When interpolating classification labels, flags, or other discrete values where smooth interpolation is inappropriate.
- Maximum performance: When speed is critical and smoothness is not required, such as fast lookups in large tabulated functions.
- Visualization: For pixel-perfect rendering where each grid cell should have a uniform appearance (e.g., heatmaps with distinct cells).
- Debugging: To verify grid coverage and identify regions with sparse data.
Alternatives:
- LinearGridSurface: Use for continuous data where smoothness is desired. Provides C0 continuity with only modest performance cost.
- CubicGridSurface2D or CubicGridSurface3D: Use for 2D/3D data requiring smooth derivatives (C2 continuity).
- TensorSplineGridSurface: Use for N-dimensional smooth interpolation with C1 continuity and custom boundary conditions.
Applications:
- Image resampling with nearest-neighbor (pixel replication)
- Voxel rendering in medical imaging or volumetric displays
- Lookup tables for discrete states or categories
- Real-time applications requiring minimal latency
- Preserving exact integer or enum values during resampling
Creating instances: Use GridNearestInterpolator(IReadOnlyList<IReadOnlyList<Double>>, IReadOnlyList<Double>, ExtrapolationMode) factory methods to create instances of this class.
Properties
| Dimension |
Gets the number of dimensions of the input space.
(Inherited from Surface) |
| Values |
Gets a read-only span containing the values of at the data points.
(Inherited from GridSurface) |
Methods
| Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
| Evaluate(Double[]) |
Evaluates the surface at the specified point.
(Inherited from Surface) |
| Evaluate( |
Evaluates the surface at the specified point.
(Inherited from Surface) |
| Evaluate( |
Evaluates the surface at the specified point.
(Inherited from GridSurface) |
| Evaluate( |
Evaluates the surface at multiple points specified by a list of vectors.
(Inherited from Surface) |
| Evaluate( |
Evaluates the surface at the specified point.
(Inherited from GridSurface) |
| Evaluate( |
Evaluates the surface at multiple points specified by a read-only span of vectors.
(Inherited from Surface) |
| Evaluate( |
Evaluates the surface at multiple points stored in column-major layout.
(Inherited from Surface) |
| Get | Serves as the default hash function. (Inherited from Object) |
| Get | Gets the Type of the current instance. (Inherited from Object) |
| Gradient( |
Computes the gradient of the surface at the specified point.
(Inherited from Surface) |
| Gradient( |
Computes the gradient of a 2D surface at the specified point.
(Inherited from Surface) |
| Gradient( |
Computes the gradient of the scalar field at the specified point.
(Inherited from GridSurface) |
| Gradient( |
Computes the gradient of the surface at the specified point.
(Inherited from Surface) |
| Gradient( | (Inherited from GridSurface) |
| Gradients( |
Computes the gradients of the surface at multiple points.
(Inherited from Surface) |
| Gradients( |
Computes the gradients of the surface at multiple points.
(Inherited from Surface) |
| Hessian |
Computes the Hessian matrix of the surface at the specified point.
(Inherited from Surface) |
| ToString | Returns a string that represents the current object. (Inherited from Object) |