source: GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp @ 2691

Revision 2691, 36.5 KB checked in by mattausch, 16 years ago (diff)

fixed several errors

  • Property svn:executable set to *
Line 
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
16
17
18namespace GtpVisibilityPreprocessor
19{
20 
21#define GVS_DEBUG 0
22#define NOT_ACCOUNTED_OBJECT 0
23#define ACCOUNTED_OBJECT 2
24#define SHOW_QT_VISUALIZATION 0
25
26static const float MIN_DIST = 0.001f;
27
28static ObjectContainer myobjects;
29
30
31/** Visualization structure for the GVS algorithm.
32*/
33struct VizStruct
34{
35        Polygon3 *enlargedTriangle;
36        Triangle3 originalTriangle;
37        VssRay *ray;
38};
39
40static vector<VizStruct> vizContainer;
41
42
43
44
45GvsPreprocessor::GvsPreprocessor():
46Preprocessor(),
47mProcessedViewCells(0),
48mCurrentViewCell(NULL),
49mCurrentViewPoint(Vector3(0.0f, 0.0f, 0.0f)),
50mOnlyRandomSampling(false)
51//mOnlyRandomSampling(true)
52{
53        Environment::GetSingleton()->GetIntValue("GvsPreprocessor.totalSamples", mTotalSamples);
54        Environment::GetSingleton()->GetIntValue("GvsPreprocessor.initialSamples", mInitialSamples);
55        Environment::GetSingleton()->GetIntValue("GvsPreprocessor.gvsSamplesPerPass", mGvsSamplesPerPass);
56        Environment::GetSingleton()->GetIntValue("GvsPreprocessor.minContribution", mMinContribution);
57        Environment::GetSingleton()->GetFloatValue("GvsPreprocessor.epsilon", mEps);
58        Environment::GetSingleton()->GetFloatValue("GvsPreprocessor.threshold", mThreshold);   
59        Environment::GetSingleton()->GetBoolValue("GvsPreprocessor.perViewCell", mPerViewCell);
60        Environment::GetSingleton()->GetIntValue("GvsPreprocessor.maxViewCells", mMaxViewCells);
61
62        Environment::GetSingleton()->GetBoolValue("Preprocessor.evaluatePixelError", mEvaluatePixelError);
63
64        Environment::GetSingleton()->GetBoolValue("ViewCells.useKdPvs", mUseKdPvs);
65
66
67        char gvsStatsLog[100];
68        Environment::GetSingleton()->GetStringValue("GvsPreprocessor.stats", gvsStatsLog);
69        mGvsStatsStream.open(gvsStatsLog);
70
71        cout << "number of gvs samples per pass: " << mGvsSamplesPerPass << endl;
72        cout << "number of samples per pass: " << mSamplesPerPass << endl;
73        cout << "only random sampling: " << mOnlyRandomSampling << endl;
74
75        Debug << "Gvs preprocessor options" << endl;
76        Debug << "number of total samples: " << mTotalSamples << endl;
77        Debug << "number of initial samples: " << mInitialSamples << endl;
78        Debug << "threshold: " << mThreshold << endl;
79        Debug << "epsilon: " << mEps << endl;
80        Debug << "stats: " << gvsStatsLog << endl;
81        Debug << "per view cell: " << mPerViewCell << endl;
82        Debug << "max view cells: " << mMaxViewCells << endl;
83        Debug << "min contribution: " << mMinContribution << endl;
84
85        mDistribution = new ViewCellBasedDistribution(*this, NULL);
86
87        mGvsStats.Reset();
88
89        // hack: some generic statistical values that can be read
90        // by an application using the preprocessor
91        for (int i = 0; i < 2; ++ i)
92                mGenericStats[i] = 0;
93}
94
95
96GvsPreprocessor::~GvsPreprocessor()
97{
98        delete mDistribution;
99        ClearRayQueue();
100}
101
102
103void GvsPreprocessor::ClearRayQueue()
104{
105        // clean ray queue
106        while (!mRayQueue.empty())
107        {
108                // handle next ray
109                VssRay *ray = mRayQueue.top();
110                mRayQueue.pop();
111
112                //delete ray;
113        }
114}
115
116
117ViewCell *GvsPreprocessor::NextViewCell()
118{
119        if (mProcessedViewCells == (int)mViewCells.size())
120                return NULL; // no more view cells
121
122        ViewCell *vc = mViewCells[mProcessedViewCells];
123
124   if (!vc->GetMesh())
125                mViewCellsManager->CreateMesh(vc);
126
127        mGvsStats.mViewCellId = vc->GetId();
128
129        Debug << "vc: " << vc->GetId() << endl;
130
131        ++ mProcessedViewCells;
132   
133        return vc;
134}
135
136
137int GvsPreprocessor::CheckDiscontinuity(const VssRay &currentRay,
138                                                                                const Triangle3 &hitTriangle,
139                                                                                const VssRay &oldRay)
140{
141        // the predicted hitpoint: we expect to hit the same mesh again
142        const Vector3 predictedHit = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay);
143
144        const float predictedLen = Magnitude(predictedHit - currentRay.mOrigin);
145        const float len = Magnitude(currentRay.mTermination - currentRay.mOrigin);
146       
147        // distance large => this is likely to be a discontinuity
148#if 1
149        if ((predictedLen - len) > mThreshold)
150#else // rather use relative distance
151        if ((predictedLen / len) > mThreshold)
152#endif
153        {
154                // apply reverse sampling to find the gap
155                VssRay *newRay = ReverseSampling(currentRay, hitTriangle, oldRay);
156
157                if (!newRay)
158                        return 1;
159
160                // set flag for visualization
161                if (0) newRay->mFlags |= VssRay::ReverseSample;
162               
163                // check if ray is not further processed (ray not deleted because using ray pool)
164                HandleRay(newRay);
165               
166                return 1;
167        }
168
169        return 0;
170}
171
172
173void GvsPreprocessor::CountObject(Intersectable *triObj)
174{
175        if ((triObj->mCounter != (NOT_ACCOUNTED_OBJECT + 1)) &&
176                (triObj->mCounter != (ACCOUNTED_OBJECT + 1)))
177        {
178                ++ triObj->mCounter;
179                ++ mGenericStats[1];
180        }
181}
182
183
184void GvsPreprocessor::UpdateStatsForVisualization(KdIntersectable *kdInt)
185{
186        //mViewCellsManager->UpdateStatsForViewCell(mCurrentViewCell, kdInt);
187
188        // count new objects in pvs due to kd node conversion   
189        myobjects.clear();
190        mKdTree->CollectObjects(kdInt->GetItem(), myobjects);
191
192        ObjectContainer::const_iterator oit, oit_end = myobjects.end();
193
194        for (oit = myobjects.begin(); oit != oit_end; ++ oit)
195                CountObject(*oit);
196}       
197
198
199bool GvsPreprocessor::HasContribution(VssRay &ray)
200{
201        if (!ray.mTerminationObject)
202                return false;
203
204        bool result;
205
206        if (!mPerViewCell)
207        {
208                // store the rays + the intersected view cells
209                const bool storeViewCells = false; //GVS_DEBUG;
210
211                mViewCellsManager->ComputeSampleContribution(ray,
212                                                                                                         true,
213                                                                                                         storeViewCells,
214                                                                                                         true);
215
216                result = ray.mPvsContribution > 0;
217        }
218        else // original per view cell gvs
219        {
220                Intersectable *obj = ray.mTerminationObject;
221
222                // counter < 2 => not accounted for yet
223                // test of triangle was accounted for yet
224                result = AddTriangleObject(obj);
225               
226                if (mUseKdPvs && (1 || result))
227                {
228                        // exchange the triangle with the node in the pvs for kd pvs
229                        KdNode *node = mKdTree->GetPvsNode(ray.mTermination);
230
231                        //KdNode *node = mKdTree->GetPvsNodeCheck(ray.mTermination, obj);
232                        //if (!node) cerr << "e: " << obj->GetBox() << " " << ray.mTermination << endl; else
233                        if (!node->Mailed())
234                        {
235                                //cout<<"o";
236                                // add to pvs
237                                node->Mail();
238                                KdIntersectable *kdInt = mKdTree->GetOrCreateKdIntersectable(node);
239                                mCurrentViewCell->GetPvs().AddSampleDirty(kdInt, 1.0f);
240
241                                if (SHOW_QT_VISUALIZATION) UpdateStatsForVisualization(kdInt); 
242                        }
243                }
244        }
245
246        return result;
247}
248
249
250bool GvsPreprocessor::HandleRay(VssRay *vssRay)
251{
252        if (!HasContribution(*vssRay))
253                return false;
254
255        if (0 && GVS_DEBUG)
256                mVssRays.push_back(new VssRay(*vssRay));
257
258        // add new ray to ray queue
259        mRayQueue.push(vssRay);
260
261        ++ mGvsStats.mTotalContribution;
262
263        return true;
264}
265
266
267/** Creates 3 new vertices for triangle vertex with specified index.
268*/
269void GvsPreprocessor::CreateDisplacedVertices(VertexContainer &vertices,
270                                                                                          const Triangle3 &hitTriangle,
271                                                                                          const VssRay &ray,
272                                                                                          const int index) const
273{
274        const int indexU = (index + 1) % 3;
275        const int indexL = (index == 0) ? 2 : index - 1;
276
277        const Vector3 a = hitTriangle.mVertices[index] - ray.GetOrigin();
278        const Vector3 b = hitTriangle.mVertices[indexU] - hitTriangle.mVertices[index];
279        const Vector3 c = hitTriangle.mVertices[index] - hitTriangle.mVertices[indexL];
280       
281        const float len = Magnitude(a);
282       
283        const Vector3 dir1 = Normalize(CrossProd(a, b)); //N((pi-xp)×(pi+1- pi));
284        const Vector3 dir2 = Normalize(CrossProd(a, c)); // N((pi-xp)×(pi- pi-1))
285        const Vector3 dir3 = DotProd(dir2, dir1) > 0 ? // N((pi-xp)×di,i-1+di,i+1×(pi-xp))
286                Normalize(dir2 + dir1) : Normalize(CrossProd(a, dir1) + CrossProd(dir2, a));
287
288        // compute the new three hit points
289        // pi, i + 1:  pi+ e·|pi-xp|·di, j
290        const Vector3 pt1 = hitTriangle.mVertices[index] + mEps * len * dir1;
291        // pi, i - 1:  pi+ e·|pi-xp|·di, j
292    const Vector3 pt2 = hitTriangle.mVertices[index] + mEps * len * dir2;
293        // pi, i:  pi+ e·|pi-xp|·di, j
294        const Vector3 pt3 = hitTriangle.mVertices[index] + mEps * len * dir3;
295       
296        vertices.push_back(pt2);
297        vertices.push_back(pt3);
298        vertices.push_back(pt1);
299}
300
301
302void GvsPreprocessor::EnlargeTriangle(VertexContainer &vertices,
303                                                                          const Triangle3 &hitTriangle,
304                                                                          const VssRay &ray) const
305{
306        CreateDisplacedVertices(vertices, hitTriangle, ray, 0);
307        CreateDisplacedVertices(vertices, hitTriangle, ray, 1);
308        CreateDisplacedVertices(vertices, hitTriangle, ray, 2);
309}
310
311
312Vector3 GvsPreprocessor::CalcPredictedHitPoint(const VssRay &newRay,
313                                                                                           const Triangle3 &hitTriangle,
314                                                                                           const VssRay &oldRay) const
315{
316        // find the intersection of the plane induced by the
317        // hit triangle with the new ray
318        Plane3 plane(hitTriangle.GetNormal(), hitTriangle.mVertices[0]);
319
320        const Vector3 hitPt =
321                plane.FindIntersection(newRay.mTermination, newRay.mOrigin);
322       
323        return hitPt;
324}
325
326
327static bool EqualVisibility(const VssRay &a, const VssRay &b)
328{
329        return a.mTerminationObject == b.mTerminationObject;
330}
331
332
333int GvsPreprocessor::SubdivideEdge(const Triangle3 &hitTriangle,
334                                                                   const Vector3 &p1,
335                                                                   const Vector3 &p2,
336                                                                   const VssRay &ray1,
337                                                                   const VssRay &ray2,
338                                                                   const VssRay &oldRay)
339{
340        //cout <<"y"<<Magnitude(p1 - p2) << " ";
341        int castRays = 0;
342
343        // cast reverse rays if necessary
344        castRays += CheckDiscontinuity(ray1, hitTriangle, oldRay);
345        castRays += CheckDiscontinuity(ray2, hitTriangle, oldRay);
346
347        if (EqualVisibility(ray1, ray2) || (SqrMagnitude(p1 - p2) <= MIN_DIST))
348        {
349                return castRays;
350        }
351       
352        // the new subdivision point
353        const Vector3 p = (p1 + p2) * 0.5f;
354        //cout << "p: " << p << " " << p1 << " " << p2 << endl;
355        // cast ray into the new point
356        SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin, SamplingStrategy::GVS, 1.0f);
357
358        VssRay *newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox(), !mPerViewCell);
359       
360        ++ castRays;
361
362        if (!newRay) return castRays;
363
364        //newRay->mFlags |= VssRay::BorderSample;
365
366        // add new ray to queue
367        const bool enqueued = HandleRay(newRay);
368
369        // subdivide further
370        castRays += SubdivideEdge(hitTriangle, p1, p, ray1, *newRay, oldRay);
371        castRays += SubdivideEdge(hitTriangle, p, p2, *newRay, ray2, oldRay);
372
373        // this ray will not be further processed
374        //if (!enqueued) delete newRay;
375
376        return castRays;
377}
378
379
380int GvsPreprocessor::AdaptiveBorderSampling(const VssRay &currentRay)
381{
382        Intersectable *tObj = currentRay.mTerminationObject;
383        // q matt: can this be possible
384        if (!tObj) return 0;
385
386        Triangle3 hitTriangle;
387
388        // other types not implemented yet
389        if (tObj->Type() == Intersectable::TRIANGLE_INTERSECTABLE)
390                hitTriangle = static_cast<TriangleIntersectable *>(tObj)->GetItem();
391        else
392                cout << "border sampling: " << Intersectable::GetTypeName(tObj) << " not yet implemented" << endl;
393
394        //cout << "type: " << Intersectable::GetTypeName(tObj) << endl;
395
396        VertexContainer enlargedTriangle;
397       
398        /// create 3 new hit points for each vertex
399        EnlargeTriangle(enlargedTriangle, hitTriangle, currentRay);
400       
401        /// create rays from sample points and handle them
402        SimpleRayContainer simpleRays;
403        simpleRays.reserve(9);
404
405        VertexContainer::const_iterator vit, vit_end = enlargedTriangle.end();
406
407        for (vit = enlargedTriangle.begin(); vit != vit_end; ++ vit)
408        {
409                const Vector3 rayDir = (*vit) - currentRay.GetOrigin();
410
411                SimpleRay sr(currentRay.GetOrigin(), rayDir, SamplingStrategy::GVS, 1.0f);
412                simpleRays.AddRay(sr); 
413        }
414
415        if (0)
416        {
417                // visualize enlarged triangles
418                VizStruct dummy;
419                dummy.enlargedTriangle = new Polygon3(enlargedTriangle);
420                dummy.originalTriangle = hitTriangle;
421                vizContainer.push_back(dummy);
422        }
423
424        // cast rays to triangle vertices and determine visibility
425        VssRayContainer vssRays;
426
427        // don't cast double rays as we need only the forward rays
428        const bool castDoubleRays = !mPerViewCell;
429        // cannot prune invalid rays because we have to compare adjacent  rays.
430        const bool pruneInvalidRays = false;
431
432
433        //////////
434        //-- fill up simple rays with random rays so we can cast 16
435
436        //const int numRandomRays = 0;
437        const int numRandomRays = 16 - (int)simpleRays.size();
438
439        GenerateRays(numRandomRays, *mDistribution, simpleRays);
440
441
442        /////////////////////
443
444        // keep origin for per view cell sampling
445        CastRays(simpleRays, vssRays, castDoubleRays, pruneInvalidRays);
446
447        const int numBorderSamples = (int)vssRays.size() - numRandomRays;
448
449#if 0
450        // set flags
451        VssRayContainer::const_iterator rit, rit_end = vssRays.end();
452        for (rit = vssRays.begin(); rit != rit_end; ++ rit, ++ i)
453                (*rit)->mFlags |= VssRay::BorderSample;
454#endif
455
456        int castRays = (int)simpleRays.size();
457
458        VssRayContainer invalidSamples;
459
460        // handle rays
461        EnqueueRays(vssRays, invalidSamples);
462
463    // recursivly subdivide each edge
464        for (int i = 0; i < numBorderSamples; ++ i)
465        {
466                castRays += SubdivideEdge(hitTriangle,
467                                                                  enlargedTriangle[i],
468                                                                  enlargedTriangle[(i + 1) % numBorderSamples],
469                                                                  *vssRays[i],
470                                                                  *vssRays[(i + 1) % numBorderSamples],
471                                                                  currentRay);
472        }
473       
474        mGvsStats.mBorderSamples += castRays;
475
476        //CLEAR_CONTAINER(invalidSamples);
477       
478        //cout << "here3 cast rays: " << castRays << endl;
479        return castRays;
480}
481
482
483bool GvsPreprocessor::GetPassingPoint(const VssRay &currentRay,
484                                                                          const Triangle3 &occluder,
485                                                                          const VssRay &oldRay,
486                                                                          Vector3 &newPoint) const
487{
488        //-- The plane p = (xp, hit(x), hit(xold)) is intersected
489        //-- with the newly found occluder (xold is the previous ray from
490        //-- which x was generated). On the intersecting line, we select a point
491        //-- pnew which lies just outside of the new triangle so the ray
492        //-- just passes through the gap
493
494        const Plane3 plane(currentRay.GetOrigin(),
495                                           currentRay.GetTermination(),
496                                           oldRay.GetTermination());
497       
498        Vector3 pt1, pt2;
499
500        const bool intersects = occluder.GetPlaneIntersection(plane, pt1, pt2);
501
502        if (!intersects)
503        {
504                //cerr << "big error!! no intersection " << pt1 << " " << pt2 << endl;
505                return false;
506        }
507
508        // get the intersection point on the old ray
509        const Plane3 triPlane(occluder.GetNormal(), occluder.mVertices[0]);
510
511        const float t = triPlane.FindT(oldRay.mOrigin, oldRay.mTermination);
512        const Vector3 pt3 = oldRay.mOrigin + t * (oldRay.mTermination - oldRay.mOrigin);
513
514        // Evaluate new hitpoint just outside the triangle
515        const float eps = mEps;
516
517        // the point is chosen to be on the side closer to the original ray
518        if (Distance(pt1, pt3) < Distance(pt2, pt3))
519                newPoint = pt1 + eps * (pt1 - pt2);
520        else
521                newPoint = pt2 + eps * (pt2 - pt1);
522
523        //cout << "passing point: " << newPoint << endl << endl;
524        return true;
525}
526
527
528VssRay *GvsPreprocessor::ReverseSampling(const VssRay &currentRay,
529                                                                                 const Triangle3 &hitTriangle,
530                                                                                 const VssRay &oldRay)
531{
532        // get triangle occluding the path to the hit mesh
533        Triangle3 occluder;
534        Intersectable *tObj = currentRay.mTerminationObject;
535
536        // q: why can this happen?
537        if (!tObj)
538                return NULL;
539
540        // other types not implemented yet
541        if (tObj->Type() == Intersectable::TRIANGLE_INTERSECTABLE)
542        {
543                occluder = static_cast<TriangleIntersectable *>(tObj)->GetItem();
544        }
545        else
546        {
547                cout << "reverse sampling: " << tObj->Type() << " not yet implemented" << endl;
548        }
549        // get a point which is passing just outside of the occluder
550    Vector3 newPoint;
551
552        // why is there sometimes no intersecton found?
553        if (!GetPassingPoint(currentRay, occluder, oldRay, newPoint))
554                return NULL;
555
556        const Vector3 predicted = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay);
557
558        Vector3 newDir, newOrigin;
559
560        //-- Construct the mutated ray with xnew,
561        //-- dir = predicted(x)- pnew as direction vector
562        newDir = predicted - newPoint;
563
564        // take xnew, p = intersect(viewcell, line(pnew, predicted(x)) as origin ?
565        // difficult to say!!
566        const float offset = 0.5f;
567        newOrigin = newPoint - newDir * offset;
568       
569        //////////////
570        //-- for per view cell sampling, we must check for intersection
571        //-- with the current view cell
572
573    if (mPerViewCell)
574        {
575                // send ray to view cell
576                static Ray ray;
577                ray.Clear();
578                ray.Init(newOrigin, -newDir, Ray::LOCAL_RAY);
579               
580                //cout << "z";
581                // check if ray intersects view cell
582                if (!mCurrentViewCell->CastRay(ray))
583                        return NULL;
584
585                Ray::Intersection &hit = ray.intersections[0];
586       
587                //cout << "q";
588                // the ray starts from the view cell
589                newOrigin = ray.Extrap(hit.mT);
590        }
591
592        const SimpleRay simpleRay(newOrigin, newDir, SamplingStrategy::GVS, 1.0f);
593
594        VssRay *reverseRay =
595                mRayCaster->CastRay(simpleRay, mViewCellsManager->GetViewSpaceBox(), !mPerViewCell);
596
597    ++ mGvsStats.mReverseSamples;
598
599        return reverseRay;
600}
601
602
603int GvsPreprocessor::CastInitialSamples(int numSamples)
604{       
605        const long startTime = GetTime();
606
607        // generate simple rays
608        SimpleRayContainer simpleRays;
609       
610        ViewCellBorderBasedDistribution vcStrat(*this, mCurrentViewCell);
611    GenerateRays(numSamples, *mDistribution, simpleRays);
612
613        //cout << "sr: " << simpleRays.size() << endl;
614        // generate vss rays
615        VssRayContainer samples;
616       
617        const bool castDoubleRays = !mPerViewCell;
618        const bool pruneInvalidRays = true;
619       
620        CastRays(simpleRays, samples, castDoubleRays, pruneInvalidRays);
621       
622        VssRayContainer invalidSamples;
623
624        // add to ray queue
625        EnqueueRays(samples, invalidSamples);
626
627        //CLEAR_CONTAINER(invalidSamples);
628        //Debug << "generated " <<  numSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
629        return (int)simpleRays.size();
630}
631
632
633void GvsPreprocessor::EnqueueRays(VssRayContainer &samples, VssRayContainer &invalidSamples)
634{
635        // add samples to ray queue
636        VssRayContainer::const_iterator vit, vit_end = samples.end();
637        for (vit = samples.begin(); vit != vit_end; ++ vit)
638        {
639                VssRay *ray = *vit;
640
641                HandleRay(ray);
642                //if (!HandleRay(ray)) invalidSamples.push_back(ray);
643        }
644}
645
646
647int GvsPreprocessor::ProcessQueue()
648{
649        ++ mGvsStats.mGvsPass;
650
651        int castSamples = 0;
652
653        while (!mRayQueue.empty())//&& (mGvsStats.mTotalSamples + castSamples < mTotalSamples) )
654        {
655                // handle next ray
656                VssRay *ray = mRayQueue.top();
657                mRayQueue.pop();
658               
659                const int newSamples = AdaptiveBorderSampling(*ray);
660
661                castSamples += newSamples;
662                // note: don't have to delete because handled by ray pool
663        }
664
665        /*if (mRayCaster->mVssRayPool.mIndex > mSamplesPerPass)
666        {
667                cout << "warning: new samples: " << castSamples << " " << "queue: "  << (int)mRayQueue.size() << endl;
668                Debug << "warning: new samples: " << castSamples << " " << "queue: "  << (int)mRayQueue.size() << endl;
669        }*/
670
671        return castSamples;
672}
673
674
675void ExportVssRays(Exporter *exporter, const VssRayContainer &vssRays)
676{
677        VssRayContainer vcRays, vcRays2, vcRays3;
678
679        VssRayContainer::const_iterator rit, rit_end = vssRays.end();
680
681        // prepare some rays for output
682        for (rit = vssRays.begin(); rit != rit_end; ++ rit)
683        {
684                //const float p = RandomValue(0.0f, (float)vssRays.size());
685
686                if (1)//(p < raysOut)
687                {
688                        if ((*rit)->mFlags & VssRay::BorderSample)
689                        {
690                                vcRays.push_back(*rit);
691                        }
692                        else if ((*rit)->mFlags & VssRay::ReverseSample)
693                        {
694                                vcRays2.push_back(*rit);
695                        }
696                        else
697                        {
698                                vcRays3.push_back(*rit);
699                        }       
700                }
701        }
702
703        exporter->ExportRays(vcRays, RgbColor(1, 0, 0));
704        exporter->ExportRays(vcRays2, RgbColor(0, 1, 0));
705        exporter->ExportRays(vcRays3, RgbColor(1, 1, 1));
706}
707
708
709void GvsPreprocessor::VisualizeViewCell(const ObjectContainer &objects)
710{
711    Intersectable::NewMail();
712        Material m;
713       
714        char str[64]; sprintf(str, "pass%06d.wrl", mProcessedViewCells);
715
716        Exporter *exporter = Exporter::GetExporter(str);
717        if (!exporter)
718                return;
719
720        ObjectContainer::const_iterator oit, oit_end = objects.end();
721
722        for (oit = objects.begin(); oit != oit_end; ++ oit)
723        {
724                Intersectable *intersect = *oit;
725               
726                m = RandomMaterial();
727                exporter->SetForcedMaterial(m);
728                exporter->ExportIntersectable(intersect);
729        }
730
731        cout << "vssrays: " << (int)mVssRays.size() << endl;
732        ExportVssRays(exporter, mVssRays);
733
734
735        /////////////////
736        //-- export view cell geometry
737
738        //exporter->SetWireframe();
739
740        m.mDiffuseColor = RgbColor(0, 1, 0);
741        exporter->SetForcedMaterial(m);
742
743        //mViewCellsManager->ExportViewCellGeometry(exporter, vc, NULL, NULL);
744        //mViewCellsManager->ExportViewCellGeometry(exporter, mCurrentViewCell, NULL, NULL);
745
746        AxisAlignedBox3 bbox = mCurrentViewCell->GetMesh()->mBox;
747        exporter->ExportBox(bbox);
748        //exporter->SetFilled();
749
750        delete exporter;
751}
752
753
754void GvsPreprocessor::VisualizeViewCells()
755{
756        char str[64]; sprintf(str, "tmp/pass%06d_%04d-", mProcessedViewCells, mPass);
757                       
758        // visualization
759        if (mGvsStats.mPassContribution > 0)
760        {
761                const bool exportRays = true;
762                const bool exportPvs = true;
763
764                mViewCellsManager->ExportSingleViewCells(mObjects,
765                                                                                                 10,
766                                                                                                 false,
767                                                                                                 exportPvs,
768                                                                                                 exportRays,
769                                                                                                 1000,
770                                                                                                 str);
771        }
772
773        // remove pass samples
774        ViewCellContainer::const_iterator vit, vit_end = mViewCellsManager->GetViewCells().end();
775
776        for (vit = mViewCellsManager->GetViewCells().begin(); vit != vit_end; ++ vit)
777        {
778                (*vit)->DelRayRefs();
779        }
780}
781
782
783void GvsPreprocessor::CompileViewCellsFromPointList()
784{
785        ViewCell::NewMail();
786
787        // Receive list of view cells from view cells manager
788        ViewCellPointsList *vcPoints = mViewCellsManager->GetViewCellPointsList();
789
790        vector<ViewCellPoints *>::const_iterator vit, vit_end = vcPoints->end();
791
792        for (vit = vcPoints->begin(); vit != vit_end; ++ vit)
793        {
794                ViewCellPoints *vp = *vit;
795
796                if (vp->first) // view cell  specified
797                {
798                        ViewCell *viewCell = vp->first;
799
800                        if (!viewCell->Mailed())
801                        {
802                                viewCell->Mail();
803                                mViewCells.push_back(viewCell);
804
805                                if (mViewCells.size() >= mMaxViewCells)
806                                        break;
807                        }
808                }
809                else // no view cell specified => compute view cells using view point
810                {
811                        SimpleRayContainer::const_iterator rit, rit_end = vp->second.end();
812
813                        for (rit = vp->second.begin(); rit != rit_end; ++ rit)
814                        {
815                                SimpleRay ray = *rit;
816
817                                ViewCell *viewCell = mViewCellsManager->GetViewCell(ray.mOrigin);
818
819                                if (viewCell && !viewCell->Mailed())
820                                {
821                                        viewCell->Mail();
822                                        mViewCells.push_back(viewCell);
823
824                                        if (mViewCells.size() >= mMaxViewCells)
825                                                break;
826                                }
827                        }
828                }
829        }
830}
831
832
833void GvsPreprocessor::CompileViewCellsList()
834{
835        if (!mViewCellsManager->GetViewCellPointsList()->empty())
836        {
837                cout << "processing view point list" << endl;
838                CompileViewCellsFromPointList();
839        }
840        else
841        {
842                ViewCell::NewMail();
843
844                while ((int)mViewCells.size() < mMaxViewCells)
845                {
846                        const int tries = 10000;
847                        int i = 0;
848
849                        for (i = 0; i < tries; ++ i)
850                        {
851                                const int idx = (int)RandomValue(0.0f, (float)mViewCellsManager->GetNumViewCells() - 0.5f);
852
853                                ViewCell *viewCell = mViewCellsManager->GetViewCell(idx);
854
855                                if (!viewCell->Mailed())
856                                {
857                                        viewCell->Mail();
858                                        break;
859                                }
860
861                                mViewCells.push_back(viewCell);
862                        }
863
864                        if (i == tries)
865                        {
866                                cerr << "big error! no view cell found" << endl;
867                                break;
868                        }
869                }
870        }
871
872        cout << "\ncomputing list of " << mViewCells.size() << " view cells" << endl;
873}
874
875
876void GvsPreprocessor::IntersectWithViewCell()
877{
878        AxisAlignedBox3 box = mCurrentViewCell->GetBox();
879
880        int oldTrianglePvs = (int)mTrianglePvs.size();
881        int newKdObj = 0;
882
883        // compute pvs kd nodes that intersect view cell
884        ObjectContainer kdobjects;
885
886        // find intersecting objects not in pvs (i.e., only unmailed)
887        mKdTree->CollectKdObjects(box, kdobjects);
888
889        ObjectContainer pvsKdObjects;
890
891        ObjectContainer::const_iterator oit, oit_end = kdobjects.end();
892
893        for (oit = kdobjects.begin(); oit != oit_end; ++ oit)
894        {
895        KdIntersectable *kdInt = static_cast<KdIntersectable *>(*oit);
896       
897                myobjects.clear();
898                mKdTree->CollectObjectsWithDublicates(kdInt->GetItem(), myobjects);
899
900                // account for kd object pvs
901                bool addkdobj = false;
902
903                ObjectContainer::const_iterator oit, oit_end = myobjects.end();
904
905                for (oit = myobjects.begin(); oit != oit_end; ++ oit)
906                {
907                        TriangleIntersectable *triObj = static_cast<TriangleIntersectable *>(*oit);
908             
909                        // test if the triangle itself intersects
910                        if (box.Intersects(triObj->GetItem()))
911                                addkdobj = AddTriangleObject(triObj);
912                }
913               
914                // add node to kd pvs
915                if (1 && addkdobj)
916                {
917                        ++ newKdObj;
918                        mCurrentViewCell->GetPvs().AddSampleDirty(kdInt, 1.0f);
919                        //mCurrentViewCell->GetPvs().AddSampleDirtyCheck(kdInt, 1.0f);
920                        if (SHOW_QT_VISUALIZATION) UpdateStatsForVisualization(kdInt);
921                }
922        }
923
924        cout << "added " << (int)mTrianglePvs.size() - oldTrianglePvs << " triangles (" << newKdObj << " objects) by intersection" << endl;
925}
926
927
928void GvsPreprocessor::PerViewCellComputation()
929{
930        while (mCurrentViewCell = NextViewCell())
931        {
932                // hack: reset counters
933                ObjectContainer::const_iterator oit, oit_end = mObjects.end();
934
935                for (oit = mObjects.begin(); oit != oit_end; ++ oit)
936                        (*oit)->mCounter = NOT_ACCOUNTED_OBJECT;
937
938                mDistribution->SetViewCell(mCurrentViewCell);
939        ComputeViewCell();
940        }
941}
942
943
944void GvsPreprocessor::PerViewCellComputation2()
945{
946        while (1)
947        {
948                if (!mRendererWidget)
949                        continue;
950
951        mCurrentViewCell = mViewCellsManager->GetViewCell(mRendererWidget->GetViewPoint());
952
953                // no valid view cell or view cell already computed
954                if (!mCurrentViewCell || !mCurrentViewCell->GetPvs().Empty() || !mRendererWidget->mComputeGVS)
955                        continue;
956
957                mRendererWidget->mComputeGVS = false;
958                // hack: reset counters
959                ObjectContainer::const_iterator oit, oit_end = mObjects.end();
960
961                for (oit = mObjects.begin(); oit != oit_end; ++ oit)
962                        (*oit)->mCounter = NOT_ACCOUNTED_OBJECT;
963
964                ComputeViewCell();
965                ++ mProcessedViewCells;
966        }
967}
968
969
970void GvsPreprocessor::StorePvs(const ObjectContainer &objectPvs)
971{
972        ObjectContainer::const_iterator oit, oit_end = objectPvs.end();
973
974        for (oit = objectPvs.begin(); oit != oit_end; ++ oit)
975        {
976                mCurrentViewCell->GetPvs().AddSample(*oit, 1);
977        }
978}
979
980
981void GvsPreprocessor::UpdatePvs(ViewCell *currentViewCell)
982{
983        ObjectPvs newPvs;
984        BvhLeaf::NewMail();
985
986        ObjectPvsIterator pit = currentViewCell->GetPvs().GetIterator();
987
988        // output PVS of view cell
989        while (pit.HasMoreEntries())
990        {               
991                Intersectable *intersect = pit.Next();
992
993                BvhLeaf *bv = intersect->mBvhLeaf;
994
995                if (!bv || bv->Mailed())
996                        continue;
997               
998                bv->Mail();
999
1000                //m.mDiffuseColor = RgbColor(1, 0, 0);
1001                newPvs.AddSampleDirty(bv, 1.0f);
1002        }
1003
1004        newPvs.SimpleSort();
1005
1006        currentViewCell->SetPvs(newPvs);
1007}
1008
1009 
1010void GvsPreprocessor::GetObjectPvs(ObjectContainer &objectPvs) const
1011{
1012        objectPvs.reserve((int)mTrianglePvs.size());
1013
1014        BvhLeaf::NewMail();
1015
1016        ObjectContainer::const_iterator oit, oit_end = mTrianglePvs.end();
1017
1018        for (oit = mTrianglePvs.begin(); oit != oit_end; ++ oit)
1019        {
1020                Intersectable *intersect = *oit;
1021       
1022                BvhLeaf *bv = intersect->mBvhLeaf;
1023
1024                // hack: reset counter
1025                (*oit)->mCounter = NOT_ACCOUNTED_OBJECT;
1026
1027                if (!bv || bv->Mailed())
1028                        continue;
1029
1030                bv->Mail();
1031                objectPvs.push_back(bv);
1032        }
1033}
1034
1035
1036void GvsPreprocessor::GlobalComputation()
1037{
1038        int passSamples = 0;
1039        int oldContribution = 0;
1040
1041        while (mGvsStats.mTotalSamples < mTotalSamples)
1042        {
1043                mRayCaster->InitPass();
1044
1045                // Ray queue empty =>
1046                // cast a number of uniform samples to fill ray queue
1047                int newSamples = CastInitialSamples(mInitialSamples);
1048
1049                if (!mOnlyRandomSampling)
1050                        newSamples += ProcessQueue();
1051
1052                passSamples += newSamples;
1053                mGvsStats.mTotalSamples += newSamples;
1054
1055                if (passSamples % (mGvsSamplesPerPass + 1) == mGvsSamplesPerPass)
1056                {
1057                        ++ mPass;
1058
1059                        mGvsStats.mPassContribution = mGvsStats.mTotalContribution - oldContribution;
1060
1061                        ////////
1062                        //-- stats
1063
1064                        //cout << "\nPass " << mPass << " #samples: " << mGvsStats.mTotalSamples << " of " << mTotalSamples << endl;
1065                        mGvsStats.mPass = mPass;
1066                        mGvsStats.Stop();
1067                        mGvsStats.Print(mGvsStatsStream);
1068
1069                        // reset
1070                        oldContribution = mGvsStats.mTotalContribution;
1071                        mGvsStats.mPassContribution = 0;
1072                        passSamples = 0;
1073
1074                        if (GVS_DEBUG)
1075                                VisualizeViewCells();
1076                }
1077        }
1078}
1079
1080
1081bool GvsPreprocessor::ComputeVisibility()
1082{
1083        cout << "Gvs Preprocessor started\n" << flush;
1084        const long startTime = GetTime();
1085
1086        //Randomize(0);
1087        mGvsStats.Reset();
1088        mGvsStats.Start();
1089
1090        if (!mLoadViewCells)
1091        {       
1092                /// construct the view cells from the scratch
1093                ConstructViewCells();
1094                // reset pvs already gathered during view cells construction
1095                mViewCellsManager->ResetPvs();
1096                cout << "finished view cell construction" << endl;
1097        }
1098
1099        if (mPerViewCell)
1100        {
1101#if 1
1102                // provide list of view cells to compute
1103                CompileViewCellsList();
1104
1105                // start per view cell gvs
1106                PerViewCellComputation();
1107#else
1108                PerViewCellComputation2();
1109
1110#endif
1111        }
1112        else
1113        {
1114                GlobalComputation();
1115        }
1116
1117        cout << "cast " << mGvsStats.mTotalSamples / (1e3f * TimeDiff(startTime, GetTime())) << "M single rays/s" << endl;
1118
1119        if (GVS_DEBUG)
1120        {
1121                Visualize();
1122                CLEAR_CONTAINER(mVssRays);
1123        }
1124       
1125        // export the preprocessed information to a file
1126        if (0 && mExportVisibility)
1127        {
1128                ExportPreprocessedData(mVisibilityFileName);
1129        }
1130       
1131        // compute the pixel error of this visibility solution
1132        if (mEvaluatePixelError)
1133        {
1134                ComputeRenderError();
1135        }
1136
1137        return true;
1138}
1139
1140
1141void GvsPreprocessor::DeterminePvsObjects(VssRayContainer &rays)
1142{
1143        // store triangle directly
1144        mViewCellsManager->DeterminePvsObjects(rays, true);
1145}
1146
1147
1148void GvsPreprocessor::Visualize()
1149{
1150        Exporter *exporter = Exporter::GetExporter("gvs.wrl");
1151
1152        if (!exporter)
1153                return;
1154       
1155        vector<VizStruct>::const_iterator vit, vit_end = vizContainer.end();
1156       
1157        for (vit = vizContainer.begin(); vit != vit_end; ++ vit)
1158        {
1159                exporter->SetWireframe();
1160                exporter->ExportPolygon((*vit).enlargedTriangle);
1161                //Material m;
1162                exporter->SetFilled();
1163                Polygon3 poly = Polygon3((*vit).originalTriangle);
1164                exporter->ExportPolygon(&poly);
1165        }
1166
1167        VssRayContainer::const_iterator rit, rit_end = mVssRays.end();
1168
1169        for (rit = mVssRays.begin(); rit != rit_end; ++ rit)
1170        {
1171                Intersectable *obj = (*rit)->mTerminationObject;
1172                exporter->ExportIntersectable(obj);
1173        }
1174
1175        ExportVssRays(exporter, mVssRays);
1176       
1177        delete exporter;
1178}
1179
1180
1181void GvsStatistics::Print(ostream &app) const
1182{
1183        app << "#ViewCells\n" << mViewCells << endl;
1184        app << "#Id\n" << mViewCellId << endl;
1185        app << "#Time\n" << mTimePerViewCell << endl;;
1186        app << "#TriPvs\n" << mTrianglePvs << endl;
1187        app << "#ObjectPvs\n" << mPerViewCellPvs << endl;
1188        app << "#UpdatedPvs\n" << (int)mPvsCost << endl;
1189
1190        app << "#PerViewCellSamples\n" << mPerViewCellSamples << endl;
1191        app << "#RaysPerSec\n" << RaysPerSec() << endl;
1192       
1193        app << "#TotalPvs\n" << mTotalPvs << endl;
1194        app << "#TotalTime\n" << mTotalTime << endl;
1195        app << "#TotalSamples\n" << mTotalSamples << endl;
1196
1197        app << "#TotalTrianglePvs\n" << mTotalTrianglePvs << endl;
1198       
1199        if (0)
1200        {
1201                app << "#ReverseSamples\n" << mReverseSamples << endl;
1202                app << "#BorderSamples\n" << mBorderSamples << endl;
1203
1204                app << "#Pass\n" << mPass << endl;
1205                app << "#ScDiff\n" << mPassContribution << endl;
1206                app << "#GvsRuns\n" << mGvsPass << endl;       
1207
1208                app     << "#SamplesContri\n" << mTotalContribution << endl;
1209        }
1210
1211        app << endl;
1212}
1213
1214
1215void GvsPreprocessor::ComputeViewCell()
1216{
1217        mCurrentViewCell->GetMesh()->ComputeBoundingBox();
1218
1219        KdNode::NewMail();
1220
1221        const long startTime = GetTime();
1222
1223        cout << "\n***********************\n"
1224                << "computing view cell " << mProcessedViewCells
1225                << " (id: " << mCurrentViewCell->GetId() << ")" << endl;
1226        cout << "bb: " << mCurrentViewCell->GetBox() << endl;
1227
1228        mGvsStats.mPerViewCellSamples = 0;
1229
1230        int oldContribution = mGvsStats.mTotalContribution;
1231        int passSamples = 0;
1232
1233        for (int i = 0; i < 0; ++ i)
1234                mGenericStats[i] = 0;
1235
1236        while (1)
1237        {
1238                int oldPvsSize = mCurrentViewCell->GetPvs().GetSize();
1239
1240                mRayCaster->InitPass();
1241
1242                // Ray queue empty =>
1243                // cast a number of uniform samples to fill ray queue
1244                int newSamples = CastInitialSamples(mInitialSamples);
1245
1246                if (!mOnlyRandomSampling)
1247                {
1248                        int samplesPerRun = ProcessQueue();
1249                        newSamples += samplesPerRun;
1250                        //if (samplesPerRun > 0) cout << "spr: " << samplesPerRun << " ";
1251                }
1252
1253                passSamples += newSamples;
1254        mGvsStats.mPerViewCellSamples += newSamples;
1255
1256                if (passSamples >= mGvsSamplesPerPass)
1257                {
1258                        if (GVS_DEBUG) VisualizeViewCell(mTrianglePvs);
1259
1260                        //const bool convertPerPass = true;
1261                        const bool convertPerPass = false;
1262
1263                        if (convertPerPass)
1264                        {       
1265                                int newObjects = ConvertObjectPvs();
1266
1267                                cout << "added " << newObjects << " triangles to triangle pvs" << endl;
1268                                mGvsStats.mTotalContribution += newObjects;
1269                        }
1270
1271                        ++ mPass;
1272                        mGvsStats.mPassContribution = mGvsStats.mTotalContribution - oldContribution;
1273
1274
1275                        ////////
1276                        //-- stats
1277
1278                        mGvsStats.mPass = mPass;
1279
1280                        cout << "\nPass " << mPass << " #samples: " << mGvsStats.mPerViewCellSamples << endl;
1281                        cout << "contribution=" << mGvsStats.mPassContribution << " (of " << mMinContribution << ")" << endl;
1282                        cout << "obj contri=" << mCurrentViewCell->GetPvs().GetSize() - oldPvsSize << " (of " << mMinContribution << ")" << endl;
1283
1284                        // termination criterium
1285                        if (mGvsStats.mPassContribution < mMinContribution)
1286                                break;
1287
1288                        // reset
1289                        oldContribution = mGvsStats.mTotalContribution;
1290                        mGvsStats.mPassContribution = 0;
1291                        passSamples = 0;
1292                }
1293        }
1294       
1295        // at last compute objects that directly intersect view cell
1296        IntersectWithViewCell();
1297
1298               
1299        ////////
1300        //-- stats
1301
1302        // timing
1303        mGvsStats.mTimePerViewCell = TimeDiff(startTime, GetTime()) * 1e-3f;
1304
1305        ComputeStats();
1306
1307        // clean up
1308        mTrianglePvs.clear();
1309}
1310
1311
1312void GvsPreprocessor::ComputeStats()
1313{
1314        // compute pvs size using larger (bvh objects)
1315        // note: for kd pvs we had to do this during gvs computation
1316
1317        if (!mUseKdPvs)
1318        {
1319                ObjectContainer objectPvs;
1320
1321                // optain object pvs
1322                GetObjectPvs(objectPvs);
1323
1324                // add pvs
1325                ObjectContainer::const_iterator it, it_end = objectPvs.end();
1326
1327                for (it = objectPvs.begin(); it != it_end; ++ it)
1328                {
1329                        mCurrentViewCell->GetPvs().AddSampleDirty(*it, 1.0f);
1330                }
1331
1332                cout << "triangle pvs of " << (int)mTrianglePvs.size()
1333                        << " was converted to object pvs of " << (int)objectPvs.size() << endl;
1334
1335                mGvsStats.mPerViewCellPvs = (int)objectPvs.size();
1336                mGvsStats.mPvsCost = 0; // todo objectPvs.EvalPvsCost();
1337        }
1338        else if (0)
1339        {
1340                //KdNode::NewMail();
1341
1342                // compute pvs kd nodes that intersect view cell
1343                ObjectContainer mykdobjects;
1344
1345                // extract kd pvs
1346                ObjectContainer::const_iterator it, it_end = mTrianglePvs.end();
1347
1348                for (it = mTrianglePvs.begin(); it != it_end; ++ it)
1349                {
1350                        Intersectable *obj = *it;
1351                        // find intersecting objects not yet in pvs (i.e., only unmailed)
1352                        mKdTree->CollectKdObjects(obj->GetBox(), mykdobjects);
1353                }
1354
1355                // add pvs
1356                it_end = mykdobjects.end();
1357
1358                for (it = mykdobjects.begin(); it != it_end; ++ it)
1359                {
1360                        mCurrentViewCell->GetPvs().AddSampleDirty(*it, 1.0f);
1361                }
1362
1363                cout << "added " << (int)mykdobjects.size() << " new objects " << endl;
1364
1365                mGvsStats.mPerViewCellPvs = mCurrentViewCell->GetPvs().GetSize();
1366                mGvsStats.mPvsCost = mCurrentViewCell->GetPvs().EvalPvsCost();
1367
1368        }
1369
1370        mGvsStats.mTrianglePvs = (int)mTrianglePvs.size();
1371
1372
1373        ////////////////
1374        // global values
1375
1376        mGvsStats.mViewCells = mProcessedViewCells;
1377        mGvsStats.mTotalTrianglePvs += mGvsStats.mTrianglePvs;
1378        mGvsStats.mTotalTime += mGvsStats.mTimePerViewCell;
1379    mGvsStats.mTotalPvs += mGvsStats.mPerViewCellPvs;
1380        mGvsStats.mTotalSamples += mGvsStats.mPerViewCellSamples;
1381
1382        mGvsStats.Stop();
1383        mGvsStats.Print(mGvsStatsStream);
1384
1385        cout << "id: " << mCurrentViewCell->GetId() << " pvs cost: "
1386             << mGvsStats.mPvsCost << " pvs tri: " << mTrianglePvs.size() << endl;
1387}
1388
1389
1390ObjectContainer triangles;
1391
1392int GvsPreprocessor::ConvertObjectPvs()
1393{
1394        int newObjects = 0;
1395
1396        ObjectPvsIterator pit = mCurrentViewCell->GetPvs().GetIterator();
1397
1398        triangles.clear();
1399
1400        // output PVS of view cell
1401        while (pit.HasMoreEntries())
1402        {               
1403                KdIntersectable *kdInt = static_cast<KdIntersectable *>(pit.Next());
1404
1405                mKdTree->CollectObjectsWithDublicates(kdInt->GetItem(), triangles);
1406
1407                ObjectContainer::const_iterator oit, oit_end = triangles.end();
1408
1409                for (oit = triangles.begin(); oit != oit_end; ++ oit)
1410                {
1411                        if (AddTriangleObject(*oit))
1412                                ++ newObjects;
1413                }
1414        }
1415
1416        return newObjects;
1417}
1418
1419
1420bool GvsPreprocessor::AddTriangleObject(Intersectable *triObj)
1421{
1422        if ((triObj->mCounter < ACCOUNTED_OBJECT))
1423        {
1424                triObj->mCounter += ACCOUNTED_OBJECT;
1425
1426                mTrianglePvs.push_back(triObj);
1427                mGenericStats[0] = (int)mTrianglePvs.size();
1428                return true;
1429        }
1430
1431        return false;
1432}
1433
1434
1435
1436}
Note: See TracBrowser for help on using the repository browser.