diff --git a/test/mesh_test.cpp b/test/mesh_test.cpp index b9e5a54a7..90717cb1a 100644 --- a/test/mesh_test.cpp +++ b/test/mesh_test.cpp @@ -125,13 +125,12 @@ Polygons SquareHole(float xOffset = 0.0) { } // namespace -//TEST(MeshIO, ReadWrite) { -// Mesh mesh = ImportMesh("c:/users/baidhir/desktop/gyroidpuzzle.ply"); -// ExportMesh("c:/repos/manifold/test/data/gyroidpuzzle1.ply", mesh, {}); -// Mesh mesh_out = ImportMesh("c:/repos/manifold/test/data/gyroidpuzzle1.ply"); -// Identical(mesh, mesh_out); -//} -// +TEST(MeshIO, ReadWrite) { + Mesh mesh = ImportMesh("data/gyroidpuzzle.ply"); + ExportMesh("data/gyroidpuzzle1.ply", mesh, {}); + Mesh mesh_out = ImportMesh("data/gyroidpuzzle1.ply"); + Identical(mesh, mesh_out); +} /** * This tests that turning a mesh into a manifold and returning it to a mesh @@ -145,20 +144,20 @@ TEST(Manifold, GetMesh) { Identical(mesh_out, mesh_out2); } -//TEST(Manifold, Regression) { -// Manifold manifold(ImportMesh("c:/repos/manifold/test/data/gyroidpuzzle.ply")); -// EXPECT_TRUE(manifold.IsManifold()); -// -// Manifold manifold1 = manifold; -// manifold1.Translate(glm::vec3(5.0f)); -// int num_overlaps = manifold.NumOverlaps(manifold1); -// ASSERT_EQ(num_overlaps, 228677); -// -// Mesh mesh_out = manifold.GetMesh(); -// Manifold manifold2(mesh_out); -// Mesh mesh_out2 = manifold2.GetMesh(); -// // Identical(mesh_out, mesh_out2); -//} +TEST(Manifold, Regression) { + Manifold manifold(ImportMesh("data/gyroidpuzzle.ply")); + EXPECT_TRUE(manifold.IsManifold()); + + Manifold manifold1 = manifold; + manifold1.Translate(glm::vec3(5.0f)); + int num_overlaps = manifold.NumOverlaps(manifold1); + ASSERT_EQ(num_overlaps, 228677); + + Mesh mesh_out = manifold.GetMesh(); + Manifold manifold2(mesh_out); + Mesh mesh_out2 = manifold2.GetMesh(); + // Identical(mesh_out, mesh_out2); +} /** * ExpectMeshes performs a decomposition, so this test ensures that compose and @@ -314,33 +313,33 @@ TEST(Manifold, ManualSmooth) { // ExportMesh("sharpenedSphere.gltf", out, options); } -//TEST(Manifold, Csaszar) { -// Manifold csaszar = Manifold::Smooth(ImportMesh("c:/repos/manifold/test/data/Csaszar.ply")); -// csaszar.Refine(100); -// ExpectMeshes(csaszar, {{70000, 140000}}); -// auto prop = csaszar.GetProperties(); -// EXPECT_NEAR(prop.volume, 84699, 10); -// EXPECT_NEAR(prop.surfaceArea, 14796, 10); -// -// // const Mesh out = csaszar.GetMesh(); -// // ExportOptions options; -// // options.faceted = false; -// // options.mat.roughness = 0.1; -// -// // options.mat.vertColor.resize(csaszar.NumVert()); -// // MeshRelation rel = csaszar.GetMeshRelation(); -// // const glm::vec4 blue(0, 0, 1, 1); -// // const glm::vec4 yellow(1, 1, 0, 1); -// // for (int tri = 0; tri < csaszar.NumTri(); ++tri) { -// // for (int i : {0, 1, 2}) { -// // const glm::vec3& uvw = rel.barycentric[rel.triBary[tri].vertBary[i]]; -// // const float alpha = glm::min(uvw[0], glm::min(uvw[1], uvw[2])); -// // options.mat.vertColor[out.triVerts[tri][i]] = -// // glm::mix(yellow, blue, glm::smoothstep(0.0f, 0.2f, alpha)); -// // } -// // } -// // ExportMesh("smoothCsaszar.gltf", out, options); -//} +TEST(Manifold, Csaszar) { + Manifold csaszar = Manifold::Smooth(ImportMesh("data/Csaszar.ply")); + csaszar.Refine(100); + ExpectMeshes(csaszar, {{70000, 140000}}); + auto prop = csaszar.GetProperties(); + EXPECT_NEAR(prop.volume, 84699, 10); + EXPECT_NEAR(prop.surfaceArea, 14796, 10); + + // const Mesh out = csaszar.GetMesh(); + // ExportOptions options; + // options.faceted = false; + // options.mat.roughness = 0.1; + + // options.mat.vertColor.resize(csaszar.NumVert()); + // MeshRelation rel = csaszar.GetMeshRelation(); + // const glm::vec4 blue(0, 0, 1, 1); + // const glm::vec4 yellow(1, 1, 0, 1); + // for (int tri = 0; tri < csaszar.NumTri(); ++tri) { + // for (int i : {0, 1, 2}) { + // const glm::vec3& uvw = rel.barycentric[rel.triBary[tri].vertBary[i]]; + // const float alpha = glm::min(uvw[0], glm::min(uvw[1], uvw[2])); + // options.mat.vertColor[out.triVerts[tri][i]] = + // glm::mix(yellow, blue, glm::smoothstep(0.0f, 0.2f, alpha)); + // } + // } + // ExportMesh("smoothCsaszar.gltf", out, options); +} /** * These tests verify the calculation of a manifold's geometric properties. @@ -423,36 +422,36 @@ TEST(Manifold, Transform) { Identical(cube.GetMesh(), cube2.GetMesh()); } -// -//TEST(Manifold, MeshRelation) { -// std::vector input; -// std::map meshID2idx; -// -// input.push_back(ImportMesh("c:/repos/manifold/test/data/gyroidpuzzle.ply")); -// Manifold gyroid(input[0]); -// -// std::vector meshIDs = gyroid.GetMeshIDs(); -// EXPECT_EQ(meshIDs.size(), 1); -// meshID2idx[meshIDs[0]] = input.size() - 1; -// -// Related(gyroid, input, meshID2idx); -//} -//TEST(Manifold, MeshRelationRefine) { -// std::vector input; -// std::map meshID2idx; -// -// input.push_back(ImportMesh("c:/repos/manifold/test/data/Csaszar.ply")); -// Manifold csaszar(input[0]); -// -// std::vector meshIDs = csaszar.GetMeshIDs(); -// EXPECT_EQ(meshIDs.size(), 1); -// meshID2idx[meshIDs[0]] = input.size() - 1; -// -// Related(csaszar, input, meshID2idx); -// csaszar.Refine(4); -// Related(csaszar, input, meshID2idx); -//} +TEST(Manifold, MeshRelation) { + std::vector input; + std::map meshID2idx; + + input.push_back(ImportMesh("data/gyroidpuzzle.ply")); + Manifold gyroid(input[0]); + + std::vector meshIDs = gyroid.GetMeshIDs(); + EXPECT_EQ(meshIDs.size(), 1); + meshID2idx[meshIDs[0]] = input.size() - 1; + + Related(gyroid, input, meshID2idx); +} + +TEST(Manifold, MeshRelationRefine) { + std::vector input; + std::map meshID2idx; + + input.push_back(ImportMesh("data/Csaszar.ply")); + Manifold csaszar(input[0]); + + std::vector meshIDs = csaszar.GetMeshIDs(); + EXPECT_EQ(meshIDs.size(), 1); + meshID2idx[meshIDs[0]] = input.size() - 1; + + Related(csaszar, input, meshID2idx); + csaszar.Refine(4); + Related(csaszar, input, meshID2idx); +} /** * The very simplest Boolean operation test. @@ -709,43 +708,43 @@ TEST(Boolean, Sphere) { RelatedOp(sphere, sphere2, result); } -//TEST(Boolean, Gyroid) { -// Mesh gyroidpuzzle = ImportMesh("c:/repos/manifold/test/data/gyroidpuzzle.ply"); -// Manifold gyroid(gyroidpuzzle); -// -// Mesh gyroidpuzzle2 = gyroidpuzzle; -// std::transform(gyroidpuzzle.vertPos.begin(), gyroidpuzzle.vertPos.end(), -// gyroidpuzzle2.vertPos.begin(), -// [](const glm::vec3& v) { return v + glm::vec3(5.0f); }); -// Manifold gyroid2(gyroidpuzzle2); -// -// EXPECT_TRUE(gyroid.IsManifold()); -// EXPECT_TRUE(gyroid.MatchesTriNormals()); -// EXPECT_LE(gyroid.NumDegenerateTris(), 12); -// // ExportMesh("gyroidpuzzle1.gltf", gyroid.Extract(), {}); -// Manifold result = gyroid + gyroid2; -// ExportMesh("gyroidUnion.gltf", result.GetMesh(), {}); -// -// EXPECT_TRUE(result.IsManifold()); -// EXPECT_TRUE(result.MatchesTriNormals()); -// EXPECT_LE(result.NumDegenerateTris(), 33); -// EXPECT_EQ(result.Decompose().size(), 1); -// auto prop = result.GetProperties(); -// EXPECT_NEAR(prop.volume, 7692, 1); -// EXPECT_NEAR(prop.surfaceArea, 9642, 1); -// -// std::vector input; -// std::map meshID2idx; -// -// std::vector meshIDs = gyroid.GetMeshIDs(); -// EXPECT_EQ(meshIDs.size(), 1); -// meshID2idx[meshIDs[0]] = input.size(); -// input.push_back(gyroidpuzzle); -// -// meshIDs = gyroid2.GetMeshIDs(); -// EXPECT_EQ(meshIDs.size(), 1); -// meshID2idx[meshIDs[0]] = input.size(); -// input.push_back(gyroidpuzzle2); -// -// Related(result, input, meshID2idx); -//} \ No newline at end of file +TEST(Boolean, Gyroid) { + Mesh gyroidpuzzle = ImportMesh("data/gyroidpuzzle.ply"); + Manifold gyroid(gyroidpuzzle); + + Mesh gyroidpuzzle2 = gyroidpuzzle; + std::transform(gyroidpuzzle.vertPos.begin(), gyroidpuzzle.vertPos.end(), + gyroidpuzzle2.vertPos.begin(), + [](const glm::vec3& v) { return v + glm::vec3(5.0f); }); + Manifold gyroid2(gyroidpuzzle2); + + EXPECT_TRUE(gyroid.IsManifold()); + EXPECT_TRUE(gyroid.MatchesTriNormals()); + EXPECT_LE(gyroid.NumDegenerateTris(), 12); + // ExportMesh("gyroidpuzzle1.gltf", gyroid.Extract(), {}); + Manifold result = gyroid + gyroid2; + ExportMesh("gyroidUnion.gltf", result.GetMesh(), {}); + + EXPECT_TRUE(result.IsManifold()); + EXPECT_TRUE(result.MatchesTriNormals()); + EXPECT_LE(result.NumDegenerateTris(), 33); + EXPECT_EQ(result.Decompose().size(), 1); + auto prop = result.GetProperties(); + EXPECT_NEAR(prop.volume, 7692, 1); + EXPECT_NEAR(prop.surfaceArea, 9642, 1); + + std::vector input; + std::map meshID2idx; + + std::vector meshIDs = gyroid.GetMeshIDs(); + EXPECT_EQ(meshIDs.size(), 1); + meshID2idx[meshIDs[0]] = input.size(); + input.push_back(gyroidpuzzle); + + meshIDs = gyroid2.GetMeshIDs(); + EXPECT_EQ(meshIDs.size(), 1); + meshID2idx[meshIDs[0]] = input.size(); + input.push_back(gyroidpuzzle2); + + Related(result, input, meshID2idx); +} \ No newline at end of file diff --git a/test/polygon_test.cpp b/test/polygon_test.cpp index 4e52065a7..ebeec70ff 100644 --- a/test/polygon_test.cpp +++ b/test/polygon_test.cpp @@ -16,7 +16,6 @@ #include #include -#include #include "test.h" @@ -61,8 +60,8 @@ Polygons Turn180(Polygons polys) { } Polygons Duplicate(Polygons polys) { - float xMin = std::numeric_limits::infinity(); - float xMax = -std::numeric_limits::infinity(); + float xMin = 1.0 / 0.0; + float xMax = -1.0 / 0.0; int indexMax = 0; for (SimplePolygon &poly : polys) { for (PolyVert &vert : poly) {