ECCE @ EIC 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 // Helper
15 
16 // The class to test
17 #include <fstream>
20 #include "Acts/Utilities/Units.hpp"
22 
23 namespace Acts {
24 
25 using namespace UnitLiterals;
26 
27 namespace Test {
28 
29 BOOST_AUTO_TEST_SUITE(Geometry)
30 
31 
32 BOOST_AUTO_TEST_CASE(PolyhedronTest) {
33  std::vector<Vector3D> tvertices = {Vector3D(-1, -1, 0.), Vector3D(1., -1, 0.),
34  Vector3D(0., 1., 0.)};
35  std::vector<std::vector<size_t>> tfaces = {{0, 1, 2}};
36 
37  Polyhedron triangle(tvertices, tfaces, tfaces);
38  BOOST_CHECK(tvertices == triangle.vertices);
39  BOOST_CHECK(tfaces == triangle.faces);
40  BOOST_CHECK(tfaces == triangle.triangularMesh);
41 
42  std::ofstream tStream;
43  tStream.open("PolyhedronTriangle.obj");
44  ObjVisualization objtH;
45  triangle.draw(objtH);
46  objtH.write(tStream);
47  tStream.close();
48 
49  std::vector<Vector3D> rvertices = {Vector3D(-1, -2, 0.), Vector3D(1., -2, 0.),
50  Vector3D(1., -1., 0.),
51  Vector3D(-1., -1., 0.)};
52  std::vector<std::vector<size_t>> rfaces = {{0, 1, 2, 3}};
53  std::vector<std::vector<size_t>> rmesh = {{0, 1, 2}, {2, 3, 0}};
54  Polyhedron rectangle(rvertices, rfaces, rmesh);
55  BOOST_CHECK(rvertices == rectangle.vertices);
56  BOOST_CHECK(rfaces == rectangle.faces);
57  BOOST_CHECK(rmesh == rectangle.triangularMesh);
58 
59  std::ofstream rStream;
60  rStream.open("PolyhedronRectangle.obj");
61  ObjVisualization objrH;
62  rectangle.draw(objrH);
63  objrH.write(rStream);
64  rStream.close();
65 
66  // Now add them
67  Polyhedron tr;
68  tr.merge(triangle);
69  BOOST_CHECK(tr.vertices == triangle.vertices);
70  BOOST_CHECK(tr.faces == triangle.faces);
71  BOOST_CHECK(tr.triangularMesh == triangle.triangularMesh);
72 
73  tr.merge(rectangle);
74 
75  std::ofstream trStream;
76  trStream.open("PolyhedronTriangleRectangle.obj");
77  ObjVisualization objtrH;
78  tr.draw(objtrH);
79  objtrH.write(trStream);
80  trStream.close();
81 }
82 
84 BOOST_AUTO_TEST_CASE(PolyhedronExtent) {
85  std::vector<Vector3D> rvertices = {Vector3D(-1, -2, 0.), Vector3D(1., -2, 0.),
86  Vector3D(1., -1., 0.),
87  Vector3D(-1., -1., 0.)};
88 
89  std::vector<std::vector<size_t>> rfaces = {{0, 1, 2, 3}};
90  std::vector<std::vector<size_t>> rmesh = {{0, 1, 2}, {2, 3, 0}};
91  Polyhedron rectangle(rvertices, rfaces, rmesh);
92 
93  auto rExtent = rectangle.extent();
94  CHECK_CLOSE_ABS(rExtent.min(binX), -1., 1e-6);
95  CHECK_CLOSE_ABS(rExtent.max(binX), 1., 1e-6);
96  CHECK_CLOSE_ABS(rExtent.min(binY), -2., 1e-6);
97  CHECK_CLOSE_ABS(rExtent.max(binY), -1., 1e-6);
98  CHECK_CLOSE_ABS(rExtent.min(binZ), 0., 1e-6);
99  CHECK_CLOSE_ABS(rExtent.max(binZ), 0., 1e-6);
100  CHECK_CLOSE_ABS(rExtent.min(binR), 1., 1e-6);
101  CHECK_CLOSE_ABS(rExtent.max(binR), VectorHelpers::perp(rvertices[0]), 1e-6);
102  CHECK_CLOSE_ABS(rExtent.min(binPhi), VectorHelpers::phi(rvertices[3]), 1e-6);
103  CHECK_CLOSE_ABS(rExtent.max(binPhi), VectorHelpers::phi(rvertices[2]), 1e-6);
104 
105  // Now shift the Extent
106  Vector3D shift(-1., 0., 1.);
107  Transform3D shiftedTransform = Transform3D::Identity();
108  shiftedTransform.pretranslate(shift);
109  rExtent = rectangle.extent(shiftedTransform);
110  CHECK_CLOSE_ABS(rExtent.min(binX), -2., 1e-6);
111  CHECK_CLOSE_ABS(rExtent.max(binX), 0., 1e-6);
112  CHECK_CLOSE_ABS(rExtent.min(binY), -2., 1e-6);
113  CHECK_CLOSE_ABS(rExtent.max(binY), -1., 1e-6);
114  CHECK_CLOSE_ABS(rExtent.min(binZ), 1., 1e-6);
115  CHECK_CLOSE_ABS(rExtent.max(binZ), 1., 1e-6);
116 }
117 
118 BOOST_AUTO_TEST_SUITE_END()
119 
120 } // namespace Test
121 
122 } // namespace Acts