QwAnalysis
|
A multi-dimensional grid of values with interpolation methods. More...
#include <QwInterpolator.h>
Public Member Functions | |
QwInterpolator (const unsigned int ndim=1) | |
Constructor with number of dimensions. More... | |
QwInterpolator (const std::vector< coord_t > &min, const std::vector< coord_t > &max, const std::vector< coord_t > &step) | |
Constructor with minimum, maximum, and step size. More... | |
QwInterpolator (const std::string &filename) | |
Constructor with file name. More... | |
virtual | ~QwInterpolator () |
Destructor. More... | |
void | SetDimensions (const unsigned int ndim) |
Set the number of coordinate dimensions and resize vectors. More... | |
void | SetMinimumMaximumStep (const coord_t min, const coord_t max, const coord_t step) |
Set minimum, maximum, and step size to single values. More... | |
void | SetMinimumMaximumStep (const std::vector< coord_t > &min, const std::vector< coord_t > &max, const std::vector< coord_t > &step) |
Set minimum, maximum, and step size to different values. More... | |
coord_t | GetMinimum (const unsigned int dim) const |
Get minimum in dimension. More... | |
coord_t | GetMaximum (const unsigned int dim) const |
Get maximum in dimension. More... | |
coord_t | GetStepSize (const unsigned int dim) const |
Get minimum in dimension. More... | |
unsigned int | GetMaximumEntries () const |
Get the maximum number of entries. More... | |
unsigned int | GetCurrentEntries () const |
Get the current number of entries. More... | |
unsigned int | GetWrapCoordinate (const unsigned int dim) const |
Get wrapping coordinate. More... | |
void | SetWrapCoordinate (const unsigned int dim, const size_t wrap=1) |
Set wrapping coordinate. More... | |
void | SetWrapCoordinate (const std::vector< size_t > &wrap) |
int | GetDataReductionFactor (const unsigned int dim) const |
Get data reduction factor. More... | |
void | SetDataReductionFactor (const unsigned int dim, const unsigned int redux) |
Set data reduction factor. More... | |
void | SetDataReductionFactor (const unsigned int redux) |
void | SetDataReductionFactor (const std::vector< unsigned int > &redux) |
void | SetInterpolationMethod (const EQwInterpolationMethod method) |
Set the interpolation method. More... | |
EQwInterpolationMethod | GetInterpolationMethod () const |
Get the interpolation method. More... | |
void | PrintCoverage (const unsigned int dim) |
Print coverage map for all bins in one dimension. More... | |
bool | InBounds (const coord_t *coord) const |
Return true if the coordinate is in bounds. More... | |
Functions to write grid values | |
bool | Set (const coord_t &coord, const value_t &value) |
Set a single value at a coordinate (false if not possible) More... | |
bool | Set (const coord_t *coord, const value_t &value) |
Set a single value at a coordinate (false if not possible) More... | |
bool | Set (const coord_t *coord, const value_t *value) |
Set a set of values at a coordinate (false if not possible) More... | |
bool | Set (const unsigned int linear_index, const value_t &value) |
Set a single value at a linearized index (false if not possible) More... | |
bool | Set (const unsigned int linear_index, const value_t *value) |
Set a set of values at a linearized index (false if not possible) More... | |
bool | Set (const unsigned int *cell_index, const value_t &value) |
Set a single value at a grid point (false if out of bounds) More... | |
bool | Set (const unsigned int *cell_index, const value_t *value) |
Set a set of values at a grid point (false if out of bounds) More... | |
Functions to retrieve interpolated values | |
value_t | GetValue (const coord_t &coord) const |
Get the interpolated value at coordinate (zero if out of bounds) More... | |
value_t | GetValue (const coord_t *coord) const |
Get the interpolated value at coordinate (zero if out of bounds) More... | |
bool | GetValue (const coord_t *coord, double &value) const |
Get the interpolated value at coordinate (zero if out of bounds) More... | |
bool | GetValue (const coord_t *coord, double *value) const |
Get the interpolated value at coordinate (zero if out of bounds) More... | |
File reading and writing | |
bool | WriteText (std::ostream &stream) const |
Write the grid as text. More... | |
bool | WriteTextFile (const std::string &filename) const |
Write the grid to text file. More... | |
bool | WriteTextScreen () const |
Write the grid to screen. More... | |
bool | ReadText (std::istream &stream) |
Read the grid from text. More... | |
bool | ReadTextFile (const std::string &filename) |
Read the grid from text file. More... | |
bool | WriteBinaryFile (const std::string &filename) const |
Write the grid values to binary file. More... | |
bool | ReadBinaryFile (const std::string &filename) |
Read the grid values from binary file. More... | |
Indexing functions (publicly available and unchecked) | |
unsigned int | Index (const coord_t *coord) const |
Return the linearized index based on the point coordinates (unchecked) More... | |
unsigned int | Index (const unsigned int *cell_index) const |
Return the linearized index based on the cell indices (unchecked) More... | |
unsigned int | Index (const unsigned int *cell_index, const unsigned int offset) const |
Return the linearized index based on the cell indices and offset (unchecked) More... | |
void | Cell (const coord_t coord, unsigned int &cell_index, double &cell_local, const unsigned int dim) const |
Return the cell index and local coordinates in one dimension (unchecked) More... | |
void | Cell (const coord_t *coord, unsigned int *cell_index, double *cell_local) const |
Return the cell index and local coordinates (unchecked) More... | |
void | Cell (const coord_t *coord, unsigned int *cell_index) const |
Return the cell index (unchecked) More... | |
void | Cell (unsigned int linear_index, unsigned int *cell_index) const |
Return the cell index based on the linearized index (unchecked) More... | |
void | Coord (const unsigned int *cell_index, coord_t *coord) const |
Return the coordinates based on the cell index (unchecked) More... | |
void | Coord (const unsigned int linear_index, coord_t *coord) const |
Return the coordinates based on the linearized index (unchecked) More... | |
Private Member Functions | |
void | Nearest (const coord_t *coord, unsigned int *cell_index) const |
Return the cell index closest to the coordinate (could be above) (unchecked) More... | |
bool | Linear (const coord_t *coord, value_t *value) const |
Linear interpolation (unchecked) More... | |
bool | NearestNeighbor (const coord_t *coord, value_t *value) const |
Nearest-neighbor (unchecked) More... | |
bool | Check (const coord_t *coord) const |
Check for boundaries with coordinate argument. More... | |
bool | Check (const unsigned int *cell_index) const |
Check for boundaries with cell index argument. More... | |
bool | Check (const unsigned int linear_index) const |
Check for boundaries with linearized index argument. More... | |
value_t | Get (const unsigned int *cell_index) const |
Get a single value by cell index (unchecked) More... | |
value_t | Get (const unsigned int index) const |
Get a single value by linearized index (unchecked) More... | |
bool | Get (const unsigned int index, value_t *value) const |
Get a vector value by linearized index (unchecked) More... | |
Private Attributes | |
unsigned int | fNDim |
Number of dimensions in coordinates. More... | |
std::vector< coord_t > | fMin |
Minimum in each dimension. More... | |
std::vector< coord_t > | fMax |
Maximum in each dimension. More... | |
std::vector< coord_t > | fStep |
Step size in each dimension. More... | |
std::vector< size_t > | fSize |
Number of points in each dimension. More... | |
std::vector< size_t > | fWrap |
Wrap around this coordinate. More... | |
std::vector< size_t > | fRedux |
Data reduction factor. More... | |
std::vector< size_t > | fExtent |
std::vector< value_t > | fValues [value_n] |
Table with pointers to arrays of values. More... | |
unsigned int | fCurrentEntries |
Number of values read in. More... | |
unsigned int | fMaximumEntries |
Maximum number of values. More... | |
unsigned int * | f_cell_index |
Pre-allocated cell index. More... | |
double * | f_cell_local |
Pre-allocated local coordinates. More... | |
EQwInterpolationMethod | fInterpolationMethod |
Interpolation method. More... | |
A multi-dimensional grid of values with interpolation methods.
This class provides various interpolation methods on a multi-dimensional grid of multi-dimensional values. Linear interpolation and nearest-neighbor are implemented for all dimensions.
The template arguments are the internal storage data type (defaults to float) and the number of dimensions of the stored data at each grid point (defaults to one). The dimension of the grid itself is set through the constructor. To describe a double vector field with 5 components on a 3-dimensional grid, you would write
The minimum, maximum, and step size of the grid have to be known before the values are filled.
Definition at line 51 of file QwInterpolator.h.
|
inline |
Constructor with number of dimensions.
Definition at line 56 of file QwInterpolator.h.
|
inline |
Constructor with minimum, maximum, and step size.
Definition at line 63 of file QwInterpolator.h.
|
inline |
Constructor with file name.
Definition at line 73 of file QwInterpolator.h.
|
inlinevirtual |
Destructor.
Definition at line 80 of file QwInterpolator.h.
|
inline |
Return the cell index and local coordinates in one dimension (unchecked)
Return the cell index and local coordinates in one dimension (unchecked)
coord | Point coordinate in one dimension |
cell_index | Cell index of the point (reference) |
cell_local | Local coordinates in cell (reference) |
dim | Dimension |
Definition at line 609 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::Index(), QwInterpolator< float, 4 >::Nearest(), and QwInterpolator< float, 4 >::PrintCoverage().
|
inline |
Return the cell index and local coordinates (unchecked)
Return the cell index and local coordinates (unchecked)
coord | Point coordinates |
cell_index | Cell index of the point (reference) |
cell_local | Local coordinates in cell (reference) |
Definition at line 633 of file QwInterpolator.h.
|
inline |
Return the cell index (unchecked)
Return the cell index (unchecked)
coord | Point coordinates |
cell_index | Cell index of the point (reference) |
Definition at line 649 of file QwInterpolator.h.
|
inline |
Return the cell index based on the linearized index (unchecked)
Return the cell index based on the linearized index (unchecked)
linear_index | Linearized index |
cell_index | Cell index (reference) |
Definition at line 663 of file QwInterpolator.h.
|
inlineprivate |
Check for boundaries with coordinate argument.
Check whether the point is inside the valid region
coord | Point coordinates |
Definition at line 525 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::GetValue(), QwInterpolator< float, 4 >::InBounds(), and QwInterpolator< float, 4 >::Set().
|
inlineprivate |
Check for boundaries with cell index argument.
Check whether the cell index is inside the valid region
cell_index | Cell index |
Definition at line 540 of file QwInterpolator.h.
|
inlineprivate |
Check for boundaries with linearized index argument.
Check whether the linearized index is inside the valid region
linear_index | Linearized index |
Definition at line 555 of file QwInterpolator.h.
|
inline |
Return the coordinates based on the cell index (unchecked)
Return the coordinates based on the cell index (unchecked)
cell_index | Cell index |
coord | Point coordinates (reference) |
Definition at line 680 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::PrintCoverage(), and QwMatrixLookup::WriteTrajMatrix().
|
inline |
Return the coordinates based on the linearized index (unchecked)
Return the coordinates based on the linearized index (unchecked)
linear_index | Linearized index |
coord | Point coordinates (reference) |
Definition at line 694 of file QwInterpolator.h.
|
inlineprivate |
Get a single value by cell index (unchecked)
Definition at line 454 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::PrintCoverage().
|
inlineprivate |
Get a single value by linearized index (unchecked)
Definition at line 460 of file QwInterpolator.h.
|
inlineprivate |
Get a vector value by linearized index (unchecked)
Definition at line 464 of file QwInterpolator.h.
|
inline |
Get the current number of entries.
Definition at line 178 of file QwInterpolator.h.
Referenced by QwMatrixLookup::LoadTrajMatrix(), QwMagneticField::ReadFieldMapStream(), and QwMatrixLookup::WriteTrajMatrix().
|
inline |
Get data reduction factor.
Definition at line 192 of file QwInterpolator.h.
|
inline |
Get the interpolation method.
Definition at line 210 of file QwInterpolator.h.
Referenced by QwMagneticField::GetInterpolationMethod().
|
inline |
Get maximum in dimension.
Definition at line 172 of file QwInterpolator.h.
Referenced by QwMatrixLookup::Bridge().
|
inline |
Get the maximum number of entries.
Definition at line 176 of file QwInterpolator.h.
Referenced by QwMatrixLookup::LoadTrajMatrix(), QwMagneticField::ReadFieldMapStream(), and QwMatrixLookup::WriteTrajMatrix().
|
inline |
Get minimum in dimension.
Definition at line 170 of file QwInterpolator.h.
Referenced by QwMatrixLookup::Bridge().
|
inline |
Get minimum in dimension.
Definition at line 174 of file QwInterpolator.h.
Referenced by QwMatrixLookup::Bridge().
|
inline |
Get the interpolated value at coordinate (zero if out of bounds)
Definition at line 329 of file QwInterpolator.h.
Referenced by QwMatrixLookup::Bridge(), QwMagneticField::GetFieldValue(), and QwInterpolator< float, 4 >::GetValue().
|
inline |
Get the interpolated value at coordinate (zero if out of bounds)
Definition at line 337 of file QwInterpolator.h.
|
inline |
Get the interpolated value at coordinate (zero if out of bounds)
Definition at line 344 of file QwInterpolator.h.
|
inline |
Get the interpolated value at coordinate (zero if out of bounds)
Definition at line 349 of file QwInterpolator.h.
|
inline |
Get wrapping coordinate.
Definition at line 181 of file QwInterpolator.h.
|
inline |
Return true if the coordinate is in bounds.
Definition at line 245 of file QwInterpolator.h.
Referenced by QwMatrixLookup::Bridge(), and QwMagneticField::GetFieldValue().
|
inline |
Return the linearized index based on the point coordinates (unchecked)
Definition at line 406 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::Get(), QwInterpolator< float, 4 >::Index(), and QwInterpolator< float, 4 >::Set().
|
inline |
Return the linearized index based on the cell indices (unchecked)
Return the linearized index based on the cell indices (unchecked)
cell_index | Index in each dimension |
Definition at line 569 of file QwInterpolator.h.
|
inline |
Return the linearized index based on the cell indices and offset (unchecked)
Return the linearized index based on the cell indices and offset (unchecked)
cell_index | Index in each dimension |
pattern | Bit pattern with offsets in each dimension |
Definition at line 587 of file QwInterpolator.h.
|
inlineprivate |
Linear interpolation (unchecked)
Perform the multi-dimensional linear interpolation (unchecked)
coord | Point coordinates |
value | Interpolated value (reference) |
Definition at line 480 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::GetValue().
|
inlineprivate |
Return the cell index closest to the coordinate (could be above) (unchecked)
Definition at line 434 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::Set().
|
inlineprivate |
Nearest-neighbor (unchecked)
Perform the nearest-neighbor interpolation (unchecked)
coord | Point coordinates |
value | Interpolated value (reference) |
Definition at line 510 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::GetValue().
|
inline |
Print coverage map for all bins in one dimension.
Definition at line 215 of file QwInterpolator.h.
Referenced by QwMagneticField::ReadFieldMapStream().
|
inline |
Read the grid values from binary file.
Read the grid values from binary file (should be 64-bit safe, untested)
filename | File name |
Definition at line 837 of file QwInterpolator.h.
References QwLog::flush(), mycout, and myendl.
Referenced by QwInterpolator< float, 4 >::QwInterpolator(), and QwMagneticField::ReadFieldMap().
|
inline |
Read the grid from text.
Read the grid values from a text stream
stream | Input stream |
Definition at line 743 of file QwInterpolator.h.
References QwLog::flush(), mycout, and myendl.
Referenced by QwInterpolator< float, 4 >::ReadTextFile().
|
inline |
Read the grid from text file.
Definition at line 389 of file QwInterpolator.h.
|
inline |
Set a single value at a coordinate (false if not possible)
Definition at line 253 of file QwInterpolator.h.
Referenced by QwMatrixLookup::LoadTrajMatrix(), QwMagneticField::ReadFieldMapStream(), QwInterpolator< float, 4 >::Set(), and QwMatrixLookup::WriteTrajMatrix().
|
inline |
Set a single value at a coordinate (false if not possible)
Definition at line 259 of file QwInterpolator.h.
|
inline |
Set a set of values at a coordinate (false if not possible)
Definition at line 264 of file QwInterpolator.h.
|
inline |
Set a single value at a linearized index (false if not possible)
Definition at line 300 of file QwInterpolator.h.
|
inline |
Set a set of values at a linearized index (false if not possible)
Definition at line 305 of file QwInterpolator.h.
|
inline |
Set a single value at a grid point (false if out of bounds)
Definition at line 314 of file QwInterpolator.h.
|
inline |
Set a set of values at a grid point (false if out of bounds)
Definition at line 319 of file QwInterpolator.h.
|
inline |
Set data reduction factor.
Definition at line 195 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::SetDataReductionFactor().
|
inline |
Definition at line 197 of file QwInterpolator.h.
|
inline |
Definition at line 201 of file QwInterpolator.h.
|
inline |
Set the number of coordinate dimensions and resize vectors.
Definition at line 128 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::QwInterpolator(), and QwInterpolator< float, 4 >::SetMinimumMaximumStep().
|
inline |
Set the interpolation method.
Definition at line 207 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::QwInterpolator(), QwMatrixLookup::QwMatrixLookup(), and QwMagneticField::SetInterpolationMethod().
|
inline |
Set minimum, maximum, and step size to single values.
Definition at line 138 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::QwInterpolator(), QwMatrixLookup::QwMatrixLookup(), and QwInterpolator< float, 4 >::SetMinimumMaximumStep().
|
inline |
Set minimum, maximum, and step size to different values.
Definition at line 144 of file QwInterpolator.h.
|
inline |
Set wrapping coordinate.
Definition at line 184 of file QwInterpolator.h.
Referenced by QwMagneticField::ReadFieldMap().
|
inline |
Definition at line 186 of file QwInterpolator.h.
|
inline |
Write the grid values to binary file.
Write the grid values to binary file (should be 64-bit safe, untested)
Integer data types can be stored differently on 32-bit and 64-bit systems. Fixed-length types uint32_t and u_int32_t are provided in stdint.h and sys/types.h, respectively. The floating point types float and double will always have a length of 32 and 64 bit, per the IEEE convention.
filename | File name |
Definition at line 792 of file QwInterpolator.h.
References QwLog::flush(), mycout, and myendl.
Referenced by QwMagneticField::WriteBinaryFile().
|
inline |
Write the grid as text.
Write the grid values to a text stream
stream | Output stream |
Definition at line 707 of file QwInterpolator.h.
References QwLog::flush(), mycout, and myendl.
Referenced by QwInterpolator< float, 4 >::WriteTextFile(), and QwInterpolator< float, 4 >::WriteTextScreen().
|
inline |
Write the grid to text file.
Definition at line 374 of file QwInterpolator.h.
Referenced by QwMagneticField::WriteTextFile().
|
inline |
Write the grid to screen.
Definition at line 382 of file QwInterpolator.h.
|
private |
Pre-allocated cell index.
Definition at line 117 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::Index(), QwInterpolator< float, 4 >::PrintCoverage(), QwInterpolator< float, 4 >::QwInterpolator(), QwInterpolator< float, 4 >::Set(), and QwInterpolator< float, 4 >::~QwInterpolator().
|
private |
Pre-allocated local coordinates.
Definition at line 119 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::Nearest(), QwInterpolator< float, 4 >::QwInterpolator(), and QwInterpolator< float, 4 >::~QwInterpolator().
|
private |
Number of values read in.
Definition at line 112 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::GetCurrentEntries(), QwInterpolator< float, 4 >::Set(), and QwInterpolator< float, 4 >::SetMinimumMaximumStep().
|
private |
Linear extent between neighbor points in each dimension (e.g. for the least significant index this will be 1, for the next index the number of points in the first index, etc...)
Definition at line 106 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::SetDimensions(), and QwInterpolator< float, 4 >::SetMinimumMaximumStep().
|
private |
Interpolation method.
Definition at line 123 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::GetInterpolationMethod(), QwInterpolator< float, 4 >::GetValue(), and QwInterpolator< float, 4 >::SetInterpolationMethod().
|
private |
Maximum in each dimension.
Definition at line 93 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::GetMaximum(), QwInterpolator< float, 4 >::SetDimensions(), and QwInterpolator< float, 4 >::SetMinimumMaximumStep().
|
private |
Maximum number of values.
Definition at line 114 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::GetMaximumEntries(), QwInterpolator< float, 4 >::PrintCoverage(), and QwInterpolator< float, 4 >::SetMinimumMaximumStep().
|
private |
Minimum in each dimension.
Definition at line 91 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::GetMinimum(), QwInterpolator< float, 4 >::SetDimensions(), and QwInterpolator< float, 4 >::SetMinimumMaximumStep().
|
private |
Number of dimensions in coordinates.
Definition at line 83 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::GetValue(), QwInterpolator< float, 4 >::Nearest(), QwInterpolator< float, 4 >::PrintCoverage(), QwInterpolator< float, 4 >::QwInterpolator(), QwInterpolator< float, 4 >::Set(), QwInterpolator< float, 4 >::SetDataReductionFactor(), QwInterpolator< float, 4 >::SetDimensions(), QwInterpolator< float, 4 >::SetMinimumMaximumStep(), and QwInterpolator< float, 4 >::SetWrapCoordinate().
|
private |
Data reduction factor.
Definition at line 101 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::GetDataReductionFactor(), and QwInterpolator< float, 4 >::SetDataReductionFactor().
|
private |
Number of points in each dimension.
Definition at line 97 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::PrintCoverage(), QwInterpolator< float, 4 >::Set(), QwInterpolator< float, 4 >::SetDimensions(), and QwInterpolator< float, 4 >::SetMinimumMaximumStep().
|
private |
Step size in each dimension.
Definition at line 95 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::GetStepSize(), QwInterpolator< float, 4 >::SetDimensions(), and QwInterpolator< float, 4 >::SetMinimumMaximumStep().
|
private |
Table with pointers to arrays of values.
Definition at line 109 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::Get(), QwInterpolator< float, 4 >::Set(), and QwInterpolator< float, 4 >::SetMinimumMaximumStep().
|
private |
Wrap around this coordinate.
Definition at line 99 of file QwInterpolator.h.
Referenced by QwInterpolator< float, 4 >::GetWrapCoordinate(), QwInterpolator< float, 4 >::Set(), QwInterpolator< float, 4 >::SetDimensions(), and QwInterpolator< float, 4 >::SetWrapCoordinate().