VTK
vtkPLY.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkPLY.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /*
16 
17 The interface routines for reading and writing PLY polygon files.
18 
19 Greg Turk, February 1994
20 
21 ---------------------------------------------------------------
22 
23 A PLY file contains a single polygonal _object_.
24 
25 An object is composed of lists of _elements_. Typical elements are
26 vertices, faces, edges and materials.
27 
28 Each type of element for a given object has one or more _properties_
29 associated with the element type. For instance, a vertex element may
30 have as properties the floating-point values x,y,z and the three unsigned
31 chars representing red, green and blue.
32 
33 ---------------------------------------------------------------
34 
35 Copyright (c) 1994 The Board of Trustees of The Leland Stanford
36 Junior University. All rights reserved.
37 
38 Permission to use, copy, modify and distribute this software and its
39 documentation for any purpose is hereby granted without fee, provided
40 that the above copyright notice and this permission notice appear in
41 all copies of this software and that you do not sell the software.
42 
43 THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
44 EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
45 WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
46 
47 */
48 
64 #ifndef vtkPLY_h
65 #define vtkPLY_h
66 
67 #include "vtkIOPLYModule.h" // For export macro
68 #include "vtkObject.h"
69 
70 #define PLY_ASCII 1 /* ascii PLY file */
71 #define PLY_BINARY_BE 2 /* binary PLY file, big endian */
72 #define PLY_BINARY_LE 3 /* binary PLY file, little endian */
73 
74 #define PLY_OKAY 0 /* ply routine worked okay */
75 #define PLY_ERROR -1 /* error in ply routine */
76 
77 /* scalar data types supported by PLY format */
78 
79 #define PLY_START_TYPE 0
80 #define PLY_CHAR 1
81 #define PLY_SHORT 2
82 #define PLY_INT 3
83 #define PLY_INT32 4
84 #define PLY_UCHAR 5
85 #define PLY_USHORT 6
86 #define PLY_UINT 7
87 #define PLY_UINT8 8
88 #define PLY_FLOAT 9
89 #define PLY_FLOAT32 10
90 #define PLY_DOUBLE 11
91 #define PLY_END_TYPE 12
92 
93 #define PLY_SCALAR 0
94 #define PLY_LIST 1
95 
96 typedef struct PlyProperty { /* description of a property */
97 
98  const char *name; /* property name */
99  int external_type; /* file's data type */
100  int internal_type; /* program's data type */
101  int offset; /* offset bytes of prop in a struct */
102 
103  int is_list; /* 1 = list, 0 = scalar */
104  int count_external; /* file's count type */
105  int count_internal; /* program's count type */
106  int count_offset; /* offset byte for list count */
107 
108 } PlyProperty;
109 
110 typedef struct PlyElement { /* description of an element */
111  char *name; /* element name */
112  int num; /* number of elements in this object */
113  int size; /* size of element (bytes) or -1 if variable */
114  int nprops; /* number of properties for this element */
115  PlyProperty **props; /* list of properties in the file */
116  char *store_prop; /* flags: property wanted by user? */
117  int other_offset; /* offset to un-asked-for props, or -1 if none*/
118  int other_size; /* size of other_props structure */
119 } PlyElement;
120 
121 typedef struct PlyOtherProp { /* describes other properties in an element */
122  char *name; /* element name */
123  int size; /* size of other_props */
124  int nprops; /* number of properties in other_props */
125  PlyProperty **props; /* list of properties in other_props */
126 } PlyOtherProp;
127 
128 typedef struct OtherData { /* for storing other_props for an other element */
129  void *other_props;
130 } OtherData;
131 
132 typedef struct OtherElem { /* data for one "other" element */
133  char *elem_name; /* names of other elements */
134  int elem_count; /* count of instances of each element */
135  OtherData **other_data; /* actual property data for the elements */
136  PlyOtherProp *other_props; /* description of the property data */
137 } OtherElem;
138 
139 typedef struct PlyOtherElems { /* "other" elements, not interpreted by user */
140  int num_elems; /* number of other elements */
141  OtherElem *other_list; /* list of data for other elements */
142 } PlyOtherElems;
143 
144 typedef struct PlyFile { /* description of PLY file */
145  FILE *fp; /* file pointer */
146  int file_type; /* ascii or binary */
147  float version; /* version number of file */
148  int nelems; /* number of elements of object */
149  PlyElement **elems; /* list of elements */
150  int num_comments; /* number of comments */
151  char **comments; /* list of comments */
152  int num_obj_info; /* number of items of object information */
153  char **obj_info; /* list of object info items */
154  PlyElement *which_elem; /* which element we're currently writing */
155  PlyOtherElems *other_elems; /* "other" elements from a PLY file */
156 } PlyFile;
157 
159 {
160 public:
161  //standard PLY library interface
162  static PlyFile *ply_write(FILE *, int, const char **, int);
163  static PlyFile *ply_open_for_writing(const char *, int, const char **, int, float *);
164  static void ply_describe_element(PlyFile *, const char *, int, int, PlyProperty *);
165  static void ply_describe_property(PlyFile *, const char *, PlyProperty *);
166  static void ply_element_count(PlyFile *, const char *, int);
167  static void ply_header_complete(PlyFile *);
168  static void ply_put_element_setup(PlyFile *, const char *);
169  static void ply_put_element(PlyFile *, void *);
170  static void ply_put_comment(PlyFile *, const char *);
171  static void ply_put_obj_info(PlyFile *, const char *);
172  static PlyFile *ply_read(FILE *, int *, char ***);
173  static PlyFile *ply_open_for_reading( const char *, int *, char ***, int *, float *);
174  static PlyElement *ply_get_element_description(PlyFile *, char *, int*, int*);
175  static void ply_get_element_setup( PlyFile *, const char *, int, PlyProperty *);
176  static void ply_get_property(PlyFile *, const char *, PlyProperty *);
177  static PlyOtherProp *ply_get_other_properties(PlyFile *, const char *, int);
178  static void ply_get_element(PlyFile *, void *);
179  static char **ply_get_comments(PlyFile *, int *);
180  static char **ply_get_obj_info(PlyFile *, int *);
181  static void ply_close(PlyFile *);
182  static void ply_get_info(PlyFile *, float *, int *);
183  static PlyOtherElems *ply_get_other_element (PlyFile *, const char *, int);
184  static void ply_describe_other_elements ( PlyFile *, PlyOtherElems *);
185  static void ply_put_other_elements (PlyFile *);
186  static void ply_free_other_elements (PlyOtherElems *);
187  static void ply_describe_other_properties(PlyFile *, PlyOtherProp *, int);
188 
189  // These methods are internal to the PLY library in the normal distribution
190  // They should be used carefully
191  static bool equal_strings(const char *, const char *);
192  static PlyElement *find_element(PlyFile *, const char *);
193  static PlyProperty *find_property(PlyElement *, const char *, int *);
194  static void write_scalar_type (FILE *, int);
195  static char **get_words(FILE *, int *, char **);
196  static char **old_get_words(FILE *, int *);
197  static void write_binary_item(PlyFile *, int, unsigned int, double, int);
198  static void write_ascii_item(FILE *, int, unsigned int, double, int);
199  static double old_write_ascii_item(FILE *, char *, int);
200  static void add_element(PlyFile *, char **, int);
201  static void add_property(PlyFile *, char **, int);
202  static void add_comment(PlyFile *, char *);
203  static void add_obj_info(PlyFile *, char *);
204  static void copy_property(PlyProperty *, const PlyProperty *);
205  static void store_item(char *, int, int, unsigned int, double);
206  static void get_stored_item( const void *, int, int *, unsigned int *, double *);
207  static double get_item_value(const char *, int);
208  static void get_ascii_item(const char *, int, int *, unsigned int *, double *);
209  static void get_binary_item(PlyFile *, int, int *, unsigned int *, double *);
210  static void ascii_get_element(PlyFile *, char *);
211  static void binary_get_element(PlyFile *, char *);
212  static void *my_alloc(size_t, int, const char *);
213  static int get_prop_type(const char *);
214 
215 };
216 
217 #endif
218 
219 
220 // VTK-HeaderTest-Exclude: vtkPLY.h
int num_comments
Definition: vtkPLY.h:150
OtherElem * other_list
Definition: vtkPLY.h:141
int count_internal
Definition: vtkPLY.h:105
struct PlyOtherElems PlyOtherElems
char ** comments
Definition: vtkPLY.h:151
char * name
Definition: vtkPLY.h:111
char * elem_name
Definition: vtkPLY.h:133
float version
Definition: vtkPLY.h:147
int other_size
Definition: vtkPLY.h:118
char * name
Definition: vtkPLY.h:122
PlyElement ** elems
Definition: vtkPLY.h:149
PlyOtherElems * other_elems
Definition: vtkPLY.h:155
PlyProperty ** props
Definition: vtkPLY.h:125
int elem_count
Definition: vtkPLY.h:134
int file_type
Definition: vtkPLY.h:146
PlyOtherProp * other_props
Definition: vtkPLY.h:136
struct PlyFile PlyFile
struct OtherData OtherData
const char * name
Definition: vtkPLY.h:98
int internal_type
Definition: vtkPLY.h:100
int num
Definition: vtkPLY.h:112
int size
Definition: vtkPLY.h:123
int nelems
Definition: vtkPLY.h:148
struct PlyProperty PlyProperty
struct PlyElement PlyElement
char * store_prop
Definition: vtkPLY.h:116
int offset
Definition: vtkPLY.h:101
OtherData ** other_data
Definition: vtkPLY.h:135
int count_offset
Definition: vtkPLY.h:106
a modified version of the PLY 1.1 library
Definition: vtkPLY.h:158
FILE * fp
Definition: vtkPLY.h:145
int count_external
Definition: vtkPLY.h:104
int num_obj_info
Definition: vtkPLY.h:152
PlyProperty ** props
Definition: vtkPLY.h:115
struct OtherElem OtherElem
int is_list
Definition: vtkPLY.h:103
int size
Definition: vtkPLY.h:113
PlyElement * which_elem
Definition: vtkPLY.h:154
char ** obj_info
Definition: vtkPLY.h:153
int nprops
Definition: vtkPLY.h:114
int num_elems
Definition: vtkPLY.h:140
struct PlyOtherProp PlyOtherProp
#define VTKIOPLY_EXPORT
int external_type
Definition: vtkPLY.h:99
int other_offset
Definition: vtkPLY.h:117
int nprops
Definition: vtkPLY.h:124
void * other_props
Definition: vtkPLY.h:129