Main Page Class Hierarchy Compound List File List Compound Members File Members

ply.h

Go to the documentation of this file.
00001 /*
00002 
00003 Header for PLY polygon files.
00004 
00005 - Greg Turk, March 1994
00006 
00007 A PLY file contains a single polygonal _object_.
00008 
00009 An object is composed of lists of _elements_. Typical elements are
00010 vertices, faces, edges and materials.
00011 
00012 Each type of element for a given object has one or more _properties_
00013 associated with the element type. For instance, a vertex element may
00014 have as properties three floating-point values x,y,z and three unsigned
00015 chars for red, green and blue.
00016 
00017 ---------------------------------------------------------------
00018 
00019 Copyright (c) 1994 The Board of Trustees of The Leland Stanford
00020 Junior University. All rights reserved. 
00021 
00022 Permission to use, copy, modify and distribute this software and its 
00023 documentation for any purpose is hereby granted without fee, provided 
00024 that the above copyright notice and this permission notice appear in 
00025 all copies of this software and that you do not sell the software. 
00026 
00027 THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND, 
00028 EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
00029 WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 
00030 
00031 */
00032 
00033 #ifndef __PLY_H__
00034 #define __PLY_H__
00035 
00036 #ifdef __cplusplus
00037 extern "C" {
00038 #endif
00039 
00040 #include <stdlib.h>
00041 #include <stdio.h>
00042 #include <stddef.h>
00043 #include <string.h>
00044 
00045  #define PLY_ASCII 1 /* ascii PLY file */
00046  #define PLY_BINARY_BE 2 /* binary PLY file, big endian */
00047  #define PLY_BINARY_LE 3 /* binary PLY file, little endian */
00048  #define PLY_BINARY_NATIVE 4 /* binary PLY file, same endianness as
00049 current architecture */
00050 
00051  #define PLY_OKAY 0 /* ply routine worked okay */
00052  #define PLY_ERROR -1 /* error in ply routine */
00053 
00054 /* scalar data types supported by PLY format */
00055 
00056  #define PLY_START_TYPE 0
00057  #define PLY_CHAR 1
00058  #define PLY_SHORT 2
00059  #define PLY_INT 3
00060  #define PLY_UCHAR 4
00061  #define PLY_USHORT 5
00062  #define PLY_UINT 6
00063  #define PLY_FLOAT 7
00064  #define PLY_DOUBLE 8
00065  #define PLY_END_TYPE 9
00066 
00067  #define PLY_SCALAR 0
00068  #define PLY_LIST 1
00069 
00070 
00071  typedef struct PlyProperty { /* description of a property */
00072 
00073  char *name; /* property name */
00074  int external_type; /* file's data type */
00075  int internal_type; /* program's data type */
00076  int offset; /* offset bytes of prop in a struct */
00077 
00078  int is_list; /* 1 = list, 0 = scalar */
00079  int count_external; /* file's count type */
00080  int count_internal; /* program's count type */
00081  int count_offset; /* offset byte for list count */
00082 
00083 } PlyProperty;
00084 
00085  typedef struct PlyElement { /* description of an element */
00086  char *name; /* element name */
00087  int num; /* number of elements in this object */
00088  int size; /* size of element (bytes) or -1 if variable */
00089  int nprops; /* number of properties for this element */
00090  PlyProperty **props; /* list of properties in the file */
00091  char *store_prop; /* flags: property wanted by user? */
00092  int other_offset; /* offset to un-asked-for props, or -1 if none*/
00093  int other_size; /* size of other_props structure */
00094 } PlyElement;
00095 
00096  typedef struct PlyOtherProp { /* describes other properties in an element */
00097  char *name; /* element name */
00098  int size; /* size of other_props */
00099  int nprops; /* number of properties in other_props */
00100  PlyProperty **props; /* list of properties in other_props */
00101 } PlyOtherProp;
00102 
00103  typedef struct OtherData { /* for storing other_props for an other element */
00104  void *other_props;
00105 } OtherData;
00106 
00107  typedef struct OtherElem { /* data for one "other" element */
00108  char *elem_name; /* names of other elements */
00109  int elem_count; /* count of instances of each element */
00110  OtherData **other_data; /* actual property data for the elements */
00111  PlyOtherProp *other_props; /* description of the property data */
00112 } OtherElem;
00113 
00114  typedef struct PlyOtherElems { /* "other" elements, not interpreted by user */
00115  int num_elems; /* number of other elements */
00116  OtherElem *other_list; /* list of data for other elements */
00117 } PlyOtherElems;
00118 
00119  typedef struct PlyFile { /* description of PLY file */
00120  FILE *fp; /* file pointer */
00121  int file_type; /* ascii or binary */
00122  float version; /* version number of file */
00123  int nelems; /* number of elements of object */
00124  PlyElement **elems; /* list of elements */
00125  int num_comments; /* number of comments */
00126  char **comments; /* list of comments */
00127  int num_obj_info; /* number of items of object information */
00128  char **obj_info; /* list of object info items */
00129  PlyElement *which_elem; /* which element we're currently writing */
00130  PlyOtherElems *other_elems; /* "other" elements from a PLY file */
00131 } PlyFile;
00132 
00133 /* memory allocation */
00134 extern char *my_alloc();
00135  #define myalloc(mem_size) my_alloc((mem_size), __LINE__, __FILE__)
00136 
00137 #ifndef ALLOCN
00138  #define REALLOCN(PTR,TYPE,OLD_N,NEW_N) \
00139 { \
00140 if ((OLD_N) == 0) \
00141 { ALLOCN((PTR),TYPE,(NEW_N));} \
00142 else \
00143 { \
00144 (PTR) = (TYPE *)realloc((PTR),(NEW_N)*sizeof(TYPE)); \
00145 if (((PTR) == NULL) && ((NEW_N) != 0)) \
00146 { \
00147 fprintf(stderr, "Memory reallocation failed on line %d in %s\n", \
00148 __LINE__, __FILE__); \
00149 fprintf(stderr, " tried to reallocate %d->%d\n", \
00150 (OLD_N), (NEW_N)); \
00151 exit(-1); \
00152 } \
00153 if ((NEW_N)>(OLD_N)) \
00154 memset((char *)(PTR)+(OLD_N)*sizeof(TYPE), 0, \
00155 ((NEW_N)-(OLD_N))*sizeof(TYPE)); \
00156 } \
00157 }
00158 
00159  #define ALLOCN(PTR,TYPE,N) \
00160 { (PTR) = (TYPE *) calloc(((unsigned)(N)),sizeof(TYPE));\
00161 if ((PTR) == NULL) { \
00162 fprintf(stderr, "Memory allocation failed on line %d in %s\n", \
00163 __LINE__, __FILE__); \
00164 exit(-1); \
00165 } \
00166 }
00167 
00168 
00169  #define FREE(PTR) { free((PTR)); (PTR) = NULL; }
00170 #endif
00171 
00172 
00173 /*** delcaration of routines ***/
00174 
00175 extern PlyFile *ply_write(FILE *, int, char **, int);
00176 extern PlyFile *ply_open_for_writing(char *, int, char **, int, float *);
00177 extern void ply_describe_element(PlyFile *, char *, int, int, PlyProperty *);
00178 extern void ply_describe_property(PlyFile *, char *, PlyProperty *);
00179 extern void ply_element_count(PlyFile *, char *, int);
00180 extern void ply_header_complete(PlyFile *);
00181 extern void ply_put_element_setup(PlyFile *, char *);
00182 extern void ply_put_element(PlyFile *, void *);
00183 extern void ply_put_comment(PlyFile *, char *);
00184 extern void ply_put_obj_info(PlyFile *, char *);
00185 extern PlyFile *ply_read(FILE *, int *, char ***);
00186 extern PlyFile *ply_open_for_reading( char *, int *, char ***, int *, float *);
00187 extern PlyProperty **ply_get_element_description(PlyFile *, char *, int*, int*);
00188 extern void ply_get_element_setup( PlyFile *, char *, int, PlyProperty *);
00189 extern void ply_get_property(PlyFile *, char *, PlyProperty *);
00190 extern PlyOtherProp *ply_get_other_properties(PlyFile *, char *, int);
00191 extern void ply_get_element(PlyFile *, void *);
00192 extern char **ply_get_comments(PlyFile *, int *);
00193 extern char **ply_get_obj_info(PlyFile *, int *);
00194 extern void ply_close(PlyFile *);
00195 extern void ply_get_info(PlyFile *, float *, int *);
00196 extern PlyOtherElems *ply_get_other_element (PlyFile *, char *, int);
00197 extern void ply_describe_other_elements ( PlyFile *, PlyOtherElems *);
00198 extern void ply_put_other_elements (PlyFile *);
00199 extern void ply_free_other_elements (PlyOtherElems *);
00200 extern void ply_describe_other_properties(PlyFile *, PlyOtherProp *, int);
00201 
00202 extern int equal_strings(char *, char *);
00203 
00204 
00205 #ifdef __cplusplus
00206 }
00207 #endif
00208 #endif /* !__PLY_H__ */
00209 

Generated at Sat Aug 5 00:17:02 2000 for Graphics Class Library by doxygen 1.1.0 written by Dimitri van Heesch, © 1997-2000

AltStyle によって変換されたページ (->オリジナル) /