OgreProgressiveMeshGenerator.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-2013 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 
29 #ifndef __ProgressiveMeshGenerator_H_
30 #define __ProgressiveMeshGenerator_H_
31 
32 #include "OgrePrerequisites.h"
33 #include "OgreVector3.h"
34 #include "OgreSmallVector.h"
35 #include "OgreMesh.h"
36 #include "OgreLodConfig.h"
37 
38 namespace Ogre
39 {
40 
42 {
43 public:
49  virtual void generateLodLevels(LodConfig& lodConfig) = 0;
50 
56  virtual void generateAutoconfiguredLodLevels(MeshPtr& mesh);
57 
64  virtual void getAutoconfig(MeshPtr& inMesh, LodConfig& outLodConfig);
65 
67 };
68 
74 {
75 public:
76 
78  virtual ~ProgressiveMeshGenerator();
79 
81  void generateLodLevels(LodConfig& lodConfig);
82 
83 protected:
84 
85  // VectorSet is basically a helper to use a vector as a small set container.
86  // Also these functions keep the code clean and fast.
87  // You can insert in O(1) time, if you know that it doesn't exists.
88  // You can remove in O(1) time, if you know the position of the item.
89  template<typename T, unsigned S>
91  public SmallVector<T, S> {
93 
94  void addNotExists(const T& item); // Complexity: O(1)!!
95  void remove(iterator it); // Complexity: O(1)!!
96  iterator add(const T& item); // Complexity: O(N)
97  void removeExists(const T& item); // Complexity: O(N)
98  bool remove(const T& item); // Complexity: O(N)
99  void replaceExists(const T& oldItem, const T& newItem); // Complexity: O(N)
100  bool has(const T& item); // Complexity: O(N)
101  iterator find(const T& item); // Complexity: O(N)
102  iterator findExists(const T& item); // Complexity: O(N)
103  };
104 
105  struct PMEdge;
106  struct PMVertex;
107  struct PMTriangle;
108  struct PMVertexHash;
109  struct PMVertexEqual;
110  struct PMCollapseCostLess;
111  struct PMCollapsedEdge;
113 
116  typedef HashSet<PMVertex*, PMVertexHash, PMVertexEqual> UniqueVertexSet;
119 
122 
125 
126  // Hash function for UniqueVertexSet.
129 
130  PMVertexHash() { assert(0); }
132  size_t operator() (const PMVertex* v) const;
133  };
134 
135  // Equality function for UniqueVertexSet.
137  bool operator() (const PMVertex* lhs, const PMVertex* rhs) const;
138  };
139 
140  // Directed edge
144  int refCount;
145 
146  explicit PMEdge(PMVertex* destination);
147  bool operator== (const PMEdge& other) const;
148  PMEdge& operator= (const PMEdge& b);
149  PMEdge(const PMEdge& b);
150  bool operator< (const PMEdge& other) const;
151  };
152 
157 
159  bool seam;
160  CollapseCostHeap::iterator costHeapPosition;
161  };
162 
164  PMVertex* vertex[3];
166  bool isRemoved;
167  unsigned short submeshID;
168  unsigned int vertexID[3];
169 
170  void computeNormal();
171  bool hasVertex(const PMVertex* v) const;
172  unsigned int getVertexID(const PMVertex* v) const;
173  bool isMalformed();
174  };
175 
177  size_t indexSize;
178  size_t indexCount;
179  };
180 
182  unsigned short* pshort;
183  unsigned int* pint;
184  };
185 
187  unsigned int srcID;
188  unsigned int dstID;
189  unsigned short submeshID;
190  };
191 
198  CollapsedEdges tmpCollapsedEdges; // Tmp container used in collapse().
200 
202 
203 #ifndef NDEBUG
204 
210 #endif
213 
214  size_t calcLodVertexCount(const LodLevel& lodConfig);
215  void tuneContainerSize();
216  void addVertexData(VertexData* vertexData, bool useSharedVertexLookup);
217  template<typename IndexType>
218  void addIndexDataImpl(IndexType* iPos, const IndexType* iEnd, VertexLookupList& lookup, unsigned short submeshID);
219  void addIndexData(IndexData* indexData, bool useSharedVertexLookup, unsigned short submeshID);
220 
221  void computeCosts();
222  bool isBorderVertex(const PMVertex* vertex) const;
223  PMEdge* getPointer(VEdges::iterator it);
224  void computeVertexCollapseCost(PMVertex* vertex);
225  Real computeEdgeCollapseCost(PMVertex* src, PMEdge* dstEdge);
226  virtual void bakeLods();
227  void collapse(PMVertex* vertex);
228  void initialize();
229  void computeLods(LodConfig& lodConfigs);
230  void updateVertexCollapseCost(PMVertex* src);
231 
232  bool hasSrcID(unsigned int srcID, unsigned short submeshID);
233  size_t findDstID(unsigned int srcID, unsigned short submeshID);
234  void replaceVertexID(PMTriangle* triangle, unsigned int oldID, unsigned int newID, PMVertex* dst);
235 
236 #ifndef NDEBUG
237  void assertValidVertex(PMVertex* v);
238  void assertValidMesh();
239  void assertOutdatedCollapseCost(PMVertex* vertex);
240 #endif // ifndef NDEBUG
241 
242  void addTriangleToEdges(PMTriangle* triangle);
243  void removeTriangleFromEdges(PMTriangle* triangle, PMVertex* skip = NULL);
244  void addEdge(PMVertex* v, const PMEdge& edge);
245  void removeEdge(PMVertex* v, const PMEdge& edge);
246  void printTriangle(PMTriangle* triangle, stringstream& str);
247  PMTriangle* findSideTriangle(const PMVertex* v1, const PMVertex* v2);
248  bool isDuplicateTriangle(PMTriangle* triangle, PMTriangle* triangle2);
249  PMTriangle* isDuplicateTriangle(PMTriangle* triangle);
250  int getTriangleID(PMTriangle* triangle);
251  void cleanupMemory();
252 };
253 
254 }
255 #endif
#define _OgreExport
Definition: OgrePlatform.h:257
Summary class collecting together vertex source information.
float Real
Software floating point type.
Summary class collecting together index data source information.
multimap< Real, PMVertex * >::type CollapseCostHeap
vector< PMVertex * >::type VertexLookupList
Improved version of ProgressiveMesh.
HashSet< PMVertex *, PMVertexHash, PMVertexEqual > UniqueVertexSet
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
#define _OgrePrivate
Definition: OgrePlatform.h:258
StringStream stringstream
vector< PMCollapsedEdge >::type CollapsedEdges
_StringBase String
vector< PMIndexBufferInfo >::type IndexBufferInfoList
String mMeshName
The name of the mesh being processed.
PMVertex * collapseTo
Triangle ID set, which are using this vertex.
VectorSet< PMTriangle *, 7 > VTriangles
Structure for automatic LOD configuration.
Definition: OgreLodConfig.h:41
SmallVector - This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the ar...
bool operator==(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)
bool operator<(SharedPtr< T > const &a, SharedPtr< U > const &b)

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri Dec 20 2013 11:13:43