ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PlyVisualization.ipp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PlyVisualization.ipp
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 template <typename T>
12  m_vertices.emplace_back(vtx.template cast<ValueType>(), color);
13 }
14 
15 template <typename T>
16 void PlyVisualization<T>::face(const std::vector<Vector3D>& vtxs,
18  FaceType idxs;
19  idxs.reserve(vtxs.size());
20  for (const auto& vtx : vtxs) {
21  vertex(vtx, color);
22  idxs.push_back(m_vertices.size() - 1);
23  }
24  m_faces.push_back(std::move(idxs));
25 }
26 
27 template <typename T>
28 void PlyVisualization<T>::faces(const std::vector<Vector3D>& vtxs,
29  const std::vector<FaceType>&, ColorType color) {
30  face(vtxs, color);
31 }
32 
33 template <typename T>
36  vertex(a, color);
37  size_t idx_a = m_vertices.size() - 1;
38  vertex(b, color);
39  size_t idx_b = m_vertices.size() - 1;
40  m_edges.emplace_back(std::make_pair(std::make_pair(idx_a, idx_b), color));
41 }
42 
43 template <typename T>
44 void PlyVisualization<T>::write(const std::string& path) const {
45  std::ofstream os;
46  std::string objectpath = path;
47  if (not IVisualization::hasExtension(path)) {
48  objectpath += std::string(".ply");
49  }
50  os.open(objectpath);
51  write(os);
52  os.close();
53 }
54 
55 template <typename T>
56 void PlyVisualization<T>::write(std::ostream& os) const {
57  os << "ply\n";
58  os << "format ascii 1.0\n";
59  os << "element vertex " << m_vertices.size() << "\n";
60  os << "property float x\n";
61  os << "property float y\n";
62  os << "property float z\n";
63  os << "property uchar red\n";
64  os << "property uchar green\n";
65  os << "property uchar blue\n";
66  os << "element face " << m_faces.size() << "\n";
67  os << "property list uchar int vertex_index\n";
68  os << "element edge " << m_edges.size() << "\n";
69  os << "property int vertex1\n";
70  os << "property int vertex2\n";
71  os << "property uchar red\n";
72  os << "property uchar green\n";
73  os << "property uchar blue\n";
74  os << "end_header\n";
75 
76  for (const std::pair<VertexType, IVisualization::ColorType>& vtx :
77  m_vertices) {
78  os << vtx.first.x() << " " << vtx.first.y() << " " << vtx.first.z() << " ";
79  os << vtx.second[0] << " " << vtx.second[1] << " " << vtx.second[2] << "\n";
80  }
81 
82  for (const FaceType& fc : m_faces) {
83  os << fc.size();
84  for (size_t i = 0; i < fc.size(); i++) {
85  os << " " << fc[i];
86  }
87  os << "\n";
88  }
89 
90  for (const std::pair<std::pair<size_t, size_t>, IVisualization::ColorType>&
91  edge : m_edges) {
92  std::pair<size_t, size_t> idxs = edge.first;
93  os << idxs.first << " " << idxs.second << " ";
94  os << edge.second[0] << " " << edge.second[1] << " " << edge.second[2]
95  << "\n";
96  }
97 }
98 
99 template <typename T>
101  m_vertices.clear();
102  m_faces.clear();
103  m_edges.clear();
104 }