Subversion Repositories gelsvn

Rev

Rev 333 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 333 Rev 393
1
/*
1
/*
2
 
2
 
3
Header for PLY polygon files.
3
Header for PLY polygon files.
4
 
4
 
5
- Greg Turk, March 1994
5
- Greg Turk, March 1994
6
 
6
 
7
A PLY file contains a single polygonal _object_.
7
A PLY file contains a single polygonal _object_.
8
 
8
 
9
An object is composed of lists of _elements_.  Typical elements are
9
An object is composed of lists of _elements_.  Typical elements are
10
vertices, faces, edges and materials.
10
vertices, faces, edges and materials.
11
 
11
 
12
Each type of element for a given object has one or more _properties_
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
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
14
have as properties three floating-point values x,y,z and three unsigned
15
chars for red, green and blue.
15
chars for red, green and blue.
16
 
16
 
17
---------------------------------------------------------------
17
---------------------------------------------------------------
18
 
18
 
19
Copyright (c) 1994 The Board of Trustees of The Leland Stanford
19
Copyright (c) 1994 The Board of Trustees of The Leland Stanford
20
Junior University.  All rights reserved.   
20
Junior University.  All rights reserved.   
21
  
21
  
22
Permission to use, copy, modify and distribute this software and its   
22
Permission to use, copy, modify and distribute this software and its   
23
documentation for any purpose is hereby granted without fee, provided   
23
documentation for any purpose is hereby granted without fee, provided   
24
that the above copyright notice and this permission notice appear in   
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.   
25
all copies of this software and that you do not sell the software.   
26
  
26
  
27
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,   
27
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,   
28
EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY   
28
EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY   
29
WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.   
29
WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.   
30
 
30
 
31
*/
31
*/
32
 
32
 
33
#ifndef __PLY_H__
33
#ifndef __PLY_H__
34
#define __PLY_H__
34
#define __PLY_H__
35
 
35
 
