Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Visualization3DTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Visualization3DTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 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 #include <boost/test/tools/output_test_stream.hpp>
10 #include <boost/test/unit_test.hpp>
11 
16 
17 #include <iostream>
18 #include <string>
19 #include <vector>
20 
22 
23 using boost::test_tools::output_test_stream;
24 
25 namespace Acts {
26 namespace Test {
27 
28 BOOST_AUTO_TEST_SUITE(Visualization)
29 
30 BOOST_AUTO_TEST_CASE(Visualization3DTesterObj) {
31  // Test the tester
32  std::string validObj = R"(# obj test file mtllib material.mtl usemtl material_a g rectangle vn 0 0 1 vt 0 0 1 v -15 -15 0 v 15 -15 0 v 15 15 0 v -15 15 0 f 1 2 3 4 l 1 2 l 2 3 l 3 4 l 4 1 )";
33 
34  // Valid obj
35  auto objErrors = testObjString(validObj);
36  BOOST_CHECK(objErrors.empty());
37 
38  // Valid obj, but triangular mesh is requested
39  objErrors = testObjString(validObj, true);
40  BOOST_CHECK(objErrors.size() == 1);
41  for (const auto& objerr : objErrors) {
42  std::cout << objerr << std::endl;
43  }
44 
45  // Non-valid obj - it has 4 errors
46  std::string invalidObj = R"(# obj test file mtllib material.mtl usemtl material_a x whatever g rectangle vn 0 0 1 vt 0 0 1 v -15 -15 0 23 v 15 -15 0 v 15. 15 0 v -15 15. 0 f 1 2 3. 4 l 0 2 l 2 3 l 3 4 l 4 1 )";
47 
48  objErrors = testObjString(invalidObj);
49  BOOST_CHECK(objErrors.size() == 4);
50  for (const auto& objerr : objErrors) {
51  std::cout << objerr << std::endl;
52  }
53 }
54 
55 BOOST_AUTO_TEST_CASE(Visualization3DTesterPly) {
56  // Test the tester
57  std::string validPly = R"(ply format ascii 1.0 comment made by Greg Turk comment this file is a cube element vertex 8 property float x property float y property float z element face 6 property list uchar int vertex_indices end_header 0 0 0 0 0 1 0 1 1 0 1 0 1 0 0 1 0 1 1 1 1 1 1 0 4 0 1 2 3 4 7 6 5 4 4 0 4 5 1 4 1 5 6 2 4 2 6 7 3 4 3 7 4 0 )";
58 
59  // Valid ply
60  auto plyErrors = testPlyString(validPly);
61  BOOST_CHECK(plyErrors.empty());
62 
63  // Valid ply, but triangular mesh is requested
64  plyErrors = testPlyString(validPly, true);
65  BOOST_CHECK(plyErrors.empty());
66  for (const auto& plyerr : plyErrors) {
67  std::cout << plyerr << std::endl;
68  }
69 
70  // Test the tester - contains 3 errors
71  std::string invalidPly = R"(ply format ascii 1.0 comment made by Greg Turk comment this file is a cube element vertex 8 property float x property float y property float z element face 6 property list uchar int vertex_indices whatever i write here end_header 0 0 0 0 0 0 1 0 1 1 0 1 0 1 0 0 1 0 1 1 1 1 1 1 0 4 0 1 2 3 4 7 6 5 4 4 0 4 5 1 4 1 5 6 4 2 6 7 3 4 3 7 4 0 )";
72 
73  // Valid ply, but triangular mesh is requested
74  plyErrors = testPlyString(invalidPly);
75  BOOST_CHECK(plyErrors.size() == 3);
76  for (const auto& plyerr : plyErrors) {
77  std::cout << plyerr << std::endl;
78  }
79 }
80 
81 BOOST_AUTO_TEST_CASE(Visualization3DConstruction) {
82  // this doesn't really test anything, other than conformance to the
83  // IVisualization3D interface
84  PlyVisualization3D ply;
85  ObjVisualization3D obj;
86 
87  IVisualization3D* vis = nullptr;
88  vis = &ply;
89  std::cout << *vis << std::endl;
90  vis = &obj;
91  std::cout << *vis << std::endl;
92 }
93 
94 BOOST_AUTO_TEST_CASE(PlyOutputTest) {
96  output_test_stream output;
97 
98  ply.vertex({0, 0, 0});
99 
100  std::string exp = R"(ply format ascii 1.0 element vertex 1 property float x property float y property float z property uchar red property uchar green property uchar blue element face 0 property list uchar int vertex_index element edge 0 property int vertex1 property int vertex2 property uchar red property uchar green property uchar blue end_header 0 0 0 120 120 120 )";
101 
102  output << ply;
103  BOOST_CHECK(output.is_equal(exp));
104 
105  ply.clear();
106  ply.vertex({0, 1, 0});
107 
108  exp = R"(ply format ascii 1.0 element vertex 1 property float x property float y property float z property uchar red property uchar green property uchar blue element face 0 property list uchar int vertex_index element edge 0 property int vertex1 property int vertex2 property uchar red property uchar green property uchar blue end_header 0 1 0 120 120 120 )";
109 
110  output << ply;
111  BOOST_CHECK(output.is_equal(exp));
112 
113  ply.clear();
114  ply.line({0, 0, 1}, {1, 0, 0});
115 
116  output << ply;
117 
118  exp = R"(ply format ascii 1.0 element vertex 2 property float x property float y property float z property uchar red property uchar green property uchar blue element face 0 property list uchar int vertex_index element edge 1 property int vertex1 property int vertex2 property uchar red property uchar green property uchar blue end_header 0 0 1 120 120 120 1 0 0 120 120 120 0 1 120 120 120 )";
119 
120  BOOST_CHECK(output.is_equal(exp));
121 
122  ply.clear();
123  ply.face({{1, 0, 0}, {1, 1, 0}, {0, 1, 0}});
124 
125  output << ply;
126 
127  exp = R"(ply format ascii 1.0 element vertex 3 property float x property float y property float z property uchar red property uchar green property uchar blue element face 1 property list uchar int vertex_index element edge 0 property int vertex1 property int vertex2 property uchar red property uchar green property uchar blue end_header 1 0 0 120 120 120 1 1 0 120 120 120 0 1 0 120 120 120 3 0 1 2 )";
128 
129  BOOST_CHECK(output.is_equal(exp));
130 }
131 
132 BOOST_AUTO_TEST_CASE(ObjOutputTest) {
133  ObjVisualization3D obj;
134 
135  output_test_stream output;
136 
137  obj.vertex({1, 0, 0});
138 
139  output << obj;
140 
141  std::string exp = R"(v 1 0 0 )";
142 
143  BOOST_CHECK(output.is_equal(exp));
144 
145  obj.clear();
146  obj.face({{1, 0, 0}, {1, 1, 0}, {0, 1, 0}});
147  output << obj;
148 
149  exp = R"(v 1 0 0 v 1 1 0 v 0 1 0 f 1 2 3 )";
150 
151  BOOST_CHECK(output.is_equal(exp));
152 }
153 
154 BOOST_AUTO_TEST_SUITE_END()
155 } // namespace Test
156 } // namespace Acts
157