File indexing completed on 2025-08-06 08:11:21
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/data/test_case.hpp>
0010 #include <boost/test/tools/output_test_stream.hpp>
0011 #include <boost/test/unit_test.hpp>
0012
0013 #include <cmath>
0014 #include <cstddef>
0015 #include <vector>
0016
0017
0018 #include "Acts/Definitions/Algebra.hpp"
0019 #include "Acts/Definitions/Units.hpp"
0020 #include "Acts/Geometry/Extent.hpp"
0021 #include "Acts/Geometry/Polyhedron.hpp"
0022 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0023 #include "Acts/Utilities/BinningType.hpp"
0024 #include "Acts/Visualization/GeometryView3D.hpp"
0025 #include "Acts/Visualization/ObjVisualization3D.hpp"
0026
0027 namespace Acts {
0028
0029 using namespace UnitLiterals;
0030
0031 namespace Test {
0032
0033 BOOST_AUTO_TEST_SUITE(Geometry)
0034
0035
0036 BOOST_AUTO_TEST_CASE(PolyhedronTest) {
0037 std::vector<Vector3> tvertices = {Vector3(-1, -1, 0.), Vector3(1., -1, 0.),
0038 Vector3(0., 1., 0.)};
0039 std::vector<std::vector<std::size_t>> tfaces = {{0, 1, 2}};
0040
0041 Polyhedron triangle(tvertices, tfaces, tfaces);
0042 BOOST_CHECK(tvertices == triangle.vertices);
0043 BOOST_CHECK(tfaces == triangle.faces);
0044 BOOST_CHECK(tfaces == triangle.triangularMesh);
0045
0046 ObjVisualization3D objVis;
0047 GeometryView3D::drawPolyhedron(objVis, triangle);
0048 objVis.write("Polyhedron_Triangle");
0049 objVis.clear();
0050
0051 std::vector<Vector3> rvertices = {Vector3(-1, -2, 0.), Vector3(1., -2, 0.),
0052 Vector3(1., -1., 0.),
0053 Vector3(-1., -1., 0.)};
0054 std::vector<std::vector<std::size_t>> rfaces = {{0, 1, 2, 3}};
0055 std::vector<std::vector<std::size_t>> rmesh = {{0, 1, 2}, {2, 3, 0}};
0056 Polyhedron rectangle(rvertices, rfaces, rmesh);
0057 BOOST_CHECK(rvertices == rectangle.vertices);
0058 BOOST_CHECK(rfaces == rectangle.faces);
0059 BOOST_CHECK(rmesh == rectangle.triangularMesh);
0060
0061 GeometryView3D::drawPolyhedron(objVis, rectangle);
0062 objVis.write("Polyhedron_Rectangle");
0063 objVis.clear();
0064
0065
0066 Polyhedron tr;
0067 tr.merge(triangle);
0068 BOOST_CHECK(tr.vertices == triangle.vertices);
0069 BOOST_CHECK(tr.faces == triangle.faces);
0070 BOOST_CHECK(tr.triangularMesh == triangle.triangularMesh);
0071 tr.merge(rectangle);
0072
0073 GeometryView3D::drawPolyhedron(objVis, tr);
0074 objVis.write("Polyhedron_TriangleRectangle");
0075 objVis.clear();
0076 }
0077
0078
0079 BOOST_AUTO_TEST_CASE(PolyhedronExtent) {
0080
0081 std::vector<Vector3> rvertices = {Vector3(-1, -2, 0.), Vector3(1., -2, 0.),
0082 Vector3(1., -1., 0.),
0083 Vector3(-1., -1., 0.)};
0084
0085 std::vector<std::vector<std::size_t>> rfaces = {{0, 1, 2, 3}};
0086 std::vector<std::vector<std::size_t>> rmesh = {{0, 1, 2}, {2, 3, 0}};
0087 Polyhedron rectangle(rvertices, rfaces, rmesh);
0088
0089 auto rExtent = rectangle.extent();
0090 CHECK_CLOSE_ABS(rExtent.min(binX), -1., 1e-6);
0091 CHECK_CLOSE_ABS(rExtent.max(binX), 1., 1e-6);
0092 CHECK_CLOSE_ABS(rExtent.min(binY), -2., 1e-6);
0093 CHECK_CLOSE_ABS(rExtent.max(binY), -1., 1e-6);
0094 CHECK_CLOSE_ABS(rExtent.min(binZ), 0., 1e-6);
0095 CHECK_CLOSE_ABS(rExtent.max(binZ), 0., 1e-6);
0096 CHECK_CLOSE_ABS(rExtent.min(binR), 1., 1e-6);
0097 CHECK_CLOSE_ABS(rExtent.max(binR), VectorHelpers::perp(rvertices[0]), 1e-6);
0098 CHECK_CLOSE_ABS(rExtent.min(binPhi), VectorHelpers::phi(rvertices[3]), 1e-6);
0099 CHECK_CLOSE_ABS(rExtent.max(binPhi), VectorHelpers::phi(rvertices[2]), 1e-6);
0100
0101
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(binX), -2., 1e-6);
0107 CHECK_CLOSE_ABS(rExtent.max(binX), 0., 1e-6);
0108 CHECK_CLOSE_ABS(rExtent.min(binY), -2., 1e-6);
0109 CHECK_CLOSE_ABS(rExtent.max(binY), -1., 1e-6);
0110 CHECK_CLOSE_ABS(rExtent.min(binZ), 1., 1e-6);
0111 CHECK_CLOSE_ABS(rExtent.max(binZ), 1., 1e-6);
0112
0113
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(binX), 3., 1e-6);
0120 CHECK_CLOSE_ABS(rExtent.max(binX), 3., 1e-6);
0121 CHECK_CLOSE_ABS(rExtent.min(binY), -5., 1e-6);
0122 CHECK_CLOSE_ABS(rExtent.max(binY), 5., 1e-6);
0123 CHECK_CLOSE_ABS(rExtent.min(binZ), -10., 1e-6);
0124 CHECK_CLOSE_ABS(rExtent.max(binZ), 10., 1e-6);
0125 CHECK_CLOSE_ABS(rExtent.min(binR), 3., 1e-6);
0126 CHECK_CLOSE_ABS(rExtent.max(binR), std::sqrt(9. + 25.), 1e-6);
0127 }
0128
0129 BOOST_AUTO_TEST_SUITE_END()
0130
0131 }
0132
0133 }