source: GTP/trunk/Lib/Vis/Preprocessing/src/CombinedPreprocessor.cpp @ 2012

Revision 2012, 3.9 KB checked in by bittner, 17 years ago (diff)

vss ray updates

  • Property svn:executable set to *
RevLine 
[1891]1#include "SceneGraph.h"
2#include "KdTree.h"
3#include "X3dExporter.h"
4#include "Environment.h"
5#include "Polygon3.h"
6#include "VssRay.h"
7#include "RssTree.h"
8#include "ViewCellsManager.h"
9#include "RenderSimulator.h"
10#include "GlRenderer.h"
11#include "SamplingStrategy.h"
12#include "PreprocessorThread.h"
13#include "CombinedPreprocessor.h"
[2012]14#include "RayCaster.h"
[1891]15
16
17namespace GtpVisibilityPreprocessor {
18
[1966]19const bool pruneInvalidRays = true;
[1891]20
21 
22  CombinedPreprocessor::CombinedPreprocessor():
23        Preprocessor()
24  {
25        // this should increase coherence of the samples
[1966]26//      Environment::GetSingleton()->GetIntValue("RssPreprocessor.vssSamples", mTotalSamples);
27//      Environment::GetSingleton()->GetIntValue("RssPreprocessor.samplesPerPass", mSamplesPerPass);
28//      Environment::GetSingleton()->GetIntValue("RssPreprocessor.vssSamplesPerPass",
29//                                                                                       mSamplesPerEvaluation);
[1891]30       
31       
32  }
33 
34
35bool
36CombinedPreprocessor::ComputeVisibility()
37{
38 
39  Debug << "Preprocessor type: combined" << endl;
40  cout<<"Combined Preprocessor started\n"<<flush;
41 
42  // if not already loaded, construct view cells from file
43  if (!mLoadViewCells) {
44        // construct view cells using it's own set of samples
45        mViewCellsManager->Construct(this);
46       
47        //-- several visualizations and statistics
48        Debug << "view cells construction finished: " << endl;
49        mViewCellsManager->PrintStatistics(Debug);
50  }
51 
52 
53  // now decode distribution string
54  char buff[1024];
55  Environment::GetSingleton()->GetStringValue("RssPreprocessor.distributions",
56                                                                                          buff);
57 
[2002]58 
[1891]59  mMixtureDistribution = new MixtureDistribution(*this);
60  mMixtureDistribution->Construct(buff);
61 
62  SimpleRayContainer rays;
63  VssRayContainer vssRays;
64
65  int lastEvaluation = 0;
66  int totalVssRays = 0;
67  mPass = 0;
68 
[2002]69  vector<VssRayContainer> rayBuffer;
[2012]70  rays.reserve(mSamplesPerPass);
71  rayBuffer.reserve(2*mSamplesPerPass);
[2002]72 
[1891]73  long startTime = GetTime();
74  for (int i=0; i < mTotalSamples; i += mSamplesPerPass, mPass++) {
[2012]75        mRayCaster->InitPass();
76       
[1891]77        cout<<"Progress : "<<(100.0f*i)/mTotalSamples<<"%"<<endl;
78        rays.clear();
79        vssRays.clear();
80       
[2012]81       
[1891]82        mMixtureDistribution->GenerateSamples(mSamplesPerPass, rays);
[1984]83
84        bool doubleRays = true;
85        CastRays(rays, vssRays, doubleRays, pruneInvalidRays);
[1894]86        totalVssRays += (int)vssRays.size();
[1900]87
[1942]88        mMixtureDistribution->ComputeContributions(vssRays);
89
[1900]90        if (mExportRays) {
91          Debug<<"Exporting rays..."<<endl<<flush;
92          char filename[256];
[1942]93
94          VssRayContainer contributingRays;
95          vssRays.GetContributingRays(contributingRays, 0);
96          sprintf(filename, "rss-crays-%04d.x3d", mPass);
97          ExportRays(filename, contributingRays, mExportNumRays);
98
[1900]99          sprintf(filename, "rss-rays-i%04d.x3d", mPass);
100          ExportRays(filename, vssRays, mExportNumRays);
[1942]101
[2002]102
103          if (mExportAnimation) {
104                rayBuffer.push_back(VssRayContainer());
105                vssRays.SelectRays(mExportNumRays, rayBuffer[rayBuffer.size()-1], true);
106          }
107
[1900]108          Debug<<"done."<<endl<<flush;
109        }
110
[1942]111        mMixtureDistribution->UpdateDistributions(vssRays);
112       
[1900]113        if (i - lastEvaluation >= mSamplesPerEvaluation) {
114          mViewCellsManager->PrintPvsStatistics(mStats);
115          mStats <<
116                "#Pass\n" <<mPass<<endl<<
117                "#Time\n" << TimeDiff(startTime, GetTime())<<endl<<
118                "#TotalSamples\n" <<i<<endl<<
119                "#RssSamples\n" <<totalVssRays<<endl;
120          lastEvaluation = i;
[2002]121
122          if (renderer) {
123                ComputeRenderError();
124          }
125         
[1900]126        }
127
[2012]128#if 0
[1966]129        cerr<<"deleting rays"<<endl;
130        //clear all unreferenced rays
131        for (int j=0; j < vssRays.size(); j++) {
132          if (vssRays[j]->RefCount() == 0)
133                delete vssRays[j];
134        }
135        cerr<<"done."<<endl;
[2012]136#endif 
[1900]137       
[1966]138        //      if (!mMixtureDistribution->RequiresRays())
139        //        CLEAR_CONTAINER(vssRays);
[1931]140
141       
[1891]142  }
[2002]143 
[1942]144  EvalViewCellHistogram();
145
[2002]146  if (mExportAnimation && mExportRays) {
147        char filename[64];
148        sprintf(filename, "rss-rays-i.x3d");
149        //rayBuffer.resize(mPass);
150        ExportRayAnimation(filename, rayBuffer);
151  }
152
[1894]153  return true;
[1891]154}
155
156}
Note: See TracBrowser for help on using the repository browser.