changed: gcc8 base update
[opensg.git] / Source / System / NodeCores / Drawables / Geometry / Util / OSGStriperHalfEdgeGraph.h
blob05b69b19ddf779bd9543f9c15b2b61d2674310e2
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGSTRIPERHALFEDGEGRAPH_H_
40 #define _OSGSTRIPERHALFEDGEGRAPH_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
45 #include <vector>
46 #include <iterator>
48 #include "OSGDrawableDef.h"
49 #include "OSGBaseTypes.h"
50 #include "OSGLog.h"
52 OSG_BEGIN_NAMESPACE
54 /*! \ingroup GrpDrawablesGeometryUtils
55 \nohierarchy
57 class OSG_DRAWABLE_DLLMAPPING StriperHalfEdgeGraph
59 public:
61 typedef UInt32 IndexT;
63 private:
65 enum TriangleState
67 INVALID = -30,
68 FAN_PART = -20,
69 STRIP_PART = -10,
70 DEGREE_0 = 0,
71 DEGREE_1 = 1,
72 DEGREE_2 = 2,
73 DEGREE_3 = 3
76 enum WalkCase { START, LEFT, RIGHT, FINISH };
78 class HalfEdge;
79 class Triangle;
80 class TriangleList;
81 class TrianglePool;
83 friend class HalfEdge;
84 friend class Triangle;
85 friend class TriangleList;
86 friend class TrianglePool;
88 /*! \nohierarchy
90 class HalfEdge
92 IndexT _vertexIndex;
94 public:
96 Triangle *triangle;
97 HalfEdge *twin;
98 HalfEdge *next;
100 inline void setVertex(IndexT startVertexIndex,
101 IndexT endVertexIndex);
102 inline IndexT vertexStart(void);
103 inline IndexT vertexEnd(void);
106 /*! \nohierarchy
108 class Triangle
110 public:
112 Int32 state;
113 Triangle *next;
114 Triangle *prev;
115 HalfEdge halfEdgeVec[3];
117 inline void init(void);
118 inline bool valid (void);
119 inline void resetDegreeState (const Int32 type);
120 inline void drop(void);
121 bool verify (void);
124 /*! \nohierarchy
126 class TriangleList
129 public:
131 Triangle *first;
132 Triangle *last;
134 inline TriangleList(void);
136 inline void reset(void);
137 inline bool empty(void);
138 inline UInt32 countElem(void);
140 inline void release(Triangle &node);
141 inline void add (Triangle &triangle);
142 inline void paste (TriangleList &list);
145 void dropOutTriangle(Triangle &triangle,
146 TriangleList *degreeBag);
148 /*! \nohierarchy
150 class TrianglePool
152 public:
154 class Chunk;
156 inline TrianglePool (UInt32 chunkSize = DEFAULT_CHUNK_SIZE);
157 inline ~TrianglePool(void);
159 inline Triangle *createTriangle(void);
160 inline void clear(void);
161 inline UInt32 countElem (void);
162 inline void setChunkSize(UInt32 chunkSize = DEFAULT_CHUNK_SIZE);
164 private:
166 enum { DEFAULT_CHUNK_SIZE = 2048 };
168 UInt32 _defaultChunkSize;
169 Chunk *_first;
170 Chunk *_last;
172 TrianglePool(const TrianglePool &other);
173 void operator =(const TrianglePool &rhs);
176 friend class TrianglePool::Chunk;
178 // temporary vector data structure
179 typedef std::vector < std::pair<UInt32,HalfEdge *> > HalfEdgeLink;
180 std::vector<HalfEdgeLink> _edgeLinkVec;
182 // Triangle Data Pool
183 TrianglePool _trianglePool;
185 // Input
186 TriangleList _validTriangleBag;
187 TriangleList _invalidTriangleBag;
189 // Output
190 typedef std::pair<IndexT,TriangleList*> Primitive;
191 std::vector<Primitive> _stripBag;
192 std::vector<Primitive> _fanBag;
193 std::vector<Primitive> _triBag;
195 protected:
197 inline HalfEdge *getHalfEdge(UInt32 startVertexIndex,
198 UInt32 endVertexIndex);
199 inline void addHalfEdge(HalfEdge &halfEdge, UInt32 startVertexIndex,
200 UInt32 endVertexIndex);
201 inline HalfEdge *findGateEdge(Triangle *triangleOut,
202 Triangle *triangleIn);
204 Int32 calcStripCost (TriangleList &strip, bool reverse);
205 Int32 fillIndexFromFan (std::vector<IndexT> &indexVec,
206 HalfEdge &firstEdge);
207 Int32 fillIndexFromStrip(std::vector<IndexT> &indexVec,
208 TriangleList &strip,
209 bool reverse );
211 public:
213 StriperHalfEdgeGraph(void);
215 StriperHalfEdgeGraph(const StriperHalfEdgeGraph &obj);
217 virtual ~StriperHalfEdgeGraph (void);
219 void reserve(UInt32 vertexNum, UInt32 triangleNum,
220 UInt32 reserveEdges = 8 );
222 inline bool addTriangle(IndexT v0, IndexT v1, IndexT v2);
223 inline UInt32 triangleCount(void);
225 bool verify (bool verbose = false);
227 UInt32 calcOptPrim(UInt32 iteration = 1, bool doStrip = true,
228 bool doFan = true, UInt32 minFanTriangleCount = 16);
230 inline UInt32 primitiveCount(void);
232 Int32 getPrimitive(std::vector<IndexT> & indexVec, Int32 type = 0);
233 Int32 calcEgdeLines(std::vector<IndexT> & indexVec, bool codeBorder = false);
235 void clear(void);
239 /*! \ingroup GrpDrawablesGeometryUtils
240 \nohierarchy
243 class StriperHalfEdgeGraph::TrianglePool::Chunk
245 public:
246 const UInt32 _size;
247 UInt32 _freeElem;
248 Chunk *_next;
249 Triangle *_data;
251 inline Chunk (const UInt32 size);
252 inline ~Chunk (void);
253 inline UInt32 countElem(void);
255 private:
257 Chunk(const Chunk &other);
258 void operator =(const Chunk &rhs);
261 /*! \ingroup GrpDrawablesGeometryUtils
264 typedef StriperHalfEdgeGraph* StriperHalfEdgeGraphP;
266 OSG_END_NAMESPACE
268 #include "OSGStriperHalfEdgeGraph.inl"
270 #endif // _OSGSTRIPERHALFEDGEGRAPH_H_