Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
wire-cell-build
util
test
test_intersection.cxx
Go to the documentation of this file.
1
#include "
WireCellUtil/Intersection.h
"
2
#include "
WireCellUtil/Testing.h
"
3
4
#include <iostream>
5
#include <random>
6
7
using namespace
WireCell
;
8
using namespace
std
;
9
10
int
main
()
11
{
12
{
13
Ray
bounds
(
Point
(-5, -500, -500),
Point
(5, 500, 500));
14
Ray
line
(
Point
(1, 0, -495),
Point
(1, 1, -495));
15
Ray
hits;
16
int
hitmask =
box_intersection
(bounds, line, hits);
17
cerr <<
"line: "
<< line <<
" bounds:"
<< bounds <<
endl
;
18
cerr <<
"got: "
<< hitmask <<
" "
<< hits<<
endl
;
19
Assert
(hitmask == 3);
20
}
21
22
23
std::random_device rd;
24
std::default_random_engine re(rd());
25
std::uniform_real_distribution<> dist(-2, 2);
26
27
Ray
bounds
(
Point
(-1,-1,-1),
Point
(1,1,1));
28
for
(
int
ind = 0; ind<100; ++ind) {
29
Point
p1
(dist(re),dist(re),dist(re));
30
Point
p2
(dist(re),dist(re),dist(re));
31
Vector
dir
= (p2-
p1
).
norm
();
32
33
cout << ind <<
" point="
<< p1 <<
" dir="
<< dir <<
endl
;
34
35
for
(
int
axis=0; axis<3; ++axis) {
36
Ray
hits;
37
int
hitmask =
hit_square
(axis, bounds, p1, dir, hits);
38
cout <<
"\t axis="
<< axis <<
" ["
<<hitmask<<
"]hits="
<< hits <<
endl
;
39
Assert
(hitmask>=0);
40
41
}
42
43
{
44
Ray
ray(p1,p2), hits;
45
int
hitmask =
box_intersection
(bounds, ray, hits);
46
cout <<
"box: hitmask="
<< hitmask <<
" ray="
<< ray
47
<<
" hits="
<< hits <<
endl
;
48
if
(
point_contained
(p1, bounds) &&
point_contained
(p2, bounds)) {
49
AssertMsg
(hitmask == 3,
"Inside box, but not enough hits"
);
50
}
51
}
52
}
53
54
return
0;
55
}
WireCell::Ray
std::pair< Point, Point > Ray
A line segment running from a first (tail) to a second (head) point.
Definition:
Point.h:21
test_gen_rays_pdsp.p2
list p2
Definition:
test_gen_rays_pdsp.py:22
WireCell::Point
D3Vector< double > Point
A 3D Cartesian point in double precision.
Definition:
Point.h:15
std
STL namespace.
dir
string dir
Definition:
INukeNucleonCorr.cxx:59
Assert
#define Assert
Definition:
Testing.h:7
test_gen_rays_pdsp.p1
list p1
Definition:
test_gen_rays_pdsp.py:21
WireCell::hit_square
int hit_square(int axis0, const Ray &bounds, const Point &point, const Vector &dir, Ray &hits)
Definition:
Intersection.cxx:8
Testing.h
bounds
BoundingBox bounds(int x, int y, int w, int h)
Definition:
main.cpp:37
geo::vect::norm
auto norm(Vector const &v)
Return norm of the specified vector.
Definition:
geo_vectors_utils.h:1202
WireCell
Definition:
Main.h:22
Vector
std::vector< float > Vector
Definition:
test_AdcSampleScaler.cxx:27
Intersection.h
AssertMsg
#define AssertMsg
Definition:
Testing.h:8
WireCell::point_contained
bool point_contained(const Point &point, const Ray &bounds)
Definition:
Point.cxx:40
main
int main()
Definition:
test_intersection.cxx:10
getreco.line
line
Definition:
getreco.py:13
WireCell::box_intersection
int box_intersection(const Ray &bounds, const Ray &ray, Ray &hits)
Definition:
Intersection.cxx:61
endl
QTextStream & endl(QTextStream &s)
Definition:
qtextstream.cpp:2030
Generated by
1.8.11