1 #ifndef BLI2DNONUNIF_OBJECT_GRID_H_
2 #define BLI2DNONUNIF_OBJECT_GRID_H_
48 template<
typename ZObject,
typename IndexType = int,
typename XType = double,
60 const std::vector<YType>* Y,
const std::vector<ZObject>* Z,
65 inline XType
x_min()
const {
return fX->front(); }
68 inline XType
x_max()
const {
return fX->back(); }
71 inline YType
y_min()
const {
return fY->front(); }
74 inline YType
y_max()
const {
return fY->back(); }
80 IndexType
index_Z(IndexType ix, IndexType iy)
const {
81 IndexType num_y_points =
fY->size();
83 return (num_y_points * ix) + iy;
91 IndexType ix_lo, ix_hi, iy_lo, iy_hi;
97 evalx = std::min(x,
x_max());
98 evalx = std::max(evalx,
x_min());
103 evaly = std::min(y,
y_max());
104 evaly = std::max(evaly,
y_min());
116 XType x1 =
fX->at( ix_lo );
117 XType x2 =
fX->at( ix_hi );
118 YType y1 =
fY->at( iy_lo );
119 YType y2 =
fY->at( iy_hi );
123 const ZObject& z11 =
fZ->at( this->
index_Z(ix_lo, iy_lo) );
124 const ZObject& z21 =
fZ->at( this->
index_Z(ix_hi, iy_lo) );
125 const ZObject& z12 =
fZ->at( this->
index_Z(ix_lo, iy_hi) );
126 const ZObject& z22 =
fZ->at( this->
index_Z(ix_hi, iy_hi) );
129 ZObject z1 = z11 * (y2-evaly)/(y2-y1) + z12 * (evaly-y1)/(y2-y1);
130 ZObject z2 = z21 * (y2-evaly)/(y2-y1) + z22 * (evaly-y1)/(y2-y1);
131 ZObject z = z1 * (x2-evalx)/(x2-x1) + z2 * (evalx-x1)/(x2-x1);
138 const std::vector<XType>*
fX;
139 const std::vector<YType>*
fY;
142 const std::vector<ZObject>*
fZ;
162 Type val,
int& lower_index,
int& upper_index)
const
168 typedef typename std::vector<Type>::const_iterator Iterator;
169 Iterator begin = vec->begin();
170 Iterator end = vec->end();
174 Iterator not_less_point = std::lower_bound(begin, end, val);
176 Iterator lower_point;
179 if (not_less_point == begin) {
182 if (*begin != val) within =
false;
184 else if (not_less_point == end) {
187 lower_point = end - 2;
191 lower_point = not_less_point - 1;
194 lower_index = std::distance(begin, lower_point);
195 upper_index = lower_index + 1;
IndexType index_Z(IndexType ix, IndexType iy) const
YType y_max() const
Retrieve the maximum y value.
const std::vector< ZObject > * fZ
Pointer to the vector of z coordinate objects.
YType y_min() const
Retrieve the minimum y value.
const std::vector< XType > * fX
Pointer to the vector of x coordinates.
XType x_max() const
Retrieve the maximum x value.
A class template that performs bilinear interpolation on a non-uniform grid with an implementation si...
const std::vector< YType > * fY
Pointer to the vector of y coordinates.
XType x_min() const
Retrieve the minimum x value.
bool get_bound_indices(const std::vector< Type > *vec, Type val, int &lower_index, int &upper_index) const
BLI2DNonUnifObjectGrid(const std::vector< XType > *X, const std::vector< YType > *Y, const std::vector< ZObject > *Z, bool extrapolate=false)
ZObject interpolate(double x, double y) const