9 #include <boost/test/tools/output_test_stream.hpp>
10 #include <boost/test/unit_test.hpp>
21 using boost::test_tools::output_test_stream;
26 BOOST_AUTO_TEST_SUITE(Visualization)
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
)";
34 BOOST_CHECK(objErrors.size() == 0);
38 BOOST_CHECK(objErrors.size() == 1);
39 for (
auto objerr : objErrors) {
40 std::cout << objerr << std::endl;
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
)";
47 BOOST_CHECK(objErrors.size() == 4);
48 for (
auto objerr : objErrors) {
49 std::cout << objerr << std::endl;
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
)";
59 BOOST_CHECK(plyErrors.size() == 0);
63 BOOST_CHECK(plyErrors.size() == 0);
64 for (
auto plyerr : plyErrors) {
65 std::cout << plyerr << std::endl;
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
)";
73 BOOST_CHECK(plyErrors.size() == 3);
74 for (
auto plyerr : plyErrors) {
75 std::cout << plyerr << std::endl;
82 PlyVisualization3D ply;
83 ObjVisualization3D obj;
87 std::cout << *vis << std::endl;
89 std::cout << *vis << std::endl;
94 output_test_stream output;
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
)";
101 BOOST_CHECK(output.is_equal(exp));
104 ply.vertex({0, 1, 0});
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
)";
109 BOOST_CHECK(output.is_equal(exp));
112 ply.line({0, 0, 1}, {1, 0, 0});
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
)";
118 BOOST_CHECK(output.is_equal(exp));
121 ply.face({{1, 0, 0}, {1, 1, 0}, {0, 1, 0}});
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
)";
127 BOOST_CHECK(output.is_equal(exp));
131 ObjVisualization3D obj;
133 output_test_stream output;
135 obj.vertex({1, 0, 0});
139 std::string exp = R"(v 1 0 0
)";
141 BOOST_CHECK(output.is_equal(exp));
144 obj.face({{1, 0, 0}, {1, 1, 0}, {0, 1, 0}});
147 exp = R"(v 1 0 0
v 1 1 0
v 0 1 0
f 1 2 3
)";
149 BOOST_CHECK(output.is_equal(exp));
152 BOOST_AUTO_TEST_SUITE_END()