VAPoR  0.1
RegularGrid.h
Go to the documentation of this file.
1 #ifndef _RegularGrid_
2 #define _RegularGrid_
3 
4 #include <ostream>
5 #include <vapor/common.h>
6 
7 //
32 //
33 
34 namespace VAPoR {
36 public:
37 
77  const size_t bs[3],
78  const size_t min[3],
79  const size_t max[3],
80  const double extents[6],
81  const bool periodic[3],
82  float ** blks
83  );
84 
98  const size_t bs[3],
99  const size_t min[3],
100  const size_t max[3],
101  const double extents[6],
102  const bool periodic[3],
103  float ** blks,
104  float missing_value
105  );
106 
107  virtual ~RegularGrid();
108 
123  float &AccessIJK(size_t i, size_t j, size_t k) const;
124 
146  virtual float GetValue(double x, double y, double z) const;
147 
163  virtual void GetUserExtents(double extents[6]) const;
164 
180  virtual void GetBoundingBox(
181  const size_t min[3], const size_t max[3], double extents[6]
182  ) const;
183 
201  virtual void GetEnclosingRegion(
202  const double minu[3], const double maxu[3], size_t min[3], size_t max[3]
203  ) const;
204 
213  //
214  virtual void GetIJKMinMax(size_t min[3], size_t max[3]) const {
215  min[0] = min[1] = min[2] = 0;
216  max[0] = _max[0]-_min[0]; max[1] = _max[1]-_min[1]; max[2] = _max[2]-_min[2];
217  }
218 
225  //
226  virtual void GetIJKOrigin(size_t min[3]) const {
227  min[0] = _minabs[0]; min[1] = _minabs[1]; min[2] = _minabs[2];
228  }
229 
236  void GetDimensions(size_t dims[3]) const;
237 
244  float GetMissingValue() const {return (_missingValue); };
245 
253  void SetMissingValue(float missing_value) {
254  _missingValue = missing_value; _hasMissing = true;
255  };
256 
264  //
265  bool HasMissingData() const { return (_hasMissing); };
266 
274  virtual int GetInterpolationOrder() const {return _interpolationOrder;};
275 
287  virtual void SetInterpolationOrder(int order);
288 
306  virtual int GetUserCoordinates(
307  size_t i, size_t j, size_t k,
308  double *x, double *y, double *z
309  ) const;
310 
326  virtual void GetIJKIndex(
327  double x, double y, double z,
328  size_t *i, size_t *j, size_t *k
329  ) const;
330 
353  virtual void GetIJKIndexFloor(
354  double x, double y, double z,
355  size_t *i, size_t *j, size_t *k
356  ) const;
357 
366  virtual void GetRange(float range[2]) const;
367 
385  virtual int Reshape(
386  const size_t min[3],
387  const size_t max[3],
388  const bool periodic[3]
389  );
390 
391 
403  virtual bool InsideGrid(double x, double y, double z) const;
404 
405 
414  //
415  virtual void HasPeriodic(bool *idim, bool *jdim, bool *kdim) const {
416  *idim = _periodic[0]; *jdim = _periodic[1]; *kdim = _periodic[2];
417  }
418 
426  //
427  virtual void SetPeriodic(const bool periodic[3]) {
428  _periodic[0] = periodic[0];
429  _periodic[1] = periodic[1];
430  _periodic[2] = periodic[2];
431  }
432 
433  void GetBlockSize(size_t bs[3]) const {
434  bs[0] = _bs[0]; bs[1] = _bs[1]; bs[2] = _bs[2];
435  }
436 
448  virtual void GetMinCellExtents(double *x, double *y, double *z) const {
449  *x = _delta[0]; *y = _delta[1]; *z = _delta[2];
450  };
451 
455  float **GetBlks() const { return(_blks); };
456 
459  size_t GetNumBlks() const { return(_nblocks); };
460 
462  float Next();
463 
465  void ResetItr();
466 
467 
469  public:
470  Iterator (RegularGrid *rg);
471  Iterator ();
472  ~Iterator () {}
473 
474  inline float &operator*() {return (*_itr);}
475 
476  Iterator &operator++(); // ++prefix
477  Iterator operator++(int); // postfix++
478 
479  bool operator==(const Iterator &other);
480  bool operator!=(const Iterator &other);
481 
483  double *x, double *y, double *z
484  ) const { return(_rg->GetUserCoordinates(
485  _x - _rg->_min[0], _y - _rg->_min[1], _z - _rg->_min[2], x,y,z));
486  };
487 
488  private:
489  RegularGrid *_rg;
490  size_t _x, _y, _z; // current index into _rg->_min[3]
491  size_t _xb; // x index within a block
492  float *_itr;
493  bool _end;
494 
495 
496  };
497 
498  Iterator begin() { return( Iterator(this)); }
499  Iterator end() { return(Iterator()); }
500 
501 
503  public:
504  ConstIterator (const RegularGrid *rg);
505  ConstIterator ();
507 
508  inline float &operator*() {return (*_itr);}
509 
510  ConstIterator &operator++(); // ++prefix
511  ConstIterator operator++(int); // postfix++
512 
513  bool operator==(const ConstIterator &other);
514  bool operator!=(const ConstIterator &other);
515 
517  double *x, double *y, double *z
518  ) const { return(_rg->GetUserCoordinates(
519  _x - _rg->_min[0], _y - _rg->_min[1], _z - _rg->_min[2], x,y,z));
520  };
521 
522  private:
523  const RegularGrid *_rg;
524  size_t _x, _y, _z; // current index into _rg->_min[3]
525  size_t _xb; // x index within a block
526  float *_itr;
527  bool _end;
528 
529 
530  };
531 
532  ConstIterator begin() const { return( ConstIterator(this)); }
533  ConstIterator end() const { return(ConstIterator()); }
534 
535 
536 
537 
538 
539  VDF_API friend std::ostream &operator<<(std::ostream &o, const RegularGrid &rg);
540 
541 
542 
543 protected:
544 
545  float &_AccessIJK(float **blks, size_t i, size_t j, size_t k) const;
546  void _ClampCoord(double &x, double &y, double &z) const;
547  void _SetExtents(const double extents[6]);
548 
549 private:
550  size_t _bs[3]; // dimensions of each block
551  size_t _bdims[3]; // dimensions (specified in blocks) of ROI
552  size_t _min[3]; // ijk offset of first voxel in ROI (relative to ROI)
553  size_t _max[3]; // ijk offset of last voxel in ROI (relative to ROI)
554  size_t _minabs[3]; // ijk offset of first voxel in ROI (absolute coords)
555  size_t _maxabs[3]; // ijk offset of last voxel in ROI (absolute coords)
556  double _minu[3];
557  double _maxu[3]; // User coords of first and last voxel
558  double _delta[3]; // increment between grid points in user coords
559  bool _periodic[3]; // periodicity of boundaries
560  float _missingValue;
561  bool _hasMissing;
562  int _interpolationOrder; // Order of interpolation
563  size_t _x, _y, _z, _xb;
564  bool _end;
565  size_t _nblocks; // num blocks allocated to _blks
566  float *_itr;
567  float **_blks;
568 
569  int _RegularGrid(
570  const size_t bs[3], const size_t min[3], const size_t max[3],
571  const double extents[6], const bool periodic[3], float ** blks
572  );
573  float _GetValueNearestNeighbor(double x, double y, double z) const;
574  float _GetValueLinear(double x, double y, double z) const;
575 
576 };
577 };
578 #endif
bool HasMissingData() const
Definition: RegularGrid.h:265
virtual void GetIJKOrigin(size_t min[3]) const
Definition: RegularGrid.h:226
#define VDF_API
Definition: common.h:61
virtual void HasPeriodic(bool *idim, bool *jdim, bool *kdim) const
Definition: RegularGrid.h:415
virtual void GetIJKMinMax(size_t min[3], size_t max[3]) const
Definition: RegularGrid.h:214
ConstIterator end() const
Definition: RegularGrid.h:533
virtual void GetMinCellExtents(double *x, double *y, double *z) const
Definition: RegularGrid.h:448
float ** GetBlks() const
Definition: RegularGrid.h:455
void GetBlockSize(size_t bs[3]) const
Definition: RegularGrid.h:433
void SetMissingValue(float missing_value)
Definition: RegularGrid.h:253
size_t GetNumBlks() const
Definition: RegularGrid.h:459
int GetUserCoordinates(double *x, double *y, double *z) const
Definition: RegularGrid.h:516
float GetMissingValue() const
Definition: RegularGrid.h:244
ConstIterator begin() const
Definition: RegularGrid.h:532
virtual int GetInterpolationOrder() const
Definition: RegularGrid.h:274
int GetUserCoordinates(double *x, double *y, double *z) const
Definition: RegularGrid.h:482
Iterator begin()
Definition: RegularGrid.h:498
virtual void SetPeriodic(const bool periodic[3])
Definition: RegularGrid.h:427