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"
55 template<
unsigned int dim ,
typename T>
61 typedef boost::fusion::vector<T[dim],T[dim]>
type;
69 static const unsigned int p1 = 0;
71 static const unsigned int p2 = 1;
76 static const unsigned int dims = dim;
92 for (
size_t i = 0 ; i < dim ; i++)
158 typename distance::ResultType distance_r = 0;
160 for (
size_t i = 0 ; i < dim ; i++)
166 if (boost::fusion::at_c<p1>(
data)[i] < sphere.
center(i))
169 distance_r += dist.accum_dist(sphere.
center(i),boost::fusion::at_c<p1>(
data)[i],i);
171 else if ( boost::fusion::at_c<p2>(
data)[i] <= sphere.
center(i))
174 distance_r += dist.accum_dist(sphere.
center(i),boost::fusion::at_c<p2>(
data)[i],i);
179 return distance_r < sphere.
radius();
190 template<
unsigned int b> T
getBase(
const unsigned int i)
const
192 return boost::fusion::at_c<b>(
data)[i];
217 for(
size_t i = 0 ; i < dim ; i++)
220 for(
size_t i = 0 ; i < dim ; i++)
251 Box(std::initializer_list<T>
p1, std::initializer_list<T>
p2)
262 inline Box(T * low, T * high)
266 for (
int i = 0 ; i < dim ; i++)
270 boost::fusion::at_c<Box::p1>(
data)[i] = low[i];
271 boost::fusion::at_c<Box::p2>(
data)[i] = high[i];
284 for (
size_t i = 0 ; i < dim ; i++)
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];
300 for (
size_t i = 0 ; i < dim ; i++)
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];
312 inline Box(T (& box_data)[dim])
316 for (
size_t i = 0 ; i < dim ; i++)
318 boost::fusion::at_c<p1>(
data)[i] = 0;
319 boost::fusion::at_c<p2>(
data)[i] = box_data[i];
331 for (
size_t i = 0 ; i < dim ; i++)
343 template<
unsigned int dimS>
inline Box(boost::fusion::vector<T[dimS],T[dimS]> & box_data)
347 for (
size_t i = 0 ; i < dim ; i++)
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];
363 for (
size_t i = 0 ; i < dim ; i++)
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];
377 for (
size_t d = 0 ; d < dim ; d++)
380 for (
size_t d = 0 ; d < dim ; d++)
393 for (
size_t i = 0 ; i < dim ; i++)
412 for (
size_t i = 0 ; i < dim ; i++)
429 inline void set(std::initializer_list<T>
p1, std::initializer_list<T>
p2)
458 boost::fusion::at_c<p1>(
data)[i] = val;
469 boost::fusion::at_c<p2>(
data)[i] = val;
481 return boost::fusion::at_c<p1>(
data)[i];
492 return boost::fusion::at_c<p2>(
data)[i];
502 for (
size_t i = 0 ; i < dim ; i++)
513 for (
size_t i = 0 ; i < dim ; i++)
524 for (
size_t i = 0 ; i < dim ; i++)
535 for (
size_t i = 0 ; i < dim ; i++)
636 for (
size_t i = 0 ; i < dim ; i++)
638 boost::fusion::at_c<p2>(
data)[i] -= p.
get(i);
639 boost::fusion::at_c<p1>(
data)[i] -= p.
get(i);
654 for (
size_t i = 0 ; i < dim ; i++)
656 boost::fusion::at_c<p2>(
data)[i] += p.
get(i);
657 boost::fusion::at_c<p1>(
data)[i] += p.
get(i);
672 for (
size_t i = 0 ; i < dim ; i++)
674 boost::fusion::at_c<p2>(
data)[i] = boost::fusion::at_c<p2>(
data)[i] + exp[i];
702 typedef ::Box<dim,T> g;
704 for (
size_t j = 0 ; j < dim ; j++)
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));
735 typedef ::Box<dim,T> g;
737 for (
size_t j = 0 ; j < dim ; j++)
739 this->
setHigh(j,this->
template getBase<g::p2>(j) + gh.template getBase<g::p2>(j) - gh.template getBase<g::p1>(j));
750 for (
size_t j = 0 ; j < dim ; j++)
768 typedef ::Box<dim,T> g;
770 for (
size_t j = 0 ; j < dim ; j++)
772 this->
setLow(j,mg * this->
template getBase<g::p1>(j));
773 this->
setHigh(j,mg * this->
template getBase<g::p2>(j));
786 typedef ::Box<dim,T> g;
788 for (
size_t j = 0 ; j < dim ; j++)
790 this->
setHigh(j,this->
template getBase<g::p1>(j) + mg * (this->
template getBase<g::p2>(j) - this->
template getBase<g::p1>(j)));
801 for (
size_t j = 0 ; j < dim ; j++)
814 for (
size_t j = 0 ; j < dim ; j++)
834 for (
size_t j = 0 ; j < dim ; j++)
839 if (reset_p1 ==
true)
849 for (
size_t j = 0 ; j < dim ; j++)
884 for (
size_t i = 0 ; i < dim ; i++)
914 for (
size_t i = 0 ; i < dim ; i++)
944 for (
size_t i = 0 ; i < dim ; i++)
973 for (
size_t i = 0 ; i < dim ; i++)
999 for (
size_t i = 0 ; i < dim ; i++)
1015 for (
size_t i = 0 ; i < dim ; i++)
1030 for (
size_t i = 0 ; i < dim ; i++)
1042 for (
size_t i = 0 ; i < dim ; i++)
1054 for (
size_t i = 0 ; i < dim ; i++)
1066 for (
size_t i = 0 ; i < dim ; i++)
1079 for (
size_t i = 0 ; i < dim ; i++)
1092 for (
size_t i = 0 ; i < dim ; i++)
1116 for (
size_t i = 0 ; i < dim ; i++)
1143 for (
size_t i = 0 ; i < dim ; i++)
1158 for (
size_t i = 0 ; i < dim ; i++)
1180 for (
size_t i = 0 ; i < dim ; i++)
1181 vol *= (
p2[i] -
p1[i] + 1.0);
1201 for (
size_t i = 0 ; i < dim ; i++)
1214 std::stringstream str;
1216 for (
size_t i = 0 ; i < dim ; i++)
1217 str <<
"x[" << i <<
"]=" <<
getLow(i) <<
" ";
1221 for (
size_t i = 0 ; i < dim ; i++)
1222 str <<
"x[" << i <<
"]=" <<
getHigh(i) <<
" ";
1236 for (
size_t i = 0 ; i < dim ; i++)
T center(unsigned int i)
Get the component i of the center.
Box(T *low, T *high)
Box constructor from a box.
void magnify_fix_P1(T mg)
Magnify the box by a factor keeping fix the point P1.
void setP1(const grid_key_dx< dim > &p1)
Set the point P1 of the box.
Box< dim, T > & operator+=(const Point< dim, T > &p)
Translate the box.
bool isInsideNP(const Point< dim, T > &p) const
Check if the point is inside the region excluding the positive part.
Box(type box_data)
Box constructor from vector::fusion.
T getLow(int i) const
get the i-coordinate of the low bound interval of the box
bool isValid() const
Check if the Box is a valid box P2 >= P1.
grid_key_dx is the key to access any element in the grid
void shrinkP2(const Point< dim, T > &p)
Shrink the point P2 by one vector.
Box(const Point< dim, T > &p1, const Point< dim, T > &p2)
Constructor from two points.
T getVolume() const
Get the volume of the box.
bool isInside(const Point< dim, T > &p) const
Check if the point is inside the box.
Box(const encapc< 1, Box< dim, T >, Mem > &b)
Box constructor from encapsulated box.
Box< dim-1, T > getSubBox()
Get the the box of dimensionality dim-1 (it eliminate the last dimension)
grid_key_dx< dim > getKP2() const
Get the point p12 as grid_key_dx.
Point< dim, T > middle() const
Return the middle point of the box.
void magnify(T mg)
Magnify the box.
Box< dim, T > & operator-=(const Point< dim, T > &p)
Translate the box.
static bool noPointers()
This structure has no internal pointers.
T getHigh(int i) const
get the high interval of the box
bool operator==(const Box< dim, T > &b) const
Compare two boxes.
Box(boost::fusion::vector< T[dimS], T[dimS]> &box_data)
Box constructor from vector::fusion of higher dimension.
static const unsigned int max_prop
Maximum number of properties.
void setHigh(int i, T val)
set the high interval of the box
void floorP2()
Apply the ceil operation to the point P2.
void invalidate()
Invalidate the box.
This class implement the point shape in an N-dimensional space.
type data
It store the two point bounding the box.
Point< dim, T > getP1() const
Get the point p1.
bool Intersect(Sphere< dim, T > &sphere)
Check if the sphere intersect the box.
void swap(Box< dim, T > &b)
exchange the data of two boxes
grid_key_dx< dim > getKP1() const
Get the point p1 as grid_key_dx.
void expand(T(&exp)[dim])
expand the box by a vector
mem_id get(size_t i) const
Get the i index.
void setP2(const grid_key_dx< dim > &p2)
Set the point P2 of the box.
bool isInside(const T(&p)[dim]) const
Check if the point is inside the region.
Box< dim, T > & operator=(const Box< dim, T > &box)
Operator= between boxes.
void floorP1()
Apply the ceil operation to the point P1.
bool Intersect(const encapc< 1, Box< dim, T >, Mem > &e_b, Box< dim, T > &b_out) const
Intersect.
static const unsigned int p1
Low point.
void setP2(const Point< dim, T > &p2)
Set the point P2 of the box.
bool Intersect(const Box< dim, T > &b, Box< dim, T > &b_out) const
Intersect.
void setP1(const Point< dim, T > &p1)
Set the point P1 of the box.
Box(const grid_key_dx< dim > &key1, const grid_key_dx< dim > &key2)
constructor from 2 grid_key_dx
void ceilP1()
Apply the ceil operation to the point P1.
void enclose(const Box< dim, T > &en)
Refine the box to enclose the given box and itself.
Box(const Box< dim, T > &box)
Box constructor from a box.
Box< dim, T > operator*(const Point< dim, T > &p)
Multiply component wise each box points with a point.
type data
structure that store the data of the point
bool isContained(const Box< dim, T > &b) const
Check if the box is contained.
void zero()
Set p1 and p2 to 0.
void enlarge(const Box< dim, T > &gh)
Enlarge the box with ghost margin.
Box(T(&box_data)[dim])
Box constructor from an array reference.
bool isInside(const encapc< 1, Point< dim, T >, Mem > &p)
Check if the point is inside the region.
bool isValidN() const
Check if the Box is a valid box P2 > P1.
const T & get(size_t i) const
Get coordinate.
void setLow(int i, T val)
set the low interval of the box
bool isInsideNB(const Point< dim, T > &p) const
Check if the point is inside the region excluding the borders.
static T getVolumeKey(const T(&p1)[dim], const T(&p2)[dim])
Get the volume spanned by the Box as grid_key_dx_iterator_sub.
type & getVector()
Get the internal boost::fusion::vector that store the data.
This class represent an N-dimensional box.
Box< dim, T > & getBox()
Get the box enclosing this Box.
const Box< dim, T > & getBox() const
Get the box enclosing this Box.
T getBase(const unsigned int i) const
Get the coordinate of the bounding point.
void enlarge_fix_P1(Box< dim, S > &gh)
Enlarge the box with ghost margin keeping fix the point P1.
static const unsigned int p2
High point.
std::string toString() const
Produce a string from the object.
Box< dim, T > & operator/=(const Point< dim, T > &p)
Divide component wise each box points with a point.
This class implement the Sphere concept in an N-dimensional space.
Box(const Box< dim, S > &b)
constructor from a Box of different type
Box(std::initializer_list< T > p1, std::initializer_list< T > p2)
Constructor from initializer list.
boost::fusion::vector< T[dim], T[dim]> type
boost fusion that store the point
void ceilP2()
Apply the ceil operation to the point P2.
bool operator!=(const Box< dim, T > &b) const
Compare two boxes.
void contained(const Box< dim, T > &en, const bool reset_p1=true)
Refine the box to be contained in the given box and itself.
T getVolumeKey() const
Get the volume spanned by the Box P1 and P2 interpreted as grid key.
void shrinkP2(T sh)
Shrink moving p2 of sh quantity (on each direction)
void set(std::initializer_list< T > p1, std::initializer_list< T > p2)
Constructor from initializer list.
Point< dim, T > getP2() const
Get the point p2.
T radius()
Get the radius of the sphere.
static const unsigned int dims
dimensionality of the box