Core functions for n-dimensional interpolation and extrapolation. More...
Functions | |
| int * | ndp_find_nearest (double *normed_elem, int *elem_index, int *elem_flag, ndp_table *table, ndp_extrapolation_method extrapolation_method, ndp_search_algorithm search_algorithm, double *dist) |
| Finds the nearest defined vertex or fully defined hypercube. | |
| ndp_query_pts * | ndp_query_pts_import (int nelems, double *qpts, ndp_axes *axes) |
| Imports and pre-processes query points for ndpolator operations. | |
| ndp_hypercube ** | ndp_find_hypercubes (ndp_query_pts *qpts, ndp_table *table) |
| Finds hypercubes containing each query point. | |
| ndp_query * | ndpolate (ndp_query_pts *qpts, ndp_table *table, ndp_extrapolation_method extrapolation_method, ndp_search_algorithm search_algorithm) |
| Performs n-dimensional interpolation and extrapolation. | |
Core functions for n-dimensional interpolation and extrapolation.
These are the main functions users will call to perform interpolation. Start here if you're new to ndpolator.
| int * ndp_find_nearest | ( | double * | normed_elem, |
| int * | elem_index, | ||
| int * | elem_flag, | ||
| ndp_table * | table, | ||
| ndp_extrapolation_method | extrapolation_method, | ||
| ndp_search_algorithm | search_algorithm, | ||
| double * | dist ) |
Finds the nearest defined vertex or fully defined hypercube.
| normed_elem | Unit hypercube-normalized query point coordinates | |
| elem_index | Superior corner indices of containing/nearest hypercube | |
| elem_flag | Per-component flags for the query point | |
| table | Self-contained ndpolator table with grid definition | |
| extrapolation_method | Method for handling out-of-bounds points | |
| search_algorithm | Algorithm to use for nearest neighbor search | |
| [out] | dist | Distance to nearest fully defined hypercube |
Finds the nearest defined vertex or the nearest fully defined hypercube.
The normed_elem parameter provides coordinates of the query point in unit hypercube space. For example, normed_elem=(0.3, 0.8, 0.2) provides coordinates with respect to the inferior hypercube corner (within the hypercube). Conversely, normed_elem=(-0.2, 0.3, 0.4) would lie outside the hypercube.
The elem_index parameter provides coordinates of the superior hypercube corner (indices of each axis where the corresponding value is the first value greater than the query point coordinate). For example, if the query point (in index space) is (4.2, 5.6, 8.9), then elem_index=(5, 6, 9).
The elem_flag parameter flags each coordinate of the normed_elem with NDP_ON_GRID, NDP_ON_VERTEX, or NDP_OUT_OF_BOUNDS. This is important because elem_index points to the nearest larger axis value if the coordinate does not coincide with the axis vertex, and points to the vertex itself if it coincides.
The extrapolation_method parameter determines whether to find the nearest vertex (NDP_METHOD_NEAREST) or nearest fully defined hypercube (NDP_METHOD_LINEAR). This determines which mask is used: table->vmask (defined vertices) or table->hcmask (fully defined hypercubes).
The search_algorithm parameter determines whether to use k-d tree or linear search. K-d tree has O(log N) complexity vs O(N) for linear search, but has upfront construction cost that may not be worthwhile for small grids.
| ndp_query_pts * ndp_query_pts_import | ( | int | nelems, |
| double * | qpts, | ||
| ndp_axes * | axes ) |
Imports and pre-processes query points for ndpolator operations.
| nelems | Number of query points to process |
| qpts | Array of query point coordinates |
| axes | Complete axes structure defining the grid |
Looks up superior index of the n-dimensional hypercube that contains each query point in qpts. The index is found by binary search for each axis sequentially.
When any of the query point components coincides with the grid vertex, that component will be flagged by NDP_ON_VERTEX. This is used by the ndp_find_hypercubes function to reduce the dimensionality of the corresponding hypercube. Any query point components that fall outside of the grid boundaries are flagged by NDP_OUT_OF_BOUNDS. Finally, all components that do fall within the grid are flagged by NDP_ON_GRID.
| ndp_hypercube ** ndp_find_hypercubes | ( | ndp_query_pts * | qpts, |
| ndp_table * | table ) |
Finds hypercubes containing each query point.
| qpts | Pre-processed ndp_query_pts structure |
| table | Self-contained ndpolator table with grid definition |
For each query point, the function identifies the N-dimensional hypercube that contains or is nearest to the point. A hypercube is defined by 2^N vertices in N-dimensional space.
The function handles several cases:
Each returned hypercube contains the vertex values needed for interpolation, organized in C-order (last dimension varies fastest).
| ndp_query * ndpolate | ( | ndp_query_pts * | qpts, |
| ndp_table * | table, | ||
| ndp_extrapolation_method | extrapolation_method, | ||
| ndp_search_algorithm | search_algorithm ) |
Performs n-dimensional interpolation and extrapolation.
| qpts | Query points structure with all necessary information |
| table | Complete ndpolator table with grid definition |
| extrapolation_method | Method for handling out-of-bounds points |
| search_algorithm | Algorithm to use for nearest neighbor search |
This is the main ndpolator function that performs n-dimensional interpolation and extrapolation on sparse grids. It processes all query points in the qpts structure and returns interpolated/extrapolated values.
The function handles three main scenarios:
The extrapolation_method parameter determines ndpolator's behavior for off-grid query points:
The search_algorithm parameter controls the method to find nearest vertices or fully defined hypercubes: