Commit: 02c353d9c0ee48b9a0fb3da9f622ddbc20a6c03e Author: Sergey Sharybin Date: Tue May 26 10:23:29 2020 +0200 Branches: opensubdiv_compare https://developer.blender.org/rB02c353d9c0ee48b9a0fb3da9f622ddbc20a6c03e
OpenSubdiv: Add regression tests for mesh topology While this looks trivial it already allowed to catch issues in one of previous attempt to optimize memory usage. It will totally be useful for an upcoming refactor of face topology storage. =================================================================== M intern/opensubdiv/CMakeLists.txt M intern/opensubdiv/internal/topology/mesh_topology.cc A intern/opensubdiv/internal/topology/mesh_topology_test.cc =================================================================== diff --git a/intern/opensubdiv/CMakeLists.txt b/intern/opensubdiv/CMakeLists.txt index 3bd125f0a35..ea48a387bbd 100644 --- a/intern/opensubdiv/CMakeLists.txt +++ b/intern/opensubdiv/CMakeLists.txt @@ -119,3 +119,15 @@ else() endif() blender_add_lib(bf_intern_opensubdiv "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") + +# Tests. + +if(WITH_GTESTS AND WITH_OPENSUBDIV) + include(GTestTesting) + + add_definitions(${GFLAGS_DEFINES}) + add_definitions(${GLOG_DEFINES}) + add_definitions(-DBLENDER_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE}) + + BLENDER_SRC_GTEST(opensubdiv_mesh_topology_test "internal/topology/mesh_topology_test.cc" "${LIB};bf_intern_opensubdiv") +endif() diff --git a/intern/opensubdiv/internal/topology/mesh_topology.cc b/intern/opensubdiv/internal/topology/mesh_topology.cc index e4bd9ce5fb2..5fb06744e83 100644 --- a/intern/opensubdiv/internal/topology/mesh_topology.cc +++ b/intern/opensubdiv/internal/topology/mesh_topology.cc @@ -138,6 +138,7 @@ void MeshTopology::setEdgeSharpness(int edge_index, float sharpness) Edge &edge = edges_[edge_index]; assert(edge.isValid()); + (void)edge; if (sharpness < 1e-6f) { return; diff --git a/intern/opensubdiv/internal/topology/mesh_topology_test.cc b/intern/opensubdiv/internal/topology/mesh_topology_test.cc new file mode 100644 index 00000000000..e80dab38fa3 --- /dev/null +++ b/intern/opensubdiv/internal/topology/mesh_topology_test.cc @@ -0,0 +1,95 @@ +// Copyright 2020 Blender Foundation. All rights reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// Author: Sergey Sharybin + +#include "internal/topology/mesh_topology.h" +#include "testing/testing.h" + +namespace blender { +namespace opensubdiv { + +TEST(MeshTopology, TrivialVertexSharpness) +{ + MeshTopology mesh_topology; + + mesh_topology.setNumVertices(3); + + mesh_topology.setVertexSharpness(0, 0.1f); + mesh_topology.setVertexSharpness(1, 0.2f); + + EXPECT_EQ(mesh_topology.getVertexSharpness(0), 0.1f); + EXPECT_EQ(mesh_topology.getVertexSharpness(1), 0.2f); + EXPECT_EQ(mesh_topology.getVertexSharpness(2), 0.0f); +} + +TEST(MeshTopology, TrivialEdgeSharpness) +{ + MeshTopology mesh_topology; + + mesh_topology.setNumVertices(8); + mesh_topology.setNumEdges(3); + + mesh_topology.setEdgeVertexIndices(0, 0, 1); + mesh_topology.setEdgeVertexIndices(1, 1, 2); + mesh_topology.setEdgeVertexIndices(2, 2, 3); + + mesh_topology.setEdgeSharpness(0, 0.1f); + mesh_topology.setEdgeSharpness(2, 0.2f); + + EXPECT_EQ(mesh_topology.getEdgeSharpness(0), 0.1f); + EXPECT_EQ(mesh_topology.getEdgeSharpness(1), 0.0f); + EXPECT_EQ(mesh_topology.getEdgeSharpness(2), 0.2f); +} + +TEST(MeshTopology, TrivialFaceTopology) +{ + MeshTopology mesh_topology; + + mesh_topology.setNumFaces(3); + + { + mesh_topology.setNumFaceVertices(0, 4); + int vertex_indices[] = {0, 1, 2, 3}; + mesh_topology.setFaceVertexIndices(0, vertex_indices); + } + + { + mesh_topology.setNumFaceVertices(1, 3); + int vertex_indices[] = {4, 5, 6}; + mesh_topology.setFaceVertexIndices(1, vertex_indices); + } + + { + mesh_topology.setNumFaceVertices(2, 5); + int vertex_indices[] = {7, 8, 9, 10, 11}; + mesh_topology.setFaceVertexIndices(2, vertex_indices); + } + + EXPECT_EQ(mesh_topology.getNumFaceVertices(0), 4); + EXPECT_EQ(mesh_topology.getNumFaceVertices(1), 3); + EXPECT_EQ(mesh_topology.getNumFaceVertices(2), 5); + + EXPECT_TRUE(mesh_topology.isFaceVertexIndicesEqual(0, {{0, 1, 2, 3}})); + EXPECT_FALSE(mesh_topology.isFaceVertexIndicesEqual(0, {{10, 1, 2, 3}})); + EXPECT_FALSE(mesh_topology.isFaceVertexIndicesEqual(0, {{0, 1, 2}})); + + EXPECT_TRUE(mesh_topology.isFaceVertexIndicesEqual(1, {{4, 5, 6}})); + EXPECT_TRUE(mesh_topology.isFaceVertexIndicesEqual(2, {{7, 8, 9, 10, 11}})); +} + +} // namespace opensubdiv +} // namespace blender _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs