OgreProgressiveMeshGenerator.h
Go to the documentation of this file.
/*
* -----------------------------------------------------------------------------
* This source file is part of OGRE
* (Object-oriented Graphics Rendering Engine)
* For the latest info, see http://www.ogre3d.org/
*
* Copyright (c) 2000-2013 Torus Knot Software Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* -----------------------------------------------------------------------------
*/
#ifndef __ProgressiveMeshGenerator_H_
#define __ProgressiveMeshGenerator_H_
#include "OgrePrerequisites.h"
#include "OgreVector3.h"
#include "OgreSmallVector.h"
#include "OgreMesh.h"
#include "OgreLodConfig.h"
namespace Ogre
{
class _OgreExport ProgressiveMeshGeneratorBase
{
public:
virtual void generateLodLevels(LodConfig& lodConfig) = 0;
virtual void generateAutoconfiguredLodLevels(MeshPtr& mesh);
virtual void getAutoconfig(MeshPtr& inMesh, LodConfig& outLodConfig);
virtual ~ProgressiveMeshGeneratorBase() { }
};
class _OgreExport ProgressiveMeshGenerator :
public ProgressiveMeshGeneratorBase
{
public:
ProgressiveMeshGenerator();
virtual ~ProgressiveMeshGenerator();
void generateLodLevels(LodConfig& lodConfig);
protected:
// VectorSet is basically a helper to use a vector as a small set container.
// Also these functions keep the code clean and fast.
// You can insert in O(1) time, if you know that it doesn't exists.
// You can remove in O(1) time, if you know the position of the item.
template<typename T, unsigned S>
struct _OgrePrivate VectorSet :
public SmallVector<T, S> {
typedef typename SmallVector<T, S>::iterator iterator;
void addNotExists(const T& item); // Complexity: O(1)!!
void remove(iterator it); // Complexity: O(1)!!
iterator add(const T& item); // Complexity: O(N)
void removeExists(const T& item); // Complexity: O(N)
bool remove(const T& item); // Complexity: O(N)
void replaceExists(const T& oldItem, const T& newItem); // Complexity: O(N)
bool has(const T& item); // Complexity: O(N)
iterator find(const T& item); // Complexity: O(N)
iterator findExists(const T& item); // Complexity: O(N)
};
struct PMEdge;
struct PMVertex;
struct PMTriangle;
struct PMVertexHash;
struct PMVertexEqual;
struct PMCollapseCostLess;
struct PMCollapsedEdge;
struct PMIndexBufferInfo;
typedef vector<PMVertex>::type VertexList;
typedef vector<PMTriangle>::type TriangleList;
typedef HashSet<PMVertex*, PMVertexHash, PMVertexEqual> UniqueVertexSet;
typedef multimap<Real, PMVertex*>::type CollapseCostHeap;
typedef vector<PMVertex*>::type VertexLookupList;
typedef VectorSet<PMEdge, 8> VEdges;
typedef VectorSet<PMTriangle*, 7> VTriangles;
typedef vector<PMCollapsedEdge>::type CollapsedEdges;
typedef vector<PMIndexBufferInfo>::type IndexBufferInfoList;
// Hash function for UniqueVertexSet.
struct _OgrePrivate PMVertexHash {
ProgressiveMeshGenerator* mGen;
PMVertexHash() { assert(0); }
PMVertexHash(ProgressiveMeshGenerator* gen) { mGen = gen; }
size_t operator() (const PMVertex* v) const;
};
// Equality function for UniqueVertexSet.
struct _OgrePrivate PMVertexEqual {
bool operator() (const PMVertex* lhs, const PMVertex* rhs) const;
};
// Directed edge
struct _OgrePrivate PMEdge {
PMVertex* dst;
Real collapseCost;
int refCount;
explicit PMEdge(PMVertex* destination);
bool operator== (const PMEdge& other) const;
PMEdge& operator= (const PMEdge& b);
PMEdge(const PMEdge& b);
bool operator< (const PMEdge& other) const;
};
struct _OgrePrivate PMVertex {
Vector3 position;
VEdges edges;
VTriangles triangles;
PMVertex* collapseTo;
bool seam;
CollapseCostHeap::iterator costHeapPosition;
};
struct _OgrePrivate PMTriangle {
PMVertex* vertex[3];
Vector3 normal;
bool isRemoved;
unsigned short submeshID;
unsigned int vertexID[3];
void computeNormal();
bool hasVertex(const PMVertex* v) const;
unsigned int getVertexID(const PMVertex* v) const;
bool isMalformed();
};
struct _OgrePrivate PMIndexBufferInfo {
size_t indexSize;
size_t indexCount;
};
union _OgrePrivate IndexBufferPointer {
unsigned short* pshort;
unsigned int* pint;
};
struct _OgrePrivate PMCollapsedEdge {
unsigned int srcID;
unsigned int dstID;
unsigned short submeshID;
};
VertexLookupList mSharedVertexLookup;
VertexLookupList mVertexLookup;
VertexList mVertexList;
TriangleList mTriangleList;
UniqueVertexSet mUniqueVertexSet;
CollapseCostHeap mCollapseCostHeap;
CollapsedEdges tmpCollapsedEdges; // Tmp container used in collapse().
IndexBufferInfoList mIndexBufferInfoList;
MeshPtr mMesh;
#ifndef NDEBUG
String mMeshName;
#endif
Real mMeshBoundingSphereRadius;
Real mCollapseCostLimit;
size_t calcLodVertexCount(const LodLevel& lodConfig);
void tuneContainerSize();
void addVertexData(VertexData* vertexData, bool useSharedVertexLookup);
template<typename IndexType>
void addIndexDataImpl(IndexType* iPos, const IndexType* iEnd, VertexLookupList& lookup, unsigned short submeshID);
void addIndexData(IndexData* indexData, bool useSharedVertexLookup, unsigned short submeshID);
void computeCosts();
bool isBorderVertex(const PMVertex* vertex) const;
PMEdge* getPointer(VEdges::iterator it);
void computeVertexCollapseCost(PMVertex* vertex);
Real computeEdgeCollapseCost(PMVertex* src, PMEdge* dstEdge);
virtual void bakeLods();
void collapse(PMVertex* vertex);
void initialize();
void computeLods(LodConfig& lodConfigs);
void updateVertexCollapseCost(PMVertex* src);
bool hasSrcID(unsigned int srcID, unsigned short submeshID);
size_t findDstID(unsigned int srcID, unsigned short submeshID);
void replaceVertexID(PMTriangle* triangle, unsigned int oldID, unsigned int newID, PMVertex* dst);
#ifndef NDEBUG
void assertValidVertex(PMVertex* v);
void assertValidMesh();
void assertOutdatedCollapseCost(PMVertex* vertex);
#endif // ifndef NDEBUG
void addTriangleToEdges(PMTriangle* triangle);
void removeTriangleFromEdges(PMTriangle* triangle, PMVertex* skip = NULL);
void addEdge(PMVertex* v, const PMEdge& edge);
void removeEdge(PMVertex* v, const PMEdge& edge);
void printTriangle(PMTriangle* triangle, stringstream& str);
PMTriangle* findSideTriangle(const PMVertex* v1, const PMVertex* v2);
bool isDuplicateTriangle(PMTriangle* triangle, PMTriangle* triangle2);
PMTriangle* isDuplicateTriangle(PMTriangle* triangle);
int getTriangleID(PMTriangle* triangle);
void cleanupMemory();
};
}
#endif
Ogre::ProgressiveMeshGenerator::mCollapseCostLimit
Real mCollapseCostLimit
Definition: OgreProgressiveMeshGenerator.h:212
Ogre::ProgressiveMeshGenerator::tmpCollapsedEdges
CollapsedEdges tmpCollapsedEdges
Definition: OgreProgressiveMeshGenerator.h:198
Ogre::ProgressiveMeshGenerator::mIndexBufferInfoList
IndexBufferInfoList mIndexBufferInfoList
Definition: OgreProgressiveMeshGenerator.h:199
Ogre::ProgressiveMeshGenerator::PMIndexBufferInfo
Definition: OgreProgressiveMeshGenerator.h:176
OgreVector3.h
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::ProgressiveMeshGenerator::PMEdge::refCount
int refCount
Definition: OgreProgressiveMeshGenerator.h:144
Ogre::ProgressiveMeshGenerator::PMVertexHash
Definition: OgreProgressiveMeshGenerator.h:127
Ogre::ProgressiveMeshGenerator::mMeshBoundingSphereRadius
Real mMeshBoundingSphereRadius
Definition: OgreProgressiveMeshGenerator.h:211
Ogre::ProgressiveMeshGeneratorBase
Definition: OgreProgressiveMeshGenerator.h:41
Ogre::ProgressiveMeshGenerator::PMVertex
Definition: OgreProgressiveMeshGenerator.h:153
Ogre::ProgressiveMeshGenerator::mMesh
MeshPtr mMesh
Definition: OgreProgressiveMeshGenerator.h:201
Ogre::VertexData
Summary class collecting together vertex source information.
Definition: OgreVertexIndexData.h:49
Ogre::ProgressiveMeshGenerator::PMVertexHash::mGen
ProgressiveMeshGenerator * mGen
Definition: OgreProgressiveMeshGenerator.h:128
Ogre::ProgressiveMeshGenerator::PMVertex::costHeapPosition
CollapseCostHeap::iterator costHeapPosition
Definition: OgreProgressiveMeshGenerator.h:160
OgreMesh.h
Ogre::ProgressiveMeshGenerator::PMTriangle::normal
Vector3 normal
Definition: OgreProgressiveMeshGenerator.h:165
Ogre::ProgressiveMeshGenerator::PMIndexBufferInfo::indexSize
size_t indexSize
Definition: OgreProgressiveMeshGenerator.h:177
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::ProgressiveMeshGenerator::mTriangleList
TriangleList mTriangleList
Definition: OgreProgressiveMeshGenerator.h:195
Ogre::IndexData
Summary class collecting together index data source information.
Definition: OgreVertexIndexData.h:242
Ogre::ProgressiveMeshGenerator::PMVertex::edges
VEdges edges
Definition: OgreProgressiveMeshGenerator.h:155
Ogre::ProgressiveMeshGenerator::CollapseCostHeap
multimap< Real, PMVertex * >::type CollapseCostHeap
Definition: OgreProgressiveMeshGenerator.h:117
Ogre::ProgressiveMeshGenerator::VectorSet
Definition: OgreProgressiveMeshGenerator.h:90
Ogre::ProgressiveMeshGenerator::VectorSet::iterator
SmallVector< T, S >::iterator iterator
Definition: OgreProgressiveMeshGenerator.h:92
Ogre::ProgressiveMeshGenerator::PMEdge::collapseCost
Real collapseCost
Definition: OgreProgressiveMeshGenerator.h:143
Ogre::ProgressiveMeshGenerator::PMVertexEqual
Definition: OgreProgressiveMeshGenerator.h:136
Ogre::ProgressiveMeshGenerator::VertexLookupList
vector< PMVertex * >::type VertexLookupList
Definition: OgreProgressiveMeshGenerator.h:118
Ogre::ProgressiveMeshGenerator::VertexList
vector< PMVertex >::type VertexList
Definition: OgreProgressiveMeshGenerator.h:112
Ogre::ProgressiveMeshGenerator
Improved version of ProgressiveMesh.
Definition: OgreProgressiveMeshGenerator.h:72
Ogre::ProgressiveMeshGenerator::UniqueVertexSet
HashSet< PMVertex *, PMVertexHash, PMVertexEqual > UniqueVertexSet
Definition: OgreProgressiveMeshGenerator.h:116
Ogre::Vector3
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
Ogre::ProgressiveMeshGenerator::PMTriangle
Definition: OgreProgressiveMeshGenerator.h:163
OgrePrerequisites.h
_OgrePrivate
#define _OgrePrivate
Definition: OgrePlatform.h:258
Ogre::stringstream
StringStream stringstream
Definition: OgrePrerequisites.h:441
Ogre::ProgressiveMeshGenerator::PMVertexHash::PMVertexHash
PMVertexHash(ProgressiveMeshGenerator *gen)
Definition: OgreProgressiveMeshGenerator.h:131
Ogre::ProgressiveMeshGenerator::CollapsedEdges
vector< PMCollapsedEdge >::type CollapsedEdges
Definition: OgreProgressiveMeshGenerator.h:123
Ogre::ProgressiveMeshGeneratorBase::~ProgressiveMeshGeneratorBase
virtual ~ProgressiveMeshGeneratorBase()
Definition: OgreProgressiveMeshGenerator.h:66
Ogre::ProgressiveMeshGenerator::PMTriangle::isRemoved
bool isRemoved
Definition: OgreProgressiveMeshGenerator.h:166
Ogre::ProgressiveMeshGenerator::PMVertexHash::PMVertexHash
PMVertexHash()
Definition: OgreProgressiveMeshGenerator.h:130
Ogre::ProgressiveMeshGenerator::PMVertex::seam
bool seam
Definition: OgreProgressiveMeshGenerator.h:159
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::ProgressiveMeshGenerator::PMVertex::triangles
VTriangles triangles
Definition: OgreProgressiveMeshGenerator.h:156
Ogre::ProgressiveMeshGenerator::TriangleList
vector< PMTriangle >::type TriangleList
Definition: OgreProgressiveMeshGenerator.h:115
Ogre::ProgressiveMeshGenerator::PMCollapsedEdge
Definition: OgreProgressiveMeshGenerator.h:186
Ogre::ProgressiveMeshGenerator::PMCollapsedEdge::srcID
unsigned int srcID
Definition: OgreProgressiveMeshGenerator.h:187
Ogre::ProgressiveMeshGenerator::IndexBufferInfoList
vector< PMIndexBufferInfo >::type IndexBufferInfoList
Definition: OgreProgressiveMeshGenerator.h:124
Ogre::ProgressiveMeshGenerator::IndexBufferPointer
Definition: OgreProgressiveMeshGenerator.h:181
Ogre::ProgressiveMeshGenerator::PMEdge
Definition: OgreProgressiveMeshGenerator.h:141
Ogre::ProgressiveMeshGenerator::PMIndexBufferInfo::indexCount
size_t indexCount
Definition: OgreProgressiveMeshGenerator.h:178
Ogre::ProgressiveMeshGenerator::mMeshName
String mMeshName
The name of the mesh being processed.
Definition: OgreProgressiveMeshGenerator.h:209
Ogre::ProgressiveMeshGenerator::PMVertex::collapseTo
PMVertex * collapseTo
Triangle ID set, which are using this vertex.
Definition: OgreProgressiveMeshGenerator.h:158
Ogre::ProgressiveMeshGenerator::mUniqueVertexSet
UniqueVertexSet mUniqueVertexSet
Definition: OgreProgressiveMeshGenerator.h:196
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::ProgressiveMeshGenerator::mCollapseCostHeap
CollapseCostHeap mCollapseCostHeap
Definition: OgreProgressiveMeshGenerator.h:197
Ogre::ProgressiveMeshGenerator::VTriangles
VectorSet< PMTriangle *, 7 > VTriangles
Definition: OgreProgressiveMeshGenerator.h:121
Ogre::ProgressiveMeshGenerator::IndexBufferPointer::pshort
unsigned short * pshort
Definition: OgreProgressiveMeshGenerator.h:182
Ogre::LodConfig
Definition: OgreLodConfig.h:104
Ogre::LodLevel
Structure for automatic LOD configuration.
Definition: OgreLodConfig.h:41
Ogre::SmallVector
SmallVector - This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the ar...
Definition: OgreSmallVector.h:717
Ogre::ProgressiveMeshGenerator::PMVertex::position
Vector3 position
Definition: OgreProgressiveMeshGenerator.h:154
Ogre::SharedPtr< Mesh >
Ogre::ProgressiveMeshGenerator::PMCollapsedEdge::submeshID
unsigned short submeshID
Definition: OgreProgressiveMeshGenerator.h:189
Ogre::vector
Definition: OgrePrerequisites.h:491
Ogre::operator==
bool operator==(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)
Definition: OgreMemorySTLAllocator.h:184
Ogre::ProgressiveMeshGenerator::PMTriangle::submeshID
unsigned short submeshID
Definition: OgreProgressiveMeshGenerator.h:167
Ogre::ProgressiveMeshGenerator::mSharedVertexLookup
VertexLookupList mSharedVertexLookup
Definition: OgreProgressiveMeshGenerator.h:192
OgreSmallVector.h
Ogre::ProgressiveMeshGenerator::PMEdge::dst
PMVertex * dst
Definition: OgreProgressiveMeshGenerator.h:142
Ogre::ProgressiveMeshGenerator::IndexBufferPointer::pint
unsigned int * pint
Definition: OgreProgressiveMeshGenerator.h:183
Ogre::ProgressiveMeshGenerator::mVertexLookup
VertexLookupList mVertexLookup
Definition: OgreProgressiveMeshGenerator.h:193
Ogre::ProgressiveMeshGenerator::VEdges
VectorSet< PMEdge, 8 > VEdges
Definition: OgreProgressiveMeshGenerator.h:120
OgreLodConfig.h
Ogre::ProgressiveMeshGenerator::PMCollapsedEdge::dstID
unsigned int dstID
Definition: OgreProgressiveMeshGenerator.h:188
Ogre::operator<
bool operator<(SharedPtr< T > const &a, SharedPtr< U > const &b)
Definition: OgreSharedPtr.h:326
Ogre::multimap
Definition: OgrePrerequisites.h:547
Ogre::ProgressiveMeshGenerator::mVertexList
VertexList mVertexList
Definition: OgreProgressiveMeshGenerator.h:194

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.