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) 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 template <typename T>
0010 void PlyVisualization3D<T>::vertex(const Vector3& vtx, ColorRGB color) {
0011   m_vertices.emplace_back(vtx.template cast<ValueType>(), color);
0012 }
0013 
0014 template <typename T>
0015 void PlyVisualization3D<T>::face(const std::vector<Vector3>& vtxs,
0016                                  ColorRGB color) {
0017   FaceType idxs;
0018   idxs.reserve(vtxs.size());
0019   for (const auto& vtx : vtxs) {
0020     vertex(vtx, color);
0021     idxs.push_back(m_vertices.size() - 1);
0022   }
0023   m_faces.push_back(std::move(idxs));
0024 }
0025 
0026 template <typename T>
0027 void PlyVisualization3D<T>::faces(const std::vector<Vector3>& vtxs,
0028                                   const std::vector<FaceType>& /*faces*/,
0029                                   ColorRGB color) {
0030   face(vtxs, color);
0031 }
0032 
0033 template <typename T>
0034 void PlyVisualization3D<T>::line(const Vector3& a, const Vector3& b,
0035                                  ColorRGB color) {
0036   vertex(a, color);
0037   std::size_t idx_a = m_vertices.size() - 1;
0038   vertex(b, color);
0039   std::size_t idx_b = m_vertices.size() - 1;
0040   m_edges.emplace_back(std::make_pair(std::make_pair(idx_a, idx_b), color));
0041 }
0042 
0043 template <typename T>
0044 void PlyVisualization3D<T>::write(const std::string& path) const {
0045   std::ofstream os;
0046   std::string objectpath = path;
0047   if (!IVisualization3D::hasExtension(path)) {
0048     objectpath += std::string(".ply");
0049   }
0050   os.open(objectpath);
0051   write(os);
0052   os.close();
0053 }
0054 
0055 template <typename T>
0056 void PlyVisualization3D<T>::write(std::ostream& os) const {
0057   os << "ply\n";
0058   os << "format ascii 1.0\n";
0059   os << "element vertex " << m_vertices.size() << "\n";
0060   os << "property float x\n";
0061   os << "property float y\n";
0062   os << "property float z\n";
0063   os << "property uchar red\n";
0064   os << "property uchar green\n";
0065   os << "property uchar blue\n";
0066   os << "element face " << m_faces.size() << "\n";
0067   os << "property list uchar int vertex_index\n";
0068   os << "element edge " << m_edges.size() << "\n";
0069   os << "property int vertex1\n";
0070   os << "property int vertex2\n";
0071   os << "property uchar red\n";
0072   os << "property uchar green\n";
0073   os << "property uchar blue\n";
0074   os << "end_header\n";
0075 
0076   for (const std::pair<VertexType, ColorRGB>& vtx : m_vertices) {
0077     os << vtx.first.x() << " " << vtx.first.y() << " " << vtx.first.z() << " ";
0078     os << vtx.second[0] << " " << vtx.second[1] << " " << vtx.second[2] << "\n";
0079   }
0080 
0081   for (const FaceType& fc : m_faces) {
0082     os << fc.size();
0083     for (std::size_t i = 0; i < fc.size(); i++) {
0084       os << " " << fc[i];
0085     }
0086     os << "\n";
0087   }
0088 
0089   for (const std::pair<std::pair<std::size_t, std::size_t>, ColorRGB>& edge :
0090        m_edges) {
0091     std::pair<std::size_t, std::size_t> idxs = edge.first;
0092     os << idxs.first << " " << idxs.second << " ";
0093     os << edge.second[0] << " " << edge.second[1] << " " << edge.second[2]
0094        << "\n";
0095   }
0096 }
0097 
0098 template <typename T>
0099 void PlyVisualization3D<T>::clear() {
0100   m_vertices.clear();
0101   m_faces.clear();
0102   m_edges.clear();
0103 }