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