Proto
Proto_Box.H
1 #pragma once
2 #ifndef _PROTO_BOX_H___
3 #define _PROTO_BOX_H___
4 
5 #include "Proto_Point.H"
6 #include "Proto_LoHiSide.H"
7 #include <cstdlib> //for size_t
8 #include <iostream>
9 #include <cmath>
11 namespace Proto
12 {
13 
14 // forward declarations
15  class BoxIterator;
16  #ifdef PR_HDF5
17  class HDF5Handler;
18  #endif
19 
26  class Box
27  {
28  #ifdef PR_HDF5
29  friend class Proto::HDF5Handler;
30  #endif
31  public:
32  typedef BoxIterator iterator; //Box::iterator aliases to BoxIterator
33 
35 
36 
39 
42  inline Box();
43 
44  //useful for bc evaluation
45  Point boundary(const Side::LoHiSide a_side) const
46  {
47  Point retval = low();
48  if(a_side == Side::Hi)
49  {
50  retval = high();
51  }
52  return retval;
53  }
54 
55  //useful for bc evaluation
56  Box faceBox(int a_idir, const Side::LoHiSide a_side) const
57  {
58  Box retval = adjCellSide(a_idir, 1, a_side);
59  if(a_side == Side::Lo)
60  {
61  retval = retval.shift(Point::Basis(a_idir, 1));
62  }
63  return retval;
64  }
65 
67 
73  inline Box(const Point& a_low, const Point& a_high);
74 
76 
81  inline Box (const int* a_lo, const int* a_hi) { define(a_lo, a_hi); }
82 
84 
90  inline void define(const int* a_lo, const int* a_hi);
91 
93 
98  inline Box(const Point& a_pt);
99 
101  inline Box(const Box& a_box);
103 
105 
106 
114  inline static Box Cube(int a_size);
115 
117 
133  inline static Box Kernel(int a_radius);
134 
136 
144  CUDA_DECORATION
145  inline static unsigned int sindex(Point a_pt, Point a_low, Point a_high);
146 
148 
156  CUDA_DECORATION
157  inline static unsigned int soffset(const Point& a_pt, const Point& a_low, const Point& a_high);
159 
161 
162 
165 
168  inline Point low() const {return m_low;};
169 
174  inline Point high() const {return m_high;};
175 
177 
192  CUDA_DECORATION
193  inline std::size_t size(unsigned char a_dim) const;
194 
196 
208  CUDA_DECORATION
209  inline std::size_t size() const;
210 
212 
227  CUDA_DECORATION
228  inline bool contains(const Point& a_pt) const;
229 
231 
249  CUDA_DECORATION
250  inline bool contains(const Box& a_rhs) const;
251 
253 
258  inline bool onBoundary(const Point& a_p) const;
259 
261 
264  CUDA_DECORATION
265  inline bool empty() const {return (m_size < 1);}
266 
268 
277  CUDA_DECORATION
278  inline unsigned int index(const Point& a_pt) const;
279 
280 
282 
288  CUDA_DECORATION
289  inline Point operator[](unsigned int a_index) const;
290 
291 
292  CUDA_DECORATION
293  inline Point operator()(unsigned int a_idx, unsigned int a_idy, unsigned a_idz) const;
295 
296 
297 
299 
300 
303 
320  inline Box operator&(const Box& a_rightBox) const;
321 
322 
324 
329  inline void operator&=(const Box& a_rhs);
332 
350  inline Box operator&(const Point& a_pt) const;
351 
353 
359  inline void operator&=(const Point& a_pt);
360 
361  //inline void operator&=(const Box& a_rightBox);
362 
369  inline bool operator==(const Box& a_rhsBox) const;
370 
372  inline bool operator!=(const Box& a_rhsBox) const
373  {
374  bool equals = (*this==a_rhsBox);
375  return !equals;
376  }
378  inline bool operator< (const Box& a_rhsBox) const
379  {
380  bool lt = this->low() < a_rhsBox.low();
381  return lt;
382  };
384 
390  inline Point operator%(const Point& a_pt) const;
391 
393 
406  inline Point mod(const Point& a_pt) const;
407 
409 
411 
412 
415 
434  inline Box shift(int a_direction, int a_offset) const;
435 
437 
452  inline Box shift(const Point& a_pt) const;
453 
472  inline Box grow(int a_numpoints) const;
473 
475 
491  inline Box grow(const Point& a_pt) const;
492 
494 
502  inline Box grow(int a_dir, int a_offset) const;
503 
505 
524  inline Box extrude(const Point& a_dir, int a_dist = 1) const;
525 
547  inline Box extrude(int a_dir, int a_dist = 1, bool a_upper = true) const;
548 
550 
553  inline Box growHi(int idir, int igrow) const;
554 
556 
559  inline Box growLo(int idir, int igrow) const;
560 
562 
584  inline Box coarsen(unsigned int a_ratio) const;
585 
587 
604  inline Box coarsen(const Point& a_pt) const;
606 
608 
613  inline bool coarsenable(const int& a_ratio) const;
614 
616 
621  inline bool coarsenable(const Point& a_ratio) const;
622 
624 
631  inline Box taperCoarsen(const Point& a_ref) const;
632 
634 
649  inline Box refine(const Point& a_pt) const;
650 
652 
671  inline Box refine(unsigned int a_ratio) const;
672 
674 
692  inline Box edge(const Point& a_dir, int a_dist = 1) const;
693 
695 
713  inline Box flatten(const int a_dir, bool a_upper = false) const;
714 
716 
733  inline Box adjacent(const Point& a_dir, int a_dist = -1) const;
734 
735 
737 
740  inline Box adjCellLo(int a_idir, int a_length) const;
741 
743 
746  inline Box adjCellHi(int a_idir, int a_length) const;
747 
749  inline Box adjCellSide(int a_idir, int a_length, Side::LoHiSide a_sd) const
750  {
751  Box retval = adjCellHi(a_idir, a_length);
752  if(a_sd == Side::Lo)
753  {
754  retval = adjCellLo(a_idir, a_length);
755  }
756  return retval;
757  }
758 
760 
762 
763 
766 
769  inline BoxIterator begin() const;
770 
772 
775  inline BoxIterator end() const;
776 
778 
781  inline BoxIterator rbegin() const;
782 
784 
787  inline BoxIterator rend() const;
788 
790 
793  inline void print() const;
795 
796  inline size_t linearSize() const
797  {
798  size_t retval = 0;
799  retval += m_low.linearSize();
800  retval += m_high.linearSize();
801  retval += sizeof(int);
802  return retval;
803  }
804 
805  inline void linearOut(char* a_buf) const
806  {
807  size_t charsiz = 0;
808  char* charbuf = a_buf;
809 
810  m_low.linearOut(charbuf);
811  charbuf += m_low.linearSize();
812  charsiz += m_low.linearSize();
813 
814  m_high.linearOut(charbuf);
815  charbuf += m_high.linearSize();
816  charsiz += m_high.linearSize();
817 
818  int* intbuf = (int* ) charbuf;
819  *intbuf = m_size;
820  charsiz += sizeof(int);
821  charbuf += sizeof(int);
822  }
823 
824  inline void linearIn(const char* a_buf)
825  {
826  size_t charsiz = 0;
827  const char* charbuf = a_buf;
828 
829  m_low.linearIn(charbuf);
830  charbuf += m_low.linearSize();
831  charsiz += m_low.linearSize();
832 
833  m_high.linearIn(charbuf);
834  charbuf += m_high.linearSize();
835  charsiz += m_high.linearSize();
836 
837  int* intbuf = (int* ) charbuf;
838  m_size = *intbuf;
839  charsiz += sizeof(int);
840  charbuf += sizeof(int);
841  }
842  private:
843  inline void recomputeSize();
844  Point m_low;
845  Point m_high;
846  int m_size;
847  }; //end class Box
848 
850  inline std::ostream& operator<<(std::ostream& a_os, const Box& a_box)
851  {
852  a_os << "[" << a_box.low() << ", " << a_box.high() << "]";
853  return a_os;
854  }
855 
857 
864  {
865  public:
868 
869  BoxIterator(const Box& a_box, int a_pos = 0)
870  : m_box(a_box), m_pos(a_pos) {}
871 
872  BoxIterator(const Box& a_box, const Point& a_pos)
873  : m_box(a_box)
874  {
875  m_pos = m_box.index(a_pos);
876  }
877  inline void begin(){m_pos = 0;};
878 
879  inline bool end()
880  {return ((m_pos < 0) || (m_pos >= m_box.size()));};
881 
882  inline bool ok() { return !end(); }
883 
885 
890  inline bool operator==(const BoxIterator& a_iter) const
891  {
892  return ((m_pos == a_iter.m_pos) && (m_box == a_iter.m_box));
893  };
894 
896  inline bool operator!=(const BoxIterator& a_iter) const
897  {
898  return !((*this) == a_iter);
899  };
900 
902 
905  inline Point operator*() const
906  {
907  return m_box[m_pos];
908  };
909 
911 
914  inline int operator()() const
915  {
916  return m_pos;
917  };
918 
921  {
922  m_pos++;
923  return *this;
924  };
925 
928  {
929  m_pos--;
930  return *this;
931  };
932 
934  inline bool done()
935  {
936  return ((m_pos < 0) || (m_pos >= m_box.size()));
937  }
938 
939 
940  private:
941  Box m_box;
942  int m_pos;
943  }; //end class BoxIterator
944 
945 #include "implem/Proto_BoxImplem.H"
946 } //end namespace Proto
947 #endif
bool operator!=(const BoxIterator &a_iter) const
Inequality Operator.
Definition: Proto_Box.H:896
Definition: Proto_HDF5.H:9
Point high() const
Access High Corner.
Definition: Proto_Box.H:174
Point low() const
Access Low Corner.
Definition: Proto_Box.H:168
BoxIterator()
Constructor.
Definition: Proto_Box.H:867
Iterator for Boxes.
Definition: Proto_Box.H:863
LoHiSide
Definition: Proto_LoHiSide.H:18
BoxIterator rend() const
Iterator Reverse End.
Definition: Proto_Box.H:600
void operator &=(const Box &a_rhs)
In Place Intersection.
CUDA_DECORATION bool empty() const
Empty Query.
Definition: Proto_Box.H:265
bool operator!=(const Box &a_rhsBox) const
Inequality Operator.
Definition: Proto_Box.H:372
void define(const int *a_lo, const int *a_hi)
Define.
Definition: Proto_Box.H:50
Box(const int *a_lo, const int *a_hi)
Primitive Constructor.
Definition: Proto_Box.H:81
Point mod(const Point &a_pt) const
Modulus Function.
Definition: Proto_Box.H:286
std::ostream & operator<<(std::ostream &a_os, const Box &a_box)
OStream Operator.
Definition: Proto_Box.H:850
int operator()() const
Get Index.
Definition: Proto_Box.H:914
CUDA_DECORATION bool contains(const Point &a_pt) const
Contains Point Query.
Definition: Proto_Box.H:133
BoxIterator & operator--()
Decrement Iterator.
Definition: Proto_Box.H:927
Box flatten(const int a_dir, bool a_upper=false) const
Flatten.
Definition: Proto_Box.H:510
Box extrude(const Point &a_dir, int a_dist=1) const
Extrude.
Definition: Proto_Box.H:346
static Box Kernel(int a_radius)
Kernel Function.
Definition: Proto_Box.H:72
Box refine(const Point &a_pt) const
Anisotropic Refine Operation.
Definition: Proto_Box.H:477
Point operator%(const Point &a_pt) const
Modulus Operator.
Definition: Proto_Box.H:281
An interval in DIM dimensional space.
Definition: Proto_Box.H:26
static CUDA_DECORATION Point Basis(int a_dir, int a_scale=1)
Get Basis.
Definition: Proto_Point.H:48
Box shift(int a_direction, int a_offset) const
Shift Transformation.
Definition: Proto_Box.H:306
Point operator*() const
Dereference Iterator.
Definition: Proto_Box.H:905
bool onBoundary(const Point &a_p) const
Point on Boundry Query.
Definition: Proto_Box.H:157
Box grow(int a_numpoints) const
Isotropic Grow Operation.
Definition: Proto_Box.H:325
bool operator==(const BoxIterator &a_iter) const
Equality Operator.
Definition: Proto_Box.H:890
Box growLo(int idir, int igrow) const
Grow Low Side.
Definition: Proto_Box.H:382
static Box Cube(int a_size)
Definition: Proto_Box.H:67
Definition: Proto_Box.H:11
bool operator==(const Box &a_rhsBox) const
Equality Operator.
Definition: Proto_Box.H:275
CUDA_DECORATION Point operator[](unsigned int a_index) const
Access Point by Index.
Definition: Proto_Box.H:179
CUDA_DECORATION std::size_t size() const
Volumetric Size.
Definition: Proto_Box.H:120
Box operator &(const Box &a_rightBox) const
Intersection Operator.
Integer Valued Vector.
Definition: Proto_Point.H:21
Box growHi(int idir, int igrow) const
Grow High Side.
Definition: Proto_Box.H:377
void print() const
Print.
Definition: Proto_Box.H:605
BoxIterator begin() const
Iterator Begin.
Definition: Proto_Box.H:585
BoxIterator & operator++()
Increment Iterator.
Definition: Proto_Box.H:920
Box taperCoarsen(const Point &a_ref) const
Tapered Coarsen.
Definition: Proto_Box.H:444
BoxIterator end() const
Iterator End.
Definition: Proto_Box.H:590
Box()
Default Constructor.
Definition: Proto_Box.H:10
bool done()
Check if Done.
Definition: Proto_Box.H:934
CUDA_DECORATION unsigned int index(const Point &a_pt) const
Point to Linear Index.
Definition: Proto_Box.H:171
Box coarsen(unsigned int a_ratio) const
Isotropic Coarsen Operation.
Definition: Proto_Box.H:387
Box adjCellLo(int a_idir, int a_length) const
Lower Adjacent Cells.
Definition: Proto_Box.H:551
bool operator<(const Box &a_rhsBox) const
< Operator. Based on same operator for Point applied to low corner. Used in Copier.
Definition: Proto_Box.H:378
bool coarsenable(const int &a_ratio) const
(Isotropic) Coarsenable Query
Definition: Proto_Box.H:455
Box adjacent(const Point &a_dir, int a_dist=-1) const
Adjacent Cells.
Definition: Proto_Box.H:527
BoxIterator rbegin() const
Iterator Reverse Begin.
Definition: Proto_Box.H:595
Box edge(const Point &a_dir, int a_dist=1) const
Edge.
Definition: Proto_Box.H:498
Box adjCellHi(int a_idir, int a_length) const
Upper Adjacent Cells.
Definition: Proto_Box.H:566