source: GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp @ 1486

Revision 1486, 18.1 KB checked in by mattausch, 18 years ago (diff)

worked on guided visibility sampling

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