Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
unittests_split_copy.cc
1 
2 #include <gtest/gtest.h>
3 #include <Unittests/unittests_common.hh>
4 #include <iostream>
5 
6 namespace {
7 
8 class OpenMeshSplitCopyTriangleMesh : public OpenMeshBase {
9 
10  protected:
11 
12  // This function is called before each test is run
13  virtual void SetUp() {
14 
15  // Do some initial stuff with the member data here...
16  }
17 
18  // This function is called after all tests are through
19  virtual void TearDown() {
20 
21  // Do some final stuff with the member data here...
22  }
23 
24  // Member already defined in OpenMeshBase
25  //Mesh mesh_;
26 };
27 
28 class OpenMeshSplitCopyPolyMesh : public OpenMeshBasePoly {
29 
30  protected:
31 
32  // This function is called before each test is run
33  virtual void SetUp() {
34 
35  // Do some initial stuff with the member data here...
36  }
37 
38  // This function is called after all tests are through
39  virtual void TearDown() {
40 
41  // Do some final stuff with the member data here...
42  }
43 
44  // Member already defined in OpenMeshBase
45  //Mesh mesh_;
46 };
47 
48 /*
49  * ====================================================================
50  * Define tests below
51  * ====================================================================
52  */
53 
54 /* splits a face that has a property in a triangle mesh with split_copy
55  * the property should be copied to the new faces
56  */
57 TEST_F(OpenMeshSplitCopyTriangleMesh, SplitCopyTriangleMesh) {
58 
59  mesh_.clear();
60 
61  // Add some vertices
62  Mesh::VertexHandle vhandle[4];
63 
64  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
65  vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
66  vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
67  vhandle[3] = mesh_.add_vertex(Mesh::Point(0.25, 0.25, 0));
68 
69  // Add one face
70  std::vector<Mesh::VertexHandle> face_vhandles;
71 
72  face_vhandles.push_back(vhandle[2]);
73  face_vhandles.push_back(vhandle[1]);
74  face_vhandles.push_back(vhandle[0]);
75 
76  Mesh::FaceHandle fh = mesh_.add_face(face_vhandles);
77 
78  // Test setup:
79  // 1 === 2
80  // | /
81  // | /
82  // | /
83  // 0
84 
85  // set property
87  mesh_.add_property(fprop_int);
88  mesh_.property(fprop_int, fh) = 999;
89 
90  // split face with new vertex
91  mesh_.split_copy(fh, vhandle[3]);
92 
93  // Check setup
94  Mesh::FaceIter f_it = mesh_.faces_begin();
95  Mesh::FaceIter f_end = mesh_.faces_end();
96  for (; f_it != f_end; ++f_it)
97  EXPECT_EQ(999, mesh_.property(fprop_int, *f_it)) << "Different Property value";
98 }
99 
100 /* splits a face that has a property in a poly mesh with split_copy
101  * the property should be copied to the new faces
102  */
103 TEST_F(OpenMeshSplitCopyPolyMesh, SplitCopyPolymesh) {
104 
105  mesh_.clear();
106 
107  // Add some vertices
108  Mesh::VertexHandle vhandle[5];
109 
110  vhandle[0] = mesh_.add_vertex(PolyMesh::Point(0, 0, 0));
111  vhandle[1] = mesh_.add_vertex(PolyMesh::Point(0, 1, 0));
112  vhandle[2] = mesh_.add_vertex(PolyMesh::Point(1, 1, 0));
113  vhandle[3] = mesh_.add_vertex(PolyMesh::Point(1, 0, 0));
114  vhandle[4] = mesh_.add_vertex(PolyMesh::Point(0.5, 0.5, 0));
115 
116  // Add face
117  std::vector<Mesh::VertexHandle> face_vhandles;
118 
119  face_vhandles.push_back(vhandle[0]);
120  face_vhandles.push_back(vhandle[1]);
121  face_vhandles.push_back(vhandle[2]);
122  face_vhandles.push_back(vhandle[3]);
123 
124  PolyMesh::FaceHandle fh = mesh_.add_face(face_vhandles);
125 
126  // Test setup:
127  // 1 === 2
128  // | |
129  // | |
130  // | |
131  // 0 === 3
132 
133  // set property
134  OpenMesh::FPropHandleT<int> fprop_int;
135  mesh_.add_property(fprop_int);
136  mesh_.property(fprop_int, fh) = 999;
137 
138  // split face with new vertex
139  mesh_.split_copy(fh, vhandle[4]);
140 
141  // Check setup
142  PolyMesh::FaceIter f_it = mesh_.faces_begin();
143  PolyMesh::FaceIter f_end = mesh_.faces_end();
144  for (; f_it != f_end; ++f_it)
145  EXPECT_EQ(999, mesh_.property(fprop_int, *f_it)) << "Different Property value";
146 
147 }
148 }
VertexHandle split_copy(EdgeHandle _eh, const Point &_p)
Edge split (= 2-to-4 split)
Definition: TriMeshT.hh:280
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:115
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Definition: PolyMeshT.hh:236
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:139