Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable-length lists are not supported #3

Open
bchretien opened this issue Jan 16, 2017 · 6 comments
Open

Variable-length lists are not supported #3

bchretien opened this issue Jan 16, 2017 · 6 comments

Comments

@bchretien
Copy link
Contributor

bchretien commented Jan 16, 2017

Hi,

First of all thanks for the library. While testing it, I encountered the following issue.

The common use cases involve fixed-length lists for properties (e.g. faces made of 3 vertices), but the PLY format also supports variable lengths for the lists of each element, for example:

ply
format ascii 1.0
comment author: Greg Turk
comment object: another cube
element vertex 8
property float x
property float y
property float z
property uchar red                    { start of vertex color }
property uchar green
property uchar blue
element face 7
property list uchar int vertex_index  { number of vertices for each face }
element edge 5                        { five edges in object }
property int vertex1                  { index to first vertex of edge }
property int vertex2                  { index to second vertex }
property uchar red                    { start of edge color }
property uchar green
property uchar blue
end_header
0 0 0 255 0 0                         { start of vertex list }
0 0 1 255 0 0
0 1 1 255 0 0
0 1 0 255 0 0
1 0 0 0 0 255
1 0 1 0 0 255
1 1 1 0 0 255
1 1 0 0 0 255
3 0 1 2                               { start of face list, begin with a triangle }
3 0 2 3                               { another triangle }
4 7 6 5 4                             { now some quadrilaterals }
4 0 4 5 1
4 1 5 6 2
4 2 6 7 3
4 3 7 4 0
0 1 255 255 255                       { start of edge list, begin with white edge }
1 2 255 255 255
2 3 255 255 255
3 0 255 255 255
2 0 0 0 0                             { end with a single black line }

(example taken from Paul Bourke's personal page)

Here faces are described as both triangles and quadrilaterals, thus taking either 3 or 4 values. Apparently, this use case is not supported by tinyply yet, since these properties are serialized into a single vector, without keeping track of how many values are assigned to each element. We could also imagine cases where these lists can take any value (0 included).

Thus, for such cases, we might need to store the data in vector<vector<T>> (or vector<T> with an additional vector of offsets).

@ddiakopoulos
Copy link
Owner

Hah! Yes, you found some dirty laundry. I think the most practical, real-world example is a file that -- as you mention -- has tris and quads. The bad news is that adding support for this would probably require a re-write of both the API and internal parsing function.

@bchretien
Copy link
Contributor Author

I managed to implement this feature: if the list length is set to 0, the property is treated as a variable-length list, stored as a std::vector<std::vector<T>>. I also added CMake support, and some basic tests. I can try to clean up things and make a PR for all of this if you're interested.

@ddiakopoulos
Copy link
Owner

👍 yes please!

@bchretien
Copy link
Contributor Author

I'm still working on this, I fixed some more issues. For example, we might want to read face data only, thus skipping vertex elements entirely, which was not supported apparently.

@marnef
Copy link

marnef commented Jan 16, 2020

I also can't find an API to at least read the number of elements in a list, e.g. 3 for triangles and 4 for quadrics. Or do I miss something? If I expect all faces to be triangles, but they are quadrics, my application using tinyply crashes :-(

@ddiakopoulos
Copy link
Owner

Hi @marnef unfortunately this API doesn't exist on the master branch yet, but you can check out the variable-length branch if you need this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants