tinyply icon indicating copy to clipboard operation
tinyply copied to clipboard

write variable length lists (tinyply 2.0)

Open caselitz opened this issue 7 years ago • 14 comments

Hi, the readme of tinyply 2.0 states:

Version 2.0 is mostly an API re-write, although various bits of the implementation have been changed. In fact, the changes reduce the overall speed of the library around 5%, although at much greater flexibility for further improvements to support variable length lists. One notable change is that tinyply now produces and consumes untyped byte buffers, with type information held as metadata.

Unfortunately there is no example how to write (and read) a variable length list in the example. I wonder how this works. I would basically like to write/read this

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 }

where lists should be represented by a std::vector<std::vector<T>>. Is this supported by tinyply 2.0?

I also saw this was discussed here and here but this is quite old and it is not clear to me what ended up in upstream (branch 2.0) and what is only available in some forks etc.?

caselitz avatar Apr 26 '18 12:04 caselitz

where lists should be represented by a std::vector<std::vector<T>>

Actually it would be nice if both was possible, variable-length (std::vector<std::vector<T>>) and flat fixed-length (std::vector<T>)

caselitz avatar Apr 26 '18 13:04 caselitz

Hi @caselitz variable length lists are fairly uncommon and so I haven't put much time towards supporting them in this library. I re-wrote some inner loops of tinyply 2.0 to better support these in the future (i.e. they do not work today) but I need to loop back and actually write the functionality. I believe @bchretien has a fork of tinyply which actually does work.

ddiakopoulos avatar Apr 26 '18 16:04 ddiakopoulos

Thanks for your quick reply and the clarification (and of course for providing the library)!

I feel the description in the readme regarding the variable length lists might be a bit misleading (at least I misunderstood it). Anyhow, I think supporting them would be a great feature for the future since they are, even though possibly uncommon, part of the PLY format.

PS: I ended up using the old version with the stuff from bchretiens fork, seems to work nicely. :)

caselitz avatar Apr 29 '18 20:04 caselitz

Hi @caselitz -- It sounds like you're unblocked on this feature already from bchretien's fork, but if you're feeling adventurous I just pushed preliminary support for this feature on a branch: https://github.com/ddiakopoulos/tinyply/tree/variable-length

ddiakopoulos avatar Apr 30 '18 17:04 ddiakopoulos

Out of pure curiosity, in what context do you use / need variable length lists? It sounds so exotic to me. It seems for quad support?

svenevs avatar May 03 '18 14:05 svenevs

@svenevs The only rational thing I can think of is given by the example in the PLY spec. Mixed uses of triangles and quads.

ddiakopoulos avatar May 03 '18 16:05 ddiakopoulos

Hi @caselitz -- It sounds like you're unblocked on this feature already from bchretien's fork, but if you're feeling adventurous I just pushed preliminary support for this feature on a branch: https://github.com/ddiakopoulos/tinyply/tree/variable-length

That's great, thank's for your effort! I will try it, hope to find the time soon...

Out of pure curiosity, in what context do you use / need variable length lists? It sounds so exotic to me. It seems for quad support?

I'm saving a list of objects in the PLY and each object is a set of (arbitrary many) vertices whose vertex_indices I store - so in my code I have a std::vector<std::vector<uint32_t>> objects and basically use tinyply to serialize/deserialize the data along with a "normal" triangle mesh.

I think this is within the scope of the PLY format. Quote from here

The PLY format describes an object as a collection of vertices, faces and other elements,

caselitz avatar May 03 '18 18:05 caselitz

I found the time to test @ddiakopoulos.

The reading works fine for me (only the debug output should be removed).

However, the writing does not work. Have you implemented/adapted that already? At least there is no adaption in the example and also the basic example fails (segfault, core dump).

caselitz avatar May 09 '18 19:05 caselitz

I saw some recent activity in the repo. Any progress on this issue here @ddiakopoulos? Maybe it would be a nice thing to include in tinyply 2.1

Thanks, Tim

caselitz avatar Jun 12 '18 12:06 caselitz

@caselitz working on it for 2.2 :)

Long tail is not the actual implementation itself but testing it adequately

ddiakopoulos avatar Jun 12 '18 16:06 ddiakopoulos

@caselitz working on it for 2.2 :)

this is not included in 2.2, right? any chance for 2.3? :)

caselitz avatar Aug 14 '18 13:08 caselitz

@caselitz yes, 2.3 will entirely be dedicated to variable length!

ddiakopoulos avatar Aug 22 '18 14:08 ddiakopoulos

Any hope for 2.3 @ddiakopoulos?

Thanks, Tim

caselitz avatar Apr 03 '19 15:04 caselitz

So now I'm hoping for 2.4 (saw a commit in the branch), great that you found time to work on the library again... thanks! :)

caselitz avatar Feb 14 '20 17:02 caselitz