1 #include "unittests_common.hh" 3 #include <OpenVolumeMesh/FileManager/FileManager.hh> 7 using namespace Geometry;
13 ASSERT_TRUE(fileManager.
readFile(
"Cylinder.ovm", mesh_));
15 EXPECT_EQ(399u, mesh_.n_vertices());
16 EXPECT_EQ(1070u, mesh_.n_edges());
17 EXPECT_EQ(960u, mesh_.n_faces());
18 EXPECT_EQ(288u, mesh_.n_cells());
25 ASSERT_TRUE(fileManager.
readFile(
"NonManifold.ovm", mesh_));
27 EXPECT_EQ(12u, mesh_.n_vertices());
28 EXPECT_EQ(20u, mesh_.n_edges());
29 EXPECT_EQ(11u, mesh_.n_faces());
30 EXPECT_EQ(2u, mesh_.n_cells());
38 ASSERT_TRUE(fileManager.
readFile(
"Cylinder.ovm", mesh_));
40 EXPECT_EQ(399u, mesh_.n_vertices());
41 EXPECT_EQ(1070u, mesh_.n_edges());
42 EXPECT_EQ(960u, mesh_.n_faces());
43 EXPECT_EQ(288u, mesh_.n_cells());
50 ASSERT_TRUE(fileManager.
readFile(
"Cylinder.ovm", mesh_));
52 EXPECT_EQ(399u, mesh_.n_vertices());
53 EXPECT_EQ(1070u, mesh_.n_edges());
54 EXPECT_EQ(960u, mesh_.n_faces());
55 EXPECT_EQ(288u, mesh_.n_cells());
58 ASSERT_TRUE(fileManager.
writeFile(
"Cylinder.copy.ovm", mesh_));
62 ASSERT_TRUE(fileManager.
readFile(
"Cylinder.copy.ovm", mesh_));
64 EXPECT_EQ(399u, mesh_.n_vertices());
65 EXPECT_EQ(1070u, mesh_.n_edges());
66 EXPECT_EQ(960u, mesh_.n_faces());
67 EXPECT_EQ(288u, mesh_.n_cells());
74 ASSERT_TRUE(fileManager.
readFile(
"Cylinder.ovm", mesh_));
76 EXPECT_EQ(399u, mesh_.n_vertices());
77 EXPECT_EQ(1070u, mesh_.n_edges());
78 EXPECT_EQ(960u, mesh_.n_faces());
79 EXPECT_EQ(288u, mesh_.n_cells());
85 for(
unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
88 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
89 vprop[VertexHandle(i)] = i;
92 mesh_.set_persistent(hfprop);
93 mesh_.set_persistent(vprop);
96 ASSERT_TRUE(fileManager.
writeFile(
"Cylinder.copy.ovm", mesh_));
100 ASSERT_TRUE(fileManager.
readFile(
"Cylinder.copy.ovm", mesh_));
102 EXPECT_EQ(399u, mesh_.n_vertices());
103 EXPECT_EQ(1070u, mesh_.n_edges());
104 EXPECT_EQ(960u, mesh_.n_faces());
105 EXPECT_EQ(288u, mesh_.n_cells());
107 EXPECT_EQ(1u, mesh_.n_halfface_props());
108 EXPECT_EQ(1u, mesh_.n_vertex_props());
113 for(
unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
116 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
117 EXPECT_EQ(i, vprop2[VertexHandle(i)]);
125 ASSERT_TRUE(fileManager.
readFile(
"Cylinder.ovm", mesh_));
127 EXPECT_EQ(399u, mesh_.n_vertices());
128 EXPECT_EQ(1070u, mesh_.n_edges());
129 EXPECT_EQ(960u, mesh_.n_faces());
130 EXPECT_EQ(288u, mesh_.n_cells());
136 for(
unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
139 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
140 vprop[VertexHandle(i)] =
Vec2i(i, i);
143 mesh_.set_persistent(hfprop);
144 mesh_.set_persistent(vprop);
147 ASSERT_TRUE(fileManager.
writeFile(
"Cylinder.copy.ovm", mesh_));
151 ASSERT_TRUE(fileManager.
readFile(
"Cylinder.copy.ovm", mesh_));
153 EXPECT_EQ(399u, mesh_.n_vertices());
154 EXPECT_EQ(1070u, mesh_.n_edges());
155 EXPECT_EQ(960u, mesh_.n_faces());
156 EXPECT_EQ(288u, mesh_.n_cells());
158 EXPECT_EQ(1u, mesh_.n_halfface_props());
159 EXPECT_EQ(1u, mesh_.n_vertex_props());
164 for(
unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
166 EXPECT_DOUBLE_EQ((
double)i/2.0, hfprop2[hfh][0]);
167 EXPECT_DOUBLE_EQ((
double)i/2.0, hfprop2[hfh][1]);
168 EXPECT_DOUBLE_EQ((
double)i/2.0, hfprop2[hfh][2]);
170 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
172 EXPECT_EQ((
int)i, vprop2[vh][0]);
173 EXPECT_EQ((
int)i, vprop2[vh][1]);
181 ASSERT_TRUE(fileManager.
readFile(
"Cylinder.ovm", mesh_));
183 EXPECT_EQ(399u, mesh_.n_vertices());
184 EXPECT_EQ(1070u, mesh_.n_edges());
185 EXPECT_EQ(960u, mesh_.n_faces());
186 EXPECT_EQ(288u, mesh_.n_cells());
192 for(
unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
194 hfprop[hfh] =
Vec3d((
double)i/2.0, (
double)i/2.0, (
double)i/2.0);
196 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
198 vprop[vh] =
Vec2i(i, i);
201 mesh_.set_persistent(hfprop);
202 mesh_.set_persistent(vprop);
204 std::ofstream ofs1(
"hfVecPropTest");
205 std::ofstream ofs2(
"vVecPropTest");
207 hfprop.serialize(ofs1);
208 vprop.serialize(ofs2);
216 for(
unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
220 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
221 vprop[VertexHandle(i)] =
Vec2i(2*i, 2*i);
224 std::ifstream ifs1(
"hfVecPropTest");
225 std::ifstream ifs2(
"vVecPropTest");
227 hfprop.deserialize(ifs1);
228 vprop.deserialize(ifs2);
233 for(
unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
235 EXPECT_DOUBLE_EQ((
double)i/2.0, hfprop[hfh][0]);
236 EXPECT_DOUBLE_EQ((
double)i/2.0, hfprop[hfh][1]);
237 EXPECT_DOUBLE_EQ((
double)i/2.0, hfprop[hfh][2]);
239 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
241 EXPECT_EQ((
int)i, vprop[vh][0]);
242 EXPECT_EQ((
int)i, vprop[vh][1]);
250 ASSERT_TRUE(fileManager.
readFile(
"Cube_with_props.ovm", mesh_));
252 EXPECT_EQ(8u, mesh_.n_vertices());
253 EXPECT_EQ(12u, mesh_.n_edges());
254 EXPECT_EQ(6u, mesh_.n_faces());
255 EXPECT_EQ(1u, mesh_.n_cells());
257 EXPECT_EQ(1u, mesh_.n_vertex_props());
258 EXPECT_EQ(1u, mesh_.n_edge_props());
259 EXPECT_EQ(0u, mesh_.n_halfedge_props());
260 EXPECT_EQ(1u, mesh_.n_face_props());
261 EXPECT_EQ(1u, mesh_.n_halfface_props());
262 EXPECT_EQ(0u, mesh_.n_cell_props());
269 ASSERT_TRUE(fileManager.
readFile(
"Cube_with_props.ovm", mesh_));
271 EXPECT_EQ(8u, mesh_.n_vertices());
272 EXPECT_EQ(12u, mesh_.n_edges());
273 EXPECT_EQ(6u, mesh_.n_faces());
274 EXPECT_EQ(1u, mesh_.n_cells());
276 EXPECT_EQ(1u, mesh_.n_vertex_props());
277 EXPECT_EQ(1u, mesh_.n_edge_props());
278 EXPECT_EQ(0u, mesh_.n_halfedge_props());
279 EXPECT_EQ(1u, mesh_.n_face_props());
280 EXPECT_EQ(1u, mesh_.n_halfface_props());
281 EXPECT_EQ(0u, mesh_.n_cell_props());
283 ASSERT_TRUE(fileManager.
writeFile(
"Cube_with_props.copy.ovm", mesh_));
287 ASSERT_TRUE(fileManager.
readFile(
"Cube_with_props.copy.ovm", mesh_));
289 EXPECT_EQ(8u, mesh_.n_vertices());
290 EXPECT_EQ(12u, mesh_.n_edges());
291 EXPECT_EQ(6u, mesh_.n_faces());
292 EXPECT_EQ(1u, mesh_.n_cells());
294 EXPECT_EQ(1u, mesh_.n_vertex_props());
295 EXPECT_EQ(1u, mesh_.n_edge_props());
296 EXPECT_EQ(0u, mesh_.n_halfedge_props());
297 EXPECT_EQ(1u, mesh_.n_face_props());
298 EXPECT_EQ(1u, mesh_.n_halfface_props());
299 EXPECT_EQ(0u, mesh_.n_cell_props());
Read/Write mesh data from/to files.
bool writeFile(const std::string &_filename, const MeshT &_mesh) const
Write a mesh to a file.
bool readFile(const std::string &_filename, MeshT &_mesh, bool _topologyCheck=true, bool _computeBottomUpIncidences=true) const
Read a mesh from a file.
bool isHexahedralMesh(const std::string &_filename) const
Test whether given file contains a hexahedral mesh.