The data starts on the byte after the line end of end_header. It holds the
elements in the order the header declares them: every
item of the first element, then every item of the second, and so on. Each item holds its
properties in the order they were declared. The format line chooses how the
values are written.
Order of the data
| Level | Order |
|---|---|
| Elements | As the element lines appear in the header |
| Items of one element | From the first to the last; the count is on the element line, and items are numbered from 0 |
| Properties of one item | As the property lines appear under the element |
| A list property | Its count, then that many items |
Nothing marks where one element ends and the next begins. A reader has to read, or step over, every property of every item, which the header makes possible.
ascii
Values are written as decimal numbers separated by white space, and each item
takes one line: a vertex is one line and a face is one line. Turk’s ply.c
reads a line for each item (it splits the line into words and takes the item’s values
from them in order), and Python’s plyfile does the same and raises an
error for a line with too few or too many numbers. A file that splits an item over
lines, or puts two items on a line, is therefore not readable by those two. Some
other readers go by white space alone; the explorer does, and marks every item that
breaks the rule in the tree and lists each one, with its offset, in the Problems
section of the Overview instead of refusing the file.
Numbers use the C locale: a full stop as the
decimal point and no thousands separators. Floating-point values may use an exponent,
as in 1.5e-3. Some writers, such as PCL for the invalid points of an
organised cloud, write nan or inf (also -nan,
-inf, NaN); the explorer reads these as the values they
stand for in a float property, and reports them in an integer one.
ply
format ascii 1.0
element vertex 3
property float x
property float y
property float z
element face 1
property list uchar int vertex_indices
end_header
0 0 0
1 0 0
0 1 0
3 0 1 2
binary_little_endian and binary_big_endian
Each value is stored in the size of its type,
packed one after another with no separators, no padding and no alignment. Integers
are two’s complement and floating-point values are IEEE 754. The two binary encodings
differ only in byte order: binary_little_endian stores the least
significant byte first, as x86 and ARM processors do, and
binary_big_endian the most significant byte first.
A list stores its count in the count type, then its items in the item type, so the size of an item of an element with a list property varies from one item to the next.
A property string (Turk’s library only, see
Scalar types) is stored as a four-byte integer
holding the length including the zero byte, the characters, and a zero byte; in ASCII it is
a word or text in double quotes. An element with a string, like one with a list, has items
of different sizes. A range grid (range_grid)
is a list element with one item for each cell of the scan.
Worked example
The same triangle as above in binary_little_endian. Its header is 169
bytes long, ending with the line feed after end_header, so the data
starts at offset 169 (A9) and the file is 218 bytes.
ply
format binary_little_endian 1.0
element vertex 3
property float x
property float y
property float z
element face 1
property list uchar int vertex_indices
end_header
| Offset | Size | Type | Bytes | Meaning |
|---|---|---|---|---|
| 169 | 4 | float | 00 00 00 00 | Vertex 0, x = 0.0 |
| 173 | 4 | float | 00 00 00 00 | Vertex 0, y = 0.0 |
| 177 | 4 | float | 00 00 00 00 | Vertex 0, z = 0.0 |
| 181 | 4 | float | 00 00 80 3F | Vertex 1, x = 1.0 |
| 185 | 4 | float | 00 00 00 00 | Vertex 1, y = 0.0 |
| 189 | 4 | float | 00 00 00 00 | Vertex 1, z = 0.0 |
| 193 | 4 | float | 00 00 00 00 | Vertex 2, x = 0.0 |
| 197 | 4 | float | 00 00 80 3F | Vertex 2, y = 1.0 |
| 201 | 4 | float | 00 00 00 00 | Vertex 2, z = 0.0 |
| 205 | 1 | uchar | 03 | Face 0, list count: 3 vertices |
| 206 | 4 | int | 00 00 00 00 | Face 0, vertex 0 |
| 210 | 4 | int | 01 00 00 00 | Face 0, vertex 1 |
| 214 | 4 | int | 02 00 00 00 | Face 0, vertex 2 |
In binary_big_endian the bytes of each value are reversed: 1.0 becomes
3F 80 00 00 and vertex number 1 becomes 00 00 00 01. The
header is three bytes shorter, 166 bytes, since big has three letters
fewer than little.
Damaged and unusual data
Nothing in a PLY file records its own length, so damage shows only when the data and the header disagree. These are the cases the explorer meets, and what it does.
| Case | What it means | In the explorer |
|---|---|---|
| Binary data too short | The header declares more items than the bytes hold (an interrupted download or a cut file) | Reads the whole items that are there, reports the shortfall, still draws them |
| Bytes after the last element | Padding, a second object appended, or a header that undercounts | Shown as Extra bytes, with a problem |
| A list count that is negative or larger than the file | A signed count type holding a negative number, or garbage in the count | Stops at that item, shows the rest as Unreadable bytes |
| Text that is not a number, or ends early (ASCII) | A word where a number belongs, or fewer numbers than the header declares | Names the word and its offset; items before it are kept |
| An ASCII value outside its type | 300 in a uchar, or 1.5 in an int | A problem on that value; the value is shown as written |
| An element with no properties | Its items take no bytes at all | A problem; the element is not listed |
| Face vertex numbers past the vertex count | The faces refer to vertices that do not exist | One problem with the number of corners; those triangles are not drawn |
| NaN or infinite coordinates | Invalid points kept in an organised point cloud | Kept in the numbering, drawn at the middle of the model, counted in the overview |
Types of 64 bits (int64) or other names | Not among the eight PLY scalar types, so no reader can know their size from the format alone | The file is shown as far as its header, with the unknown type named |
A header that has a carriage return as its only line end (an old Mac file) cannot be
told apart from a header ending in carriage return and line feed when the binary data
starts with 0A; the explorer takes a following line feed as part of the
line end, as the usual CR LF files need.