OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
Sphere.hpp
1 #ifndef SPHERE_HPP
2 #define SPHERE_HPP
3 
4 #include <boost/fusion/sequence/intrinsic/at_c.hpp>
5 #include <boost/fusion/include/at_c.hpp>
6 #include <boost/fusion/container/vector.hpp>
7 #include <boost/fusion/include/vector.hpp>
8 #include <boost/fusion/container/vector/vector_fwd.hpp>
9 #include <boost/fusion/include/vector_fwd.hpp>
10 #include "boost/multi_array.hpp"
11 #include "Point.hpp"
12 #include <Space/Shape/Point.hpp>
13 
23 template<unsigned int dim ,typename T> class Sphere
24 {
25  public:
26 
28  typedef boost::fusion::vector<T[3],T> type;
29 
32 
34  static const unsigned int x = 0;
36  static const unsigned int r = 1;
37 
44  T center(unsigned int i)
45  {
46  return boost::fusion::at_c<x>(data)[i];
47  }
48 
58  template<unsigned int k>Sphere(boost::fusion::vector<T[k]> & c, T radius)
59  {
60  // Copy the center
61  for (int i = 0 ; i < dim ; i++)
62  {
63  boost::fusion::at_c<x>(data)[i] = boost::fusion::at_c<x>(c)[i];
64  }
65 
66  boost::fusion::at_c<r>(data) = radius;
67  }
68 
74  T radius()
75  {
76  return boost::fusion::at_c<r>(data);
77  }
78 
87  template<typename Distance> T isInside(Point<dim,T> p)
88  {
89  T dist;
90 
91  // Object to calculate distances
92  Distance d;
93 
94  // calculate the distance of the center from the point
95 
96  for (int i = 0; i < dim ; i++)
97  {
98  dist += d.accum_dist(boost::fusion::at_c<x>(data)[i],p.get(i) );
99  }
100 
101  // Check if the distance is smaller than the radius
102 
103  if (dist <= boost::fusion::at_c<r>(data))
104  {return true;}
105  else
106  {return false;}
107 
108  return false;
109  }
110 
118  template<typename Distance> bool isInside(float * pnt)
119  {
120  T dist;
121 
122  // Object to calculate distances
123  Distance d;
124 
125  // calculate the distance of the center from the point
126 
127  for (int i = 0; i < dim ; i++)
128  {
129  dist += d.accum_dist(boost::fusion::at_c<x>(data)[i],pnt[i],i);
130  }
131 
132  // Check if the distance is smaller than the radius
133 
134  if (dist <= boost::fusion::at_c<r>(data))
135  {return true;}
136  else
137  {return false;}
138 
139  return false;
140  }
141 };
142 
143 #endif
T center(unsigned int i)
Get the component i of the center.
Definition: Sphere.hpp:44
type data
Structure that store the data.
Definition: Sphere.hpp:31
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:20
bool isInside(float *pnt)
Is the point inside the sphere.
Definition: Sphere.hpp:118
static const unsigned int x
property id of the center position of the sphere
Definition: Sphere.hpp:34
T get(int i) const
Get coordinate.
Definition: Point.hpp:42
boost::fusion::vector< T[3], T > type
boost fusion that store the point
Definition: Sphere.hpp:28
T isInside(Point< dim, T > p)
Check if a point is inside.
Definition: Sphere.hpp:87
This class implement the Sphere concept in an N-dimensional space.
Definition: Sphere.hpp:23
static const unsigned int r
property id of the radius of the sphere
Definition: Sphere.hpp:36
Sphere(boost::fusion::vector< T[k]> &c, T radius)
Sphere constructor.
Definition: Sphere.hpp:58
T radius()
Get the radius of the sphere.
Definition: Sphere.hpp:74