A
Alexander Schmidt
Hi,
I am not very familiar with C++ programming, so before I do a dirty hack I
ask for a more elegant solution (but only the usage of STL is allowed, no
special libs).
So I need to read a file in OFF format and store the values read in some
file format, I suppose in arrays of floats or ints would be meaningful:
My general idea:
- Open the file
- Read line 1 and check if OFF file
- Read line 2 and store values for Nv and Nf (how to tokenize that ?
searching for spaces ? is there sth. like a StringTokenizer in C++ ?)
- Read the vertex table (again: I would tokenize through searching for
strings -is there a more elegant approach ?)
- Read the faces (same question as above)
Thanks for your help !
---
The OFF format can be described as:
We use a very simple ASCII format for representing polygonal meshes. It
consists of a short header, a table of vertex coordinates, and a table of
polygons (all triangles) stored as indices into the vertex table.
a.. header
The header includes the number of vertices Nv, the number of faces
(triangles) Nf, and the number of edges which is assumed to be always 0,
i.e., there is only a vertex and a face table.
OFF
Nv Nf 0
b.. vertex table
The vertex table stored the geometry information. It contains Nv lines
with x y z coordinates for every vertex, i.e.
x[0] y[0] z[0]
...
x[Nv-1] y[Nv-1] z[Nv-1]
c.. table of faces/triangles
This table contains the connectivity information stored in Nf lines. Every
line describes a face/polygon, the first number denotes the number of
vertices, it is assumed to be always 3, i.e. the the meshes consist of
triangles only! Then the following 3 numbers are indices into the vertex
table (starting with index 0), i.e.
3 i0[0] i1[0] i2[0]
...
3 i0[Nf-1] i1[Nf-1] i2[Nf-1]
I am not very familiar with C++ programming, so before I do a dirty hack I
ask for a more elegant solution (but only the usage of STL is allowed, no
special libs).
So I need to read a file in OFF format and store the values read in some
file format, I suppose in arrays of floats or ints would be meaningful:
My general idea:
- Open the file
- Read line 1 and check if OFF file
- Read line 2 and store values for Nv and Nf (how to tokenize that ?
searching for spaces ? is there sth. like a StringTokenizer in C++ ?)
- Read the vertex table (again: I would tokenize through searching for
strings -is there a more elegant approach ?)
- Read the faces (same question as above)
Thanks for your help !
---
The OFF format can be described as:
We use a very simple ASCII format for representing polygonal meshes. It
consists of a short header, a table of vertex coordinates, and a table of
polygons (all triangles) stored as indices into the vertex table.
a.. header
The header includes the number of vertices Nv, the number of faces
(triangles) Nf, and the number of edges which is assumed to be always 0,
i.e., there is only a vertex and a face table.
OFF
Nv Nf 0
b.. vertex table
The vertex table stored the geometry information. It contains Nv lines
with x y z coordinates for every vertex, i.e.
x[0] y[0] z[0]
...
x[Nv-1] y[Nv-1] z[Nv-1]
c.. table of faces/triangles
This table contains the connectivity information stored in Nf lines. Every
line describes a face/polygon, the first number denotes the number of
vertices, it is assumed to be always 3, i.e. the the meshes consist of
triangles only! Then the following 3 numbers are indices into the vertex
table (starting with index 0), i.e.
3 i0[0] i1[0] i2[0]
...
3 i0[Nf-1] i1[Nf-1] i2[Nf-1]