LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
GeoSphere.h
Go to the documentation of this file.
1 
14 #ifndef BASICTOOL_GEOSPHERE_H
15 #define BASICTOOL_GEOSPHERE_H
16 
18 
19 #include <vector>
20 
21 namespace geoalgo {
27  class Sphere {
28 
29  public:
30  Sphere();
31  virtual ~Sphere() {}
32 
34  Sphere(const double& x, const double& y, const double& z, const double& r);
35 
37  Sphere(const Point_t& center, const double r = 0);
38 
40  Sphere(const Point_t& pt1, const Point_t& pt2);
41 
43  Sphere(const Point_t& A, const Point_t& B, const Point_t& C);
44 
45  // Alternative ctor (4) - 4 Points
46  Sphere(const Point_t& A, const Point_t& B, const Point_t& C, const Point_t& D);
47 
48  // Alternative ctor (5) - Set of points
49  Sphere(const std::vector<::geoalgo::Point_t>& pts);
50 
51  //
52  // Getters
53  //
54  const Point_t& Center() const;
55  double Radius() const;
56 
57  //
58  // Setters
59  //
60  void Center(const double x, const double y, const double z);
61  void Center(const Point_t& pt);
62  void Radius(const double& r);
63 
64  //
65  // Utilities
66  //
67  bool Contain(const Point_t& p) const;
68 
69  protected:
70  void compat(const Point_t& p, const double r = 0) const;
71  void compat(const double& r) const;
72 
75 
77  double _radius;
78 
79  public:
80  //
81  // Templates
82  //
83  /*
84 #ifndef __CINT__ // Not sure why but CINT has a problem with this ctor. FIXME
85  template <class T> Sphere(const T& center, const double r=0)
86  : Sphere(Point_t(center),r)
87  {}
88 #endif
89  */
90  template <class T>
91  Sphere(const T& pt1, const T& pt2) : Sphere(Point_t(pt1), Point_t(pt2))
92  {}
93 
94  template <class T>
95  Sphere(const T& A, const T& B, const T& C) : Sphere(Point_t(A), Point_t(B), Point_t(C))
96  {}
97 
98  template <class T>
99  Sphere(const T& A, const T& B, const T& C, const T& D)
100  : Sphere(Point_t(A), Point_t(B), Point_t(C), Point_t(D))
101  {}
102 
103  template <class T>
104  Sphere(const std::vector<T>& pts)
105  {
106  std::vector<::geoalgo::Vector> geo_pts;
107  geo_pts.reserve(pts);
108  for (auto const& p : pts)
109  geo_pts.emplace_back(p);
110  (*this) = Sphere(geo_pts);
111  }
112 
113  template <class T>
114  void Center(const T& pt)
115  {
116  Center(Point_t(pt));
117  }
118 
119  template <class T>
120  bool Contain(const T& p) const
121  {
122  return Contain(Point_t(p));
123  }
124  };
125 
126  typedef Sphere Sphere_t;
127 }
128 #endif
129  // end of doxygen group
Float_t x
Definition: compare.C:6
TRandom r
Definition: spectrum.C:23
bool Contain(const Point_t &p) const
Judge if a point is contained within a sphere.
Definition: GeoSphere.cxx:365
Sphere(const T &pt1, const T &pt2)
Definition: GeoSphere.h:91
virtual ~Sphere()
Default dtor.
Definition: GeoSphere.h:31
bool Contain(const T &p) const
Definition: GeoSphere.h:120
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:276
void Center(const T &pt)
Definition: GeoSphere.h:114
Sphere(const T &A, const T &B, const T &C)
Definition: GeoSphere.h:95
TText * pt2
Definition: plot.C:64
Sphere(const T &A, const T &B, const T &C, const T &D)
Definition: GeoSphere.h:99
Class def header for a class Point and Vector.
TMarker * pt
Definition: egs.C:25
double Radius() const
Radius getter.
Definition: GeoSphere.cxx:341
const Point_t & Center() const
Center getter.
Definition: GeoSphere.cxx:336
Sphere(const std::vector< T > &pts)
Definition: GeoSphere.h:104
Vector Point_t
Definition: GeoVector.h:204
Point_t _center
Center of Sphere.
Definition: GeoSphere.h:74
void compat(const Point_t &p, const double r=0) const
3D point compatibility check
Definition: GeoSphere.cxx:371
double _radius
Radius of Sphere.
Definition: GeoSphere.h:77
TText * pt1
Definition: plot.C:61
Sphere Sphere_t
Definition: GeoSphere.h:126
Sphere()
Default ctor.
Definition: GeoSphere.cxx:8