PLY Format
PLY or Stanford Polygon format defines a flexible and systematic scheme for storing graphical objects that are described as a collection of polygons.
A ".PLY" file is composed of 3 main mandatory sections plus optional ones thereafter. The first section is the header, then comes the data in either ASCII or binary.
Header
The header is a collection of carriage-return terminated line with at least the following:
- The first line must contain the lowercase directive: ply
This indicates that the file is intended to be read as a PLY file.
- The next line must be: format followed by either ascii, binary_little_endian or binary_big_endian and a version number.
This describes which format was used to store the information after the header.
- The next lines start off with a directive followed be attributes, these can be:
- comment followed by whatever text the author decided to use. This is ignored for reading
- element followed by a label and a number. The labels parsed are vertex and face, usually vertices are described before faces. The number corresponds to the number of entries in this file.
- property followed by a type and a label. An exception is the list type which is followed by 2 types, the first describing its length type and the second being the type stored in the list, and a label. These properties are tied to the element declared above them:
Types can be:
char or int8 |
8-bit integer |
1 |
uchar or uint8 |
8-bit unsigned integer |
1 |
short or int16 |
16-bit integer |
2 |
ushort or uint16 |
16-bit unsigned integer |
2 |
int or int32 |
32-bit integer |
4 |
uint or uint32 |
32-bit unsigned integer |
4 |
float or float32 |
single-precision floating number |
4 |
double or float64 |
double-precision floating number |
8 |
- The last line must contain the lowercase directive: endheader
ASCII data
Both vertex and face blocks are as they were described in the header with each property separated by a blank space and each line representing an element. The following example illustrates this:
ply
format ascii 1.0
element vertex 9
property float64 x
property float64 y
property float64 z
element face 8
property list uint32 int32 vertex_indices
end_header
-1.38639 1 1
-1.38639 1 1.11022e-016
-1.38639 2 1
-1.38639 2 1.66533e-016
-1.38639 -8.4892e-017 5.55112e-017
-1.38639 -1.46124e-016 1
-1.38639 -2.07357e-016 2
-1.38639 1 2
-1.38639 2 2
3 0 3 2
3 0 1 3
3 5 1 0
3 5 4 1
3 6 5 0
3 6 0 7
3 7 0 2
3 7 2 8
Binary data
The data blocks follow their description from the header so if the header is presented as such:
ply
format binary_little_endian 1.0
element vertex 9
property float64 x
property float64 y
property float64 z
element face 8
property list uint32 int32 vertex_indices
end_header
- The following data is 9 blocks of 24 bytes representing the vertices coordinates as double-precision floating numbers.
- After that come 8 blocks of 4 bytes followed by a number of packets of 4 bytes described in the initial 4. These are the indices of the polygons'vertices stated above.
|