Changeset 1473 for GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
- Timestamp:
- 09/22/06 16:31:02 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
r1460 r1473 2 2 #include "GvsPreprocessor.h" 3 3 #include "GlRenderer.h" 4 #include "VssRay.h" 5 #include "ViewCellsManager.h" 6 7 4 8 5 9 namespace GtpVisibilityPreprocessor … … 7 11 8 12 9 GvsPreprocessor::GvsPreprocessor(): Preprocessor()13 GvsPreprocessor::GvsPreprocessor(): Preprocessor(), mSamplingType(0) 10 14 { 11 environment->GetIntValue("RenderSampler.samples", mSamples); 12 cout << "number of render samples: " << mSamples << endl; 13 } 14 15 Environment::GetSingleton()->GetIntValue("RenderSampler.samples", mSamples); 16 //Environment::GetSingleton()->GetIntValue("Render.samples", mTotalSamples); 15 17 16 void 17 GvsPreprocessor::GenerateRandomRay(Ray &ray) 18 { 19 int objId = RandomValue(0, mObjects.size()); 20 Intersectable *object = objects[objId]; 21 object->GetRandomSurfacePoint(point, normal); 22 direction = UniformRandomVector(normal); 23 SetupRay(ray, point, direction); 18 cout << "number of render samples: " << mSamples << endl; 24 19 } 25 20 26 void 27 GvsPreprocessor::HandleRay(Ray &ray)21 22 int GvsPreprocessor::HandleRay(VssRay &ray) 28 23 { 29 int sampleContributions = 0; 30 31 mKdTree->CastRay(ray); 32 33 if (ray.leaves.size()) { 34 sampleContributions += AddNodeSamples(object, ray, pass); 35 36 if (ray.intersections.size()) { 37 sampleContributions += AddNodeSamples(ray.intersections[0].mObject, ray, pass); 24 int sampleContributions = 0; 25 26 if (mViewCellsManager->ComputeSampleContribution(ray, true, false)) 27 { 28 return AdaptiveBorderSampling(ray); 38 29 } 39 } 30 else 31 { 32 return ReverseSampling(ray); 33 } 40 34 } 41 35 42 void 43 GvsPreprocessor::BorderSampling(Ray &ray)36 37 int GvsPreprocessor::AdaptiveBorderSampling(VssRay &ray) 44 38 { 45 46 39 // TODO 40 return 0; 47 41 } 48 42 49 void 50 GvsPreprocessor::Pass()43 44 int GvsPreprocessor::ReverseSampling(VssRay &ray) 51 45 { 52 Ray ray; 53 while (1) { 54 AvsGenerateRay(ray); 55 HandleRay(ray); 56 while ( !mRayQueue.empty() ) { 57 Ray ray = mRayQueue.pop(); 58 mRayQueue.pop(); 59 AdaptiveBorderSampling(ray); 46 // TODO 47 return 0; 48 } 49 50 int GvsPreprocessor::CastAvsSamples(const int samplesPerPass, 51 const int sampleType, 52 RayQueue &passSamples) 53 { 54 SimpleRayContainer simpleRays; 55 const long startTime = GetTime(); 56 57 GenerateRays(samplesPerPass, sampleType, simpleRays); 58 Debug << "generated " << samplesPerPass << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 59 60 VssRayContainer samples; 61 62 // cast the rays and optain hitpoints with geometry 63 CastRays(simpleRays, samples); 64 Debug << "cast " << samplesPerPass << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 65 66 // add to ray queue 67 VssRayContainer::const_iterator vit, vit_end = samples.end(); 68 69 for (vit = samples.begin(); vit != vit_end; ++ vit) 70 { 71 mRayQueue.push(*vit); 60 72 } 61 } 73 74 return (int)mRayQueue.size(); 75 } 76 77 78 int GvsPreprocessor::Pass(const int passSamples) 79 { 80 int castSamples = 0; 81 const int uniformSamples = 1000; 82 83 while (castSamples < passSamples) 84 { 85 // Ray queue empty => 86 // cast a number of uniform samples to fill ray Queue 87 CastAvsSamples(uniformSamples, mSamplingType, mRayQueue); 88 castSamples += Pass(passSamples); 89 } 90 91 return castSamples; 92 } 93 94 95 int GvsPreprocessor::RunSampling() 96 { 97 int castSamples = 0; 98 99 while (!mRayQueue.empty()) 100 { 101 // handle next ray 102 VssRay *ray = mRayQueue.top(); 103 mRayQueue.pop(); 104 105 castSamples += HandleRay(*ray); 106 } 107 108 return castSamples; 62 109 } 63 110 … … 66 113 GvsPreprocessor::ComputeVisibility() 67 114 { 68 long startTime = GetTime(); 115 Randomize(0); 116 const long startTime = GetTime(); 117 118 cout<<"Gvs Preprocessor started\n"<<flush; 119 120 /// construct the view cells first 121 ConstructViewCells(); 69 122 123 int samples = 0; 70 124 71 Debug << "type: gvs" << endl; 72 73 cout<<"Gvs Preprocessor started\n"<<flush; 74 // cout<<"Memory/ray "<<sizeof(VssRay)+sizeof(RssTreeNode::RayInfo)<<endl; 125 while (samples < mTotalSamples) 126 { 127 samples += Pass(mSamplesPerPass); 128 129 cout<<"+"; 130 131 // mVssRays.PrintStatistics(mStats); 132 //mStats << "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl 133 // << "#TotalSamples\n" << samples << endl; 75 134 76 Randomize(0); 77 78 long startTime = GetTime(); 79 80 int totalSamples = 0; 81 82 ConstructViewCells(); 83 84 int samples = 0; 85 int i=0; 86 while (samples < mTotalSamples) { 87 for (i=0; i < mSamplesPerPass; i++, samples++) { 88 89 if (i%10000 == 0) 90 cout<<"+"; 91 92 Vector3 origin, direction; 93 mViewCellsManager->GetViewPoint(origin); 94 direction = UniformRandomVector(); 95 96 ViewCell *viewcell = mViewCellsManager->GetViewCell(origin); 97 98 if (viewcell && viewcell->GetValid()) { 99 // cast rays in both directions to make the number of samples comparable 100 // with the global sampling method which also casts a "double" ray per sample 101 for (int j=0; j < 2; j++) { 102 Intersectable *object = CastRay(origin, direction); 103 if (object) { 104 // if ray not outside of view space 105 float contribution; 106 int pvsContribution = 0; 107 float relativePvsContribution = 0; 108 if (object) { 109 float pdf = 1.0f; 110 if (viewcell->GetPvs().GetSampleContribution(object, 111 pdf, 112 contribution)) 113 ++pvsContribution; 114 relativePvsContribution += contribution; 115 viewcell->GetPvs().AddSample(object, pdf); 116 } 117 } 118 direction = -direction; 119 } 120 } 121 122 if (samples > mTotalSamples) 123 break; 135 mViewCellsManager->PrintPvsStatistics(mStats); 136 // ComputeRenderError(); 124 137 } 125 126 // mVssRays.PrintStatistics(mStats);127 mStats <<128 "#Time\n" << TimeDiff(startTime, GetTime())*1e-3<<endl<<129 "#TotalSamples\n" <<samples<<endl;130 138 131 mViewCellsManager->PrintPvsStatistics(mStats); 132 // ComputeRenderError(); 133 } 134 135 // HoleSamplingPass(); 136 if (0) { 137 Exporter *exporter = Exporter::GetExporter("ray-density.x3d"); 138 exporter->SetExportRayDensity(true); 139 exporter->ExportKdTree(*mKdTree); 140 delete exporter; 141 } 142 143 144 // $$JB temporary removed 145 // mViewCellsManager->PostProcess(objects, mSampleRays); 146 147 //-- several visualizations and statistics 148 Debug << "view cells after post processing: " << endl; 149 mViewCellsManager->PrintStatistics(Debug); 150 151 //-- render simulation after merge 152 cout << "\nevaluating bsp view cells render time after merge ... "; 153 154 mRenderSimulator->RenderScene(); 155 SimulationStatistics ss; 156 mRenderSimulator->GetStatistics(ss); 157 158 cout << " finished" << endl; 159 cout << ss << endl; 160 Debug << ss << endl; 161 162 // $$JB temporary removed 163 //mViewCellsManager->Visualize(objects, mSampleRays); 164 165 return true; 139 return true; 166 140 } 167 141
Note: See TracChangeset
for help on using the changeset viewer.