9 #include <boost/test/tools/output_test_stream.hpp>
10 #include <boost/test/unit_test.hpp>
23 using boost::test_tools::output_test_stream;
28 BOOST_AUTO_TEST_SUITE(Visualization)
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
)";
36 BOOST_CHECK(objErrors.empty());
40 BOOST_CHECK(objErrors.size() == 1);
41 for (
const auto& objerr : objErrors) {
42 std::cout << objerr << std::endl;
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
)";
49 BOOST_CHECK(objErrors.size() == 4);
50 for (
const auto& objerr : objErrors) {
51 std::cout << objerr << std::endl;
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
)";
61 BOOST_CHECK(plyErrors.empty());
65 BOOST_CHECK(plyErrors.empty());
66 for (
const auto& plyerr : plyErrors) {
67 std::cout << plyerr << std::endl;
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
)";
75 BOOST_CHECK(plyErrors.size() == 3);
76 for (
const auto& plyerr : plyErrors) {
77 std::cout << plyerr << std::endl;
84 PlyVisualization3D ply;
85 ObjVisualization3D obj;
89 std::cout << *vis << std::endl;
91 std::cout << *vis << std::endl;
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
)";
103 BOOST_CHECK(output.is_equal(exp));
106 ply.vertex({0, 1, 0});
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
)";
111 BOOST_CHECK(output.is_equal(exp));
114 ply.line({0, 0, 1}, {1, 0, 0});
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
)";
120 BOOST_CHECK(output.is_equal(exp));
123 ply.face({{1, 0, 0}, {1, 1, 0}, {0, 1, 0}});
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
)";
129 BOOST_CHECK(output.is_equal(exp));
133 ObjVisualization3D obj;
135 output_test_stream output;
137 obj.vertex({1, 0, 0});
143 BOOST_CHECK(output.is_equal(exp));
146 obj.face({{1, 0, 0}, {1, 1, 0}, {0, 1, 0}});
149 exp = R"(v 1 0 0
v 1 1 0
v 0 1 0
f 1 2 3
)";
151 BOOST_CHECK(output.is_equal(exp));
154 BOOST_AUTO_TEST_SUITE_END()