All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions | Variables
test_intersection Namespace Reference

Functions

def test_dAlgo
 

Variables

int _epsilon = 1
 
string OK = '\033[92m'
 
string NO = '\033[91m'
 
string BLUE = '\033[94m'
 
string ENDC = '\033[0m'
 

Function Documentation

def test_intersection.test_dAlgo ( )

Definition at line 18 of file larcorealg/test/GeoAlgo/test_intersection.py.

18 
19 def test_dAlgo():
20 
21  debug()
22  debug(BLUE + "Precision Being Required to Consider Two numbers Equal: {0:.2e}".format(_epsilon) + ENDC)
23  debug()
24 
25  # number of times to test each function
26  tests = 10000
27 
28  # import Distance Algo
29  iAlgo = geoalgo.GeoAlgo()
30 
31  try:
32 
33  # test distance to and back from wall
34  info('Testing Intersection Between Half-Line & AABox')
35  totSuccess_f = 0
36  intersectT_f = 0
37  totSuccess_b = 0
38  intersectT_b = 0
39  for y in range(tests):
40  success_f = 1
41  success_b = 1
42  # generate a unit cubic box from (0,0,0) to (1,1,1)
43  box = geoalgo.AABox(0,0,0,1,1,1)
44  # generate random point inside box
45  # half-line will start from this point
47  # now find random intersection point
48  # pick a side of the box that the point is on
49  pick = random()
50  side = 0
51  if ( (pick > 0.33) and (pick < 0.67) ) : side = 1
52  if ( pick > 0.67 ) : side = 2
53  # pick a direction (Left/Right), (Top/Bottom), (Front/Back) that the point should be on
54  # given the direction & side, find the intersection point on the relevant face of the cube. That will be our intersection point. Make the half-line pass through there
55  direction = 1
56  if ( random() < 0.5 ) : direction = -1
57  # pl is a parameter to know numerical value of coordinate for the face we are on
58  # if direction = 1 -> pl = +1 (box.Max())
59  # if direction = -1 -> pl = -1 (box.Min())
60  pl = 1
61  if ( direction == -1 ) :
62  pl = 0
63  if ( side == 0 ) :
64  i = geoalgo.Vector(pl,random(),random())
65  elif ( side == 1 ) :
66  i = geoalgo.Vector(random(),pl,random())
67  else :
68  i = geoalgo.Vector(random(),random(),pl)
69  # now generate half-line passing thorugh p and i & starting from p
70  d = i-p
71  lin = geoalgo.HalfLine(p,d)
72  # answer should be distance between p & i
73  # point should be i
74  answer = i.SqDist(p)
75  pt1 = geoalgo.Vector(3)
76  pt2 = geoalgo.Vector(3)
77  tim = time()
78  pt1_v = iAlgo.Intersection(box,lin)
79  intersectT_f += (time()-tim)
80  pt2_v = iAlgo.Intersection(lin,box)
81  if pt1_v.size(): pt1 = pt1_v[0]
82  if pt2_v.size(): pt2 = pt2_v[0]
83  a1 = pt1.SqDist(p)
84  a2 = pt2.SqDist(p)
85  if not ( np.abs(answer-a1) < _epsilon ) : success_f = 0
86  if not ( np.abs(answer-a2) < _epsilon ) : success_f = 0
87  for x in xrange(3):
88  if not ( np.abs(pt1[x]-i[x]) < _epsilon) : success_f = 0
89  if not ( np.abs(pt1[x]-i[x]) < _epsilon) : success_f = 0
90  totSuccess_f += success_f
91  # now backwards:
92  # make line go in opposite direction -> intersection point should be the same
93  d = p-i
94  lin = geoalgo.HalfLine(p,d)
95  pt1 = geoalgo.Vector(3)
96  pt2 = geoalgo.Vector(3)
97  tim = time()
98  pt1_v = iAlgo.Intersection(box,lin,1)
99  intersectT_b += (time()-tim)
100  pt2_v = iAlgo.Intersection(lin,box,1)
101  if pt1_v.size(): pt1 = pt1_v[0]
102  if pt2_v.size(): pt2 = pt2_v[0]
103  a1 = pt1.SqDist(p)
104  a2 = pt2.SqDist(p)
105  if not ( np.abs(answer-a1) < _epsilon ) : success_b = 0
106  if not ( np.abs(answer-a2) < _epsilon ) : success_b = 0
107  for x in xrange(3):
108  if not ( np.abs(pt1[x]-i[x]) < _epsilon) : success_b = 0
109  if not ( np.abs(pt1[x]-i[x]) < _epsilon) : success_b = 0
110  if (success_b == 1) : totSuccess_b += 1
111 
112  if ( float(totSuccess_f)/tests < 1):
113  info(NO + "Success: {0}%".format(100*float(totSuccess_f)/tests) + ENDC)
114  else:
115  info(OK + "Success: {0}%".format(100*float(totSuccess_f)/tests) + ENDC)
116  info("Time for Intersection : {0:.3f} us".format(1E6*intersectT_f/tests))
117  if ( float(totSuccess_b)/tests < 1):
118  info(NO + "Success: {0}%".format(100*float(totSuccess_b)/tests) + ENDC)
119  else:
120  info(OK + "Success: {0}%".format(100*float(totSuccess_b)/tests) + ENDC)
121  info("Time for Intersection : {0:.3f} us".format(1E6*intersectT_b/tests))
122 
123 
124  except Exception:
125  error('geoalgo::IntersectAlgo unit test failed.')
126  print traceback.format_exception(*sys.exc_info())[2]
127  return 1
128 
129  info('geoalgo::IntersectAlgo unit test complete.')
130  return 0
Algorithm to compute various geometrical relation among geometrical objects. In particular functions ...
static std::string format(PyObject *obj, unsigned int pos, unsigned int indent, unsigned int maxlen, unsigned int depth)
Definition: fclmodule.cxx:374
Representation of a 3D rectangular box which sides are aligned w/ coordinate axis. A representation of an Axis-Aligned-Boundary-Box, a simple &amp; popular representation of 3D boundary box for collision detection. The concept was taken from the reference, Real-Time-Collision-Detection (RTCD), and in particular Ch. 4.2 (page 77): .
Representation of a 3D semi-infinite line. Defines a semi-infinite 3D line by having a start point (P...

Variable Documentation

int test_intersection._epsilon = 1

Definition at line 10 of file larcorealg/test/GeoAlgo/test_intersection.py.

string test_intersection.BLUE = '\033[94m'

Definition at line 15 of file larcorealg/test/GeoAlgo/test_intersection.py.

string test_intersection.ENDC = '\033[0m'

Definition at line 16 of file larcorealg/test/GeoAlgo/test_intersection.py.

string test_intersection.NO = '\033[91m'

Definition at line 14 of file larcorealg/test/GeoAlgo/test_intersection.py.

string test_intersection.OK = '\033[92m'

Definition at line 13 of file larcorealg/test/GeoAlgo/test_intersection.py.