File indexing completed on 2025-01-18 09:13:03
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Geometry/GeometryContext.hpp"
0012 #include "Acts/Surfaces/AnnulusBounds.hpp"
0013 #include "Acts/Surfaces/ConeBounds.hpp"
0014 #include "Acts/Surfaces/ConeSurface.hpp"
0015 #include "Acts/Surfaces/ConvexPolygonBounds.hpp"
0016 #include "Acts/Surfaces/CylinderBounds.hpp"
0017 #include "Acts/Surfaces/CylinderSurface.hpp"
0018 #include "Acts/Surfaces/DiamondBounds.hpp"
0019 #include "Acts/Surfaces/DiscSurface.hpp"
0020 #include "Acts/Surfaces/DiscTrapezoidBounds.hpp"
0021 #include "Acts/Surfaces/EllipseBounds.hpp"
0022 #include "Acts/Surfaces/LineBounds.hpp"
0023 #include "Acts/Surfaces/PlaneSurface.hpp"
0024 #include "Acts/Surfaces/RadialBounds.hpp"
0025 #include "Acts/Surfaces/RectangleBounds.hpp"
0026 #include "Acts/Surfaces/StrawSurface.hpp"
0027 #include "Acts/Surfaces/TrapezoidBounds.hpp"
0028 #include "Acts/Visualization/GeometryView3D.hpp"
0029 #include "Acts/Visualization/IVisualization3D.hpp"
0030
0031 #include <fstream>
0032 #include <numbers>
0033 #include <sstream>
0034 #include <string>
0035
0036 namespace Acts::SurfaceView3DTest {
0037
0038
0039
0040
0041
0042
0043
0044
0045 static inline std::string run(IVisualization3D& helper, bool triangulate,
0046 const std::string& tag) {
0047 auto gctx = GeometryContext();
0048 auto identity = Transform3::Identity();
0049 std::stringstream cStream;
0050
0051 const double halfPhiSector = std::numbers::pi / 4.;
0052 const double centralPhi = std::numbers::pi / 2.;
0053
0054 ViewConfig sConfig = s_viewSensitive;
0055 sConfig.triangulate = triangulate;
0056
0057
0058
0059 std::vector<std::shared_ptr<ConeSurface>> coneSurfaces;
0060
0061 double coneAlpha = 0.245;
0062 double coneMinZ = 0.;
0063 double coneCutZ = 2.;
0064 double coneMaxZ = 10.;
0065
0066 auto coneBounds =
0067 std::make_shared<ConeBounds>(coneAlpha, -coneCutZ, coneMaxZ);
0068 auto cone = Surface::makeShared<ConeSurface>(identity, coneBounds);
0069 coneSurfaces.push_back(cone);
0070 GeometryView3D::drawSurface(helper, *cone, gctx, Transform3::Identity(),
0071 sConfig);
0072
0073 helper.write(std::string("Surfaces_ConeSurface") + tag);
0074 helper.write(cStream);
0075 helper.clear();
0076
0077
0078 coneBounds = std::make_shared<ConeBounds>(coneAlpha, coneMinZ, coneMaxZ,
0079 halfPhiSector);
0080 cone = Surface::makeShared<ConeSurface>(identity, coneBounds);
0081 coneSurfaces.push_back(cone);
0082 GeometryView3D::drawSurface(helper, *cone, gctx, Transform3::Identity(),
0083 sConfig);
0084
0085 helper.write(std::string("Surfaces_ConeSurfaceSector") + tag);
0086 helper.write(cStream);
0087 helper.clear();
0088
0089
0090 coneBounds = std::make_shared<ConeBounds>(coneAlpha, coneCutZ, coneMaxZ,
0091 halfPhiSector, centralPhi);
0092 cone = Surface::makeShared<ConeSurface>(identity, coneBounds);
0093 coneSurfaces.push_back(cone);
0094 GeometryView3D::drawSurface(helper, *cone, gctx, Transform3::Identity(),
0095 sConfig);
0096
0097 helper.write(std::string("Surfaces_ConeSurfaceSectorShifted") + tag);
0098 helper.write(cStream);
0099 helper.clear();
0100
0101
0102 std::vector<Transform3> threeCones = {
0103 Transform3(Translation3{-0.5 * coneMaxZ, 0., 0.}),
0104 Transform3(Translation3{0., 0., 0.}),
0105 Transform3(Translation3{0.75 * coneMaxZ, 0., 0.})};
0106
0107 for (std::size_t ic = 0; ic < coneSurfaces.size(); ++ic) {
0108 GeometryView3D::drawSurface(helper, *coneSurfaces[ic], gctx, threeCones[ic],
0109 sConfig);
0110 }
0111 helper.write(std::string("Surfaces_All_ConeSurfaces") + tag);
0112 helper.write(cStream);
0113 helper.clear();
0114
0115
0116
0117 std::vector<std::shared_ptr<CylinderSurface>> cylinderSurfaces;
0118
0119 double cylinderRadius = 5.;
0120 double cylinderHalfZ = 10.;
0121
0122
0123 auto cylinderBounds =
0124 std::make_shared<CylinderBounds>(cylinderRadius, cylinderHalfZ);
0125 auto cylinder =
0126 Surface::makeShared<CylinderSurface>(identity, cylinderBounds);
0127 cylinderSurfaces.push_back(cylinder);
0128 GeometryView3D::drawSurface(helper, *cylinder, gctx, Transform3::Identity(),
0129 sConfig);
0130
0131 helper.write(std::string("Surfaces_CylinderSurface") + tag);
0132 helper.write(cStream);
0133 helper.clear();
0134
0135
0136 cylinderBounds = std::make_shared<CylinderBounds>(
0137 cylinderRadius, cylinderHalfZ, halfPhiSector);
0138 cylinder = Surface::makeShared<CylinderSurface>(identity, cylinderBounds);
0139 cylinderSurfaces.push_back(cylinder);
0140 GeometryView3D::drawSurface(helper, *cylinder, gctx, Transform3::Identity(),
0141 sConfig);
0142
0143 helper.write(std::string("Surfaces_CylinderSurfaceSector") + tag);
0144 helper.write(cStream);
0145 helper.clear();
0146
0147
0148 cylinderBounds = std::make_shared<CylinderBounds>(
0149 cylinderRadius, cylinderHalfZ, halfPhiSector, centralPhi);
0150 cylinder = Surface::makeShared<CylinderSurface>(identity, cylinderBounds);
0151 cylinderSurfaces.push_back(cylinder);
0152 GeometryView3D::drawSurface(helper, *cylinder, gctx, Transform3::Identity(),
0153 sConfig);
0154
0155 helper.write(std::string("Surfaces_CylinderSurfaceSectorShifted") + tag);
0156 helper.write(cStream);
0157 helper.clear();
0158
0159
0160 std::vector<Transform3> threeCylinders = {
0161 Transform3(Translation3{-2 * cylinderRadius, 0., 0.}),
0162 Transform3(Translation3{0., 0., 0.}),
0163 Transform3(Translation3{2.5 * cylinderRadius, 0., 0.})};
0164
0165 for (std::size_t ic = 0; ic < cylinderSurfaces.size(); ++ic) {
0166 GeometryView3D::drawSurface(helper, *cylinderSurfaces[ic], gctx,
0167 threeCylinders[ic], sConfig);
0168 }
0169 helper.write(std::string("Surfaces_All_CylinderSurfaces") + tag);
0170 helper.write(cStream);
0171 helper.clear();
0172
0173
0174
0175 auto writeBoundingBox2D = [&](const RectangleBounds& rBounds,
0176 const std::string& path) -> void {
0177 std::string bbPath = path + tag + "_bbox";
0178
0179 auto bbBounds = std::make_shared<RectangleBounds>(rBounds);
0180 auto bbSurface = Surface::makeShared<PlaneSurface>(identity, bbBounds);
0181 GeometryView3D::drawSurface(helper, *bbSurface, gctx,
0182 Transform3::Identity(), sConfig);
0183
0184 helper.write(bbPath);
0185 helper.write(cStream);
0186 helper.clear();
0187 };
0188
0189
0190
0191
0192 double discRmin = 5.;
0193 double discRmax = 10.;
0194
0195 std::vector<std::shared_ptr<DiscSurface>> radialSurfaces;
0196
0197
0198 auto radialBounds = std::make_shared<RadialBounds>(0., discRmax);
0199 auto disc = Surface::makeShared<DiscSurface>(identity, radialBounds);
0200 radialSurfaces.push_back(disc);
0201 GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
0202 sConfig);
0203
0204 helper.write(std::string("Surfaces_DiscSurfaceFull") + tag);
0205 helper.write(cStream);
0206 helper.clear();
0207
0208
0209 radialBounds = std::make_shared<RadialBounds>(0., discRmax, halfPhiSector);
0210 disc = Surface::makeShared<DiscSurface>(identity, radialBounds);
0211 radialSurfaces.push_back(disc);
0212 GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
0213 sConfig);
0214
0215 helper.write(std::string("Surfaces_DiscSurfaceFullSector") + tag);
0216 helper.write(cStream);
0217 helper.clear();
0218
0219
0220 radialBounds =
0221 std::make_shared<RadialBounds>(0., discRmax, halfPhiSector, centralPhi);
0222 disc = Surface::makeShared<DiscSurface>(identity, radialBounds);
0223 radialSurfaces.push_back(disc);
0224 GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
0225 sConfig);
0226
0227 helper.write(std::string("Surfaces_DiscSurfaceFullSectorShifted") + tag);
0228 helper.write(cStream);
0229 helper.clear();
0230
0231
0232 radialBounds = std::make_shared<RadialBounds>(discRmin, discRmax);
0233 disc = Surface::makeShared<DiscSurface>(identity, radialBounds);
0234 radialSurfaces.push_back(disc);
0235 GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
0236 sConfig);
0237
0238 helper.write(std::string("Surfaces_DiscSurfaceRing") + tag);
0239 helper.write(cStream);
0240 helper.clear();
0241
0242
0243 radialBounds =
0244 std::make_shared<RadialBounds>(discRmin, discRmax, halfPhiSector);
0245 disc = Surface::makeShared<DiscSurface>(identity, radialBounds);
0246 radialSurfaces.push_back(disc);
0247 GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
0248 sConfig);
0249
0250 helper.write(std::string("Surfaces_DiscSurfaceRingSector") + tag);
0251 helper.write(cStream);
0252 helper.clear();
0253
0254
0255 radialBounds = std::make_shared<RadialBounds>(discRmin, discRmax,
0256 halfPhiSector, centralPhi);
0257 disc = Surface::makeShared<DiscSurface>(identity, radialBounds);
0258 radialSurfaces.push_back(disc);
0259 GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
0260 sConfig);
0261
0262 helper.write(std::string("Surfaces_DiscSurfaceRingSectorShifted") + tag);
0263 helper.write(cStream);
0264 helper.clear();
0265
0266
0267 std::vector<Transform3> sixDiscs = {
0268 Transform3(Translation3{-2.0 * discRmax, 1.5 * discRmax, 0.}),
0269 Transform3(Translation3{0., 1.5 * discRmax, 0.}),
0270 Transform3(Translation3{2.5 * discRmax, 1.5 * discRmax, 0.}),
0271 Transform3(Translation3{-2.0 * discRmax, -1.5 * discRmax, 0.}),
0272 Transform3(Translation3{0., -1.5 * discRmax, 0.}),
0273 Transform3(Translation3{2.5 * discRmax, -1.5 * discRmax, 0.})};
0274 for (std::size_t ir = 0; ir < radialSurfaces.size(); ++ir) {
0275 GeometryView3D::drawSurface(helper, *radialSurfaces[ir], gctx, sixDiscs[ir],
0276 sConfig);
0277 }
0278 helper.write(std::string("Surfaces_All_DiscSurfaces_RadialBounds") + tag);
0279 helper.write(cStream);
0280 helper.clear();
0281
0282 std::vector<std::shared_ptr<DiscSurface>> anomalDiscSurfaces;
0283
0284 double annulusMinPhi = 0.75;
0285 double annulusMaxPhi = 1.35;
0286 Vector2 offset(-4., 2.);
0287 auto annulus = std::make_shared<AnnulusBounds>(
0288 discRmin, discRmax, annulusMinPhi, annulusMaxPhi, offset);
0289 disc = Surface::makeShared<DiscSurface>(identity, annulus);
0290 anomalDiscSurfaces.push_back(disc);
0291 GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
0292 sConfig);
0293
0294 helper.write(std::string("Surfaces_DiscAnnulusBounds") + tag);
0295 helper.write(cStream);
0296 helper.clear();
0297
0298 double discTrapezoidHxRmin = 3.;
0299 double discTrapezoidHxRmax = 6.;
0300 auto discTrapezoid = std::make_shared<DiscTrapezoidBounds>(
0301 discTrapezoidHxRmin, discTrapezoidHxRmax, discRmin, discRmax);
0302 disc = Surface::makeShared<DiscSurface>(identity, discTrapezoid);
0303 anomalDiscSurfaces.push_back(disc);
0304 GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
0305 sConfig);
0306
0307 helper.write(std::string("Surfaces_DiscTrapezoidBounds") + tag);
0308 helper.write(cStream);
0309 helper.clear();
0310
0311
0312 std::vector<Transform3> twoAnomalDiscs = {
0313 Transform3(Translation3{-5., 0., 0.}),
0314 Transform3(Translation3{5., 0., 0.})};
0315 for (std::size_t id = 0; id < anomalDiscSurfaces.size(); ++id) {
0316 GeometryView3D::drawSurface(helper, *anomalDiscSurfaces[id], gctx,
0317 sixDiscs[id], sConfig);
0318 }
0319 helper.write(std::string("Surfaces_All_DiscSurfaces_AnomalBounds") + tag);
0320 helper.write(cStream);
0321 helper.clear();
0322
0323
0324
0325 std::vector<std::shared_ptr<PlaneSurface>> planarSurfaces;
0326
0327
0328 double ellipseR0min = 2;
0329 double ellipseR0max = 4;
0330 double ellipseR1min = 3;
0331 double ellipseR1max = 6;
0332 std::string name = "Surfaces_PlaneSurfaceEllipse";
0333 auto ellipse =
0334 std::make_shared<EllipseBounds>(0., 0., ellipseR1min, ellipseR1max);
0335 auto plane = Surface::makeShared<PlaneSurface>(identity, ellipse);
0336 planarSurfaces.push_back(plane);
0337 GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
0338 sConfig);
0339
0340 helper.write(name + tag);
0341 helper.write(cStream);
0342 helper.clear();
0343 writeBoundingBox2D(ellipse->boundingBox(), name);
0344
0345
0346 name = "Surfaces_PlaneSurfaceEllipseRing";
0347 ellipse = std::make_shared<EllipseBounds>(ellipseR0min, ellipseR0max,
0348 ellipseR1min, ellipseR1max);
0349 plane = Surface::makeShared<PlaneSurface>(identity, ellipse);
0350 planarSurfaces.push_back(plane);
0351 GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
0352 sConfig);
0353
0354 helper.write(name + tag);
0355 helper.write(cStream);
0356 helper.clear();
0357 writeBoundingBox2D(ellipse->boundingBox(), name);
0358
0359
0360 name = "Surfaces_PlaneSurfaceEllipseRingSector";
0361 ellipse = std::make_shared<EllipseBounds>(
0362 ellipseR0min, ellipseR0max, ellipseR1min, ellipseR1max, halfPhiSector);
0363 plane = Surface::makeShared<PlaneSurface>(identity, ellipse);
0364 planarSurfaces.push_back(plane);
0365 GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
0366 sConfig);
0367
0368 helper.write(name + tag);
0369 helper.write(cStream);
0370 helper.clear();
0371 writeBoundingBox2D(ellipse->boundingBox(), name);
0372
0373
0374 name = "Surfaces_PlaneSurfaceTriangleRegular";
0375 std::vector<Vector2> tvertices = {{-3, -1.5}, {3, -1.5}, {0, 4.5}};
0376 auto triangle = std::make_shared<ConvexPolygonBounds<3>>(tvertices);
0377 plane = Surface::makeShared<PlaneSurface>(identity, triangle);
0378 planarSurfaces.push_back(plane);
0379 GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
0380 sConfig);
0381
0382 helper.write(name + tag);
0383 helper.write(cStream);
0384 helper.clear();
0385 writeBoundingBox2D(triangle->boundingBox(), name);
0386
0387
0388 name = "Surfaces_PlaneSurfaceTriangleGeneral";
0389 tvertices = {{-1., 4.5}, {4, 6.5}, {3, 8.5}};
0390 triangle = std::make_shared<ConvexPolygonBounds<3>>(tvertices);
0391 plane = Surface::makeShared<PlaneSurface>(identity, triangle);
0392 planarSurfaces.push_back(plane);
0393 GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
0394 sConfig);
0395
0396 helper.write(name + tag);
0397 helper.write(cStream);
0398 helper.clear();
0399 writeBoundingBox2D(triangle->boundingBox(), name);
0400
0401
0402 name = "Surfaces_PlaneSurfaceConvexPolygonGeneral";
0403 tvertices = {{-1., 4.5}, {4, 6.5}, {6, 8.5}, {0, 10.5}, {-3, 6.2}};
0404 auto dynamicpolygon =
0405 std::make_shared<ConvexPolygonBounds<PolygonDynamic>>(tvertices);
0406 plane = Surface::makeShared<PlaneSurface>(identity, dynamicpolygon);
0407 planarSurfaces.push_back(plane);
0408 GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
0409 sConfig);
0410
0411 helper.write(name + tag);
0412 helper.write(cStream);
0413 helper.clear();
0414 writeBoundingBox2D(dynamicpolygon->boundingBox(), name);
0415
0416
0417 name = "Surfaces_PlaneSurfaceDiamond";
0418 auto diamond = std::make_shared<DiamondBounds>(3., 6., 2., 2., 4.);
0419 plane = Surface::makeShared<PlaneSurface>(identity, diamond);
0420 planarSurfaces.push_back(plane);
0421 GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
0422 sConfig);
0423
0424 helper.write(name + tag);
0425 helper.write(cStream);
0426 helper.clear();
0427 writeBoundingBox2D(diamond->boundingBox(), name);
0428
0429
0430 name = "Surfaces_PlaneSurfaceRectangle";
0431 auto rectangle = std::make_shared<RectangleBounds>(2., 3.);
0432 plane = Surface::makeShared<PlaneSurface>(identity, rectangle);
0433 planarSurfaces.push_back(plane);
0434 GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
0435 sConfig);
0436
0437 helper.write(name + tag);
0438 helper.write(cStream);
0439 helper.clear();
0440 writeBoundingBox2D(rectangle->boundingBox(), name);
0441
0442
0443 name = "Surfaces_PlaneSurfaceRectangleOffcentered";
0444 rectangle =
0445 std::make_shared<RectangleBounds>(Vector2{1., 2.}, Vector2{15., 12.});
0446 plane = Surface::makeShared<PlaneSurface>(identity, rectangle);
0447 GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
0448 sConfig);
0449
0450 helper.write(name + tag);
0451 helper.write(cStream);
0452 helper.clear();
0453 writeBoundingBox2D(rectangle->boundingBox(), name);
0454
0455
0456 name = "Surfaces_PlaneSurfaceTrapezoid";
0457 auto trapezoid = std::make_shared<TrapezoidBounds>(2., 5., 3.);
0458 plane = Surface::makeShared<PlaneSurface>(identity, trapezoid);
0459 planarSurfaces.push_back(plane);
0460 GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
0461 sConfig);
0462
0463 helper.write(name + tag);
0464 helper.write(cStream);
0465 helper.clear();
0466 writeBoundingBox2D(trapezoid->boundingBox(), name);
0467
0468
0469 std::vector<Transform3> ninePlanes = {
0470 Transform3(Translation3{-10., -10., 0.}),
0471 Transform3(Translation3{0., -10., 0.}),
0472 Transform3(Translation3{10., -10., 0.}),
0473 Transform3(Translation3{-10., 0., 0.}),
0474 Transform3(Translation3{0., -6., 0.}),
0475 Transform3(Translation3{10., -8., 0.}),
0476 Transform3(Translation3{-10, 10., 0.}),
0477 Transform3(Translation3{0., 10., 0.}),
0478 Transform3(Translation3{10., 10., 0.})};
0479 for (std::size_t ip = 0; ip < planarSurfaces.size(); ++ip) {
0480 GeometryView3D::drawSurface(helper, *planarSurfaces[ip], gctx,
0481 ninePlanes[ip], sConfig);
0482 }
0483 helper.write(std::string("Surfaces_All_PlaneSurfaces") + tag);
0484 helper.write(cStream);
0485 helper.clear();
0486
0487
0488
0489 name = "Surfaces_StrawSurface";
0490 auto tube = std::make_shared<LineBounds>(2., 20.);
0491 auto straw = Surface::makeShared<StrawSurface>(identity, tube);
0492 GeometryView3D::drawSurface(helper, *straw, gctx, Transform3::Identity(),
0493 sConfig);
0494
0495 helper.write(name + tag);
0496 helper.write(cStream);
0497 helper.clear();
0498
0499 return cStream.str();
0500 }
0501
0502 }