Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:38

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2019 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/tools/output_test_stream.hpp>
0010 #include <boost/test/unit_test.hpp>
0011 
0012 #include "Acts/Definitions/Algebra.hpp"
0013 #include "Acts/Visualization/IVisualization3D.hpp"
0014 #include "Acts/Visualization/ObjVisualization3D.hpp"
0015 #include "Acts/Visualization/PlyVisualization3D.hpp"
0016 
0017 #include <iostream>
0018 #include <string>
0019 #include <vector>
0020 
0021 #include "Visualization3DTester.hpp"
0022 
0023 using boost::test_tools::output_test_stream;
0024 
0025 namespace Acts {
0026 namespace Test {
0027 
0028 BOOST_AUTO_TEST_SUITE(Visualization)
0029 
0030 BOOST_AUTO_TEST_CASE(Visualization3DTesterObj) {
0031   // Test the tester
0032   std::string validObj = R"(# obj test file
0033 mtllib material.mtl
0034 usemtl material_a
0035 g rectangle
0036 vn 0 0 1
0037 vt 0 0 1
0038 v -15 -15 0
0039 v 15 -15 0
0040 v 15 15 0
0041 v -15 15 0
0042 f 1 2 3 4
0043 l 1 2
0044 l 2 3
0045 l 3 4
0046 l 4 1
0047 )";
0048 
0049   // Valid obj
0050   auto objErrors = testObjString(validObj);
0051   BOOST_CHECK(objErrors.empty());
0052 
0053   // Valid obj, but triangular mesh is requested
0054   objErrors = testObjString(validObj, true);
0055   BOOST_CHECK_EQUAL(objErrors.size(), 1);
0056   for (const auto& objerr : objErrors) {
0057     std::cout << objerr << std::endl;
0058   }
0059 
0060   // Non-valid obj - it has 4 errors
0061   std::string invalidObj = R"(# obj test file
0062 mtllib material.mtl
0063 usemtl material_a
0064 x whatever
0065 g rectangle
0066 vn 0 0 1
0067 vt 0 0 1
0068 v -15 -15 0 23
0069 v 15 -15 0
0070 v 15. 15 0
0071 v -15 15. 0
0072 f 1 2 3. 4
0073 l 0 2
0074 l 2 3
0075 l 3 4
0076 l 4 1
0077 )";
0078 
0079   objErrors = testObjString(invalidObj);
0080   BOOST_CHECK_EQUAL(objErrors.size(), 4);
0081   for (const auto& objerr : objErrors) {
0082     std::cout << objerr << std::endl;
0083   }
0084 }
0085 
0086 BOOST_AUTO_TEST_CASE(Visualization3DTesterPly) {
0087   // Test the tester
0088   std::string validPly = R"(ply
0089 format ascii 1.0        
0090 comment made by Greg Turk
0091 comment this file is a cube
0092 element vertex 8
0093 property float x
0094 property float y
0095 property float z
0096 element face 6
0097 property list uchar int vertex_indices
0098 end_header
0099 0 0 0
0100 0 0 1
0101 0 1 1
0102 0 1 0
0103 1 0 0
0104 1 0 1
0105 1 1 1
0106 1 1 0
0107 4 0 1 2 3
0108 4 7 6 5 4
0109 4 0 4 5 1
0110 4 1 5 6 2
0111 4 2 6 7 3
0112 4 3 7 4 0
0113 )";
0114 
0115   // Valid ply
0116   auto plyErrors = testPlyString(validPly);
0117   BOOST_CHECK(plyErrors.empty());
0118 
0119   // Valid ply, but triangular mesh is requested
0120   plyErrors = testPlyString(validPly, true);
0121   BOOST_CHECK(plyErrors.empty());
0122   for (const auto& plyerr : plyErrors) {
0123     std::cout << plyerr << std::endl;
0124   }
0125 
0126   // Test the tester - contains 3 errors
0127   std::string invalidPly = R"(ply
0128 format ascii 1.0        
0129 comment made by Greg Turk
0130 comment this file is a cube
0131 element vertex 8
0132 property float x
0133 property float y
0134 property float z
0135 element face 6
0136 property list uchar int vertex_indices
0137 whatever i write here
0138 end_header
0139 0 0 0 0
0140 0 0 1
0141 0 1 1
0142 0 1 0
0143 1 0 0
0144 1 0 1
0145 1 1 1
0146 1 1 0
0147 4 0 1 2 3
0148 4 7 6 5 4
0149 4 0 4 5 1
0150 4 1 5 6
0151 4 2 6 7 3
0152 4 3 7 4 0
0153 )";
0154 
0155   // Valid ply, but triangular mesh is requested
0156   plyErrors = testPlyString(invalidPly);
0157   BOOST_CHECK_EQUAL(plyErrors.size(), 3);
0158   for (const auto& plyerr : plyErrors) {
0159     std::cout << plyerr << std::endl;
0160   }
0161 }
0162 
0163 BOOST_AUTO_TEST_CASE(Visualization3DConstruction) {
0164   // this doesn't really test anything, other than conformance to the
0165   // IVisualization3D interface
0166   PlyVisualization3D ply;
0167   ObjVisualization3D obj;
0168 
0169   IVisualization3D* vis = nullptr;
0170   vis = &ply;
0171   std::cout << *vis << std::endl;
0172   vis = &obj;
0173   std::cout << *vis << std::endl;
0174 }
0175 
0176 BOOST_AUTO_TEST_CASE(PlyOutputTest) {
0177   PlyVisualization3D ply;
0178   output_test_stream output;
0179 
0180   ply.vertex({0, 0, 0});
0181 
0182   std::string exp = R"(ply
0183 format ascii 1.0
0184 element vertex 1
0185 property float x
0186 property float y
0187 property float z
0188 property uchar red
0189 property uchar green
0190 property uchar blue
0191 element face 0
0192 property list uchar int vertex_index
0193 element edge 0
0194 property int vertex1
0195 property int vertex2
0196 property uchar red
0197 property uchar green
0198 property uchar blue
0199 end_header
0200 0 0 0 120 120 120
0201 )";
0202 
0203   output << ply;
0204   BOOST_CHECK(output.is_equal(exp));
0205 
0206   ply.clear();
0207   ply.vertex({0, 1, 0});
0208 
0209   exp = R"(ply
0210 format ascii 1.0
0211 element vertex 1
0212 property float x
0213 property float y
0214 property float z
0215 property uchar red
0216 property uchar green
0217 property uchar blue
0218 element face 0
0219 property list uchar int vertex_index
0220 element edge 0
0221 property int vertex1
0222 property int vertex2
0223 property uchar red
0224 property uchar green
0225 property uchar blue
0226 end_header
0227 0 1 0 120 120 120
0228 )";
0229 
0230   output << ply;
0231   BOOST_CHECK(output.is_equal(exp));
0232 
0233   ply.clear();
0234   ply.line({0, 0, 1}, {1, 0, 0});
0235 
0236   output << ply;
0237 
0238   exp = R"(ply
0239 format ascii 1.0
0240 element vertex 2
0241 property float x
0242 property float y
0243 property float z
0244 property uchar red
0245 property uchar green
0246 property uchar blue
0247 element face 0
0248 property list uchar int vertex_index
0249 element edge 1
0250 property int vertex1
0251 property int vertex2
0252 property uchar red
0253 property uchar green
0254 property uchar blue
0255 end_header
0256 0 0 1 120 120 120
0257 1 0 0 120 120 120
0258 0 1 120 120 120
0259 )";
0260 
0261   BOOST_CHECK(output.is_equal(exp));
0262 
0263   ply.clear();
0264   ply.face({{1, 0, 0}, {1, 1, 0}, {0, 1, 0}});
0265 
0266   output << ply;
0267 
0268   exp = R"(ply
0269 format ascii 1.0
0270 element vertex 3
0271 property float x
0272 property float y
0273 property float z
0274 property uchar red
0275 property uchar green
0276 property uchar blue
0277 element face 1
0278 property list uchar int vertex_index
0279 element edge 0
0280 property int vertex1
0281 property int vertex2
0282 property uchar red
0283 property uchar green
0284 property uchar blue
0285 end_header
0286 1 0 0 120 120 120
0287 1 1 0 120 120 120
0288 0 1 0 120 120 120
0289 3 0 1 2
0290 )";
0291 
0292   BOOST_CHECK(output.is_equal(exp));
0293 }
0294 
0295 BOOST_AUTO_TEST_CASE(ObjOutputTest) {
0296   ObjVisualization3D obj;
0297 
0298   output_test_stream output;
0299 
0300   obj.vertex({1, 0, 0});
0301 
0302   output << obj;
0303 
0304   std::string exp = R"(v 1 0 0
0305 )";
0306 
0307   BOOST_CHECK(output.is_equal(exp));
0308 
0309   obj.clear();
0310   obj.face({{1, 0, 0}, {1, 1, 0}, {0, 1, 0}});
0311   output << obj;
0312 
0313   exp = R"(v 1 0 0
0314 v 1 1 0
0315 v 0 1 0
0316 f 1 2 3
0317 )";
0318 
0319   BOOST_CHECK(output.is_equal(exp));
0320 }
0321 
0322 BOOST_AUTO_TEST_SUITE_END()
0323 }  // namespace Test
0324 }  // namespace Acts