Visualization Library 2.0.0-b5

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
tri_stripper.h
Go to the documentation of this file.
1 
3 //
4 // Copyright (C) 2004 Tanguy Fautré.
5 //
6 // This software is provided 'as-is', without any express or implied
7 // warranty. In no event will the authors be held liable for any damages
8 // arising from the use of this software.
9 //
10 // Permission is granted to anyone to use this software for any purpose,
11 // including commercial applications, and to alter it and redistribute it
12 // freely, subject to the following restrictions:
13 //
14 // 1. The origin of this software must not be misrepresented; you must not
15 // claim that you wrote the original software. If you use this software
16 // in a product, an acknowledgment in the product documentation would be
17 // appreciated but is not required.
18 // 2. Altered source versions must be plainly marked as such, and must not be
19 // misrepresented as being the original software.
20 // 3. This notice may not be removed or altered from any source distribution.
21 //
22 // Tanguy Fautré// softdev@telenet.be // ////////////////////////////////////////////////////////////////////// // // Tri Stripper // ************ // // Post TnL cache aware triangle stripifier in O(n.log(n)). // // History: see ChangeLog // ////////////////////////////////////////////////////////////////////// // SVN: $Id: tri_stripper.h 86 2005-06-08 17:47:27Z gpsnoopy $ ////////////////////////////////////////////////////////////////////// // Protection against old C habits #if defined(max) #error "'max' macro defined! It's against the C++ standard. Please use 'std::max' instead (undefine 'max' macro if it was defined in another library)." #endif // Protection against old C habits #if defined(min) #error "'min' macro defined! It's against the C++ standard. Please use 'std::min' instead (undefine 'min' macro if it was defined in another library)." #endif #ifndef TRI_STRIPPER_HEADER_GUARD_TRI_STRIPPER_H #define TRI_STRIPPER_HEADER_GUARD_TRI_STRIPPER_H #include "public_types.h" #include "detail/cache_simulator.h" #include "detail/graph_array.h" #include "detail/heap_array.h" #include "detail/types.h" namespace triangle_stripper { class tri_stripper { public: tri_stripper(const indices & TriIndices); void Strip(primitive_vector * out_pPrimitivesVector); /* Stripifier Algorithm Settings */ // Set the post-T&L cache size (0 disables the cache optimizer). void SetCacheSize(size_t CacheSize = 10); // Set the minimum size of a triangle strip (should be at least 2 triangles). // The stripifier discard any candidate strips that does not satisfy the minimum size condition. void SetMinStripSize(size_t MinStripSize = 2); // Set the backward search mode in addition to the forward search mode. // In forward mode, the candidate strips are build with the current candidate triangle being the first // triangle of the strip. When the backward mode is enabled, the stripifier also tests candidate strips // where the current candidate triangle is the last triangle of the strip. // Enable this if you want better results at the expense of being slightly slower. // Note: Do *NOT* use this when the cache optimizer is enabled; it only gives worse results. void SetBackwardSearch(bool Enabled = false); // Set the cache simulator FIFO behavior (does nothing if the cache optimizer is disabled). // When enabled, the cache is simulated as a simple FIFO structure. However, when // disabled, indices that trigger cache hits are not pushed into the FIFO structure. // This allows simulating some GPUs that do not duplicate cache entries (e.g. NV25 or greater). void SetPushCacheHits(bool Enabled = true); /* End Settings */ private: typedef detail::graph_array<detail::triangle> triangle_graph; typedef detail::heap_array<size_t, std::greater<size_t> > triangle_heap; typedef std::vector<size_t> candidates; typedef triangle_graph::node_iterator tri_iterator; typedef triangle_graph::const_node_iterator const_tri_iterator; typedef triangle_graph::out_arc_iterator link_iterator; typedef triangle_graph::const_out_arc_iterator const_link_iterator; void InitTriHeap(); void Stripify(); void AddLeftTriangles(); void ResetStripIDs(); detail::strip FindBestStrip(); detail::strip ExtendToStrip(size_t Start, detail::triangle_order Order); detail::strip BackExtendToStrip(size_t Start, detail::triangle_order Order, bool ClockWise); const_link_iterator LinkToNeighbour(const_tri_iterator Node, bool ClockWise, detail::triangle_order & Order, bool NotSimulation); const_link_iterator BackLinkToNeighbour(const_tri_iterator Node, bool ClockWise, detail::triangle_order & Order); void BuildStrip(const detail::strip Strip); void MarkTriAsTaken(size_t i); void AddIndex(index i, bool NotSimulation); void BackAddIndex(index i); void AddTriangle(const detail::triangle & Tri, detail::triangle_order Order, bool NotSimulation); void BackAddTriangle(const detail::triangle & Tri, detail::triangle_order Order); bool Cache() const; size_t CacheSize() const; static detail::triangle_edge FirstEdge(const detail::triangle & Triangle, detail::triangle_order Order); static detail::triangle_edge LastEdge(const detail::triangle & Triangle, detail::triangle_order Order); primitive_vector m_PrimitivesVector; triangle_graph m_Triangles; triangle_heap m_TriHeap; candidates m_Candidates; detail::cache_simulator m_Cache; detail::cache_simulator m_BackCache; size_t m_StripID; size_t m_MinStripSize; bool m_BackwardSearch; bool m_FirstRun; }; ////////////////////////////////////////////////////////////////////////// // tri_stripper inline functions ////////////////////////////////////////////////////////////////////////// inline void tri_stripper::SetCacheSize(const size_t CacheSize) { m_Cache.resize(CacheSize); m_BackCache.resize(CacheSize); } inline void tri_stripper::SetMinStripSize(const size_t MinStripSize) { if (MinStripSize < 2) m_MinStripSize = 2; else m_MinStripSize = MinStripSize; } inline void tri_stripper::SetBackwardSearch(const bool Enabled) { m_BackwardSearch = Enabled; } inline void tri_stripper::SetPushCacheHits(bool Enabled) { m_Cache.push_cache_hits(Enabled); } } // namespace triangle_stripper #endif // TRI_STRIPPER_HEADER_GUARD_TRI_STRIPPER_H
23 // softdev@telenet.be
24 //
26 //
27 // Tri Stripper
28 // ************
29 //
30 // Post TnL cache aware triangle stripifier in O(n.log(n)).
31 //
32 // History: see ChangeLog
33 //
35 // SVN: $Id: tri_stripper.h 86 2005-06-08 17:47:27Z gpsnoopy $
37 
38 // Protection against old C habits
39 #if defined(max)
40 #error "'max' macro defined! It's against the C++ standard. Please use 'std::max' instead (undefine 'max' macro if it was defined in another library)."
41 #endif
42 
43 // Protection against old C habits
44 #if defined(min)
45 #error "'min' macro defined! It's against the C++ standard. Please use 'std::min' instead (undefine 'min' macro if it was defined in another library)."
46 #endif
47 
48 
49 
50 #ifndef TRI_STRIPPER_HEADER_GUARD_TRI_STRIPPER_H
51 #define TRI_STRIPPER_HEADER_GUARD_TRI_STRIPPER_H
52 
53 #include "public_types.h"
54 
55 #include "detail/cache_simulator.h"
56 #include "detail/graph_array.h"
57 #include "detail/heap_array.h"
58 #include "detail/types.h"
59 
60 
61 
62 
63 namespace triangle_stripper {
64 
65 
66 
67 
69 {
70 public:
71 
72  tri_stripper(const indices & TriIndices);
73 
74  void Strip(primitive_vector * out_pPrimitivesVector);
75 
76  /* Stripifier Algorithm Settings */
77 
78  // Set the post-T&L cache size (0 disables the cache optimizer).
79  void SetCacheSize(size_t CacheSize = 10);
80 
81  // Set the minimum size of a triangle strip (should be at least 2 triangles).
82  // The stripifier discard any candidate strips that does not satisfy the minimum size condition.
83  void SetMinStripSize(size_t MinStripSize = 2);
84 
85  // Set the backward search mode in addition to the forward search mode.
86  // In forward mode, the candidate strips are build with the current candidate triangle being the first
87  // triangle of the strip. When the backward mode is enabled, the stripifier also tests candidate strips
88  // where the current candidate triangle is the last triangle of the strip.
89  // Enable this if you want better results at the expense of being slightly slower.
90  // Note: Do *NOT* use this when the cache optimizer is enabled; it only gives worse results.
91  void SetBackwardSearch(bool Enabled = false);
92 
93  // Set the cache simulator FIFO behavior (does nothing if the cache optimizer is disabled).
94  // When enabled, the cache is simulated as a simple FIFO structure. However, when
95  // disabled, indices that trigger cache hits are not pushed into the FIFO structure.
96  // This allows simulating some GPUs that do not duplicate cache entries (e.g. NV25 or greater).
97  void SetPushCacheHits(bool Enabled = true);
98 
99  /* End Settings */
100 
101 private:
102 
105  typedef std::vector<size_t> candidates;
106  typedef triangle_graph::node_iterator tri_iterator;
107  typedef triangle_graph::const_node_iterator const_tri_iterator;
108  typedef triangle_graph::out_arc_iterator link_iterator;
109  typedef triangle_graph::const_out_arc_iterator const_link_iterator;
110 
111  void InitTriHeap();
112  void Stripify();
113  void AddLeftTriangles();
114  void ResetStripIDs();
115 
116  detail::strip FindBestStrip();
117  detail::strip ExtendToStrip(size_t Start, detail::triangle_order Order);
118  detail::strip BackExtendToStrip(size_t Start, detail::triangle_order Order, bool ClockWise);
119  const_link_iterator LinkToNeighbour(const_tri_iterator Node, bool ClockWise, detail::triangle_order & Order, bool NotSimulation);
120  const_link_iterator BackLinkToNeighbour(const_tri_iterator Node, bool ClockWise, detail::triangle_order & Order);
121  void BuildStrip(const detail::strip Strip);
122  void MarkTriAsTaken(size_t i);
123  void AddIndex(index i, bool NotSimulation);
124  void BackAddIndex(index i);
125  void AddTriangle(const detail::triangle & Tri, detail::triangle_order Order, bool NotSimulation);
126  void BackAddTriangle(const detail::triangle & Tri, detail::triangle_order Order);
127 
128  bool Cache() const;
129  size_t CacheSize() const;
130 
131  static detail::triangle_edge FirstEdge(const detail::triangle & Triangle, detail::triangle_order Order);
132  static detail::triangle_edge LastEdge(const detail::triangle & Triangle, detail::triangle_order Order);
133 
134  primitive_vector m_PrimitivesVector;
135  triangle_graph m_Triangles;
136  triangle_heap m_TriHeap;
137  candidates m_Candidates;
138  detail::cache_simulator m_Cache;
139  detail::cache_simulator m_BackCache;
140  size_t m_StripID;
141  size_t m_MinStripSize;
142  bool m_BackwardSearch;
143  bool m_FirstRun;
144 };
145 
146 
147 
148 
149 
151 // tri_stripper inline functions
153 
154 inline void tri_stripper::SetCacheSize(const size_t CacheSize)
155 {
156  m_Cache.resize(CacheSize);
157  m_BackCache.resize(CacheSize);
158 }
159 
160 
161 inline void tri_stripper::SetMinStripSize(const size_t MinStripSize)
162 {
163  if (MinStripSize < 2)
164  m_MinStripSize = 2;
165  else
166  m_MinStripSize = MinStripSize;
167 }
168 
169 
170 inline void tri_stripper::SetBackwardSearch(const bool Enabled)
171 {
172  m_BackwardSearch = Enabled;
173 }
174 
175 
176 
177 inline void tri_stripper::SetPushCacheHits(bool Enabled)
178 {
179  m_Cache.push_cache_hits(Enabled);
180 }
181 
182 
183 
184 
185 } // namespace triangle_stripper
186 
187 
188 
189 
190 #endif // TRI_STRIPPER_HEADER_GUARD_TRI_STRIPPER_H
void SetPushCacheHits(bool Enabled=true)
Definition: tri_stripper.h:177
void Strip(primitive_vector *out_pPrimitivesVector)
png_uint_32 i
Definition: png.h:2640
void SetBackwardSearch(bool Enabled=false)
Definition: tri_stripper.h:170
void SetMinStripSize(size_t MinStripSize=2)
Definition: tri_stripper.h:161
void SetCacheSize(size_t CacheSize=10)
Definition: tri_stripper.h:154
tri_stripper(const indices &TriIndices)
arc_list::const_iterator const_out_arc_iterator
Definition: graph_array.h:68
std::vector< primitive_group > primitive_vector
Definition: public_types.h:36
unsigned int index
Definition: public_types.h:21