Subversion Repositories gelsvn

Rev

Rev 443 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
595 jab 1
/**
2
 * @file rply.h
3
 * @brief RPly library, read/write PLY files by Diego Nehab, Princeton University
4
 */
443 jab 5
#ifndef __GEOMETRY_PLY_H
6
#define __GEOMETRY_PLY_H
371 jab 7
/* ----------------------------------------------------------------------
8
 * RPly library, read/write PLY files
9
 * Diego Nehab, Princeton University
10
 * http://www.cs.princeton.edu/~diego/professional/rply
11
 *
12
 * This library is distributed under the MIT License. See notice
13
 * at the end of this file.
14
 * ---------------------------------------------------------------------- */
15
 
16
#ifdef __cplusplus
17
extern "C" {
18
#endif
19
 
20
#define RPLY_VERSION   "RPly 1.01"
21
#define RPLY_COPYRIGHT "Copyright (C) 2003-2005 Diego Nehab"
22
#define RPLY_AUTHORS   "Diego Nehab"
23
 
24
/* ----------------------------------------------------------------------
25
 * Types
26
 * ---------------------------------------------------------------------- */
27
/* structures are opaque */
28
typedef struct t_ply_ *p_ply;
29
typedef struct t_ply_element_ *p_ply_element;
30
typedef struct t_ply_property_ *p_ply_property;
31
typedef struct t_ply_argument_ *p_ply_argument;
32
 
33
/* ply format mode type */
34
typedef enum e_ply_storage_mode_ {
35
    PLY_BIG_ENDIAN,
36
    PLY_LITTLE_ENDIAN,
37
    PLY_ASCII,   
38
    PLY_DEFAULT      /* has to be the last in enum */
39
} e_ply_storage_mode; /* order matches ply_storage_mode_list */
40
 
41
/* ply data type */
42
typedef enum e_ply_type {
43
    PLY_INT8, PLY_UINT8, PLY_INT16, PLY_UINT16, 
44
    PLY_INT32, PLY_UIN32, PLY_FLOAT32, PLY_FLOAT64,
45
    PLY_CHAR, PLY_UCHAR, PLY_SHORT, PLY_USHORT,
46
    PLY_INT, PLY_UINT, PLY_FLOAT, PLY_DOUBLE,
47
    PLY_LIST    /* has to be the last in enum */
48
} e_ply_type;   /* order matches ply_type_list */
49
 
50
/* ----------------------------------------------------------------------
51
 * Property reading callback prototype
52
 *
53
 * message: error message
54
 * ---------------------------------------------------------------------- */
55
typedef void (*p_ply_error_cb)(const char *message);
56
 
57
/* ----------------------------------------------------------------------
58
 * Opens a ply file for reading (fails if file is not a ply file)
59
 *
60
 * error_cb: error callback function
61
 * name: file name
62
 *
63
 * Returns 1 if successful, 0 otherwise
64
 * ---------------------------------------------------------------------- */
65
p_ply ply_open(const char *name, p_ply_error_cb error_cb);
66
 
67
/* ----------------------------------------------------------------------
68
 * Reads and parses the header of a ply file returned by ply_open
69
 *
70
 * ply: handle returned by ply_open
71
 *
72
 * Returns 1 if successfull, 0 otherwise
73
 * ---------------------------------------------------------------------- */
74
int ply_read_header(p_ply ply);
75
 
76
/* ----------------------------------------------------------------------
77
 * Property reading callback prototype
78
 *
79
 * argument: parameters for property being processed when callback is called
80
 *
81
 * Returns 1 if should continue processing file, 0 if should abort.
82
 * ---------------------------------------------------------------------- */
83
typedef int (*p_ply_read_cb)(p_ply_argument argument);
84
 
85
/* ----------------------------------------------------------------------
86
 * Sets up callbacks for property reading after header was parsed
87
 *
88
 * ply: handle returned by ply_open
89
 * element_name: element where property is
90
 * property_name: property to associate element with
91
 * read_cb: function to be called for each property value
92
 * pdata/idata: user data that will be passed to callback
93
 *
94
 * Returns 0 if no element or no property in element, returns the
95
 * number of element instances otherwise. 
96
 * ---------------------------------------------------------------------- */
595 jab 97
int ply_set_read_cb(p_ply ply, const char *element_name, 
371 jab 98
        const char *property_name, p_ply_read_cb read_cb, 
595 jab 99
        void *pdata, int idata);
371 jab 100
 
101
/* ----------------------------------------------------------------------
102
 * Returns information about the element originating a callback
103
 *
104
 * argument: handle to argument 
105
 * element: receives a the element handle (if non-null)
106
 * instance_index: receives the index of the current element instance 
107
 *     (if non-null)
108
 *
109
 * Returns 1 if successfull, 0 otherwise
110
 * ---------------------------------------------------------------------- */
111
int ply_get_argument_element(p_ply_argument argument, 
595 jab 112
        p_ply_element *element, int *instance_index);
371 jab 113
 
114
/* ----------------------------------------------------------------------
115
 * Returns information about the property originating a callback
116
 *
117
 * argument: handle to argument 
118
 * property: receives the property handle (if non-null)
119
 * length: receives the number of values in this property (if non-null)
120
 * value_index: receives the index of current property value (if non-null)
121
 *
122
 * Returns 1 if successfull, 0 otherwise
123
 * ---------------------------------------------------------------------- */
124
int ply_get_argument_property(p_ply_argument argument, 
595 jab 125
        p_ply_property *property, int *length, int *value_index);
371 jab 126
 
127
/* ----------------------------------------------------------------------
128
 * Returns user data associated with callback 
129
 *
130
 * pdata: receives a copy of user custom data pointer (if non-null)
131
 * idata: receives a copy of user custom data integer (if non-null)
132
 *
133
 * Returns 1 if successfull, 0 otherwise
134
 * ---------------------------------------------------------------------- */
135
int ply_get_argument_user_data(p_ply_argument argument, void **pdata, 
595 jab 136
        int *idata);
371 jab 137
 
138
/* ----------------------------------------------------------------------
139
 * Returns the value associated with a callback
140
 *
141
 * argument: handle to argument 
142
 *
143
 * Returns the current data item
144
 * ---------------------------------------------------------------------- */
145
double ply_get_argument_value(p_ply_argument argument); 
146
 
147
/* ----------------------------------------------------------------------
148
 * Reads all elements and properties calling the callbacks defined with
149
 * calls to ply_set_read_cb
150
 *
151
 * ply: handle returned by ply_open
152
 *
153
 * Returns 1 if successfull, 0 otherwise
154
 * ---------------------------------------------------------------------- */
155
int ply_read(p_ply ply);
156
 
157
/* ----------------------------------------------------------------------
158
 * Iterates over all elements by returning the next element.
159
 * Call with NULL to return handle to first element.
160
 *
161
 * ply: handle returned by ply_open
162
 * last: handle of last element returned (NULL for first element)
163
 *
164
 * Returns element if successfull or NULL if no more elements
165
 * ---------------------------------------------------------------------- */
166
p_ply_element ply_get_next_element(p_ply ply, p_ply_element last);
167
 
168
/* ----------------------------------------------------------------------
169
 * Iterates over all comments by returning the next comment.
170
 * Call with NULL to return pointer to first comment.
171
 *
172
 * ply: handle returned by ply_open
173
 * last: pointer to last comment returned (NULL for first comment)
174
 *
175
 * Returns comment if successfull or NULL if no more comments
176
 * ---------------------------------------------------------------------- */
177
const char *ply_get_next_comment(p_ply ply, const char *last);
178
 
179
/* ----------------------------------------------------------------------
180
 * Iterates over all obj_infos by returning the next obj_info.
181
 * Call with NULL to return pointer to first obj_info.
182
 *
183
 * ply: handle returned by ply_open
184
 * last: pointer to last obj_info returned (NULL for first obj_info)
185
 *
186
 * Returns obj_info if successfull or NULL if no more obj_infos
187
 * ---------------------------------------------------------------------- */
188
const char *ply_get_next_obj_info(p_ply ply, const char *last);
189
 
190
/* ----------------------------------------------------------------------
191
 * Returns information about an element
192
 *
193
 * element: element of interest
194
 * name: receives a pointer to internal copy of element name (if non-null)
195
 * ninstances: receives the number of instances of this element (if non-null)
196
 *
197
 * Returns 1 if successfull or 0 otherwise
198
 * ---------------------------------------------------------------------- */
199
int ply_get_element_info(p_ply_element element, const char** name,
595 jab 200
        int *ninstances);
371 jab 201
 
202
/* ----------------------------------------------------------------------
203
 * Iterates over all properties by returning the next property.
204
 * Call with NULL to return handle to first property.
205
 *
206
 * element: handle of element with the properties of interest
207
 * last: handle of last property returned (NULL for first property)
208
 *
209
 * Returns element if successfull or NULL if no more properties
210
 * ---------------------------------------------------------------------- */
211
p_ply_property ply_get_next_property(p_ply_element element, 
212
        p_ply_property last);
213
 
214
/* ----------------------------------------------------------------------
215
 * Returns information about a property
216
 *
217
 * property: handle to property of interest
218
 * name: receives a pointer to internal copy of property name (if non-null)
219
 * type: receives the property type (if non-null)
220
 * length_type: for list properties, receives the scalar type of
221
 *     the length field (if non-null)
222
 * value_type: for list properties, receives the scalar type of the value 
223
 *     fields  (if non-null)
224
 *
225
 * Returns 1 if successfull or 0 otherwise
226
 * ---------------------------------------------------------------------- */
227
int ply_get_property_info(p_ply_property property, const char** name,
228
        e_ply_type *type, e_ply_type *length_type, e_ply_type *value_type);
229
 
230
/* ----------------------------------------------------------------------
231
 * Creates new ply file
232
 *
233
 * name: file name
234
 * storage_mode: file format mode
235
 *
236
 * Returns handle to ply file if successfull, NULL otherwise
237
 * ---------------------------------------------------------------------- */
238
p_ply ply_create(const char *name, e_ply_storage_mode storage_mode, 
239
        p_ply_error_cb error_cb);
240
 
241
/* ----------------------------------------------------------------------
242
 * Adds a new element to the ply file created by ply_create
243
 *
244
 * ply: handle returned by ply_create
245
 * name: name of new element
246
 * ninstances: number of element of this time in file
247
 *
248
 * Returns 1 if successfull, 0 otherwise
249
 * ---------------------------------------------------------------------- */
595 jab 250
int ply_add_element(p_ply ply, const char *name, int ninstances);
371 jab 251
 
252
/* ----------------------------------------------------------------------
253
 * Adds a new property to the last element added by ply_add_element
254
 *
255
 * ply: handle returned by ply_create
256
 * name: name of new property
257
 * type: property type
258
 * length_type: scalar type of length field of a list property 
259
 * value_type: scalar type of value fields of a list property
260
 *
261
 * Returns 1 if successfull, 0 otherwise
262
 * ---------------------------------------------------------------------- */
263
int ply_add_property(p_ply ply, const char *name, e_ply_type type,
264
        e_ply_type length_type, e_ply_type value_type);
265
 
266
/* ----------------------------------------------------------------------
267
 * Adds a new list property to the last element added by ply_add_element
268
 *
269
 * ply: handle returned by ply_create
270
 * name: name of new property
271
 * length_type: scalar type of length field of a list property 
272
 * value_type: scalar type of value fields of a list property
273
 *
274
 * Returns 1 if successfull, 0 otherwise
275
 * ---------------------------------------------------------------------- */
276
int ply_add_list_property(p_ply ply, const char *name, 
277
        e_ply_type length_type, e_ply_type value_type);
278
 
279
/* ----------------------------------------------------------------------
280
 * Adds a new property to the last element added by ply_add_element
281
 *
282
 * ply: handle returned by ply_create
283
 * name: name of new property
284
 * type: property type
285
 *
286
 * Returns 1 if successfull, 0 otherwise
287
 * ---------------------------------------------------------------------- */
288
int ply_add_scalar_property(p_ply ply, const char *name, e_ply_type type);
289
 
290
/* ----------------------------------------------------------------------
291
 * Adds a new comment item 
292
 *
293
 * ply: handle returned by ply_create
294
 * comment: pointer to string with comment text
295
 *
296
 * Returns 1 if successfull, 0 otherwise
297
 * ---------------------------------------------------------------------- */
298
int ply_add_comment(p_ply ply, const char *comment);
299
 
300
/* ----------------------------------------------------------------------
301
 * Adds a new obj_info item 
302
 *
303
 * ply: handle returned by ply_create
304
 * comment: pointer to string with obj_info data
305
 *
306
 * Returns 1 if successfull, 0 otherwise
307
 * ---------------------------------------------------------------------- */
308
int ply_add_obj_info(p_ply ply, const char *obj_info);
309
 
310
/* ----------------------------------------------------------------------
311
 * Writes the ply file header after all element and properties have been
312
 * defined by calls to ply_add_element and ply_add_property
313
 *
314
 * ply: handle returned by ply_create
315
 *
316
 * Returns 1 if successfull, 0 otherwise
317
 * ---------------------------------------------------------------------- */
318
int ply_write_header(p_ply ply);
319
 
320
/* ----------------------------------------------------------------------
321
 * Writes one property value, in the order they should be written to the
322
 * file. For each element type, write all elements of that type in order.
323
 * For each element, write all its properties in order. For scalar
324
 * properties, just write the value. For list properties, write the length 
325
 * and then each of the values.
326
 *
327
 * ply: handle returned by ply_create
328
 *
329
 * Returns 1 if successfull, 0 otherwise
330
 * ---------------------------------------------------------------------- */
331
int ply_write(p_ply ply, double value);
332
 
333
/* ----------------------------------------------------------------------
334
 * Closes a ply file handle. Releases all memory used by handle
335
 *
336
 * ply: handle to be closed. 
337
 *
338
 * Returns 1 if successfull, 0 otherwise
339
 * ---------------------------------------------------------------------- */
340
int ply_close(p_ply ply);
341
 
342
#ifdef __cplusplus
343
}
344
#endif
345
 
346
#endif /* RPLY_H */
347
 
348
/* ----------------------------------------------------------------------
349
 * Copyright (C) 2003-2005 Diego Nehab. All rights reserved.
350
 *
351
 * Permission is hereby granted, free of charge, to any person obtaining
352
 * a copy of this software and associated documentation files (the
353
 * "Software"), to deal in the Software without restriction, including
354
 * without limitation the rights to use, copy, modify, merge, publish,
355
 * distribute, sublicense, and/or sell copies of the Software, and to
356
 * permit persons to whom the Software is furnished to do so, subject to
357
 * the following conditions:
358
 *
359
 * The above copyright notice and this permission notice shall be
360
 * included in all copies or substantial portions of the Software.
361
 *
362
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
363
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
364
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
365
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
366
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
367
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
368
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
369
 * ---------------------------------------------------------------------- */