All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
geoalgo::Sphere Class Reference

#include <GeoSphere.h>

Public Member Functions

 Sphere ()
 Default ctor. More...
 
virtual ~Sphere ()
 Default dtor. More...
 
 Sphere (const double &x, const double &y, const double &z, const double &r)
 Alternative ctor (0) More...
 
 Sphere (const Point_t &center, const double r=0)
 Altenartive ctor (1) - 1 Point. More...
 
 Sphere (const Point_t &pt1, const Point_t &pt2)
 Alternative ctor (2) - 2 Points. More...
 
 Sphere (const Point_t &A, const Point_t &B, const Point_t &C)
 Alternative ctor (3) - 3 Points. More...
 
 Sphere (const Point_t &A, const Point_t &B, const Point_t &C, const Point_t &D)
 
 Sphere (const std::vector< ::geoalgo::Point_t > &pts)
 
const Point_tCenter () const
 Center getter. More...
 
double Radius () const
 Radius getter. More...
 
void Center (const double x, const double y, const double z)
 Center setter. More...
 
void Center (const Point_t &pt)
 Center setter. More...
 
void Radius (const double &r)
 Radius setter. More...
 
bool Contain (const Point_t &p) const
 Judge if a point is contained within a sphere. More...
 
template<class T >
 Sphere (const T &pt1, const T &pt2)
 
template<class T >
 Sphere (const T &A, const T &B, const T &C)
 
template<class T >
 Sphere (const T &A, const T &B, const T &C, const T &D)
 
template<class T >
 Sphere (const std::vector< T > &pts)
 
template<class T >
void Center (const T &pt)
 
template<class T >
bool Contain (const T &p) const
 
 Sphere ()
 Default ctor. More...
 
virtual ~Sphere ()
 Default dtor. More...
 
 Sphere (const double &x, const double &y, const double &z, const double &r)
 Alternative ctor (0) More...
 
 Sphere (const Point_t &center, const double r=0)
 Altenartive ctor (1) - 1 Point. More...
 
 Sphere (const Point_t &pt1, const Point_t &pt2)
 Alternative ctor (2) - 2 Points. More...
 
 Sphere (const Point_t &A, const Point_t &B, const Point_t &C)
 Alternative ctor (3) - 3 Points. More...
 
 Sphere (const Point_t &A, const Point_t &B, const Point_t &C, const Point_t &D)
 
 Sphere (const std::vector< ::geoalgo::Point_t > &pts)
 
const Point_tCenter () const
 Center getter. More...
 
double Radius () const
 Radius getter. More...
 
void Center (const double x, const double y, const double z)
 Center setter. More...
 
void Center (const Point_t &pt)
 Center setter. More...
 
void Radius (const double &r)
 Radius setter. More...
 
bool Contain (const Point_t &p) const
 Judge if a point is contained within a sphere. More...
 
template<class T >
 Sphere (const T &pt1, const T &pt2)
 
template<class T >
 Sphere (const T &A, const T &B, const T &C)
 
template<class T >
 Sphere (const T &A, const T &B, const T &C, const T &D)
 
template<class T >
 Sphere (const std::vector< T > &pts)
 
template<class T >
void Center (const T &pt)
 
template<class T >
bool Contain (const T &p) const
 

Protected Member Functions

void compat (const Point_t &p, const double r=0) const
 3D point compatibility check More...
 
void compat (const double &r) const
 Positive radius compatibility check. More...
 
void compat (const Point_t &p, const double r=0) const
 3D point compatibility check More...
 
void compat (const double &r) const
 Positive radius compatibility check. More...
 

Protected Attributes

Point_t _center
 Center of Sphere. More...
 
double _radius
 Radius of Sphere. More...
 

Detailed Description

Definition at line 27 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.h.

Constructor & Destructor Documentation

geoalgo::Sphere::Sphere ( )

Default ctor.

Definition at line 8 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.cxx.

8  : _center (3)
9  , _radius (0)
10  { for(auto& v : _center) v=0; }
virtual geoalgo::Sphere::~Sphere ( )
inlinevirtual

Default dtor.

Definition at line 32 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.h.

geoalgo::Sphere::Sphere ( const double &  x,
const double &  y,
const double &  z,
const double &  r 
)

