vtkPLY.h 9.48 KB
Newer Older
1 2 3 4 5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkPLY.h

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 8
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9

10 11
     This software is distributed WITHOUT ANY WARRANTY; without even
     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 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
/*

The interface routines for reading and writing PLY polygon files.

Greg Turk, February 1994

---------------------------------------------------------------

A PLY file contains a single polygonal _object_.

An object is composed of lists of _elements_.  Typical elements are
vertices, faces, edges and materials.

Each type of element for a given object has one or more _properties_
associated with the element type.  For instance, a vertex element may
have as properties the floating-point values x,y,z and the three unsigned
chars representing red, green and blue.

---------------------------------------------------------------

Copyright (c) 1994 The Board of Trustees of The Leland Stanford
36 37 38 39 40 41 42 43 44 45
Junior University.  All rights reserved.

Permission to use, copy, modify and distribute this software and its
documentation for any purpose is hereby granted without fee, provided
that the above copyright notice and this permission notice appear in
all copies of this software and that you do not sell the software.

THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
46 47 48

*/

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
/**
 * @class   vtkPLY
 * @brief   a modified version of the PLY 1.1 library
 *
 * vtkPLY is a modified version of the PLY 1.1 library. The library
 * has been modified by wrapping in a class (to minimize global symbols);
 * to take advantage of functionality generally not available through the
 * PLY library API; and to correct problems with the PLY library.
 *
 * The original distribution was taken from the Stanford University PLY
 * file format release 1.1 (see http://graphics.stanford.edu/data/3Dscanrep/).
 *
 * @sa
 * vtkPLYWriter vtkPLYReader
*/
64

65 66
#ifndef vtkPLY_h
#define vtkPLY_h
67

68
#include "vtkIOPLYModule.h" // For export macro
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
#include "vtkObject.h"

#define PLY_ASCII      1        /* ascii PLY file */
#define PLY_BINARY_BE  2        /* binary PLY file, big endian */
#define PLY_BINARY_LE  3        /* binary PLY file, little endian */

#define PLY_OKAY    0           /* ply routine worked okay */
#define PLY_ERROR  -1           /* error in ply routine */

/* scalar data types supported by PLY format */

#define PLY_START_TYPE 0
#define PLY_CHAR       1
#define PLY_SHORT      2
#define PLY_INT        3
84 85 86 87 88 89 90 91 92 93 94 95
#define PLY_INT8       4
#define PLY_INT16      5
#define PLY_INT32      6
#define PLY_UCHAR      7
#define PLY_USHORT     8
#define PLY_UINT       9
#define PLY_UINT8      10
#define PLY_UINT16     11
#define PLY_UINT32     12
#define PLY_FLOAT      13
#define PLY_FLOAT32    14
#define PLY_DOUBLE     15
96 97
#define PLY_FLOAT64    16
#define PLY_END_TYPE   17
98 99 100 101 102 103

#define  PLY_SCALAR  0
#define  PLY_LIST    1

typedef struct PlyProperty {    /* description of a property */

Berk Geveci's avatar
Berk Geveci committed
104
  const char *name;                           /* property name */
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
  int external_type;                    /* file's data type */
  int internal_type;                    /* program's data type */
  int offset;                           /* offset bytes of prop in a struct */

  int is_list;                          /* 1 = list, 0 = scalar */
  int count_external;                   /* file's count type */
  int count_internal;                   /* program's count type */
  int count_offset;                     /* offset byte for list count */

} PlyProperty;

typedef struct PlyElement {     /* description of an element */
  char *name;                   /* element name */
  int num;                      /* number of elements in this object */
  int size;                     /* size of element (bytes) or -1 if variable */
  int nprops;                   /* number of properties for this element */
  PlyProperty **props;          /* list of properties in the file */
  char *store_prop;             /* flags: property wanted by user? */
  int other_offset;             /* offset to un-asked-for props, or -1 if none*/
  int other_size;               /* size of other_props structure */
} PlyElement;

typedef struct PlyOtherProp {   /* describes other properties in an element */
  char *name;                   /* element name */
  int size;                     /* size of other_props */
  int nprops;                   /* number of properties in other_props */
  PlyProperty **props;          /* list of properties in other_props */
} PlyOtherProp;

typedef struct OtherData { /* for storing other_props for an other element */
  void *other_props;
} OtherData;

typedef struct OtherElem {     /* data for one "other" element */
  char *elem_name;             /* names of other elements */
  int elem_count;              /* count of instances of each element */
  OtherData **other_data;      /* actual property data for the elements */
  PlyOtherProp *other_props;   /* description of the property data */
} OtherElem;

typedef struct PlyOtherElems {  /* "other" elements, not interpreted by user */
  int num_elems;                /* number of other elements */
  OtherElem *other_list;        /* list of data for other elements */
} PlyOtherElems;

