Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

IO/vtkPLY.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkPLY.h,v $
00005   Language:  C++
00006 
00007 
00008 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00009 All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without
00012 modification, are permitted provided that the following conditions are met:
00013 
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016 
00017  * Redistributions in binary form must reproduce the above copyright notice,
00018    this list of conditions and the following disclaimer in the documentation
00019    and/or other materials provided with the distribution.
00020 
00021  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00022    of any contributors may be used to endorse or promote products derived
00023    from this software without specific prior written permission.
00024 
00025  * Modified source versions must be plainly marked as such, and must not be
00026    misrepresented as being the original software.
00027 
00028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00029 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00031 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00032 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00033 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00034 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00035 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00036 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038 
00039 =========================================================================*/
00040 /*
00041 
00042 The interface routines for reading and writing PLY polygon files.
00043 
00044 Greg Turk, February 1994
00045 
00046 ---------------------------------------------------------------
00047 
00048 A PLY file contains a single polygonal _object_.
00049 
00050 An object is composed of lists of _elements_.  Typical elements are
00051 vertices, faces, edges and materials.
00052 
00053 Each type of element for a given object has one or more _properties_
00054 associated with the element type.  For instance, a vertex element may
00055 have as properties the floating-point values x,y,z and the three unsigned
00056 chars representing red, green and blue.
00057 
00058 ---------------------------------------------------------------
00059 
00060 Copyright (c) 1994 The Board of Trustees of The Leland Stanford
00061 Junior University.  All rights reserved.   
00062   
00063 Permission to use, copy, modify and distribute this software and its   
00064 documentation for any purpose is hereby granted without fee, provided   
00065 that the above copyright notice and this permission notice appear in   
00066 all copies of this software and that you do not sell the software.   
00067   
00068 THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,   
00069 EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY   
00070 WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.   
00071 
00072 */
00073 
00097 #ifndef __vtkPLY_h
00098 #define __vtkPLY_h
00099 
00100 #include <stdio.h>
00101 #include <stddef.h>
00102 #include "vtkObject.h"
00103 
00104 #define PLY_ASCII      1        /* ascii PLY file */
00105 #define PLY_BINARY_BE  2        /* binary PLY file, big endian */
00106 #define PLY_BINARY_LE  3        /* binary PLY file, little endian */
00107 
00108 #define PLY_OKAY    0           /* ply routine worked okay */
00109 #define PLY_ERROR  -1           /* error in ply routine */
00110 
00111 /* scalar data types supported by PLY format */
00112 
00113 #define PLY_START_TYPE 0
00114 #define PLY_CHAR       1
00115 #define PLY_SHORT      2
00116 #define PLY_INT        3
00117 #define PLY_UCHAR      4
00118 #define PLY_USHORT     5
00119 #define PLY_UINT       6
00120 #define PLY_FLOAT      7
00121 #define PLY_DOUBLE     8
00122 #define PLY_END_TYPE   9
00123 
00124 #define  PLY_SCALAR  0
00125 #define  PLY_LIST    1
00126 
00127 typedef struct PlyProperty {    /* description of a property */
00128 
00129   const char *name;                           /* property name */
00130   int external_type;                    /* file's data type */
00131   int internal_type;                    /* program's data type */
00132   int offset;                           /* offset bytes of prop in a struct */
00133 
00134   int is_list;                          /* 1 = list, 0 = scalar */
00135   int count_external;                   /* file's count type */
00136   int count_internal;                   /* program's count type */
00137   int count_offset;                     /* offset byte for list count */
00138 
00139 } PlyProperty;
00140 
00141 typedef struct PlyElement {     /* description of an element */
00142   char *name;                   /* element name */
00143   int num;                      /* number of elements in this object */
00144   int size;                     /* size of element (bytes) or -1 if variable */
00145   int nprops;                   /* number of properties for this element */
00146   PlyProperty **props;          /* list of properties in the file */
00147   char *store_prop;             /* flags: property wanted by user? */
00148   int other_offset;             /* offset to un-asked-for props, or -1 if none*/
00149   int other_size;               /* size of other_props structure */
00150 } PlyElement;
00151 
00152 typedef struct PlyOtherProp {   /* describes other properties in an element */
00153   char *name;                   /* element name */
00154   int size;                     /* size of other_props */
00155   int nprops;                   /* number of properties in other_props */
00156   PlyProperty **props;          /* list of properties in other_props */
00157 } PlyOtherProp;
00158 
00159 typedef struct OtherData { /* for storing other_props for an other element */
00160   void *other_props;
00161 } OtherData;
00162 
00163 typedef struct OtherElem {     /* data for one "other" element */
00164   char *elem_name;             /* names of other elements */
00165   int elem_count;              /* count of instances of each element */
00166   OtherData **other_data;      /* actual property data for the elements */
00167   PlyOtherProp *other_props;   /* description of the property data */
00168 } OtherElem;
00169 
00170 typedef struct PlyOtherElems {  /* "other" elements, not interpreted by user */
00171   int num_elems;                /* number of other elements */
00172   OtherElem *other_list;        /* list of data for other elements */
00173 } PlyOtherElems;
00174 
00175 typedef struct PlyFile {        /* description of PLY file */
00176   FILE *fp;                     /* file pointer */
00177   int file_type;                /* ascii or binary */
00178   float version;                /* version number of file */
00179   int nelems;                   /* number of elements of object */
00180   PlyElement **elems;           /* list of elements */
00181   int num_comments;             /* number of comments */
00182   char **comments;              /* list of comments */
00183   int num_obj_info;             /* number of items of object information */
00184   char **obj_info;              /* list of object info items */
00185   PlyElement *which_elem;       /* which element we're currently writing */
00186   PlyOtherElems *other_elems;   /* "other" elements from a PLY file */
00187 } PlyFile;
00188 
00189 /* memory allocation */
00190 #define myalloc(mem_size) vtkPLY::my_alloc((mem_size), __LINE__, __FILE__)
00191 
00192 class VTK_IO_EXPORT vtkPLY
00193 {
00194 public:
00195   //standard PLY library interface
00196   static PlyFile *ply_write(FILE *, int, const char **, int);
00197   static PlyFile *ply_open_for_writing(char *, int, const char **, int, float *);
00198   static void ply_describe_element(PlyFile *, char *, int, int, PlyProperty *);
00199   static void ply_describe_property(PlyFile *, char *, PlyProperty *);
00200   static void ply_element_count(PlyFile *, char *, int);
00201   static void ply_header_complete(PlyFile *);
00202   static void ply_put_element_setup(PlyFile *, char *);
00203   static void ply_put_element(PlyFile *, void *);
00204   static void ply_put_comment(PlyFile *, char *);
00205   static void ply_put_obj_info(PlyFile *, char *);
00206   static PlyFile *ply_read(FILE *, int *, char ***);
00207   static PlyFile *ply_open_for_reading( char *, int *, char ***, int *, float *);
00208   static PlyElement *ply_get_element_description(PlyFile *, char *, int*, int*);
00209   static void ply_get_element_setup( PlyFile *, char *, int, PlyProperty *);
00210   static void ply_get_property(PlyFile *, char *, PlyProperty *);
00211   static PlyOtherProp *ply_get_other_properties(PlyFile *, char *, int);
00212   static void ply_get_element(PlyFile *, void *);
00213   static char **ply_get_comments(PlyFile *, int *);
00214   static char **ply_get_obj_info(PlyFile *, int *);
00215   static void ply_close(PlyFile *);
00216   static void ply_get_info(PlyFile *, float *, int *);
00217   static PlyOtherElems *ply_get_other_element (PlyFile *, char *, int);
00218   static void ply_describe_other_elements ( PlyFile *, PlyOtherElems *);
00219   static void ply_put_other_elements (PlyFile *);
00220   static void ply_free_other_elements (PlyOtherElems *);
00221   static void ply_describe_other_properties(PlyFile *, PlyOtherProp *, int);
00222 
00223   // These methods are internal to the PLY library in the normal distribution
00224   // They should be used carefully
00225   static int equal_strings(const char *, const char *);
00226   static PlyElement *find_element(PlyFile *, char *);
00227   static PlyProperty *find_property(PlyElement *, const char *, int *);
00228   static void write_scalar_type (FILE *, int);
00229   static char **get_words(FILE *, int *, char **);
00230   static char **old_get_words(FILE *, int *);
00231   static void write_binary_item(FILE *, int, unsigned int, double, int);
00232   static void write_ascii_item(FILE *, int, unsigned int, double, int);
00233   static double old_write_ascii_item(FILE *, char *, int);
00234   static void add_element(PlyFile *, char **, int);
00235   static void add_property(PlyFile *, char **, int);
00236   static void add_comment(PlyFile *, char *);
00237   static void add_obj_info(PlyFile *, char *);
00238   static void copy_property(PlyProperty *, PlyProperty *);
00239   static void store_item(char *, int, int, unsigned int, double);
00240   static void get_stored_item( void *, int, int *, unsigned int *, double *);
00241   static double get_item_value(char *, int);
00242   static void get_ascii_item(char *, int, int *, unsigned int *, double *);
00243   static void get_binary_item(FILE *, int, int *, unsigned int *, double *);
00244   static void ascii_get_element(PlyFile *, char *);
00245   static void binary_get_element(PlyFile *, char *);
00246   static char *my_alloc(int, int, char *);
00247   static int get_prop_type(char *);
00248   
00249 };
00250 
00251 #endif
00252 
00253 

Generated on Thu Mar 28 14:19:28 2002 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001