- Main Page
- Namespaces
- Classes
- Files

# VCRA-SZCZERBACKI-PointBasedRendering/Mesh.h

    00001 #ifndef LWO_H
    00002 #define LWO_H
    00003
    00004 #include "ssVector.hpp"
    00005 #include "color.h"
    00006 #include <string>
    00007 #include <vector>
    00008
    00009 //=============================================================================
    00010 //=============================================================================
    00011
    00012 class Mesh
    00013 {
    00014 public:
    00015 #pragma pack( push, 1 )
    00016         struct Vertex
    00017         {
    00018                 void                    reset()
    00019                 {
    00020                         m_position.set(0,0,0);
    00021                         m_normal.set(0,0,0);
    00022                         m_t1.set(0,0,0);
    00023                         m_t2.set(0,0,0);
    00024                         m_maxc = 0;
    00025                         m_minc = 0;
    00026                         m_uv.set(0,0);
    00027                         m_diffuse.set(0,0,0,0);
    00028                 }
    00029                 void                    add( const Vertex &v )
    00030                 {
    00031                         m_position += v.m_position;
    00032                         m_normal += v.m_normal;
    00033                         m_t1 += v.m_t1;
    00034                         m_t2 += v.m_t2;
    00035                         m_maxc += v.m_maxc;
    00036                         m_minc += v.m_minc;
    00037                         m_uv += v.m_uv;
    00038                         m_diffuse += v.m_diffuse;
    00039                 }
    00040                 void                    mad( const Vertex &v, float c )
    00041                 {
    00042                         m_position += v.m_position * c;
    00043                         m_normal += v.m_normal * c;
    00044                         m_t1 += v.m_t1 * c;
    00045                         m_t2 += v.m_t2 * c;
    00046                         m_maxc += v.m_maxc * c;
    00047                         m_minc += v.m_minc * c;
    00048                         m_uv += v.m_uv * c;
    00049                         m_diffuse += v.m_diffuse * c;
    00050                 }
    00051                 void                    normalize()
    00052                 {
    00053                         m_normal.normalize();
    00054                         m_t1.normalize();
    00055                         m_t2.normalize();
    00056                 }
    00057                 Vector3         m_position;
    00058                 Vector3         m_normal;
    00059                 Vector3         m_t1;
    00060                 Vector3         m_t2;
    00061                 float           m_maxc;
    00062                 float           m_minc;
    00063                 int                     m_triangleUsing;        //30msb polyindex 2lsb edgeindex
    00064                 Vector2         m_uv;
    00065                 Vector4         m_diffuse;
    00066                 bool            m_reliable;
    00067         };
    00068
    00069         struct Triangle
    00070         {
    00071                 Vector3         m_normal;
    00072                 float           m_area;
    00073                 int                     m_surface;
    00074                 int                     m_v[3];
    00075                 int                     m_n[3];
    00076                 char            m_nedge[3];
    00077                 char            m_dummy;
    00078                 Vector2         m_uv[3];
    00079                 int                     m_baseTriangle;         //triangle index before subdivision
    00080         };
    00081
    00082         struct Edge
    00083         {
    00084                 bool operator<( const Edge &e ) const   { if( m_v[0] < e.m_v[0] ) return true; else if( m_v[0] > e.m_v[0] ) return false; else return (m_v[1] < e.m_v[1]) ? true : false; }
    00085                 int                     m_v[2];
    00086                 int                     m_t[2];
    00087         };
    00088
    00089         struct Surface
    00090         {
    00091                 std::string     m_name;
    00092                 Color           m_color;
    00093                 int                     m_polygons;
    00094         };
    00095 #pragma pack( pop )
    00096
    00097         Mesh();
    00098         Mesh( int vertices, int triangles );
    00099         Mesh( const char *fileName );
    00100         Mesh( const Mesh &m );
    00101         ~Mesh();
    00102
    00103         void                            load( const char *fileName );
    00104
    00105         Vertex                          &getVertex( int i )                             { SS_ASSERT(i>=0&&i<m_vertices.size()); return m_vertices[i]; }
    00106         Triangle                        &getTriangle( int i )                   { SS_ASSERT(i>=0&&i<m_triangles.size()); return m_triangles[i]; }
    00107         Edge                            &getEdge( int i )                               { SS_ASSERT(i>=0&&i<m_edges.size()); return m_edges[i]; }
    00108         Surface                         &getSurface( int i )                    { SS_ASSERT(i>=0&&i<m_surfaces.size()); return m_surfaces[i]; }
    00109
    00110         int                                     getVertexCount() const                  { return m_vertices.size(); }
    00111         int                                     getTriangleCount() const                { return m_triangles.size(); }
    00112         int                                     getEdgeCount() const                    { return m_edges.size(); }
    00113         int                                     getSurfaceCount() const                 { return m_surfaces.size(); }
    00114
    00115         std::vector<Vertex>             &getVertices()                          { return m_vertices; }
    00116         std::vector<Triangle>   &getTriangles()                         { return m_triangles; }
    00117         std::vector<Edge>               &getEdges()                                     { return m_edges; }
    00118         std::vector<Surface>    &getSurfaces()                          { return m_surfaces; }
    00119
    00120         const Vector3           &getBoundingBoxMin() const              { return m_boundingBoxMin; }
    00121         const Vector3           &getBoundingBoxMax() const              { return m_boundingBoxMax; }
    00122         float                           getBoundingRadius() const               { return m_boundingRadius; }
    00123
    00124         void                            calculateAdjacency();   //calculates also edges
    00125         void                            setTriangleUsing();
    00126         void                            calculateNormals();
    00127         void                            setParametrization();
    00128         void                            subdivide( int n );
    00129         void                            calculateBoundingBox();
    00130
    00131         struct ventry
    00132         {
    00133                 int             m_vertex;
    00134                 int             m_i;
    00135         };
    00136         const std::vector<ventry> &get1Neighbourhood( int ver, int &valence, bool &boundary, int &left, int &right );
    00137 protected:
    00138         std::vector<Vertex>             m_vertices;
    00139         std::vector<Triangle>   m_triangles;
    00140         std::vector<Edge>               m_edges;
    00141         std::vector<Surface>    m_surfaces;
    00142         std::string                             m_filename;
    00143
    00144         Vector3                                 m_boundingBoxMin;
    00145         Vector3                                 m_boundingBoxMax;
    00146         float                                   m_boundingRadius;
    00147         int                                             m_ambiguousNeighbours;
    00148         bool                                    m_adjacencyCalculated;
    00149
    00150         static UINT8                    *m_fileptr;
    00151         static UINT8                    *m_nextchunkptr;
    00152         static UINT8                    *m_nextsubchunkptr;
    00153         static UINT8                    *m_fileend;
    00154         static UINT8                    *m_readptr;
    00155
    00156         UINT32                                  readID4();
    00157         int                                             readI1();
    00158         int                                             readI2();
    00159         int                                             readI4();
    00160         UINT8                                   readU1();
    00161         UINT16                                  readU2();
    00162         UINT32                                  readU4();
    00163         float                                   readF4();
    00164         const char                              *readS0();
    00165         UINT32                                  readVX();
    00166         Vector3                                 readCOL12();
    00167         Vector3                                 readVEC12();
    00168
    00169         void                                    loadLW5( );
    00170         void                                    loadLW6( );
    00171 };
    00172
    00173 //=============================================================================
    00174 //=============================================================================
    00175
    00176 #endif