OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreLodData.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-2014 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 _LodData_H__
30 #define _LodData_H__
31 
32 #include "OgreLodPrerequisites.h"
33 #include "OgreVectorSet.h"
34 #include "OgreVectorSetImpl.h"
35 #include "OgreVector3.h"
36 
37 #ifndef MESHLOD_QUALITY
38 #define MESHLOD_QUALITY 2
42 #endif
43 
44 namespace Ogre
45 {
46 
48 
49  static const Real NEVER_COLLAPSE_COST /*= std::numeric_limits<Real>::max()*/;
50  static const Real UNINITIALIZED_COLLAPSE_COST /*= std::numeric_limits<Real>::infinity()*/;
51 
52  struct Edge;
53  struct Vertex;
54  struct Triangle;
55  struct VertexHash;
56  struct VertexEqual;
57 
60  typedef HashSet<Vertex*, VertexHash, VertexEqual> UniqueVertexSet;
62 
65 
66  // Hash function for UniqueVertexSet.
67  struct VertexHash {
69 
70  VertexHash() : mGen(0) { assert(0); }
71  VertexHash(LodData* gen) { mGen = gen; }
72  size_t operator() (const Vertex* v) const;
73  };
74 
75  // Equality function for UniqueVertexSet.
76  struct VertexEqual {
77  bool operator() (const Vertex* lhs, const Vertex* rhs) const;
78  };
79 
80  // Directed edge
81  struct Edge {
82  Vertex* dst; // destination vertex. (other end of the edge)
83  Real collapseCost; // cost of the edge.
84  int refCount; // Reference count on how many triangles are using this edge. The edge will be removed when it gets 0.
85 
86  explicit Edge(Vertex* destination);
87  bool operator== (const Edge& other) const;
88  Edge& operator= (const Edge& b);
89  Edge(const Edge& b);
90  bool operator< (const Edge& other) const;
91  };
92 
93  struct Vertex {
97 
100  bool seam;
101  CollapseCostHeap::iterator costHeapPosition;
102 
103  void addEdge(const Edge& edge);
104  void removeEdge(const Edge& edge);
105  };
106 
107  struct Triangle {
108  Vertex* vertex[3];
110  bool isRemoved;
111  unsigned short submeshID;
112  unsigned int vertexID[3];
113 
114  void computeNormal();
115  bool hasVertex(const Vertex* v) const;
116  unsigned int getVertexID(const Vertex* v) const;
117  bool isMalformed();
118  };
119 
121  unsigned short* pshort;
122  unsigned int* pint;
123  };
124 
126  size_t indexSize;
127  size_t indexCount;
128  IndexBufferPointer buf; // Used by output providers only!
129  size_t prevOnlyIndexCount; // Used by output providers only!
130  size_t prevIndexCount; // Used by output providers only!
131  };
132 
134 
137 
140 
144 #if OGRE_DEBUG_MODE
145 
150  String mMeshName;
151 #endif
154 
155  template<typename T, typename A>
156  static size_t getVectorIDFromPointer(const std::vector<T, A>& vec, const T* pointer) {
157  size_t id = pointer - &vec.at(0);
158  OgreAssert(id < vec.size() && (&vec[id] == pointer), "Invalid pointer");
159  return id;
160  }
161 
163  mUniqueVertexSet((UniqueVertexSet::size_type) 0,
164  (const UniqueVertexSet::hasher&) VertexHash(this)),
165  mMeshBoundingSphereRadius(0.0f),
166  mUseVertexNormals(true)
167  {}
168 };
169 
170 }
171 #endif
VTriangles triangles
Definition: OgreLodData.h:96
VectorSet< Edge, 8 > VEdges
Definition: OgreLodData.h:63
float Real
Software floating point type.
unsigned short submeshID
Definition: OgreLodData.h:111
CollapseCostHeap::iterator costHeapPosition
Definition: OgreLodData.h:101
bool operator<(SharedPtr< T > const &a, SharedPtr< U > const &b)
vector< Triangle >::type TriangleList
Definition: OgreLodData.h:59
CollapseCostHeap mCollapseCostHeap
Makes possible to get the vertices with the smallest collapse cost.
Definition: OgreLodData.h:142
VertexHash(LodData *gen)
Definition: OgreLodData.h:71
bool mUseVertexNormals
Definition: OgreLodData.h:153
#define OgreAssert(a, b)
Definition: OgreException.h:60
HashSet< Vertex *, VertexHash, VertexEqual > UniqueVertexSet
Definition: OgreLodData.h:60
Real mMeshBoundingSphereRadius
Definition: OgreLodData.h:152
multimap< Real, Vertex * >::type CollapseCostHeap
Definition: OgreLodData.h:61
TriangleList mTriangleList
Definition: OgreLodData.h:139
vector< IndexBufferInfo >::type IndexBufferInfoList
Definition: OgreLodData.h:133
static size_t getVectorIDFromPointer(const std::vector< T, A > &vec, const T *pointer)
Definition: OgreLodData.h:156
IndexBufferInfoList mIndexBufferInfoList
Definition: OgreLodData.h:143
vector< Vertex >::type VertexList
Definition: OgreLodData.h:56
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
#define _OgreLodExport
UniqueVertexSet mUniqueVertexSet
Provides position based vertex lookup. Position is the real identifier of a vertex.
Definition: OgreLodData.h:136
VectorSet< Triangle *, 7 > VTriangles
Definition: OgreLodData.h:64
_StringBase String
Definition: OgreCommon.h:53
VertexList mVertexList
Definition: OgreLodData.h:138
bool operator==(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)