17 #pragma warning(disable : 4661 4251)
86 Grid(
const std::vector<size_t> &dims,
const std::vector<size_t> &bs,
const std::vector<float *> &blks,
size_t topology_dimension);
87 Grid(
const DimsType &dims,
const DimsType &bs,
const std::vector<float *> &blks,
size_t topology_dimension);
163 const std::vector<size_t> &
GetBlockSize()
const {
return (_bsDeprecated); }
168 const std::vector<float *> &
GetBlks()
const {
return (_blks); };
189 CopyToArr3(indices, a);
190 return (GetValueAtIndex(a));
202 virtual void SetValue(
const size_t indices[3],
float value)
205 CopyToArr3(indices, GetNodeDimensions().size(), i3);
218 virtual float AccessIJK(
size_t i,
size_t j = 0,
size_t k = 0)
const;
248 virtual float GetValue(
const std::vector<double> &coords)
const
251 CopyToArr3(coords, c3);
252 return (GetValue(c3));
257 virtual float GetValue(
const double coords[])
const
260 CopyToArr3(coords, GetGeometryDim(), c3);
261 return (GetValue(c3));
266 double coords[] = {x, y, 0.0};
267 return (GetValue(coords));
269 virtual float GetValue(
double x,
double y,
double z)
const
271 double coords[] = {x, y, z};
272 return (GetValue(coords));
297 GetUserExtents(minu3, maxu3);
298 CopyFromArr3(minu3, minu);
299 CopyFromArr3(maxu3, maxu);
304 virtual void GetUserExtents(std::vector<double> &minu, std::vector<double> &maxu)
const
308 GetUserExtents(minu3, maxu3);
309 CopyFromArr3(minu3, minu);
310 CopyFromArr3(maxu3, maxu);
316 minu.resize(GetGeometryDim());
317 maxu.resize(GetGeometryDim());
348 virtual void GetBoundingBox(
const std::vector<size_t> &min,
const std::vector<size_t> &max, std::vector<double> &minu, std::vector<double> &maxu)
const
350 VAssert(min.size() == max.size());
356 CopyToArr3(min, min3);
357 CopyToArr3(max, max3);
358 GetBoundingBox(min3, max3, minu3, maxu3);
359 CopyFromArr3(minu3, minu);
360 CopyFromArr3(maxu3, maxu);
473 CopyToArr3(indices, GetNodeDimensions().size(), indices3);
474 GetUserCoordinates(indices3, coords3);
475 CopyFromArr3(coords3, coords);
478 virtual void GetUserCoordinates(
const std::vector<size_t> &indices, std::vector<double> &coords)
const
482 CopyToArr3(indices, indices3);
483 GetUserCoordinates(indices3, coords3);
484 CopyFromArr3(coords3, coords);
489 virtual void GetUserCoordinates(
size_t i,
size_t j,
size_t k,
double &x,
double &y,
double &z)
const;
515 CopyToArr3(coords, GetGeometryDim(), c3);
516 bool status = GetIndicesCell(c3, i3);
517 CopyFromArr3(i3, indices);
523 virtual bool GetIndicesCell(
const std::vector<double> &coords, std::vector<size_t> &indices)
const
527 CopyToArr3(coords, c3);
528 bool status = GetIndicesCell(c3, i3);
529 CopyFromArr3(i3, indices);
549 virtual void GetRange(std::vector<size_t> min, std::vector<size_t> max,
float range[2])
const
553 CopyToArr3(min, min3);
554 CopyToArr3(max, max3);
555 GetRange(min3, max3, range);
574 CopyToArr3(coords, GetGeometryDim(), c3);
575 return (InsideGrid(c3));
580 virtual bool InsideGrid(
const std::vector<double> &coords)
const
583 CopyToArr3(coords, c3);
584 return (InsideGrid(c3));
609 virtual bool GetCellNodes(
const size_t cindices[], std::vector<DimsType> &nodes)
const
612 CopyToArr3(cindices, GetCellDimensions().size(), i3);
613 return (GetCellNodes(i3, nodes));
667 virtual void ClampCoord(
const double coords[3],
double cCoords[3])
const
669 CoordType c3 = {coords[0], coords[1], coords[2]};
711 for (; i < periodic.size() && i < GetGeometryDim(); i++) { _periodic.push_back(periodic[i]); }
712 for (; i < GetGeometryDim(); i++) { _periodic.push_back(
false); }
718 virtual const std::vector<bool> &
GetPeriodic()
const {
return (_periodic); }
785 double left = verts[0];
786 double right = verts[0];
787 double top = verts[1];
788 double bottom = verts[1];
790 for (
int i = 1; i < n; i++) {
791 if (verts[i * 2 + 0] < left) left = verts[i * 2 + 0];
792 if (verts[i * 2 + 0] > right) right = verts[i * 2 + 0];
793 if (verts[i * 2 + 1] < top) top = verts[i * 2 + 1];
794 if (verts[i * 2 + 1] > bottom) bottom = verts[i * 2 + 1];
797 return ((left <= pt[0]) && (right >= pt[0]) && (top <= pt[1]) && (bottom >= pt[1]));
821 if (_min == _max)
return (
true);
822 for (
int i = 0; i < _min.size() && i < pt.size(); i++) {
823 if (pt[i] < _min[i] || pt[i] > _max[i])
return (
false);
829 if (_min == _max)
return (
true);
830 for (
int i = 0; i < _min.size(); i++) {
831 if (pt[i] < _min[i] || pt[i] > _max[i])
return (
false);
836 bool Enabled()
const {
return (_min != _max); }
855 virtual void next(
const long &offset) = 0;
858 virtual bool equal(
const void *other)
const = 0;
859 virtual std::unique_ptr<AbstractIterator>
clone()
const = 0;
873 _impl = rhs._impl->clone();
884 if (
this != &rhs) { _impl = std::move(rhs._impl); }
923 std::unique_ptr<AbstractIterator<T>> _impl;
977 virtual void next(
const long &offset);
979 virtual const void *
address()
const {
return this; };
981 virtual bool equal(
const void *rhs)
const
984 return (_index == itrptr->
_index);
987 virtual std::unique_ptr<ConstNodeIteratorAbstract>
clone()
const {
return std::unique_ptr<ConstNodeIteratorAbstract>(
new ConstNodeIteratorSG(*
this)); };
1004 virtual void next(
const long &offset);
1006 virtual std::unique_ptr<ConstNodeIteratorAbstract>
clone()
const {
return std::unique_ptr<ConstNodeIteratorAbstract>(
new ConstNodeIteratorBoxSG(*
this)); };
1031 CopyToArr3(minu, minuCT);
1032 CopyToArr3(maxu, maxuCT);
1033 return ConstNodeBegin(minuCT, maxuCT);
1050 virtual void next(
const long &offset);
1052 virtual const void *
address()
const {
return this; };
1054 virtual bool equal(
const void *rhs)
const
1058 return (_index == itrptr->
_index);
1061 virtual std::unique_ptr<ConstCellIteratorAbstract>
clone()
const {
return std::unique_ptr<ConstCellIteratorAbstract>(
new ConstCellIteratorSG(*
this)); };
1078 virtual void next(
const long &offset);
1080 virtual std::unique_ptr<ConstCellIteratorAbstract>
clone()
const {
return std::unique_ptr<ConstCellIteratorAbstract>(
new ConstCellIteratorBoxSG(*
this)); };
1085 bool _cellInsideBox(
const size_t cindices[])
const;
1106 CopyToArr3(minu, minuCT);
1107 CopyToArr3(maxu, maxuCT);
1108 return ConstCellBegin(minuCT, maxuCT);
1156 std::swap(a._blks, b._blks);
1157 std::swap(a._dims3d, b._dims3d);
1158 std::swap(a._bdims3d, b._bdims3d);
1159 std::swap(a._bs3d, b._bs3d);
1160 std::swap(a._blocksize, b._blocksize);
1161 std::swap(a._coordItr, b._coordItr);
1162 std::swap(a._index, b._index);
1163 std::swap(a._lastIndex, b._lastIndex);
1164 std::swap(a._xb, b._xb);
1165 std::swap(a._itr, b._itr);
1166 std::swap(a._pred, b._pred);
1170 std::vector<float *> _blks;
1191 Iterator begin(
const std::vector<double> &minu,
const std::vector<double> &maxu)
1194 CopyToArr3(minu, minuCT);
1195 CopyToArr3(maxu, maxuCT);
1196 return begin(minuCT, maxuCT);
1208 CopyToArr3(minu, minuCT);
1209 CopyToArr3(maxu, maxuCT);
1210 return cbegin(minuCT, maxuCT);
1216 template<
typename T>
static void CopyToArr3(
const std::vector<T> &src, std::array<T, 3> &dst)
1218 for (
int i = 0; i < src.size() && i < dst.size(); i++) { dst[i] = src[i]; }
1221 template<
typename T>
static void CopyToArr3(
const T *src,
size_t n, std::array<T, 3> &dst)
1223 for (
int i = 0; i < n && i < dst.size(); i++) { dst[i] = src[i]; }
1225 template<
typename T>
static void CopyFromArr3(
const std::array<T, 3> &src, std::vector<T> &dst)
1227 dst.resize(src.size());
1228 for (
int i = 0; i < src.size() && i < dst.size(); i++) { dst[i] = src[i]; }
1230 template<
typename T>
static void CopyFromArr3(
const std::array<T, 3> &src, T *dst)
1232 for (
int i = 0; i < src.size(); i++) { dst[i] = src[i]; }
1247 cIndices = {0, 0, 0};
1249 for (
int i = 0; i < dims.size(); i++) {
1250 cIndices[i] = indices[i];
1251 if (cIndices[i] >= dims[i]) { cIndices[i] = dims[i] - 1; }
1257 cIndices = {0, 0, 0};
1259 for (
int i = 0; i < dims.size(); i++) {
1260 cIndices[i] = indices[i];
1261 if (cIndices[i] >= dims[i]) {
1262 assert(dims[i] > 0);
1263 cIndices[i] = dims[i] - 1;
1270 float TrilinearInterpolate(
size_t i,
size_t j,
size_t k,
const double xwgt,
const double ywgt,
const double zwgt)
const;
1275 DimsType _bdims = {{1, 1, 1}};
1276 std::vector<size_t> _bsDeprecated;
1277 std::vector<size_t> _bdimsDeprecated;
1278 std::vector<float *> _blks;
1279 std::vector<bool> _periodic;
1281 size_t _topologyDimension = 0;
1282 float _missingValue = std::numeric_limits<float>::infinity();
1283 bool _hasMissing =
false;
1284 int _interpolationOrder = 1;
1285 long _nodeIDOffset = 0;
1286 long _cellIDOffset = 0;
1287 mutable CoordType _minuCache = {{std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity()}};
1288 mutable CoordType _maxuCache = {{std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity()}};
1290 void _grid(
const DimsType &dims,
const DimsType &bs,
const std::vector<float *> &blks,
size_t topology_dimension);
1293template void Grid::CopyToArr3<size_t>(
const std::vector<size_t> &src, std::array<size_t, 3> &dst);
virtual T & deref() const =0
virtual std::unique_ptr< AbstractIterator > clone() const =0
virtual const void * address() const =0
virtual bool equal(const void *other) const =0
virtual void next(const long &offset)=0
virtual ~AbstractIterator()
virtual void next(const long &offset)
virtual std::unique_ptr< ConstCellIteratorAbstract > clone() const
ConstCellIteratorBoxSG(const Grid *g, const CoordType &minu, const CoordType &maxu)
virtual ~ConstCellIteratorBoxSG()
ConstCellIteratorBoxSG(const ConstCellIteratorBoxSG &rhs)
virtual ConstIndexType & deref() const
virtual bool equal(const void *rhs) const
virtual const void * address() const
ConstCellIteratorSG(const ConstCellIteratorSG &rhs)
virtual std::unique_ptr< ConstCellIteratorAbstract > clone() const
virtual void next(const long &offset)
virtual ~ConstCellIteratorSG()
ConstCellIteratorSG(const Grid *g, bool begin)
ConstNodeIteratorBoxSG(const Grid *g, const CoordType &minu, const CoordType &maxu)
virtual ~ConstNodeIteratorBoxSG()
virtual void next(const long &offset)
virtual std::unique_ptr< ConstNodeIteratorAbstract > clone() const
ConstNodeIteratorBoxSG(const ConstNodeIteratorBoxSG &rhs)
virtual bool equal(const void *rhs) const
virtual void next(const long &offset)
virtual std::unique_ptr< ConstNodeIteratorAbstract > clone() const
ConstNodeIteratorSG(const ConstNodeIteratorSG &rhs)
virtual ~ConstNodeIteratorSG()
virtual ConstIndexType & deref() const
virtual const void * address() const
ConstNodeIteratorSG(const Grid *g, bool begin)
ForwardIterator< T > & operator++()
ForwardIterator< T > & operator=(ForwardIterator< T > &rhs)=delete
const ConstCoordItr & GetCoordItr()
ForwardIterator< T > & operator=(ForwardIterator< T > rhs)
ForwardIterator(T *rg, bool begin=true, const CoordType &minu={0.0, 0.0, 0.0}, const CoordType &maxu={0.0, 0.0, 0.0})
ForwardIterator(const ForwardIterator< T > &)=default
ForwardIterator(ForwardIterator< T > &&rhs)
friend void swap(Grid::ForwardIterator< T > &a, Grid::ForwardIterator< T > &b)
ForwardIterator< T > operator++(int)
bool operator==(const ForwardIterator< T > &rhs) const
ForwardIterator< T > & operator+=(const long int &offset)
bool operator!=(const ForwardIterator< T > &rhs)
ForwardIterator< T > operator+(const long int &offset) const
bool operator()(const CoordType &pt) const
InsideBox(const CoordType &min, const CoordType &max)
bool operator()(const double pt[]) const
bool operator!=(const PolyIterator &rhs) const
PolyIterator operator+(const long &offset) const
PolyIterator & operator=(PolyIterator &&rhs)
PolyIterator(PolyIterator const &rhs)
PolyIterator(PolyIterator &&rhs)
PolyIterator operator++(int)
PolyIterator(std::unique_ptr< AbstractIterator< T > > it)
PolyIterator & operator=(PolyIterator const &rhs)
PolyIterator & operator++()
bool operator==(const PolyIterator &rhs) const
const T & operator*() const
PolyIterator & operator+=(const long &offset)
Abstract base class for a 2D or 3D structured or unstructured grid.
virtual float GetValue(const CoordType &coords) const
Grid(const DimsType &dims, const DimsType &bs, const std::vector< float * > &blks, size_t topology_dimension)
virtual void GetUserExtents(CoordType &minu, CoordType &maxu) const
virtual ConstNodeIterator ConstNodeBegin(const std::vector< double > &minu, const std::vector< double > &maxu) const
virtual void SetInterpolationOrder(int order)
const std::vector< size_t > & GetBlockSize() const
void SetValueIJK(size_t i, size_t j, size_t k, float v)
virtual void GetUserCoordinates(const std::vector< size_t > &indices, std::vector< double > &coords) const
virtual bool GetCellNodes(const size_t cindices[], std::vector< DimsType > &nodes) const
virtual std::string GetType() const =0
virtual void SetPeriodic(const std::vector< bool > &periodic)
virtual ConstNodeIterator ConstNodeBegin(const CoordType &minu, const CoordType &maxu) const
virtual float GetMissingValue() const
Grid::PolyIterator< ConstIndexType > ConstNodeIterator
static size_t GetNumDimensions(DimsType dims)
virtual void GetUserExtentsHelper(CoordType &minu, CoordType &maxu) const =0
virtual ConstCoordItr ConstCoordBegin() const =0
Return constant grid coordinate iterator.
virtual float GetValue(const double coords[]) const
bool HasMissingData() const
Iterator begin(const std::vector< double > &minu, const std::vector< double > &maxu)
virtual size_t GetMaxVertexPerFace() const =0
virtual float GetValue(const std::vector< double > &coords) const
virtual size_t GetGeometryDim() const =0
Grid::PolyIterator< ConstIndexType > ConstCellIterator
Cell index iterator. Iterates over grid cell indices.
ConstIterator cbegin(const std::vector< double > &minu, const std::vector< double > &maxu)
virtual bool GetIndicesCell(const double coords[3], size_t indices[3]) const
virtual void GetUserCoordinates(size_t i, size_t j, size_t k, double &x, double &y, double &z) const
virtual int GetInterpolationOrder() const
virtual void SetNodeOffset(long offset)
virtual void SetValue(const size_t indices[3], float value)
virtual float GetValueAtIndex(const DimsType &indices) const
virtual bool InsideGrid(const double coords[3]) const
void SetMissingValue(float missing_value)
virtual bool GetIndicesCell(const std::vector< double > &coords, std::vector< size_t > &indices) const
const DimsType ConstIndexType
virtual const DimsType & GetCellDimensions() const =0
virtual float GetValueLinear(const CoordType &coords) const =0
virtual void GetUserCoordinates(const DimsType &indices, CoordType &coords) const =0
virtual void GetRange(std::vector< size_t > min, std::vector< size_t > max, float range[2]) const
virtual void SetCellOffset(long offset)
virtual bool GetNodeCells(const DimsType &indices, std::vector< DimsType > &cells) const =0
ConstIterator cbegin() const
virtual ConstCellIterator ConstCellBegin(const CoordType &minu, const CoordType &maxu) const
virtual void GetUserExtents(double minu[3], double maxu[3]) const
virtual float GetValueNearestNeighbor(const CoordType &coords) const =0
virtual float AccessIJK(size_t i, size_t j=0, size_t k=0) const
Iterator begin(const CoordType &minu, const CoordType &maxu)
float TrilinearInterpolate(size_t i, size_t j, size_t k, const double xwgt, const double ywgt, const double zwgt) const
virtual bool GetEnclosingRegion(const CoordType &minu, const CoordType &maxu, DimsType &min, DimsType &max) const =0
Grid::ForwardIterator< Grid const > ConstIterator
size_t GetNumDimensions() const
VDF_API friend std::ostream & operator<<(std::ostream &o, const Grid &g)
virtual bool GetCellNodes(const DimsType &cindices, std::vector< DimsType > &nodes) const =0
Grid(const std::vector< size_t > &dims, const std::vector< size_t > &bs, const std::vector< float * > &blks, size_t topology_dimension)
virtual bool HasInvertedCoordinateSystemHandiness() const
virtual void ClampCellIndex(const DimsType &indices, DimsType &cIndices) const
virtual long GetNodeOffset() const
const CoordType ConstCoordType
Grid::AbstractIterator< ConstIndexType > ConstCellIteratorAbstract
virtual const size_t GetNumNodeDimensions() const =0
const std::vector< float * > & GetBlks() const
virtual float GetValue(double x, double y, double z) const
virtual void GetBoundingBox(const DimsType &min, const DimsType &max, CoordType &minu, CoordType &maxu) const =0
void SetValueIJK(size_t i, size_t j, float v)
virtual const std::vector< bool > & GetPeriodic() const
virtual bool InsideGrid(const CoordType &coords) const =0
virtual DimsType GetCoordDimensions(size_t dim) const =0
virtual const size_t GetNumCellDimensions() const =0
static void CopyToArr3(const T *src, size_t n, std::array< T, 3 > &dst)
virtual void GetRange(float range[2]) const
static void CopyFromArr3(const std::array< T, 3 > &src, T *dst)
const std::vector< size_t > GetDimensionInBlks() const
virtual void ClampIndex(const DimsType &indices, DimsType &cIndices) const
virtual void SetValue(const DimsType &indices, float value)
virtual bool InsideGrid(const std::vector< double > &coords) const
virtual float * GetValuePtrAtIndex(const std::vector< float * > &blks, const DimsType &indices) const
virtual float GetValueAtIndex(const std::vector< size_t > &indices) const
static void CopyFromArr3(const std::array< T, 3 > &src, std::vector< T > &dst)
virtual long GetCellOffset() const
ConstIterator cend() const
virtual size_t GetTopologyDim() const
virtual float GetValue(double x, double y) const
virtual ConstNodeIterator ConstNodeEnd() const
virtual void GetUserCoordinates(size_t i, double &x, double &y, double &z) const
void SetValueIJK(size_t i, float v)
virtual size_t GetMaxVertexPerCell() const =0
virtual bool GetCellNeighbors(const DimsType &cindices, std::vector< DimsType > &cells) const =0
static void CopyToArr3(const std::vector< T > &src, std::array< T, 3 > &dst)
static bool PointInsideBoundingRectangle(const double pt[], const double verts[], int n)
virtual DimsType GetMinAbs() const
virtual bool GetIndicesCell(const CoordType &coords, DimsType &indices) const =0
virtual void ClampIndex(const std::vector< size_t > &dims, const DimsType indices, DimsType &cIndices) const
virtual ConstCoordItr ConstCoordEnd() const =0
const DimsType & GetDimensions() const
virtual ConstNodeIterator ConstNodeBegin() const
virtual void SetMinAbs(const DimsType &minAbs)
virtual ConstCellIterator ConstCellBegin(const std::vector< double > &minu, const std::vector< double > &maxu) const
virtual ConstCellIterator ConstCellBegin() const
virtual void GetUserCoordinates(const size_t indices[], double coords[]) const
float BilinearInterpolate(size_t i, size_t j, size_t k, const double xwgt, const double ywgt) const
Grid::AbstractIterator< ConstCoordType > ConstCoordItrAbstract
virtual const DimsType & GetNodeDimensions() const =0
Grid::ForwardIterator< Grid > Iterator
virtual ConstCellIterator ConstCellEnd() const
virtual void GetUserExtents(std::vector< double > &minu, std::vector< double > &maxu) const
Grid::PolyIterator< ConstCoordType > ConstCoordItr
static DimsType Dims(const DimsType &min, const DimsType &max)
virtual void ClampCoord(const double coords[3], double cCoords[3]) const
void SetHasMissingValues(bool flag)
virtual void GetBoundingBox(const std::vector< size_t > &min, const std::vector< size_t > &max, std::vector< double > &minu, std::vector< double > &maxu) const
virtual void ClampIndex(const DimsType &dims, const DimsType indices, DimsType &cIndices) const
ConstIterator cbegin(const CoordType &minu, const CoordType &maxu) const
virtual void GetUserCoordinates(size_t i, size_t j, double &x, double &y, double &z) const
virtual void GetRange(const DimsType &min, const DimsType &max, float range[2]) const
virtual void ClampCoord(const CoordType &coords, CoordType &cCoords) const =0
Grid::AbstractIterator< ConstIndexType > ConstNodeIteratorAbstract
std::array< double, 3 > CoordType
Type for specifying floating point coordinates.
std::array< size_t, 3 > DimsType
Type for specifying integer indices.