[749] | 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 | #ifdef __cplusplus
|
---|
| 37 | extern "C" {
|
---|
| 38 | #endif
|
---|
| 39 |
|
---|
| 40 | #include <stdlib.h>
|
---|
| 41 | #include <stdio.h>
|
---|
| 42 | #include <stddef.h>
|
---|
| 43 | #include <string.h>
|
---|
| 44 |
|
---|
| 45 | #define PLY_ASCII 1 /* ascii PLY file */
|
---|
| 46 | #define PLY_BINARY_BE 2 /* binary PLY file, big endian */
|
---|
| 47 | #define PLY_BINARY_LE 3 /* binary PLY file, little endian */
|
---|
| 48 | #define PLY_BINARY_NATIVE 4 /* binary PLY file, same endianness as
|
---|
| 49 | current architecture */
|
---|
| 50 |
|
---|
| 51 | #define PLY_OKAY 0 /* ply routine worked okay */
|
---|
| 52 | #define PLY_ERROR -1 /* error in ply routine */
|
---|
| 53 |
|
---|
| 54 | /* scalar data types supported by PLY format */
|
---|
| 55 |
|
---|
| 56 | #define PLY_START_TYPE 0
|
---|
| 57 | #define PLY_CHAR 1
|
---|
| 58 | #define PLY_SHORT 2
|
---|
| 59 | #define PLY_INT 3
|
---|
| 60 | #define PLY_UCHAR 4
|
---|
| 61 | #define PLY_USHORT 5
|
---|
| 62 | #define PLY_UINT 6
|
---|
| 63 | #define PLY_FLOAT 7
|
---|
| 64 | #define PLY_DOUBLE 8
|
---|
| 65 | #define PLY_END_TYPE 9
|
---|
| 66 |
|
---|
| 67 | #define PLY_SCALAR 0
|
---|
| 68 | #define PLY_LIST 1
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 | typedef struct PlyProperty { /* description of a property */
|
---|
| 72 |
|
---|
| 73 | char *name; /* property name */
|
---|
| 74 | int external_type; /* file's data type */
|
---|
| 75 | int internal_type; /* program's data type */
|
---|
| 76 | int offset; /* offset bytes of prop in a struct */
|
---|
| 77 |
|
---|
| 78 | int is_list; /* 1 = list, 0 = scalar */
|
---|
| 79 | int count_external; /* file's count type */
|
---|
| 80 | int count_internal; /* program's count type */
|
---|
| 81 | int count_offset; /* offset byte for list count */
|
---|
| 82 |
|
---|
| 83 | } PlyProperty;
|
---|
| 84 |
|
---|
| 85 | typedef struct PlyElement { /* description of an element */
|
---|
| 86 | char *name; /* element name */
|
---|
| 87 | int num; /* number of elements in this object */
|
---|
| 88 | int size; /* size of element (bytes) or -1 if variable */
|
---|
| 89 | int nprops; /* number of properties for this element */
|
---|
| 90 | PlyProperty **props; /* list of properties in the file */
|
---|
| 91 | char *store_prop; /* flags: property wanted by user? */
|
---|
| 92 | int other_offset; /* offset to un-asked-for props, or -1 if none*/
|
---|
| 93 | int other_size; /* size of other_props structure */
|
---|
| 94 | } PlyElement;
|
---|
| 95 |
|
---|
| 96 | typedef struct PlyOtherProp { /* describes other properties in an element */
|
---|
| 97 | char *name; /* element name */
|
---|
| 98 | int size; /* size of other_props */
|
---|
| 99 | int nprops; /* number of properties in other_props */
|
---|
| 100 | PlyProperty **props; /* list of properties in other_props */
|
---|
| 101 | } PlyOtherProp;
|
---|
| 102 |
|
---|
| 103 | typedef struct OtherData { /* for storing other_props for an other element */
|
---|
| 104 | void *other_props;
|
---|
| 105 | } OtherData;
|
---|
| 106 |
|
---|
| 107 | typedef struct OtherElem { /* data for one "other" element */
|
---|
| 108 | char *elem_name; /* names of other elements */
|
---|
| 109 | int elem_count; /* count of instances of each element */
|
---|
| 110 | OtherData **other_data; /* actual property data for the elements */
|
---|
| 111 | PlyOtherProp *other_props; /* description of the property data */
|
---|
| 112 | } OtherElem;
|
---|
| 113 |
|
---|
| 114 | typedef struct PlyOtherElems { /* "other" elements, not interpreted by user */
|
---|
| 115 | int num_elems; /* number of other elements */
|
---|
| 116 | OtherElem *other_list; /* list of data for other elements */
|
---|
| 117 | } PlyOtherElems;
|
---|
| 118 |
|
---|
| 119 | typedef struct PlyFile { /* description of PLY file */
|
---|
| 120 | FILE *fp; /* file pointer */
|
---|
| 121 | int file_type; /* ascii or binary */
|
---|
| 122 | float version; /* version number of file */
|
---|
| 123 | int nelems; /* number of elements of object */
|
---|
| 124 | PlyElement **elems; /* list of elements */
|
---|
| 125 | int num_comments; /* number of comments */
|
---|
| 126 | char **comments; /* list of comments */
|
---|
| 127 | int num_obj_info; /* number of items of object information */
|
---|
| 128 | char **obj_info; /* list of object info items */
|
---|
| 129 | PlyElement *which_elem; /* which element we're currently writing */
|
---|
| 130 | PlyOtherElems *other_elems; /* "other" elements from a PLY file */
|
---|
| 131 | } PlyFile;
|
---|
| 132 |
|
---|
| 133 | /* memory allocation */
|
---|
| 134 | extern char *my_alloc();
|
---|
| 135 | #define myalloc(mem_size) my_alloc((mem_size), __LINE__, __FILE__)
|
---|
| 136 |
|
---|
| 137 | #ifndef ALLOCN
|
---|
| 138 | #define REALLOCN(PTR,TYPE,OLD_N,NEW_N) \
|
---|
| 139 | { \
|
---|
| 140 | if ((OLD_N) == 0) \
|
---|
| 141 | { ALLOCN((PTR),TYPE,(NEW_N));} \
|
---|
| 142 | else \
|
---|
| 143 | { \
|
---|
| 144 | (PTR) = (TYPE *)realloc((PTR),(NEW_N)*sizeof(TYPE)); \
|
---|
| 145 | if (((PTR) == NULL) && ((NEW_N) != 0)) \
|
---|
| 146 | { \
|
---|
| 147 | fprintf(stderr, "Memory reallocation failed on line %d in %s\n", \
|
---|
| 148 | __LINE__, __FILE__); \
|
---|
| 149 | fprintf(stderr, " tried to reallocate %d->%d\n", \
|
---|
| 150 | (OLD_N), (NEW_N)); \
|
---|
| 151 | exit(-1); \
|
---|
| 152 | } \
|
---|
| 153 | if ((NEW_N)>(OLD_N)) \
|
---|
| 154 | memset((char *)(PTR)+(OLD_N)*sizeof(TYPE), 0, \
|
---|
| 155 | ((NEW_N)-(OLD_N))*sizeof(TYPE)); \
|
---|
| 156 | } \
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | #define ALLOCN(PTR,TYPE,N) \
|
---|
| 160 | { (PTR) = (TYPE *) calloc(((unsigned)(N)),sizeof(TYPE));\
|
---|
| 161 | if ((PTR) == NULL) { \
|
---|
| 162 | fprintf(stderr, "Memory allocation failed on line %d in %s\n", \
|
---|
| 163 | __LINE__, __FILE__); \
|
---|
| 164 | exit(-1); \
|
---|
| 165 | } \
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 |
|
---|
| 169 | #define FREE(PTR) { free((PTR)); (PTR) = NULL; }
|
---|
| 170 | #endif
|
---|
| 171 |
|
---|
| 172 |
|
---|
| 173 | /*** delcaration of routines ***/
|
---|
| 174 |
|
---|
| 175 | extern PlyFile *ply_write(FILE *, int, char **, int);
|
---|
| 176 | extern PlyFile *ply_open_for_writing(char *, int, char **, int, float *);
|
---|
| 177 | extern void ply_describe_element(PlyFile *, char *, int, int, PlyProperty *);
|
---|
| 178 | extern void ply_describe_property(PlyFile *, char *, PlyProperty *);
|
---|
| 179 | extern void ply_element_count(PlyFile *, char *, int);
|
---|
| 180 | extern void ply_header_complete(PlyFile *);
|
---|
| 181 | extern void ply_put_element_setup(PlyFile *, char *);
|
---|
| 182 | extern void ply_put_element(PlyFile *, void *);
|
---|
| 183 | extern void ply_put_comment(PlyFile *, char *);
|
---|
| 184 | extern void ply_put_obj_info(PlyFile *, char *);
|
---|
| 185 | extern PlyFile *ply_read(FILE *, int *, char ***);
|
---|
| 186 | extern PlyFile *ply_open_for_reading( char *, int *, char ***, int *, float *);
|
---|
| 187 | extern PlyProperty **ply_get_element_description(PlyFile *, char *, int*, int*);
|
---|
| 188 | extern void ply_get_element_setup( PlyFile *, char *, int, PlyProperty *);
|
---|
| 189 | extern void ply_get_property(PlyFile *, char *, PlyProperty *);
|
---|
| 190 | extern PlyOtherProp *ply_get_other_properties(PlyFile *, char *, int);
|
---|
| 191 | extern void ply_get_element(PlyFile *, void *);
|
---|
| 192 | extern char **ply_get_comments(PlyFile *, int *);
|
---|
| 193 | extern char **ply_get_obj_info(PlyFile *, int *);
|
---|
| 194 | extern void ply_close(PlyFile *);
|
---|
| 195 | extern void ply_get_info(PlyFile *, float *, int *);
|
---|
| 196 | extern PlyOtherElems *ply_get_other_element (PlyFile *, char *, int);
|
---|
| 197 | extern void ply_describe_other_elements ( PlyFile *, PlyOtherElems *);
|
---|
| 198 | extern void ply_put_other_elements (PlyFile *);
|
---|
| 199 | extern void ply_free_other_elements (PlyOtherElems *);
|
---|
| 200 | extern void ply_describe_other_properties(PlyFile *, PlyOtherProp *, int);
|
---|
| 201 |
|
---|
| 202 | extern int equal_strings(char *, char *);
|
---|
| 203 |
|
---|
| 204 |
|
---|
| 205 | #ifdef __cplusplus
|
---|
| 206 | }
|
---|
| 207 | #endif
|
---|
| 208 | #endif /* !__PLY_H__ */
|
---|
| 209 |
|
---|
| 210 | |
---|