Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PolyhedronTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PolyhedronTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/data/test_case.hpp>
10 #include <boost/test/tools/output_test_stream.hpp>
11 #include <boost/test/unit_test.hpp>
12 
13 #include <cmath>
14 #include <cstddef>
15 #include <vector>
16 
17 // Helper
20 #include "Acts/Geometry/Extent.hpp"
26 
27 namespace Acts {
28 
29 using namespace UnitLiterals;
30 
31 namespace Test {
32 
33 BOOST_AUTO_TEST_SUITE(Geometry)
34 
35 
36 BOOST_AUTO_TEST_CASE(PolyhedronTest) {
37  std::vector<Vector3> tvertices = {Vector3(-1, -1, 0.), Vector3(1., -1, 0.),
38  Vector3(0., 1., 0.)};
39  std::vector<std::vector<size_t>> tfaces = {{0, 1, 2}};
40 
41  Polyhedron triangle(tvertices, tfaces, tfaces);
42  BOOST_CHECK(tvertices == triangle.vertices);
43  BOOST_CHECK(tfaces == triangle.faces);
44  BOOST_CHECK(tfaces == triangle.triangularMesh);
45 
46  ObjVisualization3D objVis;
47  GeometryView3D::drawPolyhedron(objVis, triangle);
48  objVis.write("Polyhedron_Triangle");
49  objVis.clear();
50 
51  std::vector<Vector3> rvertices = {Vector3(-1, -2, 0.), Vector3(1., -2, 0.),
52  Vector3(1., -1., 0.),
53  Vector3(-1., -1., 0.)};
54  std::vector<std::vector<size_t>> rfaces = {{0, 1, 2, 3}};
55  std::vector<std::vector<size_t>> rmesh = {{0, 1, 2}, {2, 3, 0}};
56  Polyhedron rectangle(rvertices, rfaces, rmesh);
57  BOOST_CHECK(rvertices == rectangle.vertices);
58  BOOST_CHECK(rfaces == rectangle.faces);
59  BOOST_CHECK(rmesh == rectangle.triangularMesh);
60 
61  GeometryView3D::drawPolyhedron(objVis, rectangle);
62  objVis.write("Polyhedron_Rectangle");
63  objVis.clear();
64 
65  // Now add them
66  Polyhedron tr;
67  tr.merge(triangle);
68  BOOST_CHECK(tr.vertices == triangle.vertices);
69  BOOST_CHECK(tr.faces == triangle.faces);
70  BOOST_CHECK(tr.triangularMesh == triangle.triangularMesh);
71  tr.merge(rectangle);
72 
74  objVis.write("Polyhedron_TriangleRectangle");
75  objVis.clear();
76 }
77 
79 BOOST_AUTO_TEST_CASE(PolyhedronExtent) {
80  // Test a rectangle in x-y plane (at z == 0)
81  std::vector<Vector3> rvertices = {Vector3(-1, -2, 0.), Vector3(1., -2, 0.),
82  Vector3(1., -1., 0.),
83  Vector3(-1., -1., 0.)};
84 
85  std::vector<std::vector<size_t>> rfaces = {{0, 1, 2, 3}};
86  std::vector<std::vector<size_t>> rmesh = {{0, 1, 2}, {2, 3, 0}};
87  Polyhedron rectangle(rvertices, rfaces, rmesh);
88 
89  auto rExtent = rectangle.extent();
90  CHECK_CLOSE_ABS(rExtent.min(binX), -1., 1e-6);
91  CHECK_CLOSE_ABS(rExtent.max(binX), 1., 1e-6);
92  CHECK_CLOSE_ABS(rExtent.min(binY), -2., 1e-6);
93  CHECK_CLOSE_ABS(rExtent.max(binY), -1., 1e-6);
94  CHECK_CLOSE_ABS(rExtent.min(binZ), 0., 1e-6);
95  CHECK_CLOSE_ABS(rExtent.max(binZ), 0., 1e-6);
96  CHECK_CLOSE_ABS(rExtent.min(binR), 1., 1e-6);
97  CHECK_CLOSE_ABS(rExtent.max(binR), VectorHelpers::perp(rvertices[0]), 1e-6);
98  CHECK_CLOSE_ABS(rExtent.min(binPhi), VectorHelpers::phi(rvertices[3]), 1e-6);
99  CHECK_CLOSE_ABS(rExtent.max(binPhi), VectorHelpers::phi(rvertices[2]), 1e-6);
100 
101  // Now shift the Extent
102  Vector3 shift(-1., 0., 1.);
103  Transform3 shiftedTransform = Transform3::Identity();
104  shiftedTransform.pretranslate(shift);
105  rExtent = rectangle.extent(shiftedTransform);
106  CHECK_CLOSE_ABS(rExtent.min(binX), -2., 1e-6);
107  CHECK_CLOSE_ABS(rExtent.max(binX), 0., 1e-6);
108  CHECK_CLOSE_ABS(rExtent.min(binY), -2., 1e-6);
109  CHECK_CLOSE_ABS(rExtent.max(binY), -1., 1e-6);
110  CHECK_CLOSE_ABS(rExtent.min(binZ), 1., 1e-6);
111  CHECK_CLOSE_ABS(rExtent.max(binZ), 1., 1e-6);
112 
113  // Test a rectangle in yz - pane (at x == 3)
114  rvertices = {Vector3(3_mm, -5_mm, -10_mm), Vector3(3_mm, 5_mm, -10_mm),
115  Vector3(3_mm, 5_mm, 10_mm), Vector3(3_mm, -5_mm, 10_mm)};
116 
117  rectangle = Polyhedron(rvertices, rfaces, rmesh);
118  rExtent = rectangle.extent();
119  CHECK_CLOSE_ABS(rExtent.min(binX), 3., 1e-6);
120  CHECK_CLOSE_ABS(rExtent.max(binX), 3., 1e-6);
121  CHECK_CLOSE_ABS(rExtent.min(binY), -5., 1e-6);
122  CHECK_CLOSE_ABS(rExtent.max(binY), 5., 1e-6);
123  CHECK_CLOSE_ABS(rExtent.min(binZ), -10., 1e-6);
124  CHECK_CLOSE_ABS(rExtent.max(binZ), 10., 1e-6);
125  CHECK_CLOSE_ABS(rExtent.min(binR), 3., 1e-6);
126  CHECK_CLOSE_ABS(rExtent.max(binR), std::sqrt(9. + 25.), 1e-6);
127 }
128 
129 BOOST_AUTO_TEST_SUITE_END()
130 
131 } // namespace Test
132 
133 } // namespace Acts