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

Revision 2049, 4.0 KB checked in by bittner, 17 years ago (diff)

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