36
#ifdef __cplusplus
36
#ifdef __cplusplus
37
extern "C" {
37
extern "C" {
38
#endif
38
#endif
39
 
39
 
40
#include <stdio.h>
40
#include <stdio.h>
41
#include <stddef.h>
41
#include <stddef.h>
42
 
42
 
43
#ifdef LINUX
43
#ifdef LINUX
44
#include <sys/types.h>
44
#include <sys/types.h>
45
#endif
45
#endif
46
 
46
 
47
#define PLY_ASCII      1        /* ascii PLY file */
47
#define PLY_ASCII      1        /* ascii PLY file */
48
#define PLY_BINARY_BE  2        /* binary PLY file, big endian */
48
#define PLY_BINARY_BE  2        /* binary PLY file, big endian */
49
#define PLY_BINARY_LE  3        /* binary PLY file, little endian */
49
#define PLY_BINARY_LE  3        /* binary PLY file, little endian */
50
 
50
 
51
#define PLY_OKAY    0           /* ply routine worked okay */
51
#define PLY_OKAY    0           /* ply routine worked okay */
52
#define PLY_ERROR  -1           /* error in ply routine */
52
#define PLY_ERROR  -1           /* error in ply routine */
53
 
53
 
54
/* Define BIG/LITTLE_ENDIAN FLAGS if not already */
54
/* Define BIG/LITTLE_ENDIAN FLAGS if not already */
55
 
55
 
56
#ifndef BIG_ENDIAN
56
#ifndef BIG_ENDIAN
57
#define BIG_ENDIAN      4321	/* Flag for native Big Endian machines */
57
#define BIG_ENDIAN      4321	/* Flag for native Big Endian machines */
58
#endif
58
#endif
59
#ifndef LITTLE_ENDIAN
59
#ifndef LITTLE_ENDIAN
60
#define LITTLE_ENDIAN   1234	/* Flag for native Little Endian machines */
60
#define LITTLE_ENDIAN   1234	/* Flag for native Little Endian machines */
61
#endif
61
#endif
62
 
62
 
63
  /* Define BYTE_ORDER for big/little endian machines */
63
  /* Define BYTE_ORDER for big/little endian machines */
64
/* This assumes Linux/Win32 are on PC, all else is SGI... */
64
/* This assumes Linux/Win32 are on PC, all else is SGI... */
65
#ifndef BYTE_ORDER
65
#ifndef BYTE_ORDER
66
#if defined (LINUX) || defined (WIN32)
66
#if defined (LINUX) || defined (WIN32)
67
#define BYTE_ORDER LITTLE_ENDIAN
67
#define BYTE_ORDER LITTLE_ENDIAN
68
#else
68
#else
69
#define BYTE_ORDER BIG_ENDIAN
69
#define BYTE_ORDER BIG_ENDIAN
70
#endif
70
#endif
71
#endif
71
#endif
72
 
72
 
73
/* scalar data types supported by PLY format */
73
/* scalar data types supported by PLY format */
74
 
74
 
75
#define PLY_START_TYPE 0
75
#define PLY_START_TYPE 0
76
#define PLY_CHAR       1
76
#define PLY_CHAR       1
77
#define PLY_SHORT      2
77
#define PLY_SHORT      2
78
#define PLY_INT        3
78
#define PLY_INT        3
79
#define PLY_UCHAR      4
79
#define PLY_UCHAR      4
80
#define PLY_USHORT     5
80
#define PLY_USHORT     5
81
#define PLY_UINT       6
81
#define PLY_UINT       6
82
#define PLY_FLOAT      7
82
#define PLY_FLOAT      7
83
#define PLY_DOUBLE     8
83
#define PLY_DOUBLE     8
84
#define PLY_END_TYPE   9
84
#define PLY_END_TYPE   9
85
 
85
 
86
#define  PLY_SCALAR  0
86
#define  PLY_SCALAR  0
87
#define  PLY_LIST    1
87
#define  PLY_LIST    1
88
 
88
 
89
 
89
 
90
typedef struct PlyProperty {    /* description of a property */
90
typedef struct PlyProperty {    /* description of a property */
91
 
91
 
92
  char *name;                           /* property name */
92
  char *name;                           /* property name */
93
  int external_type;                    /* file's data type */
93
  int external_type;                    /* file's data type */
94
  int internal_type;                    /* program's data type */
94
  int internal_type;                    /* program's data type */
95
  int offset;                           /* offset bytes of prop in a struct */
95
  int offset;                           /* offset bytes of prop in a struct */
96
 
96
 
97
  int is_list;                          /* 1 = list, 0 = scalar */
97
  int is_list;                          /* 1 = list, 0 = scalar */
98
  int count_external;                   /* file's count type */
98
  int count_external;                   /* file's count type */
99
  int count_internal;                   /* program's count type */
99
  int count_internal;                   /* program's count type */
100
  int count_offset;                     /* offset byte for list count */
100
  int count_offset;                     /* offset byte for list count */
101
 
101
 
102
} PlyProperty;
102
} PlyProperty;
103
 
103
 
104
typedef struct PlyElement {     /* description of an element */
104
typedef struct PlyElement {     /* description of an element */
105
  char *name;                   /* element name */
105
  char *name;                   /* element name */
106
  int num;                      /* number of elements in this object */
106
  int num;                      /* number of elements in this object */
107
  int size;                     /* size of element (bytes) or -1 if variable */
107
  int size;                     /* size of element (bytes) or -1 if variable */
108
  int nprops;                   /* number of properties for this element */
108
  int nprops;                   /* number of properties for this element */
109
  PlyProperty **props;          /* list of properties in the file */
109
  PlyProperty **props;          /* list of properties in the file */
110
  char *store_prop;             /* flags: property wanted by user? */
110
  char *store_prop;             /* flags: property wanted by user? */
111
  int other_offset;             /* offset to un-asked-for props, or -1 if none*/
111
  int other_offset;             /* offset to un-asked-for props, or -1 if none*/
112
  int other_size;               /* size of other_props structure */
112
  int other_size;               /* size of other_props structure */
113
} PlyElement;
113
} PlyElement;
114
 
114
 
115
typedef struct PlyOtherProp {   /* describes other properties in an element */
115
typedef struct PlyOtherProp {   /* describes other properties in an element */
116
  char *name;                   /* element name */
116
  char *name;                   /* element name */
117
  int size;                     /* size of other_props */
117
  int size;                     /* size of other_props */
118
  int nprops;                   /* number of properties in other_props */
118
  int nprops;                   /* number of properties in other_props */
119
  PlyProperty **props;          /* list of properties in other_props */
119
  PlyProperty **props;          /* list of properties in other_props */
120
} PlyOtherProp;
120
} PlyOtherProp;
121
 
121
 
122
typedef struct OtherData { /* for storing other_props for an other element */
122
typedef struct OtherData { /* for storing other_props for an other element */
123
  void *other_props;
123
  void *other_props;
124
} OtherData;
124
} OtherData;
125
 
125
 
126
typedef struct OtherElem {     /* data for one "other" element */
126
typedef struct OtherElem {     /* data for one "other" element */
127
  char *elem_name;             /* names of other elements */
127
  char *elem_name;             /* names of other elements */
128
  int elem_count;              /* count of instances of each element */
128
  int elem_count;              /* count of instances of each element */
129
  OtherData **other_data;      /* actual property data for the elements */
129
  OtherData **other_data;      /* actual property data for the elements */
130
  PlyOtherProp *other_props;   /* description of the property data */
130
  PlyOtherProp *other_props;   /* description of the property data */
131
} OtherElem;
131
} OtherElem;
132
 
132
 
133
typedef struct PlyOtherElems {  /* "other" elements, not interpreted by user */
133
typedef struct PlyOtherElems {  /* "other" elements, not interpreted by user */
134
  int num_elems;                /* number of other elements */
134
  int num_elems;                /* number of other elements */
135
  OtherElem *other_list;        /* list of data for other elements */
135
  OtherElem *other_list;        /* list of data for other elements */
136
} PlyOtherElems;
136
} PlyOtherElems;
137
 
137
 
138
typedef struct PlyFile {        /* description of PLY file */
138
typedef struct PlyFile {        /* description of PLY file */
139
  FILE *fp;                     /* file pointer */
139
  FILE *fp;                     /* file pointer */
140
  int file_type;                /* ascii or binary */
140
  int file_type;                /* ascii or binary */
141
  float version;                /* version number of file */
141
  float version;                /* version number of file */
142
  int nelems;                   /* number of elements of object */
142
  int nelems;                   /* number of elements of object */
143
  PlyElement **elems;           /* list of elements */
143
  PlyElement **elems;           /* list of elements */
144
  int num_comments;             /* number of comments */
144
  int num_comments;             /* number of comments */
145
  char **comments;              /* list of comments */
145
  char **comments;              /* list of comments */
146
  int num_obj_info;             /* number of items of object information */
146
  int num_obj_info;             /* number of items of object information */
147
  char **obj_info;              /* list of object info items */
147
  char **obj_info;              /* list of object info items */
148
  PlyElement *which_elem;       /* which element we're currently writing */
148
  PlyElement *which_elem;       /* which element we're currently writing */
149
  PlyOtherElems *other_elems;   /* "other" elements from a PLY file */
149
  PlyOtherElems *other_elems;   /* "other" elements from a PLY file */
150
} PlyFile;
150
} PlyFile;
151
 
151
 
152
 
152
 
153
/*** delcaration of routines ***/
153
/*** delcaration of routines ***/
154
 
154
 
155
extern PlyFile *ply_write(FILE *, int, char **, int);
155
extern PlyFile *ply_write(FILE *, int, char **, int);
156
extern PlyFile *ply_open_for_writing(const char *, int, char **, int, float *);
156
extern PlyFile *ply_open_for_writing(const char *, int, char **, int, float *);
157
extern void ply_describe_element(PlyFile *, char *, int, int, PlyProperty *);
157
extern void ply_describe_element(PlyFile *, char *, int, int, PlyProperty *);
158
extern void ply_describe_property(PlyFile *, char *, PlyProperty *);
158
extern void ply_describe_property(PlyFile *, char *, PlyProperty *);
159
extern void ply_element_count(PlyFile *, char *, int);
159
extern void ply_element_count(PlyFile *, char *, int);
160
extern void ply_header_complete(PlyFile *);
160
extern void ply_header_complete(PlyFile *);
161
extern void ply_put_element_setup(PlyFile *, char *);
161
extern void ply_put_element_setup(PlyFile *, char *);
162
extern void ply_put_element(PlyFile *, void *);
162
extern void ply_put_element(PlyFile *, void *);
163
extern void ply_put_comment(PlyFile *, char *);
163
extern void ply_put_comment(PlyFile *, char *);
164
extern void ply_put_obj_info(PlyFile *, char *);
164
extern void ply_put_obj_info(PlyFile *, char *);
165
extern PlyFile *ply_read(FILE *, int *, char ***);
165
extern PlyFile *ply_read(FILE *, int *, char ***);
166
extern PlyFile *ply_open_for_reading( const char *, int *, char ***, int *, float *);
166
extern PlyFile *ply_open_for_reading( const char *, int *, char ***, int *, float *);
167
extern PlyProperty **ply_get_element_description(PlyFile *, char *, int*, int*);
167
extern PlyProperty **ply_get_element_description(PlyFile *, char *, int*, int*);
168
extern void ply_get_element_setup( PlyFile *, char *, int, PlyProperty *);
168
extern void ply_get_element_setup( PlyFile *, char *, int, PlyProperty *);
169
extern void ply_get_property(PlyFile *, char *, PlyProperty *);
169
extern void ply_get_property(PlyFile *, char *, PlyProperty *);
170
extern PlyOtherProp *ply_get_other_properties(PlyFile *, char *, int);
170
extern PlyOtherProp *ply_get_other_properties(PlyFile *, char *, int);
171
extern void ply_get_element(PlyFile *, void *);
171
extern void ply_get_element(PlyFile *, void *);
172
extern char **ply_get_comments(PlyFile *, int *);
172
extern char **ply_get_comments(PlyFile *, int *);
173
extern char **ply_get_obj_info(PlyFile *, int *);
173
extern char **ply_get_obj_info(PlyFile *, int *);
174
extern void ply_close(PlyFile *);
174
extern void ply_close(PlyFile *);
175
extern void ply_get_info(PlyFile *, float *, int *);
175
extern void ply_get_info(PlyFile *, float *, int *);
176
extern PlyOtherElems *ply_get_other_element (PlyFile *, char *, int);
176
extern PlyOtherElems *ply_get_other_element (PlyFile *, char *, int);
177
extern void ply_describe_other_properties(
177
extern void ply_describe_other_properties(
178
    PlyFile *plyfile, PlyOtherProp *other, int offset);
178
    PlyFile *plyfile, PlyOtherProp *other, int offset);
179
extern void ply_describe_other_elements ( PlyFile *, PlyOtherElems *);
179
extern void ply_describe_other_elements ( PlyFile *, PlyOtherElems *);
180
extern void ply_put_other_elements (PlyFile *);
180
extern void ply_put_other_elements (PlyFile *);
181
extern void ply_free_other_elements (PlyOtherElems *);
181
extern void ply_free_other_elements (PlyOtherElems *);
182
extern void copy_property(PlyProperty *, PlyProperty *);
182
extern void copy_property(PlyProperty *, PlyProperty *);
183
extern int equal_strings(char *, char *);
183
extern int equal_strings(char *, char *);
184
extern int ply_is_valid_property(PlyFile *plyfile, 
184
extern int ply_is_valid_property(PlyFile *plyfile, 
185
				 char *elem_name, char *prop_name);
185
				 char *elem_name, char *prop_name);
186
extern void ply_get_element_noalloc(PlyFile *plyfile, void *elem_ptr);
186
extern void ply_get_element_noalloc(PlyFile *plyfile, void *elem_ptr);
187
 
187
 
188
 
188
 
189
/* Define some functions/macros to convert numbers (as character strings) 
189
/* Define some functions/macros to convert numbers (as character strings) 
190
 * from BYTE_ORDER to BIG or LITTLE ENDIAN. */
190
 * from BYTE_ORDER to BIG or LITTLE ENDIAN. */
191
 
191
 
192
/* Reverse order of 2 characters */
192
/* Reverse order of 2 characters */
193
 
193
 
194
#define SWAP2C(str) { char c; \
194
#define SWAP2C(str) { char c; \
195
    c = (str)[0]; (str)[0] = (str)[1]; (str)[1] = c; }
195
    c = (str)[0]; (str)[0] = (str)[1]; (str)[1] = c; }
