~esys-p-dev/esys-particle/gengeo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/////////////////////////////////////////////////////////////
//                                                         //
// Copyright (c) 2007-2014 by The University of Queensland //
// Centre for Geoscience Computing                         //
// http://earth.uq.edu.au/centre-geoscience-computing      //
//                                                         //
// Primary Business: Brisbane, Queensland, Australia       //
// Licensed under the Open Software License version 3.0    //
// http://www.opensource.org/licenses/osl-3.0.php          //
//                                                         //
/////////////////////////////////////////////////////////////

#include "ClippedCircleVol.h"

using std::make_pair;

ClippedCircleVol::ClippedCircleVol()
{}
  
/*!
  constructor taking center and radius of the circle as arguments

  \param center the center of the circle
  \param radius the radius of the circle
*/
ClippedCircleVol::ClippedCircleVol(const Vector3& center,double radius):
  CircleVol(center,radius)
{}
  

/*!
  add a line to the volume

  \param l the line
  \param fit if true, line is used for fitting, if false line is only used for in/out detection
*/
void ClippedCircleVol::addLine(const Line2D& l,bool fit)
{
  m_lines.push_back(make_pair(l,fit));
}


/*!
  get a random point inside the volume

  \param n is ignored
*/
Vector3 ClippedCircleVol::getAPoint(int n) const
{
  Vector3 res;
  
  do {
    res=CircleVol::getAPoint(n);
  } while (!isIn(res));

  return res;
}
 
/*!
  get objects closest to a given point

  \param pos the point
  \param nr the max. number of objects returned
*/
const map<double,const AGeometricObject*> ClippedCircleVol::getClosestObjects(const Vector3& pos,int nr) const
{
  map<double,const AGeometricObject*> res=CircleVol::getClosestObjects(pos,nr);

  for(vector<pair<Line2D,bool> >::const_iterator iter=m_lines.begin();
      iter!=m_lines.end();
      iter++){
    if(iter->second){
      double dist=iter->first.getDist(pos);
      res.insert(make_pair(dist,&(iter->first)));
    }
  }
  return res;  
}

/*!
  test if a point is inside the volume

  \param pos the point
*/
bool ClippedCircleVol::isIn(const Vector3& pos) const
{
  bool res=CircleVol::isIn(pos);

  vector<pair<Line2D,bool> >::const_iterator iter=m_lines.begin();
  while(res && iter!=m_lines.end()){
    bool rside=((pos-iter->first.getOrig())*iter->first.getNormal())>0.0;
    res=res && rside;
    iter++;
  }
  return res;
}

/*!
  test if a sphere(circle) is completely inside the volume 

  \param S the sphere
*/
bool ClippedCircleVol::isIn(const Sphere& S)
{
  bool res=CircleVol::isIn(S);

  vector<pair<Line2D,bool> >::const_iterator iter=m_lines.begin();
  while(res && iter!=m_lines.end()){
    bool rside=((S.Center()-iter->first.getOrig())*iter->first.getNormal())>S.Radius();
    res=res && rside;
    iter++;
  }

  return res;
}