Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:23:43

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2019 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/Definitions/Algebra.hpp"
0012 #include "Acts/Visualization/IVisualization3D.hpp"
0013 #include "Acts/Visualization/ViewConfig.hpp"
0014 
0015 #include <array>
0016 #include <fstream>
0017 #include <iomanip>
0018 #include <map>
0019 #include <sstream>
0020 #include <string>
0021 #include <vector>
0022 
0023 namespace Acts {
0024 
0025 /// This helper produces output in the OBJ format. Note that colors are not
0026 /// supported in this implementation.
0027 ///
0028 template <typename T = double>
0029 class ObjVisualization3D : public IVisualization3D {
0030  public:
0031   static_assert(std::is_same_v<T, double> || std::is_same_v<T, float>,
0032                 "Use either double or float");
0033 
0034   /// Stored value type, should be double or float
0035   using ValueType = T;
0036 
0037   /// Type of a vertex based on the value type
0038   using VertexType = Eigen::Matrix<ValueType, 3, 1>;
0039 
0040   /// Type of a line
0041   using LineType = std::pair<std::size_t, std::size_t>;
0042 
0043   /// Constructor that allows to set scalor and precision
0044   /// @param prec The output precision with std::setprecision
0045   /// @param scale An (optional) scaling for the writing out
0046   ObjVisualization3D(unsigned int prec = 4, double scale = 1.)
0047       : m_outputPrecision(prec), m_outputScalor(scale) {}
0048 
0049   /// @copydoc Acts::IVisualization3D::vertex()
0050   void vertex(const Vector3& vtx, ColorRGB color = {0, 0, 0}) final;
0051 
0052   /// @copydoc Acts::IVisualization3D::line()
0053   void line(const Vector3& a, const Vector3& b,
0054             ColorRGB color = {0, 0, 0}) final;
0055 
0056   /// @copydoc Acts::IVisualization3D::face()
0057   void face(const std::vector<Vector3>& vtxs, ColorRGB color = {0, 0, 0}) final;
0058 
0059   /// @copydoc Acts::IVisualization3D::faces()
0060   void faces(const std::vector<Vector3>& vtxs,
0061              const std::vector<FaceType>& faces,
0062              ColorRGB color = {0, 0, 0}) final;
0063 
0064   /// @copydoc Acts::IVisualization3D::write(const std::string&) const
0065   void write(const std::string& path) const final;
0066 
0067   /// @copydoc Acts::IVisualization3D::write(std::ostream&) const
0068   void write(std::ostream& os) const final;
0069 
0070   /// Write the object and the material file
0071   /// @param os the output stream for the object
0072   /// @param mos the output stream for the auxiliary material file
0073   void write(std::ostream& os, std::ostream& mos) const;
0074 
0075   ///  @copydoc Acts::IVisualization3D::clear()
0076   void clear() final;
0077 
0078  private:
0079   /// The output parameters
0080   unsigned int m_outputPrecision = 4;
0081   double m_outputScalor = 1.;
0082   /// The object data to be written
0083   std::vector<VertexType> m_vertices;
0084   std::vector<FaceType> m_faces;
0085   std::vector<LineType> m_lines;
0086   /// Map of colors to be written at given index position
0087   std::map<std::size_t, ColorRGB> m_lineColors;
0088   std::map<std::size_t, ColorRGB> m_vertexColors;
0089   std::map<std::size_t, ColorRGB> m_faceColors;
0090 };
0091 
0092 #ifndef DOXYGEN
0093 #include "detail/ObjVisualization3D.ipp"
0094 #endif
0095 
0096 }  // namespace Acts