VAPoR  3.0.0
RegularGrid.h
Go to the documentation of this file.
1 #ifndef _RegularGrid_
2 #define _RegularGrid_
3 
4 #include <ostream>
5 #include <vector>
6 #include <vapor/common.h>
7 
8 //
33 //
34 
35 namespace VAPoR {
37 public:
38 
78  const size_t bs[3],
79  const size_t min[3],
80  const size_t max[3],
81  const double extents[6],
82  const bool periodic[3],
83  float ** blks
84  );
85 
99  const size_t bs[3],
100  const size_t min[3],
101  const size_t max[3],
102  const double extents[6],
103  const bool periodic[3],
104  float ** blks,
105  float missing_value
106  );
107 
108  virtual ~RegularGrid();
109 
124  float &AccessIJK(size_t i, size_t j, size_t k) const;
125 
147  virtual float GetValue(double x, double y, double z) const;
148 
164  virtual void GetUserExtents(double extents[6]) const;
165 
181  virtual void GetBoundingBox(
182  const size_t min[3], const size_t max[3], double extents[6]
183  ) const;
184  virtual void GetBoundingBox(
185  const std::vector <size_t> &min, const std::vector <size_t> &max,
186  std::vector <double> &minu, std::vector <double> &maxu
187  ) const;
188 
206  virtual void GetEnclosingRegion(
207  const double minu[3], const double maxu[3], size_t min[3], size_t max[3]
208  ) const;
209 
218  //
219  virtual void GetIJKMinMax(size_t min[3], size_t max[3]) const {
220  min[0] = min[1] = min[2] = 0;
221  max[0] = _max[0]-_min[0]; max[1] = _max[1]-_min[1]; max[2] = _max[2]-_min[2];
222  }
223 
230  //
231  virtual void GetIJKOrigin(size_t min[3]) const {
232  min[0] = _minabs[0]; min[1] = _minabs[1]; min[2] = _minabs[2];
233  }
234 
241  void GetDimensions(size_t dims[3]) const;
242 
249  float GetMissingValue() const {return (_missingValue); };
250 
258  void SetMissingValue(float missing_value) {
259  _missingValue = missing_value; _hasMissing = true;
260  };
261 
269  //
270  bool HasMissingData() const { return (_hasMissing); };
271 
279  virtual int GetInterpolationOrder() const {return _interpolationOrder;};
280 
292  virtual void SetInterpolationOrder(int order);
293 
311  virtual int GetUserCoordinates(
312  size_t i, size_t j, size_t k,
313  double *x, double *y, double *z
314  ) const;
315 
331  virtual void GetIJKIndex(
332  double x, double y, double z,
333  size_t *i, size_t *j, size_t *k
334  ) const;
335 
358  virtual void GetIJKIndexFloor(
359  double x, double y, double z,
360  size_t *i, size_t *j, size_t *k
361  ) const;
362 
371  virtual void GetRange(float range[2]) const;
372 
390  virtual int Reshape(
391  const size_t min[3],
392  const size_t max[3],
393  const bool periodic[3]
394  );
395 
396 
408  virtual bool InsideGrid(double x, double y, double z) const;
409 
410 
419  //
420  virtual void HasPeriodic(bool *idim, bool *jdim, bool *kdim) const {
421  *idim = _periodic[0]; *jdim = _periodic[1]; *kdim = _periodic[2];
422  }
423 
431  //
432  virtual void SetPeriodic(const bool periodic[3]) {
433  _periodic[0] = periodic[0];
434  _periodic[1] = periodic[1];
435  _periodic[2] = periodic[2];
436  }
437 
438  void GetBlockSize(size_t bs[3]) const {
439  bs[0] = _bs[0]; bs[1] = _bs[1]; bs[2] = _bs[2];
440  }
441 
453  virtual void GetMinCellExtents(double *x, double *y, double *z) const {
454  *x = _delta[0]; *y = _delta[1]; *z = _delta[2];
455  };
456 
461  //
462  virtual int GetRank() {
463  int rank = 0;
464  for (int i=0; i<3; i++) if (_min[i]!=_max[i]) rank++;
465  return(rank);
466  }
467 
471  float **GetBlks() const { return(_blks); };
472 
475  size_t GetNumBlks() const { return(_nblocks); };
476 
478  float Next();
479 
481  void ResetItr();
482 
483 
485  public:
486  Iterator (RegularGrid *rg);
487  Iterator ();
488  ~Iterator () {}
489 
490  inline float &operator*() {return (*_itr);}
491 
492  Iterator &operator++(); // ++prefix
493  Iterator operator++(int); // postfix++
494 
495  bool operator==(const Iterator &other);
496  bool operator!=(const Iterator &other);
497 
499  double *x, double *y, double *z
500  ) const { return(_rg->GetUserCoordinates(
501  _x - _rg->_min[0], _y - _rg->_min[1], _z - _rg->_min[2], x,y,z));
502  };
503 
504  private:
505  RegularGrid *_rg;
506  size_t _x, _y, _z; // current index into _rg->_min[3]
507  size_t _xb; // x index within a block
508  float *_itr;
509  bool _end;
510 
511 
512  };
513 
514  Iterator begin() { return( Iterator(this)); }
515  Iterator end() { return(Iterator()); }
516 
517 
519  public:
520  ConstIterator (const RegularGrid *rg);
521  ConstIterator ();
523 
524  inline float &operator*() {return (*_itr);}
525 
526  ConstIterator &operator++(); // ++prefix
527  ConstIterator operator++(int); // postfix++
528 
529  bool operator==(const ConstIterator &other);
530  bool operator!=(const ConstIterator &other);
531 
533  double *x, double *y, double *z
534  ) const { return(_rg->GetUserCoordinates(
535  _x - _rg->_min[0], _y - _rg->_min[1], _z - _rg->_min[2], x,y,z));
536  };
537 
538  private:
539  const RegularGrid *_rg;
540  size_t _x, _y, _z; // current index into _rg->_min[3]
541  size_t _xb; // x index within a block
542  float *_itr;
543  bool _end;
544 
545 
546  };
547 
548  ConstIterator begin() const { return( ConstIterator(this)); }
549  ConstIterator end() const { return(ConstIterator()); }
550 
551 
552 
553 
554 
555  VDF_API friend std::ostream &operator<<(std::ostream &o, const RegularGrid &rg);
556 
557 
558 
559 protected:
560 
561  float &_AccessIJK(float **blks, size_t i, size_t j, size_t k) const;
562  void _ClampCoord(double &x, double &y, double &z) const;
563  void _SetExtents(const double extents[6]);
564 
565 private:
566  size_t _bs[3]; // dimensions of each block
567  size_t _bdims[3]; // dimensions (specified in blocks) of ROI
568  size_t _min[3]; // ijk offset of first voxel in ROI (relative to ROI)
569  size_t _max[3]; // ijk offset of last voxel in ROI (relative to ROI)
570  size_t _minabs[3]; // ijk offset of first voxel in ROI (absolute coords)
571  size_t _maxabs[3]; // ijk offset of last voxel in ROI (absolute coords)
572  double _minu[3];
573  double _maxu[3]; // User coords of first and last voxel
574  double _delta[3]; // increment between grid points in user coords
575  bool _periodic[3]; // periodicity of boundaries
576  float _missingValue;
577  bool _hasMissing;
578  int _interpolationOrder; // Order of interpolation
579  size_t _x, _y, _z, _xb;
580  bool _end;
581  size_t _nblocks; // num blocks allocated to _blks
582  float *_itr;
583  float **_blks;
584 
585  int _RegularGrid(
586  const size_t bs[3], const size_t min[3], const size_t max[3],
587  const double extents[6], const bool periodic[3], float ** blks
588  );
589  float _GetValueNearestNeighbor(double x, double y, double z) const;
590  float _GetValueLinear(double x, double y, double z) const;
591 
592 };
593 };
594 #endif
bool HasMissingData() const
Definition: RegularGrid.h:270
virtual void GetIJKOrigin(size_t min[3]) const
Definition: RegularGrid.h:231
virtual void HasPeriodic(bool *idim, bool *jdim, bool *kdim) const
Definition: RegularGrid.h:420
virtual void GetIJKMinMax(size_t min[3], size_t max[3]) const
Definition: RegularGrid.h:219
ConstIterator end() const
Definition: RegularGrid.h:549
virtual void GetMinCellExtents(double *x, double *y, double *z) const
Definition: RegularGrid.h:453
float ** GetBlks() const
Definition: RegularGrid.h:471
void GetBlockSize(size_t bs[3]) const
Definition: RegularGrid.h:438
void SetMissingValue(float missing_value)
Definition: RegularGrid.h:258
size_t GetNumBlks() const
Definition: RegularGrid.h:475
int GetUserCoordinates(double *x, double *y, double *z) const
Definition: RegularGrid.h:532
float GetMissingValue() const
Definition: RegularGrid.h:249
ConstIterator begin() const
Definition: RegularGrid.h:548
virtual int GetInterpolationOrder() const
Definition: RegularGrid.h:279
#define VDF_API
Definition: DC.h:10
int GetUserCoordinates(double *x, double *y, double *z) const
Definition: RegularGrid.h:498
Iterator begin()
Definition: RegularGrid.h:514
virtual void SetPeriodic(const bool periodic[3])
Definition: RegularGrid.h:432
virtual int GetRank()
Definition: RegularGrid.h:462