1 /* 2 3 Header for PLY polygon files. 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 // include to quieten down silly VS warnings 37 #include <osg/Export> 38 39 #include <stdio.h> 40 #include <stddef.h> 41 42 #define PLY_ASCII 1 /* ascii PLY file */ 43 #define PLY_BINARY_BE 2 /* binary PLY file, big endian */ 44 #define PLY_BINARY_LE 3 /* binary PLY file, little endian */ 45 46 #define PLY_OKAY 0 /* ply routine worked okay */ 47 #define PLY_ERROR -1 /* error in ply routine */ 48 49 /* scalar data types supported by PLY format */ 50 51 #define PLY_START_TYPE 0 52 #define PLY_CHAR 1 53 #define PLY_SHORT 2 54 #define PLY_INT 3 55 #define PLY_UCHAR 4 56 #define PLY_USHORT 5 57 #define PLY_UINT 6 58 #define PLY_FLOAT 7 59 #define PLY_DOUBLE 8 60 #define PLY_FLOAT32 9 61 #define PLY_UINT8 10 62 #define PLY_INT32 11 63 #define PLY_END_TYPE 12 64 65 #define PLY_SCALAR 0 66 #define PLY_LIST 1 67 68 69 typedef struct PlyProperty { /* description of a property */ 70 71 const char *name; /* property name */ 72 int external_type; /* file's data type */ 73 int internal_type; /* program's data type */ 74 int offset; /* offset bytes of prop in a struct */ 75 76 int is_list; /* 1 = list, 0 = scalar */ 77 int count_external; /* file's count type */ 78 int count_internal; /* program's count type */ 79 int count_offset; /* offset byte for list count */ 80 81 } PlyProperty; 82 83 typedef struct PlyElement { /* description of an element */ 84 char *name; /* element name */ 85 int num; /* number of elements in this object */ 86 int size; /* size of element (bytes) or -1 if variable */ 87 int nprops; /* number of properties for this element */ 88 PlyProperty **props; /* list of properties in the file */ 89 char *store_prop; /* flags: property wanted by user? */ 90 int other_offset; /* offset to un-asked-for props, or -1 if none*/ 91 int other_size; /* size of other_props structure */ 92 } PlyElement; 93 94 typedef struct PlyOtherProp { /* describes other properties in an element */ 95 char *name; /* element name */ 96 int size; /* size of other_props */ 97 int nprops; /* number of properties in other_props */ 98 PlyProperty **props; /* list of properties in other_props */ 99 } PlyOtherProp; 100 101 typedef struct OtherData { /* for storing other_props for an other element */ 102 void *other_props; 103 } OtherData; 104 105 typedef struct OtherElem { /* data for one "other" element */ 106 char *elem_name; /* names of other elements */ 107 int elem_count; /* count of instances of each element */ 108 OtherData **other_data; /* actual property data for the elements */ 109 PlyOtherProp *other_props; /* description of the property data */ 110 } OtherElem; 111 112 typedef struct PlyOtherElems { /* "other" elements, not interpreted by user */ 113 int num_elems; /* number of other elements */ 114 OtherElem *other_list; /* list of data for other elements */ 115 } PlyOtherElems; 116 117 typedef struct PlyFile { /* description of PLY file */ 118 FILE *fp; /* file pointer */ 119 int file_type; /* ascii or binary */ 120 float version; /* version number of file */ 121 int nelems; /* number of elements of object */ 122 PlyElement **elems; /* list of elements */ 123 int num_comments; /* number of comments */ 124 char **comments; /* list of comments */ 125 int num_obj_info; /* number of items of object information */ 126 char **obj_info; /* list of object info items */ 127 PlyElement *which_elem; /* which element we're currently writing */ 128 PlyOtherElems *other_elems; /* "other" elements from a PLY file */ 129 } PlyFile; 130 131 /* memory allocation */ 132 extern char *my_alloc(); 133 #define myalloc(mem_size) my_alloc((mem_size), __LINE__, __FILE__) 134 135 136 /*** delcaration of routines ***/ 137 138 extern PlyFile *ply_write(FILE *, int, char **, int); 139 extern PlyFile *ply_open_for_writing(char *, int, char **, int, float *); 140 extern void ply_describe_element(PlyFile *, char *, int, int, PlyProperty *); 141 extern void ply_describe_property(PlyFile *, char *, PlyProperty *); 142 extern void ply_element_count(PlyFile *, const char *, int); 143 extern void ply_header_complete(PlyFile *); 144 extern void ply_put_element_setup(PlyFile *, const char *); 145 extern void ply_put_element(PlyFile *, void *); 146 extern void ply_put_comment(PlyFile *, const char *); 147 extern void ply_put_obj_info(PlyFile *, const char *); 148 extern PlyFile *ply_read(FILE *, int *, char ***); 149 extern PlyFile *ply_open_for_reading( char *, int *, char ***, int *, float *); 150 extern PlyProperty **ply_get_element_description(PlyFile *, char *, int*, int*); 151 extern void ply_get_element_setup( PlyFile *, char *, int, PlyProperty *); 152 extern void ply_get_property(PlyFile *, const char *, PlyProperty *); 153 extern PlyOtherProp *ply_get_other_properties(PlyFile *, char *, int); 154 extern void ply_get_element(PlyFile *, void *); 155 extern char **ply_get_comments(PlyFile *, int *); 156 extern char **ply_get_obj_info(PlyFile *, int *); 157 extern void ply_close(PlyFile *); 158 extern void ply_get_info(PlyFile *, float *, int *); 159 extern PlyOtherElems *ply_get_other_element (PlyFile *, char *, int); 160 extern void ply_describe_other_elements ( PlyFile *, PlyOtherElems *); 161 extern void ply_put_other_elements (PlyFile *); 162 extern void ply_free_other_elements (PlyOtherElems *); 163 164 extern int equal_strings(const char *, const char *); 165 166 #endif /* !__PLY_H__ */ 167 168