Changeset 1473 for GTP/trunk/Lib
- Timestamp:
- 09/22/06 16:31:02 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 8 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 -
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h
r1460 r1473 3 3 4 4 #include <fstream> 5 #include <stack> 5 6 using namespace std; 6 7 … … 10 11 11 12 class Exporter; 13 class VssRay; 12 14 13 /** Sampling based visibility preprocessing. The implementation is based on heuristical 14 sampling of view space */ 15 16 typedef stack<VssRay *> RayQueue; 17 18 /** Sampling based visibility preprocessing. The implementation is 19 based on heuristical sampling of view space. 20 */ 15 21 class GvsPreprocessor : public Preprocessor { 16 22 17 23 public: 18 int mSamples; 19 20 GvsPreprocessor(); 21 ~GvsPreprocessor() {} 22 23 virtual bool ComputeVisibility(); 24 25 24 25 GvsPreprocessor(); 26 ~GvsPreprocessor() {} 27 28 virtual bool ComputeVisibility(); 29 30 26 31 protected: 27 ofstream mStats; 28 32 33 /** Runs the adaptive sampling. The method starts with a number of random rays given 34 by the queue and continues as long it finds new visible geometry (i.e., the queue is 35 not empty). 36 37 @returns the number of samples cast. 38 */ 39 int RunSampling(); 40 41 /** One pass of the sampling preprocessor. Continues as long as at least passSample 42 rays have been cast. 43 @returns the number of samples cast. 44 */ 45 int Pass(const int passSamples); 46 47 /** Generates the rays starting the adaptive visibility sampling process. 48 */ 49 int CastAvsSamples( 50 const int samplesPerPass, 51 const int sampleType, 52 RayQueue &passSamples); 53 54 /** Uses the information gained from the ray for doing adaptive border sampling. 55 This function tries to find the border of the triangle found visible by the 56 current ray. New rays are generated which sample this border. 57 58 We use the following strategies: 59 60 a) if new triangle was found: adaptive border sampling 61 b) if triangle was found reverse sampling 62 */ 63 int HandleRay(VssRay &ray); 64 65 /** 66 */ 67 int AdaptiveBorderSampling(VssRay &ray); 68 69 int ReverseSampling(VssRay &ray); 70 71 /** Cast samples according to a specific sampling strategy. 72 */ 73 int CastPassSamples( 74 const int samplesPerPass, 75 const int sampleType, 76 VssRayContainer &passSamples) const; 77 78 79 80 ////////////////////// 81 82 ofstream mStats; 83 int mSamples; 84 int mSamplesPerPass; 85 RayQueue mRayQueue; 86 int mSamplingType; 87 int mTotalSamples; 29 88 }; 30 89 -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r1449 r1473 603 603 void HierarchyManager::ResetObjectSpaceSubdivision(const ObjectContainer &objects) 604 604 { 605 Debug << "old bv hierarchy: " << mBvHierarchy->mBvhStats << endl; 605 Debug << "old bv hierarchy:\n " << mBvHierarchy->mBvhStats << endl; 606 cout << "resetting bv hierarchy" << endl; 606 607 mHierarchyStats.nodes -= mBvHierarchy->mBvhStats.nodes; 607 608 mHierarchyStats.mGlobalCostMisses = 0; // hack: reset global cost misses -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r1449 r1473 132 132 of split is chosen for view space / object space, the candidates for the next split of 133 133 object space / view space must be reevaluated. 134 135 134 */ 136 135 class HierarchyManager -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
r1315 r1473 328 328 <File 329 329 RelativePath="..\src\glInterface.h"> 330 </File> 331 <File 332 RelativePath=".\GvsPreprocessor.cpp"> 333 </File> 334 <File 335 RelativePath=".\GvsPreprocessor.h"> 330 336 </File> 331 337 <File -
GTP/trunk/Lib/Vis/Preprocessing/src/Ray.h
r1281 r1473 5 5 #include "Matrix4x4.h" 6 6 #include "Vector3.h" 7 //#include "ViewCellBsp.h" 7 8 8 9 9 namespace GtpVisibilityPreprocessor { -
GTP/trunk/Lib/Vis/Preprocessing/src/SubdivisionCandidate.h
r1313 r1473 17 17 enum {OBJECT_SPACE, VIEW_SPACE}; 18 18 19 /// the current split plane20 //AxisAlignedPlane mSplitPlane;21 /// split axis of this plane (0, 1, 2, or 3 if non-axis-aligned)22 int mSplitAxis;23 /// the number of misses of max cost ratio until this split24 int mMaxCostMisses;25 26 19 SubdivisionCandidate(): mRenderCostDecrease(0) {}; 27 20 … … 33 26 /** Set render cost decrease achieved through this split. 34 27 */ 35 void SetRenderCostDecrease(const float renderCostDecr)28 inline void SetRenderCostDecrease(const float renderCostDecr) 36 29 { 37 30 mRenderCostDecrease = renderCostDecr; 38 31 } 39 32 40 float GetRenderCostDecrease() const33 inline float GetRenderCostDecrease() const 41 34 { 42 35 return mRenderCostDecrease; … … 49 42 return mPosition; 50 43 } 44 45 /// split axis of this plane (0, 1, 2, or 3 if non-axis-aligned) 46 int mSplitAxis; 47 /// the number of misses of max cost ratio until this split 48 int mMaxCostMisses; 51 49 52 50 protected: -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1454 r1473 267 267 268 268 mPreprocessor->GenerateRays(samplesPerPass, sampleType, simpleRays); 269 Debug << "generated " << mInitialSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;269 Debug << "generated " << samplesPerPass << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 270 270 271 271 // shoot simple ray and add it to importance samples 272 272 mPreprocessor->CastRays(simpleRays, passSamples); 273 Debug << "cast " << mInitialSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;273 Debug << "cast " << samplesPerPass << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 274 274 275 275 return (int)passSamples.size(); … … 1835 1835 if (ray.mTerminationObject) 1836 1836 { 1837 // cout << "f";1838 if (viewcell->GetPvs().GetSampleContribution(ray.mTerminationObject,1839 ray.mPdf,1840 contribution))1837 if (viewcell->GetPvs().GetSampleContribution( 1838 ray.mTerminationObject, 1839 ray.mPdf, 1840 contribution)) 1841 1841 { 1842 1842 ++ ray.mPvsContribution;
Note: See TracChangeset
for help on using the changeset viewer.