1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGSTRIPERHALFEDGEGRAPH_H_
40 #define _OSGSTRIPERHALFEDGEGRAPH_H_
48 #include "OSGDrawableDef.h"
49 #include "OSGBaseTypes.h"
54 /*! \ingroup GrpDrawablesGeometryUtils
57 class OSG_DRAWABLE_DLLMAPPING StriperHalfEdgeGraph
61 typedef UInt32 IndexT
;
76 enum WalkCase
{ START
, LEFT
, RIGHT
, FINISH
};
83 friend class HalfEdge
;
84 friend class Triangle
;
85 friend class TriangleList
;
86 friend class TrianglePool
;
100 inline void setVertex(IndexT startVertexIndex
,
101 IndexT endVertexIndex
);
102 inline IndexT
vertexStart(void);
103 inline IndexT
vertexEnd(void);
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);
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
);
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
);
166 enum { DEFAULT_CHUNK_SIZE
= 2048 };
168 UInt32 _defaultChunkSize
;
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
;
186 TriangleList _validTriangleBag
;
187 TriangleList _invalidTriangleBag
;
190 typedef std::pair
<IndexT
,TriangleList
*> Primitive
;
191 std::vector
<Primitive
> _stripBag
;
192 std::vector
<Primitive
> _fanBag
;
193 std::vector
<Primitive
> _triBag
;
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
,
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);
239 /*! \ingroup GrpDrawablesGeometryUtils
243 class StriperHalfEdgeGraph::TrianglePool::Chunk
251 inline Chunk (const UInt32 size
);
252 inline ~Chunk (void);
253 inline UInt32
countElem(void);
257 Chunk(const Chunk
&other
);
258 void operator =(const Chunk
&rhs
);
261 /*! \ingroup GrpDrawablesGeometryUtils
264 typedef StriperHalfEdgeGraph
* StriperHalfEdgeGraphP
;
268 #include "OSGStriperHalfEdgeGraph.inl"
270 #endif // _OSGSTRIPERHALFEDGEGRAPH_H_