source: trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp @ 574

Revision 574, 19.8 KB checked in by mattausch, 18 years ago (diff)

finished function for view cell construction
removed bsp rays from vspbspmanager

Line 
1#include "SceneGraph.h"
2#include "KdTree.h"
3#include "VssPreprocessor.h"
4#include "X3dExporter.h"
5#include "Environment.h"
6#include "MutualVisibility.h"
7#include "Polygon3.h"
8#include "ViewCell.h"
9#include "VssRay.h"
10#include "VssTree.h"
11#include "ViewCellsManager.h"
12#include "RenderSimulator.h"
13#include "Beam.h"
14#include "GlRenderer.h"
15
16bool use2dSampling = false;
17bool useViewspacePlane = false;
18
19VssPreprocessor::VssPreprocessor():
20  mPass(0),
21  mVssRays()
22{
23  // this should increase coherence of the samples
24  environment->GetIntValue("VssPreprocessor.samplesPerPass", mSamplesPerPass);
25  environment->GetIntValue("VssPreprocessor.initialSamples", mInitialSamples);
26  environment->GetIntValue("VssPreprocessor.vssSamples", mVssSamples);
27  environment->GetIntValue("VssPreprocessor.vssSamplesPerPass", mVssSamplesPerPass);
28  environment->GetBoolValue("VssPreprocessor.useImportanceSampling", mUseImportanceSampling);
29 
30  environment->GetBoolValue("VssPreprocessor.loadInitialSamples", mLoadInitialSamples);
31  environment->GetBoolValue("VssPreprocessor.storeInitialSamples", mStoreInitialSamples);
32  environment->GetBoolValue("VssPreprocessor.useViewSpaceBox", mUseViewSpaceBox);
33  environment->GetBoolValue("VssPreprocessor.testBeamSampling", mTestBeamSampling);
34
35  useViewspacePlane = mUseViewSpaceBox; //hack
36
37  mStats.open("stats.log");
38}
39
40VssPreprocessor::~VssPreprocessor()
41{
42  CLEAR_CONTAINER(mVssRays);
43}
44
45void
46VssPreprocessor::SetupRay(Ray &ray,
47                                                  const Vector3 &point,
48                                                  const Vector3 &direction
49                                                  )
50{
51  ray.Clear();
52  // do not store anything else then intersections at the ray
53  ray.Init(point, direction, Ray::LOCAL_RAY);
54}
55
56
57void
58VssPreprocessor::CastRays(
59                                                  SimpleRayContainer &rays,
60                                                  VssRayContainer &vssRays
61                                                  )
62{
63  for (int i=0; i < rays.size(); i++)
64        CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays);
65}
66
67
68int
69VssPreprocessor::CastRay(
70                                                 Vector3 &viewPoint,
71                                                 Vector3 &direction,
72                                                 VssRayContainer &vssRays
73                                                 )
74{
75
76    int hits = 0;
77  static Ray ray;
78  AxisAlignedBox3 box = mKdTree->GetBox();
79
80  AxisAlignedBox3 sbox = box;
81  sbox.Enlarge(Vector3(-Limits::Small));
82  if (!sbox.IsInside(viewPoint))
83        return 0;
84       
85  SetupRay(ray, viewPoint, direction);
86  // cast ray to KD tree to find intersection with other objects
87  Intersectable *objectA, *objectB;
88  Vector3 pointA, pointB;
89  float bsize = Magnitude(box.Size());
90
91
92        if (!mDetectEmptyViewSpace)
93          ray.mFlags &= ~Ray::CULL_BACKFACES;
94        else
95          ray.mFlags |= Ray::CULL_BACKFACES;
96
97  if (mKdTree->CastRay(ray)) {
98        objectA = ray.intersections[0].mObject;
99        pointA = ray.Extrap(ray.intersections[0].mT);
100  } else {
101        objectA = NULL;
102        // compute intersection with the scene bounding box
103        float tmin, tmax;
104        if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax)
105          pointA = ray.Extrap(tmax);
106        else
107          return 0;
108  }
109
110       
111  if (mDetectEmptyViewSpace) {
112        SetupRay(ray, pointA, -direction);
113  } else
114        SetupRay(ray, viewPoint, -direction);
115 
116  if (!mDetectEmptyViewSpace)
117        ray.mFlags &= ~Ray::CULL_BACKFACES;
118  else
119         ray.mFlags |= Ray::CULL_BACKFACES;
120
121  if (mKdTree->CastRay(ray)) {
122        objectB = ray.intersections[0].mObject;
123        pointB = ray.Extrap(ray.intersections[0].mT);
124  } else {
125        objectB = NULL;
126        float tmin, tmax;
127        if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax)
128          pointB = ray.Extrap(tmax);
129        else
130          return 0;
131  }
132 
133  //  if (objectA == NULL && objectB != NULL) {
134  if (mDetectEmptyViewSpace) {
135        // cast again to ensure that there is no objectA
136        SetupRay(ray, pointB, direction);
137          ray.mFlags |= Ray::CULL_BACKFACES;
138        if (mKdTree->CastRay(ray)) {
139          objectA = ray.intersections[0].mObject;
140          pointA = ray.Extrap(ray.intersections[0].mT);
141        }
142  }
143
144 
145  VssRay *vssRay  = NULL;
146
147  bool validSample = (objectA != objectB);
148  if (0 && mDetectEmptyViewSpace) {   // consider all samples valid
149        // check if the viewpoint lies on the line segment AB
150        if (Distance(pointA, pointB) <
151                Distance(viewPoint, pointA) + Distance(viewPoint, pointB) - Limits::Small) {
152          validSample = false;
153        }
154  }
155       
156  if (validSample) {
157        if (objectA) {
158          vssRay = new VssRay(pointB,
159                                                  pointA,
160                                                  objectB,
161                                                  objectA,
162                                                  mPass
163                                                  );
164          vssRays.push_back(vssRay);
165          hits ++;
166        }
167       
168        if (objectB) {
169          vssRay = new VssRay(pointA,
170                                                  pointB,
171                                                  objectA,
172                                                  objectB,
173                                                  mPass
174                                                  );
175          vssRays.push_back(vssRay);
176          hits ++;
177        }
178  }
179       
180  return hits;
181}
182
183
184Vector3
185VssPreprocessor::GetViewpoint(AxisAlignedBox3 *viewSpaceBox)
186{
187  AxisAlignedBox3 box;
188
189  if (viewSpaceBox)
190        box =*viewSpaceBox;
191  else
192        box = mKdTree->GetBox();
193
194  // shrink the box in the y direction
195  return box.GetRandomPoint();
196}
197
198Vector3
199VssPreprocessor::GetDirection(const Vector3 &viewpoint,
200                                                          AxisAlignedBox3 *viewSpaceBox
201                                                          )
202{
203  Vector3 point;
204  if (!use2dSampling) {
205        if (0) {
206          Vector3 normal;
207          int i = Random((int)mObjects.size());
208          Intersectable *object = mObjects[i];
209          object->GetRandomSurfacePoint(point, normal);
210        } else
211          point = mKdTree->GetBox().GetRandomPoint();
212        //        point = viewpoint + UniformRandomVector();
213
214  } else {
215        AxisAlignedBox3 box;
216
217        if (viewSpaceBox)
218          box =*viewSpaceBox;
219        else
220          box = mKdTree->GetBox();
221
222        point = box.GetRandomPoint();
223        point.y = viewpoint.y;
224  }
225
226  return point - viewpoint;
227}
228
229int
230VssPreprocessor::GenerateImportanceRays(VssTree *vssTree,
231                                                                                const int desiredSamples,
232                                                                                SimpleRayContainer &rays
233                                                                                )
234{
235  int num;
236  if (0) {
237        float minRayContribution;
238        float maxRayContribution;
239        float avgRayContribution;
240
241        vssTree->GetRayContributionStatistics(minRayContribution,
242                                                                                  maxRayContribution,
243                                                                                  avgRayContribution);
244
245        cout<<
246          "#MIN_RAY_CONTRIB\n"<<minRayContribution<<endl<<
247          "#MAX_RAY_CONTRIB\n"<<maxRayContribution<<endl<<
248          "#AVG_RAY_CONTRIB\n"<<avgRayContribution<<endl;
249
250        float p = desiredSamples/(float)(avgRayContribution*vssTree->stat.Leaves());
251        num = vssTree->GenerateRays(p, rays);
252  } else {
253        int leaves = vssTree->stat.Leaves();
254        num = vssTree->GenerateRays(desiredSamples, leaves, rays);
255  }
256
257  cout<<"Generated "<<num<<" rays."<<endl;
258
259  return num;
260}
261
262
263bool
264VssPreprocessor::ExportRays(const char *filename,
265                                                        const VssRayContainer &vssRays,
266                                                        const int number
267                                                        )
268{
269  cout<<"Exporting vss rays..."<<endl<<flush;
270
271  Exporter *exporter = NULL;
272  exporter = Exporter::GetExporter(filename);
273  //    exporter->SetWireframe();
274  //    exporter->ExportKdTree(*mKdTree);
275  exporter->SetFilled();
276  exporter->ExportScene(mSceneGraph->mRoot);
277  exporter->SetWireframe();
278
279  if (mViewSpaceBox) {
280        exporter->SetForcedMaterial(RgbColor(1,0,1));
281        exporter->ExportBox(*mViewSpaceBox);
282        exporter->ResetForcedMaterial();
283  }
284
285  VssRayContainer rays;
286  vssRays.SelectRays(number, rays);
287 
288  exporter->ExportRays(rays, RgbColor(1, 0, 0));
289
290  delete exporter;
291
292  cout<<"done."<<endl<<flush;
293
294  return true;
295}
296
297
298bool
299VssPreprocessor::ExportVssTree(char *filename,
300                                                           VssTree *tree,
301                                                           const Vector3 &dir
302                                                           )
303{
304  Exporter *exporter = Exporter::GetExporter(filename);
305  exporter->SetFilled();
306  exporter->ExportScene(mSceneGraph->mRoot);
307  //  exporter->SetWireframe();
308  bool result = exporter->ExportVssTree2( *tree, dir );
309  delete exporter;
310  return result;
311}
312
313bool
314VssPreprocessor::ExportVssTreeLeaf(char *filename,
315                                                                   VssTree *tree,
316                                                                   VssTreeLeaf *leaf)
317{
318  Exporter *exporter = NULL;
319  exporter = Exporter::GetExporter(filename);
320  exporter->SetWireframe();
321  exporter->ExportKdTree(*mKdTree);
322
323  if (mViewSpaceBox) {
324        exporter->SetForcedMaterial(RgbColor(1,0,0));
325        exporter->ExportBox(*mViewSpaceBox);
326        exporter->ResetForcedMaterial();
327  }
328
329  exporter->SetForcedMaterial(RgbColor(0,0,1));
330  exporter->ExportBox(tree->GetBBox(leaf));
331  exporter->ResetForcedMaterial();
332
333  VssRayContainer rays[4];
334  for (int i=0; i < leaf->rays.size(); i++) {
335        int k = leaf->rays[i].GetRayClass();
336        rays[k].push_back(leaf->rays[i].mRay);
337  }
338
339  // SOURCE RAY
340  exporter->ExportRays(rays[0], RgbColor(1, 0, 0));
341  // TERMINATION RAY
342  exporter->ExportRays(rays[1], RgbColor(1, 1, 1));
343  // PASSING_RAY
344  exporter->ExportRays(rays[2], RgbColor(1, 1, 0));
345  // CONTAINED_RAY
346  exporter->ExportRays(rays[3], RgbColor(0, 0, 1));
347
348  delete exporter;
349  return true;
350}
351
352void
353VssPreprocessor::ExportVssTreeLeaves(VssTree *tree, const int number)
354{
355  vector<VssTreeLeaf *> leaves;
356  tree->CollectLeaves(leaves);
357
358  int num = 0;
359  int i;
360  float p = number / (float)leaves.size();
361  for (i=0; i < leaves.size(); i++) {
362        if (RandomValue(0,1) < p) {
363          char filename[64];
364          sprintf(filename, "vss-leaf-%04d.x3d", num);
365          ExportVssTreeLeaf(filename, tree, leaves[i]);
366          num++;
367        }
368        if (num >= number)
369          break;
370  }
371}
372#include "ViewCellBsp.h"
373
374void VssPreprocessor::TestBeamCasting(VssTree *tree,
375                                                                          ViewCellsManager *vm,
376                                                                          const ObjectContainer &objects)
377{
378        //debuggerWidget = new GlDebuggerWidget(renderer);
379        //  renderer->resize(640, 480);
380        //debuggerWidget->resize(640, 480);
381
382        vector<VssTreeLeaf *> leaves;
383        tree->CollectLeaves(leaves);
384
385        Exporter *exporter = Exporter::GetExporter("shafts.x3d");
386
387        exporter->SetWireframe();
388        exporter->ExportGeometry(objects);
389        exporter->SetFilled();
390        //Randomize();
391        debuggerWidget = new GlDebuggerWidget(renderer);
392
393        /*debuggerWidget->mBeam = beam;
394        debuggerWidget->mSourceObject = sourceObj;
395        debuggerWidget->mSamples = 10000;
396       
397        Debug << "showing window" << endl;
398        debuggerWidget->show();*/
399       
400        renderer->makeCurrent();
401
402        for (int i = 0; i < 10; ++ i)
403        {
404                Beam beam;
405                Intersectable *sourceObj = mObjects[5];
406
407                const int index = (int)RandomValue(0, (Real)((int)leaves.size() - 1));
408                VssTreeLeaf *leaf = leaves[index];
409
410                AxisAlignedBox3 dirBox = tree->GetDirBBox(leaf);
411                AxisAlignedBox3 box = tree->GetBBox(leaf);
412               
413                beam.Construct(box, dirBox);
414
415                // collect kd leaves and view cells
416                mKdTree->CastBeam(beam);
417                vm->CastBeam(beam);
418
419                Debug << "found " << beam.mViewCells.size() << " view cells and "
420                          << beam.mKdNodes.size() << " kd nodes" << endl;
421
422                BeamSampleStatistics stats;
423
424                renderer->SampleBeamContributions(sourceObj,
425                                                                                  beam,
426                                                                                  200000,
427                                                                                  stats);
428
429                char s[64]; sprintf(s, "shaft%04d.png", i);
430
431                QImage image = renderer->toImage();
432                image.save(s, "PNG");
433                Debug << "beam statistics: " << stats << endl << endl;
434
435                if (1)
436                {
437                        AxisAlignedBox3 sbox = mSceneGraph->GetBox();
438                        Vector3 bmin = sbox.Min() - 150.0f;
439                        Vector3 bmax = sbox.Max() + 150.0f;
440                        AxisAlignedBox3 vbox(bmin, bmax);
441               
442                        exporter->ExportBeam(beam, vbox);
443                }
444
445                bool exportViewCells = false;
446               
447                if (exportViewCells)
448                {
449                        ViewCellContainer::const_iterator it, it_end = beam.mViewCells.end();
450                       
451                        for (it = beam.mViewCells.begin(); it != beam.mViewCells.end(); ++ it)
452                        {
453                                BspNodeGeometry geom;
454                                AxisAlignedBox3 vbox;
455                                vbox.Initialize();
456                                vbox.Include((*it)->GetMesh());
457                       
458                                exporter->SetWireframe();
459                                exporter->ExportBox(vbox);
460                                exporter->SetFilled();
461                                exporter->ExportViewCell(*it);
462                        }
463
464                        /*vector<KdNode *>::const_iterator it, it_end = beam.mKdNodes.end();
465                       
466                        for (it = beam.mKdNodes.begin(); it != beam.mKdNodes.end(); ++ it)
467                        {
468                                exporter->ExportBox(mKdTree->GetBox((*it)));
469                        }*/
470                }
471        }
472        /*while (1)
473        { debuggerWidget->repaint();
474        };*/
475        delete exporter;
476}
477
478
479float
480VssPreprocessor::GetAvgPvsSize(VssTree *tree,
481                                                           const vector<AxisAlignedBox3> &viewcells
482                                                           )
483{
484  vector<AxisAlignedBox3>::const_iterator it, it_end = viewcells.end();
485
486  int sum = 0;
487  for (it = viewcells.begin(); it != it_end; ++ it)
488        sum += tree->GetPvsSize(*it);
489
490  return sum/(float)viewcells.size();
491}
492
493bool
494VssPreprocessor::ComputeVisibility()
495{
496
497
498  long startTime = GetTime();
499
500  int totalSamples = 0;
501
502
503  AxisAlignedBox3 *box = new AxisAlignedBox3(mKdTree->GetBox());
504 
505  if (!useViewspacePlane) {
506        float size = 0.05f;
507        float s = 0.5f - size;
508        float olds = Magnitude(box->Size());
509        box->Enlarge(box->Size()*Vector3(-s));
510        Vector3 translation = Vector3(-olds*0.1f, 0, 0);
511        box->SetMin(box->Min() + translation);
512        box->SetMax(box->Max() + translation);
513  } else {
514
515        // sample city like heights
516        box->SetMin(1, box->Min(1) + box->Size(1)*0.2f);
517        box->SetMax(1, box->Min(1) + box->Size(1)*0.3f);
518  }
519
520  if (use2dSampling)
521        box->SetMax(1, box->Min(1));
522
523  cout<<"mUseViewSpaceBox="<<mUseViewSpaceBox<<endl;
524  Debug << "use view space box=" << mUseViewSpaceBox << endl;
525  if (mUseViewSpaceBox)
526  {
527        mViewSpaceBox = box;
528        mViewCellsManager->SetViewSpaceBox(*box);
529  }
530  else
531  {
532        mViewSpaceBox = NULL;
533        mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox());
534  }
535 
536  //-- load view cells from file if requested
537  if (mLoadViewCells)
538  {     
539          // load now because otherwise bounding box not correct
540          mViewCellsManager->LoadViewCells(mViewCellsFilename, &mObjects);
541  }
542  else
543  {
544          // construct view cells using it's own set of samples
545          mViewCellsManager->Construct(this);
546
547          //-- several visualizations and statistics
548          Debug << "view cells after construction: " << endl;
549          mViewCellsManager->PrintStatistics(Debug);
550  }
551       
552
553  VssTree *vssTree = NULL;
554
555  mSceneGraph->CollectObjects(&mObjects);
556
557  long initialTime = GetTime();
558
559  if (mLoadInitialSamples)
560  {
561          cout << "Loading samples from file ... ";
562          LoadSamples(mVssRays, mObjects);
563          cout << "finished\n" << endl;
564          totalSamples = (int)mVssRays.size();
565  }
566  else
567  {
568       
569        while (totalSamples < mInitialSamples) {
570                int passContributingSamples = 0;
571                int passSampleContributions = 0;
572                int passSamples = 0;
573
574                int index = 0;
575
576                int sampleContributions;
577
578                int s = Min(mSamplesPerPass, mInitialSamples);
579                for (int k=0; k < s; k++) {
580                        // changed by matt
581                        Vector3 viewpoint;
582                        //                      viewpoint = GetViewpoint(mViewSpaceBox);
583                        mViewCellsManager->GetViewPoint(viewpoint);
584                        Vector3 direction = GetDirection(viewpoint, mViewSpaceBox);
585
586                        sampleContributions = CastRay(viewpoint, direction, mVssRays);
587
588                        if (sampleContributions) {
589                                passContributingSamples ++;
590                                passSampleContributions += sampleContributions;
591                        }
592                        passSamples++;
593                        totalSamples++;
594                }
595
596                mPass++;
597                int pvsSize = 0;
598                float avgRayContrib = (passContributingSamples > 0) ?
599                        passSampleContributions/(float)passContributingSamples : 0;
600
601                cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl;
602                cout << "#TotalSamples=" << totalSamples/1000
603                        << "k   #SampleContributions=" << passSampleContributions << " ("
604                        << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS="
605                        << pvsSize/(float)mObjects.size() << endl
606                        << "avg ray contrib=" << avgRayContrib << endl;
607
608                mStats <<
609                        "#Pass\n" <<mPass<<endl<<
610                        "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<<
611                        "#TotalSamples\n" << totalSamples<< endl<<
612                        "#SampleContributions\n" << passSampleContributions << endl <<
613                        "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl <<
614                        "#AvgPVS\n"<< pvsSize/(float)mObjects.size() << endl <<
615                        "#AvgRayContrib\n" << avgRayContrib << endl;
616          }
617 
618          cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl;
619
620
621         
622  }
623 
624
625  cout << "#totalRayStackSize=" << (int)mVssRays.size() << endl << flush;
626  Debug << (int)mVssRays.size() << " rays generated in "
627            << TimeDiff(initialTime, GetTime()) * 1e-3 << " seconds" << endl;
628
629  if (mStoreInitialSamples)
630  {
631          cout << "Writing " << (int)mVssRays.size() << " samples to file ... ";
632          ExportSamples(mVssRays);
633          cout << "finished\n" << endl;
634
635          /*VssRayContainer dummyRays;
636          LoadSamples(dummyRays, mObjects);
637          Debug << "rays " << (int)mVssRays.size() << " " << dummyRays.size() << endl;
638
639          for (int i = 0; i < (int)mVssRays.size(); ++ i)
640          {
641                  Debug << mVssRays[i]->GetOrigin() << " " << mVssRays[i]->GetTermination() << " " << mVssRays[i]->mOriginObject << " " << mVssRays[i]->mTerminationObject << endl;
642                  Debug << dummyRays[i]->GetOrigin() << " " << dummyRays[i]->GetTermination() << " " << dummyRays[i]->mOriginObject << " " << dummyRays[i]->mTerminationObject << endl << endl;
643          }*/
644  }
645
646 
647  //int numExportRays = 5000;
648  int numExportRays = 0;
649
650  if (numExportRays) {
651        char filename[64];
652        sprintf(filename, "vss-rays-initial.x3d");
653        ExportRays(filename, mVssRays, numExportRays);
654  }
655
656  vssTree = new VssTree;
657  // viewcells = Construct(mVssRays);
658
659  vssTree->Construct(mVssRays, mViewSpaceBox);
660  cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl;
661
662  if (0)
663  {
664          ExportVssTree("vss-tree-100.x3d", vssTree, Vector3(1,0,0));
665          ExportVssTree("vss-tree-001.x3d", vssTree, Vector3(0,0,1));
666          ExportVssTree("vss-tree-101.x3d", vssTree, Vector3(1,0,1));
667          ExportVssTree("vss-tree-101m.x3d", vssTree, Vector3(-1,0,-1));
668          ExportVssTreeLeaves(vssTree, 10);
669  }
670
671  // viewcells->UpdatePVS(newVssRays);
672  // get viewcells as kd tree boxes
673  vector<AxisAlignedBox3> kdViewcells;
674  if (0) {
675        vector<KdLeaf *> leaves;
676        mKdTree->CollectLeaves(leaves);
677        vector<KdLeaf *>::const_iterator it;
678        int targetLeaves = 50;
679        float prob = targetLeaves/(float)leaves.size();
680        for (it = leaves.begin(); it != leaves.end(); ++it)
681          if (RandomValue(0.0f,1.0f) < prob)
682                kdViewcells.push_back(mKdTree->GetBox(*it));
683
684        float avgPvs = GetAvgPvsSize(vssTree, kdViewcells);
685        cout<<"Initial average PVS size = "<<avgPvs<<endl;
686  }
687
688
689  int samples = 0;
690  int pass = 0;
691
692 
693  // cast view cell samples
694  while (samples < mVssSamples)
695  {
696       
697        int num = mVssSamplesPerPass;
698        SimpleRayContainer rays;
699        VssRayContainer vssRays;
700
701        if (!mUseImportanceSampling) {
702          for (int j=0; j < num; j++) {
703            // changed by matt
704                //Vector3 viewpoint = GetViewpoint(mViewSpaceBox);
705                Vector3 viewpoint;
706                mViewCellsManager->GetViewPoint(viewpoint);
707                Vector3 direction = GetDirection(viewpoint, mViewSpaceBox);
708                rays.push_back(SimpleRay(viewpoint, direction));
709          }
710        } else {
711          num = GenerateImportanceRays(vssTree, num, rays);
712        }
713
714        for (int i=0; i < rays.size(); i++)
715          CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays);
716
717        vssTree->AddRays(vssRays);
718
719        if (0) {
720          int subdivided = vssTree->UpdateSubdivision();
721          cout<<"subdivided leafs = "<<subdivided<<endl;
722        }
723
724        float avgPvs = GetAvgPvsSize(vssTree, kdViewcells);
725        cout<<"Average PVS size = "<<avgPvs<<endl;
726
727        /// compute view cell contribution of rays
728        mViewCellsManager->ComputeSampleContributions(vssRays, true, false);
729       
730        if (numExportRays) {
731          char filename[64];
732          if (mUseImportanceSampling)
733                sprintf(filename, "vss-rays-i%04d.x3d", pass);
734          else
735                sprintf(filename, "vss-rays-%04d.x3d", pass);
736
737          ExportRays(filename, vssRays, numExportRays);
738        }
739
740        samples+=num;
741        float pvs = vssTree->GetAvgPvsSize();
742        cout<<"*****************************\n";
743        cout<<samples<<" avgPVS ="<<pvs<<endl;
744        cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl;
745        cout<<"*****************************\n";
746//      if (samples >= mVssSamples) break;
747        pass ++;
748  }
749
750  if (mTestBeamSampling && mUseGlRenderer)
751  {     
752          TestBeamCasting(vssTree, mViewCellsManager, mObjects);
753  }
754
755  Debug << vssTree->stat << endl;
756
757  if (0)
758  {
759        VssRayContainer viewCellRays;
760 
761        // compute rays used for view cells construction
762        const int numRays = mViewCellsManager->GetVisualizationSamples();
763
764        vssTree->CollectRays(viewCellRays, numRays);
765  }
766
767  //-- render simulation after merge
768  cout << "\nevaluating bsp view cells render time after sampling ... ";
769  mRenderSimulator->RenderScene();
770  SimulationStatistics ss;
771  mRenderSimulator->GetStatistics(ss);
772 
773  cout << " finished" << endl;
774  cout << ss << endl;
775  Debug << ss << endl;
776
777  delete vssTree;
778 
779  return true;
780}
Note: See TracBrowser for help on using the repository browser.