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) {
89 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
90 vprop[VertexHandle(i)] = 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) {
117 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
118 EXPECT_EQ(i, vprop2[VertexHandle(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) {
140 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
141 vprop[VertexHandle(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) {
167 EXPECT_DOUBLE_EQ((
double)i/2.0, hfprop2[hfh][0]);
168 EXPECT_DOUBLE_EQ((
double)i/2.0, hfprop2[hfh][1]);
169 EXPECT_DOUBLE_EQ((
double)i/2.0, hfprop2[hfh][2]);
171 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
173 EXPECT_EQ((
int)i, vprop2[vh][0]);
174 EXPECT_EQ((
int)i, vprop2[vh][1]);
182 ASSERT_TRUE(fileManager.
readFile(
"Cylinder.ovm", mesh_));
184 EXPECT_EQ(399u, mesh_.n_vertices());
185 EXPECT_EQ(1070u, mesh_.n_edges());
186 EXPECT_EQ(960u, mesh_.n_faces());
187 EXPECT_EQ(288u, mesh_.n_cells());
193 for(
unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
195 hfprop[hfh] =
Vec3d((
double)i/2.0, (
double)i/2.0, (
double)i/2.0);
197 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
199 vprop[vh] =
Vec2i(i, i);
202 mesh_.set_persistent(hfprop);
203 mesh_.set_persistent(vprop);
205 std::ofstream ofs1(
"hfVecPropTest");
206 std::ofstream ofs2(
"vVecPropTest");
208 hfprop.serialize(ofs1);
209 vprop.serialize(ofs2);
217 for(
unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
221 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
222 vprop[VertexHandle(i)] =
Vec2i(2*i, 2*i);
225 std::ifstream ifs1(
"hfVecPropTest");
226 std::ifstream ifs2(
"vVecPropTest");
228 hfprop.deserialize(ifs1);
229 vprop.deserialize(ifs2);
234 for(
unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
236 EXPECT_DOUBLE_EQ((
double)i/2.0, hfprop[hfh][0]);
237 EXPECT_DOUBLE_EQ((
double)i/2.0, hfprop[hfh][1]);
238 EXPECT_DOUBLE_EQ((
double)i/2.0, hfprop[hfh][2]);
240 for(
unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
242 EXPECT_EQ((
int)i, vprop[vh][0]);
243 EXPECT_EQ((
int)i, vprop[vh][1]);
251 ASSERT_TRUE(fileManager.
readFile(
"Cube_with_props.ovm", mesh_));
253 EXPECT_EQ(8u, mesh_.n_vertices());
254 EXPECT_EQ(12u, mesh_.n_edges());
255 EXPECT_EQ(6u, mesh_.n_faces());
256 EXPECT_EQ(1u, mesh_.n_cells());
258 EXPECT_EQ(1u, mesh_.n_vertex_props());
259 EXPECT_EQ(1u, mesh_.n_edge_props());
260 EXPECT_EQ(0u, mesh_.n_halfedge_props());
261 EXPECT_EQ(1u, mesh_.n_face_props());
262 EXPECT_EQ(1u, mesh_.n_halfface_props());
263 EXPECT_EQ(0u, mesh_.n_cell_props());
270 ASSERT_TRUE(fileManager.
readFile(
"Cube_with_props.ovm", mesh_));
272 EXPECT_EQ(8u, mesh_.n_vertices());
273 EXPECT_EQ(12u, mesh_.n_edges());
274 EXPECT_EQ(6u, mesh_.n_faces());
275 EXPECT_EQ(1u, mesh_.n_cells());
277 EXPECT_EQ(1u, mesh_.n_vertex_props());
278 EXPECT_EQ(1u, mesh_.n_edge_props());
279 EXPECT_EQ(0u, mesh_.n_halfedge_props());
280 EXPECT_EQ(1u, mesh_.n_face_props());
281 EXPECT_EQ(1u, mesh_.n_halfface_props());
282 EXPECT_EQ(0u, mesh_.n_cell_props());
284 ASSERT_TRUE(fileManager.
writeFile(
"Cube_with_props.copy.ovm", mesh_));
288 ASSERT_TRUE(fileManager.
readFile(
"Cube_with_props.copy.ovm", mesh_));
290 EXPECT_EQ(8u, mesh_.n_vertices());
291 EXPECT_EQ(12u, mesh_.n_edges());
292 EXPECT_EQ(6u, mesh_.n_faces());
293 EXPECT_EQ(1u, mesh_.n_cells());
295 EXPECT_EQ(1u, mesh_.n_vertex_props());
296 EXPECT_EQ(1u, mesh_.n_edge_props());
297 EXPECT_EQ(0u, mesh_.n_halfedge_props());
298 EXPECT_EQ(1u, mesh_.n_face_props());
299 EXPECT_EQ(1u, mesh_.n_halfface_props());
300 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.
bool isHexahedralMesh(const std::string &_filename) const
Test whether given file contains a hexahedral mesh.
Read/Write mesh data from/to files.
bool writeFile(const std::string &_filename, const MeshT &_mesh) const
Write a mesh to a file.