VAPoR  0.1
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 
312  virtual int GetUserCoordinates(
313  size_t i, size_t j, size_t k,
314  double *x, double *y, double *z
315  ) const;
316 
319 
331 
332  void getBilinearWeights(double x, double y, double z,
333  double &iwgt, double &jwgt) const;
334 
337 
352 
353  double bilinearElevation(size_t i0, size_t i1, size_t j0, size_t j1,
354  size_t k0, double iwgt, double jwgt) const;
355 
358 
373  double bilinearInterpolation(size_t i0, size_t i1, size_t j0, size_t j1,
374  size_t k0, double iwgt, double jwgt) const;
375 
378 
394 
395  double quadraticInterpolation(double x, double y, double z) const;
396 
407 
408  double verticalLinearInterpolation(double x, double y, double z) const;
409 
425  virtual void GetIJKIndex(
426  double x, double y, double z,
427  size_t *i, size_t *j, size_t *k
428  ) const;
429 
452  virtual void GetIJKIndexFloor(
453  double x, double y, double z,
454  size_t *i, size_t *j, size_t *k
455  ) const;
456 
465  virtual void GetRange(float range[2]) const;
466 
484  virtual int Reshape(
485  const size_t min[3],
486  const size_t max[3],
487  const bool periodic[3]
488  );
489 
490 
502  virtual bool InsideGrid(double x, double y, double z) const;
503 
504 
513  //
514  virtual void HasPeriodic(bool *idim, bool *jdim, bool *kdim) const {
515  *idim = _periodic[0]; *jdim = _periodic[1]; *kdim = _periodic[2];
516  }
517 
525  //
526  virtual void SetPeriodic(const bool periodic[3]) {
527  _periodic[0] = periodic[0];
528  _periodic[1] = periodic[1];
529  _periodic[2] = periodic[2];
530  }
531 
532  void GetBlockSize(size_t bs[3]) const {
533  bs[0] = _bs[0]; bs[1] = _bs[1]; bs[2] = _bs[2];
534  }
535 
547  virtual void GetMinCellExtents(double *x, double *y, double *z) const {
548  *x = _delta[0]; *y = _delta[1]; *z = _delta[2];
549  };
550 
555  //
556  virtual int GetRank() {
557  int rank = 0;
558  for (int i=0; i<3; i++) if (_min[i]!=_max[i]) rank++;
559  return(rank);
560  }
561 
562  virtual double _interpolateVaryingCoord(size_t /*i0*/, size_t /*j0*/,
563  size_t /*k0*/, double /*x*/, double /*y*/, double /*z*/) const
564  {return 0.0;};
565 
569  float **GetBlks() const { return(_blks); };
570 
573  size_t GetNumBlks() const { return(_nblocks); };
574 
576  float Next();
577 
579  void ResetItr();
580 
581 
583  public:
584  Iterator (RegularGrid *rg);
585  Iterator ();
586  ~Iterator () {}
587 
588  inline float &operator*() {return (*_itr);}
589 
590  Iterator &operator++(); // ++prefix
591  Iterator operator++(int); // postfix++
592 
593  bool operator==(const Iterator &other);
594  bool operator!=(const Iterator &other);
595 
597  double *x, double *y, double *z
598  ) const { return(_rg->GetUserCoordinates(
599  _x - _rg->_min[0], _y - _rg->_min[1], _z - _rg->_min[2], x,y,z));
600  };
601 
602  private:
603  RegularGrid *_rg;
604  size_t _x, _y, _z; // current index into _rg->_min[3]
605  size_t _xb; // x index within a block
606  float *_itr;
607  bool _end;
608 
609 
610  };
611 
612  Iterator begin() { return( Iterator(this)); }
613  Iterator end() { return(Iterator()); }
614 
615 
617  public:
618  ConstIterator (const RegularGrid *rg);
619  ConstIterator ();
621 
622  inline float &operator*() {return (*_itr);}
623 
624  ConstIterator &operator++(); // ++prefix
625  ConstIterator operator++(int); // postfix++
626 
627  bool operator==(const ConstIterator &other);
628  bool operator!=(const ConstIterator &other);
629 
631  double *x, double *y, double *z
632  ) const { return(_rg->GetUserCoordinates(
633  _x - _rg->_min[0], _y - _rg->_min[1], _z - _rg->_min[2], x,y,z));
634  };
635 
636  private:
637  const RegularGrid *_rg;
638  size_t _x, _y, _z; // current index into _rg->_min[3]
639  size_t _xb; // x index within a block
640  float *_itr;
641  bool _end;
642 
643 
644  };
645 
646  ConstIterator begin() const { return( ConstIterator(this)); }
647  ConstIterator end() const { return(ConstIterator()); }
648 
649 
650 
651 
652 
653  VDF_API friend std::ostream &operator<<(std::ostream &o, const RegularGrid &rg);
654 
655 
656 
657 protected:
658 
659  float &_AccessIJK(float **blks, size_t i, size_t j, size_t k) const;
660  void _ClampCoord(double &x, double &y, double &z) const;
661  void _SetExtents(const double extents[6]);
662  size_t _min[3]; // ijk offset of first voxel in ROI (relative to ROI)
663  size_t _max[3]; // ijk offset of last voxel in ROI (relative to ROI)
664 
665 private:
666  size_t _bs[3]; // dimensions of each block
667  size_t _bdims[3]; // dimensions (specified in blocks) of ROI
668  size_t _minabs[3]; // ijk offset of first voxel in ROI (absolute coords)
669  size_t _maxabs[3]; // ijk offset of last voxel in ROI (absolute coords)
670  double _minu[3];
671  double _maxu[3]; // User coords of first and last voxel
672  double _delta[3]; // increment between grid points in user coords
673  bool _periodic[3]; // periodicity of boundaries
674  float _missingValue;
675  bool _hasMissing;
676  int _interpolationOrder; // Order of interpolation
677  size_t _x, _y, _z, _xb;
678  bool _end;
679  size_t _nblocks; // num blocks allocated to _blks
680  float *_itr;
681  float **_blks;
682 
683  int _RegularGrid(
684  const size_t bs[3], const size_t min[3], const size_t max[3],
685  const double extents[6], const bool periodic[3], float ** blks
686  );
687  float _GetValueNearestNeighbor(double x, double y, double z) const;
688  float _GetValueLinear(double x, double y, double z) const;
689 
690 };
691 };
692 #endif
bool HasMissingData() const
Definition: RegularGrid.h:270
virtual void GetIJKOrigin(size_t min[3]) const
Definition: RegularGrid.h:231
#define VDF_API
Definition: common.h:61
virtual void HasPeriodic(bool *idim, bool *jdim, bool *kdim) const
Definition: RegularGrid.h:514
virtual void GetIJKMinMax(size_t min[3], size_t max[3]) const
Definition: RegularGrid.h:219
ConstIterator end() const
Definition: RegularGrid.h:647
virtual void GetMinCellExtents(double *x, double *y, double *z) const
Definition: RegularGrid.h:547
float ** GetBlks() const
Definition: RegularGrid.h:569
void GetBlockSize(size_t bs[3]) const
Definition: RegularGrid.h:532
void SetMissingValue(float missing_value)
Definition: RegularGrid.h:258
size_t GetNumBlks() const
Definition: RegularGrid.h:573
int GetUserCoordinates(double *x, double *y, double *z) const
Definition: RegularGrid.h:630
virtual double _interpolateVaryingCoord(size_t, size_t, size_t, double, double, double) const
Definition: RegularGrid.h:562
float GetMissingValue() const
Definition: RegularGrid.h:249
ConstIterator begin() const
Definition: RegularGrid.h:646
virtual int GetInterpolationOrder() const
Definition: RegularGrid.h:279
int GetUserCoordinates(double *x, double *y, double *z) const
Definition: RegularGrid.h:596
Iterator begin()
Definition: RegularGrid.h:612
virtual void SetPeriodic(const bool periodic[3])
Definition: RegularGrid.h:526
virtual int GetRank()
Definition: RegularGrid.h:556