196
 
196
 
197
/* Reverse order of 4 characters */
197
/* Reverse order of 4 characters */
198
#define SWAP4C(str) { char c; \
198
#define SWAP4C(str) { char c; \
199
  c = (str)[0]; (str)[0] = (str)[3]; (str)[3] = c; \
199
  c = (str)[0]; (str)[0] = (str)[3]; (str)[3] = c; \
200
  c = (str)[1]; (str)[1] = (str)[2]; (str)[2] = c; }
200
  c = (str)[1]; (str)[1] = (str)[2]; (str)[2] = c; }
201
 
201
 
202
/* Reverse order of 8 characters */
202
/* Reverse order of 8 characters */
203
#define SWAP8C(str) { char c; \
203
#define SWAP8C(str) { char c; \
204
  c = (str)[0]; (str)[0] = (str)[7]; (str)[7] = c; \
204
  c = (str)[0]; (str)[0] = (str)[7]; (str)[7] = c; \
205
  c = (str)[1]; (str)[1] = (str)[6]; (str)[6] = c; \
205
  c = (str)[1]; (str)[1] = (str)[6]; (str)[6] = c; \
206
  c = (str)[2]; (str)[2] = (str)[5]; (str)[5] = c; \
206
  c = (str)[2]; (str)[2] = (str)[5]; (str)[5] = c; \
