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 
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 */
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 */
127 
128 typedef struct OtherData { /* for storing other_props for an other element */
129  void *other_props;
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 */
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 */
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 */
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);
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
OtherElem
struct OtherElem OtherElem
vtkPLY::ply_element_count
static void ply_element_count(PlyFile *, const char *, int)
PlyFile::which_elem
PlyElement * which_elem
Definition: vtkPLY.h:154
vtkPLY::ply_get_element
static void ply_get_element(PlyFile *, void *)
vtkPLY::equal_strings
static bool equal_strings(const char *, const char *)
vtkPLY::add_comment
static void add_comment(PlyFile *, char *)
vtkPLY::add_element
static void add_element(PlyFile *, char **, int)
PlyOtherProp
Definition: vtkPLY.h:121
PlyOtherProp
struct PlyOtherProp PlyOtherProp
PlyOtherElems
Definition: vtkPLY.h:139
PlyFile
struct PlyFile PlyFile
PlyElement::other_offset
int other_offset
Definition: vtkPLY.h:117
PlyFile::version
float version
Definition: vtkPLY.h:147
PlyElement::name
char * name
Definition: vtkPLY.h:111
vtkPLY::ply_write
static PlyFile * ply_write(FILE *, int, const char **, int)
PlyProperty::internal_type
int internal_type
Definition: vtkPLY.h:100
vtkPLY::ply_put_element
static void ply_put_element(PlyFile *, void *)
PlyOtherElems::other_list
OtherElem * other_list
Definition: vtkPLY.h:141
vtkPLY::ply_header_complete
static void ply_header_complete(PlyFile *)
vtkPLY::old_get_words
static char ** old_get_words(FILE *, int *)
PlyFile::obj_info
char ** obj_info
Definition: vtkPLY.h:153
PlyFile::elems
PlyElement ** elems
Definition: vtkPLY.h:149
vtkPLY::binary_get_element
static void binary_get_element(PlyFile *, char *)
vtkPLY::get_ascii_item
static void get_ascii_item(const char *, int, int *, unsigned int *, double *)
vtkPLY::ply_get_info
static void ply_get_info(PlyFile *, float *, int *)
PlyFile::file_type
int file_type
Definition: vtkPLY.h:146
PlyOtherProp::props
PlyProperty ** props
Definition: vtkPLY.h:125
vtkPLY::ply_describe_element
static void ply_describe_element(PlyFile *, const char *, int, int, PlyProperty *)
vtkPLY::copy_property
static void copy_property(PlyProperty *, const PlyProperty *)
vtkPLY::ply_describe_property
static void ply_describe_property(PlyFile *, const char *, PlyProperty *)
PlyProperty::is_list
int is_list
Definition: vtkPLY.h:103
PlyProperty::name
const char * name
Definition: vtkPLY.h:98
PlyProperty::count_external
int count_external
Definition: vtkPLY.h:104
vtkPLY::ply_put_obj_info
static void ply_put_obj_info(PlyFile *, const char *)
PlyElement::other_size
int other_size
Definition: vtkPLY.h:118
vtkPLY::ply_describe_other_elements
static void ply_describe_other_elements(PlyFile *, PlyOtherElems *)
vtkPLY::ply_put_other_elements
static void ply_put_other_elements(PlyFile *)
PlyProperty
Definition: vtkPLY.h:96
PlyFile::other_elems
PlyOtherElems * other_elems
Definition: vtkPLY.h:155
PlyElement
Definition: vtkPLY.h:110
vtkPLY::find_element
static PlyElement * find_element(PlyFile *, const char *)
vtkPLY::get_prop_type
static int get_prop_type(const char *)
OtherData::other_props
void * other_props
Definition: vtkPLY.h:129
vtkPLY::ply_get_other_properties
static PlyOtherProp * ply_get_other_properties(PlyFile *, const char *, int)
vtkIOPLYModule.h
PlyOtherProp::size
int size
Definition: vtkPLY.h:123
vtkPLY::add_obj_info
static void add_obj_info(PlyFile *, char *)
PlyOtherProp::nprops
int nprops
Definition: vtkPLY.h:124
vtkPLY::my_alloc
static void * my_alloc(size_t, int, const char *)
PlyProperty::offset
int offset
Definition: vtkPLY.h:101
vtkPLY::get_stored_item
static void get_stored_item(const void *, int, int *, unsigned int *, double *)
OtherData
struct OtherData OtherData
PlyProperty::external_type
int external_type
Definition: vtkPLY.h:99
vtkPLY::ply_put_element_setup
static void ply_put_element_setup(PlyFile *, const char *)
PlyElement::num
int num
Definition: vtkPLY.h:112
vtkPLY::get_binary_item
static void get_binary_item(PlyFile *, int, int *, unsigned int *, double *)
PlyFile::num_obj_info
int num_obj_info
Definition: vtkPLY.h:152
PlyElement::store_prop
char * store_prop
Definition: vtkPLY.h:116
vtkPLY::ply_get_obj_info
static char ** ply_get_obj_info(PlyFile *, int *)
OtherElem::elem_name
char * elem_name
Definition: vtkPLY.h:133
PlyProperty
struct PlyProperty PlyProperty
vtkPLY::write_scalar_type
static void write_scalar_type(FILE *, int)
vtkPLY
a modified version of the PLY 1.1 library
Definition: vtkPLY.h:159
OtherElem::other_props
PlyOtherProp * other_props
Definition: vtkPLY.h:136
vtkPLY::ply_read
static PlyFile * ply_read(FILE *, int *, char ***)
vtkPLY::ply_close
static void ply_close(PlyFile *)
vtkPLY::ply_get_element_description
static PlyElement * ply_get_element_description(PlyFile *, char *, int *, int *)
PlyProperty::count_internal
int count_internal
Definition: vtkPLY.h:105
vtkPLY::get_words
static char ** get_words(FILE *, int *, char **)
vtkObject.h
vtkPLY::ply_open_for_reading
static PlyFile * ply_open_for_reading(const char *, int *, char ***, int *, float *)
PlyFile::fp
FILE * fp
Definition: vtkPLY.h:145
PlyProperty::count_offset
int count_offset
Definition: vtkPLY.h:106
PlyOtherProp::name
char * name
Definition: vtkPLY.h:122
PlyFile::nelems
int nelems
Definition: vtkPLY.h:148
vtkPLY::ply_open_for_writing
static PlyFile * ply_open_for_writing(const char *, int, const char **, int, float *)
VTKIOPLY_EXPORT
#define VTKIOPLY_EXPORT
Definition: vtkIOPLYModule.h:15
vtkPLY::ply_describe_other_properties
static void ply_describe_other_properties(PlyFile *, PlyOtherProp *, int)
vtkPLY::ply_get_element_setup
static void ply_get_element_setup(PlyFile *, const char *, int, PlyProperty *)
vtkPLY::add_property
static void add_property(PlyFile *, char **, int)
vtkPLY::write_binary_item
static void write_binary_item(PlyFile *, int, unsigned int, double, int)
vtkPLY::old_write_ascii_item
static double old_write_ascii_item(FILE *, char *, int)
OtherElem::other_data
OtherData ** other_data
Definition: vtkPLY.h:135
PlyElement
struct PlyElement PlyElement
vtkPLY::find_property
static PlyProperty * find_property(PlyElement *, const char *, int *)
vtkPLY::ply_get_property
static void ply_get_property(PlyFile *, const char *, PlyProperty *)
OtherData
Definition: vtkPLY.h:128
PlyElement::nprops
int nprops
Definition: vtkPLY.h:114
vtkPLY::ply_put_comment
static void ply_put_comment(PlyFile *, const char *)
vtkPLY::ascii_get_element
static void ascii_get_element(PlyFile *, char *)
vtkPLY::ply_get_comments
static char ** ply_get_comments(PlyFile *, int *)
vtkPLY::ply_get_other_element
static PlyOtherElems * ply_get_other_element(PlyFile *, const char *, int)
PlyOtherElems
struct PlyOtherElems PlyOtherElems
PlyElement::props
PlyProperty ** props
Definition: vtkPLY.h:115
PlyFile
Definition: vtkPLY.h:144
vtkPLY::get_item_value
static double get_item_value(const char *, int)
PlyFile::num_comments
int num_comments
Definition: vtkPLY.h:150
OtherElem
Definition: vtkPLY.h:132
OtherElem::elem_count
int elem_count
Definition: vtkPLY.h:134
PlyElement::size
int size
Definition: vtkPLY.h:113
PlyFile::comments
char ** comments
Definition: vtkPLY.h:151
vtkPLY::write_ascii_item
static void write_ascii_item(FILE *, int, unsigned int, double, int)
vtkPLY::store_item
static void store_item(char *, int, int, unsigned int, double)
PlyOtherElems::num_elems
int num_elems
Definition: vtkPLY.h:140
vtkPLY::ply_free_other_elements
static void ply_free_other_elements(PlyOtherElems *)