Alternative ctor (0)

Definition at line 12 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.cxx.

13  : Sphere()
14  { _center[0] = x; _center[1] = y; _center[2] = z; _radius = r; }
process_name opflash particleana ie ie ie z
process_name opflash particleana ie x
process_name opflash particleana ie ie y
esac echo uname r
geoalgo::Sphere::Sphere ( const Point_t center,
const double  r = 0 
)

Altenartive ctor (1) - 1 Point.

Definition at line 16 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.cxx.

17  : _radius (r)
18  {_center = center;}
esac echo uname r
geoalgo::Sphere::Sphere ( const Point_t pt1,
const Point_t pt2 
)

Alternative ctor (2) - 2 Points.

Definition at line 20 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.cxx.

21  {
22  compat(pt1);
23  compat(pt2);
24  _center = (pt1+pt2)/2.;
25  _radius = pt1.Dist(pt2)/2.;
26  }
void compat(const Point_t &p, const double r=0) const
3D point compatibility check
geoalgo::Sphere::Sphere ( const Point_t A,
const Point_t B,
const Point_t C 
)

Alternative ctor (3) - 3 Points.

Definition at line 31 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.cxx.

32  {
33  compat(A);
34  compat(B);
35  compat(C);
36  // any three points are co-planar
37  // (if collinear no sphere passing through all 3)
38  // These 3 points make a triangle
39  // find the perpendicular bi-sectors to the segments
40  // making up the triangle. They will intersect
41  // at the sphere's center
42 
43  // check if collinear. If so return exception
44  Vector_t AB(B-A);
45  Vector_t AC(C-A);
46  Vector_t BC(C-B);
47 
48  double dABAB = AB.Dot(AB);
49  double dACAC = AC.Dot(AC);
50  double dABAC = AB.Dot(AC);
51 
52  double d = dABAB * dACAC - dABAC * dABAC;
53  double s,t;
54 
55  // if d == 0 they lie on one line
56  if (d == 0){
57  std::cout << "d is 0!" << std::endl;
58  double lenAB = AB.Length();
59  double lenAC = AC.Length();
60  double lenBC = BC.Length();
61  // which segment is longest?
62  if ( (lenAB > lenAC) && (lenAB > lenBC) ){
63  _center = (A+B)/2.;
64  _radius = _center.Dist(A);
65  }
66  else if( lenAC > lenBC ){
67  _center = (A+C)/2.;
68  _radius = _center.Dist(A);
69  }
70  else{
71  _center = (B+C)/2;
72  _radius = _center.Dist(B);
73  }
74  }// if d == 0
75 
76  else{
77  s = 0.5 * ( dABAB * dACAC - dACAC * dABAC ) / d;
78  t = 0.5 * ( dACAC * dABAB - dABAB * dABAC ) / d;
79 
80  // if s & t both > 0 && 1-s-t also > 0 then P = A + s*(B-A) + t*(C-A) is the center
81  if ( (s > 0) && (t > 0) && ((1-s-t) > 0) ){
82  _center = A+(B-A)*s+(C-A)*t;
83  _radius = _center.Dist(A);
84  }
85 
86  // otherwise only one will be negative. The side it belongs on will be
87  // the longest side and will determine the side to take as diameter
88  else if (s <= 0){
89  // side AB is the one
90  _center = (A+C)/2.;
91  _radius = _center.Dist(A);
92  }
93  else if (t <= 0){
94  // AC is the side
95  _center = (A+B)/2.;
96  _radius = _center.Dist(A);
97  }
98  else{
99  _center = (B+C)/2;
100  _radius = _center.Dist(B);
101  }
102  }// else (if d not equal to 0)
103 
104  }
double Dist(const Vector &obj) const
Compute the distance to another vector.
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
void compat(const Point_t &p, const double r=0) const
3D point compatibility check
float A
Definition: dedx.py:137
recob::tracking::Vector_t Vector_t
BEGIN_PROLOG could also be cout
geoalgo::Sphere::Sphere ( const Point_t A,
const Point_t B,
const Point_t C,
const Point_t D 
)

Definition at line 183 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.cxx.

