# OgreProgressiveMesh.h

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 // The underlying algorithms in this class are based heavily on:
    00030 /*
    00031  *  Progressive Mesh type Polygon Reduction Algorithm
    00032  *  by Stan Melax (c) 1998
    00033  */
    00034
    00035 #ifndef __ProgressiveMesh_H_
    00036 #define __ProgressiveMesh_H_
    00037
    00038 #include "OgrePrerequisites.h"
    00039 #include "OgreVector3.h"
    00040 #include "OgreHardwareVertexBuffer.h"
    00041 #include "OgreHardwareIndexBuffer.h"
    00042 #include "OgreRenderOperation.h"
    00043
    00044 namespace Ogre {
    00045
    00059     class _OgreExport ProgressiveMesh : public ProgMeshAlloc
    00060     {
    00061     public:
    00062
    00064         enum VertexReductionQuota
    00065         {
    00067             VRQ_CONSTANT,
    00069             VRQ_PROPORTIONAL
    00070         };
    00071
    00072         typedef std::vector<IndexData*> LODFaceList;
    00073
    00081         ProgressiveMesh(const VertexData* vertexData, const IndexData* indexData);
    00082         virtual ~ProgressiveMesh();
    00083
    00099         virtual void addExtraVertexPositionBuffer(const VertexData* vertexData);
    00100
    00109         virtual void build(ushort numLevels, LODFaceList* outList,
    00110             VertexReductionQuota quota = VRQ_PROPORTIONAL, Real reductionValue = 0.5f );
    00111
    00112     protected:
    00113         const VertexData *mpVertexData;
    00114         const IndexData *mpIndexData;
    00115
    00116         size_t mCurrNumIndexes;
    00117         size_t mNumCommonVertices;
    00118
    00119         // Internal classes
    00120         class PMTriangle;
    00121         class PMVertex;
    00122
    00123         public: // VC6 hack
    00124
    00127         class _OgrePrivate PMFaceVertex {
    00128         public:
    00129             size_t realIndex;
    00130             PMVertex* commonVertex;
    00131         };
    00132
    00133         protected:
    00134
    00136         class _OgrePrivate PMTriangle {
    00137         public:
    00138             PMTriangle();
    00139             void setDetails(size_t index, PMFaceVertex *v0, PMFaceVertex *v1, PMFaceVertex *v2);
    00140             void computeNormal(void);
    00141             void replaceVertex(PMFaceVertex *vold, PMFaceVertex *vnew);
    00142             bool hasCommonVertex(PMVertex *v) const;
    00143             bool hasFaceVertex(PMFaceVertex *v) const;
    00144             PMFaceVertex* getFaceVertexFromCommon(PMVertex* commonVert);
    00145             void notifyRemoved(void);
    00146
    00147             PMFaceVertex* vertex[3]; // the 3 points that make this tri
    00148             Vector3   normal;    // unit vector orthogonal to this face
    00149             bool      removed;   // true if this tri is now removed
    00150             size_t index;
    00151         };
    00152
    00159         class _OgrePrivate PMVertex {
    00160         public:
    00161             PMVertex();
    00162             void setDetails(const Vector3& v, size_t index);
    00163             void removeIfNonNeighbor(PMVertex *n);
    00164             bool isBorder(void);
    00165             bool isManifoldEdgeWith(PMVertex* v); // is edge this->src a manifold edge?
    00166             void notifyRemoved(void);
    00167
    00168             Vector3  position;  // location of point in euclidean space
    00169             size_t index;       // place of vertex in original list
    00170             typedef std::set<PMVertex *> NeighborList;
    00171             typedef std::set<PMVertex *> DuplicateList;
    00172             NeighborList neighbor; // adjacent vertices
    00173             typedef std::set<PMTriangle *> FaceList;
    00174             FaceList face;     // adjacent triangles
    00175
    00176             Real collapseCost;  // cached cost of collapsing edge
    00177             PMVertex * collapseTo; // candidate vertex for collapse
    00178             bool      removed;   // true if this vert is now removed
    00179             bool      toBeRemoved; // denug
    00180
    00181             bool seam;
    00182
    00183         };
    00184
    00185         typedef std::vector<PMTriangle> TriangleList;
    00186         typedef std::vector<PMFaceVertex> FaceVertexList;
    00187         typedef std::vector<PMVertex> CommonVertexList;
    00188         typedef std::vector<Real> WorstCostList;
    00189
    00191         struct PMWorkingData
    00192         {
    00193             TriangleList mTriList;
    00194             FaceVertexList mFaceVertList; // The vertex details referenced by the triangles
    00195             CommonVertexList mVertList; // The master list of common vertices
    00196         };
    00197
    00198         typedef std::vector<PMWorkingData> WorkingDataList;
    00200         WorkingDataList mWorkingData;
    00201
    00203         WorstCostList mWorstCosts;
    00204
    00206         void addWorkingData(const VertexData* vertexData, const IndexData* indexData);
    00207
    00209         void initialiseEdgeCollapseCosts(void);
    00211         Real computeEdgeCollapseCost(PMVertex *src, PMVertex *dest);
    00213         Real computeEdgeCostAtVertexForBuffer(WorkingDataList::iterator idata, size_t vertIndex);
    00215         void computeEdgeCostAtVertex(size_t vertIndex);
    00217         void computeAllCosts(void);
    00219         size_t getNextCollapser(void);
    00221         void bakeNewLOD(IndexData* pData);
    00222
    00229         void collapse(PMVertex *collapser);
    00230
    00232         void dumpContents(const String& log);
    00233
    00234
    00235
    00236
    00237
    00238
    00239
    00240
    00241
    00242     };
    00243
    00244
    00245
    00246 }
    00247
    00248 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Jul 26 11:32:19 2009