00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef _OSGHALFEDGEGRAPH_H_
00040 #define _OSGHALFEDGEGRAPH_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044
00045 #include <vector>
00046 #include <iterator>
00047
00048 #include <OSGConfig.h>
00049 #include <OSGSystemDef.h>
00050
00051 #include <OSGBaseTypes.h>
00052
00053 #include <OSGLog.h>
00054
00055 OSG_BEGIN_NAMESPACE
00056
00057 #if !defined(OSG_DO_DOC) || defined(OSG_DOC_DEV)
00058
00059 class OSG_SYSTEMLIB_DLLMAPPING HalfEdgeGraph
00060 {
00061 public:
00062
00063 typedef UInt32 IndexT;
00064
00065 private:
00066
00067 enum TriangleState { INVALID = -30, FAN_PART = -20, STRIP_PART = -10,
00068 DEGREE_0 = 0, DEGREE_1 = 1, DEGREE_2 = 2,
00069 DEGREE_3 = 3 };
00070
00071 enum WalkCase { START, LEFT, RIGHT, FINISH };
00072
00073 class HalfEdge;
00074 class Triangle;
00075 class TriangleList;
00076 class TrianglePool;
00077
00078 friend class HalfEdge;
00079 friend class Triangle;
00080 friend class TriangleList;
00081 friend class TrianglePool;
00082
00083 class HalfEdge
00084 {
00085 IndexT _vertexIndex;
00086
00087 public:
00088
00089 Triangle *triangle;
00090 HalfEdge *twin;
00091 HalfEdge *next;
00092
00093 inline void setVertex(IndexT startVertexIndex,
00094 IndexT endVertexIndex);
00095 inline IndexT vertexStart(void);
00096 inline IndexT vertexEnd(void);
00097 };
00098
00099 class Triangle
00100 {
00101 public:
00102
00103 Int32 state;
00104 Triangle *next;
00105 Triangle *prev;
00106 HalfEdge halfEdgeVec[3];
00107
00108 inline void init(void);
00109 inline bool valid (void);
00110 inline void resetDegreeState (const Int32 type);
00111 inline void drop(void);
00112 bool verify (void);
00113 };
00114
00115 class TriangleList
00116 {
00117
00118 public:
00119
00120 Triangle *first;
00121 Triangle *last;
00122
00123 inline TriangleList(void);
00124
00125 inline void reset(void);
00126 inline bool empty(void);
00127 inline UInt32 countElem(void);
00128
00129 inline void release(Triangle &node);
00130 inline void add (Triangle &triangle);
00131 inline void paste (TriangleList &list);
00132 };
00133
00134 inline void dropOutTriangle(Triangle &triangle,
00135 TriangleList *degreeBag);
00136
00137 class TrianglePool
00138 {
00139 public:
00140
00141 class Chunk;
00142
00143 inline TrianglePool (UInt32 chunkSize = DEFAULT_CHUNK_SIZE);
00144 inline ~TrianglePool(void);
00145
00146 inline Triangle *createTriangle(void);
00147 inline void clear(void);
00148 inline UInt32 countElem (void);
00149 inline void setChunkSize(UInt32 chunkSize = DEFAULT_CHUNK_SIZE);
00150
00151 private:
00152
00153 enum { DEFAULT_CHUNK_SIZE = 2048 };
00154
00155 UInt32 _defaultChunkSize;
00156 Chunk *_first;
00157 Chunk *_last;
00158
00159
00160 };
00161
00162 friend class TrianglePool::Chunk;
00163
00164
00165 typedef std::vector < std::pair<UInt32,HalfEdge *> > HalfEdgeLink;
00166 std::vector<HalfEdgeLink> _edgeLinkVec;
00167
00168
00169 TrianglePool _trianglePool;
00170
00171
00172 TriangleList _validTriangleBag;
00173 TriangleList _invalidTriangleBag;
00174
00175
00176 typedef std::pair<IndexT,TriangleList*> Primitive;
00177 std::vector<Primitive> _stripBag;
00178 std::vector<Primitive> _fanBag;
00179 std::vector<Primitive> _triBag;
00180
00181 protected:
00182
00183 inline HalfEdge *getHalfEdge(UInt32 startVertexIndex,
00184 UInt32 endVertexIndex);
00185 inline void addHalfEdge(HalfEdge &halfEdge, UInt32 startVertexIndex,
00186 UInt32 endVertexIndex);
00187 inline HalfEdge *findGateEdge(Triangle *triangleOut,
00188 Triangle *triangleIn);
00189
00190 Int32 calcStripCost(TriangleList &strip, bool reverse);
00191 Int32 fillIndexFromFan(std::vector<IndexT> &indexVec, HalfEdge &firstEdge);
00192 Int32 fillIndexFromStrip(std::vector<IndexT> &indexVec, TriangleList &strip,
00193 bool reverse );
00194
00195 public:
00196
00197 HalfEdgeGraph(void);
00198
00199 HalfEdgeGraph(const HalfEdgeGraph &obj);
00200
00201 virtual ~HalfEdgeGraph (void);
00202
00203 void reserve(UInt32 vertexNum, UInt32 triangleNum,
00204 UInt32 reserveEdges = 8 );
00205
00206 inline bool addTriangle(IndexT v0, IndexT v1, IndexT v2);
00207 inline UInt32 triangleCount(void);
00208
00209 bool verify (bool verbose = false);
00210
00211 UInt32 calcOptPrim(UInt32 iteration = 1, bool doStrip = true,
00212 bool doFan = true, UInt32 minFanTriangleCount = 16);
00213
00214 inline UInt32 primitiveCount(void);
00215
00216 Int32 getPrimitive(std::vector<IndexT> & indexVec, Int32 type = 0);
00217 Int32 calcEgdeLines(std::vector<IndexT> & indexVec, bool codeBorder = false);
00218
00219 void clear(void);
00220
00221 };
00222
00223 class HalfEdgeGraph::TrianglePool::Chunk
00224 {
00225 public:
00226 const UInt32 _size;
00227 UInt32 _freeElem;
00228 Chunk *_next;
00229 Triangle *_data;
00230
00231 inline Chunk (const UInt32 size);
00232 inline ~Chunk (void);
00233 inline UInt32 countElem(void);
00234 };
00235
00236 typedef HalfEdgeGraph* HalfEdgeGraphP;
00237
00238 #endif // remove from all but dev docs
00239
00240 OSG_END_NAMESPACE
00241
00242 #include "OSGHalfEdgeGraph.inl"
00243
00244 #endif // _OSGHALFEDGEGRAPH_H_