Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:14

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 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 https://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 <filesystem>
0016 #include <map>
0017 #include <string>
0018 #include <vector>
0019 
0020 namespace Acts {
0021 
0022 /// This helper produces output in the OBJ format. Note that colors are not
0023 /// supported in this implementation.
0024 ///
0025 class ObjVisualization3D : public IVisualization3D {
0026  public:
0027   /// Stored value type, should be double or float
0028   using ValueType = double;
0029 
0030   /// Type of a vertex based on the value type
0031   using VertexType = Eigen::Matrix<ValueType, 3, 1>;
0032 
0033   /// Type of a line
0034   using LineType = std::pair<std::size_t, std::size_t>;
0035 
0036   /// Constructor that allows to set scalor and precision
0037   /// @param prec The output precision with std::setprecision
0038   /// @param scale An (optional) scaling for the writing out
0039   ObjVisualization3D(unsigned int prec = 4, double scale = 1.)
0040       : m_outputPrecision(prec), m_outputScalor(scale) {}
0041 
0042   /// @copydoc Acts::IVisualization3D::vertex()
0043   void vertex(const Vector3& vtx, Color color = s_defaultColor) final;
0044 
0045   /// @copydoc Acts::IVisualization3D::line()
0046   void line(const Vector3& a, const Vector3& b,
0047             Color color = s_defaultColor) final;
0048 
0049   /// @copydoc Acts::IVisualization3D::face()
0050   void face(const std::vector<Vector3>& vtxs,
0051             Color color = s_defaultColor) final;
0052 
0053   /// @copydoc Acts::IVisualization3D::faces()
0054   void faces(const std::vector<Vector3>& vtxs,
0055              const std::vector<FaceType>& faces,
0056              Color color = s_defaultColor) final;
0057 
0058   /// @copydoc Acts::IVisualization3D::write(const std::filesystem::path&) const
0059   void write(const std::filesystem::path& path) const final;
0060 
0061   /// @copydoc Acts::IVisualization3D::write(std::ostream&) const
0062   void write(std::ostream& os) const final;
0063 
0064   /// Write the object and the material file
0065   /// @param os the output stream for the object
0066   /// @param mos the output stream for the auxiliary material file
0067   void write(std::ostream& os, std::ostream& mos) const;
0068 
0069   ///  @copydoc Acts::IVisualization3D::clear()
0070   void clear() final;
0071 
0072   /// Start a new object context with a name
0073   /// @param name The name of the object
0074   void object(const std::string& name) final;
0075 
0076  private:
0077   struct Object {
0078     std::string name;
0079     std::vector<VertexType> vertices{};
0080     std::vector<FaceType> faces{};
0081     std::vector<LineType> lines{};
0082 
0083     /// The object data to be written
0084     /// Map of colors to be written at given index position
0085     std::map<std::size_t, Color> lineColors{};
0086     std::map<std::size_t, Color> vertexColors{};
0087     std::map<std::size_t, Color> faceColors{};
0088   };
0089 
0090   Object& object();
0091   const Object& object() const;
0092 
0093   /// The output parameters
0094   unsigned int m_outputPrecision = 4;
0095   double m_outputScalor = 1.;
0096 
0097   std::vector<Object> m_objects;
0098 };
0099 
0100 }  // namespace Acts