source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/vrippack-0.31/src/plytools/polygon.doc @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 17.0 KB
Line 
1The PLY Polygon File Format
2---------------------------
3
4Introduction
5------------
6
7This document presents the PLY polygon file format, a format for storing
8graphical objects that are described as a collection of polygons.  Our goal is
9to provide a format that is simple and easy to implement but that is general
10enough to be useful for a wide range of models.  The file format has two
11sub-formats: an ASCII representation for easily getting started, and a binary
12version for compact storage and for rapid saving and loading.  We hope that
13this format will promote the exchange of graphical object between programs and
14also between groups of people.
15
16Overview
17--------
18
19Anyone who has worked in the field of computer graphics for even a short
20time knows about the bewildering array of storage formats for graphical
21objects.  It seems as though every programmer creates a new file format for
22nearly every new programming project.  The way out of this morass of
23formats is to create a single file format that is both flexible enough to
24anticipate future needs and that is simple enough so as not to drive away
25potential users.  Once such a format is defined, a suite of utilities (both
26procedures and entire programs) can be written that are centered around this
27format.  Each new utility that is added to the suite can leverage off the power
28of the others.
29
30The PLY format describes an object as a collection of vertices, faces and
31other elements, along with properties such as color and normal direction that
32can be attached to these elements.  A PLY file contains the description of
33exactly one object.  Sources of such objects include: hand-digitized objects,
34polygon objects from modeling programs, range data, triangles from marching
35cubes (isosurfaces from volume data), terrain data, radiosity models.
36Properties that might be stored with the object include: color, surface
37normals, texture coordinates, transparency, range data confidence, and
38different properties for the front and back of a polygon.
39
40The PLY format is NOT intended to be a general scene description
41language, a shading language or a catch-all modeling format.  This means
42that it includes no transformation matrices, object instantiation, modeling
43hierarchies, or object sub-parts.  It does not include parametric patches,
44quadric surfaces, constructive solid geometry operations, triangle strips,
45polygons with holes, or texture descriptions (not to be confused with texture
46coordinates, which it does support!).
47
48A typical PLY object definition is simply a list of (x,y,z) triples for
49vertices and a list of faces that are described by indices into the list of
50vertices.  Most PLY files include this core information.  Vertices and faces
51are two examples of "elements", and the bulk of a PLY file is its list of
52elements.  Each element in a given file has a fixed number of "properties" that
53are specified for each element.  The typical information in a PLY file contains
54just two elements, the (x,y,z) triples for vertices and the vertex indices for
55each face.  Applications can create new properties that are attached to
56elements of an object.  For example, the properties red, green and blue are
57commonly associated with vertex elements.  New properties are added in such a
58way that old programs do not break when these new properties are encountered.
59Properties that are not understood by a program can either be carried along
60uninterpreted or can be discarded.  In addition, one can create a new element
61type and define the properties associated with this element.  Examples of new
62elements are edges, cells (lists of pointers to faces) and materials (ambient,
63diffuse and specular colors and coefficients).  New elements can also be
64carried along or discarded by programs that do not understand them.
65
66File Structure
67--------------
68
69This is the structure of a typical PLY file:
70
71  Header
72  Vertex List
73  Face List
74  (lists of other elements)
75
76The header is a series of carraige-return terminated lines of text that
77describe the remainder of the file.  The header includes a description of each
78element type, including the element's name (e.g. "edge"), how many such
79elements are in the object, and a list of the various properties associated
80with the element.  The header also tells whether the file is binary or ASCII.
81Following the header is one list of elements for each element type, presented
82in the order described in the header.
83
84Below is the complete ASCII description for a cube.  The header of a binary
85version of the same object would differ only in substituting the word
86"binary_little_endian" or "binary_big_endian" for the word "ascii".  The
87comments in brackets are NOT part of the file, they are annotations to this
88example.  Comments in files are ordinary keyword-identified lines that begin
89with the word "comment".
90
91ply
92format ascii 1.0           { ascii/binary, format version number }
93comment made by Greg Turk  { comments keyword specified, like all lines }
94comment this file is a cube
95element vertex 8           { define "vertex" element, 8 of them in file }
96property float x           { vertex contains float "x" coordinate }
97property float y           { y coordinate is also a vertex property }
98property float z           { z coordinate, too }
99element face 6             { there are 6 "face" elements in the file }
100property list uchar int vertex_index { "vertex_indices" is a list of ints }
101end_header                 { delimits the end of the header }
1020 0 0                      { start of vertex list }
1030 0 1
1040 1 1
1050 1 0
1061 0 0
1071 0 1
1081 1 1
1091 1 0
1104 0 1 2 3                  { start of face list }
1114 7 6 5 4
1124 0 4 5 1
1134 1 5 6 2
1144 2 6 7 3
1154 3 7 4 0
116
117This example demonstrates the basic components of the header.  Each part
118of the header is a carraige-return terminated ASCII string that begins with a
119keyword.  Even the start and end of the header ("ply<cr>" and
120"end_header<cr>") are in this form.  The characters "ply<cr>" must be the
121first four characters of the file, since they serve as the fileÕs magic number. 
122Following the start of the header is the keyword "format" and a specification
123of either ASCII or binary format, followed by a version number.  Next is the
124description of each of the elements in the polygon file, and within each
125element description is the specification of the properties.  Then generic
126element description has this form:
127
128element <element-name> <number-in-file>
129property <data-type> <property-name-1>
130property <data-type> <property-name-2>
131property <data-type> <property-name-3>
132...
133
134The properties listed after an "element" line define both the data type of the
135property and also the order in which the property appears for each element. 
136There are two kinds of data types a property may have: scalar and list.  Here
137is a list of the scalar data types a property may have:
138
139name        type        number of bytes
140---------------------------------------
141char       character                 1
142uchar      unsigned character        1
143short      short integer             2
144ushort     unsigned short integer    2
145int        integer                   4
146uint       unsigned integer          4
147float      single-precision float    4
148double     double-precision float    8
149
150These byte counts are important and must not vary across implementations in
151order for these files to be portable.  There is a special form of property
152definitions that uses the list data type:
153
154  property list <numerical-type> <numerical-type> <property-name>
155
156An example of this is from the cube file above:
157
158  property list uchar int vertex_index
159
160This means that the property "vertex_index"  contains first an unsigned char
161telling how many indices the property contains, followed by a list containing
162that many integers.  Each integer in this variable-length list is an index to
163a vertex.
164
165Another Example
166---------------
167
168Here is another cube definition:
169
170ply
171format ascii 1.0
172comment author: Greg Turk
173comment object: another cube
174element vertex 8
175property float x
176property float y
177property float z
178property red uchar                    { start of vertex color }
179property green uchar
180property blue uchar
181element face 7
182property list uchar int vertex_index  { number of vertices for each face }
183element edge 5                        { five edges in object }
184property int vertex1                  { index to first vertex of edge }
185property int vertex2                  { index to second vertex }
186property uchar red                    { start of edge color }
187property uchar green
188property uchar blue
189end_header
1900 0 0 255 0 0                         { start of vertex list }
1910 0 1 255 0 0
1920 1 1 255 0 0
1930 1 0 255 0 0
1941 0 0 0 0 255
1951 0 1 0 0 255
1961 1 1 0 0 255
1971 1 0 0 0 255
1983 0 1 2                           { start of face list, begin with a triangle }
1993 0 2 3                           { another triangle }
2004 7 6 5 4                         { now some quadrilaterals }
2014 0 4 5 1
2024 1 5 6 2
2034 2 6 7 3
2044 3 7 4 0
2050 1 255 255 255                   { start of edge list, begin with white edge }
2061 2 255 255 255
2072 3 255 255 255
2083 0 255 255 255
2092 0 0 0 0                         { end with a single black line }
210
211This file specifies a red, green and blue value for each vertex.  To
212illustrate the variable-length nature of vertex_index, the first two faces of
213the object are triangles instead of a single square.  This means that the
214number of faces in the object is 7.  This object also contains a list of
215edges.  Each edge contains two pointers to the vertices that delinate the
216edge.  Each edge also has a color.  The five edges defined above were
217specified so as to highlight the two triangles in the file.  The first four
218edges are white, and they surround the two triangles.  The final edge is
219black, and it is the edge that separates the triangles.
220
221User-Defined Elements
222---------------------
223
224The examples above showed the use of three elements: vertices, faces and
225edges.  The PLY format allows users to define their own elements as well. 
226The format for defining a new element is exactly the same as for vertices,
227faces and edges.  Here is the section of a header that defines a material
228property:
229
230element material 6
231property ambient_red uchar               { ambient color }
232property ambient_green uchar
233property ambient_blue uchar
234property ambient_coeff float
235property diffuse_red uchar               { diffuse color }
236property diffuse_green uchar
237property diffuse_blue uchar
238property diffuse_coeff float
239property specular_red uchar              { specular color }
240property specular_green uchar
241property specular_blue uchar
242property specular_coeff float
243property specular_power float            { Phong power }
244
245These lines would appear in the header directly after the specification of
246vertices, faces and edges.  If we want each vertex to have a material
247specification, we might add this line to the end of the properties for a
248vertex:
249
250  property material_index int
251
252This integer is now an index into the list of materials contained in the file.
253It may be tempting for the author of a new application to invent several new
254elements to be stored in PLY files.  This practice should be kept to a
255minimum.  Much better is to try adapting common elements (vertices, faces,
256edges, materials) to new uses, so that other programs that understand these
257elements might be useful in manipulating these adapted elements.  Take, for
258example, an application that describes molecules as collections of spheres and
259cylinders.  It would be tempting define sphere and cylinder elements for the
260PLY files containing the molecules.  If, however, we use the vertex and edge
261elements for this purpose (adding the radius property to each), we can make
262use of programs that manipulate and display vertices and edges.  Clearly one
263should not create special elements for triangles and quadrilaterals, but
264instead use the face element.  What if a program does not know the adjacency
265between faces and vertices (so-called unshared vertices)?  This is where each
266triangle (say) is purely a collection of three positions in space, with no
267notion whether some triangles have common vertices.  This is a fairly common
268situation.  Assuming there are N triangles in a given object, then 3N vertices
269should be written to the file, followed by N faces that simply connect up
270these vertices.  We anticipate that a utility will be written that converts
271between unshared and shared vertex files.
272
273Object Information
274------------------
275
276
277Interface Routines
278------------------
279
280This section describes a set of C routines that make it easy to read and write
281PLY polygon files.  Both binary and ASCII files can be written with almost
282identical procedure calls.  There are simple mechanisms for allowing a program
283to carry along information about an object even if the program doesn't
284explicitly know about all the types of elements and properties in a file.
285
286Writing Files
287-------------
288
289Whether reading or writing a PLY file, there is one data structure that
290is associated with a given file, and that is the "PlyFile" data type.
291To write a file, we call the routine "ply_write":
292
293  PlyFile *ply_write (FILE *fp,           /* pointer to file for writing */
294                      int nelems,         /* number of elements in file */
295                      char **elem_names,  /* list of element names */
296                      int file_type)      /* binary or ascii? */
297
298This routine returns a pointer to a structure of type PlyFile which will
299be used later to refer to the file.  "ply_write" is called with a pointer
300to a file that we have opened for writing, the number of
301
302
303
304General Utilities
305-----------------
306
307rescale
308center of mass
309compute vertex normals
310polygon editor
311polygon display
312create platonic and archemidean polyhedra
313truncate, stellate, dual, snub
314laplacian smoothing
315mesh simplification
316conversion to and from PLY files
317shared <-> unshared vertices
318split arbitrary polygons into triangles
319find connected components
320refine a subdivision surface
321strip away some properties and/or elements of a PLY file
322create new properties with default values
323combine multiple polygonal objects into one
324re-map values of properties into new ranges (like [0,255] into [0,1])
325re-name properties
326orient the faces of an object so that adjacent faces are consistant
327
328Pre-Defined Elements and Properties
329-----------------------------------
330
331Although the PLY format allows arbitrary new elements and properties, the
332biggest benefit of using the format is for communication between programs. 
333These programs should understand a common set of elements and properties. 
334To that end, we present suggestions for the names and types of a number of
335properties.
336
337The suggestions for properties are broken down into three separate lists.  The
338first of these lists contain the two elements (vertex and face) and the
339associated four properties that ALL programs that use PLY files should
340understand.  These four properties (x, y, z, vertex_index) comprise the
341minimal information that any polygon file should contain.  Writing a program
342that expects these four properties is trivial, thus making it easy for a
343program to accept any PLY file that contains these "core" properties.  The
344second list describes further  properties that are likely to be used often.
345The final set are some suggestions for properties that some applications may
346desire.
347
348Core List (required)
349--------------------
350
351Element: vertex
352x        float        x coordinate
353y        float        y coordinate
354z        float        z coordinate
355Element: face
356vertex_index        list of int        indices to vertices
357
358Second List (often used)
359------------------------
360
361Element: vertex
362nx        float        x component of normal
363ny        float        y component of normal
364nz        float        z component of normal
365red        uchar        red part of color
366green        uchar        green part of color
367blue        uchar        blue part of color
368alpha        uchar        amount of transparency
369material_index        int        index to list of materials
370Element: face
371Element: edge
372vertex1        int        index to vertex
373vertex2        int        other index to vertex
374Element: material
375red        uchar        red part of color
376green        uchar        green part of color
377blue        uchar        blue part of color
378alpha        uchar        amount of transparency
379reflect_coeff        float        amount of light reflected
380refract_coeff        float        amount of light transmitted
381refract_index        float        index of refraction
382extinct_coeff        float        extinction coefficient
383
384Third List (suggested extensions)
385---------------------------------
386
387Element: vertex
388face_index        list of int        indices to faces
389vertex_index        list of int        indices to vertices
390edge_index        list of int        indices to edges
391radius        float        for spheres
392Element: face
393back_red        uchar        color of backside
394back_green        uchar
395back_blue        uchar
396Element: edge
397face1        int        index to face
398face2        int        other index to face
399radius        float        for cylinders
400crease_tag        uchar        crease in subdivision surface
401Element: material
402Element: cell                examples: tetrahedra, cubes
403face_index        list of int        indices to faces
404vertex_index        list of int        indices to vertices
405edge_index        list of int        indices to edges
406
407
Note: See TracBrowser for help on using the repository browser.