ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VisualizationTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file VisualizationTests.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 
12 #include <iostream>
13 #include <string>
14 
18 #include "VisualizationTester.hpp"
19 
20 using boost::test_tools::output_test_stream;
21 
22 namespace Acts {
23 namespace Test {
24 
25 BOOST_AUTO_TEST_SUITE(Visualization)
26 
27 BOOST_AUTO_TEST_CASE(VisualizationTesterObj) {
28  // Test the tester
29  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 )";
30 
31  // Valid obj
32  auto objErrors = testObjString(validObj);
33  BOOST_CHECK(objErrors.size() == 0);
34 
35  // Valid obj, but triangular mesh is requested
36  objErrors = testObjString(validObj, true);
37  BOOST_CHECK(objErrors.size() == 1);
38  for (auto objerr : objErrors) {
39  std::cout << objerr << std::endl;
40  }
41 
42  // Non-valid obj - it has 4 errors
43  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 )";
44 
45  objErrors = testObjString(invalidObj);
46  BOOST_CHECK(objErrors.size() == 4);
47  for (auto objerr : objErrors) {
48  std::cout << objerr << std::endl;
49  }
50 }
51 
52 BOOST_AUTO_TEST_CASE(VisualizationTesterPly) {
53  // Test the tester
54  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 )";
55 
56  // Valid ply
57  auto plyErrors = testPlyString(validPly);
58  BOOST_CHECK(plyErrors.size() == 0);
59 
60  // Valid ply, but triangular mesh is requested
61  plyErrors = testPlyString(validPly, true);
62  BOOST_CHECK(plyErrors.size() == 0);
63  for (auto plyerr : plyErrors) {
64  std::cout << plyerr << std::endl;
65  }
66 
67  // Test the tester - contains 3 errors
68  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 )";
69 
70  // Valid ply, but triangular mesh is requested
71  plyErrors = testPlyString(invalidPly);
72  BOOST_CHECK(plyErrors.size() == 3);
73  for (auto plyerr : plyErrors) {
74  std::cout << plyerr << std::endl;
75  }
76 }
77 
78 BOOST_AUTO_TEST_CASE(VisualizationConstruction) {
79  // this doesn't really test anything, other than conformance to the
80  // IVisualization interface
81  PlyVisualization ply;
82  ObjVisualization obj;
83 
84  IVisualization* vis;
85  vis = &ply;
86  std::cout << *vis << std::endl;
87  vis = &obj;
88  std::cout << *vis << std::endl;
89 }
90 
91 BOOST_AUTO_TEST_CASE(PlyOutputTest) {
92  PlyVisualization ply;
93  output_test_stream output;
94 
95  ply.vertex({0, 0, 0});
96 
97  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 )";
98 
99  output << ply;
100  BOOST_CHECK(output.is_equal(exp));
101 
102  ply.clear();
103  ply.vertex({0, 1, 0});
104 
105  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 )";
106 
107  output << ply;
108  BOOST_CHECK(output.is_equal(exp));
109 
110  ply.clear();
111  ply.line({0, 0, 1}, {1, 0, 0});
112 
113  output << ply;
114 
115  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 )";
116 
117  BOOST_CHECK(output.is_equal(exp));
118 
119  ply.clear();
120  ply.face({{1, 0, 0}, {1, 1, 0}, {0, 1, 0}});
121 
122  output << ply;
123 
124  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 )";
125 
126  BOOST_CHECK(output.is_equal(exp));
127 }
128 
129 BOOST_AUTO_TEST_CASE(ObjOutputTest) {
130  ObjVisualization obj;
131 
132  output_test_stream output;
133 
134  obj.vertex({1, 0, 0});
135 
136  output << obj;
137 
138  std::string exp = R"(v 1 0 0 )";
139 
140  BOOST_CHECK(output.is_equal(exp));
141 
142  obj.clear();
143  obj.face({{1, 0, 0}, {1, 1, 0}, {0, 1, 0}});
144  output << obj;
145 
146  exp = R"(v 1 0 0 v 1 1 0 v 0 1 0 f 1 2 3 )";
147 
148  BOOST_CHECK(output.is_equal(exp));
149 }
150 
151 BOOST_AUTO_TEST_SUITE_END()
152 } // namespace Test
153 } // namespace Acts
154