00001 #ifndef PLY_H 00002 #define PLY_H 00003 00004 namespace luxrays { 00005 00006 /* ---------------------------------------------------------------------- 00007 * RPly library, read/write PLY files 00008 * Diego Nehab, Princeton University 00009 * http://www.cs.princeton.edu/~diego/professional/rply 00010 * 00011 * This library is distributed under the MIT License. See notice 00012 * at the end of this file. 00013 * ---------------------------------------------------------------------- */ 00014 00015 #define RPLY_VERSION "RPly 1.01" 00016 #define RPLY_COPYRIGHT "Copyright (C) 2003-2005 Diego Nehab" 00017 #define RPLY_AUTHORS "Diego Nehab" 00018 00019 /* ---------------------------------------------------------------------- 00020 * Types 00021 * ---------------------------------------------------------------------- */ 00022 /* structures are opaque */ 00023 typedef struct t_ply_ *p_ply; 00024 typedef struct t_ply_element_ *p_ply_element; 00025 typedef struct t_ply_property_ *p_ply_property; 00026 typedef struct t_ply_argument_ *p_ply_argument; 00027 00028 /* ply format mode type */ 00029 typedef enum e_ply_storage_mode_ { 00030 PLY_BIG_ENDIAN, 00031 PLY_LITTLE_ENDIAN, 00032 PLY_ASCII, 00033 PLY_DEFAULT /* has to be the last in enum */ 00034 } e_ply_storage_mode; /* order matches ply_storage_mode_list */ 00035 00036 /* ply data type */ 00037 typedef enum e_ply_type { 00038 PLY_INT8, PLY_UINT8, PLY_INT16, PLY_UINT16, 00039 PLY_INT32, PLY_UIN32, PLY_FLOAT32, PLY_FLOAT64, 00040 PLY_CHAR, PLY_UCHAR, PLY_SHORT, PLY_USHORT, 00041 PLY_INT, PLY_UINT, PLY_FLOAT, PLY_DOUBLE, 00042 PLY_LIST /* has to be the last in enum */ 00043 } e_ply_type; /* order matches ply_type_list */ 00044 00045 /* ---------------------------------------------------------------------- 00046 * Property reading callback prototype 00047 * 00048 * message: error message 00049 * ---------------------------------------------------------------------- */ 00050 typedef void (*p_ply_error_cb)(const char *message); 00051 00052 /* ---------------------------------------------------------------------- 00053 * Opens a ply file for reading (fails if file is not a ply file) 00054 * 00055 * error_cb: error callback function 00056 * name: file name 00057 * 00058 * Returns 1 if successful, 0 otherwise 00059 * ---------------------------------------------------------------------- */ 00060 p_ply ply_open(const char *name, p_ply_error_cb error_cb); 00061 00062 /* ---------------------------------------------------------------------- 00063 * Reads and parses the header of a ply file returned by ply_open 00064 * 00065 * ply: handle returned by ply_open 00066 * 00067 * Returns 1 if successfull, 0 otherwise 00068 * ---------------------------------------------------------------------- */ 00069 int ply_read_header(p_ply ply); 00070 00071 /* ---------------------------------------------------------------------- 00072 * Property reading callback prototype 00073 * 00074 * argument: parameters for property being processed when callback is called 00075 * 00076 * Returns 1 if should continue processing file, 0 if should abort. 00077 * ---------------------------------------------------------------------- */ 00078 typedef int (*p_ply_read_cb)(p_ply_argument argument); 00079 00080 /* ---------------------------------------------------------------------- 00081 * Sets up callbacks for property reading after header was parsed 00082 * 00083 * ply: handle returned by ply_open 00084 * element_name: element where property is 00085 * property_name: property to associate element with 00086 * read_cb: function to be called for each property value 00087 * pdata/idata: user data that will be passed to callback 00088 * 00089 * Returns 0 if no element or no property in element, returns the 00090 * number of element instances otherwise. 00091 * ---------------------------------------------------------------------- */ 00092 long ply_set_read_cb(p_ply ply, const char *element_name, 00093 const char *property_name, p_ply_read_cb read_cb, 00094 void *pdata, long idata); 00095 00096 /* ---------------------------------------------------------------------- 00097 * Returns information about the element originating a callback 00098 * 00099 * argument: handle to argument 00100 * element: receives a the element handle (if non-null) 00101 * instance_index: receives the index of the current element instance 00102 * (if non-null) 00103 * 00104 * Returns 1 if successfull, 0 otherwise 00105 * ---------------------------------------------------------------------- */ 00106 int ply_get_argument_element(p_ply_argument argument, 00107 p_ply_element *element, long *instance_index); 00108 00109 /* ---------------------------------------------------------------------- 00110 * Returns information about the property originating a callback 00111 * 00112 * argument: handle to argument 00113 * property: receives the property handle (if non-null) 00114 * length: receives the number of values in this property (if non-null) 00115 * value_index: receives the index of current property value (if non-null) 00116 * 00117 * Returns 1 if successfull, 0 otherwise 00118 * ---------------------------------------------------------------------- */ 00119 int ply_get_argument_property(p_ply_argument argument, 00120 p_ply_property *property, long *length, long *value_index); 00121 00122 /* ---------------------------------------------------------------------- 00123 * Returns user data associated with callback 00124 * 00125 * pdata: receives a copy of user custom data pointer (if non-null) 00126 * idata: receives a copy of user custom data integer (if non-null) 00127 * 00128 * Returns 1 if successfull, 0 otherwise 00129 * ---------------------------------------------------------------------- */ 00130 int ply_get_argument_user_data(p_ply_argument argument, void **pdata, 00131 long *idata); 00132 00133 /* ---------------------------------------------------------------------- 00134 * Returns the value associated with a callback 00135 * 00136 * argument: handle to argument 00137 * 00138 * Returns the current data item 00139 * ---------------------------------------------------------------------- */ 00140 double ply_get_argument_value(p_ply_argument argument); 00141 00142 /* ---------------------------------------------------------------------- 00143 * Reads all elements and properties calling the callbacks defined with 00144 * calls to ply_set_read_cb 00145 * 00146 * ply: handle returned by ply_open 00147 * 00148 * Returns 1 if successfull, 0 otherwise 00149 * ---------------------------------------------------------------------- */ 00150 int ply_read(p_ply ply); 00151 00152 /* ---------------------------------------------------------------------- 00153 * Iterates over all elements by returning the next element. 00154 * Call with NULL to return handle to first element. 00155 * 00156 * ply: handle returned by ply_open 00157 * last: handle of last element returned (NULL for first element) 00158 * 00159 * Returns element if successfull or NULL if no more elements 00160 * ---------------------------------------------------------------------- */ 00161 p_ply_element ply_get_next_element(p_ply ply, p_ply_element last); 00162 00163 /* ---------------------------------------------------------------------- 00164 * Iterates over all comments by returning the next comment. 00165 * Call with NULL to return pointer to first comment. 00166 * 00167 * ply: handle returned by ply_open 00168 * last: pointer to last comment returned (NULL for first comment) 00169 * 00170 * Returns comment if successfull or NULL if no more comments 00171 * ---------------------------------------------------------------------- */ 00172 const char *ply_get_next_comment(p_ply ply, const char *last); 00173 00174 /* ---------------------------------------------------------------------- 00175 * Iterates over all obj_infos by returning the next obj_info. 00176 * Call with NULL to return pointer to first obj_info. 00177 * 00178 * ply: handle returned by ply_open 00179 * last: pointer to last obj_info returned (NULL for first obj_info) 00180 * 00181 * Returns obj_info if successfull or NULL if no more obj_infos 00182 * ---------------------------------------------------------------------- */ 00183 const char *ply_get_next_obj_info(p_ply ply, const char *last); 00184 00185 /* ---------------------------------------------------------------------- 00186 * Returns information about an element 00187 * 00188 * element: element of interest 00189 * name: receives a pointer to internal copy of element name (if non-null) 00190 * ninstances: receives the number of instances of this element (if non-null) 00191 * 00192 * Returns 1 if successfull or 0 otherwise 00193 * ---------------------------------------------------------------------- */ 00194 int ply_get_element_info(p_ply_element element, const char** name, 00195 long *ninstances); 00196 00197 /* ---------------------------------------------------------------------- 00198 * Iterates over all properties by returning the next property. 00199 * Call with NULL to return handle to first property. 00200 * 00201 * element: handle of element with the properties of interest 00202 * last: handle of last property returned (NULL for first property) 00203 * 00204 * Returns element if successfull or NULL if no more properties 00205 * ---------------------------------------------------------------------- */ 00206 p_ply_property ply_get_next_property(p_ply_element element, 00207 p_ply_property last); 00208 00209 /* ---------------------------------------------------------------------- 00210 * Returns information about a property 00211 * 00212 * property: handle to property of interest 00213 * name: receives a pointer to internal copy of property name (if non-null) 00214 * type: receives the property type (if non-null) 00215 * length_type: for list properties, receives the scalar type of 00216 * the length field (if non-null) 00217 * value_type: for list properties, receives the scalar type of the value 00218 * fields (if non-null) 00219 * 00220 * Returns 1 if successfull or 0 otherwise 00221 * ---------------------------------------------------------------------- */ 00222 int ply_get_property_info(p_ply_property property, const char** name, 00223 e_ply_type *type, e_ply_type *length_type, e_ply_type *value_type); 00224 00225 /* ---------------------------------------------------------------------- 00226 * Creates new ply file 00227 * 00228 * name: file name 00229 * storage_mode: file format mode 00230 * 00231 * Returns handle to ply file if successfull, NULL otherwise 00232 * ---------------------------------------------------------------------- */ 00233 p_ply ply_create(const char *name, e_ply_storage_mode storage_mode, 00234 p_ply_error_cb error_cb); 00235 00236 /* ---------------------------------------------------------------------- 00237 * Adds a new element to the ply file created by ply_create 00238 * 00239 * ply: handle returned by ply_create 00240 * name: name of new element 00241 * ninstances: number of element of this time in file 00242 * 00243 * Returns 1 if successfull, 0 otherwise 00244 * ---------------------------------------------------------------------- */ 00245 int ply_add_element(p_ply ply, const char *name, long ninstances); 00246 00247 /* ---------------------------------------------------------------------- 00248 * Adds a new property to the last element added by ply_add_element 00249 * 00250 * ply: handle returned by ply_create 00251 * name: name of new property 00252 * type: property type 00253 * length_type: scalar type of length field of a list property 00254 * value_type: scalar type of value fields of a list property 00255 * 00256 * Returns 1 if successfull, 0 otherwise 00257 * ---------------------------------------------------------------------- */ 00258 int ply_add_property(p_ply ply, const char *name, e_ply_type type, 00259 e_ply_type length_type, e_ply_type value_type); 00260 00261 /* ---------------------------------------------------------------------- 00262 * Adds a new list property to the last element added by ply_add_element 00263 * 00264 * ply: handle returned by ply_create 00265 * name: name of new property 00266 * length_type: scalar type of length field of a list property 00267 * value_type: scalar type of value fields of a list property 00268 * 00269 * Returns 1 if successfull, 0 otherwise 00270 * ---------------------------------------------------------------------- */ 00271 int ply_add_list_property(p_ply ply, const char *name, 00272 e_ply_type length_type, e_ply_type value_type); 00273 00274 /* ---------------------------------------------------------------------- 00275 * Adds a new property to the last element added by ply_add_element 00276 * 00277 * ply: handle returned by ply_create 00278 * name: name of new property 00279 * type: property type 00280 * 00281 * Returns 1 if successfull, 0 otherwise 00282 * ---------------------------------------------------------------------- */ 00283 int ply_add_scalar_property(p_ply ply, const char *name, e_ply_type type); 00284 00285 /* ---------------------------------------------------------------------- 00286 * Adds a new comment item 00287 * 00288 * ply: handle returned by ply_create 00289 * comment: pointer to string with comment text 00290 * 00291 * Returns 1 if successfull, 0 otherwise 00292 * ---------------------------------------------------------------------- */ 00293 int ply_add_comment(p_ply ply, const char *comment); 00294 00295 /* ---------------------------------------------------------------------- 00296 * Adds a new obj_info item 00297 * 00298 * ply: handle returned by ply_create 00299 * comment: pointer to string with obj_info data 00300 * 00301 * Returns 1 if successfull, 0 otherwise 00302 * ---------------------------------------------------------------------- */ 00303 int ply_add_obj_info(p_ply ply, const char *obj_info); 00304 00305 /* ---------------------------------------------------------------------- 00306 * Writes the ply file header after all element and properties have been 00307 * defined by calls to ply_add_element and ply_add_property 00308 * 00309 * ply: handle returned by ply_create 00310 * 00311 * Returns 1 if successfull, 0 otherwise 00312 * ---------------------------------------------------------------------- */ 00313 int ply_write_header(p_ply ply); 00314 00315 /* ---------------------------------------------------------------------- 00316 * Writes one property value, in the order they should be written to the 00317 * file. For each element type, write all elements of that type in order. 00318 * For each element, write all its properties in order. For scalar 00319 * properties, just write the value. For list properties, write the length 00320 * and then each of the values. 00321 * 00322 * ply: handle returned by ply_create 00323 * 00324 * Returns 1 if successfull, 0 otherwise 00325 * ---------------------------------------------------------------------- */ 00326 int ply_write(p_ply ply, double value); 00327 00328 /* ---------------------------------------------------------------------- 00329 * Closes a ply file handle. Releases all memory used by handle 00330 * 00331 * ply: handle to be closed. 00332 * 00333 * Returns 1 if successfull, 0 otherwise 00334 * ---------------------------------------------------------------------- */ 00335 int ply_close(p_ply ply); 00336 00337 #endif /* RPLY_H */ 00338 00339 /* ---------------------------------------------------------------------- 00340 * Copyright (C) 2003-2005 Diego Nehab. All rights reserved. 00341 * 00342 * Permission is hereby granted, free of charge, to any person obtaining 00343 * a copy of this software and associated documentation files (the 00344 * "Software"), to deal in the Software without restriction, including 00345 * without limitation the rights to use, copy, modify, merge, publish, 00346 * distribute, sublicense, and/or sell copies of the Software, and to 00347 * permit persons to whom the Software is furnished to do so, subject to 00348 * the following conditions: 00349 * 00350 * The above copyright notice and this permission notice shall be 00351 * included in all copies or substantial portions of the Software. 00352 * 00353 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00354 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00355 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00356 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 00357 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 00358 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 00359 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00360 * ---------------------------------------------------------------------- */ 00361 00362 }
1.6.3