Changeset 440 for trunk/VUT/GtpVisibilityPreprocessor
- Timestamp:
- 11/30/05 18:02:55 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 2 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
r438 r440 103 103 ExportBspLeaves(const BspTree &tree, const int maxPvs = 0) = 0; 104 104 105 virtual void 106 ExportGeometry(const ObjectContainer &objects) = 0; 107 105 108 void SetExportRayDensity(const bool d) { mExportRayDensity = d; } 106 109 -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r439 r440 40 40 41 41 filenames.push_back(string(str, pos, str.size() - pos)); 42 return filenames.size();42 return (int)filenames.size(); 43 43 } 44 44 … … 161 161 } 162 162 163 164 void Preprocessor::ExportSplits(const ObjectContainer &objects,165 const RayContainer &sampleRays,166 const int visSamples)167 {168 Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d");169 170 if (exporter)171 {172 Material m;173 m.mDiffuseColor = RgbColor(1, 0, 0);174 exporter->SetForcedMaterial(m);175 exporter->SetWireframe();176 exporter->ExportBspSplits(*mBspTree, true);177 178 // take forced material, else big scenes cannot be viewed179 m.mDiffuseColor = RgbColor(0, 1, 0);180 exporter->SetForcedMaterial(m);181 exporter->SetFilled();182 183 exporter->ResetForcedMaterial();184 185 // export rays186 if (0)187 {188 RayContainer outRays;189 190 for (int i = 0; i < sampleRays.size(); ++ i)191 {192 // only rays piercing geometry193 if (!sampleRays[i]->intersections.empty())194 outRays.push_back(sampleRays[i]);195 }196 if (BspTree::sConstructionMethod == BspTree::FROM_SAMPLES)197 {198 // export rays199 exporter->ExportRays(outRays, 1000, RgbColor(1, 1, 0));200 }201 }202 203 if (1)204 ExportSceneGeometry(exporter, objects);205 206 delete exporter;207 }208 }209 210 inline bool vc_gt(ViewCell *a, ViewCell *b)211 {212 return a->GetPvs().GetSize() > b->GetPvs().GetSize();213 }214 215 void Preprocessor::ExportBspPvs(const ObjectContainer &objects,216 const RayContainer &sampleRays,217 const int visSamples)218 {219 const int leafOut = 10;220 221 ViewCell::NewMail();222 223 //-- some rays for output224 const int raysOut = min((int)sampleRays.size(), visSamples);225 cout << "visualization using " << visSamples << " samples" << endl;226 vector<Ray *> vcRays[leafOut];227 228 if (0)229 {230 //-- some random view cells and rays for output231 vector<BspLeaf *> bspLeaves;232 233 for (int i = 0; i < leafOut; ++ i)234 bspLeaves.push_back(mBspTree->GetRandomLeaf());235 236 for (int i = 0; i < bspLeaves.size(); ++ i)237 {238 cout << "creating output for view cell " << i << " ... ";239 // check whether we can add the current ray to the output rays240 for (int k = 0; k < raysOut; ++ k)241 {242 Ray *ray = sampleRays[k];243 244 for (int j = 0; j < (int)ray->bspIntersections.size(); ++ j)245 {246 BspLeaf *leaf = ray->bspIntersections[j].mLeaf;247 248 if (bspLeaves[i]->GetViewCell() == leaf->GetViewCell())249 {250 vcRays[i].push_back(ray);251 }252 }253 }254 255 Intersectable::NewMail();256 257 BspViewCell *vc = dynamic_cast<BspViewCell *>(bspLeaves[i]->GetViewCell());258 259 //bspLeaves[j]->Mail();260 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i);261 262 Exporter *exporter = Exporter::GetExporter(s);263 exporter->SetFilled();264 265 ViewCellPvsMap::iterator it = vc->GetPvs().mEntries.begin();266 267 exporter->SetWireframe();268 //exporter->SetFilled();269 270 Material m;//= RandomMaterial();271 m.mDiffuseColor = RgbColor(0, 1, 0);272 exporter->SetForcedMaterial(m);273 274 if (vc->GetMesh())275 exporter->ExportViewCell(vc);276 else277 {278 PolygonContainer cell;279 // export view cell geometry280 mBspTree->ConstructGeometry(vc, cell);281 exporter->ExportPolygons(cell);282 CLEAR_CONTAINER(cell);283 }284 285 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize()286 << ", piercing rays=" << (int)vcRays[i].size() << endl;287 288 // export rays piercing this view cell289 exporter->ExportRays(vcRays[i], 1000, RgbColor(0, 1, 0));290 291 m.mDiffuseColor = RgbColor(1, 0, 0);292 exporter->SetForcedMaterial(m);293 294 // exporter->SetWireframe();295 exporter->SetFilled();296 297 // output PVS of view cell298 for (; it != vc->GetPvs().mEntries.end(); ++ it)299 {300 Intersectable *intersect = (*it).first;301 if (!intersect->Mailed())302 {303 exporter->ExportIntersectable(intersect);304 intersect->Mail();305 }306 }307 308 // output rest of the objects309 if (0)310 {311 Material m;//= RandomMaterial();312 m.mDiffuseColor = RgbColor(0, 0, 1);313 exporter->SetForcedMaterial(m);314 315 for (int j = 0; j < objects.size(); ++ j)316 if (!objects[j]->Mailed())317 {318 exporter->SetForcedMaterial(m);319 exporter->ExportIntersectable(objects[j]);320 objects[j]->Mail();321 }322 }323 DEL_PTR(exporter);324 cout << "finished" << endl;325 }326 }327 else328 {329 ViewCellContainer viewCells;330 331 mBspTree->CollectViewCells(viewCells);332 stable_sort(viewCells.begin(), viewCells.end(), vc_gt);333 334 int limit = min(leafOut, (int)viewCells.size());335 336 for (int i = 0; i < limit; ++ i)337 {338 cout << "creating output for view cell " << i << " ... ";339 340 Intersectable::NewMail();341 BspViewCell *vc = dynamic_cast<BspViewCell *>(viewCells[i]);342 343 cout << "creating output for view cell " << i << " ... ";344 // check whether we can add the current ray to the output rays345 for (int k = 0; k < raysOut; ++ k)346 {347 Ray *ray = sampleRays[k];348 349 for (int j = 0; j < (int)ray->bspIntersections.size(); ++ j)350 {351 BspLeaf *leaf = ray->bspIntersections[j].mLeaf;352 353 if (vc == leaf->GetViewCell())354 {355 vcRays[i].push_back(ray);356 }357 }358 }359 360 //bspLeaves[j]->Mail();361 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i);362 363 Exporter *exporter = Exporter::GetExporter(s);364 365 exporter->SetWireframe();366 367 Material m;//= RandomMaterial();368 m.mDiffuseColor = RgbColor(0, 1, 0);369 exporter->SetForcedMaterial(m);370 371 if (vc->GetMesh())372 exporter->ExportViewCell(vc);373 else374 {375 PolygonContainer cell;376 // export view cell377 mBspTree->ConstructGeometry(vc, cell);378 exporter->ExportPolygons(cell);379 CLEAR_CONTAINER(cell);380 }381 382 383 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize()384 << ", piercing rays=" << (int)vcRays[i].size() << endl;385 386 387 // export rays piercing this view cell388 exporter->ExportRays(vcRays[i], 1000, RgbColor(0, 1, 0));389 390 m.mDiffuseColor = RgbColor(1, 0, 0);391 exporter->SetForcedMaterial(m);392 393 ViewCellPvsMap::const_iterator it,394 it_end = vc->GetPvs().mEntries.end();395 396 // output PVS of view cell397 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it)398 {399 Intersectable *intersect = (*it).first;400 if (!intersect->Mailed())401 {402 Material m = RandomMaterial();403 404 exporter->SetForcedMaterial(m);405 406 exporter->ExportIntersectable(intersect);407 intersect->Mail();408 }409 }410 411 DEL_PTR(exporter);412 cout << "finished" << endl;413 }414 }415 }416 417 418 void Preprocessor::ExportSceneGeometry(Exporter *exporter,419 const ObjectContainer &objects)420 {421 Material m;//= RandomMaterial();422 m.mDiffuseColor = RgbColor(0, 1, 0);423 exporter->SetForcedMaterial(m);424 exporter->SetWireframe();425 426 for (int j = 0; j < objects.size(); ++ j)427 exporter->ExportIntersectable(objects[j]);428 }429 430 163 bool Preprocessor::PrepareViewCells() 431 164 { … … 436 169 if (strcmp(viewCellsStr, "kdTree") == 0) 437 170 { 438 //mViewCellsManager = new KdViewCellsManager(mKdTree);171 mViewCellsManager = new KdViewCellsManager(mKdTree); 439 172 } 440 173 if (strcmp(viewCellsStr, "bspTree") == 0) 441 174 { 442 //mViewCellsManager = new BspViewCellsManager(mBspTree, mBspConstructionSamples); 175 int bspConstructionSamples = 0; 176 177 environment->GetIntValue("BspTree.Construction.samples", bspConstructionSamples); 178 mViewCellsManager = new BspViewCellsManager(mBspTree, bspConstructionSamples); 443 179 } 444 180 else if (strcmp(viewCellsStr, "vspTree") == 0) 445 181 { 446 //mViewCellsManager = new VspKdViewCellContaienr(mVspKdTree, mVspKdConstructionSamples); 182 int vspKdConstructionSamples = 0; 183 184 environment->GetIntValue("VspKdTree.Construction.samples", vspKdConstructionSamples); 185 mViewCellsManager = new VspKdViewCellsManager(mVspKdTree, vspKdConstructionSamples); 447 186 } 448 187 else if (strcmp(viewCellsStr, "sceneDependent") == 0) 449 188 { 450 189 //TODO 451 //mViewCellsManager = new BspViewCellContainer(mBspTree); 190 int bspConstructionSamples = 0; 191 192 environment->GetIntValue("BspTree.Construction.samples", bspConstructionSamples); 193 mViewCellsManager = new BspViewCellsManager(mBspTree, bspConstructionSamples); 452 194 } 453 195 else … … 457 199 } 458 200 201 int postProcessSamples = 0; 202 int visSamples = 0; 203 204 environment->GetIntValue("ViewCells.PostProcessing.samples", postProcessSamples); 205 environment->GetIntValue("BspTree.Visualization.samples", visSamples); 206 207 mViewCellsManager->SetPostProcessSamples(postProcessSamples); 208 mViewCellsManager->SetVisualizationSamples(visSamples); 209 210 459 211 //-- parse view cells construction method 212 460 213 bool loadViewCells = false; 461 214 environment->GetBoolValue("ViewCell.Construction.loadFromFile", loadViewCells); -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h
r439 r440 100 100 101 101 protected: 102 void ExportBspPvs(const ObjectContainer &objects,103 const RayContainer &sampleRays,104 const int visSamples);105 102 106 void ExportSplits(const ObjectContainer &objects, 107 const RayContainer &sampleRays, 108 const int visSamples); 103 ///////////////////////// 109 104 110 /** Export scene geometry. 111 */ 112 void ExportSceneGeometry(Exporter *exporter, const ObjectContainer &objects); 113 105 /// samples used for construction of the BSP view cells tree. 114 106 int mBspConstructionSamples; 107 /// samples used for construction of the VSP KD tree. 108 int mVspKdConstructionSamples; 115 109 }; 116 110 -
trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp
r439 r440 53 53 /* class BspRenderSimulator implementation */ 54 54 /********************************************************/ 55 BspRenderSimulator::BspRenderSimulator(BspTree *bspTree): 56 mBspTree(bspTree) 57 { 58 } 55 59 56 60 BspRenderSimulator::BspRenderSimulator(float objRenderCost, … … 149 153 KdTree *kdTree): 150 154 RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mKdTree(kdTree) 155 { 156 } 157 158 KdRenderSimulator::KdRenderSimulator(KdTree *kdTree): 159 mKdTree(kdTree) 151 160 { 152 161 } -
trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.h
r439 r440 84 84 { 85 85 public: 86 BspRenderSimulator(BspTree *bspTree); 87 86 88 BspRenderSimulator(float objRenderCost, 87 89 float vcOverhead, … … 104 106 { 105 107 public: 108 KdRenderSimulator(KdTree *kdTree); 109 106 110 KdRenderSimulator(float objRenderCost, 107 111 float vcOverhead, -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r439 r440 15 15 environment->GetIntValue("Sampling.samplesPerPass", mSamplesPerPass); 16 16 environment->GetIntValue("Sampling.totalSamples", mTotalSamples); 17 environment->GetIntValue("BspTree.Construction.samples", mBspConstructionSamples);18 environment->GetIntValue("VspKdTree.Construction.samples", mVspConstructionSamples);19 environment->GetIntValue("ViewCells.PostProcessing.samples", mPostProcessSamples);20 environment->GetIntValue("BspTree.Visualization.samples", mVisualizationSamples);21 17 22 mKdPvsDepth = 100;23 18 mStats.open("stats.log"); 24 19 } … … 27 22 { 28 23 CLEAR_CONTAINER(mSampleRays); 29 CLEAR_CONTAINER(mVs pSampleRays);24 CLEAR_CONTAINER(mVssSampleRays); 30 25 } 31 26 … … 34 29 const Vector3 &point, 35 30 const Vector3 &direction, 36 const int type) 31 const int type, 32 const Ray::Intersection &origin) 37 33 { 38 34 ray.intersections.clear(); … … 40 36 ray.testedObjects.clear(); 41 37 ray.bspIntersections.clear(); 38 42 39 ray.mFlags |= Ray::STORE_KDLEAVES | Ray::STORE_BSP_INTERSECTIONS; 43 40 // cout<<point<<" "<<direction<<endl; 44 41 ray.Init(point, direction, type); 45 } 46 47 KdNode * 48 SamplingPreprocessor::GetNodeForPvs(KdLeaf *leaf) 49 { 50 KdNode *node = leaf; 51 while (node->mParent && node->mDepth > mKdPvsDepth) 52 node = node->mParent; 53 return node; 54 } 55 56 int 57 SamplingPreprocessor::AddNodeSamples(const Ray &ray, 58 Intersectable *sObject, 59 Intersectable *tObject 60 ) 61 { 62 int contributingSamples = 0; 63 int j; 64 int objects = 0; 65 if (sObject) 66 objects++; 67 if (tObject) 68 objects++; 69 70 if (objects) { 71 for (j=0; j < ray.kdLeaves.size(); j++) { 72 KdNode *node = GetNodeForPvs( ray.kdLeaves[j] ); 73 if (sObject) 74 contributingSamples += sObject->mKdPvs.AddSample(node); 75 if (tObject) 76 contributingSamples += tObject->mKdPvs.AddSample(node); 77 } 78 } 79 80 for (j=1; j < ((int)ray.kdLeaves.size() - 1); j++) { 81 ray.kdLeaves[j]->AddPassingRay2(ray, 82 objects, 83 ray.kdLeaves.size() 84 ); 85 } 86 87 return contributingSamples; 88 } 89 42 ray.sourceObject = origin; 43 } 90 44 91 45 void … … 102 56 } 103 57 104 int SamplingPreprocessor::AddObjectSamples(Intersectable *obj, const Ray &ray)105 {106 int contributingSamples = 0;107 int j;108 58 109 // object can be seen from the view cell => add to view cell pvs 110 /*for (j=0; j < ray.bspIntersections.size(); ++ j) 59 int 60 SamplingPreprocessor::CastRays(const RayContainer &rays, 61 int &sampleContributions, 62 int &contributingSamples) 111 63 { 112 BspLeaf *leaf = ray.bspIntersections[j].mLeaf; 113 // if ray not in unbounded space 114 if (leaf->GetViewCell() != &mUnbounded) 115 contributingSamples += 116 leaf->GetViewCell()->GetPvs().AddSample(obj); 117 }*/ 64 // cast ray to KD tree to find intersection with other objects 65 RayContainer::const_iterator it, it_end = rays.end(); 118 66 119 // rays passing through this viewcell 120 /*if (mPass > 1) 121 for (j=1; j < ((int)ray.bspIntersections.size() - 1); ++ j) 122 { 123 BspLeaf *leaf = ray.bspIntersections[j].mLeaf; 124 125 if (leaf->GetViewCell() != &mUnbounded) 126 leaf->GetViewCell()-> 127 AddPassingRay(ray, contributingSamples ? 1 : 0); 128 } 129 */ 130 return contributingSamples; 131 } 132 67 for (it = rays.begin(); it != it_end; ++it) 68 mKdTree->CastRay((*it)); 69 70 sampleContributions = mViewCellsManager->CastRays(rays); 71 } 133 72 134 73 int 135 SamplingPreprocessor::CastRay(Intersectable *object, Ray &ray) 136 { 137 int sampleContributions = 0; 138 139 /* long t1 = GetRealTime(); 74 SamplingPreprocessor::CastRay(const Ray &ray) 75 { 140 76 // cast ray to KD tree to find intersection with other objects 141 77 mKdTree->CastRay(ray); 142 long t2 = GetRealTime(); 143 144 if (0 && object && object->GetId() > 2197) { 145 object->Describe(cout)<<endl; 146 cout<<ray<<endl; 147 } 148 149 switch(ViewCell::sHierarchy) 150 { 151 case ViewCell::BSP: 152 153 //-- cast ray to BSP tree to get intersection with view cells 154 if (!mBspTree) 155 break; 156 157 mBspTree->CastRay(ray); 158 159 if (object) 160 sampleContributions += AddObjectSamples(object, ray); 161 162 if (!ray.intersections.empty()) // second intersection found 163 { 164 sampleContributions += 165 AddObjectSamples(ray.intersections[0].mObject, ray); 166 } 167 break; 168 case ViewCell::KD: 169 if (ray.kdLeaves.size()) 170 { 171 Intersectable *terminator = 172 ray.intersections.size() ? ray.intersections[0].mObject: NULL; 173 174 sampleContributions += AddNodeSamples(ray, 175 object, 176 terminator); 177 } 178 break; 179 case ViewCell::VSP: 180 // TODO: 181 break; 182 default: 183 Debug << "Should never come here" << endl; 184 break; 185 } 186 */ 187 return sampleContributions; 78 79 return mViewCellsManager->CastRay(ray); 188 80 } 189 81 … … 265 157 Vector3 target = t*poly.mVertices[edge] + (1.0f-t)*poly.mVertices[(edge + 1)% 266 158 poly.mVertices.size()]; 267 SetupRay(ray, point, target - point, Ray::LOCAL_RAY );159 SetupRay(ray, point, target - point, Ray::LOCAL_RAY, Ray::Intersection(0, object, 0)); 268 160 if (!mesh->CastRay(ray, mi)) { 269 161 // the rays which intersect the mesh have been discarded since they are not tangent 270 162 // to the mesh 271 163 rays++; 272 edgeSamplesContributions += CastRay( object,ray);164 edgeSamplesContributions += CastRay(ray); 273 165 } 274 166 } … … 347 239 SamplingPreprocessor::ComputeVisibility() 348 240 { 349 350 241 // pickup an object 351 242 ObjectContainer objects; 352 243 244 /// rays per pass 245 RayContainer passRays; 246 353 247 mSceneGraph->CollectObjects(&objects); 354 248 355 249 Vector3 point, normal, direction; 356 Ray ray;250 //Ray ray; 357 251 358 252 long startTime = GetTime(); … … 361 255 int totalSamples = 0; 362 256 363 int pvsOut = Min((int)objects.size(), 10);364 257 int pvsSize = 0; 365 366 RayContainer rays[10];367 258 368 259 while (totalSamples < mTotalSamples) { … … 374 265 int reverseSamples = 0; 375 266 376 377 //cout << "totalSamples: " << totalSamples << endl;378 379 267 for (i = 0; i < objects.size(); i++) { 380 268 … … 383 271 384 272 int pvsSize = 0; 385 //if (ViewCell::sHierarchy == ViewCell::KD)386 // pvsSize = object->mKdPvs.GetSize();387 388 273 389 274 if (0 && pvsSize && mPass == 1000 ) { … … 394 279 395 280 bool viewcellSample = true; 396 int sampleContributions;281 //int sampleContributions; 397 282 bool debug = false; //(object->GetId() >= 2199); 398 283 if (viewcellSample) { … … 423 308 } 424 309 310 Ray *ray = new Ray(); 311 312 // the source object 313 Ray::Intersection source = 314 Ray::Intersection(0, reverseSample ? NULL : object, faceIndex); 315 425 316 // construct a ray 426 SetupRay(ray, point, direction, Ray::LOCAL_RAY); 427 428 sampleContributions = CastRay(reverseSample ? NULL : object, ray); 317 SetupRay(*ray, point, direction, Ray::LOCAL_RAY, source); 318 passRays.push_back(ray); 429 319 430 320 //-- CORR matt: put block inside loop 431 if (sampleContributions) {321 /*if (sampleContributions) { 432 322 passContributingSamples ++; 433 323 passSampleContributions += sampleContributions; 434 } 435 436 if ( i < pvsOut ) { 437 Ray *nray = new Ray(ray); 438 rays[i].push_back(nray); 439 } 440 441 if (!ray.intersections.empty()) { 442 // check whether we can add this to the rays 443 for (int j = 0; j < pvsOut; j++) { 444 if (objects[j] == ray.intersections[0].mObject) { 445 Ray *nray = new Ray(ray); 446 rays[j].push_back(nray); 447 } 448 } 449 } 324 }*/ 325 450 326 //------------------- 451 327 ProcessViewCells(ray, 452 reverseSample ? NULL : object, 453 faceIndex, 328 objects, 454 329 passContributingSamples, 455 330 passSampleContributions); … … 465 340 } 466 341 342 CastRays(passRays, passSampleContributions, passContributingSamples); 343 CLEAR_CONTAINER(passRays); 344 passRays.clear(); 345 467 346 totalSamples += passSamples; 468 347 … … 472 351 mPass++; 473 352 474 // TODO: move into view cell container475 /*if (ViewCell::sHierarchy == ViewCell::KD)476 {477 pvsSize = 0;478 479 for (i=0; i < objects.size(); i++) {480 Intersectable *object = objects[i];481 pvsSize += object->mKdPvs.GetSize();482 }483 }484 else485 353 pvsSize += passSampleContributions; 486 */354 487 355 float avgRayContrib = (passContributingSamples > 0) ? 488 356 passSampleContributions/(float)passContributingSamples : 0; … … 506 374 } 507 375 508 // if (ViewCell::sHierarchy == ViewCell::KD) 509 cout << "#totalKdPvsSize=" << mKdTree->CollectLeafPvs() << endl; 510 511 //-- render simulation 512 cout << "\nevaluating bsp view cells render time before merge ... "; 513 514 SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 515 516 cout << " finished" << endl; 517 cout << ss << endl; 518 Debug << ss << endl; 519 520 if (mBspTree) 521 { 522 //-- post processing of bsp view cells 523 int vcSize = 0; 524 int pvsSize = 0; 525 526 Debug << "overall scene size: " << (int)objects.size() << endl; 527 528 BspViewCellsStatistics stat; 529 mBspTree->EvaluateViewCellsStats(stat); 530 Debug << "original view cell partition:\n" << stat << endl; 531 532 if (1) // export view cells 533 { 534 cout << "exporting initial view cells (=leaves) ... "; 535 Exporter *exporter = Exporter::GetExporter("view_cells.x3d"); 536 if (exporter) 537 { 538 exporter->SetWireframe(); 539 exporter->ExportBspLeaves(*mBspTree, stat.maxPvs); 540 //exporter->ExportBspViewCellPartition(*mBspTree, 0); 541 542 if (1) 543 ExportSceneGeometry(exporter, objects); 544 545 delete exporter; 546 } 547 cout << "finished" << endl; 548 } 549 550 cout << "starting post processing using " << mPostProcessSamples << " samples ... "; 551 552 long startTime = GetTime(); 553 int merged = PostprocessViewCells(mSampleRays); 554 555 cout << "finished" << endl; 556 cout << "merged " << merged << " view cells in " 557 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl; 558 559 //-- recount pvs 560 mBspTree->EvaluateViewCellsStats(stat); 561 562 Debug << "after post processing:\n" << stat << endl; 563 564 //-- render simulation 565 cout << "\nevaluating render time after merge ... "; 566 567 SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 568 569 cout << " finished" << endl; 570 571 cout << ss << endl; 572 Debug << ss << endl; 573 574 if (1) // export view cells 575 { 576 cout << "exporting view cells after merge ... "; 577 Exporter *exporter = Exporter::GetExporter("merged_view_cells.x3d"); 578 if (exporter) 579 { 580 exporter->ExportBspViewCellPartition(*mBspTree, stat.maxPvs); 581 //exporter->ExportBspViewCellPartition(*mBspTree, 0); 582 delete exporter; 583 } 584 585 cout << "finished" << endl; 586 } 587 588 //-- visualization of the BSP splits 589 bool exportSplits = false; 590 environment->GetBoolValue("BspTree.Visualization.exportSplits", exportSplits); 591 592 cout << "exporting splits ... "; 593 if (exportSplits) 594 ExportSplits(objects, mSampleRays, mVisualizationSamples); 595 cout << "finished" << endl; 596 597 // export the PVS of sample view cells 598 if (1) 599 ExportBspPvs(objects, mSampleRays, mVisualizationSamples); 600 } 376 //cout << "#totalKdPvsSize=" << mKdTree->CollectLeafPvs() << endl; 601 377 602 378 // HoleSamplingPass(); … … 608 384 } 609 385 610 if (mVspKdTree) 611 { 612 if (1) 613 { 614 Exporter *exporter = Exporter::GetExporter("vspkdtree.x3d"); 615 //exporter->SetWireframe(); 616 exporter->ExportVspKdTree(*mVspKdTree, mVspKdTree->GetStatistics().maxPvsSize); 617 618 Debug << "average PVS size: " << mVspKdTree->GetAvgPvsSize() << endl; 619 620 if (0) ExportSceneGeometry(exporter, objects); 621 622 bool exportRays = true; 623 624 if (exportRays) 625 { 626 int raysSize = 2000; 627 float prob = raysSize / (float)mVspSampleRays.size(); 628 629 exporter->SetWireframe(); 630 631 VssRayContainer rays; 632 for (int i = 0; i < mVspSampleRays.size(); ++ i) 633 { 634 if (RandomValue(0,1) < prob) 635 rays.push_back(mVspSampleRays[i]); 636 } 637 638 exporter->ExportRays(rays, RgbColor(1, 0, 0)); 639 } 640 641 delete exporter; 642 } 643 644 if (1) 645 { 646 vector<VspKdTreeLeaf *> leafContainer; 647 648 mVspKdTree->CollectLeaves(leafContainer); 649 650 for (int i = 0; i < 10; ++ i) 651 { 652 char s[64]; 653 sprintf(s, "vsp_leaves%04d.x3d", i); 654 Exporter *exporter = Exporter::GetExporter(s); 655 656 // export geometry 657 VspKdTreeLeaf *leaf = leafContainer[Random((int)leafContainer.size())]; 658 AxisAlignedBox3 box = mVspKdTree->GetBBox(leaf); 659 660 Material m; 661 m.mDiffuseColor = RgbColor(0, 1, 1); 662 exporter->SetForcedMaterial(m); 663 exporter->SetWireframe(); 664 exporter->ExportBox(box); 665 666 //-- export stored rays 667 VssRayContainer vssRays; 668 leaf->GetRays(vssRays); 669 670 VssRayContainer rays; 671 672 VssRayContainer::const_iterator it, it_end = vssRays.end(); 673 674 for (it = vssRays.begin(); it != it_end; ++ it) 675 { 676 //if (!(*it)->mOriginObject && !(*it)->mTerminationObject) 677 rays.push_back(*it); 678 679 //if (!(*it)->mOriginObject && !(*it)->mTerminationObject) 680 // Debug << "ERR: " << (*it)->mOrigin << " " << (*it)->mTermination << endl; 681 } 682 683 exporter->ExportRays(rays, RgbColor(1, 0, 0)); 684 685 //-- export stored PVS 686 ObjectContainer pvsObj; 687 leaf->ExtractPvs(pvsObj); 688 689 ExportSceneGeometry(exporter, pvsObj); 690 691 delete exporter; 692 } 693 } 694 } 695 696 bool exportRays = false; 697 if (exportRays) { 698 Exporter *exporter = NULL; 699 exporter = Exporter::GetExporter("sample-rays.x3d"); 700 exporter->SetWireframe(); 701 exporter->ExportKdTree(*mKdTree); 702 exporter->ExportBspTree(*mBspTree); 703 704 for (i=0; i < pvsOut; i++) 705 exporter->ExportRays(rays[i], 1000, RgbColor(1, 0, 0)); 706 exporter->SetFilled(); 707 708 delete exporter; 709 } 386 //-- post process view cells 387 mViewCellsManager->PostProcess(objects, mSampleRays); 388 710 389 711 390 //-- several visualizations and statistics 712 if (1) {713 714 for (int k=0; k < pvsOut; k++) {715 Intersectable *object = objects[k];716 char s[64];717 sprintf(s, "sample-pvs%04d.x3d", k);718 Exporter *exporter = Exporter::GetExporter(s);719 exporter->SetWireframe();720 391 392 //-- render simulation 393 cout << "\nevaluating bsp view cells render time before merge ... "; 721 394 722 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 723 Intersectable::NewMail(); 395 SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 724 396 725 // avoid adding the object to the list726 object->Mail();727 ObjectContainer visibleObjects;397 cout << " finished" << endl; 398 cout << ss << endl; 399 Debug << ss << endl; 728 400 729 for (; i != object->mKdPvs.mEntries.end(); i++) 730 { 731 KdNode *node = (*i).first; 732 exporter->ExportBox(mKdTree->GetBox(node)); 733 mKdTree->CollectObjects(node, visibleObjects); 734 } 735 736 exporter->ExportRays(rays[k], 1000, RgbColor(0, 1, 0)); 737 exporter->SetFilled(); 738 739 for (int j = 0; j < visibleObjects.size(); j++) 740 exporter->ExportIntersectable(visibleObjects[j]); 741 742 743 Material m; 744 m.mDiffuseColor = RgbColor(1, 0, 0); 745 exporter->SetForcedMaterial(m); 746 exporter->ExportIntersectable(object); 747 748 delete exporter; 749 } 750 } 401 mViewCellsManager->Visualize(objects, mSampleRays); 751 402 752 403 return true; … … 754 405 755 406 void SamplingPreprocessor::ProcessViewCells(const Ray &ray, 756 Intersectable *object, 757 const int faceIndex, 407 const ObjectContainer &objects, 758 408 int &contributingSamples, 759 409 int &sampleContributions) 760 410 { 761 } 762 /* 763 void SamplingPreprocessor::ProcessVspViewCells(Ray &ray, 764 Intersectable *object, 765 const int faceIndex, 766 int &contributingSamples, 767 int &sampleContributions) 768 { 769 if (!mVspKdTree) 770 { 771 // store samples for vsp kd tree construction 772 if ((int)mVspSampleRays.size() < mVspConstructionSamples) 411 // save rays for view cells construction 412 if (!mViewCellsManager->ViewCellsConstructed()) 773 413 { 774 if (!ray.intersections.empty()) 775 { 776 ray.sourceObject = Ray::Intersection(0.0, object, faceIndex); 777 VssRay *sRay = new VssRay(ray); 778 mVspSampleRays.push_back(sRay); 779 } 780 } 414 if ((int)mSampleRays.size() < mViewCellsManager->GetConstructionSamples()) 415 mVssSampleRays.push_back(new VssRay(ray)); 781 416 else 782 417 { 783 // construct VSP tree using the collected samples 784 cout << "building VSP tree from " << (int)mVspSampleRays.size() << " samples " << endl; 785 mVspKdTree = new VspKdTree(); 786 mVspKdTree->Construct(mVspSampleRays, &mKdTree->GetBox()); 418 mViewCellsManager->Construct(objects, mVssSampleRays); 419 // construct view cells using the collected samples 420 cout << "building view cells from " << (int)mSampleRays.size() << " samples " << endl; 787 421 788 422 // add contributions of saved samples to PVS … … 790 424 //sampleContributions += mBspTree->GetStat().sampleContributions; 791 425 792 Debug << mVspKdTree->GetStatistics(); 793 794 // throw away samples because BSP leaves not stored in order 795 // Need ordered rays for post processing => collect new rays 796 //CLEAR_CONTAINER(mVspSampleRays); 797 } 798 } 799 } 800 801 void SamplingPreprocessor::ProcessBspViewCells(const Ray &ray, 802 Intersectable *object, 803 const int faceIndex, 804 int &contributingSamples, 805 int &sampleContributions) 806 { 807 // save rays for bsp tree construction 808 if (!mBspTree) 809 { 810 if ((BspTree::sConstructionMethod == BspTree::FROM_SAMPLES) && 811 ((int)mSampleRays.size() < mBspConstructionSamples)) 812 { 813 MeshInstance *mi = dynamic_cast<MeshInstance *>(object); 814 815 Ray *sRay = new Ray(ray); 816 mSampleRays.push_back(sRay); 817 818 // also add origin to sample 819 sRay->sourceObject = Ray::Intersection(0.0, object, faceIndex); 820 } 821 else 822 { 823 // construct BSP tree using the collected samples 824 cout << "building bsp tree from " << (int)mSampleRays.size() << " samples " << endl; 825 BuildBspTree(); 826 827 // add contributions of saved samples to PVS 828 contributingSamples += mBspTree->GetStat().contributingSamples; 829 sampleContributions += mBspTree->GetStat().sampleContributions; 830 831 BspTreeStatistics(Debug); 832 833 if (0) Export("vc_bsptree.x3d", false, false, true); 834 835 // throw away samples because BSP leaves not stored in order 836 // Need ordered rays for post processing => collect new rays 837 CLEAR_CONTAINER(mSampleRays); 838 } 839 } 840 // save rays for post processing 841 else if (((int)mSampleRays.size() < mPostProcessSamples) || 842 ((int)mSampleRays.size() < mVisualizationSamples)) 426 // throw away samples 427 CLEAR_CONTAINER(mVssSampleRays); 428 } 429 } 430 // Need (ordered) rays for post processing => collect new rays 431 else if (((int)mSampleRays.size() < mViewCellsManager->GetPostProcessSamples()) || 432 ((int)mSampleRays.size() < mViewCellsManager->GetVisualizationSamples())) 843 433 { 844 434 mSampleRays.push_back(new Ray(ray)); 845 435 } 846 436 } 847 */848 // merge or subdivide view cells849 int SamplingPreprocessor::PostprocessViewCells(const RayContainer &rays)850 {851 int merged = 0;852 853 RayContainer::const_iterator rit, rit_end = rays.end();854 vector<Ray::BspIntersection>::const_iterator iit;855 856 int limit = min((int)mSampleRays.size(), mPostProcessSamples);857 858 for (int i = 0; i < limit; ++ i)859 {860 Ray *ray = mSampleRays[i];861 862 // traverse leaves stored in the rays and compare and merge consecutive863 // leaves (i.e., the neighbors in the tree)864 if (ray->bspIntersections.size() < 2)865 continue;866 867 iit = ray->bspIntersections.begin();868 869 BspLeaf *previousLeaf = (*iit).mLeaf;870 ++ iit;871 872 for (; iit != ray->bspIntersections.end(); ++ iit)873 {874 BspLeaf *leaf = (*iit).mLeaf;875 876 if (mBspTree->ShouldMerge(leaf, previousLeaf))877 {878 mBspTree->MergeViewCells(leaf, previousLeaf);879 880 ++ merged;881 }882 883 previousLeaf = leaf;884 }885 }886 887 return merged;888 } -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h
r439 r440 22 22 23 23 protected: 24 /** Sets up ray for sampling. 25 */ 24 26 void 25 27 SetupRay(Ray &ray, 26 28 const Vector3 &point, 27 29 const Vector3 &direction, 28 const int type); 30 const int type, 31 const Ray::Intersection &source); 29 32 30 KdNode * 31 GetNodeForPvs(KdLeaf *leaf); 32 33 int 34 AddNodeSamples(const Ray &ray, 35 Intersectable *sObject, 36 Intersectable *tObject 37 ); 38 33 /** Refined sampling for finding "holes", i.e., difficult visibility. 34 */ 39 35 void 40 36 HoleSamplingPass(); 41 37 38 /** Casts a bundle of sample rays into the scene. 39 */ 40 int CastRays(const RayContainer &rays, 41 int &sampleContribtion, 42 int &contributingSamples); 43 44 /** Casts a ray into the scene. 45 */ 42 46 int 43 CastRay(Intersectable *object, 44 Ray &ray); 47 CastRay(const Ray &ray); 45 48 46 KdNode *47 GetNodeToSample(Intersectable *object);49 /** Verify if the exact visibility for this object was established. 50 */ 48 51 void 49 52 VerifyVisibility(Intersectable *object); 50 53 51 int 52 CastEdgeSamples( 54 /** Sample the shiluette of objects in order to find visibility changes 55 along the visibility skeleton. 56 */ 57 int CastEdgeSamples( 53 58 Intersectable *object, 54 59 const Vector3 &point, … … 57 62 ); 58 63 59 /** Processes the BSP based view cells during a pass. 60 64 /** Processes the view cells during a pass. 61 65 @param ray the current ray 62 @param object the currently processed object63 @param faceIndex the sampled face of the object64 @param contributingSamples samples contributing to pvs65 @param sampleContributions contribution of the samples66 */67 /*void ProcessBspViewCells(const Ray &ray,68 Intersectable *object,69 const int faceIndex,70 int &contributingSamples,71 int &sampleContributions);72 66 73 void ProcessVspViewCells(Ray &ray, 74 Intersectable *object, 75 const int faceIndex, 76 int &contributingSamples, 77 int &sampleContributions); 67 @param contributingSamples returns the samples contributing to pvs 68 @param sampleContributions returns the accumulated 69 contribution of the samples 78 70 */ 71 79 72 void ProcessViewCells(const Ray &ray, 80 Intersectable *object, 81 const int faceIndex, 73 const ObjectContainer &objects, 82 74 int &contributingSamples, 83 75 int &sampleContributions); … … 87 79 int AddObjectSamples(Intersectable *obj, const Ray &ray); 88 80 89 /** Post processes view cells (i.e., merges or subdivides view cells based 90 on the PVS and the ray sets. 91 @param rays a set of rays which carries the visibility information 92 the merging / subdivision is based on. 93 @returns number of merged view cells. 81 /** 82 Returns random node as target for the current sample ray. 94 83 */ 95 int PostprocessViewCells(const RayContainer &rays); 84 KdNode *GetNodeToSample(Intersectable *object); 85 96 86 97 87 protected: … … 101 91 int mSamplesPerPass; 102 92 int mTotalSamples; 103 int mKdPvsDepth;93 104 94 ofstream mStats; 105 95 ObjectContainer mObjects; 106 96 107 97 RayContainer mSampleRays; 108 VssRayContainer mVspSampleRays; 109 110 int mVspConstructionSamples; 111 112 int mPostProcessSamples; 113 int mVisualizationSamples; 114 98 VssRayContainer mVssSampleRays; 115 99 }; 116 100 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r439 r440 35 35 */ 36 36 const float BspTree::sBalancedRaysTable[] = {1, -1, 0, 0, 0}; 37 38 int BspTree::sConstructionMethod = FROM_INPUT_VIEW_CELLS;39 37 40 38 int BspTree::sFrontId = 0; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r437 r440 526 526 static void ParseEnvironment(); 527 527 528 /// BSP tree construction method529 static int sConstructionMethod;530 531 528 532 529 protected: -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
r437 r440 441 441 int CastRay(Ray &ray); 442 442 443 /** Set to true if new view cells shall be generated in each leaf.444 */445 void SetGenerateViewCells(int generateViewCells);446 447 443 /// bsp tree construction types 448 444 enum {FROM_INPUT_VIEW_CELLS, FROM_SCENE_GEOMETRY, FROM_SAMPLES}; -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
r433 r440 444 444 445 445 void 446 VspKdTree::Construct( VssRayContainer &rays,446 VspKdTree::Construct(const VssRayContainer &rays, 447 447 AxisAlignedBox3 *forcedBoundingBox) 448 448 { -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h
r428 r440 426 426 virtual ~VspKdTree(); 427 427 428 virtual void Construct( VssRayContainer &rays,428 virtual void Construct(const VssRayContainer &rays, 429 429 AxisAlignedBox3 *forcedBoundingBox = NULL); 430 430 -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r438 r440 1148 1148 CLEAR_CONTAINER(polys); 1149 1149 } 1150 1151 1152 void X3dExporter::ExportGeometry(const ObjectContainer &objects) 1153 { 1154 for (int j = 0; j < objects.size(); ++ j) 1155 ExportIntersectable(objects[j]); 1156 } 1157 1158 -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h
r438 r440 84 84 85 85 virtual void 86 ExportGeometry(const ObjectContainer &objects); 87 88 virtual void 86 89 ExportBspSplitPlanes(const BspTree &tree); 87 90
Note: See TracChangeset
for help on using the changeset viewer.