1 #include <gtest/gtest.h>
2 #include <Unittests/unittests_common.hh>
4 #include <OpenVolumeMesh/FileManager/FileManager.hh>
8 using namespace Geometry;
14 ASSERT_TRUE(fileManager.
readFile(
"Cylinder.ovm", mesh_));
16 EXPECT_EQ(399u, mesh_.n_vertices());
17 EXPECT_EQ(1070u, mesh_.n_edges());
18 EXPECT_EQ(960u, mesh_.n_faces());
19 EXPECT_EQ(288u, mesh_.n_cells());
26 ASSERT_TRUE(fileManager.
readFile(
"NonManifold.ovm", mesh_));
28 EXPECT_EQ(12u, mesh_.n_vertices());
29 EXPECT_EQ(20u, mesh_.n_edges());
30 EXPECT_EQ(11u, mesh_.n_faces());
31 EXPECT_EQ(2u, mesh_.n_cells());
39 ASSERT_TRUE(fileManager.
readFile(
"Cylinder.ovm", mesh_));
41 EXPECT_EQ(399u, mesh_.n_vertices());
42 EXPECT_EQ(1070u, mesh_.n_edges());
43 EXPECT_EQ(960u, mesh_.n_faces());
44 EXPECT_EQ(288u, mesh_.n_cells());
51 ASSERT_TRUE(fileManager.
readFile(
"Cylinder.ovm", mesh_));
53 EXPECT_EQ(399u, mesh_.n_vertices());
54 EXPECT_EQ(1070u, mesh_.n_edges());
55 EXPECT_EQ(960u, mesh_.n_faces());
56 EXPECT_EQ(288u, mesh_.n_cells());
59 ASSERT_TRUE(fileManager.
writeFile(
"Cylinder.copy.ovm", mesh_));
63 ASSERT_TRUE(fileManager.
readFile(
"Cylinder.copy.ovm", mesh_));
65 EXPECT_EQ(399u, mesh_.n_vertices());
66 EXPECT_EQ(1070u, mesh_.n_edges());
67 EXPECT_EQ(960u, mesh_.n_faces());
68 EXPECT_EQ(288u, mesh_.n_cells());
75 ASSERT_TRUE(fileManager.
readFile(
"Cylinder.ovm", mesh_));
77 EXPECT_EQ(399u, mesh_.n_vertices());
78 EXPECT_EQ(1070u, mesh_.n_edges());
79 EXPECT_EQ(960u, mesh_.n_faces());
80 EXPECT_EQ(288u, mesh_.n_cells());
86 for(
unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
87 hfprop[i] = (float)i/2.0f;
89 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
93 mesh_.set_persistent(hfprop);
94 mesh_.set_persistent(vprop);
97 ASSERT_TRUE(fileManager.
writeFile(
"Cylinder.copy.ovm", mesh_));
101 ASSERT_TRUE(fileManager.
readFile(
"Cylinder.copy.ovm", mesh_));
103 EXPECT_EQ(399u, mesh_.n_vertices());
104 EXPECT_EQ(1070u, mesh_.n_edges());
105 EXPECT_EQ(960u, mesh_.n_faces());
106 EXPECT_EQ(288u, mesh_.n_cells());
108 EXPECT_EQ(1u, mesh_.n_halfface_props());
109 EXPECT_EQ(1u, mesh_.n_vertex_props());
114 for(
unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
115 EXPECT_FLOAT_EQ((
float)i/2.0f, hfprop2[i]);
117 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
118 EXPECT_EQ(i, vprop2[i]);
126 ASSERT_TRUE(fileManager.
readFile(
"Cylinder.ovm", mesh_));
128 EXPECT_EQ(399u, mesh_.n_vertices());
129 EXPECT_EQ(1070u, mesh_.n_edges());
130 EXPECT_EQ(960u, mesh_.n_faces());
131 EXPECT_EQ(288u, mesh_.n_cells());
137 for(
unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
138 hfprop[i] =
Vec3d((
double)i/2.0, (
double)i/2.0, (
double)i/2.0);
140 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
141 vprop[i] =
Vec2i(i, i);
144 mesh_.set_persistent(hfprop);
145 mesh_.set_persistent(vprop);
148 ASSERT_TRUE(fileManager.
writeFile(
"Cylinder.copy.ovm", mesh_));
152 ASSERT_TRUE(fileManager.
readFile(
"Cylinder.copy.ovm", mesh_));
154 EXPECT_EQ(399u, mesh_.n_vertices());
155 EXPECT_EQ(1070u, mesh_.n_edges());
156 EXPECT_EQ(960u, mesh_.n_faces());
157 EXPECT_EQ(288u, mesh_.n_cells());
159 EXPECT_EQ(1u, mesh_.n_halfface_props());
160 EXPECT_EQ(1u, mesh_.n_vertex_props());
165 for(
unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
166 EXPECT_DOUBLE_EQ((
double)i/2.0, hfprop2[i][0]);
167 EXPECT_DOUBLE_EQ((
double)i/2.0, hfprop2[i][1]);
168 EXPECT_DOUBLE_EQ((
double)i/2.0, hfprop2[i][2]);
170 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
171 EXPECT_EQ((
int)i, vprop2[i][0]);
172 EXPECT_EQ((
int)i, vprop2[i][1]);
180 ASSERT_TRUE(fileManager.
readFile(
"Cylinder.ovm", mesh_));
182 EXPECT_EQ(399u, mesh_.n_vertices());
183 EXPECT_EQ(1070u, mesh_.n_edges());
184 EXPECT_EQ(960u, mesh_.n_faces());
185 EXPECT_EQ(288u, mesh_.n_cells());
191 for(
unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
192 hfprop[i] =
Vec3d((
double)i/2.0, (
double)i/2.0, (
double)i/2.0);
194 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
195 vprop[i] =
Vec2i(i, i);
198 mesh_.set_persistent(hfprop);
199 mesh_.set_persistent(vprop);
201 std::ofstream ofs1(
"hfVecPropTest");
202 std::ofstream ofs2(
"vVecPropTest");
204 hfprop.serialize(ofs1);
205 vprop.serialize(ofs2);
213 for(
unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
214 hfprop[i] =
Vec3d((
double)i/3.0, (
double)i/3.0, (
double)i/3.0);
217 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
218 vprop[i] =
Vec2i(2*i, 2*i);
221 std::ifstream ifs1(
"hfVecPropTest");
222 std::ifstream ifs2(
"vVecPropTest");
224 hfprop.deserialize(ifs1);
225 vprop.deserialize(ifs2);
230 for(
unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
231 EXPECT_DOUBLE_EQ((
double)i/2.0, hfprop[i][0]);
232 EXPECT_DOUBLE_EQ((
double)i/2.0, hfprop[i][1]);
233 EXPECT_DOUBLE_EQ((
double)i/2.0, hfprop[i][2]);
235 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
236 EXPECT_EQ((
int)i, vprop[i][0]);
237 EXPECT_EQ((
int)i, vprop[i][1]);
245 ASSERT_TRUE(fileManager.
readFile(
"Cube_with_props.ovm", mesh_));
247 EXPECT_EQ(8u, mesh_.n_vertices());
248 EXPECT_EQ(12u, mesh_.n_edges());
249 EXPECT_EQ(6u, mesh_.n_faces());
250 EXPECT_EQ(1u, mesh_.n_cells());
252 EXPECT_EQ(1u, mesh_.n_vertex_props());
253 EXPECT_EQ(1u, mesh_.n_edge_props());
254 EXPECT_EQ(0u, mesh_.n_halfedge_props());
255 EXPECT_EQ(1u, mesh_.n_face_props());
256 EXPECT_EQ(1u, mesh_.n_halfface_props());
257 EXPECT_EQ(0u, mesh_.n_cell_props());
264 ASSERT_TRUE(fileManager.
readFile(
"Cube_with_props.ovm", mesh_));
266 EXPECT_EQ(8u, mesh_.n_vertices());
267 EXPECT_EQ(12u, mesh_.n_edges());
268 EXPECT_EQ(6u, mesh_.n_faces());
269 EXPECT_EQ(1u, mesh_.n_cells());
271 EXPECT_EQ(1u, mesh_.n_vertex_props());
272 EXPECT_EQ(1u, mesh_.n_edge_props());
273 EXPECT_EQ(0u, mesh_.n_halfedge_props());
274 EXPECT_EQ(1u, mesh_.n_face_props());
275 EXPECT_EQ(1u, mesh_.n_halfface_props());
276 EXPECT_EQ(0u, mesh_.n_cell_props());
278 ASSERT_TRUE(fileManager.
writeFile(
"Cube_with_props.copy.ovm", mesh_));
282 ASSERT_TRUE(fileManager.
readFile(
"Cube_with_props.copy.ovm", mesh_));
284 EXPECT_EQ(8u, mesh_.n_vertices());
285 EXPECT_EQ(12u, mesh_.n_edges());
286 EXPECT_EQ(6u, mesh_.n_faces());
287 EXPECT_EQ(1u, mesh_.n_cells());
289 EXPECT_EQ(1u, mesh_.n_vertex_props());
290 EXPECT_EQ(1u, mesh_.n_edge_props());
291 EXPECT_EQ(0u, mesh_.n_halfedge_props());
292 EXPECT_EQ(1u, mesh_.n_face_props());
293 EXPECT_EQ(1u, mesh_.n_halfface_props());
294 EXPECT_EQ(0u, mesh_.n_cell_props());
bool readFile(const std::string &_filename, MeshT &_mesh, bool _topologyCheck=true, bool _computeBottomUpIncidences=true) const
Read a mesh from a file.
Property classes for the different entity types.
Read/Write mesh data from/to files.
bool isHexahedralMesh(const std::string &_filename) const
Test whether given file contains a hexahedral mesh.
bool writeFile(const std::string &_filename, const MeshT &_mesh) const
Write a mesh to a file.