PLY格式文件

PLY是一种电脑档案格式,全名为多边形档案(Polygon File Format)或 斯坦福三角形档案(Stanford Triangle Format)。

该格式主要用以储存立体扫描结果的三维数值,透过多边形片面的集合描述三维物体,与其他格式相较之下这是较为简单的方法。它可以储存的资讯包含颜色、透明度、表面法向量、材质座标与资料可信度,并能对多边形的正反两面设定不同的属性。

在档案内容的储存上PLY有两种版本,分别是纯文字(ASCII)版本与二元码(binary)版本。

每个PLY档都包含档头(header),用以设定网格模型的“元素”与“属性”,以及在档头下方接着一连串的元素“数值资料”。

一般而言,网格模型的“元素”就是顶点(vertices)面(faces),另外还可能包含有边(edges)、深度图样本(samples of range maps)与三角带(triangle strips)等元素。

无论是纯文字(ASCII)版本还是二元码(binary)版本的PLY文档,档头资讯都是以纯文字(ASCII)编码编写,说白了就是你能直接看懂的文字,接续其后的数值资料才有编码之分。

PLY档案以此行:

ply

开头作为PLY格式的识别。接着第二行是版本资讯,目前有三种写法:

format ascii 1.0

format binary_little_endian 1.0

format binary_big_endian 1.0

其中ascii, binary_little_endian, binary_big_endian是档案储存的编码方式,而1.0是遵循的标准版本(现阶段仅有PLY 1.0版)。在档头中可使用'comment'作为一行的开头以编写注解,例如:

comment This is a comment!

描述元素及属性,必须使用'element'及'property'的关键字,一般的格式为element下方接着属性列表,例如:

element  

 property  

 property  

 property  

'property'不仅定义了数值资料的型态,其出现顺序亦定义了数值资料的顺序。

内定的数值资料形态有两种写法:

一种是char uchar short ushort int uint float double,

另外一种是具有位元长度的int8 uint8 int16 uint16 int32 uint32 float32 float64

例如,描述一个包含12个顶点的物体,每个顶点使用3个单精度浮点数 (x,y,z)代表点的座标,使用3个unsigned char代表顶点颜色,颜色顺序为 (B, G, R),则档头的写法为:

element vertex 12

property float x

property float y

property float z

property uchar blue

property uchar green

property uchar red

其中vertex是内定的元素类型,接续的6行property描述构成vertex元素的数值字段顺序代表的意义,及其资料形态。

另一个常使用的元素是。由于一个面是由3个以上的顶点所组成,因此使用一个“顶点列表”即可描述一个面, PLY格式使用一个特殊关键字'property list'定义之。 例如,一个具有10个面的物体,其PLY档头可能包含:

element face 10

 property list uchar int vertex_indices

'property list'表示该元素面(face)的特性是由一行的顶点列表来描述。列表开头以uchar型态的数值表示列表的项目数,后面接着数值资料为int型的顶点索引值(vertex_indices),顶点索引值从0开始。

最后,标头必须以此行结尾:

end_header

档头后接着的是元素资料(端点座标、拓朴连结等)。在ASCII格式中各个端点与面的资讯都是以独立的一行描述,而二元编码格式则连续储存这些资料,加载时须以'element'定义的元素数目以及'property'中设定的资料形态计算各笔字段的长度。

举个栗子,一个描述8个顶点,6个面的立方体的PLY文件如下:

ply
format ascii 1.0           { ascii/binary, format version number }
comment made by Greg Turk  { comments keyword specified, like all lines }
comment this file is a cube
element vertex 8           { define "vertex" element, 8 of them in file }
property float x           { vertex contains float "x" coordinate }
property float y           { y coordinate is also a vertex property }
property float z           { z coordinate, too }
element face 6             { there are 6 "face" elements in the file }
property list uchar int vertex_index { "vertex_indices" is a list of ints }
end_header                 { delimits the end of the header }
0 0 0                      { start of vertex list }
0 0 1
0 1 1
0 1 0
1 0 0
1 0 1
1 1 1
1 1 0
4 0 1 2 3                  { start of face list }
4 7 6 5 4
4 0 4 5 1
4 1 5 6 2
4 2 6 7 3
4 3 7 4 0

参考资料

https://www.cnblogs.com/liangliangdetianxia/p/4000295.html

https://blog.csdn.net/lafengxiaoyu/article/details/72871570

你可能感兴趣的:(python,自我总结归纳,其它资料)