183  {
184 
185  compat(A);
186  compat(B);
187  compat(C);
188  compat(D);
189 
190  // let's make sure there aren't duplicates...if so -> call a
191  // different constructor
192  std::vector<geoalgo::Point_t> valid_points = {A};
193  bool duplicate = false;
194  for (auto const& pt : valid_points){
195  if (pt.SqDist(B) < 0.0001)
196  duplicate = true;
197  }
198  if (duplicate == false)
199  valid_points.push_back(B);
200  duplicate = false;
201  for (auto const& pt : valid_points){
202  if (pt.SqDist(C) < 0.0001)
203  duplicate = true;
204  }
205  if (duplicate == false)
206  valid_points.push_back(C);
207  duplicate = false;
208  for (auto const& pt : valid_points){
209  if (pt.SqDist(D) < 0.0001)
210  duplicate = true;
211  }
212  if (duplicate == false)
213  valid_points.push_back(D);
214 
215  // if we have less then 4 points -> call the appropriate constructor
216  if (valid_points.size() < 4){
217  (*this) = Sphere(valid_points);
218  return;
219  }
220 
221  // get sphere from 3 points (A,B,C)
222  Vector_t AB(B-A);
223  Vector_t AC(C-A);
224  Vector_t AD(D-A);
225 
226  double dABAB = AB.Dot(AB);
227  double dACAC = AC.Dot(AC);
228  double dADAD = AD.Dot(AD);
229  double dABAC = AB.Dot(AC);
230  double dABAD = AB.Dot(AD);
231  double dACAD = AC.Dot(AD);
232 
233  double d = 4*dABAC*dABAD*dACAD;
234 
235  if (d==0){
236  // are any points duplicates? if so
237  // find the points that are collinear and call constructor
238  // for the
239  throw GeoAlgoException("GeoSphere Exception: I think it means 3 points collinear. Find out which and call 3 point constructor - TO DO");
240  }
241 
242  double s = (dABAC*dACAD*dADAD + dABAD*dACAC*dACAD - dABAB*dACAD*dACAD)/d;
243  double t = (dABAB*dACAD*dABAD + dABAD*dABAC*dADAD - dABAD*dABAD*dACAC)/d;
244  double u = (dABAB*dABAC*dACAD + dABAC*dABAD*dACAC - dABAC*dABAC*dADAD)/d;
245 
246  // if everything positive! P = A + s(B-A) + t(C-A) + u(D-A)
247  if ( (s > 0) && (t > 0) && (u > 0) && ((1-s-t-u) > 0) ){
248  _center = A + AB*s + AC*t + AD*u;
249  _radius = _center.Dist(A);
250  }
251  else{
252  // take the largest side and use it as the diameter
253  double maxdist = A.Dist(B);
254  Vector_t max1 = A;
255  Vector_t max2 = B;
256  if (A.Dist(C) > maxdist){
257  maxdist = A.Dist(C);
258  max1 = A;
259  max2 = C;
260  }
261  if (A.Dist(D) > maxdist){
262  maxdist = A.Dist(D);
263  max1 = A;
264  max2 = D;
265  }
266  if (B.Dist(C) > maxdist){
267  maxdist = B.Dist(C);
268  max1 = B;
269  max2 = C;
270  }
271  if (B.Dist(D) > maxdist){
272  maxdist = B.Dist(D);
273  max1 = B;
274  max2 = D;
275  }
276  if (C.Dist(D) > maxdist){
277  maxdist = C.Dist(D);
278  max1 = C;
279  max2 = D;
280  }
281  _center = (max1+max2)/2.;
282  _radius = max1.Dist(max2)/2.;
283  }
284 
285 
286  // TEMPORARY
287  // otherwise find the 4 possible sphere combinations,
288  // which contains the 4th point,
289  // and if multiple ones choose the one with the smallest radius
290  Sphere tmp = Sphere(A,B,C);
291  //_radius = kINVALID_DOUBLE;
292  if (tmp.Contain(D)){
293  _center = tmp.Center();
294  _radius = tmp.Radius();
295  }
296  tmp = Sphere(A,B,D);
297  if (tmp.Contain(C)){
298  if (tmp.Radius() < _radius){
299  _center = tmp.Center();
300  _radius = tmp.Radius();
301  }
302  }
303  tmp = Sphere(A,C,D);
304  if (tmp.Contain(B)){
305  if (tmp.Radius() < _radius){
306  _center = tmp.Center();
307  _radius = tmp.Radius();
308  }
309  }
310  tmp = Sphere(B,C,D);
311  if (tmp.Contain(A)){
312  if (tmp.Radius() < _radius){
313  _center = tmp.Center();
314  _radius = tmp.Radius();
315  }
316  }
317 
318  }
double Dist(const Vector &obj) const
Compute the distance to another vector.
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
void compat(const Point_t &p, const double r=0) const
3D point compatibility check
float A
Definition: dedx.py:137
recob::tracking::Vector_t Vector_t
geoalgo::Sphere::Sphere ( const std::vector< ::geoalgo::Point_t > &  pts)

