File indexing completed on 2025-10-13 08:18:27
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Geometry/GeometryHierarchyMap.hpp"
0010 #include "Acts/Material/ISurfaceMaterial.hpp"
0011 #include "Acts/Surfaces/AnnulusBounds.hpp"
0012 #include "Acts/Surfaces/CylinderBounds.hpp"
0013 #include "Acts/Surfaces/CylinderSurface.hpp"
0014 #include "Acts/Surfaces/DiscSurface.hpp"
0015 #include "Acts/Surfaces/LineBounds.hpp"
0016 #include "Acts/Surfaces/PerigeeSurface.hpp"
0017 #include "Acts/Surfaces/PlanarBounds.hpp"
0018 #include "Acts/Surfaces/PlaneSurface.hpp"
0019 #include "Acts/Surfaces/RadialBounds.hpp"
0020 #include "Acts/Surfaces/RectangleBounds.hpp"
0021 #include "Acts/Surfaces/StrawSurface.hpp"
0022 #include "Acts/Surfaces/Surface.hpp"
0023 #include "Acts/Surfaces/SurfaceBounds.hpp"
0024 #include "Acts/Surfaces/TrapezoidBounds.hpp"
0025 #include "Acts/Visualization/IVisualization3D.hpp"
0026
0027 #include <pybind11/eval.h>
0028 #include <pybind11/pybind11.h>
0029 #include <pybind11/pytypes.h>
0030 #include <pybind11/stl.h>
0031
0032 namespace py = pybind11;
0033 using namespace pybind11::literals;
0034 using namespace Acts;
0035
0036 namespace ActsPython {
0037
0038
0039 void addSurfaces(py::module_& m) {
0040 {
0041 py::class_<SurfaceBounds, std::shared_ptr<SurfaceBounds>>(m,
0042 "SurfaceBounds");
0043 }
0044
0045 {
0046 py::class_<CylinderBounds, SurfaceBounds, std::shared_ptr<CylinderBounds>>(
0047 m, "CylinderBounds")
0048 .def(py::init<double, double>())
0049 .def(py::init(
0050 [](const std::array<double, CylinderBounds::eSize>& values) {
0051 return CylinderBounds(values);
0052 }))
0053 .def("__getitem__",
0054 [](const CylinderBounds& self, int index) {
0055 return self.get(CylinderBounds::BoundValues(index));
0056 })
0057 .def("__str__", [](const CylinderBounds& self) {
0058 std::ostringstream oss;
0059 oss << self;
0060 return oss.str();
0061 });
0062 }
0063
0064 {
0065 py::class_<DiscBounds, SurfaceBounds, std::shared_ptr<DiscBounds>>(
0066 m, "DiscBounds");
0067
0068 py::class_<AnnulusBounds, DiscBounds, std::shared_ptr<AnnulusBounds>>(
0069 m, "AnnulusBounds")
0070 .def(py::init<double, double, double, double>())
0071 .def(py::init(
0072 [](const std::array<double, AnnulusBounds::eSize>& values) {
0073 return AnnulusBounds(values);
0074 }))
0075 .def("__getitem__",
0076 [](const AnnulusBounds& self, int index) {
0077 return self.get(AnnulusBounds::BoundValues(index));
0078 })
0079 .def("__str__", [](const AnnulusBounds& self) {
0080 std::ostringstream oss;
0081 oss << self;
0082 return oss.str();
0083 });
0084
0085 py::class_<RadialBounds, DiscBounds, std::shared_ptr<RadialBounds>>(
0086 m, "RadialBounds")
0087 .def(py::init<double, double>())
0088 .def(
0089 py::init([](const std::array<double, RadialBounds::eSize>& values) {
0090 return RadialBounds(values);
0091 }))
0092 .def("__getitem__",
0093 [](const RadialBounds& self, int index) {
0094 return self.get(RadialBounds::BoundValues(index));
0095 })
0096 .def("__str__", [](const RadialBounds& self) {
0097 std::ostringstream oss;
0098 oss << self;
0099 return oss.str();
0100 });
0101 }
0102
0103 {
0104 py::class_<LineBounds, SurfaceBounds, std::shared_ptr<LineBounds>>(
0105 m, "LineBounds")
0106 .def(py::init<double, double>())
0107 .def(py::init([](const std::array<double, LineBounds::eSize>& values) {
0108 return LineBounds(values);
0109 }))
0110 .def("__getitem__",
0111 [](const LineBounds& self, int index) {
0112 return self.get(LineBounds::BoundValues(index));
0113 })
0114 .def("__str__", [](const LineBounds& self) {
0115 std::ostringstream oss;
0116 oss << self;
0117 return oss.str();
0118 });
0119 }
0120
0121 {
0122 py::class_<PlanarBounds, SurfaceBounds, std::shared_ptr<PlanarBounds>>(
0123 m, "PlanarBounds");
0124
0125 py::class_<RectangleBounds, PlanarBounds, std::shared_ptr<RectangleBounds>>(
0126 m, "RectangleBounds")
0127 .def(py::init<double, double>())
0128 .def(py::init(
0129 [](const std::array<double, RectangleBounds::eSize>& values) {
0130 return RectangleBounds(values);
0131 }))
0132 .def("__getitem__",
0133 [](const RectangleBounds& self, int index) {
0134 return self.get(RectangleBounds::BoundValues(index));
0135 })
0136 .def("__str__", [](const RectangleBounds& self) {
0137 std::ostringstream oss;
0138 oss << self;
0139 return oss.str();
0140 });
0141
0142 py::class_<TrapezoidBounds, PlanarBounds, std::shared_ptr<TrapezoidBounds>>(
0143 m, "TrapezoidBounds")
0144 .def(py::init<double, double, double, double>())
0145 .def(py::init(
0146 [](const std::array<double, TrapezoidBounds::eSize>& values) {
0147 return TrapezoidBounds(values);
0148 }))
0149 .def("__getitem__",
0150 [](const TrapezoidBounds& self, int index) {
0151 return self.get(TrapezoidBounds::BoundValues(index));
0152 })
0153 .def("__str__", [](const TrapezoidBounds& self) {
0154 std::ostringstream oss;
0155 oss << self;
0156 return oss.str();
0157 });
0158 }
0159
0160 {
0161 py::class_<Surface, std::shared_ptr<Surface>>(m, "Surface")
0162
0163 .def_property_readonly(
0164 "geometryId", [](const Surface& self) { return self.geometryId(); })
0165 .def("assignGeometryId",
0166 [](Surface& self, const GeometryIdentifier& id) {
0167 self.assignGeometryId(id);
0168 })
0169 .def("center", &Surface::center)
0170 .def_property_readonly("type", &Surface::type)
0171 .def("visualize", &Surface::visualize)
0172 .def_property_readonly("surfaceMaterial",
0173 &Surface::surfaceMaterialSharedPtr)
0174 .def("createCylinder",
0175 [](const Transform3& transform,
0176 std::shared_ptr<const CylinderBounds> bounds) {
0177 return Surface::makeShared<CylinderSurface>(transform, bounds);
0178 })
0179 .def("createDisc",
0180 [](const Transform3& transform,
0181 std::shared_ptr<const DiscBounds> bounds) {
0182 return Surface::makeShared<DiscSurface>(transform, bounds);
0183 })
0184 .def("createDisc",
0185 [](std::shared_ptr<const DiscBounds> bounds,
0186 const DetectorElementBase& detelement) {
0187 return Surface::makeShared<DiscSurface>(bounds, detelement);
0188 })
0189 .def("createStraw",
0190 [](const Transform3& transform,
0191 std::shared_ptr<const LineBounds> bounds) {
0192 return Surface::makeShared<StrawSurface>(transform, bounds);
0193 })
0194 .def("createStraw",
0195 [](std::shared_ptr<const LineBounds> bounds,
0196 const DetectorElementBase& detelement) {
0197 return Surface::makeShared<StrawSurface>(bounds, detelement);
0198 })
0199 .def("createPerigee",
0200 [](const Vector3& vertex) {
0201 return Surface::makeShared<PerigeeSurface>(vertex);
0202 })
0203 .def("createPlane",
0204 [](const Transform3& transform,
0205 std::shared_ptr<const PlanarBounds> bounds) {
0206 return Surface::makeShared<PlaneSurface>(transform, bounds);
0207 })
0208 .def("createPlane", [](std::shared_ptr<const PlanarBounds> pbounds,
0209 const DetectorElementBase& detelement) {
0210 return Surface::makeShared<PlaneSurface>(pbounds, detelement);
0211 });
0212
0213 py::class_<CylinderSurface, Surface, std::shared_ptr<CylinderSurface>>(
0214 m, "CylinderSurface");
0215
0216 py::class_<DiscSurface, Surface, std::shared_ptr<DiscSurface>>(
0217 m, "DiscSurface");
0218
0219 py::class_<PlaneSurface, Surface, std::shared_ptr<PlaneSurface>>(
0220 m, "PlaneSurface");
0221
0222 py::class_<PerigeeSurface, Surface, std::shared_ptr<PerigeeSurface>>(
0223 m, "PerigeeSurface");
0224
0225 py::class_<StrawSurface, Surface, std::shared_ptr<StrawSurface>>(
0226 m, "StrawSurface");
0227 }
0228
0229 {
0230 py::enum_<Surface::SurfaceType>(m, "SurfaceType")
0231 .value("Cone", Surface::SurfaceType::Cone)
0232 .value("Cylinder", Surface::SurfaceType::Cylinder)
0233 .value("Disc", Surface::SurfaceType::Disc)
0234 .value("Perigee", Surface::SurfaceType::Perigee)
0235 .value("Plane", Surface::SurfaceType::Plane)
0236 .value("Straw", Surface::SurfaceType::Straw)
0237 .value("Curvilinear", Surface::SurfaceType::Curvilinear)
0238 .value("Other", Surface::SurfaceType::Other);
0239 }
0240
0241
0242 using SurfaceHierarchyMap =
0243 Acts::GeometryHierarchyMap<std::shared_ptr<Acts::Surface>>;
0244
0245 py::class_<SurfaceHierarchyMap, std::shared_ptr<SurfaceHierarchyMap>>(
0246 m, "SurfaceHierarchyMap")
0247 .def(py::init<>())
0248 .def(py::init<std::vector<SurfaceHierarchyMap::InputElement>>())
0249 .def("__len__",
0250 [](const SurfaceHierarchyMap& self) { return self.size(); })
0251 .def("__getitem__",
0252 [](const SurfaceHierarchyMap& self, std::size_t index) {
0253 return self.valueAt(index);
0254 });
0255 }
0256
0257 }