Overture  Version 25
ply.h
Go to the documentation of this file.
1 /*
2 
3 Header for PLY polygon files -- PRIVATE ROUTINES & DATA
4 
5 - Greg Turk, March 1994
6 
7 A PLY file contains a single polygonal _object_.
8 
9 An object is composed of lists of _elements_. Typical elements are
10 vertices, faces, edges and materials.
11 
12 Each type of element for a given object has one or more _properties_
13 associated with the element type. For instance, a vertex element may
14 have as properties three floating-point values x,y,z and three unsigned
15 chars for red, green and blue.
16 
17 ---------------------------------------------------------------
18 
19 Copyright (c) 1994 The Board of Trustees of The Leland Stanford
20 Junior University. All rights reserved.
21 
22 Permission to use, copy, modify and distribute this software and its
23 documentation for any purpose is hereby granted without fee, provided
24 that the above copyright notice and this permission notice appear in
25 all copies of this software and that you do not sell the software.
26 
27 THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
28 EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
29 WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
30 
31 */
32 
33 #ifndef __PLY_H__
34 #define __PLY_H__
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #include <stdio.h>
41 #include <stddef.h>
42 
43 #define PLY_ASCII 1 /* ascii PLY file */
44 #define PLY_BINARY_BE 2 /* binary PLY file, big endian */
45 #define PLY_BINARY_LE 3 /* binary PLY file, little endian */
46 
47 #define PLY_OKAY 0 /* ply routine worked okay */
48 #define PLY_ERROR -1 /* error in ply routine */
49 
50 /* scalar data types supported by PLY format */
51 
52 #define PLY_START_TYPE 0
53 #define PLY_CHAR 1
54 #define PLY_SHORT 2
55 #define PLY_INT 3
56 #define PLY_UCHAR 4
57 #define PLY_USHORT 5
58 #define PLY_UINT 6
59 #define PLY_FLOAT 7
60 #define PLY_DOUBLE 8
61 #define PLY_END_TYPE 9
62 
63 #define PLY_SCALAR 0
64 #define PLY_LIST 1
65 
66 
67 typedef struct PlyProperty { /* description of a property */
68 
69  char *name; /* property name */
70  int external_type; /* file's data type */
71  int internal_type; /* program's data type */
72  int offset; /* offset bytes of prop in a struct */
73 
74  int is_list; /* 1 = list, 0 = scalar */
75  int count_external; /* file's count type */
76  int count_internal; /* program's count type */
77  int count_offset; /* offset byte for list count */
78 
79 } PlyProperty;
80 
81 typedef struct PlyElement { /* description of an element */
82  char *name; /* element name */
83  int num; /* number of elements in this object */
84  int size; /* size of element (bytes) or -1 if variable */
85  int nprops; /* number of properties for this element */
86  PlyProperty **props; /* list of properties in the file */
87  char *store_prop; /* flags: property wanted by user? */
88  int other_offset; /* offset to un-asked-for props, or -1 if none*/
89  int other_size; /* size of other_props structure */
90 } PlyElement;
91 
92 typedef struct PlyOtherProp { /* describes other properties in an element */
93  char *name; /* element name */
94  int size; /* size of other_props */
95  int nprops; /* number of properties in other_props */
96  PlyProperty **props; /* list of properties in other_props */
97 } PlyOtherProp;
98 
99 typedef struct OtherData { /* for storing other_props for an other element */
100  void *other_props;
101 } OtherData;
102 
103 typedef struct OtherElem { /* data for one "other" element */
104  char *elem_name; /* names of other elements */
105  int elem_count; /* count of instances of each element */
106  OtherData **other_data; /* actual property data for the elements */
107  PlyOtherProp *other_props; /* description of the property data */
108 } OtherElem;
109 
110 typedef struct PlyOtherElems { /* "other" elements, not interpreted by user */
111  int num_elems; /* number of other elements */
112  OtherElem *other_list; /* list of data for other elements */
113 } PlyOtherElems;
114 
115 typedef struct PlyFile { /* description of PLY file */
116  FILE *fp; /* file pointer */
117  int file_type; /* ascii or binary */
118  float version; /* version number of file */
119  int nelems; /* number of elements of object */
120  PlyElement **elems; /* list of elements */
121  int num_comments; /* number of comments */
122  char **comments; /* list of comments */
123  int num_obj_info; /* number of items of object information */
124  char **obj_info; /* list of object info items */
125  PlyElement *which_elem; /* which element we're currently writing */
126  PlyOtherElems *other_elems; /* "other" elements from a PLY file */
127 } PlyFile;
128 
129 
130 /* memory allocation */
131 extern char *my_alloc();
132 #define myalloc(mem_size) my_alloc((mem_size), __LINE__, __FILE__)
133 
134 /*** declaration of routines ***/
135 
136 extern PlyFile *ply_write(FILE *, int, char **, int);
137 extern PlyFile *ply_open_for_writing(char *, int, char **, int, float *);
138 extern void ply_describe_element(PlyFile *, char *, int, int, PlyProperty *);
139 extern void ply_describe_property(PlyFile *, char *, PlyProperty *);
140 extern void ply_element_count(PlyFile *, char *, int);
141 extern void ply_header_complete(PlyFile *);
142 extern void ply_put_element_setup(PlyFile *, char *);
143 extern void ply_put_element(PlyFile *, void *);
144 extern void ply_put_comment(PlyFile *, char *);
145 extern void ply_put_obj_info(PlyFile *, char *);
146 extern PlyFile *ply_read(FILE *, int *, char ***);
147 extern PlyFile *ply_open_for_reading( char *, int *, char ***, int *, float *);
148 extern PlyProperty **ply_get_element_description(PlyFile *, char *, int*, int*);
149 extern void ply_get_element_setup( PlyFile *, char *, int, PlyProperty *);
150 extern void ply_get_property(PlyFile *, char *, PlyProperty *);
151 extern PlyOtherProp *ply_get_other_properties(PlyFile *, char *, int);
152 /* wdh extern ply_get_element(PlyFile *, void *); */
153 extern void ply_get_element(PlyFile *, void *);
154 extern char **ply_get_comments(PlyFile *, int *);
155 extern char **ply_get_obj_info(PlyFile *, int *);
156 extern void ply_close(PlyFile *);
157 extern void ply_get_info(PlyFile *, float *, int *);
158 extern PlyOtherElems *ply_get_other_element (PlyFile *, char *, int);
160 extern void ply_put_other_elements (PlyFile *);
161 extern void ply_free_other_elements (PlyOtherElems *);
162 
163 extern int equal_strings(const char *, const char *);
164 
165 
166 #ifdef __cplusplus
167 }
168 #endif
169 #endif /* !__PLY_H__ */
170