OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgreProgressiveMesh.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2011 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 // The underlying algorithms in this class are based heavily on:
29 /*
30  * Progressive Mesh type Polygon Reduction Algorithm
31  * by Stan Melax (c) 1998
32  */
33 
34 #ifndef __ProgressiveMesh_H_
35 #define __ProgressiveMesh_H_
36 
37 #include "OgrePrerequisites.h"
38 #include "OgreVector3.h"
41 #include "OgreRenderOperation.h"
42 
43 namespace Ogre {
44 
65  {
66  public:
67 
70  {
74  VRQ_PROPORTIONAL
75  };
76 
78 
86  ProgressiveMesh(const VertexData* vertexData, const IndexData* indexData);
87  virtual ~ProgressiveMesh();
88 
104  virtual void addExtraVertexPositionBuffer(const VertexData* vertexData);
105 
114  virtual void build(ushort numLevels, LODFaceList* outList,
115  VertexReductionQuota quota = VRQ_PROPORTIONAL, Real reductionValue = 0.5f );
116 
117  protected:
120 
123 
124  // Internal classes
125  class PMTriangle;
126  class PMVertex;
127 
128  public: // VC6 hack
129 
133  public:
134  size_t realIndex;
136  };
137 
138  protected:
139 
142  public:
143  PMTriangle();
144  void setDetails(size_t index, PMFaceVertex *v0, PMFaceVertex *v1, PMFaceVertex *v2);
145  void computeNormal(void);
146  void replaceVertex(PMFaceVertex *vold, PMFaceVertex *vnew);
147  bool hasCommonVertex(PMVertex *v) const;
148  bool hasFaceVertex(PMFaceVertex *v) const;
149  PMFaceVertex* getFaceVertexFromCommon(PMVertex* commonVert);
150  void notifyRemoved(void);
151 
152  PMFaceVertex* vertex[3]; // the 3 points that make this tri
153  Vector3 normal; // unit vector orthogonal to this face
154  bool removed; // true if this tri is now removed
155  size_t index;
156  };
157 
165  public:
166  PMVertex();
167  void setDetails(const Vector3& v, size_t index);
168  void removeIfNonNeighbor(PMVertex *n);
169  bool isBorder(void);
170  bool isManifoldEdgeWith(PMVertex* v); // is edge this->src a manifold edge?
171  void notifyRemoved(void);
172 
173  Vector3 position; // location of point in euclidean space
174  size_t index; // place of vertex in original list
177  NeighborList neighbor; // adjacent vertices
179  FaceList face; // adjacent triangles
180 
181  Real collapseCost; // cached cost of collapsing edge
182  PMVertex * collapseTo; // candidate vertex for collapse
183  bool removed; // true if this vert is now removed
184  bool toBeRemoved; // denug
185 
186  bool seam;
187 
188  };
189 
194 
197  {
199  FaceVertexList mFaceVertList; // The vertex details referenced by the triangles
200  CommonVertexList mVertList; // The master list of common vertices
201  };
202 
206 
209 
211  void addWorkingData(const VertexData* vertexData, const IndexData* indexData);
212 
214  void initialiseEdgeCollapseCosts(void);
216  Real computeEdgeCollapseCost(PMVertex *src, PMVertex *dest);
218  Real computeEdgeCostAtVertexForBuffer(WorkingDataList::iterator idata, size_t vertIndex);
220  void computeEdgeCostAtVertex(size_t vertIndex);
222  void computeAllCosts(void);
224  size_t getNextCollapser(void);
226  void bakeNewLOD(IndexData* pData);
227 
234  void collapse(PMVertex *collapser);
235 
237  void dumpContents(const String& log);
238 
239 
240 
241 
242 
243 
244 
245 
246 
247  };
248 
249 
253 }
254 
255 #endif
float Real
Software floating point type.
#define _OgreExport
Definition: OgrePlatform.h:203
A vertex as used by a face.
const VertexData * mpVertexData
set< PMVertex * >::type NeighborList
vector< PMFaceVertex >::type FaceVertexList
Data used to calculate the collapse costs.
vector< PMWorkingData >::type WorkingDataList
const IndexData * mpIndexData
WorstCostList mWorstCosts
The worst collapse cost from all vertex buffers for each vertex.
#define _OgrePrivate
Definition: OgrePlatform.h:204
This class reduces the complexity of the geometry it is given.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
VertexReductionQuota
The way to derive the quota of vertices which are reduced at each LOD.
Summary class collecting together index data source information.
vector< PMVertex >::type CommonVertexList
FaceVertexList mFaceVertList
List of faces.
vector< PMTriangle >::type TriangleList
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
unsigned short ushort
vector< Real >::type WorstCostList
Summary class collecting together vertex source information.
A set number of vertices are removed at each reduction.
A vertex in the progressive mesh, holds info like collapse cost etc.
vector< IndexData * >::type LODFaceList
_StringBase String
set< PMVertex * >::type DuplicateList
WorkingDataList mWorkingData
Multiple copies, 1 per vertex buffer.
set< PMTriangle * >::type FaceList
A triangle in the progressive mesh, holds extra info like face normal.