How to read ply files
Documentation Help Center Documentation. The function returns a pointCloud object, ptCloud. File name, specified as a character vector or a string scalar. The polygon PLY file format , also known as the Stanford triangle format stores three-dimensional data from 3-D scanners. It is a format for storing graphical objects that are described as a collection of polygons.
A PLY file consists of a header, followed by a list of vertices and then, a list of polygons. The header specifies how many vertices and polygons are in the file. It also states what properties are associated with each vertex, such as x , y , z coordinates, normals, and color. The file format has two sub-formats: an ASCII representation and a binary version for compact storage and for rapid saving and loading. Only the numeric data that follows the header is different between the two versions.
The point cloud data PCD file format also stores three-dimensional data. Connect and share knowledge within a single location that is structured and easy to search. I'm jumping into the world of. I've read a little bit about them but the documentation regarding their formatting doesn't quite seem to line up with what I have in my file. I've been trying to make sense of this article here but I'm not having much luck.
Like I said, I'm trying to make sense of it so I can write my own program to take the vertices and connect them to reform the object. Can anyone help? Wikipedia has an answer for you. The ply-file starts with a header, which offers you all relevant information about how to read the data section.
Important keywords of the header are element and property. The element keyword introduces a new section, which describes data.
There are two of them in your example. The first to store the vertex data and the other one to store the face data. The property keyword introduces a new property of this data section. It is followed by the type and the kind of the data. The information in the data block is stored in the order of appearence. Let's have look at your example:. For example, if we wanted to create the "vertex" and "face" PLY elements of the tet.
Once you have suitably structured array, the static method PlyElement. Note that there's no need to create PlyProperty instances explicitly. One slight hiccup here is that variable-length fields in a numpy array i. For simplicity and predictability, the length defaults to 8-bit unsigned integer, and the value defaults to bit signed integer, which covers the majority of use cases. Exceptions must be stated explicitly:.
Comments can have leading whitespace, but trailing whitespace may be stripped and should not be relied upon. Comments may not contain embedded newlines. The PLY format provides no way to assert that all the data for a given list property is of the same length, yet this is a relatively common occurrence. In such cases, it's usually much more convenient to have the data in a two-dimensional array, as opposed to a one-dimensional array of type object.
Here's a pretty easy way to obtain a two dimensional array, assuming we know the row length in advance:. A plausible code pattern is to read a PLY file into a PlyData instance, perform some operations on it, possibly modifying data and metadata in place, and write the result to a new file.
This pattern is partially supported. As of version 0. To rename a property of a PlyElement instance, you can remove the property from properties , rename the field in data , and re-add the property to properties with the new name by creating a new PlyProperty or PlyListProperty instance:.
Note that it is always safe to create a new PlyElement or PlyData instance instead of modifying one in place, and this is the recommended style:. Objects created by this library don't claim ownership of the other objects they refer to, which has implications for both styles creating new instances and modifying in place. For example, a single PlyElement instance can be contained by multiple PlyData instances, but modifying that instance will then affect all of those containing PlyData instances.
On Python 3, you will probably run into issues because sys. Write to a named file instead. For the most part, PLY concepts map nicely to Python and specifically to numpy , and leveraging that has strongly influenced the design of this package. The elements attribute of a PlyData instance is simply a list of PlyElement instances, and the data attribute of a PlyElement instance is a numpy array, and a list property field of a PLY element datum is referred to in the data attribute by a type of object with the value being another numpy array, etc.
When applicable, we favor simplicity over power or user-friendliness. Thus, list property types in PlyElement. Which element? What if the array has length zero? Whatever default we could choose in that case could lead to subtle edge-case bugs if the user isn't vigilant. Also, all input and output is done in "one shot": all the arrays must be created up front rather than being processed in a streaming fashion. We aim to support all valid PLY files.
However, exactly what constitutes a "valid" file isn't obvious, since there doesn't seem to be a single complete and consistent description of the PLY format. Even the "authoritative" Ply. Where can comments appear in the header? It appears that in all the "official" examples, all comments immediately follow the "format" line, but the language of the document neither places any such restrictions nor explicitly allows comments to be placed anywhere else. Thus, it isn't clear whether comments can appear anywhere in the header or must immediately follow the "format" line.
At least one popular reader of PLY files chokes on comments before the "format" line. Another ambiguity is names: what strings are allowed as PLY element and property names?
This may not be such a big deal, though: although names are theoretically arbitrary, in practice, the majority of PLY element and property names probably come from a small finite set "face", "x", "nx", "green", etc.
A more serious problem is that the PLY format specification appears to be inconsistent regarding the syntax of property definitions.
0コメント