Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:38

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2020 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Geometry/ConeVolumeBounds.hpp"
0012 #include "Acts/Geometry/CuboidVolumeBounds.hpp"
0013 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0014 #include "Acts/Geometry/GenericCuboidVolumeBounds.hpp"
0015 #include "Acts/Geometry/TrapezoidVolumeBounds.hpp"
0016 #include "Acts/Geometry/Volume.hpp"
0017 #include "Acts/Visualization/GeometryView3D.hpp"
0018 #include "Acts/Visualization/IVisualization3D.hpp"
0019 
0020 #include <fstream>
0021 #include <sstream>
0022 #include <string>
0023 
0024 namespace Acts::VolumeView3DTest {
0025 
0026 /// Helper method to visualize all types of surfaces
0027 ///
0028 /// @param helper The visualization helper
0029 /// @param triangulate The directive whether to create triangular meshes
0030 /// @param tag The test tag (mode) identification
0031 ///
0032 /// @return a string containing all written characters
0033 
0034 static inline std::string run(IVisualization3D& helper, bool triangulate,
0035                               const std::string& tag) {
0036   auto gctx = GeometryContext();
0037   auto identity = Transform3::Identity();
0038   std::stringstream cStream;
0039 
0040   double halfPhiSector = M_PI / 4.;
0041 
0042   ViewConfig vConfig = s_viewVolume;
0043   vConfig.triangulate = triangulate;
0044 
0045   // ---------------------------------------------------
0046   // Cuboid surface section
0047   auto box = std::make_shared<CuboidVolumeBounds>(4., 3., 6.);
0048   auto cuboid = std::make_shared<Volume>(identity, box);
0049   GeometryView3D::drawVolume(helper, *cuboid, gctx, Transform3::Identity(),
0050                              vConfig);
0051   helper.write(std::string("Volumes_CuboidVolume") + tag);
0052   helper.write(cStream);
0053   helper.clear();
0054 
0055   //----------------------------------------------------
0056   // Cone volume section
0057   // Single solid Cone
0058   auto solidCone =
0059       std::make_shared<ConeVolumeBounds>(0., 0., 0.45, 5., 5., 0., M_PI);
0060   auto cone = std::make_shared<Volume>(identity, solidCone);
0061   GeometryView3D::drawVolume(helper, *cone, gctx, Transform3::Identity(),
0062                              vConfig);
0063   helper.write("Volumes_ConeVolumeSolid");
0064   helper.write(cStream);
0065   helper.clear();
0066 
0067   // Single solid Cone - with cut off
0068   auto cutOffCone =
0069       std::make_shared<ConeVolumeBounds>(0., 0., 0.45, 8., 5., 0., M_PI);
0070   cone = std::make_shared<Volume>(identity, cutOffCone);
0071   GeometryView3D::drawVolume(helper, *cone, gctx, Transform3::Identity(),
0072                              vConfig);
0073   helper.write("Volumes_ConeVolumeSolidCutOff");
0074   helper.write(cStream);
0075   helper.clear();
0076 
0077   // Cone - Cone inlay
0078   auto cutOffHollowCone =
0079       std::make_shared<ConeVolumeBounds>(0.35, 7., 0.45, 8., 5, 0., M_PI);
0080   cone = std::make_shared<Volume>(identity, cutOffHollowCone);
0081   GeometryView3D::drawVolume(helper, *cone, gctx, Transform3::Identity(),
0082                              vConfig);
0083   helper.write("Volumes_ConeVolumeConeCone");
0084   helper.write(cStream);
0085   helper.clear();
0086 
0087   // Sectoral Cone - Cone inlay
0088   auto cutOffHollowSectoralCone =
0089       std::make_shared<ConeVolumeBounds>(0.35, 7., 0.45, 8., 5., 0., 0.456);
0090   cone = std::make_shared<Volume>(identity, cutOffHollowSectoralCone);
0091   GeometryView3D::drawVolume(helper, *cone, gctx, Transform3::Identity(),
0092                              vConfig);
0093   helper.write("Volumes_ConeVolumeConeConeSectoral");
0094   helper.write(cStream);
0095   helper.clear();
0096 
0097   // Single Hollow Cone - cylindrical inlay
0098   auto cutOffHollowCylCone =
0099       std::make_shared<ConeVolumeBounds>(1., 0.45, 8., 5., 0., M_PI);
0100   cone = std::make_shared<Volume>(identity, cutOffHollowCylCone);
0101   GeometryView3D::drawVolume(helper, *cone, gctx, Transform3::Identity(),
0102                              vConfig);
0103   helper.write("Volumes_ConeVolumeConeCylinder");
0104   helper.write(cStream);
0105   helper.clear();
0106 
0107   // Single Hollow Cylinder - Cone inlay
0108   auto cutOffHollowConeCyl =
0109       std::make_shared<ConeVolumeBounds>(12., 0.35, 7., 5., 0., M_PI);
0110   cone = std::make_shared<Volume>(identity, cutOffHollowConeCyl);
0111   GeometryView3D::drawVolume(helper, *cone, gctx, Transform3::Identity(),
0112                              vConfig);
0113   helper.write("Volumes_ConeVolumeCylinderCone");
0114   helper.write(cStream);
0115   helper.clear();
0116 
0117   //----------------------------------------------------
0118   // Cylinder volume section
0119   double cylinderInnerR = 1.;
0120   double cylinderOuterR = 5.;
0121   double cylinderHalfZ = 10.;
0122 
0123   auto fullCylinder =
0124       std::make_shared<CylinderVolumeBounds>(0., cylinderOuterR, cylinderHalfZ);
0125   auto cylinder = std::make_shared<Volume>(identity, fullCylinder);
0126   GeometryView3D::drawVolume(helper, *cylinder, gctx, Transform3::Identity(),
0127                              vConfig);
0128   helper.write("Volumes_CylinderVolumeFull");
0129   helper.write(cStream);
0130   helper.clear();
0131 
0132   auto tubeCylinder = std::make_shared<CylinderVolumeBounds>(
0133       cylinderInnerR, cylinderOuterR, cylinderHalfZ);
0134   cylinder = std::make_shared<Volume>(identity, tubeCylinder);
0135   GeometryView3D::drawVolume(helper, *cylinder, gctx, Transform3::Identity(),
0136                              vConfig);
0137   helper.write("Volumes_CylinderVolumeTube");
0138   helper.write(cStream);
0139   helper.clear();
0140 
0141   tubeCylinder = std::make_shared<CylinderVolumeBounds>(
0142       cylinderInnerR, cylinderOuterR, cylinderHalfZ, halfPhiSector);
0143   cylinder = std::make_shared<Volume>(identity, tubeCylinder);
0144   GeometryView3D::drawVolume(helper, *cylinder, gctx, Transform3::Identity(),
0145                              vConfig);
0146   helper.write("Volumes_CylinderVolumeTubeSector");
0147   helper.write(cStream);
0148   helper.clear();
0149 
0150   //----------------------------------------------------
0151   // Trapezoid volume section
0152   std::array<Vector3, 8> vertices;
0153   vertices = {{{0, 0, 0},
0154                {2, 0, 0},
0155                {2, 1, 0},
0156                {0, 1, 0},
0157                {0, 0, 1},
0158                {2, 0, 1},
0159                {2, 1, 1},
0160                {0, 1, 1}}};
0161   auto genericCuboid = std::make_shared<GenericCuboidVolumeBounds>(vertices);
0162   auto generic = std::make_shared<Volume>(identity, genericCuboid);
0163   GeometryView3D::drawVolume(helper, *generic, gctx, Transform3::Identity(),
0164                              vConfig);
0165   helper.write("Volumes_GenericCuboidVolume");
0166   helper.write(cStream);
0167   helper.clear();
0168 
0169   //----------------------------------------------------
0170   // Trapezoid volume section
0171   auto trapezoid = std::make_shared<TrapezoidVolumeBounds>(2., 4., 5., 6.);
0172   auto trapezoidVolume = std::make_shared<Volume>(identity, trapezoid);
0173   GeometryView3D::drawVolume(helper, *trapezoidVolume, gctx,
0174                              Transform3::Identity(), vConfig);
0175   helper.write("Volumes_TrapezoidVolume");
0176   helper.write(cStream);
0177   helper.clear();
0178 
0179   return cStream.str();
0180 }
0181 
0182 }  // namespace Acts::VolumeView3DTest