fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / Contrib / PLY / OSGply.h
blob4afb6eb59c1abb3b0d1b566803aa00a44217a69e
1 /*
3 Header for PLY polygon files.
5 - Greg Turk, March 1994
7 A PLY file contains a single polygonal _object_.
9 An object is composed of lists of _elements_. Typical elements are
10 vertices, faces, edges and materials.
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.
17 ---------------------------------------------------------------
19 Copyright (c) 1994 The Board of Trustees of The Leland Stanford
20 Junior University. All rights reserved.
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.
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.
31 -- Changes
33 - Modified for inclusion in OpenSG.
37 #ifndef __PLY_H__
38 #define __PLY_H__
40 #include <iostream>
41 #include <vector>
42 #include "OSGConfig.h"
45 OSG_BEGIN_NAMESPACE
47 const int PLY_ASCII = 1; /* ascii PLY file */
48 const int PLY_BINARY_BE = 2; /* binary PLY file, big endian */
49 const int PLY_BINARY_LE = 3; /* binary PLY file, little endian */
51 const int PLY_OKAY = 0; /* ply routine worked okay */
52 const int PLY_ERROR = -1; /* error in ply routine */
54 /* scalar data types supported by PLY format */
56 const int PLY_START_TYPE = 0;
57 const int PLY_CHAR = 1;
58 const int PLY_SHORT = 2;
59 const int PLY_INT = 3;
60 const int PLY_UCHAR = 4;
61 const int PLY_USHORT = 5;
62 const int PLY_UINT = 6;
63 const int PLY_FLOAT = 7;
64 const int PLY_DOUBLE = 8;
65 const int PLY_END_TYPE = 9;
67 const bool PLY_SCALAR = false;
68 const bool PLY_LIST = true;
71 struct PlyProperty { /* description of a property */
73 std::string 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 */
78 bool 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 */
83 PlyProperty(std::string name_,
84 int external_type_,
85 int internal_type_,
86 int offset_,
88 bool is_list_,
90 int count_external_,
91 int count_internal_,
92 int count_offset_ ) :
93 name (name_ ),
94 external_type (external_type_ ),
95 internal_type (internal_type_ ),
96 offset (offset_ ),
98 is_list (is_list_),
99 count_external(count_external_ ),
100 count_internal(count_internal_ ),
101 count_offset (count_offset_ ) {}
104 PlyProperty(void) :
105 name ( ),
106 external_type (0 ),
107 internal_type (0 ),
108 offset (0 ),
110 is_list (false),
111 count_external(0 ),
112 count_internal(0 ),
113 count_offset (0 ) {}
116 struct PlyElement { /* description of an element */
117 std::string name; /* element name */
118 int num; /* number of elements in this object */
119 int size; /* size of element (bytes) or -1 if
120 * variable */
121 std::vector<PlyProperty> props; /* list of properties in the file */
122 std::vector<char> store_prop; /* flags: property wanted by user? */
123 int other_offset; /* offset to un-asked-for props, or -1 if
124 * none*/
125 int other_size; /* size of other_props structure */
127 PlyElement(void) :
128 name ( ),
129 num (0),
130 size (0),
131 props ( ),
132 store_prop ( ),
133 other_offset(0),
134 other_size (0) {}
137 struct PlyOtherProp { /* describes other properties in an element */
138 std::string name; /* element name */
139 int size; /* size of other_props */
140 int nprops; /* number of properties in other_props */
141 PlyProperty **props; /* list of properties in other_props */
143 PlyOtherProp(void) :
144 name(),
145 size(0),
146 nprops(0),
147 props(NULL) {}
149 private:
151 PlyOtherProp(const PlyOtherProp &other);
152 void operator =(const PlyOtherProp &rhs);
155 struct OtherData { /* for storing other_props for an other element */
156 void *other_props;
159 struct OtherElem { /* data for one "other" element */
160 std::string elem_name; /* names of other elements */
161 int elem_count; /* count of instances of each element */
162 OtherData **other_data; /* actual property data for the elements */
163 PlyOtherProp *other_props; /* description of the property data */
165 OtherElem(void) :
166 elem_name ( ),
167 elem_count (0 ),
168 other_data (NULL),
169 other_props(NULL) {}
171 OtherElem(const OtherElem &other) :
172 elem_name (other.elem_name ),
173 elem_count (other.elem_count ),
174 other_data (other.other_data ),
175 other_props(other.other_props) {}
177 const OtherElem &operator =(const OtherElem &rhs)
179 elem_name = rhs.elem_name;
180 elem_count = rhs.elem_count;
181 other_data = rhs.other_data;
182 other_props = rhs.other_props;
184 return *this;
187 private:
191 struct PlyFile { /* description of PLY file */
192 std::ostream *ofp; /* output file pointer */
193 std::istream *ifp; /* input file pointer */
194 int file_type; /* ascii or binary */
195 float version; /* version number of file */
196 std::vector<PlyElement> elems; /* list of elements */
197 std::vector<std::string> comments; /* list of comments */
198 std::vector<std::string> obj_info; /* list of object info items */
199 PlyElement *which_elem; /* which element we're currently writing */
200 std::vector<OtherElem> other_elems; /* Elements not interpreterd by user */
201 bool reverse_bytes;
203 PlyFile(void) :
204 ofp (NULL ),
205 ifp (NULL ),
206 file_type (0 ),
207 version (0.f ),
208 elems ( ),
209 comments ( ),
210 obj_info ( ),
211 which_elem (NULL ),
212 other_elems ( ),
213 reverse_bytes(false) {}
215 private:
217 PlyFile(const PlyFile &other);
218 void operator =(const PlyFile &rhs);
222 /*** delcaration of routines ***/
224 extern PlyFile *ply_write(std::ostream *, int, char **, int);
225 //extern PlyFile *ply_open_for_writing(char *, int, char **, int, float *);
226 extern void ply_describe_element(PlyFile *, char *, int, int, PlyProperty *);
227 extern void ply_describe_property(PlyFile *, char *, PlyProperty *);
228 extern void ply_element_count(PlyFile *, char *, int);
229 extern void ply_header_complete(PlyFile *);
230 extern void ply_put_element_setup(PlyFile *, const std::string&);
231 extern void ply_put_element(PlyFile *, void *);
232 extern void ply_put_comment(PlyFile *, char *);
233 extern void ply_put_obj_info(PlyFile *, char *);
234 extern PlyFile *ply_read(std::istream *, std::vector<std::string>&);
235 //extern PlyFile *ply_open_for_reading( char *, int *, char ***, int *, float *);
236 extern bool ply_get_element_description(PlyFile *, const std::string&, int*, std::vector<PlyProperty>&);
237 extern void ply_get_element_setup( PlyFile *, char *, int, PlyProperty *);
238 extern void ply_get_property(PlyFile *, const std::string&, PlyProperty *);
239 extern PlyOtherProp *ply_get_other_properties(PlyFile *, char *, int);
240 extern void ply_get_element(PlyFile *, void *);
241 extern std::vector<std::string>& ply_get_comments(PlyFile *, int *);
242 extern std::vector<std::string>& ply_get_obj_info(PlyFile *, int *);
243 extern void ply_close(PlyFile *);
244 extern void ply_get_info(PlyFile *, float *, int *);
245 extern std::vector<OtherElem>& ply_get_other_element (PlyFile *, char *, int);
246 extern void ply_describe_other_elements ( PlyFile *, const std::vector<OtherElem>&);
247 extern void ply_put_other_elements (PlyFile *);
249 extern int equal_strings(const char *, const char *);
251 OSG_END_NAMESPACE
253 #endif /* !__PLY_H__ */