ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ObjTestWriter.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ObjTestWriter.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2018 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 #include <fstream>
10 #include <vector>
13 #include "Acts/Geometry/Volume.hpp"
19 
20 namespace Acts {
21 
22 using IdentifiedPolyderon = std::tuple<std::string, bool, Polyhedron>;
23 
24 namespace Test {
25 
26 struct ObjTestWriter {
31  static void writeSectorLinesObj(const std::string& name,
32  const std::pair<Vector3D, Vector3D>& lineA,
33  const std::pair<Vector3D, Vector3D>& lineB) {
34  std::ofstream ostream;
35  ostream.open(name + ".obj");
36  ObjVisualization objH;
37  objH.line(lineA.first, lineA.second);
38  objH.line(lineB.first, lineB.second);
39  objH.write(ostream);
40  ostream.close();
41  }
42 
50  static void writeSectorPlanesObj(const std::string& name, double phiSec,
51  double phiAvg, double hX, double hY) {
52  // Construct the helper planes for sectoral building
53  auto sectorBounds = std::make_shared<RectangleBounds>(hX, hY);
54 
55  Vector3D helperColX(0., 0., 1.);
56  Vector3D helperColY(1., 0., 0.);
57  Vector3D helperColZ(0., 1., 0.);
58  RotationMatrix3D helperRotation;
59  helperRotation.col(0) = helperColX;
60  helperRotation.col(1) = helperColY;
61  helperRotation.col(2) = helperColZ;
62  // curvilinear surfaces are boundless
63  Transform3D helperTransform{helperRotation};
64 
65  auto sectorTransformM = std::make_shared<Transform3D>(helperTransform);
66  sectorTransformM->prerotate(AngleAxis3D(phiAvg - phiSec, helperColX));
67 
68  auto sectorTransformP = std::make_shared<Transform3D>(helperTransform);
69  sectorTransformP->prerotate(AngleAxis3D(phiAvg + phiSec, helperColX));
70 
71  auto sectorPlaneM =
72  Surface::makeShared<PlaneSurface>(sectorTransformM, sectorBounds);
73 
74  auto sectorPlaneP =
75  Surface::makeShared<PlaneSurface>(sectorTransformP, sectorBounds);
76 
77  std::ofstream ostream;
78  ostream.open(name + ".obj");
79  ObjVisualization objH;
80  sectorPlaneM->polyhedronRepresentation(GeometryContext(), 1).draw(objH);
81  sectorPlaneP->polyhedronRepresentation(GeometryContext(), 1).draw(objH);
82  objH.write(ostream);
83  ostream.close();
84  }
85 
90  static void writeObj(const std::vector<IdentifiedPolyderon>& iphs) {
91  for (const auto& iph : iphs) {
92  std::ofstream ostream;
93  ostream.open(std::get<std::string>(iph) + ".obj");
94  ObjVisualization objH;
95  std::get<Polyhedron>(iph).draw(objH, std::get<bool>(iph));
96  objH.write(ostream);
97  ostream.close();
98  }
99  }
100 
105  static void writeObj(const std::string& name,
106  const Volume::BoundingBox& bBox) {
107  std::ofstream ostream;
108  ostream.open(name + std::string(".obj"));
109  ObjVisualization objH;
110  bBox.draw(objH);
111  objH.write(ostream);
112  ostream.close();
113  }
114 };
115 
116 } // namespace Test
117 
118 } // namespace Acts