Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
unittests_properties.cc
1 
2 #include <iostream>
3 
4 #include <gtest/gtest.h>
5 
6 #include "unittests_common.hh"
7 
8 #include <OpenVolumeMesh/Attribs/StatusAttrib.hh>
9 
10 using namespace OpenVolumeMesh;
11 using namespace Geometry;
12 
13 TEST_F(PolyhedralMeshBase, PropertySmartPointerTestSimple) {
14 
15  generatePolyhedralMesh(mesh_);
16 
17  for(int i = 0; i < 1; ++i) {
18 
19  VertexPropertyT<float> v_prop = mesh_.request_vertex_property<float>("SimpleTestProp");
20  }
21 }
22 
23 TEST_F(PolyhedralMeshBase, PropertySmartPointerTest1) {
24 
25  generatePolyhedralMesh(mesh_);
26 
27  EXPECT_EQ(12u, mesh_.n_vertices());
28 
29  VertexPropertyT<double> v_prop_d = mesh_.request_vertex_property<double>("MyVPropDbl");
30 
31  for(int i = 0; i < 1; ++i) {
32 
33  VertexPropertyT<float> v_prop = mesh_.request_vertex_property<float>("MyVProp");
34 
35  v_prop[0] = 1.4f;
36 
37  VertexPropertyT<float> v_prop2(v_prop);
38 
39  VertexPropertyT<float> v_prop3 = v_prop;
40 
41  EXPECT_EQ(12u, v_prop3->n_elements());
42 
43  EXPECT_EQ(2u, mesh_.n_vertex_props());
44 
45  VertexPropertyT<float> v_prop_duplicate = mesh_.request_vertex_property<float>("MyVProp");
46 
47  EXPECT_EQ(2u, mesh_.n_vertex_props());
48 
49  EXPECT_FLOAT_EQ(1.4f, v_prop3[0]);
50 
51  VertexPropertyT<std::string> v_prop_duplicate_2 = mesh_.request_vertex_property<std::string>("MyVProp");
52 
53  EXPECT_EQ(3u, mesh_.n_vertex_props());
54  }
55 
56  mesh_.set_persistent(v_prop_d);
57 
58  EXPECT_EQ(1u, mesh_.n_vertex_props());
59 
60  mesh_.add_vertex(Vec3d(0.0, 0.0, 0.0));
61 
62  EXPECT_EQ(13u, mesh_.n_vertices());
63 
64  VertexPropertyT<double> v_prop_d2 = mesh_.request_vertex_property<double>("MyVPropDbl");
65 
66  EXPECT_EQ(1u, mesh_.n_vertex_props());
67 
68  HalfEdgePropertyT<int> he_prop = mesh_.request_halfedge_property<int>("MyHEProp");
69 
70  EXPECT_EQ(40u, he_prop->n_elements());
71 
72  mesh_.add_edge(VertexHandle(0), VertexHandle(2));
73 
74  EXPECT_EQ(42u, he_prop->n_elements());
75 }
76 
77 TEST_F(HexahedralMeshBase, PropertySmartPointerPersistencyTest1) {
78 
79  generateHexahedralMesh(mesh_);
80 
81  for(int i = 0; i < 1; ++i) {
82 
83  VertexPropertyT<float> v_prop = mesh_.request_vertex_property<float>("FloatVProp");
84 
85  v_prop[0] = 24.5f;
86  v_prop[11] = 2.34f;
87 
88  mesh_.set_persistent(v_prop);
89  }
90 
91  VertexPropertyT<float> v_prop2 = mesh_.request_vertex_property<float>("FloatVProp");
92 
93  EXPECT_FLOAT_EQ(24.5f, v_prop2[0]);
94  EXPECT_FLOAT_EQ(2.34f, v_prop2[11]);
95 }
96 
97 TEST_F(HexahedralMeshBase, PropertySmartPointerPersistencyTest2) {
98 
99  generateHexahedralMesh(mesh_);
100 
101  for(int i = 0; i < 1; ++i) {
102 
103  VertexPropertyT<float> v_prop = mesh_.request_vertex_property<float>("FloatVProp");
104 
105  mesh_.set_persistent(v_prop);
106  }
107 
108  EXPECT_EQ(1u, mesh_.n_vertex_props());
109 
110  for(int i = 0; i < 1; ++i) {
111 
112  VertexPropertyT<float> v_prop = mesh_.request_vertex_property<float>("FloatVProp");
113 
114  EXPECT_EQ(1u, mesh_.n_vertex_props());
115 
116  mesh_.set_persistent(v_prop, false);
117  }
118 
119  EXPECT_EQ(0u, mesh_.n_vertex_props());
120 }
121 
122 TEST_F(HexahedralMeshBase, AnonymousPropertiesTest1) {
123 
124  generateHexahedralMesh(mesh_);
125 
126  CellPropertyT<float> c_prop = mesh_.request_cell_property<float>();
127  CellPropertyT<float> c_prop2 = c_prop;
128 
129  EXPECT_EQ(1u, mesh_.n_cell_props());
130 
131  mesh_.set_persistent(c_prop);
132 
133  EXPECT_EQ(1u, mesh_.n_cell_props());
134 
135  mesh_.set_persistent(c_prop2, false);
136 
137  EXPECT_EQ(1u, mesh_.n_cell_props());
138 }
139 
140 TEST_F(HexahedralMeshBase, AnonymousPropertiesTest2) {
141 
142  generateHexahedralMesh(mesh_);
143 
144  CellPropertyT<float> c_prop1 = mesh_.request_cell_property<float>();
145 
146  for(int i = 0; i < 1; ++i) {
147 
148  CellPropertyT<float> c_prop2 = mesh_.request_cell_property<float>();
149  EXPECT_EQ(2u, mesh_.n_cell_props());
150  }
151 
152  EXPECT_EQ(1u, mesh_.n_cell_props());
153 }
154 
155 TEST_F(PolyhedralMeshBase, StatusTest) {
156 
157  generatePolyhedralMesh(mesh_);
158 
159  EXPECT_EQ(12u, mesh_.n_vertices());
160 
161  StatusAttrib status(mesh_);
162 }
163 
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Definition: PolyMeshT.hh:236
Property classes for the different entity types.