1 | #include "Environment.h"
|
---|
2 | #include "GvsPreprocessor.h"
|
---|
3 | #include "GlRenderer.h"
|
---|
4 | #include "VssRay.h"
|
---|
5 | #include "ViewCellsManager.h"
|
---|
6 | #include "Triangle3.h"
|
---|
7 | #include "IntersectableWrapper.h"
|
---|
8 | #include "Plane3.h"
|
---|
9 | #include "RayCaster.h"
|
---|
10 | #include "Exporter.h"
|
---|
11 | #include "SamplingStrategy.h"
|
---|
12 | #include "BvHierarchy.h"
|
---|
13 | #include "Polygon3.h"
|
---|
14 | #include "IntersectableWrapper.h"
|
---|
15 | #include "Timer/PerfTimer.h"
|
---|
16 | #include "Vector2.h"
|
---|
17 | #include "RndGauss.h"
|
---|
18 |
|
---|
19 |
|
---|
20 |
|
---|
21 | namespace GtpVisibilityPreprocessor
|
---|
22 | {
|
---|
23 |
|
---|
24 | #define GVS_DEBUG 0
|
---|
25 | #define NOT_ACCOUNTED_OBJECT 0
|
---|
26 | #define ACCOUNTED_OBJECT 2
|
---|
27 | #define DETERMINISTIC_GVS 0
|
---|
28 |
|
---|
29 | static const float MIN_DIST = 0.001f;
|
---|
30 |
|
---|
31 | static ObjectContainer myobjects;
|
---|
32 | static int sInvalidSamples = 0;
|
---|
33 |
|
---|
34 | ///////////
|
---|
35 | //-- timers
|
---|
36 |
|
---|
37 |
|
---|
38 | static PerfTimer rayTimer;
|
---|
39 | static PerfTimer kdPvsTimer;
|
---|
40 | static PerfTimer gvsTimer;
|
---|
41 | static PerfTimer initialTimer;
|
---|
42 | static PerfTimer intersectionTimer;
|
---|
43 | static PerfTimer preparationTimer;
|
---|
44 | static PerfTimer mainLoopTimer;
|
---|
45 | static PerfTimer contributionTimer;
|
---|
46 | static PerfTimer castTimer;
|
---|
47 | static PerfTimer generationTimer;
|
---|
48 |
|
---|
49 |
|
---|
50 | /////////////////////
|
---|
51 |
|
---|
52 |
|
---|
53 | /** Visualization structure for the GVS algorithm.
|
---|
54 | */
|
---|
55 | struct VizStruct
|
---|
56 | {
|
---|
57 | Polygon3 *enlargedTriangle;
|
---|
58 | Triangle3 originalTriangle;
|
---|
59 | VssRay *ray;
|
---|
60 | };
|
---|
61 |
|
---|
62 | static vector<VizStruct> vizContainer;
|
---|
63 |
|
---|
64 |
|
---|
65 |
|
---|
66 |
|
---|
67 | GvsPreprocessor::GvsPreprocessor():
|
---|
68 | Preprocessor(),
|
---|
69 | mProcessedViewCells(0),
|
---|
70 | mCurrentViewCell(NULL),
|
---|
71 | mCurrentViewPoint(Vector3(0.0f, 0.0f, 0.0f)),
|
---|
72 | mOnlyRandomSampling(false),
|
---|
73 | //mOnlyRandomSampling(true),
|
---|
74 | mUseProbablyVisibleSampling(false)
|
---|
75 | {
|
---|
76 | Environment::GetSingleton()->GetIntValue("GvsPreprocessor.totalSamples", mTotalSamples);
|
---|
77 | Environment::GetSingleton()->GetIntValue("GvsPreprocessor.initialSamples", mInitialSamples);
|
---|
78 | Environment::GetSingleton()->GetIntValue("GvsPreprocessor.gvsSamplesPerPass", mGvsSamplesPerPass);
|
---|
79 | Environment::GetSingleton()->GetIntValue("GvsPreprocessor.minContribution", mMinContribution);
|
---|
80 | Environment::GetSingleton()->GetFloatValue("GvsPreprocessor.epsilon", mEps);
|
---|
81 | Environment::GetSingleton()->GetFloatValue("GvsPreprocessor.threshold", mThreshold);
|
---|
82 | Environment::GetSingleton()->GetBoolValue("GvsPreprocessor.perViewCell", mPerViewCell);
|
---|
83 | Environment::GetSingleton()->GetIntValue("GvsPreprocessor.maxViewCells", mMaxViewCells);
|
---|
84 |
|
---|
85 | Environment::GetSingleton()->GetBoolValue("Preprocessor.evaluatePixelError", mEvaluatePixelError);
|
---|
86 |
|
---|
87 | Environment::GetSingleton()->GetBoolValue("ViewCells.useKdPvs", mUseKdPvs);
|
---|
88 |
|
---|
89 |
|
---|
90 | char gvsStatsLog[100];
|
---|
91 | Environment::GetSingleton()->GetStringValue("GvsPreprocessor.stats", gvsStatsLog);
|
---|
92 | mGvsStatsStream.open(gvsStatsLog);
|
---|
93 |
|
---|
94 | cout << "number of gvs samples per pass: " << mGvsSamplesPerPass << endl;
|
---|
95 | cout << "number of samples per pass: " << mSamplesPerPass << endl;
|
---|
96 | cout << "only random sampling: " << mOnlyRandomSampling << endl;
|
---|
97 |
|
---|
98 | Debug << "Gvs preprocessor options" << endl;
|
---|
99 | Debug << "number of total samples: " << mTotalSamples << endl;
|
---|
100 | Debug << "number of initial samples: " << mInitialSamples << endl;
|
---|
101 | Debug << "threshold: " << mThreshold << endl;
|
---|
102 | Debug << "epsilon: " << mEps << endl;
|
---|
103 | Debug << "stats: " << gvsStatsLog << endl;
|
---|
104 | Debug << "per view cell: " << mPerViewCell << endl;
|
---|
105 | Debug << "max view cells: " << mMaxViewCells << endl;
|
---|
106 | Debug << "min contribution: " << mMinContribution << endl;
|
---|
107 |
|
---|
108 | mDistribution = new ViewCellBasedDistribution(*this, NULL);
|
---|
109 |
|
---|
110 | mGvsStats.Reset();
|
---|
111 |
|
---|
112 | // hack: some generic statistical values that can be used
|
---|
113 | // by an application using the preprocessor
|
---|
114 | for (int i = 0; i < 2; ++ i)
|
---|
115 | mGenericStats[i] = 0;
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | GvsPreprocessor::~GvsPreprocessor()
|
---|
120 | {
|
---|
121 | delete mDistribution;
|
---|
122 | ClearRayQueue();
|
---|
123 | }
|
---|
124 |
|
---|
125 |
|
---|
126 | void GvsPreprocessor::ClearRayQueue()
|
---|
127 | {
|
---|
128 | // clean ray queue
|
---|
129 | while (!mRayQueue.empty())
|
---|
130 | {
|
---|
131 | // handle next ray
|
---|
132 | VssRay *ray = mRayQueue.top();
|
---|
133 | mRayQueue.pop();
|
---|
134 |
|
---|
135 | // note: deletion of the ray is handled by ray pool
|
---|
136 | }
|
---|
137 | }
|
---|
138 |
|
---|
139 |
|
---|
140 | ViewCell *GvsPreprocessor::NextViewCell()
|
---|
141 | {
|
---|
142 | if (mProcessedViewCells == (int)mViewCells.size())
|
---|
143 | return NULL; // no more view cells
|
---|
144 |
|
---|
145 | ViewCell *vc = mViewCells[mProcessedViewCells];
|
---|
146 |
|
---|
147 | if (!vc->GetMesh())
|
---|
148 | mViewCellsManager->CreateMesh(vc);
|
---|
149 |
|
---|
150 | mGvsStats.mViewCellId = vc->GetId();
|
---|
151 |
|
---|
152 | Debug << "vc: " << vc->GetId() << endl;
|
---|
153 |
|
---|
154 | ++ mProcessedViewCells;
|
---|
155 |
|
---|
156 | return vc;
|
---|
157 | }
|
---|
158 |
|
---|
159 |
|
---|
160 | int GvsPreprocessor::CheckDiscontinuity(const VssRay ¤tRay,
|
---|
161 | const Triangle3 &hitTriangle,
|
---|
162 | const VssRay &oldRay)
|
---|
163 | {
|
---|
164 | // the predicted hitpoint: we expect to hit the same mesh again
|
---|
165 | Vector3 predictedHit = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay);
|
---|
166 |
|
---|
167 | float predictedLen = Magnitude(predictedHit - currentRay.mOrigin);
|
---|
168 | float len = Magnitude(currentRay.mTermination - currentRay.mOrigin);
|
---|
169 |
|
---|
170 | // distance large => this is likely to be a discontinuity
|
---|
171 | if (!((predictedLen - len) > mThreshold))
|
---|
172 | // q: rather use relative distance?
|
---|
173 | //if ((predictedLen / len) > mThreshold)
|
---|
174 | return 0;
|
---|
175 |
|
---|
176 | SimpleRay simpleRay;
|
---|
177 |
|
---|
178 | // apply reverse sampling to find the gap
|
---|
179 | if (!ComputeReverseRay(currentRay, hitTriangle, oldRay, simpleRay))
|
---|
180 | return 0;
|
---|
181 |
|
---|
182 | static VssRayContainer reverseRays;
|
---|
183 | reverseRays.clear();
|
---|
184 |
|
---|
185 | if (DETERMINISTIC_GVS)
|
---|
186 | {
|
---|
187 | VssRay *reverseRay =
|
---|
188 | mRayCaster->CastRay(simpleRay, mViewCellsManager->GetViewSpaceBox(), !mPerViewCell);
|
---|
189 |
|
---|
190 | reverseRays.push_back(reverseRay);
|
---|
191 | }
|
---|
192 | else
|
---|
193 | {
|
---|
194 | float scale = 0.01f;
|
---|
195 |
|
---|
196 | if (0)
|
---|
197 | CastRayBundle4(simpleRay, reverseRays, mViewCellsManager->GetViewSpaceBox());
|
---|
198 | else
|
---|
199 | CastRayBundle16(simpleRay, reverseRays, scale);
|
---|
200 | }
|
---|
201 |
|
---|
202 | mGvsStats.mReverseSamples += (int)reverseRays.size();
|
---|
203 |
|
---|
204 | EnqueueRays(reverseRays);
|
---|
205 |
|
---|
206 | return (int)reverseRays.size();
|
---|
207 | }
|
---|
208 |
|
---|
209 |
|
---|
210 | int GvsPreprocessor::CountObject(Intersectable *triObj)
|
---|
211 | {
|
---|
212 | int numObjects = 0;
|
---|
213 |
|
---|
214 | if ((triObj->mCounter != (NOT_ACCOUNTED_OBJECT + 1)) &&
|
---|
215 | (triObj->mCounter != (ACCOUNTED_OBJECT + 1)))
|
---|
216 | {
|
---|
217 | ++ triObj->mCounter;
|
---|
218 | ++ numObjects;
|
---|
219 | }
|
---|
220 |
|
---|
221 | mGenericStats[1] += numObjects;
|
---|
222 |
|
---|
223 | return numObjects;
|
---|
224 | }
|
---|
225 |
|
---|
226 |
|
---|
227 | void GvsPreprocessor::UpdateStatsForVisualization(KdIntersectable *kdInt)
|
---|
228 | {
|
---|
229 | int numObj = 0;
|
---|
230 |
|
---|
231 | // count new objects in pvs due to kd node conversion
|
---|
232 | myobjects.clear();
|
---|
233 | // also gather duplicates to avoid mailing
|
---|
234 | mKdTree->CollectObjectsWithDublicates(kdInt->GetItem(), myobjects);
|
---|
235 |
|
---|
236 | ObjectContainer::const_iterator oit, oit_end = myobjects.end();
|
---|
237 |
|
---|
238 | for (oit = myobjects.begin(); oit != oit_end; ++ oit)
|
---|
239 | numObj += CountObject(*oit);
|
---|
240 |
|
---|
241 | mViewCellsManager->UpdateStatsForViewCell(mCurrentViewCell, kdInt, numObj);
|
---|
242 | }
|
---|
243 |
|
---|
244 |
|
---|
245 | void GvsPreprocessor::AddKdNodeToPvs(const Vector3 &termination)
|
---|
246 | {
|
---|
247 | kdPvsTimer.Entry();
|
---|
248 |
|
---|
249 | // exchange the triangle with the node in the pvs for kd pvs
|
---|
250 | KdNode *node = mKdTree->GetPvsNode(termination);
|
---|
251 |
|
---|
252 | //KdNode *node = mKdTree->GetPvsNodeCheck(ray.mTermination, obj);
|
---|
253 | //if (!node) cerr << "e " << obj->GetBox() << " " << ray.mTermination << endl; else
|
---|
254 | if (!node->Mailed())
|
---|
255 | {
|
---|
256 | // add to pvs
|
---|
257 | node->Mail();
|
---|
258 | KdIntersectable *kdInt = mKdTree->GetOrCreateKdIntersectable(node);
|
---|
259 | mCurrentViewCell->GetPvs().AddSampleDirty(kdInt, 1.0f);
|
---|
260 |
|
---|
261 | if (QT_VISUALIZATION_SHOWN) UpdateStatsForVisualization(kdInt);
|
---|
262 | }
|
---|
263 |
|
---|
264 | kdPvsTimer.Exit();
|
---|
265 | }
|
---|
266 |
|
---|
267 |
|
---|
268 | bool GvsPreprocessor::HasContribution(VssRay &ray)
|
---|
269 | {
|
---|
270 | if (!ray.mTerminationObject)
|
---|
271 | return false;
|
---|
272 |
|
---|
273 | contributionTimer.Entry();
|
---|
274 |
|
---|
275 | bool result;
|
---|
276 |
|
---|
277 | if (!mPerViewCell)
|
---|
278 | {
|
---|
279 | // store the rays + the intersected view cells
|
---|
280 | const bool storeViewCells = false;
|
---|
281 |
|
---|
282 | mViewCellsManager->ComputeSampleContribution(ray,
|
---|
283 | true,
|
---|
284 | storeViewCells,
|
---|
285 | true);
|
---|
286 |
|
---|
287 | result = ray.mPvsContribution > 0;
|
---|
288 | }
|
---|
289 | else // original per view cell gvs
|
---|
290 | {
|
---|
291 | // test if triangle was accounted for yet
|
---|
292 | result = AddTriangleObject(ray.mTerminationObject);
|
---|
293 |
|
---|
294 | if (mUseKdPvs)
|
---|
295 | AddKdNodeToPvs(ray.mTermination);
|
---|
296 | }
|
---|
297 |
|
---|
298 | contributionTimer.Exit();
|
---|
299 |
|
---|
300 | return result;
|
---|
301 | }
|
---|
302 |
|
---|
303 |
|
---|
304 | bool GvsPreprocessor::HandleRay(VssRay *vssRay)
|
---|
305 | {
|
---|
306 | if (!vssRay || !HasContribution(*vssRay))
|
---|
307 | return false;
|
---|
308 |
|
---|
309 | if (0 && GVS_DEBUG)
|
---|
310 | mVssRays.push_back(new VssRay(*vssRay));
|
---|
311 |
|
---|
312 | // add new ray to ray queue
|
---|
313 | mRayQueue.push(vssRay);
|
---|
314 |
|
---|
315 | ++ mGvsStats.mTotalContribution;
|
---|
316 |
|
---|
317 | return true;
|
---|
318 | }
|
---|
319 |
|
---|
320 |
|
---|
321 | /** Creates 3 new vertices for triangle vertex with specified index.
|
---|
322 | */
|
---|
323 | void GvsPreprocessor::CreateDisplacedVertices(VertexContainer &vertices,
|
---|
324 | const Triangle3 &hitTriangle,
|
---|
325 | const VssRay &ray,
|
---|
326 | const int index) const
|
---|
327 | {
|
---|
328 | const int indexU = (index + 1) % 3;
|
---|
329 | const int indexL = (index == 0) ? 2 : index - 1;
|
---|
330 |
|
---|
331 | const Vector3 a = hitTriangle.mVertices[index] - ray.GetOrigin();
|
---|
332 | const Vector3 b = hitTriangle.mVertices[indexU] - hitTriangle.mVertices[index];
|
---|
333 | const Vector3 c = hitTriangle.mVertices[index] - hitTriangle.mVertices[indexL];
|
---|
334 |
|
---|
335 | const float len = Magnitude(a);
|
---|
336 |
|
---|
337 | const Vector3 dir1 = Normalize(CrossProd(a, b)); //N((pi-xp)×(pi+1- pi));
|
---|
338 | const Vector3 dir2 = Normalize(CrossProd(a, c)); // N((pi-xp)×(pi- pi-1))
|
---|
339 | const Vector3 dir3 = DotProd(dir2, dir1) > 0 ? // N((pi-xp)×di,i-1+di,i+1×(pi-xp))
|
---|
340 | Normalize(dir2 + dir1) : Normalize(CrossProd(a, dir1) + CrossProd(dir2, a));
|
---|
341 |
|
---|
342 | // compute the new three hit points
|
---|
343 | // pi, i + 1: pi+ e·|pi-xp|·di, j
|
---|
344 | const Vector3 pt1 = hitTriangle.mVertices[index] + mEps * len * dir1;
|
---|
345 | // pi, i - 1: pi+ e·|pi-xp|·di, j
|
---|
346 | const Vector3 pt2 = hitTriangle.mVertices[index] + mEps * len * dir2;
|
---|
347 | // pi, i: pi+ e·|pi-xp|·di, j
|
---|
348 | const Vector3 pt3 = hitTriangle.mVertices[index] + mEps * len * dir3;
|
---|
349 |
|
---|
350 | vertices.push_back(pt2);
|
---|
351 | vertices.push_back(pt3);
|
---|
352 | vertices.push_back(pt1);
|
---|
353 | }
|
---|
354 |
|
---|
355 |
|
---|
356 | void GvsPreprocessor::EnlargeTriangle(VertexContainer &vertices,
|
---|
357 | const Triangle3 &hitTriangle,
|
---|
358 | const VssRay &ray) const
|
---|
359 | {
|
---|
360 | CreateDisplacedVertices(vertices, hitTriangle, ray, 0);
|
---|
361 | CreateDisplacedVertices(vertices, hitTriangle, ray, 1);
|
---|
362 | CreateDisplacedVertices(vertices, hitTriangle, ray, 2);
|
---|
363 | }
|
---|
364 |
|
---|
365 |
|
---|
366 | Vector3 GvsPreprocessor::CalcPredictedHitPoint(const VssRay &newRay,
|
---|
367 | const Triangle3 &hitTriangle,
|
---|
368 | const VssRay &oldRay) const
|
---|
369 | {
|
---|
370 | // find the intersection of the plane induced by the
|
---|
371 | // hit triangle with the new ray
|
---|
372 | Plane3 plane(hitTriangle.GetNormal(), hitTriangle.mVertices[0]);
|
---|
373 |
|
---|
374 | const Vector3 hitPt =
|
---|
375 | plane.FindIntersection(newRay.mTermination, newRay.mOrigin);
|
---|
376 |
|
---|
377 | return hitPt;
|
---|
378 | }
|
---|
379 |
|
---|
380 |
|
---|
381 | static bool EqualVisibility(const VssRay &a, const VssRay &b)
|
---|
382 | {
|
---|
383 | return a.mTerminationObject == b.mTerminationObject;
|
---|
384 | }
|
---|
385 |
|
---|
386 |
|
---|
387 | int GvsPreprocessor::SubdivideEdge(const Triangle3 &hitTriangle,
|
---|
388 | const Vector3 &p1,
|
---|
389 | const Vector3 &p2,
|
---|
390 | const VssRay &ray1,
|
---|
391 | const VssRay &ray2,
|
---|
392 | const VssRay &oldRay)
|
---|
393 | {
|
---|
394 | //cout <<"y"<<Magnitude(p1 - p2) << " ";
|
---|
395 | int castRays = 0;
|
---|
396 |
|
---|
397 | // cast reverse rays if necessary
|
---|
398 | castRays += CheckDiscontinuity(ray1, hitTriangle, oldRay);
|
---|
399 | castRays += CheckDiscontinuity(ray2, hitTriangle, oldRay);
|
---|
400 |
|
---|
401 | if (EqualVisibility(ray1, ray2) || (SqrMagnitude(p1 - p2) <= MIN_DIST))
|
---|
402 | {
|
---|
403 | return castRays;
|
---|
404 | }
|
---|
405 |
|
---|
406 | // the new subdivision point
|
---|
407 | const Vector3 p = (p1 + p2) * 0.5f;
|
---|
408 | //cout << "p: " << p << " " << p1 << " " << p2 << endl;
|
---|
409 |
|
---|
410 | SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin, SamplingStrategy::GVS, 1.0f);
|
---|
411 |
|
---|
412 | VssRay *newRay;
|
---|
413 |
|
---|
414 | // cast single ray
|
---|
415 | castTimer.Entry();
|
---|
416 |
|
---|
417 | // cast single ray to check if a triangle was missed. note: not efficient!!
|
---|
418 | newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox(), !mPerViewCell);
|
---|
419 | castTimer.Exit();
|
---|
420 |
|
---|
421 | ++ castRays;
|
---|
422 |
|
---|
423 | // this ray will not be further processed
|
---|
424 | // note: ray deletion is handled by ray pool
|
---|
425 | if (!newRay) return castRays;
|
---|
426 |
|
---|
427 | rayTimer.Entry();
|
---|
428 |
|
---|
429 | // new triangle discovered? => add new ray to queue
|
---|
430 | HandleRay(newRay);
|
---|
431 |
|
---|
432 | rayTimer.Exit();
|
---|
433 |
|
---|
434 | //newRay->mFlags |= VssRay::BorderSample;
|
---|
435 |
|
---|
436 | // subdivide further
|
---|
437 | castRays += SubdivideEdge(hitTriangle, p1, p, ray1, *newRay, oldRay);
|
---|
438 | castRays += SubdivideEdge(hitTriangle, p, p2, *newRay, ray2, oldRay);
|
---|
439 |
|
---|
440 | return castRays;
|
---|
441 | }
|
---|
442 |
|
---|
443 |
|
---|
444 | int GvsPreprocessor::AdaptiveBorderSampling(const VssRay ¤tRay)
|
---|
445 | {
|
---|
446 | Intersectable *tObj = currentRay.mTerminationObject;
|
---|
447 |
|
---|
448 | // question matt: can this be possible?
|
---|
449 | if (!tObj) return 0;
|
---|
450 |
|
---|
451 | Triangle3 hitTriangle;
|
---|
452 |
|
---|
453 | // other types not implemented yet
|
---|
454 | if (tObj->Type() == Intersectable::TRIANGLE_INTERSECTABLE)
|
---|
455 | hitTriangle = static_cast<TriangleIntersectable *>(tObj)->GetItem();
|
---|
456 | else
|
---|
457 | cout << "border sampling: " << Intersectable::GetTypeName(tObj) << " not yet implemented" << endl;
|
---|
458 |
|
---|
459 | //cout << "type: " << Intersectable::GetTypeName(tObj) << endl;
|
---|
460 | generationTimer.Entry();
|
---|
461 |
|
---|
462 | static VertexContainer enlargedTriangle;
|
---|
463 | enlargedTriangle.clear();
|
---|
464 |
|
---|
465 | /// create 3 new hit points for each vertex
|
---|
466 | EnlargeTriangle(enlargedTriangle, hitTriangle, currentRay);
|
---|
467 |
|
---|
468 | /// create rays from sample points and handle them
|
---|
469 | static SimpleRayContainer simpleRays;
|
---|
470 | simpleRays.clear();
|
---|
471 |
|
---|
472 | VertexContainer::const_iterator vit, vit_end = enlargedTriangle.end();
|
---|
473 |
|
---|
474 | for (vit = enlargedTriangle.begin(); vit != vit_end; ++ vit)
|
---|
475 | {
|
---|
476 | const Vector3 rayDir = (*vit) - currentRay.GetOrigin();
|
---|
477 |
|
---|
478 | SimpleRay sr(currentRay.GetOrigin(), rayDir, SamplingStrategy::GVS, 1.0f);
|
---|
479 | simpleRays.AddRay(sr);
|
---|
480 | }
|
---|
481 |
|
---|
482 | if (0)
|
---|
483 | {
|
---|
484 | // visualize enlarged triangles
|
---|
485 | VizStruct dummy;
|
---|
486 | dummy.enlargedTriangle = new Polygon3(enlargedTriangle);
|
---|
487 | dummy.originalTriangle = hitTriangle;
|
---|
488 | vizContainer.push_back(dummy);
|
---|
489 | }
|
---|
490 |
|
---|
491 |
|
---|
492 | //////////
|
---|
493 | //-- fill up simple rays with random rays so we can cast 16 rays at a time
|
---|
494 |
|
---|
495 | const int numRandomRays = 16 - (int)simpleRays.size();
|
---|
496 |
|
---|
497 | if (!DETERMINISTIC_GVS)
|
---|
498 | {
|
---|
499 | if (0)
|
---|
500 | {
|
---|
501 | SimpleRay mainRay = SimpleRay(currentRay.GetOrigin(),
|
---|
502 | currentRay.GetNormalizedDir(),
|
---|
503 | SamplingStrategy::GVS,
|
---|
504 | 1.0f);
|
---|
505 |
|
---|
506 | GenerateJitteredRays(simpleRays, mainRay, numRandomRays, 0, 0.01f);
|
---|
507 | }
|
---|
508 | else
|
---|
509 | GenerateImportanceSamples(currentRay, hitTriangle, numRandomRays, simpleRays);
|
---|
510 | }
|
---|
511 | else
|
---|
512 | GenerateRays(numRandomRays, *mDistribution, simpleRays, sInvalidSamples);
|
---|
513 |
|
---|
514 | generationTimer.Exit();
|
---|
515 |
|
---|
516 | /////////////////////
|
---|
517 | //-- cast rays to vertices and determine visibility
|
---|
518 |
|
---|
519 | static VssRayContainer vssRays;
|
---|
520 | vssRays.clear();
|
---|
521 |
|
---|
522 | // for the original implementation we don't cast double rays
|
---|
523 | const bool castDoubleRays = !mPerViewCell;
|
---|
524 | // cannot prune invalid rays because we have to compare adjacent rays
|
---|
525 | const bool pruneInvalidRays = false;
|
---|
526 |
|
---|
527 | //gvsTimer.Entry();
|
---|
528 | castTimer.Entry();
|
---|
529 |
|
---|
530 | CastRays(simpleRays, vssRays, castDoubleRays, pruneInvalidRays);
|
---|
531 |
|
---|
532 | castTimer.Exit();
|
---|
533 | //gvsTimer.Exit();
|
---|
534 |
|
---|
535 | const int numBorderSamples = (int)vssRays.size() - numRandomRays;
|
---|
536 | int castRays = (int)simpleRays.size();
|
---|
537 |
|
---|
538 | // handle cast rays
|
---|
539 | EnqueueRays(vssRays);
|
---|
540 |
|
---|
541 | if (0)
|
---|
542 | {
|
---|
543 | // set flags
|
---|
544 | VssRayContainer::const_iterator rit, rit_end = vssRays.end();
|
---|
545 |
|
---|
546 | for (rit = vssRays.begin(); rit != rit_end; ++ rit)
|
---|
547 | (*rit)->mFlags |= VssRay::BorderSample;
|
---|
548 | }
|
---|
549 |
|
---|
550 | // recursivly subdivide each edge
|
---|
551 | for (int i = 0; i < numBorderSamples; ++ i)
|
---|
552 | {
|
---|
553 | castRays += SubdivideEdge(hitTriangle,
|
---|
554 | enlargedTriangle[i],
|
---|
555 | enlargedTriangle[(i + 1) % numBorderSamples],
|
---|
556 | *vssRays[i],
|
---|
557 | *vssRays[(i + 1) % numBorderSamples],
|
---|
558 | currentRay);
|
---|
559 | }
|
---|
560 |
|
---|
561 | mGvsStats.mBorderSamples += castRays;
|
---|
562 |
|
---|
563 | return castRays;
|
---|
564 | }
|
---|
565 |
|
---|
566 |
|
---|
567 | int GvsPreprocessor::AdaptiveBorderSamplingOpt(const VssRay ¤tRay)
|
---|
568 | {
|
---|
569 | Intersectable *tObj = currentRay.mTerminationObject;
|
---|
570 |
|
---|
571 | // question matt: can this be possible?
|
---|
572 | if (!tObj) return 0;
|
---|
573 |
|
---|
574 | Triangle3 hitTriangle;
|
---|
575 |
|
---|
576 | // other types not implemented yet
|
---|
577 | if (tObj->Type() == Intersectable::TRIANGLE_INTERSECTABLE)
|
---|
578 | hitTriangle = static_cast<TriangleIntersectable *>(tObj)->GetItem();
|
---|
579 | else
|
---|
580 | cout << "border sampling: " << Intersectable::GetTypeName(tObj) << " not yet implemented" << endl;
|
---|
581 |
|
---|
582 | generationTimer.Entry();
|
---|
583 |
|
---|
584 | static VertexContainer enlargedTriangle;
|
---|
585 | enlargedTriangle.clear();
|
---|
586 |
|
---|
587 | /// create 3 new hit points for each vertex
|
---|
588 | EnlargeTriangle(enlargedTriangle, hitTriangle, currentRay);
|
---|
589 |
|
---|
590 | static VertexContainer subdivEnlargedTri;
|
---|
591 | subdivEnlargedTri.clear();
|
---|
592 |
|
---|
593 | for (size_t i = 0; i < enlargedTriangle.size(); ++ i)
|
---|
594 | {
|
---|
595 | const Vector3 p1 = enlargedTriangle[i];
|
---|
596 | const Vector3 p2 = enlargedTriangle[(i + 1) % enlargedTriangle.size()];
|
---|
597 |
|
---|
598 | // the new subdivision point
|
---|
599 | const Vector3 p = (p1 + p2) * 0.5f;
|
---|
600 |
|
---|
601 | subdivEnlargedTri.push_back(p1);
|
---|
602 | subdivEnlargedTri.push_back(p);
|
---|
603 | }
|
---|
604 |
|
---|
605 | /// create rays from sample points and handle them
|
---|
606 | static SimpleRayContainer simpleRays;
|
---|
607 | simpleRays.clear();
|
---|
608 |
|
---|
609 | VertexContainer::const_iterator vit, vit_end = subdivEnlargedTri.end();
|
---|
610 |
|
---|
611 | for (vit = subdivEnlargedTri.begin(); vit != vit_end; ++ vit)
|
---|
612 | {
|
---|
613 | const Vector3 rayDir = (*vit) - currentRay.GetOrigin();
|
---|
614 |
|
---|
615 | SimpleRay sr(currentRay.GetOrigin(), rayDir, SamplingStrategy::GVS, 1.0f);
|
---|
616 | simpleRays.AddRay(sr);
|
---|
617 | }
|
---|
618 |
|
---|
619 |
|
---|
620 | //////////
|
---|
621 | //-- fill up simple rays with random rays so we can cast 16 rays at a time
|
---|
622 |
|
---|
623 | const int numRandomRays = 16 - ((int)simpleRays.size() % 16);
|
---|
624 |
|
---|
625 | SimpleRay mainRay = SimpleRay(currentRay.GetOrigin(),
|
---|
626 | currentRay.GetNormalizedDir(),
|
---|
627 | SamplingStrategy::GVS, 1.0f);
|
---|
628 |
|
---|
629 | GenerateJitteredRays(simpleRays, mainRay, numRandomRays, 0, 0.01f);
|
---|
630 | //GenerateRays(numRandomRays, *mDistribution, simpleRays, sInvalidSamples);
|
---|
631 |
|
---|
632 | generationTimer.Exit();
|
---|
633 |
|
---|
634 |
|
---|
635 | /////////////////////
|
---|
636 | //-- cast rays to vertices and determine visibility
|
---|
637 |
|
---|
638 | static VssRayContainer vssRays;
|
---|
639 | vssRays.clear();
|
---|
640 |
|
---|
641 | // for the original implementation we don't cast double rays
|
---|
642 | const bool castDoubleRays = !mPerViewCell;
|
---|
643 | // cannot prune invalid rays because we have to compare adjacent rays
|
---|
644 | const bool pruneInvalidRays = false;
|
---|
645 |
|
---|
646 | //if ((simpleRays.size() % 16) != 0) cerr << "ray size not aligned" << endl;
|
---|
647 |
|
---|
648 | //gvsTimer.Entry();
|
---|
649 | castTimer.Entry();
|
---|
650 |
|
---|
651 | CastRays(simpleRays, vssRays, castDoubleRays, pruneInvalidRays);
|
---|
652 |
|
---|
653 | castTimer.Exit();
|
---|
654 | //gvsTimer.Exit();
|
---|
655 |
|
---|
656 | const int numBorderSamples = (int)vssRays.size() - numRandomRays;
|
---|
657 | int castRays = (int)simpleRays.size();
|
---|
658 |
|
---|
659 | // handle cast rays
|
---|
660 | EnqueueRays(vssRays);
|
---|
661 |
|
---|
662 | #if 0
|
---|
663 |
|
---|
664 | // recursivly subdivide each edge
|
---|
665 | for (int i = 0; i < numBorderSamples; ++ i)
|
---|
666 | {
|
---|
667 | castRays += SubdivideEdge(hitTriangle,
|
---|
668 | subdivEnlargedTri[i],
|
---|
669 | subdivEnlargedTri[(i + 1) % numBorderSamples],
|
---|
670 | *vssRays[i],
|
---|
671 | *vssRays[(i + 1) % numBorderSamples],
|
---|
672 | currentRay);
|
---|
673 | }
|
---|
674 |
|
---|
675 | #endif
|
---|
676 |
|
---|
677 |
|
---|
678 | mGvsStats.mBorderSamples += castRays;
|
---|
679 |
|
---|
680 | return castRays;
|
---|
681 | }
|
---|
682 |
|
---|
683 |
|
---|
684 | bool GvsPreprocessor::GetPassingPoint(const VssRay ¤tRay,
|
---|
685 | const Triangle3 &occluder,
|
---|
686 | const VssRay &oldRay,
|
---|
687 | Vector3 &newPoint) const
|
---|
688 | {
|
---|
689 | /////////////////////////
|
---|
690 | //-- We interserct the plane p = (xp, hit(x), hit(xold))
|
---|
691 | //-- with the newly found occluder (xold is the previous ray from
|
---|
692 | //-- which x was generated). On the intersecting line, we select a point
|
---|
693 | //-- pnew which lies just outside of the new triangle so the ray
|
---|
694 | //-- just passes through the gap
|
---|
695 |
|
---|
696 | const Plane3 plane(currentRay.GetOrigin(),
|
---|
697 | currentRay.GetTermination(),
|
---|
698 | oldRay.GetTermination());
|
---|
699 |
|
---|
700 | Vector3 pt1, pt2;
|
---|
701 |
|
---|
702 | if (!occluder.GetPlaneIntersection(plane, pt1, pt2))
|
---|
703 | return false;
|
---|
704 |
|
---|
705 | // get the intersection point on the old ray
|
---|
706 | const Plane3 triPlane(occluder.GetNormal(), occluder.mVertices[0]);
|
---|
707 |
|
---|
708 | const float t = triPlane.FindT(oldRay.mOrigin, oldRay.mTermination);
|
---|
709 | const Vector3 pt3 = oldRay.mOrigin + t * (oldRay.mTermination - oldRay.mOrigin);
|
---|
710 |
|
---|
711 | // evaluate new hitpoint just outside the triangle
|
---|
712 | // the point is chosen to be on the side closer to the original ray
|
---|
713 | if (SqrDistance(pt1, pt3) < SqrDistance(pt2, pt3))
|
---|
714 | newPoint = pt1 + mEps * (pt1 - pt2);
|
---|
715 | else
|
---|
716 | newPoint = pt2 + mEps * (pt2 - pt1);
|
---|
717 |
|
---|
718 | //cout << "passing point: " << newPoint << endl << endl;
|
---|
719 | return true;
|
---|
720 | }
|
---|
721 |
|
---|
722 |
|
---|
723 | bool GvsPreprocessor::ComputeReverseRay(const VssRay ¤tRay,
|
---|
724 | const Triangle3 &hitTriangle,
|
---|
725 | const VssRay &oldRay,
|
---|
726 | SimpleRay &reverseRay)
|
---|
727 | {
|
---|
728 | // get triangle occluding the path to the hit mesh
|
---|
729 | Triangle3 occluder;
|
---|
730 | Intersectable *tObj = currentRay.mTerminationObject;
|
---|
731 |
|
---|
732 | // q: why can this happen?
|
---|
733 | if (!tObj)
|
---|
734 | return false;
|
---|
735 |
|
---|
736 | // other types not implemented yet
|
---|
737 | if (tObj->Type() == Intersectable::TRIANGLE_INTERSECTABLE)
|
---|
738 | occluder = static_cast<TriangleIntersectable *>(tObj)->GetItem();
|
---|
739 | else
|
---|
740 | cout << "reverse sampling: " << tObj->Type() << " not yet implemented" << endl;
|
---|
741 |
|
---|
742 | // get a point which is passing just outside of the occluder
|
---|
743 | Vector3 newPoint;
|
---|
744 |
|
---|
745 | // q: why is there sometimes no intersecton found?
|
---|
746 | if (!GetPassingPoint(currentRay, occluder, oldRay, newPoint))
|
---|
747 | return false;
|
---|
748 |
|
---|
749 | const Vector3 predicted = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay);
|
---|
750 |
|
---|
751 | Vector3 newDir, newOrigin;
|
---|
752 |
|
---|
753 | //////////////
|
---|
754 | //-- Construct the mutated ray with xnew,
|
---|
755 | //-- dir = predicted(x)- pnew as direction vector
|
---|
756 |
|
---|
757 | newDir = predicted - newPoint;
|
---|
758 |
|
---|
759 | // take xnew, p = intersect(viewcell, line(pnew, predicted(x)) as origin ?
|
---|
760 | // difficult to say!!
|
---|
761 | const float offset = 0.5f;
|
---|
762 | newOrigin = newPoint - newDir * offset;
|
---|
763 |
|
---|
764 |
|
---|
765 | //////////////
|
---|
766 | //-- for per view cell sampling, we must check for intersection
|
---|
767 | //-- with the current view cell
|
---|
768 |
|
---|
769 | if (mPerViewCell)
|
---|
770 | {
|
---|
771 | // send ray to view cell
|
---|
772 | static Ray ray;
|
---|
773 |
|
---|
774 | ray.Clear();
|
---|
775 | ray.Init(newOrigin, -newDir, Ray::LOCAL_RAY);
|
---|
776 |
|
---|
777 | // check if ray intersects view cell
|
---|
778 | if (!mCurrentViewCell->CastRay(ray))
|
---|
779 | return NULL;
|
---|
780 |
|
---|
781 | Ray::Intersection &hit = ray.intersections[0];
|
---|
782 |
|
---|
783 | // the ray starts from the view cell
|
---|
784 | newOrigin = ray.Extrap(hit.mT);
|
---|
785 | }
|
---|
786 |
|
---|
787 | reverseRay = SimpleRay(newOrigin, newDir, SamplingStrategy::GVS, 1.0f);
|
---|
788 |
|
---|
789 | return true;
|
---|
790 | }
|
---|
791 |
|
---|
792 |
|
---|
793 | int GvsPreprocessor::CastInitialSamples(int numSamples)
|
---|
794 | {
|
---|
795 | initialTimer.Entry();
|
---|
796 |
|
---|
797 | // generate simple rays
|
---|
798 | static SimpleRayContainer simpleRays;
|
---|
799 | simpleRays.clear();
|
---|
800 |
|
---|
801 | generationTimer.Entry();
|
---|
802 |
|
---|
803 | if (mUseProbablyVisibleSampling)// && (RandomValue(0, 1) > 0.5))
|
---|
804 | {
|
---|
805 | ProbablyVisibleDistribution distr(*this, mCurrentViewCell, &mProbablyVisibleTriangles);
|
---|
806 | GenerateRays(numSamples, distr, simpleRays, sInvalidSamples);
|
---|
807 | }
|
---|
808 | else
|
---|
809 | {
|
---|
810 | GenerateRays(DETERMINISTIC_GVS ? numSamples : numSamples / 16, *mDistribution, simpleRays, sInvalidSamples);
|
---|
811 | }
|
---|
812 |
|
---|
813 | generationTimer.Exit();
|
---|
814 |
|
---|
815 | // cast generated samples
|
---|
816 | static VssRayContainer vssRays;
|
---|
817 | vssRays.clear();
|
---|
818 |
|
---|
819 | castTimer.Entry();
|
---|
820 |
|
---|
821 | if (DETERMINISTIC_GVS)
|
---|
822 | {
|
---|
823 | const bool castDoubleRays = !mPerViewCell;
|
---|
824 | const bool pruneInvalidRays = false;
|
---|
825 | //const bool pruneInvalidRays = true;
|
---|
826 |
|
---|
827 | CastRays(simpleRays, vssRays, castDoubleRays, pruneInvalidRays);
|
---|
828 | }
|
---|
829 | else
|
---|
830 | {
|
---|
831 | float scale = 0.1f;
|
---|
832 | if (0)
|
---|
833 | // casting bundles of 4 rays generated from the simple rays
|
---|
834 | CastRayBundles4(simpleRays, vssRays);
|
---|
835 | else
|
---|
836 | CastRayBundles16(simpleRays, vssRays, scale);
|
---|
837 | }
|
---|
838 |
|
---|
839 | castTimer.Exit();
|
---|
840 |
|
---|
841 | // add to ray queue
|
---|
842 | EnqueueRays(vssRays);
|
---|
843 |
|
---|
844 | initialTimer.Exit();
|
---|
845 |
|
---|
846 | return (int)vssRays.size();
|
---|
847 | }
|
---|
848 |
|
---|
849 |
|
---|
850 | void GvsPreprocessor::EnqueueRays(VssRayContainer &samples)
|
---|
851 | {
|
---|
852 | rayTimer.Entry();
|
---|
853 |
|
---|
854 | // add samples to ray queue
|
---|
855 | VssRayContainer::const_iterator vit, vit_end = samples.end();
|
---|
856 | for (vit = samples.begin(); vit != vit_end; ++ vit)
|
---|
857 | {
|
---|
858 | VssRay *ray = *vit;
|
---|
859 | HandleRay(ray);
|
---|
860 | // note: deletion of invalid samples handked by ray pool
|
---|
861 | }
|
---|
862 |
|
---|
863 | rayTimer.Exit();
|
---|
864 | }
|
---|
865 |
|
---|
866 |
|
---|
867 | int GvsPreprocessor::ProcessQueue()
|
---|
868 | {
|
---|
869 | gvsTimer.Entry();
|
---|
870 |
|
---|
871 | ++ mGvsStats.mGvsRuns;
|
---|
872 |
|
---|
873 | int castSamples = 0;
|
---|
874 |
|
---|
875 | while (!mRayQueue.empty())
|
---|
876 | {
|
---|
877 | // handle next ray
|
---|
878 | VssRay *ray = mRayQueue.top();
|
---|
879 | mRayQueue.pop();
|
---|
880 |
|
---|
881 | if (1)
|
---|
882 | castSamples += AdaptiveBorderSampling(*ray);
|
---|
883 | else
|
---|
884 | castSamples += AdaptiveBorderSamplingOpt(*ray);
|
---|
885 | // note: don't have to delete because handled by ray pool
|
---|
886 | }
|
---|
887 |
|
---|
888 | gvsTimer.Exit();
|
---|
889 |
|
---|
890 | return castSamples;
|
---|
891 | }
|
---|
892 |
|
---|
893 |
|
---|
894 | void ExportVssRays(Exporter *exporter, const VssRayContainer &vssRays)
|
---|
895 | {
|
---|
896 | VssRayContainer vcRays, vcRays2, vcRays3;
|
---|
897 |
|
---|
898 | VssRayContainer::const_iterator rit, rit_end = vssRays.end();
|
---|
899 |
|
---|
900 | // prepare some rays for output
|
---|
901 | for (rit = vssRays.begin(); rit != rit_end; ++ rit)
|
---|
902 | {
|
---|
903 | //const float p = RandomValue(0.0f, (float)vssRays.size());
|
---|
904 |
|
---|
905 | if (1)//(p < raysOut)
|
---|
906 | {
|
---|
907 | if ((*rit)->mFlags & VssRay::BorderSample)
|
---|
908 | vcRays.push_back(*rit);
|
---|
909 | else if ((*rit)->mFlags & VssRay::ReverseSample)
|
---|
910 | vcRays2.push_back(*rit);
|
---|
911 | else
|
---|
912 | vcRays3.push_back(*rit);
|
---|
913 | }
|
---|
914 | }
|
---|
915 |
|
---|
916 | exporter->ExportRays(vcRays, RgbColor(1, 0, 0));
|
---|
917 | exporter->ExportRays(vcRays2, RgbColor(0, 1, 0));
|
---|
918 | exporter->ExportRays(vcRays3, RgbColor(1, 1, 1));
|
---|
919 | }
|
---|
920 |
|
---|
921 |
|
---|
922 | void GvsPreprocessor::VisualizeViewCell(const ObjectContainer &objects)
|
---|
923 | {
|
---|
924 | Intersectable::NewMail();
|
---|
925 | Material m;
|
---|
926 |
|
---|
927 | char str[64]; sprintf_s(str, "pass%06d.wrl", mProcessedViewCells);
|
---|
928 |
|
---|
929 | Exporter *exporter = Exporter::GetExporter(str);
|
---|
930 | if (!exporter)
|
---|
931 | return;
|
---|
932 |
|
---|
933 | ObjectContainer::const_iterator oit, oit_end = objects.end();
|
---|
934 |
|
---|
935 | for (oit = objects.begin(); oit != oit_end; ++ oit)
|
---|
936 | {
|
---|
937 | Intersectable *intersect = *oit;
|
---|
938 |
|
---|
939 | m = RandomMaterial();
|
---|
940 | exporter->SetForcedMaterial(m);
|
---|
941 | exporter->ExportIntersectable(intersect);
|
---|
942 | }
|
---|
943 |
|
---|
944 | cout << "vssrays: " << (int)mVssRays.size() << endl;
|
---|
945 | ExportVssRays(exporter, mVssRays);
|
---|
946 |
|
---|
947 |
|
---|
948 | /////////////////
|
---|
949 | //-- export view cell geometry
|
---|
950 |
|
---|
951 | //exporter->SetWireframe();
|
---|
952 |
|
---|
953 | m.mDiffuseColor = RgbColor(0, 1, 0);
|
---|
954 | exporter->SetForcedMaterial(m);
|
---|
955 |
|
---|
956 | AxisAlignedBox3 bbox = mCurrentViewCell->GetMesh()->mBox;
|
---|
957 | exporter->ExportBox(bbox);
|
---|
958 | //exporter->SetFilled();
|
---|
959 |
|
---|
960 | delete exporter;
|
---|
961 | }
|
---|
962 |
|
---|
963 |
|
---|
964 | void GvsPreprocessor::VisualizeViewCells()
|
---|
965 | {
|
---|
966 | char str[64]; sprintf_s(str, "tmp/pass%06d_%04d-", mProcessedViewCells, mPass);
|
---|
967 |
|
---|
968 | // visualization
|
---|
969 | if (mGvsStats.mPassContribution > 0)
|
---|
970 | {
|
---|
971 | const bool exportRays = true;
|
---|
972 | const bool exportPvs = true;
|
---|
973 |
|
---|
974 | mViewCellsManager->ExportSingleViewCells(mObjects,
|
---|
975 | 10,
|
---|
976 | false,
|
---|
977 | exportPvs,
|
---|
978 | exportRays,
|
---|
979 | 1000,
|
---|
980 | str);
|
---|
981 | }
|
---|
982 |
|
---|
983 | // remove pass samples
|
---|
984 | ViewCellContainer::const_iterator vit, vit_end = mViewCellsManager->GetViewCells().end();
|
---|
985 |
|
---|
986 | for (vit = mViewCellsManager->GetViewCells().begin(); vit != vit_end; ++ vit)
|
---|
987 | {
|
---|
988 | (*vit)->DelRayRefs();
|
---|
989 | }
|
---|
990 | }
|
---|
991 |
|
---|
992 |
|
---|
993 | void GvsPreprocessor::CompileViewCellsFromPointList()
|
---|
994 | {
|
---|
995 | ViewCell::NewMail();
|
---|
996 |
|
---|
997 | // Receive list of view cells from view cells manager
|
---|
998 | ViewCellPointsList *vcPoints = mViewCellsManager->GetViewCellPointsList();
|
---|
999 |
|
---|
1000 | vector<ViewCellPoints *>::const_iterator vit, vit_end = vcPoints->end();
|
---|
1001 |
|
---|
1002 | for (vit = vcPoints->begin(); vit != vit_end; ++ vit)
|
---|
1003 | {
|
---|
1004 | ViewCellPoints *vp = *vit;
|
---|
1005 |
|
---|
1006 | if (vp->first) // view cell specified
|
---|
1007 | {
|
---|
1008 | ViewCell *viewCell = vp->first;
|
---|
1009 |
|
---|
1010 | if (!viewCell->Mailed())
|
---|
1011 | {
|
---|
1012 | viewCell->Mail();
|
---|
1013 | mViewCells.push_back(viewCell);
|
---|
1014 |
|
---|
1015 | if (mViewCells.size() >= mMaxViewCells)
|
---|
1016 | break;
|
---|
1017 | }
|
---|
1018 | }
|
---|
1019 | else // no view cell specified => compute view cells using view point
|
---|
1020 | {
|
---|
1021 | SimpleRayContainer::const_iterator rit, rit_end = vp->second.end();
|
---|
1022 |
|
---|
1023 | for (rit = vp->second.begin(); rit != rit_end; ++ rit)
|
---|
1024 | {
|
---|
1025 | SimpleRay ray = *rit;
|
---|
1026 |
|
---|
1027 | ViewCell *viewCell = mViewCellsManager->GetViewCell(ray.mOrigin);
|
---|
1028 |
|
---|
1029 | if (viewCell && !viewCell->Mailed())
|
---|
1030 | {
|
---|
1031 | viewCell->Mail();
|
---|
1032 | mViewCells.push_back(viewCell);
|
---|
1033 |
|
---|
1034 | if (mViewCells.size() >= mMaxViewCells)
|
---|
1035 | break;
|
---|
1036 | }
|
---|
1037 | }
|
---|
1038 | }
|
---|
1039 | }
|
---|
1040 | }
|
---|
1041 |
|
---|
1042 |
|
---|
1043 | void GvsPreprocessor::CompileViewCellsList()
|
---|
1044 | {
|
---|
1045 | if (!mViewCellsManager->GetViewCellPointsList()->empty())
|
---|
1046 | {
|
---|
1047 | cout << "processing view point list" << endl;
|
---|
1048 | CompileViewCellsFromPointList();
|
---|
1049 | }
|
---|
1050 | else
|
---|
1051 | {
|
---|
1052 | ViewCell::NewMail();
|
---|
1053 |
|
---|
1054 | while ((int)mViewCells.size() < mMaxViewCells)
|
---|
1055 | {
|
---|
1056 | const int tries = 10000;
|
---|
1057 | int i = 0;
|
---|
1058 |
|
---|
1059 | for (i = 0; i < tries; ++ i)
|
---|
1060 | {
|
---|
1061 | const int idx = (int)RandomValue(0.0f, (float)mViewCellsManager->GetNumViewCells() - 0.5f);
|
---|
1062 |
|
---|
1063 | ViewCell *viewCell = mViewCellsManager->GetViewCell(idx);
|
---|
1064 |
|
---|
1065 | if (!viewCell->Mailed())
|
---|
1066 | {
|
---|
1067 | viewCell->Mail();
|
---|
1068 | break;
|
---|
1069 | }
|
---|
1070 |
|
---|
1071 | mViewCells.push_back(viewCell);
|
---|
1072 | }
|
---|
1073 |
|
---|
1074 | if (i == tries)
|
---|
1075 | {
|
---|
1076 | cerr << "big error! no view cell found" << endl;
|
---|
1077 | break;
|
---|
1078 | }
|
---|
1079 | }
|
---|
1080 | }
|
---|
1081 |
|
---|
1082 | cout << "\ncomputing list of " << mViewCells.size() << " view cells" << endl;
|
---|
1083 | }
|
---|
1084 |
|
---|
1085 |
|
---|
1086 | void GvsPreprocessor::ComputeViewCellGeometryIntersection()
|
---|
1087 | {
|
---|
1088 | intersectionTimer.Entry();
|
---|
1089 |
|
---|
1090 | AxisAlignedBox3 box = mCurrentViewCell->GetBox();
|
---|
1091 |
|
---|
1092 | int oldTrianglePvs = (int)mTrianglePvs.size();
|
---|
1093 | int newKdObj = 0;
|
---|
1094 |
|
---|
1095 | // compute pvs kd nodes that intersect view cell
|
---|
1096 | ObjectContainer kdobjects;
|
---|
1097 |
|
---|
1098 | // find intersecting objects not in pvs (i.e., only unmailed)
|
---|
1099 | mKdTree->CollectKdObjects(box, kdobjects);
|
---|
1100 |
|
---|
1101 | ObjectContainer pvsKdObjects;
|
---|
1102 |
|
---|
1103 | ObjectContainer::const_iterator oit, oit_end = kdobjects.end();
|
---|
1104 |
|
---|
1105 | for (oit = kdobjects.begin(); oit != oit_end; ++ oit)
|
---|
1106 | {
|
---|
1107 | KdIntersectable *kdInt = static_cast<KdIntersectable *>(*oit);
|
---|
1108 |
|
---|
1109 | myobjects.clear();
|
---|
1110 | mKdTree->CollectObjectsWithDublicates(kdInt->GetItem(), myobjects);
|
---|
1111 |
|
---|
1112 | // account for kd object pvs
|
---|
1113 | bool addkdobj = false;
|
---|
1114 |
|
---|
1115 | ObjectContainer::const_iterator oit, oit_end = myobjects.end();
|
---|
1116 |
|
---|
1117 | for (oit = myobjects.begin(); oit != oit_end; ++ oit)
|
---|
1118 | {
|
---|
1119 | TriangleIntersectable *triObj = static_cast<TriangleIntersectable *>(*oit);
|
---|
1120 |
|
---|
1121 | // test if the triangle itself intersects
|
---|
1122 | if (box.Intersects(triObj->GetItem()))
|
---|
1123 | addkdobj = AddTriangleObject(triObj);
|
---|
1124 | }
|
---|
1125 |
|
---|
1126 | // add node to kd pvs
|
---|
1127 | if (1 && addkdobj)
|
---|
1128 | {
|
---|
1129 | ++ newKdObj;
|
---|
1130 | mCurrentViewCell->GetPvs().AddSampleDirty(kdInt, 1.0f);
|
---|
1131 | //mCurrentViewCell->GetPvs().AddSampleDirtyCheck(kdInt, 1.0f);
|
---|
1132 | if (QT_VISUALIZATION_SHOWN) UpdateStatsForVisualization(kdInt);
|
---|
1133 | }
|
---|
1134 | }
|
---|
1135 |
|
---|
1136 | cout << "added " << (int)mTrianglePvs.size() - oldTrianglePvs << " triangles (" << newKdObj << " objects) by intersection" << endl;
|
---|
1137 |
|
---|
1138 | intersectionTimer.Exit();
|
---|
1139 | }
|
---|
1140 |
|
---|
1141 |
|
---|
1142 | void GvsPreprocessor::PerViewCellComputation()
|
---|
1143 | {
|
---|
1144 | while (mCurrentViewCell = NextViewCell())
|
---|
1145 | {
|
---|
1146 | preparationTimer.Entry();
|
---|
1147 |
|
---|
1148 | // hack: reset counters (could be done with a mailing-like approach
|
---|
1149 | ObjectContainer::const_iterator oit, oit_end = mObjects.end();
|
---|
1150 | for (oit = mObjects.begin(); oit != oit_end; ++ oit)
|
---|
1151 | (*oit)->mCounter = NOT_ACCOUNTED_OBJECT;
|
---|
1152 |
|
---|
1153 | preparationTimer.Exit();
|
---|
1154 |
|
---|
1155 | mDistribution->SetViewCell(mCurrentViewCell);
|
---|
1156 |
|
---|
1157 | ComputeViewCell();
|
---|
1158 | }
|
---|
1159 | }
|
---|
1160 |
|
---|
1161 |
|
---|
1162 | void GvsPreprocessor::PerViewCellComputation2()
|
---|
1163 | {
|
---|
1164 | while (1)
|
---|
1165 | {
|
---|
1166 | if (!mRendererWidget)
|
---|
1167 | continue;
|
---|
1168 |
|
---|
1169 | mCurrentViewCell = mViewCellsManager->GetViewCell(mRendererWidget->GetViewPoint());
|
---|
1170 |
|
---|
1171 | // no valid view cell or view cell already computed
|
---|
1172 | if (!mCurrentViewCell || !mCurrentViewCell->GetPvs().Empty() || !mRendererWidget->mComputeGVS)
|
---|
1173 | continue;
|
---|
1174 |
|
---|
1175 | mRendererWidget->mComputeGVS = false;
|
---|
1176 | // hack: reset counters
|
---|
1177 | ObjectContainer::const_iterator oit, oit_end = mObjects.end();
|
---|
1178 |
|
---|
1179 | for (oit = mObjects.begin(); oit != oit_end; ++ oit)
|
---|
1180 | (*oit)->mCounter = NOT_ACCOUNTED_OBJECT;
|
---|
1181 |
|
---|
1182 | ComputeViewCell();
|
---|
1183 | ++ mProcessedViewCells;
|
---|
1184 | }
|
---|
1185 | }
|
---|
1186 |
|
---|
1187 |
|
---|
1188 | void GvsPreprocessor::StorePvs(const ObjectContainer &objectPvs)
|
---|
1189 | {
|
---|
1190 | ObjectContainer::const_iterator oit, oit_end = objectPvs.end();
|
---|
1191 |
|
---|
1192 | for (oit = objectPvs.begin(); oit != oit_end; ++ oit)
|
---|
1193 | {
|
---|
1194 | mCurrentViewCell->GetPvs().AddSample(*oit, 1);
|
---|
1195 | }
|
---|
1196 | }
|
---|
1197 |
|
---|
1198 |
|
---|
1199 | void GvsPreprocessor::UpdatePvs(ViewCell *currentViewCell)
|
---|
1200 | {
|
---|
1201 | ObjectPvs newPvs;
|
---|
1202 | BvhLeaf::NewMail();
|
---|
1203 |
|
---|
1204 | ObjectPvsIterator pit = currentViewCell->GetPvs().GetIterator();
|
---|
1205 |
|
---|
1206 | // output PVS of view cell
|
---|
1207 | while (pit.HasMoreEntries())
|
---|
1208 | {
|
---|
1209 | Intersectable *intersect = pit.Next();
|
---|
1210 |
|
---|
1211 | BvhLeaf *bv = intersect->mBvhLeaf;
|
---|
1212 |
|
---|
1213 | if (!bv || bv->Mailed())
|
---|
1214 | continue;
|
---|
1215 |
|
---|
1216 | bv->Mail();
|
---|
1217 |
|
---|
1218 | //m.mDiffuseColor = RgbColor(1, 0, 0);
|
---|
1219 | newPvs.AddSampleDirty(bv, 1.0f);
|
---|
1220 | }
|
---|
1221 |
|
---|
1222 | newPvs.SimpleSort();
|
---|
1223 |
|
---|
1224 | currentViewCell->SetPvs(newPvs);
|
---|
1225 | }
|
---|
1226 |
|
---|
1227 |
|
---|
1228 | void GvsPreprocessor::GetObjectPvs(ObjectContainer &objectPvs) const
|
---|
1229 | {
|
---|
1230 | BvhLeaf::NewMail();
|
---|
1231 |
|
---|
1232 | objectPvs.reserve((int)mTrianglePvs.size());
|
---|
1233 |
|
---|
1234 | ObjectContainer::const_iterator oit, oit_end = mTrianglePvs.end();
|
---|
1235 |
|
---|
1236 | for (oit = mTrianglePvs.begin(); oit != oit_end; ++ oit)
|
---|
1237 | {
|
---|
1238 | Intersectable *intersect = *oit;
|
---|
1239 |
|
---|
1240 | BvhLeaf *bv = intersect->mBvhLeaf;
|
---|
1241 |
|
---|
1242 | // hack: reset counter
|
---|
1243 | (*oit)->mCounter = NOT_ACCOUNTED_OBJECT;
|
---|
1244 |
|
---|
1245 | if (!bv || bv->Mailed())
|
---|
1246 | continue;
|
---|
1247 |
|
---|
1248 | bv->Mail();
|
---|
1249 | objectPvs.push_back(bv);
|
---|
1250 | }
|
---|
1251 | }
|
---|
1252 |
|
---|
1253 |
|
---|
1254 | void GvsPreprocessor::GlobalComputation()
|
---|
1255 | {
|
---|
1256 | int passSamples = 0;
|
---|
1257 | int randomSamples = 0;
|
---|
1258 | int gvsSamples = 0;
|
---|
1259 | int oldContribution = 0;
|
---|
1260 |
|
---|
1261 | while (mGvsStats.mTotalSamples < mTotalSamples)
|
---|
1262 | {
|
---|
1263 | mRayCaster->InitPass();
|
---|
1264 |
|
---|
1265 | int newRandomSamples, newGvsSamples;
|
---|
1266 |
|
---|
1267 | // Ray queue empty =>
|
---|
1268 | // cast a number of uniform samples to fill ray queue
|
---|
1269 | newRandomSamples = CastInitialSamples(mInitialSamples);
|
---|
1270 |
|
---|
1271 | if (!mOnlyRandomSampling)
|
---|
1272 | newGvsSamples = ProcessQueue();
|
---|
1273 |
|
---|
1274 | passSamples += newRandomSamples + newGvsSamples;
|
---|
1275 | mGvsStats.mTotalSamples += newRandomSamples + newGvsSamples;
|
---|
1276 |
|
---|
1277 | mGvsStats.mRandomSamples += newRandomSamples;
|
---|
1278 | mGvsStats.mGvsSamples += newGvsSamples;
|
---|
1279 |
|
---|
1280 |
|
---|
1281 | if (passSamples % (mGvsSamplesPerPass + 1) == mGvsSamplesPerPass)
|
---|
1282 | {
|
---|
1283 | ++ mPass;
|
---|
1284 |
|
---|
1285 | mGvsStats.mPassContribution = mGvsStats.mTotalContribution - oldContribution;
|
---|
1286 |
|
---|
1287 | ////////
|
---|
1288 | //-- stats
|
---|
1289 |
|
---|
1290 | //cout << "\nPass " << mPass << " #samples: " << mGvsStats.mTotalSamples << " of " << mTotalSamples << endl;
|
---|
1291 | mGvsStats.mPass = mPass;
|
---|
1292 | mGvsStats.Stop();
|
---|
1293 | mGvsStats.Print(mGvsStatsStream);
|
---|
1294 |
|
---|
1295 | // reset
|
---|
1296 | oldContribution = mGvsStats.mTotalContribution;
|
---|
1297 | mGvsStats.mPassContribution = 0;
|
---|
1298 | passSamples = 0;
|
---|
1299 |
|
---|
1300 | if (GVS_DEBUG)
|
---|
1301 | VisualizeViewCells();
|
---|
1302 | }
|
---|
1303 | }
|
---|
1304 | }
|
---|
1305 |
|
---|
1306 |
|
---|
1307 | bool GvsPreprocessor::ComputeVisibility()
|
---|
1308 | {
|
---|
1309 | cout << "Gvs Preprocessor started\n" << flush;
|
---|
1310 | const long startTime = GetTime();
|
---|
1311 |
|
---|
1312 | //Randomize(0);
|
---|
1313 | mGvsStats.Reset();
|
---|
1314 | mGvsStats.Start();
|
---|
1315 |
|
---|
1316 | if (!mLoadViewCells)
|
---|
1317 | {
|
---|
1318 | /// construct the view cells from the scratch
|
---|
1319 | ConstructViewCells();
|
---|
1320 | // reset pvs already gathered during view cells construction
|
---|
1321 | mViewCellsManager->ResetPvs();
|
---|
1322 | cout << "finished view cell construction" << endl;
|
---|
1323 | }
|
---|
1324 |
|
---|
1325 | if (mPerViewCell)
|
---|
1326 | {
|
---|
1327 | #if 1
|
---|
1328 | // provide list of view cells to compute
|
---|
1329 | CompileViewCellsList();
|
---|
1330 |
|
---|
1331 | // start per view cell gvs
|
---|
1332 | PerViewCellComputation();
|
---|
1333 | #else
|
---|
1334 | PerViewCellComputation2();
|
---|
1335 |
|
---|
1336 | #endif
|
---|
1337 | }
|
---|
1338 | else
|
---|
1339 | {
|
---|
1340 | GlobalComputation();
|
---|
1341 | }
|
---|
1342 |
|
---|
1343 | cout << "cast " << mGvsStats.mTotalSamples / (1e3f * TimeDiff(startTime, GetTime())) << "M single rays/s" << endl;
|
---|
1344 |
|
---|
1345 | if (GVS_DEBUG)
|
---|
1346 | {
|
---|
1347 | Visualize();
|
---|
1348 | CLEAR_CONTAINER(mVssRays);
|
---|
1349 | }
|
---|
1350 |
|
---|
1351 | // export the preprocessed information to a file
|
---|
1352 | if (0 && mExportVisibility)
|
---|
1353 | ExportPreprocessedData(mVisibilityFileName);
|
---|
1354 |
|
---|
1355 | // compute the pixel error of this visibility solution
|
---|
1356 | if (0 && mEvaluatePixelError)
|
---|
1357 | ComputeRenderError();
|
---|
1358 |
|
---|
1359 | return true;
|
---|
1360 | }
|
---|
1361 |
|
---|
1362 |
|
---|
1363 | void GvsPreprocessor::DeterminePvsObjects(VssRayContainer &rays)
|
---|
1364 | {
|
---|
1365 | // store triangle directly
|
---|
1366 | mViewCellsManager->DeterminePvsObjects(rays, true);
|
---|
1367 | }
|
---|
1368 |
|
---|
1369 |
|
---|
1370 | void GvsPreprocessor::Visualize()
|
---|
1371 | {
|
---|
1372 | Exporter *exporter = Exporter::GetExporter("gvs.wrl");
|
---|
1373 |
|
---|
1374 | if (!exporter)
|
---|
1375 | return;
|
---|
1376 |
|
---|
1377 | vector<VizStruct>::const_iterator vit, vit_end = vizContainer.end();
|
---|
1378 |
|
---|
1379 | for (vit = vizContainer.begin(); vit != vit_end; ++ vit)
|
---|
1380 | {
|
---|
1381 | exporter->SetWireframe();
|
---|
1382 | exporter->ExportPolygon((*vit).enlargedTriangle);
|
---|
1383 | //Material m;
|
---|
1384 | exporter->SetFilled();
|
---|
1385 | Polygon3 poly = Polygon3((*vit).originalTriangle);
|
---|
1386 | exporter->ExportPolygon(&poly);
|
---|
1387 | }
|
---|
1388 |
|
---|
1389 | VssRayContainer::const_iterator rit, rit_end = mVssRays.end();
|
---|
1390 |
|
---|
1391 | for (rit = mVssRays.begin(); rit != rit_end; ++ rit)
|
---|
1392 | {
|
---|
1393 | Intersectable *obj = (*rit)->mTerminationObject;
|
---|
1394 | exporter->ExportIntersectable(obj);
|
---|
1395 | }
|
---|
1396 |
|
---|
1397 | ExportVssRays(exporter, mVssRays);
|
---|
1398 |
|
---|
1399 | delete exporter;
|
---|
1400 | }
|
---|
1401 |
|
---|
1402 |
|
---|
1403 | void GvsStatistics::Print(ostream &app) const
|
---|
1404 | {
|
---|
1405 | app << "#ViewCells\n" << mViewCells << endl;
|
---|
1406 | app << "#Id\n" << mViewCellId << endl;
|
---|
1407 | app << "#Time\n" << mTimePerViewCell << endl;;
|
---|
1408 | app << "#TriPvs\n" << mTrianglePvs << endl;
|
---|
1409 | app << "#ObjectPvs\n" << mPerViewCellPvs << endl;
|
---|
1410 | app << "#UpdatedPvs\n" << (int)mPvsCost << endl;
|
---|
1411 |
|
---|
1412 | app << "#PerViewCellSamples\n" << mPerViewCellSamples << endl;
|
---|
1413 | app << "#RaysPerSec\n" << RaysPerSec() << endl;
|
---|
1414 |
|
---|
1415 | app << "#TotalPvs\n" << mTotalPvs << endl;
|
---|
1416 | app << "#TotalTime\n" << mTotalTime << endl;
|
---|
1417 | app << "#TotalSamples\n" << mTotalSamples << endl;
|
---|
1418 |
|
---|
1419 | app << "#AvgPvs: " << mPvsCost / mViewCells << endl;
|
---|
1420 | app << "#TotalTrianglePvs\n" << mTotalTrianglePvs << endl;
|
---|
1421 |
|
---|
1422 | if (0)
|
---|
1423 | {
|
---|
1424 | app << "#ReverseSamples\n" << mReverseSamples << endl;
|
---|
1425 | app << "#BorderSamples\n" << mBorderSamples << endl;
|
---|
1426 |
|
---|
1427 | app << "#Pass\n" << mPass << endl;
|
---|
1428 | app << "#ScDiff\n" << mPassContribution << endl;
|
---|
1429 | app << "#GvsRuns\n" << mGvsRuns << endl;
|
---|
1430 |
|
---|
1431 | app << "#SamplesContri\n" << mTotalContribution << endl;
|
---|
1432 | }
|
---|
1433 |
|
---|
1434 | app << endl;
|
---|
1435 | }
|
---|
1436 |
|
---|
1437 |
|
---|
1438 | void GvsPreprocessor::ComputeViewCell()
|
---|
1439 | {
|
---|
1440 | const long startTime = GetTime();
|
---|
1441 |
|
---|
1442 | // initialise
|
---|
1443 | mGvsStats.mPerViewCellSamples = 0;
|
---|
1444 | mGvsStats.mRandomSamples = 0;
|
---|
1445 | mGvsStats.mGvsSamples = 0;
|
---|
1446 | mUseProbablyVisibleSampling = false;
|
---|
1447 | //renderer->mPvsStat.currentPass = 0;
|
---|
1448 |
|
---|
1449 | mPass = 0;
|
---|
1450 |
|
---|
1451 | int oldContribution = 0;
|
---|
1452 | int passSamples = 0;
|
---|
1453 |
|
---|
1454 | for (int i = 0; i < 2; ++ i)
|
---|
1455 | mGenericStats[i] = 0;
|
---|
1456 |
|
---|
1457 | mTrianglePvs.clear();
|
---|
1458 |
|
---|
1459 |
|
---|
1460 | // hack: take bounding box of view cell as view cell bounds
|
---|
1461 | mCurrentViewCell->GetMesh()->ComputeBoundingBox();
|
---|
1462 |
|
---|
1463 | // use mailing for kd node pvs
|
---|
1464 | KdNode::NewMail();
|
---|
1465 |
|
---|
1466 | cout << "\n***********************\n"
|
---|
1467 | << "computing view cell " << mProcessedViewCells
|
---|
1468 | << " (id: " << mCurrentViewCell->GetId() << ")" << endl;
|
---|
1469 | cout << "bb: " << mCurrentViewCell->GetBox() << endl;
|
---|
1470 |
|
---|
1471 | mainLoopTimer.Entry();
|
---|
1472 |
|
---|
1473 | while (1)
|
---|
1474 | {
|
---|
1475 | sInvalidSamples = 0;
|
---|
1476 | int oldPvsSize = mCurrentViewCell->GetPvs().GetSize();
|
---|
1477 |
|
---|
1478 | mRayCaster->InitPass();
|
---|
1479 |
|
---|
1480 | int newRandomSamples, newGvsSamples, newSamples;
|
---|
1481 |
|
---|
1482 | // Ray queue empty =>
|
---|
1483 | // cast a number of uniform samples to fill ray queue
|
---|
1484 | newRandomSamples = CastInitialSamples(mInitialSamples);
|
---|
1485 |
|
---|
1486 | //if (!mUseProbablyVisibleSampling && !mOnlyRandomSampling)
|
---|
1487 | if (!mOnlyRandomSampling)
|
---|
1488 | newGvsSamples = ProcessQueue();
|
---|
1489 |
|
---|
1490 | newSamples = newRandomSamples + newGvsSamples;
|
---|
1491 |
|
---|
1492 | passSamples += newSamples;
|
---|
1493 | mGvsStats.mPerViewCellSamples += newSamples;
|
---|
1494 |
|
---|
1495 | mGvsStats.mRandomSamples += newRandomSamples;
|
---|
1496 | mGvsStats.mGvsSamples += newGvsSamples;
|
---|
1497 |
|
---|
1498 |
|
---|
1499 | if (passSamples >= mGvsSamplesPerPass)
|
---|
1500 | {
|
---|
1501 | if (GVS_DEBUG) VisualizeViewCell(mTrianglePvs);
|
---|
1502 |
|
---|
1503 | //const bool convertPerPass = true;
|
---|
1504 | const bool convertPerPass = false;
|
---|
1505 |
|
---|
1506 | if (convertPerPass)
|
---|
1507 | {
|
---|
1508 | int newObjects = ConvertObjectPvs();
|
---|
1509 |
|
---|
1510 | cout << "added " << newObjects << " triangles to triangle pvs" << endl;
|
---|
1511 | mGvsStats.mTotalContribution += newObjects;
|
---|
1512 | }
|
---|
1513 |
|
---|
1514 | ++ mPass;
|
---|
1515 | mGvsStats.mPassContribution = mGvsStats.mTotalContribution - oldContribution;
|
---|
1516 |
|
---|
1517 | if (mGvsStats.mPassContribution < 2000)
|
---|
1518 | mUseProbablyVisibleSampling = true;
|
---|
1519 |
|
---|
1520 | if (mUseProbablyVisibleSampling)
|
---|
1521 | PrepareProbablyVisibleSampling();
|
---|
1522 |
|
---|
1523 |
|
---|
1524 | ////////
|
---|
1525 | //-- stats
|
---|
1526 |
|
---|
1527 | mGvsStats.mPass = mPass;
|
---|
1528 |
|
---|
1529 | cout << "\nPass " << mPass << " #samples: " << mGvsStats.mPerViewCellSamples << endl;
|
---|
1530 | cout << "contribution=" << mGvsStats.mPassContribution << " (of " << mMinContribution << ")" << endl;
|
---|
1531 | cout << "obj contri=" << mCurrentViewCell->GetPvs().GetSize() - oldPvsSize << " (of " << mMinContribution << ")" << endl;
|
---|
1532 |
|
---|
1533 | // termination criterium
|
---|
1534 | if (mGvsStats.mPassContribution < mMinContribution)
|
---|
1535 | break;
|
---|
1536 |
|
---|
1537 | // reset stats
|
---|
1538 | oldContribution = mGvsStats.mTotalContribution;
|
---|
1539 | mGvsStats.mPassContribution = 0;
|
---|
1540 | passSamples = 0;
|
---|
1541 |
|
---|
1542 | // compute the pixel error of this visibility solution
|
---|
1543 | if (0 && mEvaluatePixelError)
|
---|
1544 | ComputeRenderError();
|
---|
1545 | }
|
---|
1546 | }
|
---|
1547 |
|
---|
1548 | mainLoopTimer.Exit();
|
---|
1549 |
|
---|
1550 | // at last compute objects that directly intersect view cell
|
---|
1551 | ComputeViewCellGeometryIntersection();
|
---|
1552 |
|
---|
1553 | // compute the pixel error of this visibility solution
|
---|
1554 | if (mEvaluatePixelError)
|
---|
1555 | ComputeRenderError();
|
---|
1556 |
|
---|
1557 | ////////
|
---|
1558 | //-- stats
|
---|
1559 |
|
---|
1560 | // timing
|
---|
1561 | mGvsStats.mTimePerViewCell = TimeDiff(startTime, GetTime()) * 1e-3f;
|
---|
1562 |
|
---|
1563 | ComputeStats();
|
---|
1564 | }
|
---|
1565 |
|
---|
1566 |
|
---|
1567 | void GvsPreprocessor::ComputeStats()
|
---|
1568 | {
|
---|
1569 | // compute pvs size using larger (bvh objects)
|
---|
1570 | // note: for kd pvs we had to do this during gvs computation
|
---|
1571 | if (!mUseKdPvs)
|
---|
1572 | {
|
---|
1573 | ObjectContainer objectPvs;
|
---|
1574 |
|
---|
1575 | // optain object pvs
|
---|
1576 | GetObjectPvs(objectPvs);
|
---|
1577 |
|
---|
1578 | // add pvs
|
---|
1579 | ObjectContainer::const_iterator it, it_end = objectPvs.end();
|
---|
1580 |
|
---|
1581 | for (it = objectPvs.begin(); it != it_end; ++ it)
|
---|
1582 | {
|
---|
1583 | mCurrentViewCell->GetPvs().AddSampleDirty(*it, 1.0f);
|
---|
1584 | }
|
---|
1585 |
|
---|
1586 | cout << "triangle pvs of " << (int)mTrianglePvs.size()
|
---|
1587 | << " was converted to object pvs of " << (int)objectPvs.size() << endl;
|
---|
1588 |
|
---|
1589 | mGvsStats.mPerViewCellPvs = (int)objectPvs.size();
|
---|
1590 | mGvsStats.mPvsCost = 0; // todo objectPvs.EvalPvsCost();
|
---|
1591 | }
|
---|
1592 | else
|
---|
1593 | {
|
---|
1594 | if (0) // compute pvs kd nodes that intersect view cell
|
---|
1595 | {
|
---|
1596 | ObjectContainer mykdobjects;
|
---|
1597 |
|
---|
1598 | // extract kd pvs
|
---|
1599 | ObjectContainer::const_iterator it, it_end = mTrianglePvs.end();
|
---|
1600 |
|
---|
1601 | for (it = mTrianglePvs.begin(); it != it_end; ++ it)
|
---|
1602 | {
|
---|
1603 | Intersectable *obj = *it;
|
---|
1604 | // find intersecting objects not yet in pvs (i.e., only unmailed)
|
---|
1605 | mKdTree->CollectKdObjects(obj->GetBox(), mykdobjects);
|
---|
1606 | }
|
---|
1607 |
|
---|
1608 | // add pvs
|
---|
1609 | it_end = mykdobjects.end();
|
---|
1610 |
|
---|
1611 | for (it = mykdobjects.begin(); it != it_end; ++ it)
|
---|
1612 | {
|
---|
1613 | mCurrentViewCell->GetPvs().AddSampleDirty(*it, 1.0f);
|
---|
1614 | }
|
---|
1615 |
|
---|
1616 | cout << "added " << (int)mykdobjects.size() << " new objects " << endl;
|
---|
1617 | }
|
---|
1618 |
|
---|
1619 | mGvsStats.mPerViewCellPvs = mCurrentViewCell->GetPvs().GetSize();
|
---|
1620 | mGvsStats.mPvsCost = mCurrentViewCell->GetPvs().EvalPvsCost();
|
---|
1621 |
|
---|
1622 | }
|
---|
1623 |
|
---|
1624 | mGvsStats.mTrianglePvs = (int)mTrianglePvs.size();
|
---|
1625 |
|
---|
1626 |
|
---|
1627 | ////////////////
|
---|
1628 | // global values
|
---|
1629 |
|
---|
1630 | mGvsStats.mViewCells = mProcessedViewCells;
|
---|
1631 | mGvsStats.mTotalTrianglePvs += mGvsStats.mTrianglePvs;
|
---|
1632 | mGvsStats.mTotalTime += mGvsStats.mTimePerViewCell;
|
---|
1633 | mGvsStats.mTotalPvs += mGvsStats.mPerViewCellPvs;
|
---|
1634 | mGvsStats.mTotalSamples += mGvsStats.mPerViewCellSamples;
|
---|
1635 |
|
---|
1636 | cout << "id: " << mCurrentViewCell->GetId() << endl;
|
---|
1637 | cout << "pvs cost " << mGvsStats.mPvsCost / 1000000 << " M" << endl;
|
---|
1638 | cout << "pvs tri: " << mTrianglePvs.size() << endl;
|
---|
1639 | cout << "samples: " << mGvsStats.mTotalSamples / 1000000 << " M" << endl;
|
---|
1640 | printf("contri: %f tri / K rays\n", 1000.0f * (float)mTrianglePvs.size() / mGvsStats.mTotalSamples);
|
---|
1641 |
|
---|
1642 | //cout << "invalid samples ratio: " << (float)sInvalidSamples / mGvsStats.mPerViewCellSamples << endl;
|
---|
1643 |
|
---|
1644 | double rayTime = rayTimer.TotalTime();
|
---|
1645 | double kdPvsTime = kdPvsTimer.TotalTime();
|
---|
1646 | double gvsTime = gvsTimer.TotalTime();
|
---|
1647 | double initialTime = initialTimer.TotalTime();
|
---|
1648 | double intersectionTime = intersectionTimer.TotalTime();
|
---|
1649 | double preparationTime = preparationTimer.TotalTime();
|
---|
1650 | double mainLoopTime = mainLoopTimer.TotalTime();
|
---|
1651 | double contributionTime = contributionTimer.TotalTime();
|
---|
1652 | double castTime = castTimer.TotalTime();
|
---|
1653 | double generationTime = generationTimer.TotalTime();
|
---|
1654 | double rawCastTime = mRayCaster->rawCastTimer.TotalTime();
|
---|
1655 |
|
---|
1656 | cout << "handleRay : " << rayTime << endl;
|
---|
1657 | cout << "kd pvs : " << kdPvsTime << endl;
|
---|
1658 | cout << "gvs sampling : " << gvsTime << endl;
|
---|
1659 | cout << "initial sampling : " << initialTime << endl;
|
---|
1660 | cout << "view cell intersection : " << intersectionTime << endl;
|
---|
1661 | cout << "preparation : " << preparationTime << endl;
|
---|
1662 | cout << "main loop : " << mainLoopTime << endl;
|
---|
1663 | cout << "has contribution : " << contributionTime << endl;
|
---|
1664 | cout << "cast time : " << castTime << endl;
|
---|
1665 | cout << "generation time : " << generationTime << endl;
|
---|
1666 | cout << "raw cast time : " << rawCastTime << endl;
|
---|
1667 |
|
---|
1668 | double randomRaysPerSec = mGvsStats.mRandomSamples / (1e6 * initialTime);
|
---|
1669 | double gvsRaysPerSec = mGvsStats.mGvsSamples / (1e6 * gvsTime);
|
---|
1670 | double rawRaysPerSec = mGvsStats.mPerViewCellSamples / (1e6 * rawCastTime);
|
---|
1671 |
|
---|
1672 | cout << "cast " << randomRaysPerSec << " M random rays/s: " << endl;
|
---|
1673 | cout << "cast " << gvsRaysPerSec << " M gvs rays/s: " << endl;
|
---|
1674 | cout << "cast " << rawRaysPerSec << " M raw rays/s: " << endl;
|
---|
1675 |
|
---|
1676 | mGvsStats.Stop();
|
---|
1677 | mGvsStats.Print(mGvsStatsStream);
|
---|
1678 | }
|
---|
1679 |
|
---|
1680 |
|
---|
1681 | int GvsPreprocessor::ConvertObjectPvs()
|
---|
1682 | {
|
---|
1683 | static ObjectContainer triangles;
|
---|
1684 |
|
---|
1685 | int newObjects = 0;
|
---|
1686 |
|
---|
1687 | ObjectPvsIterator pit = mCurrentViewCell->GetPvs().GetIterator();
|
---|
1688 |
|
---|
1689 | triangles.clear();
|
---|
1690 |
|
---|
1691 | // output PVS of view cell
|
---|
1692 | while (pit.HasMoreEntries())
|
---|
1693 | {
|
---|
1694 | KdIntersectable *kdInt = static_cast<KdIntersectable *>(pit.Next());
|
---|
1695 |
|
---|
1696 | mKdTree->CollectObjectsWithDublicates(kdInt->GetItem(), triangles);
|
---|
1697 |
|
---|
1698 | ObjectContainer::const_iterator oit, oit_end = triangles.end();
|
---|
1699 |
|
---|
1700 | for (oit = triangles.begin(); oit != oit_end; ++ oit)
|
---|
1701 | {
|
---|
1702 | if (AddTriangleObject(*oit))
|
---|
1703 | ++ newObjects;
|
---|
1704 | }
|
---|
1705 | }
|
---|
1706 |
|
---|
1707 | return newObjects;
|
---|
1708 | }
|
---|
1709 |
|
---|
1710 |
|
---|
1711 | bool GvsPreprocessor::AddTriangleObject(Intersectable *triObj)
|
---|
1712 | {
|
---|
1713 | if ((triObj->mCounter < ACCOUNTED_OBJECT))
|
---|
1714 | {
|
---|
1715 | triObj->mCounter += ACCOUNTED_OBJECT;
|
---|
1716 |
|
---|
1717 | mTrianglePvs.push_back(triObj);
|
---|
1718 | mGenericStats[0] = (int)mTrianglePvs.size();
|
---|
1719 |
|
---|
1720 | return true;
|
---|
1721 | }
|
---|
1722 |
|
---|
1723 | return false;
|
---|
1724 | }
|
---|
1725 |
|
---|
1726 |
|
---|
1727 | void GvsPreprocessor::CastRayBundles4(const SimpleRayContainer &rays, VssRayContainer &vssRays)
|
---|
1728 | {
|
---|
1729 | AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox();
|
---|
1730 |
|
---|
1731 | SimpleRayContainer::const_iterator it, it_end = rays.end();
|
---|
1732 |
|
---|
1733 | for (it = rays.begin(); it != it_end; ++ it)
|
---|
1734 | CastRayBundle4(*it, vssRays, box);
|
---|
1735 | }
|
---|
1736 |
|
---|
1737 |
|
---|
1738 | void GvsPreprocessor::CastRayBundle4(const SimpleRay &ray,
|
---|
1739 | VssRayContainer &vssRays,
|
---|
1740 | const AxisAlignedBox3 &box)
|
---|
1741 | {
|
---|
1742 | const float pertubDir = 0.01f;
|
---|
1743 | static Vector3 pertub;
|
---|
1744 |
|
---|
1745 | static int hit_triangles[4];
|
---|
1746 | static float dist[4];
|
---|
1747 | static Vector3 dirs[4];
|
---|
1748 | static Vector3 origs[4];
|
---|
1749 |
|
---|
1750 | origs[0] = ray.mOrigin;
|
---|
1751 | dirs[0] = ray.mDirection;
|
---|
1752 |
|
---|
1753 | for (int i = 1; i < 4; ++ i)
|
---|
1754 | {
|
---|
1755 | origs[i] = ray.mOrigin;
|
---|
1756 |
|
---|
1757 | pertub.x = RandomValue(-pertubDir, pertubDir);
|
---|
1758 | pertub.y = RandomValue(-pertubDir, pertubDir);
|
---|
1759 | pertub.z = RandomValue(-pertubDir, pertubDir);
|
---|
1760 |
|
---|
1761 | dirs[i] = ray.mDirection + pertub;
|
---|
1762 | dirs[i] *= 1.0f / Magnitude(dirs[i]);
|
---|
1763 | }
|
---|
1764 |
|
---|
1765 | Cast4Rays(dist, dirs, origs, vssRays, box);
|
---|
1766 | }
|
---|
1767 |
|
---|
1768 |
|
---|
1769 | void GvsPreprocessor::CastRays4(const SimpleRayContainer &rays, VssRayContainer &vssRays)
|
---|
1770 | {
|
---|
1771 | SimpleRayContainer::const_iterator it, it_end = rays.end();
|
---|
1772 |
|
---|
1773 | static float dist[4];
|
---|
1774 | static Vector3 dirs[4];
|
---|
1775 | static Vector3 origs[4];
|
---|
1776 |
|
---|
1777 | AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox();
|
---|
1778 |
|
---|
1779 | for (it = rays.begin(); it != it_end; ++ it)
|
---|
1780 | {
|
---|
1781 | for (int i = 1; i < 4; ++ i)
|
---|
1782 | {
|
---|
1783 | origs[i] = rays[i].mOrigin;
|
---|
1784 | dirs[i] = rays[i].mDirection;
|
---|
1785 | }
|
---|
1786 | }
|
---|
1787 |
|
---|
1788 | Cast4Rays(dist, dirs, origs, vssRays, box);
|
---|
1789 | }
|
---|
1790 |
|
---|
1791 |
|
---|
1792 | void GvsPreprocessor::Cast4Rays(float *dist,
|
---|
1793 | Vector3 *dirs,
|
---|
1794 | Vector3 *origs,
|
---|
1795 | VssRayContainer &vssRays,
|
---|
1796 | const AxisAlignedBox3 &box)
|
---|
1797 | {
|
---|
1798 | static int hit_triangles[4];
|
---|
1799 |
|
---|
1800 | mRayCaster->CastRaysPacket4(box.Min(), box.Max(), origs, dirs, hit_triangles, dist);
|
---|
1801 |
|
---|
1802 | VssRay *ray;
|
---|
1803 |
|
---|
1804 | for (int i = 0; i < 4; ++ i)
|
---|
1805 | {
|
---|
1806 | if (hit_triangles[i] != -1)
|
---|
1807 | {
|
---|
1808 | TriangleIntersectable *triObj = static_cast<TriangleIntersectable *>(mObjects[hit_triangles[i]]);
|
---|
1809 |
|
---|
1810 | if (DotProd(triObj->GetItem().GetNormal(), dirs[i] >= 0))
|
---|
1811 | ray = NULL;
|
---|
1812 | else
|
---|
1813 | ray = mRayCaster->RequestRay(origs[i], origs[i] + dirs[i] * dist[i], NULL, triObj, mPass, 1.0f);
|
---|
1814 | }
|
---|
1815 | else
|
---|
1816 | {
|
---|
1817 | ray = NULL;
|
---|
1818 | }
|
---|
1819 |
|
---|
1820 | vssRays.push_back(ray);
|
---|
1821 | }
|
---|
1822 | }
|
---|
1823 |
|
---|
1824 |
|
---|
1825 | void GvsPreprocessor::CastRayBundle16(const SimpleRay &ray, VssRayContainer &vssRays, float scale)
|
---|
1826 | {
|
---|
1827 | static SimpleRayContainer simpleRays;
|
---|
1828 | simpleRays.clear();
|
---|
1829 |
|
---|
1830 | simpleRays.push_back(ray);
|
---|
1831 | GenerateJitteredRays(simpleRays, ray, 15, 0, scale);
|
---|
1832 |
|
---|
1833 | CastRays(simpleRays, vssRays, false, false);
|
---|
1834 | }
|
---|
1835 |
|
---|
1836 |
|
---|
1837 | void GvsPreprocessor::CastRayBundles16(const SimpleRayContainer &rays, VssRayContainer &vssRays, float scale)
|
---|
1838 | {
|
---|
1839 | SimpleRayContainer::const_iterator it, it_end = rays.end();
|
---|
1840 |
|
---|
1841 | for (it = rays.begin(); it != it_end; ++ it)
|
---|
1842 | CastRayBundle16(*it, vssRays, scale);
|
---|
1843 | }
|
---|
1844 |
|
---|
1845 |
|
---|
1846 | void GvsPreprocessor::ComputeRenderError()
|
---|
1847 | {
|
---|
1848 | // compute rendering error
|
---|
1849 | if (renderer && renderer->mPvsStatFrames)
|
---|
1850 | {
|
---|
1851 | if (!mViewCellsManager->GetViewCellPointsList()->empty())
|
---|
1852 | {
|
---|
1853 | ViewCellPointsList *vcPoints = mViewCellsManager->GetViewCellPointsList();
|
---|
1854 | ViewCellPointsList::const_iterator vit = vcPoints->begin(), vit_end = vcPoints->end();
|
---|
1855 |
|
---|
1856 | SimpleRayContainer viewPoints;
|
---|
1857 |
|
---|
1858 | for (; vit != vit_end; ++ vit)
|
---|
1859 | {
|
---|
1860 | ViewCellPoints *vp = *vit;
|
---|
1861 |
|
---|
1862 | SimpleRayContainer::const_iterator rit = vp->second.begin(), rit_end = vp->second.end();
|
---|
1863 |
|
---|
1864 | for (; rit!=rit_end; ++rit)
|
---|
1865 | {
|
---|
1866 | ViewCell *vc = mViewCellsManager->GetViewCell((*rit).mOrigin);
|
---|
1867 | if (vc == mCurrentViewCell)
|
---|
1868 | viewPoints.push_back(*rit);
|
---|
1869 | }
|
---|
1870 | }
|
---|
1871 |
|
---|
1872 | renderer->mPvsErrorBuffer.clear();
|
---|
1873 |
|
---|
1874 | if (viewPoints.size() != renderer->mPvsErrorBuffer.size())
|
---|
1875 | {
|
---|
1876 | renderer->mPvsErrorBuffer.resize(viewPoints.size());
|
---|
1877 | renderer->ClearErrorBuffer();
|
---|
1878 | }
|
---|
1879 |
|
---|
1880 | cout << "evaluating list of " << viewPoints.size() << " pts" << endl;
|
---|
1881 | renderer->EvalPvsStat(viewPoints);
|
---|
1882 | }
|
---|
1883 | else
|
---|
1884 | {
|
---|
1885 | cout << "evaluating random points" << endl;
|
---|
1886 | renderer->EvalPvsStat();
|
---|
1887 | }
|
---|
1888 |
|
---|
1889 | mStats <<
|
---|
1890 | "#AvgPvsRenderError\n" <<renderer->mPvsStat.GetAvgError()<<endl<<
|
---|
1891 | "#AvgPixelError\n" <<renderer->GetAvgPixelError()<<endl<<
|
---|
1892 | "#MaxPixelError\n" <<renderer->GetMaxPixelError()<<endl<<
|
---|
1893 | "#MaxPvsRenderError\n" <<renderer->mPvsStat.GetMaxError()<<endl<<
|
---|
1894 | "#ErrorFreeFrames\n" <<renderer->mPvsStat.GetErrorFreeFrames()<<endl<<
|
---|
1895 | "#AvgRenderPvs\n" <<renderer->mPvsStat.GetAvgPvs()<<endl;
|
---|
1896 | }
|
---|
1897 | }
|
---|
1898 |
|
---|
1899 |
|
---|
1900 | void GvsPreprocessor::GenerateImportanceSamples(const VssRay &ray,
|
---|
1901 | const Triangle3 &triangle,
|
---|
1902 | int numSamples,
|
---|
1903 | SimpleRayContainer &simpleRays)
|
---|
1904 | {
|
---|
1905 | const size_t samplesSize = simpleRays.size();
|
---|
1906 |
|
---|
1907 | while (simpleRays.size() < (samplesSize + numSamples))
|
---|
1908 | {
|
---|
1909 | SimpleRay sray;
|
---|
1910 | if (GenerateImportanceSample(ray, triangle, sray))
|
---|
1911 | simpleRays.push_back(sray);
|
---|
1912 | }
|
---|
1913 | }
|
---|
1914 |
|
---|
1915 |
|
---|
1916 | bool GvsPreprocessor::GenerateImportanceSample(const VssRay &ray,
|
---|
1917 | const Triangle3 &triangle,
|
---|
1918 | SimpleRay &sray)
|
---|
1919 | {
|
---|
1920 | Vector3 d = ray.GetDir();
|
---|
1921 |
|
---|
1922 | // Compute right handed coordinate system from direction
|
---|
1923 | Vector3 U, V;
|
---|
1924 |
|
---|
1925 | Vector3 nd = Normalize(d);
|
---|
1926 | nd.RightHandedBase(U, V);
|
---|
1927 |
|
---|
1928 | Vector3 origin = ray.mOrigin;
|
---|
1929 | Vector3 termination = ray.mTermination;
|
---|
1930 |
|
---|
1931 | float rr[2];
|
---|
1932 |
|
---|
1933 | rr[0] = RandomValue(0, 1);
|
---|
1934 | rr[1] = RandomValue(0, 1);
|
---|
1935 |
|
---|
1936 | Vector2 vr2(rr[0], rr[1]);
|
---|
1937 | const float sigma = triangle.GetBoundingBox().Radius() * 5.0f;
|
---|
1938 | Vector2 gaussvec2;
|
---|
1939 |
|
---|
1940 | GaussianOn2D(vr2, sigma, // input
|
---|
1941 | gaussvec2); // output
|
---|
1942 |
|
---|
1943 | const Vector3 shift = gaussvec2.xx * U + gaussvec2.yy * V;
|
---|
1944 |
|
---|
1945 | //cout << "t: " << termination;
|
---|
1946 | termination += shift;
|
---|
1947 | //cout << " new t: " << termination << endl;
|
---|
1948 | Vector3 direction = termination - origin;
|
---|
1949 |
|
---|
1950 | const float len = Magnitude(direction);
|
---|
1951 |
|
---|
1952 | if (len < Limits::Small)
|
---|
1953 | return false;
|
---|
1954 |
|
---|
1955 | direction /= len;
|
---|
1956 |
|
---|
1957 | // $$ jb the pdf is yet not correct for all sampling methods!
|
---|
1958 | const float pdf = 1.0f;
|
---|
1959 | sray = SimpleRay(origin, direction, SamplingStrategy::GVS, pdf);
|
---|
1960 |
|
---|
1961 | return true;
|
---|
1962 | }
|
---|
1963 |
|
---|
1964 |
|
---|
1965 | void GvsPreprocessor::PrepareProbablyVisibleSampling()
|
---|
1966 | {
|
---|
1967 |
|
---|
1968 | // warning: using mailing!
|
---|
1969 | Intersectable::NewMail();
|
---|
1970 |
|
---|
1971 | mProbablyVisibleTriangles.clear();
|
---|
1972 | CollectProbablyVisibleTriangles(mProbablyVisibleTriangles);
|
---|
1973 | }
|
---|
1974 |
|
---|
1975 |
|
---|
1976 | void GvsPreprocessor::CollectProbablyVisibleTriangles(ObjectContainer &triangles)
|
---|
1977 | {
|
---|
1978 | ObjectPvsIterator pit = mCurrentViewCell->GetPvs().GetIterator();
|
---|
1979 |
|
---|
1980 | static ObjectContainer tmpTriangles;
|
---|
1981 |
|
---|
1982 | while (pit.HasMoreEntries())
|
---|
1983 | {
|
---|
1984 | tmpTriangles.clear();
|
---|
1985 |
|
---|
1986 | KdIntersectable *kdObj = static_cast<KdIntersectable *>(pit.Next());
|
---|
1987 | mKdTree->CollectObjectsWithDublicates(kdObj->GetItem(), tmpTriangles);
|
---|
1988 |
|
---|
1989 | ObjectContainer::const_iterator oit, oit_end = tmpTriangles.end();
|
---|
1990 |
|
---|
1991 | for (oit = tmpTriangles.begin(); oit != oit_end; ++ oit)
|
---|
1992 | {
|
---|
1993 | TriangleIntersectable *triObj = static_cast<TriangleIntersectable *>(*oit);
|
---|
1994 |
|
---|
1995 | // find objects which are not yet accounted for yet contained in kd pvs objects
|
---|
1996 | if (!triObj->Mailed() && (triObj->mCounter < ACCOUNTED_OBJECT))
|
---|
1997 | {
|
---|
1998 | triObj->Mail();
|
---|
1999 | triangles.push_back(triObj);
|
---|
2000 | }
|
---|
2001 | }
|
---|
2002 | }
|
---|
2003 | }
|
---|
2004 |
|
---|
2005 |
|
---|
2006 | }
|
---|