typedef struct PlyFile {        /* description of PLY file */
  FILE *fp;                     /* file pointer */
  int file_type;                /* ascii or binary */
  float version;                /* version number of file */
  int nelems;                   /* number of elements of object */
  PlyElement **elems;           /* list of elements */
  int num_comments;             /* number of comments */
  char **comments;              /* list of comments */
  int num_obj_info;             /* number of items of object information */
  char **obj_info;              /* list of object info items */
  PlyElement *which_elem;       /* which element we're currently writing */
  PlyOtherElems *other_elems;   /* "other" elements from a PLY file */
} PlyFile;

164
class VTKIOPLY_EXPORT vtkPLY
165 166 167
{
public:
  //standard PLY library interface
Berk Geveci's avatar
Berk Geveci committed
168
  static PlyFile *ply_write(FILE *, int, const char **, int);
169
  static PlyFile *ply_open_for_writing(const char *, int, const char **, int, float *);
Ken Martin's avatar
Ken Martin committed
170 171 172
  static void ply_describe_element(PlyFile *, const char *, int, int, PlyProperty *);
  static void ply_describe_property(PlyFile *, const char *, PlyProperty *);
  static void ply_element_count(PlyFile *, const char *, int);
173
  static void ply_header_complete(PlyFile *);
Berk Geveci's avatar
Berk Geveci committed
174
  static void ply_put_element_setup(PlyFile *, const char *);
175
  static void ply_put_element(PlyFile *, void *);
Ken Martin's avatar
Ken Martin committed
176
  static void ply_put_comment(PlyFile *, const char *);
Berk Geveci's avatar
Berk Geveci committed
177
  static void ply_put_obj_info(PlyFile *, const char *);
178
  static PlyFile *ply_read(FILE *, int *, char ***);
179
  static PlyFile *ply_open_for_reading( const char *, int *, char ***, int *, float *);
180
  static PlyElement *ply_get_element_description(PlyFile *, char *, int*, int*);
181 182 183
  static void ply_get_element_setup( PlyFile *, const char *, int, PlyProperty *);
  static void ply_get_property(PlyFile *, const char *, PlyProperty *);
  static PlyOtherProp *ply_get_other_properties(PlyFile *, const char *, int);
Dan Blezek's avatar
Dan Blezek committed
184
  static void ply_get_element(PlyFile *, void *);
185 186 187 188
  static char **ply_get_comments(PlyFile *, int *);
  static char **ply_get_obj_info(PlyFile *, int *);
  static void ply_close(PlyFile *);
  static void ply_get_info(PlyFile *, float *, int *);
189
  static PlyOtherElems *ply_get_other_element (PlyFile *, const char *, int);
190 191 192 193 194 195 196
  static void ply_describe_other_elements ( PlyFile *, PlyOtherElems *);
  static void ply_put_other_elements (PlyFile *);
  static void ply_free_other_elements (PlyOtherElems *);
  static void ply_describe_other_properties(PlyFile *, PlyOtherProp *, int);

  // These methods are internal to the PLY library in the normal distribution
  // They should be used carefully
197
  static bool equal_strings(const char *, const char *);
Ken Martin's avatar
Ken Martin committed
198
  static PlyElement *find_element(PlyFile *, const char *);
Berk Geveci's avatar
Berk Geveci committed
199
  static PlyProperty *find_property(PlyElement *, const char *, int *);
200 201 202
  static void write_scalar_type (FILE *, int);
  static char **get_words(FILE *, int *, char **);
  static char **old_get_words(FILE *, int *);
203
  static void write_binary_item(PlyFile *, int, unsigned int, double, int);
204 205 206 207 208 209
  static void write_ascii_item(FILE *, int, unsigned int, double, int);
  static double old_write_ascii_item(FILE *, char *, int);
  static void add_element(PlyFile *, char **, int);
  static void add_property(PlyFile *, char **, int);
  static void add_comment(PlyFile *, char *);
  static void add_obj_info(PlyFile *, char *);
210
  static void copy_property(PlyProperty *, const PlyProperty *);
211
  static void store_item(char *, int, int, unsigned int, double);
212
  static void get_stored_item( const void *, int, int *, unsigned int *, double *);
213 214
  static double get_item_value(const char *, int);
  static void get_ascii_item(const char *, int, int *, unsigned int *, double *);
215
  static void get_binary_item(PlyFile *, int, int *, unsigned int *, double *);
216 217
  static void ascii_get_element(PlyFile *, char *);
  static void binary_get_element(PlyFile *, char *);
218
  static void *my_alloc(size_t, int, const char *);
219
  static int get_prop_type(const char *);
220

221 222 223 224 225
};

#endif


226
// VTK-HeaderTest-Exclude: vtkPLY.h