Blender  V3.3
mesh_topology_test.cc
Go to the documentation of this file.
1 // Copyright 2020 Blender Foundation. All rights reserved.
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software Foundation,
15 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 //
17 // Author: Sergey Sharybin
18 
20 #include "testing/testing.h"
21 
22 namespace blender {
23 namespace opensubdiv {
24 
25 TEST(MeshTopology, TrivialVertexSharpness)
26 {
27  MeshTopology mesh_topology;
28 
29  mesh_topology.setNumVertices(3);
30  mesh_topology.finishResizeTopology();
31 
32  mesh_topology.setVertexSharpness(0, 0.1f);
33  mesh_topology.setVertexSharpness(1, 0.2f);
34 
35  EXPECT_EQ(mesh_topology.getVertexSharpness(0), 0.1f);
36  EXPECT_EQ(mesh_topology.getVertexSharpness(1), 0.2f);
37  EXPECT_EQ(mesh_topology.getVertexSharpness(2), 0.0f);
38 }
39 
40 TEST(MeshTopology, TrivialEdgeSharpness)
41 {
42  MeshTopology mesh_topology;
43 
44  mesh_topology.setNumVertices(8);
45  mesh_topology.setNumEdges(3);
46  mesh_topology.finishResizeTopology();
47 
48  mesh_topology.setEdgeVertexIndices(0, 0, 1);
49  mesh_topology.setEdgeVertexIndices(1, 1, 2);
50  mesh_topology.setEdgeVertexIndices(2, 2, 3);
51 
52  mesh_topology.setEdgeSharpness(0, 0.1f);
53  mesh_topology.setEdgeSharpness(2, 0.2f);
54 
55  EXPECT_EQ(mesh_topology.getEdgeSharpness(0), 0.1f);
56  EXPECT_EQ(mesh_topology.getEdgeSharpness(1), 0.0f);
57  EXPECT_EQ(mesh_topology.getEdgeSharpness(2), 0.2f);
58 }
59 
60 TEST(MeshTopology, TrivialFaceTopology)
61 {
62  MeshTopology mesh_topology;
63 
64  mesh_topology.setNumFaces(3);
65  mesh_topology.setNumFaceVertices(0, 4);
66  mesh_topology.setNumFaceVertices(1, 3);
67  mesh_topology.setNumFaceVertices(2, 5);
68  mesh_topology.finishResizeTopology();
69 
70  EXPECT_EQ(mesh_topology.getNumFaceVertices(0), 4);
71  EXPECT_EQ(mesh_topology.getNumFaceVertices(1), 3);
72  EXPECT_EQ(mesh_topology.getNumFaceVertices(2), 5);
73 
74  {
75  int vertex_indices[] = {0, 1, 2, 3};
76  mesh_topology.setFaceVertexIndices(0, 4, vertex_indices);
77  }
78 
79  {
80  int vertex_indices[] = {4, 5, 6};
81  mesh_topology.setFaceVertexIndices(1, 3, vertex_indices);
82  }
83 
84  {
85  int vertex_indices[] = {7, 8, 9, 10, 11};
86  mesh_topology.setFaceVertexIndices(2, 5, vertex_indices);
87  }
88 
89  EXPECT_TRUE(mesh_topology.isFaceVertexIndicesEqual(0, {{0, 1, 2, 3}}));
90  EXPECT_FALSE(mesh_topology.isFaceVertexIndicesEqual(0, {{10, 1, 2, 3}}));
91  EXPECT_FALSE(mesh_topology.isFaceVertexIndicesEqual(0, {{0, 1, 2}}));
92 
93  EXPECT_TRUE(mesh_topology.isFaceVertexIndicesEqual(1, {{4, 5, 6}}));
94  EXPECT_TRUE(mesh_topology.isFaceVertexIndicesEqual(2, {{7, 8, 9, 10, 11}}));
95 }
96 
97 } // namespace opensubdiv
98 } // namespace blender
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
void setEdgeSharpness(int edge_index, float sharpness)
float getEdgeSharpness(int edge_index) const
void setNumVertices(int num_vertices)
void setFaceVertexIndices(int face_index, int num_face_vertex_indices, const int *face_vertex_indices)
void setVertexSharpness(int vertex_index, float sharpness)
int getNumFaceVertices(int face_index) const
bool isFaceVertexIndicesEqual(int face_index, int num_expected_face_vertex_indices, const int *expected_face_vertex_indices) const
void setEdgeVertexIndices(int edge_index, int v1, int v2)
float getVertexSharpness(int vertex_index) const
void setNumFaceVertices(int face_index, int num_face_vertices)
TEST(MeshTopology, TrivialVertexSharpness)