Commit 56351967 authored by Mike Kremer's avatar Mike Kremer

Finished ascii file reader which will be deprecated soon...

git-svn-id: http://www.openvolumemesh.org/svnrepo/OpenVolumeMesh/trunk@57 66977474-1d4b-4f09-8fe9-267525286df2
parent 62ee3e4d
......@@ -94,7 +94,7 @@ void SomeClass::someFunction() {
...
// Our two-dimensional integer vector class
typedef OpenVolumeMesh::Vec2ui Vec2ui;
typedef OpenVolumeMesh::Geometry::Vec2ui Vec2ui;
// Vec2ui stands for "two-dimensional vector of unsigned integers"
......@@ -125,7 +125,7 @@ void SomeClass::someFunction {
...
// Create mesh
typedef OpenVolumeMesh::Vec3d Vec3d;
typedef OpenVolumeMesh::Geometry::Vec3d Vec3d;
OpenVolumeMesh::PolyhedralMesh< Vec3d > myMesh;
// Fill mesh
......
......@@ -2,4 +2,124 @@
\page file_format File Format
%OpenVolumeMesh comes with a file format specification
that is implemented in the OpenVolumeMesh::IO::FileManager class.
As for now, the file format only supports plain text, but a support
for binary files is planned. Also the data type for vertices is restricted
to OpenVolumeMesh::Geometry::Vec3d and the serialization of the
properties is restricted to integral types for the moment.
A full generic support is also planned for the future. Find the
file format specification below.
\section file_spec File Format Specification
\verbatim
OVM ASCII # File header indicating whether data is
# coded as plain text or binary
Vertices # Indicate that all vertices are listed below
n_v # The total number of vertices (>= 0)
x_1 y_1 z_1 # Coordinate of the first vertex
...
x_n y_n z_n # Coordinate of the n_v'th vertex
# == Optional: ========================
Property "name" # A vertex property's name
type # The property's data type: Only integral
# types (bool, int, float, double, string)
p_1 # Property value for the first vertex
...
p_n # Property value for the last vertex
# Other properties may follow using
# the same scheme
# =====================================
Edges # Indicate that edges are specified below
n_e # The total number of edges (>= 0)
vs_1 vt_1 # First edge's source vertex index followed
... # by the first edge's target vertex index
vs_n vt_n # Last edge's source and target vertices
# == Optional: ========================
Property "name" # The same as for vertices
... # =====================================
Faces # Indicate that faces are specified below
n_f # The total number of faces (>= 0)
d he1_1 ... hed_1 # The first face's valence followed by its
... # incident half-edges' indices
d he1_n ... hed_n # Last face's definition
# == Optional: ========================
Property "name" # The same as for vertices
... # =====================================
Polyhedra # Indicates that polyhedra are specified below
n_c # The total number of cells (>= 0)
d hf1_1 ... hfd_1 # The first polyhedron's valence followed
... # by its incident half-faces' indices
d hf1_n ... hfd_n # The last polyhedron's definition
# == Optional: ========================
Property "name" # The same as for vertices
... # =====================================
\endverbatim
\section file_example A Simple Example File
\verbatim
OVM ASCII
Vertices
8
-1.0 -1.0 -1.0
1.0 -1.0 -1.0
1.0 1.0 -1.0
-1.0 1.0 -1.0
-1.0 -1.0 1.0
1.0 -1.0 1.0
1.0 1.0 1.0
-1.0 1.0 1.0
Property "Vertex Weights"
float
1.363
6.334
2.766
8.348
4.214
2.136
7.114
0.651
Edges
12
0 1
1 2
2 3
3 0
4 5
5 6
6 7
7 4
0 4
1 5
2 6
3 7
Property "Edge Tag"
bool
1
1
0
1
1
0
0
1
0
0
1
1
Faces
6
4 0 2 4 6
4 8 10 12 14
4 18 10 21 3
4 16 15 23 6
4 20 12 22 4
4 0 18 9 17
Polyhedra
1
6 1 2 5 6 9 10
\endverbatim
**/
......@@ -44,6 +44,7 @@
#define FILEMANAGER_HH_
#include <string>
#include <fstream>
namespace OpenVolumeMesh {
......@@ -106,6 +107,22 @@ public:
* \brief Test whether given file contains a hexahedral mesh
*/
bool isHexahedralMesh(const std::string& _filename) const;
private:
// Remove leading and trailing whitespaces
void trimString(std::string& _string) const;
// Get quoted text out of a string
void extractQuotedText(std::string& _string) const;
// Get a whole line from file
bool getCleanLine(std::istream& ifs, std::string& _string, bool _skipEmptyLines = true) const;
// Add and initialize property
template<class MeshT, class PropHandleT, typename PropT, typename IterT>
void initializeProperty(std::ifstream& _iff, MeshT& _mesh, const std::string& _s_tmp,
const IterT& _begin, const IterT& _end) const;
};
} // Namespace IO
......
OVM ASCII
Vertices
8
-1.0 -1.0 -1.0
1.0 -1.0 -1.0
1.0 1.0 -1.0
-1.0 1.0 -1.0
-1.0 -1.0 1.0
1.0 -1.0 1.0
1.0 1.0 1.0
-1.0 1.0 1.0
Property "Vertex Weights"
float
1.363
6.334
2.766
8.348
4.214
2.136
7.114
0.651
Edges
12
0 1
1 2
2 3
3 0
4 5
5 6
6 7
7 4
0 4
1 5
2 6
3 7
Property "Edge Tag"
bool
1
1
0
1
1
0
0
1
0
0
1
1
Faces
6
4 0 2 4 6
4 8 10 12 14
4 18 10 21 3
4 16 15 23 6
4 20 12 23 5
4 0 18 9 17
Polyhedra
1
6 1 2 5 6 9 10
OVM ASCII
Vertices
399
4.97203 0.504645 0.913112
......
......@@ -31,4 +31,16 @@ TEST_F(HexahedralMeshBase, LoadFile) {
EXPECT_EQ(288u, mesh_.n_cells());
}
TEST_F(PolyhedralMeshBase, LoadFileWithProps) {
OpenVolumeMesh::IO::FileManager fileManager;
ASSERT_TRUE(fileManager.readFile("Cube_with_props.ovm", mesh_));
EXPECT_EQ(8u, mesh_.n_vertices());
EXPECT_EQ(12u, mesh_.n_edges());
EXPECT_EQ(6u, mesh_.n_faces());
EXPECT_EQ(1u, mesh_.n_cells());
}
#endif // INCLUDE GUARD
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment