Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PlyVisualization3D.ipp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PlyVisualization3D.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>
11  m_vertices.emplace_back(vtx.template cast<ValueType>(), color);
12 }
13 
14 template <typename T>
15 void PlyVisualization3D<T>::face(const std::vector<Vector3>& vtxs,
16  ColorRGB color) {
17  FaceType idxs;
18  idxs.reserve(vtxs.size());
19  for (const auto& vtx : vtxs) {
20  vertex(vtx, color);
21  idxs.push_back(m_vertices.size() - 1);
22  }
23  m_faces.push_back(std::move(idxs));
24 }
25 
26 template <typename T>
27 void PlyVisualization3D<T>::faces(const std::vector<Vector3>& vtxs,
28  const std::vector<FaceType>& /*faces*/,
29  ColorRGB color) {
30  face(vtxs, color);
31 }
32 
33 template <typename T>
35  ColorRGB color) {
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>
45  std::ofstream os;
46  std::string objectpath = path;
47  if (not IVisualization3D::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 PlyVisualization3D<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, ColorRGB>& vtx : m_vertices) {
77  os << vtx.first.x() << " " << vtx.first.y() << " " << vtx.first.z() << " ";
78  os << vtx.second[0] << " " << vtx.second[1] << " " << vtx.second[2] << "\n";
79  }
80 
81  for (const FaceType& fc : m_faces) {
82  os << fc.size();
83  for (size_t i = 0; i < fc.size(); i++) {
84  os << " " << fc[i];
85  }
86  os << "\n";
87  }
88 
89  for (const std::pair<std::pair<size_t, size_t>, ColorRGB>& edge : m_edges) {
90  std::pair<size_t, size_t> idxs = edge.first;
91  os << idxs.first << " " << idxs.second << " ";
92  os << edge.second[0] << " " << edge.second[1] << " " << edge.second[2]
93  << "\n";
94  }
95 }
96 
97 template <typename T>
99  m_vertices.clear();
100  m_faces.clear();
101  m_edges.clear();
102 }