unittests_split_copy.cc 4.12 KB
Newer Older
1
2
3
4
5

#include <gtest/gtest.h>
#include <Unittests/unittests_common.hh>
#include <iostream>

6
7
namespace {

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
class OpenMeshSplitCopyTriangleMesh : public OpenMeshBase {

    protected:

        // This function is called before each test is run
        virtual void SetUp() {

            // Do some initial stuff with the member data here...
        }

        // This function is called after all tests are through
        virtual void TearDown() {

            // Do some final stuff with the member data here...
        }

    // Member already defined in OpenMeshBase
    //Mesh mesh_;
};

class OpenMeshSplitCopyPolyMesh : public OpenMeshBasePoly {

    protected:

        // This function is called before each test is run
        virtual void SetUp() {

            // Do some initial stuff with the member data here...
        }

        // This function is called after all tests are through
        virtual void TearDown() {

            // Do some final stuff with the member data here...
        }

    // Member already defined in OpenMeshBase
    //Mesh mesh_;
};

/*
 * ====================================================================
 * Define tests below
 * ====================================================================
 */

/* splits a face that has a property in a triangle mesh with split_copy
 * the property should be copied to the new faces
 */
TEST_F(OpenMeshSplitCopyTriangleMesh, SplitCopyTriangleMesh) {

  mesh_.clear();
60
  mesh_.request_face_status();
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

  // Add some vertices
  Mesh::VertexHandle vhandle[4];

  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
  vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
  vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
  vhandle[3] = mesh_.add_vertex(Mesh::Point(0.25, 0.25, 0));

  // Add one face
  std::vector<Mesh::VertexHandle> face_vhandles;

  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[0]);

  Mesh::FaceHandle fh = mesh_.add_face(face_vhandles);

  // Test setup:
  //  1 === 2
  //  |   /
  //  |  /
  //  | /
  //  0

  // set property
  OpenMesh::FPropHandleT<int> fprop_int;
  mesh_.add_property(fprop_int);
  mesh_.property(fprop_int, fh) = 999;
90
91
  //set internal property
  mesh_.status(fh).set_tagged(true);
92
93
94
95
96
97
98
99

  // split face with new vertex
  mesh_.split_copy(fh, vhandle[3]);

  // Check setup
  Mesh::FaceIter f_it = mesh_.faces_begin();
  Mesh::FaceIter f_end = mesh_.faces_end();
  for (; f_it != f_end; ++f_it)
100
  {
101
    EXPECT_EQ(999, mesh_.property(fprop_int, *f_it)) << "Different Property value";
102
103
    EXPECT_TRUE(mesh_.status(*f_it).tagged()) << "Different internal property value";
  }
104
105
106
107
108
109
110
111
}

/* splits a face that has a property in a poly mesh with split_copy
 * the property should be copied to the new faces
 */
TEST_F(OpenMeshSplitCopyPolyMesh, SplitCopyPolymesh) {

  mesh_.clear();
112
  mesh_.request_face_status();
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

  // Add some vertices
  Mesh::VertexHandle vhandle[5];

  vhandle[0] = mesh_.add_vertex(PolyMesh::Point(0, 0, 0));
  vhandle[1] = mesh_.add_vertex(PolyMesh::Point(0, 1, 0));
  vhandle[2] = mesh_.add_vertex(PolyMesh::Point(1, 1, 0));
  vhandle[3] = mesh_.add_vertex(PolyMesh::Point(1, 0, 0));
  vhandle[4] = mesh_.add_vertex(PolyMesh::Point(0.5, 0.5, 0));

  // Add face
  std::vector<Mesh::VertexHandle> face_vhandles;

  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[3]);

  PolyMesh::FaceHandle fh = mesh_.add_face(face_vhandles);

  // Test setup:
  //  1 === 2
  //  |     |
  //  |     |
  //  |     |
  //  0 === 3

  // set property
  OpenMesh::FPropHandleT<int> fprop_int;
  mesh_.add_property(fprop_int);
  mesh_.property(fprop_int, fh) = 999;
144
145
  //set internal property
  mesh_.status(fh).set_tagged(true);
146
147
148
149
150
151
152
153

  // split face with new vertex
  mesh_.split_copy(fh, vhandle[4]);

  // Check setup
  PolyMesh::FaceIter f_it = mesh_.faces_begin();
  PolyMesh::FaceIter f_end = mesh_.faces_end();
  for (; f_it != f_end; ++f_it)
154
  {
155
    EXPECT_EQ(999, mesh_.property(fprop_int, *f_it)) << "Different Property value";
156
157
    EXPECT_TRUE(mesh_.status(*f_it).tagged()) << "Different internal property value";
  }
158
159

}
160
}