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

Revision 2036, 4.2 KB checked in by bittner, 17 years ago (diff)

dummy kd tree preparation

  • 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 :"<<mTotalSamples/1e6f<<"M rays, "<<(100.0f*i)/mTotalSamples<<"%"<<endl;
84       
85        rays.clear();
86        vssRays.clear();
87       
88       
89        mMixtureDistribution->GenerateSamples(mSamplesPerPass, rays);
90       
91        bool doubleRays = true;
92        CastRays(rays, vssRays, doubleRays, pruneInvalidRays);
93        totalVssRays += (int)vssRays.size();
94
95        mMixtureDistribution->ComputeContributions(vssRays);
96
97        //cout<<"view cell cast time:"<<viewCellCastTimer.TotalTime()<<" s"<<endl;
98        //cout<<"pvs time:"<<pvsTimer.TotalTime()<<" s"<<endl;
99        //cout<<"obj time:"<<objTimer.TotalTime()<<" s"<<endl;
100
101        if (mExportRays) {
102          Debug<<"Exporting rays..."<<endl<<flush;
103          char filename[256];
104
105          VssRayContainer contributingRays;
106          vssRays.GetContributingRays(contributingRays, 0);
107          sprintf(filename, "rss-crays-%04d.x3d", mPass);
108          ExportRays(filename, contributingRays, mExportNumRays);
109
110          sprintf(filename, "rss-rays-i%04d.x3d", mPass);
111          ExportRays(filename, vssRays, mExportNumRays);
112
113
114          if (mExportAnimation) {
115                rayBuffer.push_back(VssRayContainer());
116                vssRays.SelectRays(mExportNumRays, rayBuffer[rayBuffer.size()-1], true);
117          }
118
119          Debug<<"done."<<endl<<flush;
120        }
121
122        mMixtureDistribution->UpdateDistributions(vssRays);
123       
124        if (i - lastEvaluation >= mSamplesPerEvaluation) {
125          mViewCellsManager->PrintPvsStatistics(mStats);
126          mStats <<
127                "#Pass\n" <<mPass<<endl<<
128                "#Time\n" << TimeDiff(startTime, GetTime())<<endl<<
129                "#TotalSamples\n" <<i<<endl<<
130                "#RssSamples\n" <<totalVssRays<<endl;
131          lastEvaluation = i;
132
133          if (renderer) {
134                ComputeRenderError();
135          }
136         
137        }
138
139#if 0
140        cerr<<"deleting rays"<<endl;
141        //clear all unreferenced rays
142        for (int j=0; j < vssRays.size(); j++) {
143          if (vssRays[j]->RefCount() == 0)
144                delete vssRays[j];
145        }
146        cerr<<"done."<<endl;
147#endif 
148       
149        //      if (!mMixtureDistribution->RequiresRays())
150        //        CLEAR_CONTAINER(vssRays);
151
152       
153  }
154 
155  EvalViewCellHistogram();
156
157  if (mExportAnimation && mExportRays) {
158        char filename[64];
159        sprintf(filename, "rss-rays-i.x3d");
160        //rayBuffer.resize(mPass);
161        ExportRayAnimation(filename, rayBuffer);
162  }
163
164  return true;
165}
166
167}
Note: See TracBrowser for help on using the repository browser.