source: trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp @ 496

Revision 496, 19.7 KB checked in by bittner, 19 years ago (diff)

glrenderer split into widget and buffer, buffer moved to the same thread as the preprocessor

Line 
1#include "SceneGraph.h"
2#include "KdTree.h"
3#include "RssPreprocessor.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 "RssTree.h"
11#include "ViewCellsManager.h"
12#include "RenderSimulator.h"
13#include "GlRenderer.h"
14
15static bool useViewSpaceBox = false;
16static bool use2dSampling = false;
17static bool fromBoxVisibility = false;
18
19
20RssPreprocessor::RssPreprocessor():
21  mPass(0),
22  mVssRays()
23{
24  // this should increase coherence of the samples
25  environment->GetIntValue("RssPreprocessor.samplesPerPass", mSamplesPerPass);
26  environment->GetIntValue("RssPreprocessor.initialSamples", mInitialSamples);
27  environment->GetIntValue("RssPreprocessor.vssSamples", mRssSamples);
28  environment->GetIntValue("RssPreprocessor.vssSamplesPerPass", mRssSamplesPerPass);
29  environment->GetBoolValue("RssPreprocessor.useImportanceSampling", mUseImportanceSampling);
30
31  environment->GetBoolValue("RssPreprocessor.Export.pvs", mExportPvs);
32  environment->GetBoolValue("RssPreprocessor.Export.rssTree", mExportRssTree);
33  environment->GetBoolValue("RssPreprocessor.Export.rays", mExportRays);
34  environment->GetIntValue("RssPreprocessor.Export.numRays", mExportNumRays);
35  environment->GetBoolValue("RssPreprocessor.useViewcells", mUseViewcells);
36  environment->GetBoolValue("RssPreprocessor.objectBasedSampling", mObjectBasedSampling);
37  environment->GetBoolValue("RssPreprocessor.directionalSampling", mDirectionalSampling);
38
39  environment->GetBoolValue("RssPreprocessor.loadInitialSamples", mLoadInitialSamples);
40  environment->GetBoolValue("RssPreprocessor.storeInitialSamples", mStoreInitialSamples);
41 
42  mStats.open("stats.log");
43
44}
45
46RssPreprocessor::~RssPreprocessor()
47{
48  // mVssRays get deleted in the tree
49  //  CLEAR_CONTAINER(mVssRays);
50}
51
52void
53RssPreprocessor::SetupRay(Ray &ray,
54                                                  const Vector3 &point,
55                                                  const Vector3 &direction
56                                                  )
57{
58  ray.intersections.clear();
59  // do not store anything else then intersections at the ray
60  ray.Init(point, direction, Ray::LOCAL_RAY);
61}
62
63int
64RssPreprocessor::CastRay(
65                                                 Vector3 &viewPoint,
66                                                 Vector3 &direction,
67                                                 VssRayContainer &vssRays
68                                                 )
69{
70  int hits = 0;
71  static Ray ray;
72  AxisAlignedBox3 box = mKdTree->GetBox();
73
74  AxisAlignedBox3 sbox = box;
75  sbox.Enlarge(Vector3(-Limits::Small));
76  if (!sbox.IsInside(viewPoint))
77        return 0;
78       
79  SetupRay(ray, viewPoint, direction);
80  // cast ray to KD tree to find intersection with other objects
81  Intersectable *objectA, *objectB;
82  Vector3 pointA, pointB;
83  float bsize = Magnitude(box.Size());
84
85 
86  if (mKdTree->CastRay(ray)) {
87        objectA = ray.intersections[0].mObject;
88        pointA = ray.Extrap(ray.intersections[0].mT);
89  } else {
90        objectA = NULL;
91        // compute intersection with the scene bounding box
92        float tmin, tmax;
93        if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax)
94          pointA = ray.Extrap(tmax);
95        else
96          return 0;
97  }
98
99  bool detectEmptyViewSpace = true;
100       
101  if (detectEmptyViewSpace) {
102        SetupRay(ray, pointA, -direction);
103  } else
104        SetupRay(ray, viewPoint, -direction);
105       
106       
107  if (mKdTree->CastRay(ray)) {
108        objectB = ray.intersections[0].mObject;
109        pointB = ray.Extrap(ray.intersections[0].mT);
110  } else {
111        objectB = NULL;
112        float tmin, tmax;
113        if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax)
114          pointB = ray.Extrap(tmax);
115        else
116          return 0;
117  }
118
119  //  if (objectA == NULL && objectB != NULL) {
120  if (1) {
121        // cast again to ensure that there is no objectA
122        SetupRay(ray, pointB, direction);
123        if (mKdTree->CastRay(ray)) {
124          objectA = ray.intersections[0].mObject;
125          pointA = ray.Extrap(ray.intersections[0].mT);
126        }
127  }
128 
129 
130  VssRay *vssRay  = NULL;
131
132  bool validSample = (objectA != objectB);
133  if (0 && detectEmptyViewSpace) {   // consider all samples valid
134        // check if the viewpoint lies on the line segment AB
135        if (Distance(pointA, pointB) <
136                Distance(viewPoint, pointA) + Distance(viewPoint, pointB) - Limits::Small) {
137          validSample = false;
138        }
139  }
140       
141  if (validSample) {
142        if (objectA) {
143          vssRay = new VssRay(pointB,
144                                                  pointA,
145                                                  objectB,
146                                                  objectA,
147                                                  mPass
148                                                  );
149          vssRays.push_back(vssRay);
150          hits ++;
151        }
152       
153        if (objectB) {
154          vssRay = new VssRay(pointA,
155                                                  pointB,
156                                                  objectA,
157                                                  objectB,
158                                                  mPass
159                                                  );
160          vssRays.push_back(vssRay);
161          hits ++;
162        }
163  }
164       
165  return hits;
166}
167
168
169Vector3
170RssPreprocessor::GetViewpoint(AxisAlignedBox3 *viewSpaceBox)
171{
172  AxisAlignedBox3 box;
173       
174  if (viewSpaceBox)
175        box =*viewSpaceBox;
176  else
177        box = mKdTree->GetBox();
178       
179  // shrink the box in the y direction
180  return box.GetRandomPoint();
181}
182
183Vector3
184RssPreprocessor::GetDirection(const Vector3 &viewpoint,
185                                                          AxisAlignedBox3 *viewSpaceBox
186                                                          )
187{
188  Vector3 point;
189  if (!use2dSampling) {
190        if (mObjectBasedSampling) {
191          Vector3 normal;
192          int i = RandomValue(0, mObjects.size()-1);
193          Intersectable *object = mObjects[i];
194          object->GetRandomSurfacePoint(point, normal);
195        } else {
196          // select
197          if (mDirectionalSampling) {
198                point = viewpoint + UniformRandomVector();
199          } else {
200                // select the other point uniformly distruted in the whole viewspace
201                AxisAlignedBox3 box;
202               
203                if (viewSpaceBox)
204                  box =*viewSpaceBox;
205                else
206                  box = mKdTree->GetBox();
207               
208                point = box.GetRandomPoint();
209          }
210        }
211  } else {
212        AxisAlignedBox3 box;
213               
214        if (viewSpaceBox)
215          box =*viewSpaceBox;
216        else
217          box = mKdTree->GetBox();
218       
219        point = box.GetRandomPoint();
220        point.y = viewpoint.y;
221  }
222       
223  return point - viewpoint;
224}
225
226Vector3
227RssPreprocessor::InitialGetDirection(const Vector3 &viewpoint,
228                                                                         AxisAlignedBox3 *viewSpaceBox
229                                                                         )
230{
231  Vector3 point;
232  if (!use2dSampling) {
233        if (1 || mObjectBasedSampling) {
234          Vector3 normal;
235          int i = RandomValue(0, mObjects.size()-1);
236          Intersectable *object = mObjects[i];
237          object->GetRandomSurfacePoint(point, normal);
238        } else {
239          // select
240          if (1 || mDirectionalSampling) {
241                point = viewpoint + UniformRandomVector();
242          } else {
243                // select the other point uniformly distruted in the whole viewspace
244                AxisAlignedBox3 box;
245               
246                if (viewSpaceBox)
247                  box =*viewSpaceBox;
248                else
249                  box = mKdTree->GetBox();
250               
251                point = box.GetRandomPoint();
252          }
253        }
254  } else {
255        AxisAlignedBox3 box;
256       
257        if (viewSpaceBox)
258          box =*viewSpaceBox;
259        else
260          box = mKdTree->GetBox();
261       
262        point = box.GetRandomPoint();
263        point.y = viewpoint.y;
264  }
265 
266  return point - viewpoint;
267}
268
269int
270RssPreprocessor::GenerateImportanceRays(RssTree *rssTree,
271                                                                                const int desiredSamples,
272                                                                                SimpleRayContainer &rays
273                                                                                )
274{
275  int num;
276
277  rssTree->UpdateTreeStatistics();
278
279  cout<<
280        "#RSS_AVG_PVS_SIZE\n"<<rssTree->stat.avgPvsSize<<endl<<
281        "#RSS_AVG_RAYS\n"<<rssTree->stat.avgRays<<endl<<
282        "#RSS_AVG_RAY_CONTRIB\n"<<rssTree->stat.avgRayContribution<<endl<<
283        "#RSS_AVG_PVS_ENTROPY\n"<<rssTree->stat.avgPvsEntropy<<endl<<
284        "#RSS_AVG_RAY_LENGTH_ENTROPY\n"<<rssTree->stat.avgRayLengthEntropy<<endl<<
285        "#RSS_AVG_IMPORTANCE\n"<<rssTree->stat.avgImportance<<endl;
286 
287  if (0) {
288        float p = desiredSamples/(float)(rssTree->stat.avgRayContribution*rssTree->stat.Leaves());
289        num = rssTree->GenerateRays(p, rays);
290  } else {
291        int leaves = rssTree->stat.Leaves()/1;
292        num = rssTree->GenerateRays(desiredSamples, leaves, rays);
293  }
294       
295  cout<<"Generated "<<num<<" rays."<<endl;
296       
297  return num;
298}
299
300
301bool
302RssPreprocessor::ExportRays(const char *filename,
303                                                        const VssRayContainer &vssRays,
304                                                        const int number
305                                                        )
306{
307  cout<<"Exporting vss rays..."<<endl<<flush;
308       
309  Exporter *exporter = NULL;
310  exporter = Exporter::GetExporter(filename);
311  //    exporter->SetWireframe();
312  //    exporter->ExportKdTree(*mKdTree);
313  exporter->SetFilled();
314  exporter->ExportScene(mSceneGraph->mRoot);
315  exporter->SetWireframe();
316
317  if (mViewSpaceBox) {
318        exporter->SetForcedMaterial(RgbColor(1,0,1));
319        exporter->ExportBox(*mViewSpaceBox);
320        exporter->ResetForcedMaterial();
321  }
322       
323  VssRayContainer rays;
324 
325  vssRays.SelectRays( number, rays);
326
327  exporter->ExportRays(rays, RgbColor(1, 0, 0));
328       
329  delete exporter;
330
331  cout<<"done."<<endl<<flush;
332
333  return true;
334}
335
336
337bool
338RssPreprocessor::ExportRssTree(char *filename,
339                                                           RssTree *tree,
340                                                           const Vector3 &dir
341                                                           )
342{
343  Exporter *exporter = Exporter::GetExporter(filename);
344  exporter->SetFilled();
345  exporter->ExportScene(mSceneGraph->mRoot);
346  //  exporter->SetWireframe();
347  bool result = exporter->ExportRssTree2( *tree, dir );
348  delete exporter;
349  return result;
350}
351
352bool
353RssPreprocessor::ExportRssTreeLeaf(char *filename,
354                                                                   RssTree *tree,
355                                                                   RssTreeLeaf *leaf)
356{
357  Exporter *exporter = NULL;
358  exporter = Exporter::GetExporter(filename);
359  exporter->SetWireframe();
360  exporter->ExportKdTree(*mKdTree);
361       
362  if (mViewSpaceBox) {
363        exporter->SetForcedMaterial(RgbColor(1,0,0));
364        exporter->ExportBox(*mViewSpaceBox);
365        exporter->ResetForcedMaterial();
366  }
367       
368  exporter->SetForcedMaterial(RgbColor(0,0,1));
369  exporter->ExportBox(tree->GetBBox(leaf));
370  exporter->ResetForcedMaterial();
371       
372  VssRayContainer rays[4];
373  for (int i=0; i < leaf->rays.size(); i++) {
374        int k = leaf->rays[i].GetRayClass();
375        rays[k].push_back(leaf->rays[i].mRay);
376  }
377       
378  // SOURCE RAY
379  exporter->ExportRays(rays[0], RgbColor(1, 0, 0));
380  // TERMINATION RAY
381  exporter->ExportRays(rays[1], RgbColor(1, 1, 1));
382  // PASSING_RAY
383  exporter->ExportRays(rays[2], RgbColor(1, 1, 0));
384  // CONTAINED_RAY
385  exporter->ExportRays(rays[3], RgbColor(0, 0, 1));
386
387  delete exporter;
388  return true;
389}
390
391void
392RssPreprocessor::ExportRssTreeLeaves(RssTree *tree, const int number)
393{
394  vector<RssTreeLeaf *> leaves;
395  tree->CollectLeaves(leaves);
396
397  int num = 0;
398  int i;
399  float p = number / (float)leaves.size();
400  for (i=0; i < leaves.size(); i++) {
401        if (RandomValue(0,1) < p) {
402          char filename[64];
403          sprintf(filename, "rss-leaf-%04d.x3d", num);
404          ExportRssTreeLeaf(filename, tree, leaves[i]);
405          num++;
406        }
407        if (num >= number)
408          break;
409  }
410}
411
412
413float
414RssPreprocessor::GetAvgPvsSize(RssTree *tree,
415                                                           const vector<AxisAlignedBox3> &viewcells
416                                                           )
417{
418  vector<AxisAlignedBox3>::const_iterator it, it_end = viewcells.end();
419
420  int sum = 0;
421  for (it = viewcells.begin(); it != it_end; ++ it)
422        sum += tree->GetPvsSize(*it);
423       
424  return sum/(float)viewcells.size();
425}
426
427
428void
429RssPreprocessor::ExportPvs(char *filename,
430                                                   RssTree *rssTree
431                                                   )
432{
433  ObjectContainer pvs;
434  if (rssTree->CollectRootPvs(pvs)) {
435        Exporter *exporter = Exporter::GetExporter(filename);
436        exporter->SetFilled();
437        exporter->ExportGeometry(pvs);
438        exporter->SetWireframe();
439        exporter->ExportBox(rssTree->bbox);
440        exporter->ExportViewpoint(rssTree->bbox.Center(), Vector3(1,0,0));
441        delete exporter;
442  }
443}
444
445
446void
447RssPreprocessor::ComputeRenderError()
448{
449  // compute rendering error
450  if (renderer) {
451        //      emit EvalPvsStat();
452        //      QMutex mutex;
453        //      mutex.lock();
454        //      renderer->mRenderingFinished.wait(&mutex);
455        //      mutex.unlock();
456        renderer->EvalPvsStat();
457        mStats <<
458          "#AvgPvsRenderError\n" <<renderer->mPvsStat.GetAvgError()<<endl<<
459          "#MaxPvsRenderError\n" <<renderer->mPvsStat.GetMaxError()<<endl<<
460          "#ErrorFreeFrames\n" <<renderer->mPvsStat.GetErrorFreeFrames()<<endl;
461  }
462}
463
464bool
465RssPreprocessor::ComputeVisibility()
466{
467 
468  //  connect(this, SIGNAL(EvalPvsStat()), renderer, SLOT(EvalPvsStat()) );
469 
470  cout<<"Rss Preprocessor started\n"<<flush;
471  cout<<"Memory/ray "<<sizeof(VssRay)+sizeof(RssTreeNode::RayInfo)<<endl;
472
473  Randomize(0);
474 
475       
476  long startTime = GetTime();
477 
478  int totalSamples = 0;
479
480  AxisAlignedBox3 *box = new AxisAlignedBox3(mKdTree->GetBox());
481
482  if (fromBoxVisibility) {
483        float m = box->Min(1);
484        float bsize = box->Size(1);
485
486        float size = 0.02f;
487        float s = 0.5f - size;
488        float olds = Magnitude(box->Size());
489        box->Enlarge(box->Size()*Vector3(-s));
490        //      Vector3 translation = Vector3(-olds*0.2f, 0, 0);
491        Vector3 translation = Vector3(-0.05f*olds, 0, 0);
492        box->SetMin(box->Min() + translation);
493        box->SetMax(box->Max() + translation);
494
495        box->SetMin(1,  m + bsize*0.1f);
496        box->SetMax(1,  m + bsize*0.6f);
497
498       
499  } else {
500               
501        // sample city like heights
502        float m = box->Min(1);
503        float bsize = box->Size(1);
504        box->SetMin(1,  m + bsize*0.2f);
505        box->SetMax(1,  m + bsize*0.3f);
506  }
507
508  if (use2dSampling)
509        box->SetMax(1, box->Min(1));
510       
511  if (useViewSpaceBox)
512  {
513        mViewSpaceBox = box;
514        mViewCellsManager->SetViewSpaceBox(*box);
515  }
516  else
517  {
518        mViewSpaceBox = NULL;
519        mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox());
520  }
521               
522
523  RssTree *rssTree = NULL;
524  int rssPass = 0;
525  int rssSamples = 0;
526
527#if 0
528  if (mLoadInitialSamples) {
529        cout << "Loading samples from file ... ";
530        LoadSamples(mVssRays, mObjects);
531        cout << "finished\n" << endl;
532  } else {
533#endif
534        while (totalSamples < mInitialSamples) {
535          int passContributingSamples = 0;
536          int passSampleContributions = 0;
537          int passSamples = 0;
538          int index = 0;
539         
540          int sampleContributions;
541         
542          //int s = Min(mSamplesPerPass, mInitialSamples);
543          int s = mInitialSamples;
544         
545          for (int k=0; k < s; k++) {
546               
547               
548                //Vector3 viewpoint = GetViewpoint(mViewSpaceBox);
549                Vector3 viewpoint;
550                //              mViewCellsManager->GetViewPoint(viewpoint);
551                viewpoint = GetViewpoint(mViewSpaceBox);
552                Vector3 direction = InitialGetDirection(viewpoint, mViewSpaceBox);
553               
554                sampleContributions = CastRay(viewpoint, direction, mVssRays);
555               
556               
557                //-- CORR matt: put block inside loop
558                if (sampleContributions) {
559                  passContributingSamples ++;
560                  passSampleContributions += sampleContributions;
561                }
562                passSamples++;
563                totalSamples++;
564          }
565         
566         
567          float avgRayContrib = (passContributingSamples > 0) ?
568                passSampleContributions/(float)passContributingSamples : 0;
569         
570          cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl;
571          cout << "#TotalSamples=" << totalSamples/1000
572                   << "k   #SampleContributions=" << passSampleContributions << " ("
573                   << 100*passContributingSamples/(float)passSamples<<"%)"
574                   << "avgcontrib=" << avgRayContrib << endl;
575         
576          mPass++;
577        }
578         
579        cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl;
580        cout << "#totalRayStackSize=" << (int)mVssRays.size() << endl <<flush;
581       
582        rssSamples += mVssRays.size();
583       
584       
585        if (mExportRays) {
586          char filename[64];
587          sprintf(filename, "rss-rays-initial.x3d");
588          ExportRays(filename, mVssRays, mExportNumRays);
589        }
590       
591        if (mStoreInitialSamples)
592          {
593                cout << "Writing samples to file ... ";
594                WriteSamples(mVssRays);
595                cout << "finished\n" << endl;
596          }
597       
598        if (mUseViewcells) {
599          // construct view cells
600          mViewCellsManager->Construct(mObjects, mVssRays);
601          // evaluate contributions of the intitial rays
602          mViewCellsManager->ComputeSampleContributions(mVssRays);
603         
604         
605          mStats <<
606                "#Pass\n" <<mPass<<endl<<
607                "#RssPass\n" <<rssPass<<endl<<
608                "#Time\n" << TimeDiff(startTime, GetTime())*1e-3<<endl<<
609                "#TotalSamples\n" <<totalSamples<<endl<<
610                "#RssSamples\n" <<rssSamples<<endl;
611         
612        ComputeRenderError();
613
614        mVssRays.PrintStatistics(mStats);
615        mViewCellsManager->PrintPvsStatistics(mStats);
616
617        VssRayContainer selectedRays;
618        int desired = Max(
619                                          mViewCellsManager->GetPostProcessSamples(),
620                                          mViewCellsManager->GetVisualizationSamples());
621
622        mVssRays.SelectRays(desired, selectedRays);
623       
624        //-- post process view cells
625        mViewCellsManager->PostProcess(mObjects, selectedRays);
626       
627        //-- several visualizations and statistics
628        Debug << "view cells after post processing: " << endl;
629        mViewCellsManager->PrintStatistics(Debug);
630       
631        if (1)
632          mViewCellsManager->Visualize(mObjects, selectedRays);
633  }
634
635
636 
637  rssPass++;
638 
639  rssTree = new RssTree;
640  rssTree->SetPass(mPass);
641 
642  if (mUseImportanceSampling) {
643       
644        if (fromBoxVisibility)
645          rssTree->Construct(mVssRays, mViewSpaceBox);
646        else
647          rssTree->Construct(mVssRays, NULL);
648
649        rssTree->stat.Print(mStats);
650        cout<<"RssTree root PVS size = "<<rssTree->GetRootPvsSize()<<endl;
651       
652        if (mExportRssTree) {
653          ExportRssTree("rss-tree-100.x3d", rssTree, Vector3(1,0,0));
654          ExportRssTree("rss-tree-001.x3d", rssTree, Vector3(0,0,1));
655          ExportRssTree("rss-tree-101.x3d", rssTree, Vector3(1,0,1));
656          ExportRssTree("rss-tree-101m.x3d", rssTree, Vector3(-1,0,-1));
657          ExportRssTreeLeaves(rssTree, 10);
658        }
659       
660        if (mExportPvs) {
661          ExportPvs("rss-pvs-initial.x3d", rssTree);
662        }
663  }
664 
665  // viewcells->UpdatePVS(newVssRays);
666 
667
668  while (1) {
669        int num = mRssSamplesPerPass;
670        SimpleRayContainer rays;
671        VssRayContainer vssRays;
672
673
674        if (!mUseImportanceSampling) {
675          for (int j=0; j < num; j++) {
676            //changed by matt
677                //Vector3 viewpoint = GetViewpoint(mViewSpaceBox);
678                Vector3 viewpoint;
679                mViewCellsManager->GetViewPoint(viewpoint);
680                Vector3 direction = GetDirection(viewpoint, mViewSpaceBox);
681                rays.push_back(SimpleRay(viewpoint, direction));
682          }
683        } else {
684          num = GenerateImportanceRays(rssTree, num, rays);
685        }
686               
687               
688        for (int i=0; i < rays.size(); i++)
689          CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays);
690
691       
692        totalSamples += rays.size();
693        rssSamples += vssRays.size();
694
695       
696       
697        mStats <<
698          "#Pass\n" <<mPass<<endl<<
699          "#RssPass\n" <<rssPass<<endl<<
700          "#Time\n" << TimeDiff(startTime, GetTime())*1e-3<<endl<<
701          "#TotalSamples\n" <<totalSamples<<endl<<
702          "#RssSamples\n" <<rssSamples<<endl;
703
704
705        if (mUseViewcells) {
706         
707          /// compute view cell contribution of rays
708          mViewCellsManager->ComputeSampleContributions(vssRays);
709         
710          vssRays.PrintStatistics(mStats);
711          mViewCellsManager->PrintPvsStatistics(mStats);
712        }
713
714
715        ComputeRenderError();
716       
717        // epxort rays before adding them to the tree -> some of them can be deleted
718
719        if (mExportRays) {
720          char filename[64];
721          if (mUseImportanceSampling)
722                sprintf(filename, "rss-rays-i%04d.x3d", rssPass);
723          else
724                sprintf(filename, "rss-rays-%04d.x3d", rssPass);
725         
726          ExportRays(filename, vssRays, mExportNumRays);
727
728          // now export all contributing rays
729          VssRayContainer contributingRays;
730          vssRays.GetContributingRays(contributingRays, mPass);
731          mStats<<"#NUM_CONTRIBUTING_RAYS\n"<<contributingRays.size()<<endl;
732          sprintf(filename, "rss-crays-%04d.x3d", rssPass);
733          ExportRays(filename, contributingRays, mExportNumRays);
734        }
735
736       
737        // add rays to the tree after the viewcells have been cast to have their contributions
738        // already when adding into the tree
739        // do not add those rays which have too low or no contribution....
740       
741        if (mUseImportanceSampling) {
742          rssTree->AddRays(vssRays);
743         
744          if (0) {
745                cout<<"############# Rss PVS STAT ##################\n";
746                cout<<"#AVG_RSS_PVS\n"<<rssTree->GetAvgPvsSize()<<endl;
747                cout<<"#RSS_ROOT_PVS\n"<<rssTree->GetRootPvsSize()<<endl;
748          }
749         
750         
751          if (mUpdateSubdivision) {
752                int updatePasses = 1;
753                if (mPass % updatePasses == 0) {
754                  int subdivided = rssTree->UpdateSubdivision();
755                  cout<<"subdivided leafs = "<<subdivided<<endl;
756                  cout<<"#total leaves = "<<rssTree->stat.Leaves()<<endl;
757                }
758          }
759        }
760       
761
762       
763        if (mExportPvs) {
764          char filename[64];
765          sprintf(filename, "rss-pvs-%04d.x3d", rssPass);
766          ExportPvs(filename, rssTree);
767        }
768
769       
770        if (!mUseImportanceSampling)
771          CLEAR_CONTAINER(vssRays);
772
773        if (totalSamples >= mRssSamples + mInitialSamples)
774          break;
775
776       
777        rssPass++;
778        mPass++;
779        rssTree->SetPass(mPass);
780  }
781 
782  if (mUseViewcells) {
783
784
785  //-- render simulation after merge
786  cout << "\nevaluating bsp view cells render time after merge ... ";
787 
788  mRenderSimulator->RenderScene();
789  SimulationStatistics ss;
790  mRenderSimulator->GetStatistics(ss);
791
792  cout << " finished" << endl;
793  cout << ss << endl;
794  Debug << ss << endl;
795
796  }
797
798  delete rssTree;
799 
800  return true;
801}
802
Note: See TracBrowser for help on using the repository browser.