OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
Box.hpp
1 
2 #ifndef BOX_HPP_
3 #define BOX_HPP_
4 
5 #include "Space/Shape/Sphere.hpp"
6 #include <boost/fusion/sequence/intrinsic/at_c.hpp>
7 #include "Grid/grid_key.hpp"
8 #include "Grid/Encap.hpp"
9 #include <sstream>
10 
16 enum Base
17 {
18  UP,
19  DOWN
20 };
21 
55 template<unsigned int dim , typename T>
56 class Box
57 {
58 public:
59 
61  typedef boost::fusion::vector<T[dim],T[dim]> type;
63  typedef T btype;
64 
67 
69  static const unsigned int p1 = 0;
71  static const unsigned int p2 = 1;
73  static const unsigned int max_prop = 2;
74 
76  static const unsigned int dims = dim;
77 
88  bool Intersect(const Box<dim,T> & b, Box<dim,T> & b_out) const
89  {
90  // check if p1 of b is smaller than
91 
92  for (size_t i = 0 ; i < dim ; i++)
93  {
94  if (getLow(i) <= b.getLow(i))
95  b_out.setLow(i,b.getLow(i));
96  else if (getLow(i) <= b.getHigh(i))
97  b_out.setLow(i,getLow(i));
98  else
99  return false;
100 
101  if (getHigh(i) >= b.getHigh(i))
102  b_out.setHigh(i,b.getHigh(i));
103  else if (getHigh(i) >= b.getLow(i))
104  b_out.setHigh(i,getHigh(i));
105  else
106  return false;
107  }
108  return true;
109  }
110 
121  template<typename Mem> bool Intersect(const encapc<1,Box<dim,T>,Mem> & e_b, Box<dim,T> & b_out) const
122  {
123  return Intersect(e_b,b_out);
124  }
125 
152  template <typename distance> bool Intersect(Sphere<dim,T> & sphere)
153  {
154  // distance functor
155  distance dist;
156 
157  // Get the nearest point of the box from the center of the sphere
158  typename distance::ResultType distance_r = 0;
159 
160  for (size_t i = 0 ; i < dim ; i++)
161  {
162 
163  // if the center of the sphere on dimension i is not in the i box interval
164  // do not accumulate, otherwise accumulate from the nearest point on that
165  // dimension
166  if (boost::fusion::at_c<p1>(data)[i] < sphere.center(i))
167  {
168  // accumulate the distance from p1
169  distance_r += dist.accum_dist(sphere.center(i),boost::fusion::at_c<p1>(data)[i],i);
170  }
171  else if ( boost::fusion::at_c<p2>(data)[i] <= sphere.center(i))
172  {
173  // accumulate the distance from p2
174  distance_r += dist.accum_dist(sphere.center(i),boost::fusion::at_c<p2>(data)[i],i);
175  }
176  }
177 
178  // return if there is intersection
179  return distance_r < sphere.radius();
180  }
181 
190  template<unsigned int b> T getBase(const unsigned int i) const
191  {
192  return boost::fusion::at_c<b>(data)[i];
193  }
194 
201  Box<dim-1,T> getSubBox()
202  {
203  return Box<dim-1,T>(data);
204  }
205 
216  {
217  for(size_t i = 0 ; i < dim ; i++)
218  {setLow(i,box.getLow(i));}
219 
220  for(size_t i = 0 ; i < dim ; i++)
221  {setHigh(i,box.getHigh(i));}
222 
223  // return itself
224  return *this;
225  }
226 
227  public:
228 
230  Box()
231  {}
232 
239  Box(const Point<dim,T> & p1, const Point<dim,T> & p2)
240  {
241  setP1(p1);
242  setP2(p2);
243  }
244 
251  Box(std::initializer_list<T> p1, std::initializer_list<T> p2)
252  {
253  set(p1,p2);
254  }
255 
262  inline Box(T * low, T * high)
263  {
264  // copy all the data
265 
266  for (int i = 0 ; i < dim ; i++)
267  {
268  // p1 is low p2 is high
269 
270  boost::fusion::at_c<Box::p1>(data)[i] = low[i];
271  boost::fusion::at_c<Box::p2>(data)[i] = high[i];
272  }
273  }
274 
280  inline Box(const Box<dim,T> & box)
281  {
282  // we copy the data
283 
284  for (size_t i = 0 ; i < dim ; i++)
285  {
286  boost::fusion::at_c<p1>(data)[i] = boost::fusion::at_c<p1>(box.data)[i];
287  boost::fusion::at_c<p2>(data)[i] = boost::fusion::at_c<p2>(box.data)[i];
288  }
289  }
290 
296  inline Box(type box_data)
297  {
298  // we copy the data
299 
300  for (size_t i = 0 ; i < dim ; i++)
301  {
302  boost::fusion::at_c<p1>(data)[i] = boost::fusion::at_c<p1>(box_data)[i];
303  boost::fusion::at_c<p2>(data)[i] = boost::fusion::at_c<p2>(box_data)[i];
304  }
305  }
306 
312  inline Box(T (& box_data)[dim])
313  {
314  // we copy the data
315 
316  for (size_t i = 0 ; i < dim ; i++)
317  {
318  boost::fusion::at_c<p1>(data)[i] = 0;
319  boost::fusion::at_c<p2>(data)[i] = box_data[i];
320  }
321  }
322 
329  inline Box(const grid_key_dx<dim> & key1, const grid_key_dx<dim> & key2)
330  {
331  for (size_t i = 0 ; i < dim ; i++)
332  {
333  setLow(i,key1.get(i));
334  setHigh(i,key2.get(i));
335  }
336  }
337 
343  template<unsigned int dimS> inline Box(boost::fusion::vector<T[dimS],T[dimS]> & box_data)
344  {
345  // we copy the data
346 
347  for (size_t i = 0 ; i < dim ; i++)
348  {
349  boost::fusion::at_c<p1>(data)[i] = boost::fusion::at_c<p1>(box_data)[i];
350  boost::fusion::at_c<p2>(data)[i] = boost::fusion::at_c<p2>(box_data)[i];
351  }
352  }
353 
359  template<typename Mem> inline Box(const encapc<1,Box<dim,T>,Mem> & b)
360  {
361  // we copy the data
362 
363  for (size_t i = 0 ; i < dim ; i++)
364  {
365  boost::fusion::at_c<p1>(data)[i] = b.template get<p1>()[i];
366  boost::fusion::at_c<p2>(data)[i] = b.template get<p2>()[i];
367  }
368  }
369 
375  template <typename S> inline Box(const Box<dim,S> & b)
376  {
377  for (size_t d = 0 ; d < dim ; d++)
378  {this->setLow(d,b.getLow(d));}
379 
380  for (size_t d = 0 ; d < dim ; d++)
381  {this->setHigh(d,b.getHigh(d));}
382  }
383 
391  inline Box<dim,T> & operator/=(const Point<dim,T> & p)
392  {
393  for (size_t i = 0 ; i < dim ; i++)
394  {
395  setLow(i, getLow(i)/p.get(i));
396  setHigh(i, getHigh(i)/p.get(i));
397  }
398  return *this;
399  }
400 
409  {
410  Box<dim,T> ret;
411 
412  for (size_t i = 0 ; i < dim ; i++)
413  {
414  ret.setLow(i, getLow(i)*p.get(i));
415  ret.setHigh(i, getHigh(i)*p.get(i));
416  }
417  return ret;
418  }
419 
429  inline void set(std::initializer_list<T> p1, std::initializer_list<T> p2)
430  {
431  size_t i = 0;
432  for(T x : p1)
433  {
434  setLow(i,x);
435  i++;
436  if (i >= dim)
437  break;
438  }
439 
440  i = 0;
441  for(T x : p2)
442  {
443  setHigh(i,x);
444  i++;
445  if (i >= dim)
446  break;
447  }
448  }
449 
456  inline void setLow(int i, T val)
457  {
458  boost::fusion::at_c<p1>(data)[i] = val;
459  }
460 
467  inline void setHigh(int i, T val)
468  {
469  boost::fusion::at_c<p2>(data)[i] = val;
470  }
471 
479  inline T getLow(int i) const
480  {
481  return boost::fusion::at_c<p1>(data)[i];
482  }
483 
490  inline T getHigh(int i) const
491  {
492  return boost::fusion::at_c<p2>(data)[i];
493  }
494 
500  inline void setP1(const grid_key_dx<dim> & p1)
501  {
502  for (size_t i = 0 ; i < dim ; i++)
503  setLow(i,p1.get(i));
504  }
505 
511  inline void setP2(const grid_key_dx<dim> & p2)
512  {
513  for (size_t i = 0 ; i < dim ; i++)
514  setHigh(i,p2.get(i));
515  }
516 
522  inline void setP1(const Point<dim,T> & p1)
523  {
524  for (size_t i = 0 ; i < dim ; i++)
525  setLow(i,p1.get(i));
526  }
527 
533  inline void setP2(const Point<dim,T> & p2)
534  {
535  for (size_t i = 0 ; i < dim ; i++)
536  setHigh(i,p2.get(i));
537  }
538 
547  {
548  return *this;
549  }
550 
558  const Box<dim,T> & getBox() const
559  {
560  return *this;
561  }
562 
570  {
571  return data;
572  }
573 
580  {
581  // grid key to return
582  grid_key_dx<dim> ret(boost::fusion::at_c<p1>(data));
583 
584  return ret;
585  }
586 
593  {
594  // grid key to return
595  grid_key_dx<dim> ret(boost::fusion::at_c<p2>(data));
596 
597  return ret;
598  }
599 
605  inline Point<dim,T> getP1() const
606  {
607  // grid key to return
608  Point<dim,T> ret(boost::fusion::at_c<p1>(data));
609 
610  return ret;
611  }
612 
619  inline Point<dim,T> getP2() const
620  {
621  // grid key to return
622  Point<dim,T> ret(boost::fusion::at_c<p2>(data));
623 
624  return ret;
625  }
626 
634  inline Box<dim,T> & operator-=(const Point<dim,T> & p)
635  {
636  for (size_t i = 0 ; i < dim ; i++)
637  {
638  boost::fusion::at_c<p2>(data)[i] -= p.get(i);
639  boost::fusion::at_c<p1>(data)[i] -= p.get(i);
640  }
641 
642  return *this;
643  }
644 
652  inline Box<dim,T> & operator+=(const Point<dim,T> & p)
653  {
654  for (size_t i = 0 ; i < dim ; i++)
655  {
656  boost::fusion::at_c<p2>(data)[i] += p.get(i);
657  boost::fusion::at_c<p1>(data)[i] += p.get(i);
658  }
659 
660  return *this;
661  }
662 
670  inline void expand(T (& exp)[dim])
671  {
672  for (size_t i = 0 ; i < dim ; i++)
673  {
674  boost::fusion::at_c<p2>(data)[i] = boost::fusion::at_c<p2>(data)[i] + exp[i];
675  }
676  }
677 
700  void enlarge(const Box<dim,T> & gh)
701  {
702  typedef ::Box<dim,T> g;
703 
704  for (size_t j = 0 ; j < dim ; j++)
705  {
706  this->setLow(j,this->template getBase<g::p1>(j) + gh.template getBase<g::p1>(j));
707  this->setHigh(j,this->template getBase<g::p2>(j) + gh.template getBase<g::p2>(j));
708  }
709  }
710 
733  template<typename S> inline void enlarge_fix_P1(Box<dim,S> & gh)
734  {
735  typedef ::Box<dim,T> g;
736 
737  for (size_t j = 0 ; j < dim ; j++)
738  {
739  this->setHigh(j,this->template getBase<g::p2>(j) + gh.template getBase<g::p2>(j) - gh.template getBase<g::p1>(j));
740  }
741  }
742 
748  void invalidate()
749  {
750  for (size_t j = 0 ; j < dim ; j++)
751  {
752  this->setLow(j,this->getHigh(j)+1);
753  }
754  }
755 
756 
766  void magnify(T mg)
767  {
768  typedef ::Box<dim,T> g;
769 
770  for (size_t j = 0 ; j < dim ; j++)
771  {
772  this->setLow(j,mg * this->template getBase<g::p1>(j));
773  this->setHigh(j,mg * this->template getBase<g::p2>(j));
774  }
775  }
776 
784  inline void magnify_fix_P1(T mg)
785  {
786  typedef ::Box<dim,T> g;
787 
788  for (size_t j = 0 ; j < dim ; j++)
789  {
790  this->setHigh(j,this->template getBase<g::p1>(j) + mg * (this->template getBase<g::p2>(j) - this->template getBase<g::p1>(j)));
791  }
792  }
793 
799  inline void shrinkP2(T sh)
800  {
801  for (size_t j = 0 ; j < dim ; j++)
802  {
803  this->setHigh(j,this->getHigh(j) - sh);
804  }
805  }
806 
812  inline void enclose(const Box<dim,T> & en)
813  {
814  for (size_t j = 0 ; j < dim ; j++)
815  {
816  if (getLow(j) > en.getLow(j))
817  this->setLow(j,en.getLow(j));
818 
819  if (getHigh(j) < en.getHigh(j))
820  this->setHigh(j,en.getHigh(j));
821  }
822  }
823 
832  inline void contained(const Box<dim,T> & en, const bool reset_p1 = true)
833  {
834  for (size_t j = 0 ; j < dim ; j++)
835  {
836  if (getHigh(j) > (en.getHigh(j) - en.getLow(j)))
837  setHigh(j,en.getHigh(j) - en.getLow(j));
838 
839  if (reset_p1 == true)
840  setLow(j,0);
841  }
842  }
843 
847  inline void zero()
848  {
849  for (size_t j = 0 ; j < dim ; j++)
850  {
851  setHigh(j,0);
852  setLow(j,0);
853  }
854  }
855 
863  inline bool isContained(const Box<dim,T> & b) const
864  {
865  bool isc = true;
866 
867  isc &= isInside(b.getP1());
868  isc &= isInside(b.getP2());
869 
870  return isc;
871  }
872 
880  inline bool isInside(const Point<dim,T> & p) const
881  {
882  // check if bound
883 
884  for (size_t i = 0 ; i < dim ; i++)
885  {
886  // if outside the region return false
887  if ( boost::fusion::at_c<Point<dim,T>::x>(p.data)[i] < boost::fusion::at_c<Box<dim,T>::p1>(this->data)[i]
888  || boost::fusion::at_c<Point<dim,T>::x>(p.data)[i] > boost::fusion::at_c<Box<dim,T>::p2>(this->data)[i])
889  {
890  // Out of bound
891 
892  return false;
893  }
894 
895  }
896 
897  // In bound
898 
899  return true;
900  }
901 
910  inline bool isInsideNP(const Point<dim,T> & p) const
911  {
912  // check if bound
913 
914  for (size_t i = 0 ; i < dim ; i++)
915  {
916  // if outside the region return false
917  if ( boost::fusion::at_c<Point<dim,T>::x>(p.data)[i] < boost::fusion::at_c<Box<dim,T>::p1>(this->data)[i]
918  || boost::fusion::at_c<Point<dim,T>::x>(p.data)[i] >= boost::fusion::at_c<Box<dim,T>::p2>(this->data)[i])
919  {
920  // Out of bound
921 
922 
923 
924  return false;
925  }
926 
927  }
928 
929  // In bound
930 
931  return true;
932  }
933 
940  inline bool isInsideNB(const Point<dim,T> & p) const
941  {
942  // check if bound
943 
944  for (size_t i = 0 ; i < dim ; i++)
945  {
946  // if outside the region return false
947  if ( boost::fusion::at_c<Point<dim,T>::x>(p.data)[i] <= boost::fusion::at_c<Box<dim,T>::p1>(this->data)[i]
948  || boost::fusion::at_c<Point<dim,T>::x>(p.data)[i] >= boost::fusion::at_c<Box<dim,T>::p2>(this->data)[i])
949  {
950  // Out of bound
951 
952  return false;
953  }
954 
955  }
956 
957  // In bound
958 
959  return true;
960  }
961 
969  inline bool isInside(const T (&p)[dim]) const
970  {
971  // check if bound
972 
973  for (size_t i = 0 ; i < dim ; i++)
974  {
975  // if outside the region return false
976  if ( p[i] < boost::fusion::at_c<Box<dim,T>::p1>(this->data)[i]
977  || p[i] > boost::fusion::at_c<Box<dim,T>::p2>(this->data)[i])
978  {
979  // Out of bound
980 
981  return false;
982  }
983 
984  }
985 
986  // In bound
987 
988  return true;
989  }
990 
991 
997  inline bool isValid() const
998  {
999  for (size_t i = 0 ; i < dim ; i++)
1000  {
1001  if (getLow(i) > getHigh(i))
1002  return false;
1003  }
1004 
1005  return true;
1006  }
1007 
1013  inline bool isValidN() const
1014  {
1015  for (size_t i = 0 ; i < dim ; i++)
1016  {
1017  if (getLow(i) >= getHigh(i))
1018  return false;
1019  }
1020 
1021  return true;
1022  }
1023 
1028  inline void floorP1()
1029  {
1030  for (size_t i = 0 ; i < dim ; i++)
1031  {
1032  setLow(i,std::floor(getLow(i)));
1033  }
1034  }
1035 
1040  inline void floorP2()
1041  {
1042  for (size_t i = 0 ; i < dim ; i++)
1043  {
1044  setHigh(i,std::floor(getHigh(i)));
1045  }
1046  }
1047 
1052  inline void ceilP1()
1053  {
1054  for (size_t i = 0 ; i < dim ; i++)
1055  {
1056  setLow(i,std::ceil(getLow(i)));
1057  }
1058  }
1059 
1064  inline void ceilP2()
1065  {
1066  for (size_t i = 0 ; i < dim ; i++)
1067  {
1068  setHigh(i,std::ceil(getHigh(i)));
1069  }
1070  }
1071 
1077  inline void shrinkP2(const Point<dim,T> & p)
1078  {
1079  for (size_t i = 0 ; i < dim ; i++)
1080  {
1081  setHigh(i,getHigh(i) - p.get(i));
1082  }
1083  }
1084 
1090  void swap(Box<dim,T> & b)
1091  {
1092  for (size_t i = 0 ; i < dim ; i++)
1093  {
1094  T tmp_l = getLow(i);
1095  T tmp_h = getHigh(i);
1096 
1097  setLow(i,b.getLow(i));
1098  setHigh(i,b.getHigh(i));
1099 
1100  b.setLow(i,tmp_l);
1101  b.setHigh(i,tmp_h);
1102  }
1103  }
1104 
1112  template <typename Mem> inline bool isInside(const encapc<1,Point<dim,T>,Mem> & p)
1113  {
1114  // check if bound
1115 
1116  for (size_t i = 0 ; i < dim ; i++)
1117  {
1118  // if outside the region return false
1119  if ( p.template get<Point<dim,T>::x>()[i] < boost::fusion::at_c<Box<dim,T>::p1>(this->data)[i]
1120  || p.template get<Point<dim,T>::x>()[i] > boost::fusion::at_c<Box<dim,T>::p2>(this->data)[i])
1121  {
1122  // Out of bound
1123 
1124  return false;
1125  }
1126 
1127  }
1128 
1129  // In bound
1130 
1131  return true;
1132  }
1133 
1139  inline T getVolume() const
1140  {
1141  T vol = 1.0;
1142 
1143  for (size_t i = 0 ; i < dim ; i++)
1144  vol *= (getHigh(i) - getLow(i));
1145 
1146  return vol;
1147  }
1148 
1154  inline T getVolumeKey() const
1155  {
1156  T vol = 1.0;
1157 
1158  for (size_t i = 0 ; i < dim ; i++)
1159  vol *= (getHigh(i) - getLow(i) + 1.0);
1160 
1161  return vol;
1162  }
1163 
1176  inline static T getVolumeKey(const T (&p1)[dim], const T(&p2)[dim])
1177  {
1178  T vol = 1.0;
1179 
1180  for (size_t i = 0 ; i < dim ; i++)
1181  vol *= (p2[i] - p1[i] + 1.0);
1182 
1183  return vol;
1184  }
1185 
1187  static bool noPointers()
1188  {
1189  return true;
1190  }
1191 
1197  inline Point<dim,T> middle() const
1198  {
1199  Point<dim,T> p;
1200 
1201  for (size_t i = 0 ; i < dim ; i++)
1202  p.get(i) = (getLow(i) + getHigh(i))/2;
1203 
1204  return p;
1205  }
1206 
1212  std::string toString() const
1213  {
1214  std::stringstream str;
1215 
1216  for (size_t i = 0 ; i < dim ; i++)
1217  str << "x[" << i << "]=" << getLow(i) << " ";
1218 
1219  str << " | ";
1220 
1221  for (size_t i = 0 ; i < dim ; i++)
1222  str << "x[" << i << "]=" << getHigh(i) << " ";
1223 
1224  return str.str();
1225  }
1226 
1234  bool operator==(const Box<dim,T> & b) const
1235  {
1236  for (size_t i = 0 ; i < dim ; i++)
1237  {
1238  if (getLow(i) != b.getLow(i))
1239  return false;
1240 
1241  if (getHigh(i) != b.getHigh(i))
1242  return false;
1243  }
1244 
1245  return true;
1246  }
1247 
1248 
1256  bool operator!=(const Box<dim,T> & b) const
1257  {
1258  return ! this->operator==(b);
1259  }
1260 };
1261 
1262 #endif
T center(unsigned int i)
Get the component i of the center.
Definition: Sphere.hpp:44
Box(T *low, T *high)
Box constructor from a box.
Definition: Box.hpp:262
void magnify_fix_P1(T mg)
Magnify the box by a factor keeping fix the point P1.
Definition: Box.hpp:784
void setP1(const grid_key_dx< dim > &p1)
Set the point P1 of the box.
Definition: Box.hpp:500
Box< dim, T > & operator+=(const Point< dim, T > &p)
Translate the box.
Definition: Box.hpp:652
bool isInsideNP(const Point< dim, T > &p) const
Check if the point is inside the region excluding the positive part.
Definition: Box.hpp:910
Box(type box_data)
Box constructor from vector::fusion.
Definition: Box.hpp:296
T getLow(int i) const
get the i-coordinate of the low bound interval of the box
Definition: Box.hpp:479
bool isValid() const
Check if the Box is a valid box P2 >= P1.
Definition: Box.hpp:997
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
void shrinkP2(const Point< dim, T > &p)
Shrink the point P2 by one vector.
Definition: Box.hpp:1077
Box(const Point< dim, T > &p1, const Point< dim, T > &p2)
Constructor from two points.
Definition: Box.hpp:239
T getVolume() const
Get the volume of the box.
Definition: Box.hpp:1139
bool isInside(const Point< dim, T > &p) const
Check if the point is inside the box.
Definition: Box.hpp:880
Box(const encapc< 1, Box< dim, T >, Mem > &b)
Box constructor from encapsulated box.
Definition: Box.hpp:359
Box< dim-1, T > getSubBox()
Get the the box of dimensionality dim-1 (it eliminate the last dimension)
Definition: Box.hpp:201
grid_key_dx< dim > getKP2() const
Get the point p12 as grid_key_dx.
Definition: Box.hpp:592
Point< dim, T > middle() const
Return the middle point of the box.
Definition: Box.hpp:1197
void magnify(T mg)
Magnify the box.
Definition: Box.hpp:766
Box< dim, T > & operator-=(const Point< dim, T > &p)
Translate the box.
Definition: Box.hpp:634
static bool noPointers()
This structure has no internal pointers.
Definition: Box.hpp:1187
T getHigh(int i) const
get the high interval of the box
Definition: Box.hpp:490
bool operator==(const Box< dim, T > &b) const
Compare two boxes.
Definition: Box.hpp:1234
Box(boost::fusion::vector< T[dimS], T[dimS]> &box_data)
Box constructor from vector::fusion of higher dimension.
Definition: Box.hpp:343
static const unsigned int max_prop
Maximum number of properties.
Definition: Box.hpp:73
T btype
type of the box
Definition: Box.hpp:63
void setHigh(int i, T val)
set the high interval of the box
Definition: Box.hpp:467
void floorP2()
Apply the ceil operation to the point P2.
Definition: Box.hpp:1040
void invalidate()
Invalidate the box.
Definition: Box.hpp:748
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:22
type data
It store the two point bounding the box.
Definition: Box.hpp:66
Point< dim, T > getP1() const
Get the point p1.
Definition: Box.hpp:605
bool Intersect(Sphere< dim, T > &sphere)
Check if the sphere intersect the box.
Definition: Box.hpp:152
void swap(Box< dim, T > &b)
exchange the data of two boxes
Definition: Box.hpp:1090
grid_key_dx< dim > getKP1() const
Get the point p1 as grid_key_dx.
Definition: Box.hpp:579
void expand(T(&exp)[dim])
expand the box by a vector
Definition: Box.hpp:670
mem_id get(size_t i) const
Get the i index.
Definition: grid_key.hpp:394
void setP2(const grid_key_dx< dim > &p2)
Set the point P2 of the box.
Definition: Box.hpp:511
bool isInside(const T(&p)[dim]) const
Check if the point is inside the region.
Definition: Box.hpp:969
Box< dim, T > & operator=(const Box< dim, T > &box)
Operator= between boxes.
Definition: Box.hpp:215
void floorP1()
Apply the ceil operation to the point P1.
Definition: Box.hpp:1028
bool Intersect(const encapc< 1, Box< dim, T >, Mem > &e_b, Box< dim, T > &b_out) const
Intersect.
Definition: Box.hpp:121
Box()
default constructor
Definition: Box.hpp:230
static const unsigned int p1
Low point.
Definition: Box.hpp:69
void setP2(const Point< dim, T > &p2)
Set the point P2 of the box.
Definition: Box.hpp:533
bool Intersect(const Box< dim, T > &b, Box< dim, T > &b_out) const
Intersect.
Definition: Box.hpp:88
void setP1(const Point< dim, T > &p1)
Set the point P1 of the box.
Definition: Box.hpp:522
Box(const grid_key_dx< dim > &key1, const grid_key_dx< dim > &key2)
constructor from 2 grid_key_dx
Definition: Box.hpp:329
void ceilP1()
Apply the ceil operation to the point P1.
Definition: Box.hpp:1052
void enclose(const Box< dim, T > &en)
Refine the box to enclose the given box and itself.
Definition: Box.hpp:812
Box(const Box< dim, T > &box)
Box constructor from a box.
Definition: Box.hpp:280
Box< dim, T > operator*(const Point< dim, T > &p)
Multiply component wise each box points with a point.
Definition: Box.hpp:408
type data
structure that store the data of the point
Definition: Point.hpp:36
bool isContained(const Box< dim, T > &b) const
Check if the box is contained.
Definition: Box.hpp:863
void zero()
Set p1 and p2 to 0.
Definition: Box.hpp:847
void enlarge(const Box< dim, T > &gh)
Enlarge the box with ghost margin.
Definition: Box.hpp:700
Box(T(&box_data)[dim])
Box constructor from an array reference.
Definition: Box.hpp:312
bool isInside(const encapc< 1, Point< dim, T >, Mem > &p)
Check if the point is inside the region.
Definition: Box.hpp:1112
bool isValidN() const
Check if the Box is a valid box P2 > P1.
Definition: Box.hpp:1013
const T & get(size_t i) const
Get coordinate.
Definition: Point.hpp:142
void setLow(int i, T val)
set the low interval of the box
Definition: Box.hpp:456
bool isInsideNB(const Point< dim, T > &p) const
Check if the point is inside the region excluding the borders.
Definition: Box.hpp:940
static T getVolumeKey(const T(&p1)[dim], const T(&p2)[dim])
Get the volume spanned by the Box as grid_key_dx_iterator_sub.
Definition: Box.hpp:1176
type & getVector()
Get the internal boost::fusion::vector that store the data.
Definition: Box.hpp:569
This class represent an N-dimensional box.
Definition: Box.hpp:56
Box< dim, T > & getBox()
Get the box enclosing this Box.
Definition: Box.hpp:546
const Box< dim, T > & getBox() const
Get the box enclosing this Box.
Definition: Box.hpp:558
T getBase(const unsigned int i) const
Get the coordinate of the bounding point.
Definition: Box.hpp:190
void enlarge_fix_P1(Box< dim, S > &gh)
Enlarge the box with ghost margin keeping fix the point P1.
Definition: Box.hpp:733
static const unsigned int p2
High point.
Definition: Box.hpp:71
std::string toString() const
Produce a string from the object.
Definition: Box.hpp:1212
Box< dim, T > & operator/=(const Point< dim, T > &p)
Divide component wise each box points with a point.
Definition: Box.hpp:391
This class implement the Sphere concept in an N-dimensional space.
Definition: Sphere.hpp:23
Box(const Box< dim, S > &b)
constructor from a Box of different type
Definition: Box.hpp:375
Box(std::initializer_list< T > p1, std::initializer_list< T > p2)
Constructor from initializer list.
Definition: Box.hpp:251
boost::fusion::vector< T[dim], T[dim]> type
boost fusion that store the point
Definition: Box.hpp:61
void ceilP2()
Apply the ceil operation to the point P2.
Definition: Box.hpp:1064
bool operator!=(const Box< dim, T > &b) const
Compare two boxes.
Definition: Box.hpp:1256
void contained(const Box< dim, T > &en, const bool reset_p1=true)
Refine the box to be contained in the given box and itself.
Definition: Box.hpp:832
T getVolumeKey() const
Get the volume spanned by the Box P1 and P2 interpreted as grid key.
Definition: Box.hpp:1154
void shrinkP2(T sh)
Shrink moving p2 of sh quantity (on each direction)
Definition: Box.hpp:799
void set(std::initializer_list< T > p1, std::initializer_list< T > p2)
Constructor from initializer list.
Definition: Box.hpp:429
Point< dim, T > getP2() const
Get the point p2.
Definition: Box.hpp:619
T radius()
Get the radius of the sphere.
Definition: Sphere.hpp:74
static const unsigned int dims
dimensionality of the box
Definition: Box.hpp:76