TAPs 0.7.7.3
TAPsReadPly.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsReadPly.hpp
00003 
00004 Create an OpenGL Model Object from a .ply file
00005 
00006 SUKITTI PUNAK   (05/24/2006)
00007 UPDATE          (06/01/2006)
00008 ******************************************************************************/
00009 #ifndef TAPs_READ_PLY_HPP
00010 #define TAPs_READ_PLY_HPP
00011 
00012 // The necessary headers are included in TAPsReadModel.hpp which directly uses
00013 // this header.
00014 
00015 BEGIN_NAMESPACE_TAPs
00016 //=============================================================================
00017 template <typename T> class ReadModels;
00018 //=============================================================================
00019 template <typename T>
00020 class ReadPly {
00021     friend class ReadModels<T>;
00022 // Member Functions  ----------------------------------------------------------
00023 public:
00024     //-------------------------------------------------------------------------
00025     // Read an input file
00026     //  I/P: fileName
00027     //  O/P: *prModel
00028     // More than one fn per each operation due to the design of Model types;
00029     //   E.g.
00030     //   One for PolygonalModel and its derived classes
00031     //   The other for XPolygonalModel and its derived classes
00032     //
00033     //   Each pairs are exactly identical (both declaration and definition) 
00034     //   except the passed prModel pointer.
00035     //-------------------------------------------------------------------------
00036     static bool readFile( const char *fileName, OpenGL::PolygonalModel<T> * const prModel );
00037     static bool readFile( const char *fileName, OpenGL::XPolygonalModel<T> * const prModel );
00038     static bool readFile( const char *fileName, OpenGL::HalfEdgeModel<T> * const prModel );
00039     //-------------------------------------------------------------------------
00040 private:
00041     //-------------------------------------------------------------------------
00042     static void Clear ();
00043     //-------------------------------------------------------------------------
00044     // Process Each Node
00045     //-------------------------------------------------------------------------
00046     static bool ProcessHEADER( FILE * inputFile, OpenGL::MeshModel<T> * const prModel );
00047     //-------------------------------------------------------------------------
00048     static bool ProcessFORMAT( char * line );
00049     static void ProcessELEMENT( char * line, OpenGL::MeshModel<T> * const prModel );
00050     static void ProcessPROPERTY( char * line );
00051     //-------------------------------------------------------------------------
00052     static void ProcessVERTEX_LIST_ASCII( FILE * inputFile, OpenGL::PolygonalModel<T> * const prModel );
00053     static void ProcessVERTEX_LIST_ASCII( FILE * inputFile, OpenGL::XPolygonalModel<T> * const prModel );
00054     static void ProcessVERTEX_LIST_ASCII( FILE * inputFile, OpenGL::HalfEdgeModel<T> * const prModel );
00055     //-------------------------------------------------------------------------
00056     static void ProcessFACE_LIST_ASCII( FILE * inputFile, OpenGL::PolygonalModel<T> * const prModel );
00057     static void ProcessFACE_LIST_ASCII( FILE * inputFile, OpenGL::XPolygonalModel<T> * const prModel );
00058     static void ProcessFACE_LIST_ASCII( FILE * inputFile, OpenGL::HalfEdgeModel<T> * const prModel );
00059     //-------------------------------------------------------------------------
00060     // BINARY BIG ENDDIAN           e.g. UNIX
00061     static void ProcessVERTEX_LIST_BINARY_BIG_ENDDIAN( FILE * inputFile, OpenGL::PolygonalModel<T> * const prModel );
00062     static void ProcessVERTEX_LIST_BINARY_BIG_ENDDIAN( FILE * inputFile, OpenGL::XPolygonalModel<T> * const prModel );
00063     static void ProcessVERTEX_LIST_BINARY_BIG_ENDDIAN( FILE * inputFile, OpenGL::HalfEdgeModel<T> * const prModel );
00064     //-------------------------------------------------------------------------
00065     static void ProcessFACE_LIST_BINARY_BIG_ENDDIAN( FILE * inputFile, OpenGL::PolygonalModel<T> * const prModel );
00066     static void ProcessFACE_LIST_BINARY_BIG_ENDDIAN( FILE * inputFile, OpenGL::XPolygonalModel<T> * const prModel );
00067     static void ProcessFACE_LIST_BINARY_BIG_ENDDIAN( FILE * inputFile, OpenGL::HalfEdgeModel<T> * const prModel );
00068     //-------------------------------------------------------------------------
00069     // BINARY LITTLE ENDDIAN        e.g. PC
00070     static void ProcessVERTEX_LIST_BINARY_LITTLE_ENDDIAN( FILE * inputFile, OpenGL::PolygonalModel<T> * const prModel );
00071     static void ProcessVERTEX_LIST_BINARY_LITTLE_ENDDIAN( FILE * inputFile, OpenGL::XPolygonalModel<T> * const prModel );
00072     static void ProcessVERTEX_LIST_BINARY_LITTLE_ENDDIAN( FILE * inputFile, OpenGL::HalfEdgeModel<T> * const prModel );
00073     //-------------------------------------------------------------------------
00074     static void ProcessFACE_LIST_BINARY_LITTLE_ENDDIAN( FILE * inputFile, OpenGL::PolygonalModel<T> * const prModel );
00075     static void ProcessFACE_LIST_BINARY_LITTLE_ENDDIAN( FILE * inputFile, OpenGL::XPolygonalModel<T> * const prModel );
00076     static void ProcessFACE_LIST_BINARY_LITTLE_ENDDIAN( FILE * inputFile, OpenGL::HalfEdgeModel<T> * const prModel );
00077     //-------------------------------------------------------------------------
00078     static void ConvertBigEnddianToLittleEnddian ( unsigned char dataType, unsigned char * prData );
00079     //-------------------------------------------------------------------------
00080     //-------------------------------------------------------------------------
00081 // Data Members ---------------------------------------------------------------
00082 private:
00083     //---------------------------------------------------------------
00084     enum PlyEnum {
00085 //-----------------------------------------------
00086 // Format
00087 //-----------------------------------------------
00088         FORMAT_ASCII = 1,
00089         FORMAT_BINARY_LITTLE_ENDDIAN,   // PC
00090         FORMAT_BINARY_BIG_ENDDIAN,      // UNIX
00091 //-----------------------------------------------
00092 // Element
00093 //-----------------------------------------------
00094         ELEMENT_VERTEX,             // = 4
00095         ELEMENT_FACE,
00096         ELEMENT_EDGE,
00097 //-----------------------------------------------
00098 // List
00099 //-----------------------------------------------
00100         LIST_VERTEX_INDICES,        // = 7
00101 //-----------------------------------------------
00102 // Name        Type              Number of Bytes
00103 //-----------------------------------------------
00104 // int8       character                 1
00105 // uint8      unsigned character        1
00106 // int16      short integer             2
00107 // uint16     unsigned short integer    2
00108 // int32      integer                   4
00109 // uint32     unsigned integer          4
00110 // float32    single-precision float    4
00111 // float64    double-precision float    8
00112 //-----------------------------------------------
00113 // Alias name:
00114 //   uchar  --> uint8
00115 //   int    --> int32
00116 //   float  --> float32
00117 //   double --> float64
00118 //-----------------------------------------------
00119         INT_8,                      // = 8
00120         UINT_8,
00121         INT_16,
00122         UINT_16,
00123         INT_32,
00124         UINT_32,
00125         FLOAT_32,
00126         FLOAT_64,
00127 //-----------------------------------------------
00128 // Examples of User Defined
00129 //-----------------------------------------------
00130 // element material 6
00131 // property ambient_red uint8               { ambient color }
00132 // property ambient_green uint8
00133 // property ambient_blue uint8
00134 // property ambient_coeff float32
00135 // property diffuse_red uint8               { diffuse color }
00136 // property diffuse_green uint8
00137 // property diffuse_blue uint8
00138 // property diffuse_coeff float32
00139 // property specular_red uint8              { specular color }
00140 // property specular_green uint8
00141 // property specular_blue uint8
00142 // property specular_coeff float32
00143 // property specular_power float32          { Phong power }
00144 //-----------------------------------------------
00145 // Attribute
00146         X, Y, Z,                    // = 16, 17, 18
00147         CONFIDENCE,
00148         INTENSITY,
00149         VERTEX1, VERTEX2,   // for edge list
00150         RED, GREEN, BLUE,
00151 //-----------------------------------------------
00152         UNDEFINED                   // = 26
00153     };
00154     //---------------------------------------------------------------
00155     static unsigned char    m_eFormat;          // format type
00156     static float            m_fFormatVersion;   // format version
00157     static unsigned char    m_eCurrentListType; // current list type (V, F, or E)
00158     //---------------------------------------------------------------
00159     // For vertex list
00160     static std::vector<unsigned char>   m_veVertexListType;
00161     static std::vector<unsigned char>   m_veVertexListAttrib;
00162     //---------------------------------------------------------------
00163     // For face list
00164     static std::vector<unsigned char>   m_veFaceListType;
00165     static std::vector<unsigned char>   m_veFaceListAttrib;
00166     //---------------------------------------------------------------
00167     // For edge list
00168     static std::vector<unsigned char>   m_veEdgeListType;
00169     static std::vector<unsigned char>   m_veEdgeListAttrib;
00170     //---------------------------------------------------------------
00171     static int vertexNo;            // current vertex number
00172     static int halfEdgeCounter;     // count number of half-edges
00173 //  static FILE *fileIn;
00174 
00175     /*
00176     // for half-edge originated vertex look up
00177     static HEVertex<T> ** vertexList;
00178     // hash table for vertex ring list
00179     // used for half-edge pair look up
00180     static HashTableBySTLVector<int> * vertexRingList;
00181     // hash table for halfedge ring list
00182     // used for half-edge pair look up
00183     static HashTableBySTLVector< HEHalfEdge<T>* > * halfEdgeRingList;
00184     // (bounday) half-edges on hole faces
00185     static HEHalfEdge<T> * boundaryHalfEdgePtr;
00186     //*/
00187 };
00188 //=============================================================================
00189 END_NAMESPACE_TAPs
00190 //-----------------------------------------------------------------------------
00191 // Include definition if TAPs_USE_EXPORT is not defined
00192 //#if !defined( TAPs_USE_EXPORT )
00193     #include "TAPsReadPly.cpp"
00194 //#endif
00195 //-----------------------------------------------------------------------------
00196 #endif
00197 //34567890123456789012345678901234567890123456789012345678901234567890123456789
00198 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines