File indexing completed on 2025-01-18 09:13:03
0001
0002
0003
0004
0005
0006
0007
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 namespace Acts::Test {
0024
0025 BOOST_AUTO_TEST_SUITE(Visualization)
0026
0027 BOOST_AUTO_TEST_CASE(Visualization3DTesterObj) {
0028
0029 std::string validObj = R"(# obj test file
0030 mtllib material.mtl
0031 usemtl material_a
0032 g rectangle
0033 vn 0 0 1
0034 vt 0 0 1
0035 v -15 -15 0
0036 v 15 -15 0
0037 v 15 15 0
0038 v -15 15 0
0039 f 1 2 3 4
0040 l 1 2
0041 l 2 3
0042 l 3 4
0043 l 4 1
0044 )";
0045
0046
0047 auto objErrors = testObjString(validObj);
0048 BOOST_CHECK(objErrors.empty());
0049
0050
0051 objErrors = testObjString(validObj, true);
0052 BOOST_CHECK_EQUAL(objErrors.size(), 1);
0053 for (const auto& objerr : objErrors) {
0054 std::cout << objerr << std::endl;
0055 }
0056
0057
0058 std::string invalidObj = R"(# obj test file
0059 mtllib material.mtl
0060 usemtl material_a
0061 x whatever
0062 g rectangle
0063 vn 0 0 1
0064 vt 0 0 1
0065 v -15 -15 0 23
0066 v 15 -15 0
0067 v 15. 15 0
0068 v -15 15. 0
0069 f 1 2 3. 4
0070 l 0 2
0071 l 2 3
0072 l 3 4
0073 l 4 1
0074 )";
0075
0076 objErrors = testObjString(invalidObj);
0077 BOOST_CHECK_EQUAL(objErrors.size(), 4);
0078 for (const auto& objerr : objErrors) {
0079 std::cout << objerr << std::endl;
0080 }
0081 }
0082
0083 BOOST_AUTO_TEST_CASE(Visualization3DTesterPly) {
0084
0085 std::string validPly = R"(ply
0086 format ascii 1.0
0087 comment made by Greg Turk
0088 comment this file is a cube
0089 element vertex 8
0090 property float x
0091 property float y
0092 property float z
0093 element face 6
0094 property list uchar int vertex_indices
0095 end_header
0096 0 0 0
0097 0 0 1
0098 0 1 1
0099 0 1 0
0100 1 0 0
0101 1 0 1
0102 1 1 1
0103 1 1 0
0104 4 0 1 2 3
0105 4 7 6 5 4
0106 4 0 4 5 1
0107 4 1 5 6 2
0108 4 2 6 7 3
0109 4 3 7 4 0
0110 )";
0111
0112
0113 auto plyErrors = testPlyString(validPly);
0114 BOOST_CHECK(plyErrors.empty());
0115
0116
0117 plyErrors = testPlyString(validPly, true);
0118 BOOST_CHECK(plyErrors.empty());
0119 for (const auto& plyerr : plyErrors) {
0120 std::cout << plyerr << std::endl;
0121 }
0122
0123
0124 std::string invalidPly = R"(ply
0125 format ascii 1.0
0126 comment made by Greg Turk
0127 comment this file is a cube
0128 element vertex 8
0129 property float x
0130 property float y
0131 property float z
0132 element face 6
0133 property list uchar int vertex_indices
0134 whatever i write here
0135 end_header
0136 0 0 0 0
0137 0 0 1
0138 0 1 1
0139 0 1 0
0140 1 0 0
0141 1 0 1
0142 1 1 1
0143 1 1 0
0144 4 0 1 2 3
0145 4 7 6 5 4
0146 4 0 4 5 1
0147 4 1 5 6
0148 4 2 6 7 3
0149 4 3 7 4 0
0150 )";
0151
0152
0153 plyErrors = testPlyString(invalidPly);
0154 BOOST_CHECK_EQUAL(plyErrors.size(), 3);
0155 for (const auto& plyerr : plyErrors) {
0156 std::cout << plyerr << std::endl;
0157 }
0158 }
0159
0160 BOOST_AUTO_TEST_CASE(Visualization3DConstruction) {
0161
0162
0163 PlyVisualization3D ply;
0164 ObjVisualization3D obj;
0165
0166 IVisualization3D* vis = nullptr;
0167 vis = &ply;
0168 std::cout << *vis << std::endl;
0169 vis = &obj;
0170 std::cout << *vis << std::endl;
0171 }
0172
0173 BOOST_AUTO_TEST_CASE(PlyOutputTest) {
0174 PlyVisualization3D ply;
0175 boost::test_tools::output_test_stream output;
0176
0177 ply.vertex({0, 0, 0});
0178
0179 std::string exp = R"(ply
0180 format ascii 1.0
0181 element vertex 1
0182 property float x
0183 property float y
0184 property float z
0185 property uchar red
0186 property uchar green
0187 property uchar blue
0188 element face 0
0189 property list uchar int vertex_index
0190 element edge 0
0191 property int vertex1
0192 property int vertex2
0193 property uchar red
0194 property uchar green
0195 property uchar blue
0196 end_header
0197 0 0 0 120 120 120
0198 )";
0199
0200 output << ply;
0201 BOOST_CHECK(output.is_equal(exp));
0202
0203 ply.clear();
0204 ply.vertex({0, 1, 0});
0205
0206 exp = R"(ply
0207 format ascii 1.0
0208 element vertex 1
0209 property float x
0210 property float y
0211 property float z
0212 property uchar red
0213 property uchar green
0214 property uchar blue
0215 element face 0
0216 property list uchar int vertex_index
0217 element edge 0
0218 property int vertex1
0219 property int vertex2
0220 property uchar red
0221 property uchar green
0222 property uchar blue
0223 end_header
0224 0 1 0 120 120 120
0225 )";
0226
0227 output << ply;
0228 BOOST_CHECK(output.is_equal(exp));
0229
0230 ply.clear();
0231 ply.line({0, 0, 1}, {1, 0, 0});
0232
0233 output << ply;
0234
0235 exp = R"(ply
0236 format ascii 1.0
0237 element vertex 2
0238 property float x
0239 property float y
0240 property float z
0241 property uchar red
0242 property uchar green
0243 property uchar blue
0244 element face 0
0245 property list uchar int vertex_index
0246 element edge 1
0247 property int vertex1
0248 property int vertex2
0249 property uchar red
0250 property uchar green
0251 property uchar blue
0252 end_header
0253 0 0 1 120 120 120
0254 1 0 0 120 120 120
0255 0 1 120 120 120
0256 )";
0257
0258 BOOST_CHECK(output.is_equal(exp));
0259
0260 ply.clear();
0261 ply.face({{1, 0, 0}, {1, 1, 0}, {0, 1, 0}});
0262
0263 output << ply;
0264
0265 exp = R"(ply
0266 format ascii 1.0
0267 element vertex 3
0268 property float x
0269 property float y
0270 property float z
0271 property uchar red
0272 property uchar green
0273 property uchar blue
0274 element face 1
0275 property list uchar int vertex_index
0276 element edge 0
0277 property int vertex1
0278 property int vertex2
0279 property uchar red
0280 property uchar green
0281 property uchar blue
0282 end_header
0283 1 0 0 120 120 120
0284 1 1 0 120 120 120
0285 0 1 0 120 120 120
0286 3 0 1 2
0287 )";
0288
0289 BOOST_CHECK(output.is_equal(exp));
0290 }
0291
0292 BOOST_AUTO_TEST_CASE(ObjOutputTest) {
0293 ObjVisualization3D obj;
0294
0295 boost::test_tools::output_test_stream output;
0296
0297 obj.vertex({1, 0, 0});
0298
0299 output << obj;
0300
0301 std::string exp = R"(usemtl material_120_120_120
0302 v 1 0 0
0303 )";
0304
0305 BOOST_CHECK(output.is_equal(exp));
0306
0307 obj.clear();
0308 obj.face({{1, 0, 0}, {1, 1, 0}, {0, 1, 0}});
0309 output << obj;
0310
0311 exp = R"(usemtl material_120_120_120
0312 v 1 0 0
0313 v 1 1 0
0314 v 0 1 0
0315 usemtl material_120_120_120
0316 f 1 2 3
0317 )";
0318
0319 BOOST_CHECK(output.is_equal(exp));
0320 }
0321
0322 BOOST_AUTO_TEST_CASE(ColorTests) {
0323 Color red{"#ff0000"};
0324 BOOST_CHECK_EQUAL(red, Color(255, 0, 0));
0325
0326 Color green{"#00ff00"};
0327 BOOST_CHECK_EQUAL(green, Color(0, 255, 0));
0328
0329 Color blue{"#0000ff"};
0330 BOOST_CHECK_EQUAL(blue, Color(0, 0, 255));
0331
0332 Color grey{"#808080"};
0333 BOOST_CHECK_EQUAL(grey, Color(128, 128, 128));
0334 BOOST_CHECK_EQUAL(grey, Color(std::array{128, 128, 128}));
0335 BOOST_CHECK_EQUAL(grey,
0336 Color(std::array{128 / 255.0, 128 / 255.0, 128 / 255.0}));
0337 BOOST_CHECK_EQUAL(grey, Color(128 / 255.0, 128 / 255.0, 128 / 255.0));
0338
0339 static_assert(Color{"#0000ff"} == Color(0, 0, 255));
0340 }
0341
0342 BOOST_AUTO_TEST_SUITE_END()
0343
0344 }