ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VolumeVisualizationBase.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file VolumeVisualizationBase.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
13 
19 
20 #include <fstream>
21 #include <sstream>
22 #include <string>
23 
24 namespace Acts {
25 namespace VolumeVisualization {
33 
34 static inline std::string test(IVisualization& helper, bool triangulate,
35  const std::string& tag) {
36  auto gctx = GeometryContext();
37  auto identity = std::make_shared<Transform3D>(Transform3D::Identity());
38  std::ofstream stream;
39  std::stringstream cStream;
40 
41  double halfPhiSector = M_PI / 4.;
42 
46  auto write = [&](const std::string& path, bool clear = true) -> void {
47  std::string wpath = path + tag;
48  helper.write(wpath);
49  helper.write(cStream);
50  if (clear) {
51  helper.clear();
52  }
53  };
54 
55  // ---------------------------------------------------
56  // Cuboid surface section
57  IVisualization::ColorType boxColor = {0, 0, 255};
58 
59  auto box = std::make_shared<CuboidVolumeBounds>(4., 3., 6.);
60  auto cuboid = std::make_shared<AbstractVolume>(identity, box);
61  Visualization::drawVolume(helper, *cuboid, gctx, Transform3D::Identity(), 72,
62  triangulate, boxColor);
63  write("Volumes_CuboidVolume");
64 
65  //----------------------------------------------------
66  // Cylinder volume section
67  IVisualization::ColorType cylinderColor = {0, 196, 252};
68 
69  double cylinderInnerR = 1.;
70  double cylinderOuterR = 5.;
71  double cylinderHalfZ = 10.;
72 
73  auto fullCylinder =
74  std::make_shared<CylinderVolumeBounds>(0., cylinderOuterR, cylinderHalfZ);
75  auto cylinder = std::make_shared<AbstractVolume>(identity, fullCylinder);
76  Visualization::drawVolume(helper, *cylinder, gctx, Transform3D::Identity(),
77  72, triangulate, cylinderColor);
78  write("Volumes_CylinderVolumeFull");
79 
80  auto tubeCylinder = std::make_shared<CylinderVolumeBounds>(
81  cylinderInnerR, cylinderOuterR, cylinderHalfZ);
82  cylinder = std::make_shared<AbstractVolume>(identity, tubeCylinder);
83  Visualization::drawVolume(helper, *cylinder, gctx, Transform3D::Identity(),
84  72, triangulate, cylinderColor);
85  write("Volumes_CylinderVolumeTube");
86 
87  tubeCylinder = std::make_shared<CylinderVolumeBounds>(
88  cylinderInnerR, cylinderOuterR, cylinderHalfZ, halfPhiSector);
89  cylinder = std::make_shared<AbstractVolume>(identity, tubeCylinder);
90  Visualization::drawVolume(helper, *cylinder, gctx, Transform3D::Identity(),
91  72, triangulate, cylinderColor);
92  write("Volumes_CylinderVolumeTubeSector");
93 
94  //----------------------------------------------------
95  // Trapezoid volume section
96  IVisualization::ColorType genericColor = {23, 196, 22};
97  std::array<Vector3D, 8> vertices;
98  vertices = {{{0, 0, 0},
99  {2, 0, 0},
100  {2, 1, 0},
101  {0, 1, 0},
102  {0, 0, 1},
103  {2, 0, 1},
104  {2, 1, 1},
105  {0, 1, 1}}};
106  auto genericCuboid = std::make_shared<GenericCuboidVolumeBounds>(vertices);
107  auto generic = std::make_shared<AbstractVolume>(identity, genericCuboid);
108  Visualization::drawVolume(helper, *generic, gctx, Transform3D::Identity(), 72,
109  triangulate, genericColor);
110  write("Volumes_GenericCuboidVolume");
111 
112  //----------------------------------------------------
113  // Trapezoid volume section
114  IVisualization::ColorType trapezoidColor = {23, 196, 22};
115  auto trapezoid = std::make_shared<TrapezoidVolumeBounds>(2., 4., 5., 6.);
116  auto trapezoidVolume = std::make_shared<AbstractVolume>(identity, trapezoid);
117  Visualization::drawVolume(helper, *trapezoidVolume, gctx,
118  Transform3D::Identity(), 72, triangulate,
119  trapezoidColor);
120  write("Volumes_TrapezoidVolume");
121 
122  return cStream.str();
123 }
124 
125 } // namespace VolumeVisualization
126 } // namespace Acts