McStasMcXtrace / McCode

The home of the McStas (neutrons) and McXtrace (x-rays) Monte-Carlo ray-tracing instrument simulation codes.
https://github.com/McStasMcXtrace/McCode/wiki
GNU General Public License v3.0
77 stars 54 forks source link

McCode common: off/ply-reader is not robust #565

Open ebknudsen opened 6 years ago

ebknudsen commented 6 years ago

The Off/ply-file reader often crashes with a seg.-fault if the file is not quite formatted right. Instances:

  1. if line-endings are "\r" - the file does nor work
  2. if you have normal vectors on the same lines as the vertices. This explicitly supported by the off format standard
  3. If you add color to the faces as supported by the ply-format etc.

Instead the format has to be (the comments are optional):

OFF

comment

N n 0

comment

x_0 y_0 z_0 x_1 y_1 z1 ... x{N-1} y{N-1} z{N-1}

comment

m_0 i_0 j_0 k_0 (l0) ... m{n-1} i{n-1} j{n-1} (l_{n-1})

where N is the number of vertices, n the number of faces, x_q, y_q, z_q are the coordinates for vertex q. m is the number of vertices forming the face. Lastly, i_q, j_q, k_q, and l_q are vertex indices that make up face q, and so on

willend commented 6 years ago

It would be great to have a more flexible / tolerant off/ply reader - especially for use with Peter Link's reflectivity patch (which lists an m-value after each face definition)

willend commented 6 years ago

Related Peter Link patch mentioned here: https://github.com/McStasMcXtrace/McCode/issues/540

willend commented 6 years ago

Consider also if read_table-lib should be used for the reading of these files...

willend commented 6 years ago

A suggestion for a more flexible OFF "standard" would include surface normals and extra surface data, ala:

OFF

comment(s)

N n 0

comment(s)

x_0 y_0 z0 (n{x0} n{y0} n{z0}) x_1 y_1 z1 (n{x1} n{y1} n{z1}) ... x{N-1} y{N-1} z_{N-1}

comment(s)

m_0 i_0 j_0 k_0 (l_0) [surfparms0] ... m{n-1} i{n-1} j{n-1} (l{n-1}) [surfparms{n-1}]

Further, we should probably tolerate face indexing starting from 0 or 1 - both types of output exist...

Multiple face ranks in one file (e.g. both triangles and rectangles) is probably too complex, but a (non-coredump) failure should be raised.