JAPAn
Just Another Parity Analyzer
|
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. | |
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. | |
QwInterpolator (const std::string &filename) | |
Constructor with file name. | |
virtual | ~QwInterpolator () |
Destructor. | |
void | SetDimensions (const unsigned int ndim) |
Set the number of coordinate dimensions and resize vectors. | |
void | SetMinimumMaximumStep (const coord_t min, const coord_t max, const coord_t step) |
Set minimum, maximum, and step size to single values. | |
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. | |
coord_t | GetMinimum (const unsigned int dim) const |
Get minimum in dimension. | |
coord_t | GetMaximum (const unsigned int dim) const |
Get maximum in dimension. | |
coord_t | GetStepSize (const unsigned int dim) const |
Get minimum in dimension. | |
unsigned int | GetMaximumEntries () const |
Get the maximum number of entries. | |
unsigned int | GetCurrentEntries () const |
Get the current number of entries. | |
unsigned int | GetWrapCoordinate (const unsigned int dim) const |
Get wrapping coordinate. | |
void | SetWrapCoordinate (const unsigned int dim, const size_t wrap=1) |
Set wrapping coordinate. | |
void | SetWrapCoordinate (const std::vector< size_t > &wrap) |
int | GetDataReductionFactor (const unsigned int dim) const |
Get data reduction factor. | |
void | SetDataReductionFactor (const unsigned int dim, const unsigned int redux) |
Set data reduction factor. | |
void | SetDataReductionFactor (const unsigned int redux) |
void | SetDataReductionFactor (const std::vector< unsigned int > &redux) |
void | SetInterpolationMethod (const EQwInterpolationMethod method) |
Set the interpolation method. | |
EQwInterpolationMethod | GetInterpolationMethod () const |
Get the interpolation method. | |
void | PrintCoverage (const unsigned int dim) |
Print coverage map for all bins in one dimension. | |
bool | InBounds (const coord_t *coord) const |
Return true if the coordinate is in bounds. | |
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) | |
bool | Set (const coord_t *coord, const value_t &value) |
Set a single value at a coordinate (false if not possible) | |
bool | Set (const coord_t *coord, const value_t *value) |
Set a set of values at a coordinate (false if not possible) | |
bool | Set (const unsigned int linear_index, const value_t &value) |
Set a single value at a linearized index (false if not possible) | |
bool | Set (const unsigned int linear_index, const value_t *value) |
Set a set of values at a linearized index (false if not possible) | |
bool | Set (const unsigned int *cell_index, const value_t &value) |
Set a single value at a grid point (false if out of bounds) | |
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) | |
Functions to retrieve interpolated values | |
value_t | GetValue (const coord_t &coord) const |
Get the interpolated value at coordinate (zero if out of bounds) | |
value_t | GetValue (const coord_t *coord) const |
Get the interpolated value at coordinate (zero if out of bounds) | |
bool | GetValue (const coord_t *coord, double &value) const |
Get the interpolated value at coordinate (zero if out of bounds) | |
bool | GetValue (const coord_t *coord, double *value) const |
Get the interpolated value at coordinate (zero if out of bounds) | |
File reading and writing | |
bool | WriteText (std::ostream &stream) const |
Write the grid as text. | |
bool | WriteTextFile (const std::string &filename) const |
Write the grid to text file. | |
bool | WriteTextScreen () const |
Write the grid to screen. | |
bool | ReadText (std::istream &stream) |
Read the grid from text. | |
bool | ReadTextFile (const std::string &filename) |
Read the grid from text file. | |
bool | WriteBinaryFile (const std::string &filename) const |
Write the grid values to binary file. | |
bool | ReadBinaryFile (const std::string &filename) |
Read the grid values from binary file. | |
Private Attributes | |
unsigned int | fNDim |
Number of dimensions in coordinates. | |
std::vector< coord_t > | fMin |
Minimum in each dimension. | |
std::vector< coord_t > | fMax |
Maximum in each dimension. | |
std::vector< coord_t > | fStep |
Step size in each dimension. | |
std::vector< size_t > | fSize |
Number of points in each dimension. | |
std::vector< size_t > | fWrap |
Wrap around this coordinate. | |
std::vector< size_t > | fRedux |
Data reduction factor. | |
std::vector< size_t > | fExtent |
std::vector< value_t > | fValues [value_n] |
Table with pointers to arrays of values. | |
unsigned int | fCurrentEntries |
Number of values read in. | |
unsigned int | fMaximumEntries |
Maximum number of values. | |
unsigned int * | f_cell_index |
Pre-allocated cell index. | |
double * | f_cell_local |
Pre-allocated local coordinates. | |
EQwInterpolationMethod | fInterpolationMethod |
Interpolation method. | |
Indexing functions (publicly available and unchecked) | |
unsigned int | Index (const coord_t *coord) const |
Return the linearized index based on the point coordinates (unchecked) | |
unsigned int | Index (const unsigned int *cell_index) const |
Return the linearized index based on the cell indices (unchecked) | |
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) | |
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) | |
void | Cell (const coord_t *coord, unsigned int *cell_index, double *cell_local) const |
Return the cell index and local coordinates (unchecked) | |
void | Cell (const coord_t *coord, unsigned int *cell_index) const |
Return the cell index (unchecked) | |
void | Cell (unsigned int linear_index, unsigned int *cell_index) const |
Return the cell index based on the linearized index (unchecked) | |
void | Coord (const unsigned int *cell_index, coord_t *coord) const |
Return the coordinates based on the cell index (unchecked) | |
void | Coord (const unsigned int linear_index, coord_t *coord) const |
Return the coordinates based on the linearized index (unchecked) | |
void | Nearest (const coord_t *coord, unsigned int *cell_index) const |
Return the cell index closest to the coordinate (could be above) (unchecked) | |
bool | Linear (const coord_t *coord, value_t *value) const |
Linear interpolation (unchecked) | |
bool | NearestNeighbor (const coord_t *coord, value_t *value) const |
Nearest-neighbor (unchecked) | |
bool | Check (const coord_t *coord) const |
Check for boundaries with coordinate argument. | |
bool | Check (const unsigned int *cell_index) const |
Check for boundaries with cell index argument. | |
bool | Check (const unsigned int linear_index) const |
Check for boundaries with linearized index argument. | |
value_t | Get (const unsigned int *cell_index) const |
Get a single value by cell index (unchecked) | |
value_t | Get (const unsigned int index) const |
Get a single value by linearized index (unchecked) | |
bool | Get (const unsigned int index, value_t *value) const |
Get a vector value by linearized index (unchecked) | |
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 54 of file QwInterpolator.h.
|
inline |
Constructor with number of dimensions.
Definition at line 59 of file QwInterpolator.h.
References f_cell_index, f_cell_local, fNDim, kMultiLinear, SetDimensions(), and SetInterpolationMethod().
|
inline |
Constructor with minimum, maximum, and step size.
Definition at line 66 of file QwInterpolator.h.
References f_cell_index, f_cell_local, fNDim, kMultiLinear, SetDimensions(), SetInterpolationMethod(), and SetMinimumMaximumStep().
|
inline |
Constructor with file name.
Definition at line 76 of file QwInterpolator.h.
References f_cell_index, f_cell_local, fNDim, kMultiLinear, ReadBinaryFile(), and SetInterpolationMethod().
|
inlinevirtual |
Destructor.
Definition at line 83 of file QwInterpolator.h.
References f_cell_index, and f_cell_local.
|
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 652 of file QwInterpolator.h.
References Cell(), and f_cell_local.
|
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 636 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 612 of file QwInterpolator.h.
References fMin, fSize, fStep, and fWrap.
Referenced by Cell(), Cell(), Coord(), Index(), Linear(), Nearest(), and PrintCoverage().
|
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 666 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 528 of file QwInterpolator.h.
References fMax, fMin, fNDim, and fWrap.
Referenced by GetValue(), InBounds(), Set(), Set(), and 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 543 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 558 of file QwInterpolator.h.
References fMaximumEntries.
|
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 683 of file QwInterpolator.h.
References fMin, fNDim, and fStep.
Referenced by Coord(), and PrintCoverage().
|
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 697 of file QwInterpolator.h.
References Cell(), Coord(), and f_cell_index.
|
inlineprivate |
Get a single value by cell index (unchecked)
Definition at line 457 of file QwInterpolator.h.
References fValues, and Index().
Referenced by Linear(), NearestNeighbor(), and PrintCoverage().
|
inlineprivate |
Get a single value by linearized index (unchecked)
Definition at line 463 of file QwInterpolator.h.
References fValues.
|
inlineprivate |
|
inline |
Get the current number of entries.
Definition at line 181 of file QwInterpolator.h.
References fCurrentEntries.
|
inline |
Get data reduction factor.
Definition at line 195 of file QwInterpolator.h.
References fRedux.
|
inline |
Get the interpolation method.
Definition at line 213 of file QwInterpolator.h.
References fInterpolationMethod.
|
inline |
|
inline |
Get the maximum number of entries.
Definition at line 179 of file QwInterpolator.h.
References fMaximumEntries.
|
inline |
|
inline |
|
inline |
Get the interpolated value at coordinate (zero if out of bounds)
Definition at line 332 of file QwInterpolator.h.
References fNDim, and GetValue().
Referenced by GetValue(), GetValue(), and GetValue().
|
inline |
Get the interpolated value at coordinate (zero if out of bounds)
Definition at line 340 of file QwInterpolator.h.
References GetValue().
|
inline |
Get the interpolated value at coordinate (zero if out of bounds)
Definition at line 347 of file QwInterpolator.h.
References GetValue().
|
inline |
Get the interpolated value at coordinate (zero if out of bounds)
Definition at line 352 of file QwInterpolator.h.
References Check(), fInterpolationMethod, kMultiLinear, kNearestNeighbor, Linear(), and NearestNeighbor().
|
inline |
|
inline |
Return true if the coordinate is in bounds.
Definition at line 248 of file QwInterpolator.h.
References Check().
|
inline |
Return the linearized index based on the point coordinates (unchecked)
Definition at line 409 of file QwInterpolator.h.
References Cell(), f_cell_index, and Index().
Referenced by Get(), Index(), Linear(), NearestNeighbor(), Set(), and 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 572 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 590 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 483 of file QwInterpolator.h.
References Cell(), f_cell_index, f_cell_local, fNDim, Get(), and Index().
Referenced by GetValue().
|
inlineprivate |
Return the cell index closest to the coordinate (could be above) (unchecked)
Definition at line 437 of file QwInterpolator.h.
References Cell(), f_cell_local, and fNDim.
Referenced by NearestNeighbor(), and Set().
|
inlineprivate |
Nearest-neighbor (unchecked)
Perform the nearest-neighbor interpolation (unchecked)
coord | Point coordinates |
value | Interpolated value (reference) |
Definition at line 513 of file QwInterpolator.h.
References f_cell_index, Get(), Index(), and Nearest().
Referenced by GetValue().
|
inline |
Print coverage map for all bins in one dimension.
Definition at line 218 of file QwInterpolator.h.
References Cell(), Coord(), f_cell_index, fMaximumEntries, fNDim, fSize, Get(), mycout, and myendl.
|
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 840 of file QwInterpolator.h.
References QwLog::flush(), fMax, fMaximumEntries, fMin, fNDim, fStep, fValues, mycout, myendl, SetDimensions(), and SetMinimumMaximumStep().
Referenced by QwInterpolator().
|
inline |
Read the grid from text.
Read the grid values from a text stream
stream | Input stream |
Definition at line 746 of file QwInterpolator.h.
References QwLog::flush(), fMax, fMin, fNDim, fStep, fValues, mycout, myendl, SetDimensions(), and SetMinimumMaximumStep().
Referenced by ReadTextFile().
|
inline |
Read the grid from text file.
Definition at line 392 of file QwInterpolator.h.
References ReadText().
|
inline |
Set a single value at a coordinate (false if not possible)
Definition at line 256 of file QwInterpolator.h.
Referenced by Set(), Set(), Set(), Set(), Set(), and Set().
|
inline |
|
inline |
Set a set of values at a coordinate (false if not possible)
Definition at line 267 of file QwInterpolator.h.
References Check(), f_cell_index, fNDim, fSize, fWrap, Index(), Nearest(), and Set().
|
inline |
Set a single value at a grid point (false if out of bounds)
Definition at line 317 of file QwInterpolator.h.
References Set().
|
inline |
Set a set of values at a grid point (false if out of bounds)
Definition at line 322 of file QwInterpolator.h.
References Check(), Index(), and Set().
|
inline |
Set a single value at a linearized index (false if not possible)
Definition at line 303 of file QwInterpolator.h.
References Set().
|
inline |
Set a set of values at a linearized index (false if not possible)
Definition at line 308 of file QwInterpolator.h.
References Check(), fCurrentEntries, and fValues.
|
inline |
|
inline |
Set data reduction factor.
Definition at line 198 of file QwInterpolator.h.
References fRedux.
Referenced by SetDataReductionFactor().
|
inline |
Definition at line 200 of file QwInterpolator.h.
References fNDim, and SetDataReductionFactor().
|
inline |
Set the number of coordinate dimensions and resize vectors.
Definition at line 131 of file QwInterpolator.h.
References fExtent, fMax, fMin, fNDim, fSize, fStep, fWrap, mycerr, and myendl.
Referenced by QwInterpolator(), QwInterpolator(), ReadBinaryFile(), ReadText(), and SetMinimumMaximumStep().
|
inline |
Set the interpolation method.
Definition at line 210 of file QwInterpolator.h.
References fInterpolationMethod.
Referenced by QwInterpolator(), QwInterpolator(), and QwInterpolator().
|
inline |
Set minimum, maximum, and step size to single values.
Definition at line 141 of file QwInterpolator.h.
References fNDim, and SetMinimumMaximumStep().
Referenced by QwInterpolator(), ReadBinaryFile(), ReadText(), and SetMinimumMaximumStep().
|
inline |
Set minimum, maximum, and step size to different values.
Definition at line 147 of file QwInterpolator.h.
References fCurrentEntries, fExtent, fMax, fMaximumEntries, fMin, fNDim, fSize, fStep, fValues, mycerr, myendl, and SetDimensions().
|
inline |
|
inline |
|
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 795 of file QwInterpolator.h.
References QwLog::flush(), fMax, fMin, fNDim, fStep, fValues, mycout, and myendl.
|
inline |
Write the grid as text.
Write the grid values to a text stream
stream | Output stream |
Definition at line 710 of file QwInterpolator.h.
References QwLog::flush(), fMax, fMin, fNDim, fStep, fValues, mycout, and myendl.
Referenced by WriteTextFile(), and WriteTextScreen().
|
inline |
Write the grid to text file.
Definition at line 377 of file QwInterpolator.h.
References WriteText().
|
inline |
Write the grid to screen.
Definition at line 385 of file QwInterpolator.h.
References WriteText().
|
private |
Pre-allocated cell index.
Definition at line 120 of file QwInterpolator.h.
Referenced by Coord(), Index(), Linear(), NearestNeighbor(), PrintCoverage(), QwInterpolator(), QwInterpolator(), QwInterpolator(), Set(), and ~QwInterpolator().
|
private |
Pre-allocated local coordinates.
Definition at line 122 of file QwInterpolator.h.
Referenced by Cell(), Linear(), Nearest(), QwInterpolator(), QwInterpolator(), QwInterpolator(), and ~QwInterpolator().
|
private |
Number of values read in.
Definition at line 115 of file QwInterpolator.h.
Referenced by GetCurrentEntries(), Set(), and 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 109 of file QwInterpolator.h.
Referenced by Cell(), Index(), Index(), SetDimensions(), and SetMinimumMaximumStep().
|
private |
Interpolation method.
Definition at line 126 of file QwInterpolator.h.
Referenced by GetInterpolationMethod(), GetValue(), and SetInterpolationMethod().
|
private |
Maximum in each dimension.
Definition at line 96 of file QwInterpolator.h.
Referenced by Check(), GetMaximum(), ReadBinaryFile(), ReadText(), SetDimensions(), SetMinimumMaximumStep(), WriteBinaryFile(), and WriteText().
|
private |
Maximum number of values.
Definition at line 117 of file QwInterpolator.h.
Referenced by Check(), GetMaximumEntries(), PrintCoverage(), ReadBinaryFile(), and SetMinimumMaximumStep().
|
private |
Minimum in each dimension.
Definition at line 94 of file QwInterpolator.h.
Referenced by Cell(), Check(), Coord(), GetMinimum(), ReadBinaryFile(), ReadText(), SetDimensions(), SetMinimumMaximumStep(), WriteBinaryFile(), and WriteText().
|
private |
Number of dimensions in coordinates.
Definition at line 91 of file QwInterpolator.h.
Referenced by Cell(), Cell(), Check(), Check(), Coord(), GetValue(), Index(), Index(), Linear(), Nearest(), PrintCoverage(), QwInterpolator(), QwInterpolator(), QwInterpolator(), ReadBinaryFile(), ReadText(), Set(), Set(), SetDataReductionFactor(), SetDataReductionFactor(), SetDimensions(), SetMinimumMaximumStep(), SetMinimumMaximumStep(), SetWrapCoordinate(), WriteBinaryFile(), and WriteText().
|
private |
Data reduction factor.
Definition at line 104 of file QwInterpolator.h.
Referenced by GetDataReductionFactor(), SetDataReductionFactor(), and SetDataReductionFactor().
|
private |
Number of points in each dimension.
Definition at line 100 of file QwInterpolator.h.
Referenced by Cell(), Check(), PrintCoverage(), Set(), SetDimensions(), and SetMinimumMaximumStep().
|
private |
Step size in each dimension.
Definition at line 98 of file QwInterpolator.h.
Referenced by Cell(), Coord(), GetStepSize(), ReadBinaryFile(), ReadText(), SetDimensions(), SetMinimumMaximumStep(), WriteBinaryFile(), and WriteText().
|
private |
Table with pointers to arrays of values.
Definition at line 112 of file QwInterpolator.h.
Referenced by Get(), Get(), Get(), ReadBinaryFile(), ReadText(), Set(), SetMinimumMaximumStep(), WriteBinaryFile(), and WriteText().
|
private |
Wrap around this coordinate.
Definition at line 102 of file QwInterpolator.h.
Referenced by Cell(), Check(), GetWrapCoordinate(), Set(), SetDimensions(), SetWrapCoordinate(), and SetWrapCoordinate().