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
17 #include "Acts/Utilities/Units.hpp"
20 
21 #include <fstream>
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  ObjVisualization3D objVis;
43  GeometryView3D::drawPolyhedron(objVis, triangle);
44  objVis.write("Polyhedron_Triangle");
45  objVis.clear();
46 
47  std::vector<Vector3D> rvertices = {Vector3D(-1, -2, 0.), Vector3D(1., -2, 0.),
48  Vector3D(1., -1., 0.),
49  Vector3D(-1., -1., 0.)};
50  std::vector<std::vector<size_t>> rfaces = {{0, 1, 2, 3}};
51  std::vector<std::vector<size_t>> rmesh = {{0, 1, 2}, {2, 3, 0}};
52  Polyhedron rectangle(rvertices, rfaces, rmesh);
53  BOOST_CHECK(rvertices == rectangle.vertices);
54  BOOST_CHECK(rfaces == rectangle.faces);
55  BOOST_CHECK(rmesh == rectangle.triangularMesh);
56 
57  GeometryView3D::drawPolyhedron(objVis, rectangle);
58  objVis.write("Polyhedron_Rectangle");
59  objVis.clear();
60 
61  // Now add them
62  Polyhedron tr;
63  tr.merge(triangle);
64  BOOST_CHECK(tr.vertices == triangle.vertices);
65  BOOST_CHECK(tr.faces == triangle.faces);
66  BOOST_CHECK(tr.triangularMesh == triangle.triangularMesh);
67  tr.merge(rectangle);
68 
70  objVis.write("Polyhedron_TriangleRectangle");
71  objVis.clear();
72 }
73 
75 BOOST_AUTO_TEST_CASE(PolyhedronExtent) {
76  // Test a rectangle in x-y plane (at z == 0)
77  std::vector<Vector3D> rvertices = {Vector3D(-1, -2, 0.), Vector3D(1., -2, 0.),
78  Vector3D(1., -1., 0.),
79  Vector3D(-1., -1., 0.)};
80 
81  std::vector<std::vector<size_t>> rfaces = {{0, 1, 2, 3}};
82  std::vector<std::vector<size_t>> rmesh = {{0, 1, 2}, {2, 3, 0}};
83  Polyhedron rectangle(rvertices, rfaces, rmesh);
84 
85  auto rExtent = rectangle.extent();
86  CHECK_CLOSE_ABS(rExtent.min(binX), -1., 1e-6);
87  CHECK_CLOSE_ABS(rExtent.max(binX), 1., 1e-6);
88  CHECK_CLOSE_ABS(rExtent.min(binY), -2., 1e-6);
89  CHECK_CLOSE_ABS(rExtent.max(binY), -1., 1e-6);
90  CHECK_CLOSE_ABS(rExtent.min(binZ), 0., 1e-6);
91  CHECK_CLOSE_ABS(rExtent.max(binZ), 0., 1e-6);
92  CHECK_CLOSE_ABS(rExtent.min(binR), 1., 1e-6);
93  CHECK_CLOSE_ABS(rExtent.max(binR), VectorHelpers::perp(rvertices[0]), 1e-6);
94  CHECK_CLOSE_ABS(rExtent.min(binPhi), VectorHelpers::phi(rvertices[3]), 1e-6);
95  CHECK_CLOSE_ABS(rExtent.max(binPhi), VectorHelpers::phi(rvertices[2]), 1e-6);
96 
97  // Now shift the Extent
98  Vector3D shift(-1., 0., 1.);
99  Transform3D shiftedTransform = Transform3D::Identity();
100  shiftedTransform.pretranslate(shift);
101  rExtent = rectangle.extent(shiftedTransform);
102  CHECK_CLOSE_ABS(rExtent.min(binX), -2., 1e-6);
103  CHECK_CLOSE_ABS(rExtent.max(binX), 0., 1e-6);
104  CHECK_CLOSE_ABS(rExtent.min(binY), -2., 1e-6);
105  CHECK_CLOSE_ABS(rExtent.max(binY), -1., 1e-6);
106  CHECK_CLOSE_ABS(rExtent.min(binZ), 1., 1e-6);
107  CHECK_CLOSE_ABS(rExtent.max(binZ), 1., 1e-6);
108 
109  // Test a rectangle in yz - pane (at x == 3)
110  rvertices = {Vector3D(3_mm, -5_mm, -10_mm), Vector3D(3_mm, 5_mm, -10_mm),
111  Vector3D(3_mm, 5_mm, 10_mm), Vector3D(3_mm, -5_mm, 10_mm)};
112 
113  rectangle = Polyhedron(rvertices, rfaces, rmesh);
114  rExtent = rectangle.extent();
115  CHECK_CLOSE_ABS(rExtent.min(binX), 3., 1e-6);
116  CHECK_CLOSE_ABS(rExtent.max(binX), 3., 1e-6);
117  CHECK_CLOSE_ABS(rExtent.min(binY), -5., 1e-6);
118  CHECK_CLOSE_ABS(rExtent.max(binY), 5., 1e-6);
119  CHECK_CLOSE_ABS(rExtent.min(binZ), -10., 1e-6);
120  CHECK_CLOSE_ABS(rExtent.max(binZ), 10., 1e-6);
121  CHECK_CLOSE_ABS(rExtent.min(binR), 3., 1e-6);
122  CHECK_CLOSE_ABS(rExtent.max(binR), std::sqrt(9. + 25.), 1e-6);
123 }
124 
125 BOOST_AUTO_TEST_SUITE_END()
126 
127 } // namespace Test
128 
129 } // namespace Acts