207
  c = (str)[3]; (str)[3] = (str)[4]; (str)[4] = c; }
207
  c = (str)[3]; (str)[3] = (str)[4]; (str)[4] = c; }
208
 
208
 
209
/* Macros that call the SWAPn function if necessary for this BYTE_ORDER */
209
/* Macros that call the SWAPn function if necessary for this BYTE_ORDER */
210
#if BYTE_ORDER == BIG_ENDIAN
210
#if BYTE_ORDER == BIG_ENDIAN
211
#define SWAP_TO_ENDIAN2(str,end) if ((end)==PLY_BINARY_LE) SWAP2C((char*) str)
211
#define SWAP_TO_ENDIAN2(str,end) if ((end)==PLY_BINARY_LE) SWAP2C((char*) str)
212
#define SWAP_TO_ENDIAN4(str,end) if ((end)==PLY_BINARY_LE) SWAP4C((char*) str)
212
#define SWAP_TO_ENDIAN4(str,end) if ((end)==PLY_BINARY_LE) SWAP4C((char*) str)
213
#define SWAP_TO_ENDIAN8(str,end) if ((end)==PLY_BINARY_LE) SWAP8C((char*) str)
213
#define SWAP_TO_ENDIAN8(str,end) if ((end)==PLY_BINARY_LE) SWAP8C((char*) str)
214
#elif BYTE_ORDER == LITTLE_ENDIAN
214
#elif BYTE_ORDER == LITTLE_ENDIAN
215
#define SWAP_TO_ENDIAN2(str,end) if ((end)==PLY_BINARY_BE) SWAP2C((char*) str)
215
#define SWAP_TO_ENDIAN2(str,end) if ((end)==PLY_BINARY_BE) SWAP2C((char*) str)
216
#define SWAP_TO_ENDIAN4(str,end) if ((end)==PLY_BINARY_BE) SWAP4C((char*) str)
216
#define SWAP_TO_ENDIAN4(str,end) if ((end)==PLY_BINARY_BE) SWAP4C((char*) str)
217
#define SWAP_TO_ENDIAN8(str,end) if ((end)==PLY_BINARY_BE) SWAP8C((char*) str)
217
#define SWAP_TO_ENDIAN8(str,end) if ((end)==PLY_BINARY_BE) SWAP8C((char*) str)
218
#endif
218
#endif
219
 
219
 
220
#ifdef __cplusplus 
220
#ifdef __cplusplus 
221
} 
221
} 
222
#endif 
222
#endif 
223
#endif /* !__PLY_H__ */
223
#endif /* !__PLY_H__ */
224
 
224
 
225
 
225