Definition at line 322 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.cxx.

323  : _center(0,0,0)
324  , _radius(0)
325  {
326 
327  switch(pts.size()) {
328  case 0:
329  break;
330  case 1: _center = pts.front();
331  break;
332  case 2: (*this) = Sphere(pts[0],pts[1]);
333  break;
334  case 3: (*this) = Sphere(pts[0],pts[1],pts[2]);
335  break;
336  case 4: (*this) = Sphere(pts[0],pts[1],pts[2],pts[3]);
337  break;
338  default:
339  throw GeoAlgoException("Cannot call Sphere constructor with more than 4 points. Something went wront");
340  }
341 
342  }
template<class T >
geoalgo::Sphere::Sphere ( const T &  pt1,
const T &  pt2 
)
inline
template<class T >
geoalgo::Sphere::Sphere ( const T &  A,
const T &  B,
const T &  C 
)
inline
template<class T >
geoalgo::Sphere::Sphere ( const T &  A,
const T &  B,
const T &  C,
const T &  D 
)
inline
template<class T >
geoalgo::Sphere::Sphere ( const std::vector< T > &  pts)
inline

Definition at line 105 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.h.

106  {
107  std::vector< ::geoalgo::Vector> geo_pts;
108  geo_pts.reserve(pts);
109  for(auto const& p : pts) geo_pts.emplace_back(p);
110  (*this) = Sphere(geo_pts);
111  }
pdgs p
Definition: selectors.fcl:22
geoalgo::Sphere::Sphere ( )

Default ctor.

virtual geoalgo::Sphere::~Sphere ( )
inlinevirtual

Default dtor.

Definition at line 30 of file sbncode/sbncode/OpT0Finder/flashmatch/GeoAlgo/GeoSphere.h.

geoalgo::Sphere::Sphere ( const double &  x,
const double &  y,
const double &  z,
const double &  r 
)

Alternative ctor (0)

geoalgo::Sphere::Sphere ( const Point_t center,
const double  r = 0 
)

Altenartive ctor (1) - 1 Point.

geoalgo::Sphere::Sphere ( const Point_t pt1,
const Point_t pt2 
)

Alternative ctor (2) - 2 Points.

geoalgo::Sphere::Sphere ( const Point_t A,
const Point_t B,
const Point_t C 
)

Alternative ctor (3) - 3 Points.

geoalgo::Sphere::Sphere ( const Point_t A,
const Point_t B,
const Point_t C,
const Point_t D 
)
geoalgo::Sphere::Sphere ( const std::vector< ::geoalgo::Point_t > &  pts)
template<class T >
geoalgo::Sphere::Sphere ( const T &  pt1,
const T &  pt2 
)
inline
template<class T >
geoalgo::Sphere::Sphere ( const T &  A,
const T &  B,
const T &  C 
)
inline
template<class T >
geoalgo::Sphere::Sphere ( const T &  A,
const T &  B,
const T &  C,
const T &  D 
)
inline
template<class T >
geoalgo::Sphere::Sphere ( const std::vector< T > &  pts)
inline

Definition at line 103 of file sbncode/sbncode/OpT0Finder/flashmatch/GeoAlgo/GeoSphere.h.

104  {
105  std::vector< ::geoalgo::Vector> geo_pts;
106  geo_pts.reserve(pts);
107  for(auto const& p : pts) geo_pts.emplace_back(p);
108  (*this) = Sphere(geo_pts);
109  }
pdgs p
Definition: selectors.fcl:22

