Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mesh_cleanup_test.cc « mesh « draco « src « dracoenc « draco « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1051d193d876216f2676b4429a436aca70873834 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright 2016 The Draco Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "draco/mesh/mesh_cleanup.h"

#include "draco/core/draco_test_base.h"
#include "draco/core/vector_d.h"
#include "draco/mesh/triangle_soup_mesh_builder.h"

namespace draco {

class MeshCleanupTest : public ::testing::Test {};

TEST_F(MeshCleanupTest, TestDegneratedFaces) {
  // This test verifies that the mesh cleanup tools removes degenerated faces.
  TriangleSoupMeshBuilder mb;
  mb.Start(2);
  const int pos_att_id =
      mb.AddAttribute(GeometryAttribute::POSITION, 3, DT_FLOAT32);
  // clang-format off
  mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(0),
                               Vector3f(0.f, 0.f, 0.f).data(),
                               Vector3f(1.f, 0.f, 0.f).data(),
                               Vector3f(0.f, 1.f, 0.f).data());
  mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(1),
                               Vector3f(0.f, 1.f, 0.f).data(),
                               Vector3f(1.f, 0.f, 0.f).data(),
                               Vector3f(1.f, 0.f, 0.f).data());
  // clang-format on

  std::unique_ptr<Mesh> mesh = mb.Finalize();
  ASSERT_NE(mesh, nullptr) << "Failed to build the test mesh.";
  ASSERT_EQ(mesh->num_faces(), 2) << "Wrong number of faces in the input mesh.";
  MeshCleanupOptions cleanup_options;
  MeshCleanup cleanup;
  ASSERT_TRUE(cleanup(mesh.get(), cleanup_options))
      << "Failed to cleanup the mesh.";
  ASSERT_EQ(mesh->num_faces(), 1) << "Failed to remove degenerated faces.";
}

TEST_F(MeshCleanupTest, TestDegneratedFacesAndIsolatedVertices) {
  // This test verifies that the mesh cleanup tools removes degenerated faces
  // and isolated vertices.
  TriangleSoupMeshBuilder mb;
  mb.Start(2);
  const int pos_att_id =
      mb.AddAttribute(GeometryAttribute::POSITION, 3, DT_FLOAT32);
  // clang-format off
  mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(0),
                               Vector3f(0.f, 0.f, 0.f).data(),
                               Vector3f(1.f, 0.f, 0.f).data(),
                               Vector3f(0.f, 1.f, 0.f).data());
  mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(1),
                               Vector3f(10.f, 1.f, 0.f).data(),
                               Vector3f(1.f, 0.f, 0.f).data(),
                               Vector3f(10.f, 1.f, 0.f).data());
  // clang-format on

  std::unique_ptr<Mesh> mesh = mb.Finalize();
  ASSERT_NE(mesh, nullptr) << "Failed to build the test mesh.";
  ASSERT_EQ(mesh->num_faces(), 2) << "Wrong number of faces in the input mesh.";
  ASSERT_EQ(mesh->num_points(), 4)
      << "Wrong number of point ids in the input mesh.";
  const MeshCleanupOptions cleanup_options;
  MeshCleanup cleanup;
  ASSERT_TRUE(cleanup(mesh.get(), cleanup_options))
      << "Failed to cleanup the mesh.";
  ASSERT_EQ(mesh->num_faces(), 1) << "Failed to remove degenerated faces.";
  ASSERT_EQ(mesh->num_points(), 3)
      << "Failed to remove isolated attribute indices.";
}

TEST_F(MeshCleanupTest, TestAttributes) {
  TriangleSoupMeshBuilder mb;
  mb.Start(2);
  const int pos_att_id =
      mb.AddAttribute(GeometryAttribute::POSITION, 3, DT_FLOAT32);
  const int generic_att_id =
      mb.AddAttribute(GeometryAttribute::GENERIC, 2, DT_FLOAT32);
  // clang-format off
  mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(0),
                               Vector3f(0.f, 0.f, 0.f).data(),
                               Vector3f(1.f, 0.f, 0.f).data(),
                               Vector3f(0.f, 1.f, 0.f).data());
  mb.SetAttributeValuesForFace(generic_att_id, FaceIndex(0),
                               Vector2f(0.f, 0.f).data(),
                               Vector2f(0.f, 0.f).data(),
                               Vector2f(0.f, 0.f).data());

  mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(1),
                               Vector3f(10.f, 1.f, 0.f).data(),
                               Vector3f(1.f, 0.f, 0.f).data(),
                               Vector3f(10.f, 1.f, 0.f).data());
  mb.SetAttributeValuesForFace(generic_att_id, FaceIndex(1),
                               Vector2f(1.f, 0.f).data(),
                               Vector2f(1.f, 0.f).data(),
                               Vector2f(1.f, 0.f).data());
  // clang-format on

  std::unique_ptr<Mesh> mesh = mb.Finalize();
  ASSERT_NE(mesh, nullptr) << "Failed to build the test mesh.";
  ASSERT_EQ(mesh->num_faces(), 2) << "Wrong number of faces in the input mesh.";
  ASSERT_EQ(mesh->num_points(), 5)
      << "Wrong number of point ids in the input mesh.";
  ASSERT_EQ(mesh->attribute(1)->size(), 2u)
      << "Wrong number of generic attribute entries.";
  const MeshCleanupOptions cleanup_options;
  MeshCleanup cleanup;
  ASSERT_TRUE(cleanup(mesh.get(), cleanup_options))
      << "Failed to cleanup the mesh.";
  ASSERT_EQ(mesh->num_faces(), 1) << "Failed to remove degenerated faces.";
  ASSERT_EQ(mesh->num_points(), 3)
      << "Failed to remove isolated attribute indices.";
  ASSERT_EQ(mesh->attribute(0)->size(), 3u)
      << "Wrong number of unique positions after cleanup.";
  ASSERT_EQ(mesh->attribute(1)->size(), 1u)
      << "Wrong number of generic attribute entries after cleanup.";
}

}  // namespace draco