plylib.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2004                                                \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *   
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
00021 *                                                                           *
00022 ****************************************************************************/
00023 /****************************************************************************
00024 Acknowlegments
00025 Portions of this file were based on the original code of the Ply library 
00026 of Greg Turk and on the work of Claudio Rocchini
00027 
00028 ****************************************************************************/
00029 /****************************************************************************
00030   History
00031 
00032 $Log: not supported by cvs2svn $
00033 Revision 1.5  2005/11/26 00:12:25  cignoni
00034 added prototype of  interpret_texture_name
00035 
00036 Revision 1.4  2005/11/12 07:07:47  cignoni
00037 Changed Offset types to remove warnings
00038 
00039 Revision 1.3  2005/01/03 10:35:59  cignoni
00040 Improved the compatibility for ply format for faces having the list size (e.g. number of vertexes of a face) as a char instead of a uchar.
00041 Added a couple of new face descriptors, corrected a bug in error reporting function (and restructured) and translated a few comments.
00042 Thanks to Patrick Min for the careful bug reporting
00043 
00044 Revision 1.2  2004/04/27 13:29:19  turini
00045 *** empty log message ***
00046 
00047 Revision 1.1  2004/03/03 15:00:51  cignoni
00048 Initial commit
00049 
00050 ****************************************************************************/
00051 
00052 #ifndef __VCG_PLYLIB 
00053 #define __VCG_PLYLIB 
00054 
00055 #include <memory.h>
00056 #include <vector>
00057 #include <string>
00058 #include <assert.h>
00059 
00060 namespace vcg {
00061 namespace ply {
00062 
00063         // Data types supported by the ply format
00064 enum PlyTypes {
00065         T_NOTYPE,
00066         T_CHAR,
00067         T_SHORT,
00068         T_INT,
00069         T_UCHAR,
00070         T_USHORT,
00071         T_UINT,
00072         T_FLOAT,
00073         T_DOUBLE,
00074         T_MAXTYPE
00075 };
00076 
00077         // Error codes reported by GetError
00078 enum PlyError {
00079         E_NOERROR,                              // 0
00080                 // Errors of  open(..)
00081         E_CANTOPEN,                             // 1
00082         E_NOTHEADER,                    // 2
00083         E_UNESPECTEDEOF,                // 3
00084         E_NOFORMAT,                             // 4
00085         E_SYNTAX,                               // 5
00086         E_PROPOUTOFELEMENT,             // 6
00087         E_BADTYPENAME,                  // 7
00088                 // Errors of addtoread(..)
00089         E_ELEMNOTFOUND,                 // 8
00090         E_PROPNOTFOUND,                 // 9
00091         E_BADTYPE,                              // 10
00092         E_INCOMPATIBLETYPE,             // 11
00093         E_BADCAST,                              // 12
00094         E_MAXPLYERRORS
00095 };
00096 
00097                 // file formats supported by the ply format
00098 enum PlyFormat {
00099         F_UNSPECIFIED,
00100         F_ASCII,
00101         F_BINLITTLE,
00102         F_BINBIG
00103 };
00104 
00105 
00106 #ifdef USE_ZLIB
00107 typedef void * GZFILE;
00108 #else
00109 typedef FILE * GZFILE;
00110 #endif
00111 
00112 
00113         // Messaggio di errore
00114 //extern const char * ply_error_msg[];
00115 
00116         // TIPO FILE
00117 
00118 
00119 // Descrittore esterno di propieta'
00120 class PropDescriptor
00121 {
00122 public:
00123         const char * elemname;                  // Nome dell'elemento
00124         const char * propname;                  // Nome della propieta'
00125         int     stotype1;                               // Tipo dell'elemento su file    (se lista tipo degli elementi della lista)
00126         int memtype1;                           // Tipo dell'elemento in memoria (se lista tipo degli elementi della lista)
00127         size_t offset1;                         // Offset del valore in memoria
00128         int islist;                                     // 1 se lista, 0 altrimenti
00129         int alloclist;            // 1 se alloca lista, 0 se preallocata
00130         int stotype2;                           // Tipo del numero di elementi della lista su file
00131         int memtype2;                           // Tipo del numero di elementi della lista in memoria
00132         size_t offset2;                         // Offset valore memoria
00133 
00134         int format;                                     // duplicazione del formato
00135         
00136         size_t                  stotypesize() const; // per sapere quanto e'grande un dato descrittore sul file
00137         size_t                  memtypesize() const; // per sapere quanto e'grande un dato descrittore in memoria
00138         const char *memtypename() const; 
00139         const char *stotypename() const;
00140 };
00141 
00142 // Reading Callback (used to copy a data prop)
00143 typedef bool (* readelemcb) ( GZFILE fp, void * mem, PropDescriptor * p );
00144 
00145 class PlyProperty
00146 {
00147 public:
00148         inline PlyProperty()
00149         {
00150                 tipo            = 0;
00151                 islist          = 0;
00152                 tipoindex       = 0;
00153                 bestored        = 0;
00154         }
00155 
00156         inline PlyProperty( const char * na, int ti, int isl, int t2 )
00157         {
00158                 assert(na);
00159                 assert(ti>0);
00160                 assert(ti<T_MAXTYPE);
00161                 assert( t2>0 || (t2==0 && isl==0) );
00162                 assert(t2<T_MAXTYPE);
00163 
00164                 name            = std::string(na);
00165                 tipo            = ti;
00166                 islist          = isl;
00167                 tipoindex       = t2;
00168                 bestored        = 0;
00169         }
00170 
00171         std::string name;                               // Nome della propieta'
00172         int    tipo;                            // Tipo di dato
00173         int    islist;                          // Vero se e' una lista
00174         int    tipoindex;                       // Tipo del contatore della lista
00175 
00176         int        bestored;                    // 1 se va storata
00177         PropDescriptor desc;            // Descrittore di memorizzazione
00178 
00179         readelemcb      cb;                             // Callback di lettura
00180 };
00181 
00182 
00183 class PlyElement
00184 {
00185 public:
00186         
00187         inline PlyElement()
00188         {
00189                 number  = 0;
00190         }
00191 
00192         inline PlyElement( const char * na, int nu )
00193         {
00194                 assert(na);
00195                 assert(nu>=0);
00196 
00197                 name    = std::string(na);
00198                 number  = nu;
00199         }
00200 
00201         
00202         inline void SetName( const char * na )
00203         {
00204                 name = std::string(na);
00205         }
00206 
00207         inline void SetNumbert( int nu )
00208         {
00209                 assert(nu>0);
00210                 number = nu;
00211         }
00212 
00213         void AddProp( const char * na, int ti, int isl, int t2 );
00214 
00215         int AddToRead(
00216                 const char * propname,
00217                 int     stotype1,
00218                 int memtype1,
00219                 size_t offset1,
00220                 int islist,
00221                 int alloclist,
00222                 int stotype2,
00223                 int memtype2,
00224                 size_t offset2
00225         );      // Vedi struttura PropDescriptor
00226 
00227         PlyProperty * FindProp( const char * name );
00228 
00229         std::string name;                               // Nome dell'elemento
00230         int    number;                          // Numero di elementi di questo tipo
00231 
00232   std::vector<PlyProperty> props;       // Vettore dinamico delle property
00233 };
00234 
00235 
00236 class PlyFile
00237 {
00238 private:
00239         void compile( PlyElement * e );
00240         void compile( PlyProperty * p );
00241 
00242 public:
00243                 // Modi di apertura
00244         enum {
00245                 MODE_READ,
00246                 MODE_WRITE
00247         };
00248 
00249          PlyFile();
00250         ~PlyFile();
00251 
00252                 // Apre un file ply
00253         int Open( const char * filename, int mode );
00254                 // Chiude un file e disalloca la memoria
00255         void Destroy();
00256                 // Ritorna il codice dell'ultimo errore
00257         inline int GetError() const { return error; }
00258                 // Definizione di lettura (Vedi struttura PropDescriptor)
00259         int AddToRead(
00260                 const char * elemname,
00261                 const char * propname,
00262                 int     stotype1,
00263                 int memtype1,
00264                 size_t offset1,
00265                 int islist,
00266                 int alloclist,
00267                 int stotype2,
00268                 int memtype2,
00269                 size_t offset2
00270         );
00271                 // Come sopra ma con descrittore
00272         inline int AddToRead( const PropDescriptor & p )
00273         {
00274                 return AddToRead(p.elemname,p.propname,p.stotype1,
00275                         p.memtype1,p.offset1,p.islist,p.alloclist,p.stotype2,
00276                         p.memtype2,p.offset2
00277                 );
00278         }
00279         
00280                 // Ritorna il numero di oggetti di un tipo di elemento
00281         const char * ElemName( int i );
00282 
00283         int ElemNumber( int i ) const;
00284                 // Setta il tipo di elemento corrente per effetture
00285                 // la lettura
00286         inline void SetCurElement( int i )
00287         {
00288                 if(i<0 || i>=int(elements.size())) cure = 0;
00289                 else
00290                 {
00291                         cure = &(elements[i]);
00292                         compile(cure);
00293                 }
00294         }
00295                 // Lettura du un elemento
00296         int Read( void * mem );
00297 
00298   std::vector<PlyElement>   elements;   // Vettore degli elementi
00299         std::vector<std::string>  comments;     // Vettore dei commenti
00300         static const char * typenames[9];
00301         static const char * newtypenames[9];
00302 
00303   inline const char * GetHeader() const { return header.c_str(); }
00304 protected:
00305 
00306         GZFILE gzfp;
00307 
00308         float  version;                         // Versione del file
00309         int    error;                           // Errore corrente (vedi enum)
00310         int    format;                          // Formato del file (vedi enum )
00311 
00312   std::string   header;                 // Testo dell'header    
00313 
00314         PlyElement * cure;                      // Elemento da leggere
00315 
00316                 // Callback di lettura: vale ReadBin o ReadAcii
00317         int (* ReadCB)( GZFILE fp, const PlyProperty * r, void * mem, int fmt );
00318 
00319         int OpenRead( const char * filename );
00320         int OpenWrite( const char * filename );
00321         
00322         PlyElement * AddElement( const char * name, int number );
00323         int FindType( const char * name ) const;
00324         PlyElement * FindElement( const char * name );
00325 };
00326 
00327 void interpret_texture_name(const char*a, const char*fn, char*output);
00328 
00329   } // end namespace ply
00330 } // end namespace vcg
00331 #endif


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:34:12