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