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

Revision 2008, 3.7 KB checked in by bittner, 18 years ago (diff)

ray sort update

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