Skip to content

Commit

Permalink
workspace: Upgrade tinyobjloader to latest commit (RobotLocomotion#14866
Browse files Browse the repository at this point in the history
)

Correct unit test based on tinyobj impl changes
  • Loading branch information
jwnimmer-tri authored Apr 7, 2021
1 parent 1b4cea2 commit 0b704d0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
52 changes: 36 additions & 16 deletions geometry/proximity/test/obj_to_surface_mesh_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,46 @@ GTEST_TEST(ObjToSurfaceMeshTest, ReadObjToSurfaceMesh) {
EXPECT_EQ(expect_vertices[i], surface.vertex(SurfaceVertexIndex(i)).r_MV());
}

// This test relies on the specific content of the file quad_cube.obj. The
// last section of quad_cube.obj describes the six square faces of the cube.
// We expect that each square is subdivided into two triangles. Note that
// vertex indices in the file quad_cube.obj are from 1 to 8, but tinyobj
// has vertex indices from 0 to 7. We assume that tinyobj subdivides a
// polygon into a triangle fan around the first vertex; polygon ABCDE...
// becomes triangles ABC, ACD, ADE, etc.
// TODO(SeanCurtis-TRI) Devise a formulation of this that is less sensitive
// to the details of the triangulation algorithm.
// This test is brittle. It depends on:
// - the exact construction of quad faces in quad_cube.obj.
// - the algorithm that tinyobj uses to triangulate n-gons into triangles.
// While we have 100% control over the former, we have no control over the
// latter. History has shown that the algorithm changes. In the past, it
// would create a fan around the *first* declared vertex, this current
// encoding creates a fan around the second. In other words, it's the
// difference between the following two triangulations
//
// ┌───┐ ┌───┐
// │╲ │ │ ╱│
// │ ╲ │ │ ╱ │
// │ ╲│ │╱ │
// └───┘ └───┘
//
// This test may fail with subsequent updates to the triangulation algorithm.
int expect_faces[12][3] {
{0, 1, 2}, {0, 2, 3}, // face 1 2 3 4 in quad_cube.obj
{4, 7, 6}, {4, 6, 5}, // face 5 8 7 6 in quad_cube.obj
{0, 4, 5}, {0, 5, 1}, // face 1 5 6 2 in quad_cube.obj
{1, 5, 6}, {1, 6, 2}, // face 2 6 7 3 in quad_cube.obj
{2, 6, 7}, {2, 7, 3}, // face 3 7 8 4 in quad_cube.obj
{4, 0, 3}, {4, 3, 7} // face 5 1 4 8 in quad_cube.obj
{0, 1, 3}, {1, 2, 3}, // face 1 2 3 4 in quad_cube.obj
{4, 7, 5}, {7, 6, 5}, // face 5 8 7 6 in quad_cube.obj
{0, 4, 1}, {4, 5, 1}, // face 1 5 6 2 in quad_cube.obj
{1, 5, 2}, {5, 6, 2}, // face 2 6 7 3 in quad_cube.obj
{2, 6, 3}, {6, 7, 3}, // face 3 7 8 4 in quad_cube.obj
{4, 0, 7}, {0, 3, 7} // face 5 1 4 8 in quad_cube.obj
};

auto face_equal = [](const SurfaceFace& f, const SurfaceFace& g) -> bool {
return std::make_tuple(f.vertex(0), f.vertex(1), f.vertex(2)) ==
std::make_tuple(g.vertex(0), g.vertex(1), g.vertex(2));
auto face_equal = [](const SurfaceFace& f,
const SurfaceFace& g) -> ::testing::AssertionResult {
const auto f_indices =
std::make_tuple(f.vertex(0), f.vertex(1), f.vertex(2));
const auto g_indices =
std::make_tuple(g.vertex(0), g.vertex(1), g.vertex(2));
if (f_indices == g_indices) return ::testing::AssertionSuccess();
return ::testing::AssertionFailure()
<< "\n Expected: " << f.vertex(0) << ", " << f.vertex(1) << ", "
<< f.vertex(2) << "\n Found: " << g.vertex(0) << ", " << g.vertex(1)
<< ", " << g.vertex(2);
};

for (int i = 0; i < 12; ++i) {
EXPECT_TRUE(face_equal(SurfaceFace(expect_faces[i]),
surface.element(SurfaceFaceIndex(i))));
Expand Down
4 changes: 2 additions & 2 deletions tools/workspace/tinyobjloader/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def tinyobjloader_repository(
github_archive(
name = name,
repository = "tinyobjloader/tinyobjloader",
commit = "9173980d1de273b17eba5e10eb189e8b4be89425",
sha256 = "fe06bf462bf386ea7f6bf34f94c78099c849df348d4a6df681707fba5b5b643c", # noqa
commit = "15bc2685b51612748bcfdb820bb4d42087a7dce1",
sha256 = "a5a4b72db1799621567e156853e92215d07a21b3d84098990e0dd79645cce647", # noqa
build_file = "@drake//tools/workspace/tinyobjloader:package.BUILD.bazel", # noqa
mirrors = mirrors,
patches = [
Expand Down

0 comments on commit 0b704d0

Please sign in to comment.