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

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