1 | #ifndef __BITVECTORPVS_H
|
---|
2 | #define __BITVECTORPVS_H
|
---|
3 |
|
---|
4 | #include <vector>
|
---|
5 | #include "common.h"
|
---|
6 | #include "PvsBase.h"
|
---|
7 |
|
---|
8 | using namespace std;
|
---|
9 |
|
---|
10 | namespace GtpVisibilityPreprocessor {
|
---|
11 |
|
---|
12 | // specialisation of vector<bool>
|
---|
13 | typedef vector<bool> bit_vector;
|
---|
14 |
|
---|
15 | /** Iterator over a bitvector pvs.
|
---|
16 | */
|
---|
17 | #if 0
|
---|
18 | template<typename T, typename S>
|
---|
19 | class BitVectorPvsIterator
|
---|
20 | {
|
---|
21 | public:
|
---|
22 |
|
---|
23 | HashPvsIterator<T, S>() {}
|
---|
24 |
|
---|
25 | HashPvsIterator<T, S>(const typename HASH_SET::const_iterator &itCurrent,
|
---|
26 | const typename HASH_SET::const_iterator &itEnd):
|
---|
27 | mItCurrent(itCurrent), mItEnd(itEnd)
|
---|
28 | {
|
---|
29 | }
|
---|
30 |
|
---|
31 | bool HasMoreEntries() const
|
---|
32 | {
|
---|
33 | return (mItCurrent != mItEnd);
|
---|
34 | }
|
---|
35 |
|
---|
36 | PvsEntry<T, S> Next()
|
---|
37 | {
|
---|
38 | // hack: create new pvs entry
|
---|
39 | return PvsEntry<T, S>(*(mItCurrent) ++, S(0.0));
|
---|
40 | }
|
---|
41 |
|
---|
42 | private:
|
---|
43 | typename HASH_SET::const_iterator mItCurrent;
|
---|
44 | typename HASH_SET::const_iterator mItEnd;
|
---|
45 | };
|
---|
46 | #endif
|
---|
47 |
|
---|
48 | #if 0
|
---|
49 | /** Pvs implemented as bitvector
|
---|
50 | */
|
---|
51 | template<typename T, typename S>
|
---|
52 | class BitVectorPvs//: public PvsBase<T>
|
---|
53 | {
|
---|
54 | template<typename T, typename S> friend class BitVectorPvsIterator;
|
---|
55 |
|
---|
56 | public:
|
---|
57 |
|
---|
58 | //HashPvs(): mEntries((Intersectable *)100) {};
|
---|
59 | HashPvs() {};
|
---|
60 | //virtual ~HashPvs() {};
|
---|
61 |
|
---|
62 | int GetSize() const;
|
---|
63 | bool Empty() const;
|
---|
64 |
|
---|
65 | /** Adds sample to PVS.
|
---|
66 | @returns contribution of sample (0 or 1)
|
---|
67 | */
|
---|
68 | float AddSample(T sample, const float pdf);
|
---|
69 |
|
---|
70 | /** Adds sample to PVS without checking for presence of the sample
|
---|
71 | warning: pvs remains unsorted!
|
---|
72 | */
|
---|
73 | void AddSampleDirty(T sample, const float pdf);
|
---|
74 |
|
---|
75 | /** Adds sample dirty (on the end of the vector) but
|
---|
76 | first checks if sample is already in clean part of the pvs.
|
---|
77 | */
|
---|
78 | bool AddSampleDirtyCheck(T sample, const float pdf);
|
---|
79 |
|
---|
80 | /** Sort pvs entries - this should always be called after a
|
---|
81 | sequence of AddSampleDirty calls
|
---|
82 | */
|
---|
83 | void Sort();
|
---|
84 |
|
---|
85 | /** Clears the pvs.
|
---|
86 | */
|
---|
87 | void Clear(const bool trim = true);
|
---|
88 |
|
---|
89 | bool IsDirty() const;
|
---|
90 |
|
---|
91 | bool RequiresResort() const;
|
---|
92 |
|
---|
93 | /** Finds sample in PVS.
|
---|
94 | @param checkDirty if dirty part of the pvs should be checked for entry
|
---|
95 | (warning: linear runtime in dirty part)
|
---|
96 | @returns iterator on the sample if found, else the place where
|
---|
97 | it would be added in the sorted vector.
|
---|
98 | */
|
---|
99 | bool Find(T sample, typename HASH_SET::iterator &it);
|
---|
100 |
|
---|
101 | typename HashPvsIterator<T, S> GetIterator() const;
|
---|
102 |
|
---|
103 | /** Compute continuous PVS difference
|
---|
104 | */
|
---|
105 | float GetPvsHomogenity(HashPvs<T, S> &pvs);
|
---|
106 |
|
---|
107 | static void Merge(HashPvs<T, S> &mergedPvs,
|
---|
108 | const HashPvs<T, S> &a,
|
---|
109 | const HashPvs<T, S> &b);
|
---|
110 |
|
---|
111 | static int GetEntrySizeByte();
|
---|
112 | static float GetEntrySize();
|
---|
113 |
|
---|
114 | bool GetSampleContribution(T sample,
|
---|
115 | const float pdf,
|
---|
116 | float &contribution);
|
---|
117 |
|
---|
118 | int GetSamples() const
|
---|
119 | {
|
---|
120 | return mSamples;
|
---|
121 | }
|
---|
122 |
|
---|
123 | void MergeInPlace(const HashPvs<T, S> &a)
|
---|
124 | {
|
---|
125 | cerr << "not implemented yet" << endl;
|
---|
126 | }
|
---|
127 |
|
---|
128 | bool RequiresResortLog() const
|
---|
129 | {
|
---|
130 | return false;
|
---|
131 | }
|
---|
132 |
|
---|
133 | void Reserve(const int n)
|
---|
134 | {
|
---|
135 | // not necessary
|
---|
136 | }
|
---|
137 |
|
---|
138 | /** Sort pvs entries assume that the pvs contains unique entries
|
---|
139 | */
|
---|
140 | void SimpleSort()
|
---|
141 | {
|
---|
142 | // not necessary
|
---|
143 | }
|
---|
144 |
|
---|
145 | int SubtractPvs(const HashPvs<T, S> &pvs)
|
---|
146 | {
|
---|
147 | cerr << "not yet implemented" << endl;
|
---|
148 | return 0;
|
---|
149 | }
|
---|
150 |
|
---|
151 | /** Compute continuous PVS difference
|
---|
152 | */
|
---|
153 | void ComputeContinuousPvsDifference(HashPvs<T, S> &pvs,
|
---|
154 | float &pvsReduction,
|
---|
155 | float &pvsEnlargement)
|
---|
156 | {
|
---|
157 | cerr << "not yet implemented" << endl;
|
---|
158 | }
|
---|
159 | protected:
|
---|
160 |
|
---|
161 | /// hash table of PVS entries
|
---|
162 | HASH_SET mEntries;
|
---|
163 |
|
---|
164 | /// Number of samples used to create the PVS
|
---|
165 | int mSamples;
|
---|
166 | };
|
---|
167 |
|
---|
168 |
|
---|
169 | template <typename T, typename S>
|
---|
170 | bool HashPvs<T, S>::Find(T sample, typename HASH_SET::iterator &it)
|
---|
171 | {
|
---|
172 | it = mEntries.find(sample);
|
---|
173 |
|
---|
174 | // already in map
|
---|
175 | return (it != mEntries.end());
|
---|
176 | }
|
---|
177 |
|
---|
178 |
|
---|
179 | template <typename T, typename S>
|
---|
180 | int HashPvs<T, S>::GetSize() const
|
---|
181 | {
|
---|
182 | return (int)mEntries.size();
|
---|
183 | }
|
---|
184 |
|
---|
185 |
|
---|
186 | template <typename T, typename S>
|
---|
187 | bool HashPvs<T, S>::Empty() const
|
---|
188 | {
|
---|
189 | return mEntries.empty();
|
---|
190 | }
|
---|
191 |
|
---|
192 |
|
---|
193 | template <typename T, typename S>
|
---|
194 | float HashPvs<T, S>::AddSample(T sample, const float pdf)
|
---|
195 | {
|
---|
196 | HASH_SET::iterator it;
|
---|
197 |
|
---|
198 | if (Find(sample, it))
|
---|
199 | return 0.0f;
|
---|
200 |
|
---|
201 | mEntries.insert(sample);
|
---|
202 | return 1.0f;
|
---|
203 | }
|
---|
204 |
|
---|
205 |
|
---|
206 | template <typename T, typename S>
|
---|
207 | void HashPvs<T, S>::AddSampleDirty(T sample, const float pdf)
|
---|
208 | {
|
---|
209 | HASH_SET::iterator it;
|
---|
210 |
|
---|
211 | // not yet in map
|
---|
212 | if (!Find(sample, it))
|
---|
213 | {
|
---|
214 | mEntries.insert(sample);
|
---|
215 | }
|
---|
216 | }
|
---|
217 |
|
---|
218 |
|
---|
219 | template <typename T, typename S>
|
---|
220 | bool HashPvs<T, S>::AddSampleDirtyCheck(T sample,
|
---|
221 | const float pdf)
|
---|
222 | {
|
---|
223 | HASH_SET::iterator it;
|
---|
224 |
|
---|
225 | // already in map
|
---|
226 | if (Find(sample, it))
|
---|
227 | return false;
|
---|
228 |
|
---|
229 | mEntries.insert(sample);
|
---|
230 | return true;
|
---|
231 | }
|
---|
232 |
|
---|
233 |
|
---|
234 | template <typename T, typename S>
|
---|
235 | void HashPvs<T, S>::Sort()
|
---|
236 | {
|
---|
237 | }
|
---|
238 |
|
---|
239 |
|
---|
240 | template <typename T, typename S>
|
---|
241 | void HashPvs<T, S>::Clear(const bool trim = true)
|
---|
242 | {
|
---|
243 | mEntries.clear();
|
---|
244 | }
|
---|
245 |
|
---|
246 |
|
---|
247 | template <typename T, typename S>
|
---|
248 | bool HashPvs<T, S>::IsDirty() const
|
---|
249 | {
|
---|
250 | return false;
|
---|
251 | }
|
---|
252 |
|
---|
253 |
|
---|
254 | template <typename T, typename S>
|
---|
255 | bool HashPvs<T, S>::RequiresResort() const
|
---|
256 | {
|
---|
257 | return false;
|
---|
258 | }
|
---|
259 |
|
---|
260 |
|
---|
261 | template <typename T, typename S>
|
---|
262 | typename HashPvsIterator<T, S> HashPvs<T, S>::GetIterator() const
|
---|
263 | {
|
---|
264 | HashPvsIterator<T, S> pit(mEntries.begin(), mEntries.end());
|
---|
265 |
|
---|
266 | return pit;
|
---|
267 | }
|
---|
268 |
|
---|
269 |
|
---|
270 | template <typename T, typename S>
|
---|
271 | float HashPvs<T, S>::GetEntrySize()
|
---|
272 | {
|
---|
273 | return (float)(sizeof(T)) / float(1024 * 1024);
|
---|
274 | }
|
---|
275 |
|
---|
276 |
|
---|
277 | template <typename T, typename S>
|
---|
278 | int HashPvs<T, S>::GetEntrySizeByte()
|
---|
279 | {
|
---|
280 | return sizeof(T);
|
---|
281 | }
|
---|
282 |
|
---|
283 |
|
---|
284 | template <typename T, typename S>
|
---|
285 | float HashPvs<T, S>::GetPvsHomogenity(HashPvs<T, S> &pvs)
|
---|
286 | {
|
---|
287 | float pvsReduction, pvsEnlargement;
|
---|
288 |
|
---|
289 | ComputeContinuousPvsDifference(pvs, pvsReduction, pvsEnlargement);
|
---|
290 |
|
---|
291 | return pvsReduction + pvsEnlargement;
|
---|
292 | }
|
---|
293 |
|
---|
294 |
|
---|
295 | template <typename T, typename S>
|
---|
296 | bool HashPvs<T, S>::GetSampleContribution(T sample,
|
---|
297 | const float pdf,
|
---|
298 | float &contribution)
|
---|
299 | {
|
---|
300 | HASH_SET::iterator it;
|
---|
301 | const bool entryFound = Find(sample, it);
|
---|
302 |
|
---|
303 | if (entryFound)
|
---|
304 | {
|
---|
305 | contribution = 0.0f;
|
---|
306 | return false;
|
---|
307 | }
|
---|
308 | else
|
---|
309 | {
|
---|
310 | contribution = 1.0f;
|
---|
311 | return true;
|
---|
312 | }
|
---|
313 | }
|
---|
314 |
|
---|
315 |
|
---|
316 | template <typename T, typename S>
|
---|
317 | void HashPvs<T, S>::Merge(HashPvs<T, S> &mergedPvs,
|
---|
318 | const HashPvs<T, S> &a,
|
---|
319 | const HashPvs<T, S> &b)
|
---|
320 | {
|
---|
321 | }
|
---|
322 |
|
---|
323 | #endif
|
---|
324 |
|
---|
325 | }
|
---|
326 |
|
---|
327 | #endif
|
---|
328 |
|
---|