Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-05 08:55:22

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include <cmath>
0012 #include <cstddef>
0013 #include <vector>
0014 
0015 // Helper
0016 #include "Acts/Definitions/Algebra.hpp"
0017 #include "Acts/Definitions/Units.hpp"
0018 #include "Acts/Geometry/Extent.hpp"
0019 #include "Acts/Geometry/Polyhedron.hpp"
0020 #include "Acts/Utilities/BinningType.hpp"
0021 #include "Acts/Visualization/GeometryView3D.hpp"
0022 #include "Acts/Visualization/ObjVisualization3D.hpp"
0023 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0024 
0025 using namespace Acts;
0026 using namespace Acts::UnitLiterals;
0027 
0028 namespace ActsTests {
0029 
0030 BOOST_AUTO_TEST_SUITE(GeometrySuite)
0031 
0032 /// Unit tests for Polyderon construction & operator +=
0033 BOOST_AUTO_TEST_CASE(PolyhedronTest) {
0034   std::vector<Vector3> tvertices = {Vector3(-1, -1, 0.), Vector3(1., -1, 0.),
0035                                     Vector3(0., 1., 0.)};
0036   std::vector<std::vector<std::size_t>> tfaces = {{0, 1, 2}};
0037 
0038   Polyhedron triangle(tvertices, tfaces, tfaces);
0039   BOOST_CHECK(tvertices == triangle.vertices);
0040   BOOST_CHECK(tfaces == triangle.faces);
0041   BOOST_CHECK(tfaces == triangle.triangularMesh);
0042 
0043   ObjVisualization3D objVis;
0044   GeometryView3D::drawPolyhedron(objVis, triangle);
0045   objVis.write("Polyhedron_Triangle");
0046   objVis.clear();
0047 
0048   std::vector<Vector3> rvertices = {Vector3(-1, -2, 0.), Vector3(1., -2, 0.),
0049                                     Vector3(1., -1., 0.),
0050                                     Vector3(-1., -1., 0.)};
0051   std::vector<std::vector<std::size_t>> rfaces = {{0, 1, 2, 3}};
0052   std::vector<std::vector<std::size_t>> rmesh = {{0, 1, 2}, {2, 3, 0}};
0053   Polyhedron rectangle(rvertices, rfaces, rmesh);
0054   BOOST_CHECK(rvertices == rectangle.vertices);
0055   BOOST_CHECK(rfaces == rectangle.faces);
0056   BOOST_CHECK(rmesh == rectangle.triangularMesh);
0057 
0058   GeometryView3D::drawPolyhedron(objVis, rectangle);
0059   objVis.write("Polyhedron_Rectangle");
0060   objVis.clear();
0061 
0062   // Now add them
0063   Polyhedron tr;
0064   tr.merge(triangle);
0065   BOOST_CHECK(tr.vertices == triangle.vertices);
0066   BOOST_CHECK(tr.faces == triangle.faces);
0067   BOOST_CHECK(tr.triangularMesh == triangle.triangularMesh);
0068   tr.merge(rectangle);
0069 
0070   GeometryView3D::drawPolyhedron(objVis, tr);
0071   objVis.write("Polyhedron_TriangleRectangle");
0072   objVis.clear();
0073 }
0074 
0075 /// Unit tests for Polyderon construction & operator +=
0076 BOOST_AUTO_TEST_CASE(PolyhedronExtent) {
0077   // Test a rectangle in x-y plane (at z == 0)
0078   std::vector<Vector3> rvertices = {Vector3(-1, -2, 0.), Vector3(1., -2, 0.),
0079                                     Vector3(1., -1., 0.),
0080                                     Vector3(-1., -1., 0.)};
0081 
0082   std::vector<std::vector<std::size_t>> rfaces = {{0, 1, 2, 3}};
0083   std::vector<std::vector<std::size_t>> rmesh = {{0, 1, 2}, {2, 3, 0}};
0084   Polyhedron rectangle(rvertices, rfaces, rmesh);
0085 
0086   auto rExtent = rectangle.extent();
0087   CHECK_CLOSE_ABS(rExtent.min(AxisDirection::AxisX), -1., 1e-6);
0088   CHECK_CLOSE_ABS(rExtent.max(AxisDirection::AxisX), 1., 1e-6);
0089   CHECK_CLOSE_ABS(rExtent.min(AxisDirection::AxisY), -2., 1e-6);
0090   CHECK_CLOSE_ABS(rExtent.max(AxisDirection::AxisY), -1., 1e-6);
0091   CHECK_CLOSE_ABS(rExtent.min(AxisDirection::AxisZ), 0., 1e-6);
0092   CHECK_CLOSE_ABS(rExtent.max(AxisDirection::AxisZ), 0., 1e-6);
0093   CHECK_CLOSE_ABS(rExtent.min(AxisDirection::AxisR), 1., 1e-6);
0094   CHECK_CLOSE_ABS(rExtent.max(AxisDirection::AxisR),
0095                   VectorHelpers::perp(rvertices[0]), 1e-6);
0096   CHECK_CLOSE_ABS(rExtent.min(AxisDirection::AxisPhi),
0097                   VectorHelpers::phi(rvertices[3]), 1e-6);
0098   CHECK_CLOSE_ABS(rExtent.max(AxisDirection::AxisPhi),
0099                   VectorHelpers::phi(rvertices[2]), 1e-6);
0100 
0101   // Now shift the Extent
0102   Vector3 shift(-1., 0., 1.);
0103   Transform3 shiftedTransform = Transform3::Identity();
0104   shiftedTransform.pretranslate(shift);
0105   rExtent = rectangle.extent(shiftedTransform);
0106   CHECK_CLOSE_ABS(rExtent.min(AxisDirection::AxisX), -2., 1e-6);
0107   CHECK_CLOSE_ABS(rExtent.max(AxisDirection::AxisX), 0., 1e-6);
0108   CHECK_CLOSE_ABS(rExtent.min(AxisDirection::AxisY), -2., 1e-6);
0109   CHECK_CLOSE_ABS(rExtent.max(AxisDirection::AxisY), -1., 1e-6);
0110   CHECK_CLOSE_ABS(rExtent.min(AxisDirection::AxisZ), 1., 1e-6);
0111   CHECK_CLOSE_ABS(rExtent.max(AxisDirection::AxisZ), 1., 1e-6);
0112 
0113   // Test a rectangle in yz - pane (at x == 3)
0114   rvertices = {Vector3(3_mm, -5_mm, -10_mm), Vector3(3_mm, 5_mm, -10_mm),
0115                Vector3(3_mm, 5_mm, 10_mm), Vector3(3_mm, -5_mm, 10_mm)};
0116 
0117   rectangle = Polyhedron(rvertices, rfaces, rmesh);
0118   rExtent = rectangle.extent();
0119   CHECK_CLOSE_ABS(rExtent.min(AxisDirection::AxisX), 3., 1e-6);
0120   CHECK_CLOSE_ABS(rExtent.max(AxisDirection::AxisX), 3., 1e-6);
0121   CHECK_CLOSE_ABS(rExtent.min(AxisDirection::AxisY), -5., 1e-6);
0122   CHECK_CLOSE_ABS(rExtent.max(AxisDirection::AxisY), 5., 1e-6);
0123   CHECK_CLOSE_ABS(rExtent.min(AxisDirection::AxisZ), -10., 1e-6);
0124   CHECK_CLOSE_ABS(rExtent.max(AxisDirection::AxisZ), 10., 1e-6);
0125   CHECK_CLOSE_ABS(rExtent.min(AxisDirection::AxisR), 3., 1e-6);
0126   CHECK_CLOSE_ABS(rExtent.max(AxisDirection::AxisR), std::sqrt(9. + 25.), 1e-6);
0127 }
0128 
0129 BOOST_AUTO_TEST_SUITE_END()
0130 
0131 }  // namespace ActsTests