ply.h
Go to the documentation of this file.
1 /* Copyright (c) 1994 The Board of Trustees of The Leland Stanford
2 Junior University. All rights reserved.
3 
4 Header for PLY polygon files.
5 
6 - Greg Turk, March 1994
7 
8 A PLY file contains a single polygonal _object_.
9 
10 An object is composed of lists of _elements_. Typical elements are
11 vertices, faces, edges and materials.
12 
13 Each type of element for a given object has one or more _properties_
14 associated with the element type. For instance, a vertex element may
15 have as properties three floating-point values x,y,z and three unsigned
16 chars for red, green and blue.
17 
18 ---------------------------------------------------------------
19 
20 Copyright (c) 1994 The Board of Trustees of The Leland Stanford
21 Junior University. All rights reserved.
22 
23 Permission to use, copy, modify and distribute this software and its
24 documentation for any purpose is hereby granted without fee, provided
25 that the above copyright notice and this permission notice appear in
26 all copies of this software and that you do not sell the software.
27 
28 THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
29 EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
30 WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
31 
32 */
33 
34 #ifndef SURGSIM_DATASTRUCTURES_PLY_H
35 #define SURGSIM_DATASTRUCTURES_PLY_H
36 
37 #ifdef __cplusplus
38 #include <cstddef>
39 
40 namespace SurgSim {
41 namespace DataStructures {
42 extern "C" {
43 #endif
44 
45 #include <stdio.h>
46 #include <stddef.h>
47 
48 #define PLY_ASCII 1 /* ascii PLY file */
49 #define PLY_BINARY_BE 2 /* binary PLY file, big endian */
50 #define PLY_BINARY_LE 3 /* binary PLY file, little endian */
51 
52 #define PLY_OKAY 0 /* ply routine worked okay */
53 #define PLY_ERROR -1 /* error in ply routine */
54 
55 /* scalar data types supported by PLY format */
56 
57 #define PLY_START_TYPE 0
58 #define PLY_CHAR 1
59 #define PLY_SHORT 2
60 #define PLY_INT 3
61 #define PLY_UCHAR 4
62 #define PLY_USHORT 5
63 #define PLY_UINT 6
64 #define PLY_FLOAT 7
65 #define PLY_DOUBLE 8
66 #define PLY_END_TYPE 9
67 
68 #define PLY_SCALAR 0
69 #define PLY_LIST 1
70 
71 
72 typedef struct PlyProperty { /* description of a property */
73 
74  char *name; /* property name */
75  int external_type; /* file's data type */
76  int internal_type; /* program's data type */
77  int offset; /* offset bytes of prop in a struct */
78 
79  int is_list; /* 1 = list, 0 = scalar */
80  int count_external; /* file's count type */
81  int count_internal; /* program's count type */
82  int count_offset; /* offset byte for list count */
83 
84 } PlyProperty;
85 
86 typedef struct PlyElement { /* description of an element */
87  char *name; /* element name */
88  int num; /* number of elements in this object */
89  int size; /* size of element (bytes) or -1 if variable */
90  int nprops; /* number of properties for this element */
91  PlyProperty **props; /* list of properties in the file */
92  char *store_prop; /* flags: property wanted by user? */
93  int other_offset; /* offset to un-asked-for props, or -1 if none*/
94  int other_size; /* size of other_props structure */
95 } PlyElement;
96 
97 typedef struct PlyOtherProp { /* describes other properties in an element */
98  char *name; /* element name */
99  int size; /* size of other_props */
100  int nprops; /* number of properties in other_props */
101  PlyProperty **props; /* list of properties in other_props */
102 } PlyOtherProp;
103 
104 typedef struct OtherData { /* for storing other_props for an other element */
105  void *other_props;
106 } OtherData;
107 
108 typedef struct OtherElem { /* data for one "other" element */
109  char *elem_name; /* names of other elements */
110  int elem_count; /* count of instances of each element */
111  OtherData **other_data; /* actual property data for the elements */
112  PlyOtherProp *other_props; /* description of the property data */
113 } OtherElem;
114 
115 typedef struct PlyOtherElems { /* "other" elements, not interpreted by user */
116  int num_elems; /* number of other elements */
117  OtherElem *other_list; /* list of data for other elements */
118 } PlyOtherElems;
119 
120 typedef struct PlyFile { /* description of PLY file */
121  FILE *fp; /* file pointer */
122  int file_type; /* ascii or binary */
123  float version; /* version number of file */
124  int nelems; /* number of elements of object */
125  PlyElement **elems; /* list of elements */
126  int num_comments; /* number of comments */
127  char **comments; /* list of comments */
128  int num_obj_info; /* number of items of object information */
129  char **obj_info; /* list of object info items */
130  PlyElement *which_elem; /* which element we're currently writing */
131  PlyOtherElems *other_elems; /* "other" elements from a PLY file */
132 } PlyFile;
133 
134 /* memory allocation */
135 extern char *my_alloc();
136 #define myalloc(mem_size) my_alloc((mem_size), __LINE__, __FILE__)
137 
138 
139 /*** delcaration of routines ***/
140 
141 extern PlyFile *ply_write(FILE *, int, char **, int);
142 extern PlyFile *ply_open_for_writing(const char *, int, char **, int, float *);
143 extern void ply_describe_element(PlyFile *, char *, int, int, PlyProperty *);
144 extern void ply_describe_property(PlyFile *, char *, PlyProperty *);
145 extern void ply_element_count(PlyFile *, char *, int);
146 extern void ply_header_complete(PlyFile * plyfile);
147 extern void ply_put_element_setup(PlyFile *, char *);
148 extern void ply_put_element(PlyFile *, void *);
149 extern void ply_put_comment(PlyFile *, char *);
150 extern void ply_put_obj_info(PlyFile *, char *);
151 extern PlyFile *ply_read(FILE *, int *, char ***);
152 extern PlyFile *ply_open_for_reading(const char *, int *, char ***, int *, float *);
153 extern PlyProperty **ply_get_element_description(PlyFile *, char *, int*, int*);
154 extern void ply_get_element_setup( PlyFile *, char *, int, PlyProperty *);
155 extern void ply_get_property(PlyFile *, char *, PlyProperty *);
156 extern PlyOtherProp *ply_get_other_properties(PlyFile *, char *, int);
157 extern void ply_get_element(PlyFile *, void *);
158 extern char **ply_get_comments(PlyFile *, int *);
159 extern char **ply_get_obj_info(PlyFile *, int *);
160 extern void ply_close(PlyFile * plyfile);
161 extern void ply_get_info(PlyFile *, float *, int *);
162 extern PlyOtherElems *ply_get_other_element (PlyFile *, char *, int);
164 extern void ply_put_other_elements (PlyFile *plyfile);
165 extern void ply_free_other_elements (PlyOtherElems *elements);
166 
167 extern int equal_strings(const char *,const char *);
168 
169 /* find an element in a plyfile's list */
170 PlyElement *find_element(PlyFile *, const char *);
171 
172 /* find a property in an element's list */
173 PlyProperty *find_property(PlyElement *, const char *, int *);
174 
175 
176 #ifdef __cplusplus
177 }
178 }
179 }
180 #endif
181 
182 #endif
183 
PlyFile::which_elem
PlyElement * which_elem
Definition: ply.h:130
find_element
PlyElement * find_element(PlyFile *, const char *)
Definition: ply.c:1472
ply_get_element_description
PlyProperty ** ply_get_element_description(PlyFile *, char *, int *, int *)
Definition: ply.c:864
PlyOtherProp
Definition: ply.h:97
ply_header_complete
void ply_header_complete(PlyFile *plyfile)
Definition: ply.c:433
PlyOtherElems
Definition: ply.h:115
PlyElement::other_offset
int other_offset
Definition: ply.h:93
PlyOtherProp
struct PlyOtherProp PlyOtherProp
PlyFile::version
float version
Definition: ply.h:123
PlyElement::name
char * name
Definition: ply.h:87
ply_get_obj_info
char ** ply_get_obj_info(PlyFile *, int *)
Definition: ply.c:1035
PlyOtherElems
struct PlyOtherElems PlyOtherElems
PlyProperty::internal_type
int internal_type
Definition: ply.h:76
find_property
PlyProperty * find_property(PlyElement *, const char *, int *)
Definition: ply.c:1495
PlyOtherElems::other_list
OtherElem * other_list
Definition: ply.h:117
PlyFile::obj_info
char ** obj_info
Definition: ply.h:129
ply_close
void ply_close(PlyFile *plyfile)
Definition: ply.c:1362
PlyFile::elems
PlyElement ** elems
Definition: ply.h:125
ply_put_element
void ply_put_element(PlyFile *, void *)
Definition: ply.c:528
PlyFile::file_type
int file_type
Definition: ply.h:122
ply_put_obj_info
void ply_put_obj_info(PlyFile *, char *)
Definition: ply.c:663
PlyOtherProp::props
PlyProperty ** props
Definition: ply.h:101
ply_open_for_reading
PlyFile * ply_open_for_reading(const char *, int *, char ***, int *, float *)
Definition: ply.c:819
PlyProperty::is_list
int is_list
Definition: ply.h:79
ply_get_other_element
PlyOtherElems * ply_get_other_element(PlyFile *, char *, int)
Definition: ply.c:1211
ply_get_property
void ply_get_property(PlyFile *, char *, PlyProperty *)
Definition: ply.c:957
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
PlyProperty::count_external
int count_external
Definition: ply.h:80
ply_open_for_writing
PlyFile * ply_open_for_writing(const char *, int, char **, int, float *)
Definition: ply.c:207
PlyElement::other_size
int other_size
Definition: ply.h:94
PlyProperty
Definition: ply.h:72
PlyFile::other_elems
PlyOtherElems * other_elems
Definition: ply.h:131
ply_put_comment
void ply_put_comment(PlyFile *, char *)
Definition: ply.c:640
ply_describe_other_elements
void ply_describe_other_elements(PlyFile *, PlyOtherElems *)
Definition: ply.c:1282
PlyElement
Definition: ply.h:86
OtherData::other_props
void * other_props
Definition: ply.h:105
PlyOtherProp::size
int size
Definition: ply.h:99
PlyOtherProp::nprops
int nprops
Definition: ply.h:100
PlyProperty::offset
int offset
Definition: ply.h:77
PlyProperty::external_type
int external_type
Definition: ply.h:75
PlyElement::num
int num
Definition: ply.h:88
PlyFile::num_obj_info
int num_obj_info
Definition: ply.h:128
my_alloc
char * my_alloc()
PlyElement::store_prop
char * store_prop
Definition: ply.h:92
OtherElem::elem_name
char * elem_name
Definition: ply.h:109
equal_strings
int equal_strings(const char *, const char *)
Definition: ply.c:1448
OtherElem::other_props
PlyOtherProp * other_props
Definition: ply.h:112
ply_element_count
void ply_element_count(PlyFile *, char *, int)
Definition: ply.c:407
ply_get_other_properties
PlyOtherProp * ply_get_other_properties(PlyFile *, char *, int)
Definition: ply.c:1122
PlyProperty::count_internal
int count_internal
Definition: ply.h:81
PlyProperty
struct PlyProperty PlyProperty
PlyFile::fp
FILE * fp
Definition: ply.h:121
ply_describe_property
void ply_describe_property(PlyFile *, char *, PlyProperty *)
Definition: ply.c:303
PlyProperty::count_offset
int count_offset
Definition: ply.h:82
PlyOtherProp::name
char * name
Definition: ply.h:98
OtherElem
struct OtherElem OtherElem
ply_get_element
void ply_get_element(PlyFile *, void *)
Definition: ply.c:998
ply_get_element_setup
void ply_get_element_setup(PlyFile *, char *, int, PlyProperty *)
Definition: ply.c:907
ply_get_info
void ply_get_info(PlyFile *, float *, int *)
Definition: ply.c:1435
PlyFile::nelems
int nelems
Definition: ply.h:124
OtherElem::other_data
OtherData ** other_data
Definition: ply.h:111
OtherData
Definition: ply.h:104
PlyFile
struct PlyFile PlyFile
PlyElement::nprops
int nprops
Definition: ply.h:90
OtherData
struct OtherData OtherData
ply_get_comments
char ** ply_get_comments(PlyFile *, int *)
Definition: ply.c:1017
ply_put_other_elements
void ply_put_other_elements(PlyFile *plyfile)
Definition: ply.c:1314
ply_free_other_elements
void ply_free_other_elements(PlyOtherElems *elements)
Definition: ply.c:1343
ply_write
PlyFile * ply_write(FILE *, int, char **, int)
Definition: ply.c:152
PlyElement::props
PlyProperty ** props
Definition: ply.h:91
PlyFile
Definition: ply.h:120
PlyFile::num_comments
int num_comments
Definition: ply.h:126
OtherElem
Definition: ply.h:108
OtherElem::elem_count
int elem_count
Definition: ply.h:110
PlyElement::size
int size
Definition: ply.h:89
ply_read
PlyFile * ply_read(FILE *, int *, char ***)
Definition: ply.c:700
PlyFile::comments
char ** comments
Definition: ply.h:127
PlyProperty::name
char * name
Definition: ply.h:74
PlyElement
struct PlyElement PlyElement
ply_describe_element
void ply_describe_element(PlyFile *, char *, int, int, PlyProperty *)
Definition: ply.c:259
PlyOtherElems::num_elems
int num_elems
Definition: ply.h:116
ply_put_element_setup
void ply_put_element_setup(PlyFile *, char *)
Definition: ply.c:505