Member Function Documentation

const Point_t& geoalgo::Sphere::Center ( ) const

Center getter.

const Point_t & geoalgo::Sphere::Center ( ) const

Center getter.

Definition at line 344 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.cxx.

344 { return _center; }
void geoalgo::Sphere::Center ( const double  x,
const double  y,
const double  z 
)

Center setter.

void geoalgo::Sphere::Center ( const Point_t pt)

Center setter.

void geoalgo::Sphere::Center ( const double  x,
const double  y,
const double  z 
)

Center setter.

Definition at line 348 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.cxx.

349  { _center[0] = x; _center[1] = y; _center[2] = z; }
process_name opflash particleana ie ie ie z
process_name opflash particleana ie x
process_name opflash particleana ie ie y
void geoalgo::Sphere::Center ( const Point_t pt)

Center setter.

Definition at line 351 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.cxx.

352  { compat(center); _center = center; }
void compat(const Point_t &p, const double r=0) const
3D point compatibility check
template<class T >
void geoalgo::Sphere::Center ( const T &  pt)
inline
template<class T >
void geoalgo::Sphere::Center ( const T &  pt)
inline

Definition at line 113 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.h.

114  { Center(Point_t(pt)); }
const Point_t & Center() const
Center getter.
void geoalgo::Sphere::compat ( const Point_t p,
const double  r = 0 
) const
protected

3D point compatibility check

void geoalgo::Sphere::compat ( const double &  r) const
protected

Positive radius compatibility check.

void geoalgo::Sphere::compat ( const Point_t p,
const double  r = 0 
) const
protected

3D point compatibility check

Definition at line 363 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.cxx.

364  {
365  if(p.size()!=3) throw GeoAlgoException("Only 3D points allowed for sphere");
366  compat(r);
367  }
pdgs p
Definition: selectors.fcl:22
void compat(const Point_t &p, const double r=0) const
3D point compatibility check
esac echo uname r
void geoalgo::Sphere::compat ( const double &  r) const
protected

Positive radius compatibility check.

Definition at line 369 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.cxx.

370  { if(r<0) throw GeoAlgoException("Only positive value allowed for radius"); }
esac echo uname r
bool geoalgo::Sphere::Contain ( const Point_t p) const

Judge if a point is contained within a sphere.

bool geoalgo::Sphere::Contain ( const Point_t p) const

Judge if a point is contained within a sphere.

Definition at line 357 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.cxx.

358  {
359  _center.compat(p);
360  return ( p._Dist_(_center) < _radius );
361  }
pdgs p
Definition: selectors.fcl:22
void compat(const Vector &obj) const
Dimensional check for a compatibility.
template<class T >
bool geoalgo::Sphere::Contain ( const T &  p) const
inline

Definition at line 114 of file sbncode/sbncode/OpT0Finder/flashmatch/GeoAlgo/GeoSphere.h.

115  { return Contain(Point_t(p)); }
bool Contain(const Point_t &p) const
Judge if a point is contained within a sphere.
pdgs p
Definition: selectors.fcl:22
template<class T >
bool geoalgo::Sphere::Contain ( const T &  p) const
inline

Definition at line 116 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.h.

117  { return Contain(Point_t(p)); }
bool Contain(const Point_t &p) const
Judge if a point is contained within a sphere.
pdgs p
Definition: selectors.fcl:22
double geoalgo::Sphere::Radius ( ) const

Radius getter.

double geoalgo::Sphere::Radius ( ) const

Radius getter.

Definition at line 346 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.cxx.

346 { return _radius; }
void geoalgo::Sphere::Radius ( const double &  r)

Radius setter.

void geoalgo::Sphere::Radius ( const double &  r)

Radius setter.

Definition at line 354 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.cxx.

355  { compat(r); _radius = r; }
void compat(const Point_t &p, const double r=0) const
3D point compatibility check
esac echo uname r

Member Data Documentation

Point_t geoalgo::Sphere::_center
protected

Center of Sphere.

Definition at line 76 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.h.

double geoalgo::Sphere::_radius
protected

Radius of Sphere.

Definition at line 79 of file larcorealg/larcorealg/GeoAlgo/GeoSphere.h.


The documentation for this class was generated from the following files: