Changeset 477 for trunk/VUT/GtpVisibilityPreprocessor
- Timestamp:
- 12/22/05 01:36:06 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp
r476 r477 80 80 // compute render time of PVS times probability that view point is in view cell 81 81 const float vcCost = pInVc * mViewCellsManager->GetRendercost(vc, mObjRenderCost); 82 Debug << "cost: " << vcCost << " rcost: " << mViewCellsManager->GetRendercost(vc, mObjRenderCost) << endl; 82 Debug << "cost: " << vcCost << " rcost: " 83 << mViewCellsManager->GetRendercost(vc, mObjRenderCost) << endl; 83 84 84 85 // crossing the border of a view cell is depending on the move speed … … 104 105 } 105 106 106 float RenderSimulator::GetCrossVcProbability() 107 float RenderSimulator::GetCrossVcProbability() const 107 108 { 108 /*const float avgArea = mViewCellsManager->GetTotalArea() / 109 mViewCellsManager->GetViewCells().size(); 109 // assume the view cells are uniformly distributed 110 const float vcNum = 111 (float)mViewCellsManager->GetViewCells().size(); 110 112 111 return mMoveSpeed * mViewCellsManager->GetSceneBbox()->SurfaceArea() / */ 112 return 0; 113 return 1.0f - (1 / mMoveSpeed * vcNum); 113 114 } 114 115 -
trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.h
r473 r477 82 82 /** Probability for crossing one view cell. 83 83 */ 84 float GetCrossVcProbability() ;84 float GetCrossVcProbability() const; 85 85 86 86 /// render time for single object of the PVS -
trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp
r475 r477 176 176 if (!use2dSampling) { 177 177 Vector3 normal; 178 int i = (int)RandomValue(0, mObjects.size()-1);178 int i = (int)RandomValue(0, (Real)((int)mObjects.size()-1)); 179 179 Intersectable *object = mObjects[i]; 180 180 object->GetRandomSurfacePoint(point, normal); -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r475 r477 151 151 // pickup a random face of each mesh 152 152 Mesh *mesh = mi->GetMesh(); 153 int face = (int)RandomValue(0, ( int)mesh->mFaces.size() - 1);153 int face = (int)RandomValue(0, (Real)((int)mesh->mFaces.size() - 1)); 154 154 155 155 Polygon3 poly(mesh->mFaces[face], mesh); 156 156 poly.Scale(1.001f); 157 157 // now extend a random edge of the face 158 int edge = (int)RandomValue(0, ( int)poly.mVertices.size() - 1);158 int edge = (int)RandomValue(0, (Real)((int)poly.mVertices.size() - 1)); 159 159 float t = RandomValue(0.0f, 1.0f); 160 160 Vector3 target = t*poly.mVertices[edge] + (1.0f-t)*poly.mVertices[(edge + 1)% … … 192 192 Debug << "Finding random neighbour" << endl; 193 193 for (int tries = 0; tries < 10; tries++) { 194 int index = (int)RandomValue(0, pvsSize - 1);194 int index = (int)RandomValue(0, (Real)(pvsSize - 1)); 195 195 KdPvsData data; 196 196 KdNode *node; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r475 r477 281 281 } 282 282 283 283 284 float ViewCellsManager::GetVolume(ViewCell *viewCell) const 284 285 { … … 287 288 288 289 289 290 290 float ViewCellsManager::GetArea(ViewCell *viewCell) const 291 291 { … … 294 294 295 295 296 297 float ViewCellsManager::GetTotalArea() 296 float ViewCellsManager::GetAccVcArea() 298 297 { 299 298 // if already computed … … 316 315 s << mViewCellsStats << endl; 317 316 } 317 318 318 319 319 /**********************************************************************/ … … 409 409 { 410 410 // compute view cell area as subsititute for probability 411 #if 0 411 412 return GetArea(viewCell) / mBspTree->GetBoundingBox().SurfaceArea(); 412 //return GetArea(viewCell) / GetTotalArea(); 413 } 413 #else 414 return GetArea(viewCell) / GetAccVcArea(); 415 #endif 416 } 417 414 418 415 419 float BspViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost) const 416 420 { 417 421 return viewCell->GetPvs().GetSize() * objRendercost; 422 } 423 424 425 AxisAlignedBox3 BspViewCellsManager::GetSceneBbox() const 426 { 427 return mBspTree->GetBoundingBox(); 418 428 } 419 429 … … 430 440 const VssRayContainer &rays) 431 441 { 442 if (mBspRays.empty()) 443 ConstructBspRays(rays, mConstructionSamples); 444 432 445 if (!ViewCellsConstructed()) 433 446 { … … 442 455 Debug << "original view cell partition:\n" << mViewCellsStats << endl; 443 456 444 if (1) // export view cells before merge457 if (1) // export view cells 445 458 { 446 459 cout << "exporting initial view cells (=leaves) ... "; … … 449 462 if (exporter) 450 463 { 451 exporter->SetWireframe(); 452 exporter->ExportBspLeaves(*mBspTree, mViewCellsStats.maxPvs); 453 //exporter->ExportBspViewCellPartition(*mBspTree, 0); 464 //exporter->SetWireframe(); 465 exporter->SetFilled(); 466 exporter->ExportBspViewCellPartition(*mBspTree, 467 mViewCellsStats.maxPvs); 454 468 455 469 if (0) 456 470 { 457 Material m; //= RandomMaterial();471 Material m; 458 472 m.mDiffuseColor = RgbColor(0, 1, 0); 459 473 exporter->SetForcedMaterial(m); … … 466 480 } 467 481 cout << "finished" << endl; 468 469 //-- render simulation after merge470 cout << "\nevaluating bsp view cells render time after merge ... ";471 472 mRenderSimulator->RenderScene();473 SimulationStatistics ss;474 mRenderSimulator->GetStatistics(ss);475 476 cout << " finished" << endl;477 cout << ss << endl;478 Debug << ss << endl;479 480 482 } 481 483 482 484 cout << "starting post processing using " << mPostProcessSamples << " samples ... "; 483 485 484 486 long startTime = GetTime(); 487 485 488 486 489 // $$JB we do not have connectivity information from the ray in the moment … … 489 492 //-- merge or subdivide view cells 490 493 int merged = 0; 491 #if 0 492 493 RayContainer::const_iterator rit, rit_end = rays.end(); 494 494 495 vector<BspIntersection>::const_iterator iit; 495 496 496 int limit = min((int)rays.size(), mPostProcessSamples); 497 498 for (int i = 0; i < limit; ++ i) 497 for (int i = 0; i < (int)mBspRays.size(); ++ i) 499 498 { 500 Ray *ray = rays[i];501 499 BspRay *ray = mBspRays[i]; 500 502 501 // traverse leaves stored in the rays and compare and merge consecutive 503 502 // leaves (i.e., the neighbors in the tree) 504 if (ray-> bspIntersections.size() < 2)503 if (ray->intersections.size() < 2) 505 504 continue; 506 507 iit = ray-> bspIntersections.begin();505 506 iit = ray->intersections.begin(); 508 507 509 508 BspLeaf *previousLeaf = (*iit).mLeaf; 510 509 ++ iit; 511 510 512 for (; iit != ray-> bspIntersections.end(); ++ iit)511 for (; iit != ray->intersections.end(); ++ iit) 513 512 { 514 513 BspLeaf *leaf = (*iit).mLeaf; … … 524 523 } 525 524 } 526 #endif 525 527 526 //-- stats and visualizations 528 527 cout << "finished" << endl; … … 531 530 532 531 Debug << "Postprocessing: Merged " << merged << " view cells in " 533 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl; 534 535 //-- recount pvs 532 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl << endl; 533 534 // reset view cells and stats 535 mViewCells.clear(); 536 mBspTree->CollectViewCells(mViewCells); 536 537 mViewCellsStats.Reset(); 537 538 mBspTree->EvaluateViewCellsStats(mViewCellsStats); … … 540 541 } 541 542 543 544 BspViewCellsManager::~BspViewCellsManager() 545 { 546 CLEAR_CONTAINER(mBspRays); 547 } 548 549 542 550 int BspViewCellsManager::GetType() const 543 551 { … … 551 559 if (!ViewCellsConstructed()) 552 560 return; 553 554 //-- recount pvs 555 ViewCellsStatistics vcStats; 556 mBspTree->EvaluateViewCellsStats(vcStats); 557 561 562 if (mBspRays.empty()) 563 ConstructBspRays(sampleRays, mConstructionSamples); 564 558 565 if (1) // export view cells 559 566 { 560 567 cout << "exporting view cells after merge ... "; 561 568 Exporter *exporter = Exporter::GetExporter("merged_view_cells.x3d"); 562 569 563 570 if (exporter) 564 571 { 565 exporter->ExportBspViewCellPartition(*mBspTree, vcStats.maxPvs);566 //exporter->ExportBspViewCellPartition(*mBspTree, 0);572 exporter->ExportBspViewCellPartition(*mBspTree, 573 mViewCellsStats.maxPvs); 567 574 delete exporter; 568 575 } 569 576 570 577 cout << "finished" << endl; 571 578 } 572 579 573 580 //-- visualization of the BSP splits 574 581 bool exportSplits = false; 575 582 environment->GetBoolValue("BspTree.Visualization.exportSplits", exportSplits); 576 583 577 584 if (exportSplits) 578 585 { 579 586 cout << "exporting splits ... "; 580 ExportSplits(objects, sampleRays);587 ExportSplits(objects); 581 588 cout << "finished" << endl; 582 589 } 583 584 ExportBspPvs(objects , sampleRays);590 591 ExportBspPvs(objects); 585 592 } 586 593 … … 591 598 } 592 599 593 void BspViewCellsManager::ExportSplits(const ObjectContainer &objects, 594 const VssRayContainer &sampleRays)600 601 void BspViewCellsManager::ExportSplits(const ObjectContainer &objects) 595 602 { 596 603 Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); … … 602 609 exporter->SetForcedMaterial(m); 603 610 exporter->SetWireframe(); 611 604 612 exporter->ExportBspSplits(*mBspTree, true); 605 613 … … 611 619 exporter->ResetForcedMaterial(); 612 620 613 bool exportRays = false;614 bool exportGeometry = false;615 616 environment->GetBoolValue("BspTree.Visualization.exportRays", exportRays);617 environment->GetBoolValue("BspTree.Visualization.exportGeometry", exportGeometry);618 619 621 // export rays 620 if ( exportRays)622 if (0) 621 623 { 622 624 VssRayContainer outRays; 623 624 int raysSize = min((int)sampleRays.size(), mVisualizationSamples); 625 626 int raysSize = min((int)mBspRays.size(), mVisualizationSamples); 627 625 628 for (int i = 0; i < raysSize; ++ i) 626 {627 629 // only rays piercing geometry 628 outRays.push_back(sampleRays[i]); 629 } 630 630 outRays.push_back(mBspRays[i]->vssRay); 631 631 632 // export rays 632 633 exporter->ExportRays(outRays, RgbColor(1, 1, 0)); 633 634 } 634 635 if ( exportGeometry)635 636 if (0) 636 637 exporter->ExportGeometry(objects); 637 638 638 639 delete exporter; 639 640 } 640 641 } 641 642 642 void BspViewCellsManager::ExportBspPvs(const ObjectContainer &objects, 643 const VssRayContainer &sampleRays) 644 { 645 const int leafOut = 10; 646 647 ViewCell::NewMail(); 648 649 //-- some rays for output 650 const int raysOut = min((int)sampleRays.size(), mVisualizationSamples); 651 652 Debug << "Output view cells:" << endl; 653 654 if (1) 655 { 656 //-- some random view cells and rays for output 657 vector<BspLeaf *> bspLeaves; 658 659 for (int i = 0; i < leafOut; ++ i) 660 bspLeaves.push_back(mBspTree->GetRandomLeaf()); 661 662 for (int i = 0; i < bspLeaves.size(); ++ i) 663 { 664 BspLeaf *leaf = bspLeaves[i]; 665 RayContainer vcRays; 666 667 cout << "creating output for view cell " << i << " ... "; 668 669 // TODO matt 670 // check whether we can add the current ray to the output rays 671 /*for (int k = 0; k < raysOut; ++ k) 672 { 673 Ray *ray = sampleRays[k]; 674 675 for (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) 676 { 677 BspLeaf *leaf2 = ray->bspIntersections[j].mLeaf; 678 679 if (leaf->GetViewCell() == leaf2->GetViewCell()) 680 { 681 vcRays.push_back(ray); 682 } 683 } 684 }*/ 685 686 Intersectable::NewMail(); 687 688 BspViewCell *vc = dynamic_cast<BspViewCell *>(leaf->GetViewCell()); 689 690 //bspLeaves[j]->Mail(); 691 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 692 693 Exporter *exporter = Exporter::GetExporter(s); 694 exporter->SetFilled(); 695 696 exporter->SetWireframe(); 697 //exporter->SetFilled(); 698 699 Material m;//= RandomMaterial(); 700 m.mDiffuseColor = RgbColor(1, 1, 0); 701 exporter->SetForcedMaterial(m); 702 703 if (vc->GetMesh()) 704 exporter->ExportViewCell(vc); 705 else 706 { 707 PolygonContainer vcGeom; 708 // export view cell geometry 709 mBspTree->ConstructGeometry(vc, vcGeom); 710 exporter->ExportPolygons(vcGeom); 711 CLEAR_CONTAINER(vcGeom); 712 } 713 714 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 715 << ", piercing rays=" << (int)vcRays.size() << endl; 716 717 // export rays piercing this view cell 718 //exporter->ExportRays(vcRays, 1000, RgbColor(0, 1, 0)); 719 720 m.mDiffuseColor = RgbColor(1, 0, 0); 721 exporter->SetForcedMaterial(m); 722 723 // exporter->SetWireframe(); 724 exporter->SetFilled(); 725 726 ObjectPvsMap::iterator it, it_end = vc->GetPvs().mEntries.end(); 727 // output PVS of view cell 728 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 729 { 730 Intersectable *intersect = (*it).first; 731 if (!intersect->Mailed()) 732 { 733 exporter->ExportIntersectable(intersect); 734 intersect->Mail(); 735 } 736 } 737 738 DEL_PTR(exporter); 739 cout << "finished" << endl; 740 } 741 } 742 else 743 { 744 ViewCellContainer viewCells; 745 RayContainer vcRays; 746 747 mBspTree->CollectViewCells(viewCells); 748 stable_sort(viewCells.begin(), viewCells.end(), vc_gt); 749 750 const int limit = min(leafOut, (int)viewCells.size()); 751 752 for (int i = 0; i < limit; ++ i) 753 { 754 cout << "creating output for view cell " << i << " ... "; 755 756 Intersectable::NewMail(); 757 BspViewCell *vc = dynamic_cast<BspViewCell *>(viewCells[i]); 758 759 cout << "creating output for view cell " << i << " ... "; 760 761 // TODO matt 762 // check whether we can add the current ray to the output rays 763 /*for (int k = 0; k < raysOut; ++ k) 764 { 765 Ray *ray = sampleRays[k]; 766 767 for (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) 768 { 769 BspLeaf *leaf = ray->bspIntersections[j].mLeaf; 770 771 if (vc == leaf->GetViewCell()) 772 vcRays.push_back(ray); 773 } 774 }*/ 775 776 //bspLeaves[j]->Mail(); 777 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 778 779 Exporter *exporter = Exporter::GetExporter(s); 780 exporter->SetWireframe(); 781 782 Material m;//= RandomMaterial(); 783 m.mDiffuseColor = RgbColor(0, 1, 0); 784 exporter->SetForcedMaterial(m); 785 786 if (vc->GetMesh()) 787 exporter->ExportViewCell(vc); 788 else 789 { 790 PolygonContainer cell; 791 // export view cell 792 mBspTree->ConstructGeometry(vc, cell); 793 exporter->ExportPolygons(cell); 794 CLEAR_CONTAINER(cell); 795 } 796 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 797 << ", piercing rays=" << (int)vcRays.size() << endl; 798 799 // export rays piercing this view cell 800 exporter->ExportRays(vcRays, 1000, RgbColor(0, 1, 0)); 801 802 m.mDiffuseColor = RgbColor(1, 0, 0); 803 exporter->SetForcedMaterial(m); 804 805 ObjectPvsMap::const_iterator it, it_end = vc->GetPvs().mEntries.end(); 806 807 // output PVS of view cell 808 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 809 { 810 Intersectable *intersect = (*it).first; 811 812 if (!intersect->Mailed()) 813 { 814 Material m = RandomMaterial(); 815 exporter->SetForcedMaterial(m); 816 817 exporter->ExportIntersectable(intersect); 818 819 intersect->Mail(); 820 } 821 } 643 644 void BspViewCellsManager::ExportBspPvs(const ObjectContainer &objects) 645 { 646 bool exportRays = false; 647 bool exportGeometry = false; 648 649 environment->GetBoolValue("VspBspTree.Visualization.exportRays", exportRays); 650 environment->GetBoolValue("VspBspTree.Visualization.exportGeometry", exportGeometry); 651 652 const int leafOut = 10; 653 654 ViewCell::NewMail(); 655 656 //-- some rays for output 657 const int raysOut = min((int)mBspRays.size(), mVisualizationSamples); 658 cout << "visualization using " << mVisualizationSamples << " samples" << endl; 659 Debug << "\nOutput view cells: " << endl; 660 661 if (1) 662 { 663 //-- some random view cells and rays for output 664 vector<BspLeaf *> vspBspLeaves; 665 666 for (int i = 0; i < leafOut; ++ i) 667 vspBspLeaves.push_back(mBspTree->GetRandomLeaf()); 668 669 for (int i = 0; i < (int)vspBspLeaves.size(); ++ i) 670 { 671 VssRayContainer vcRays; 672 cout << "creating output for view cell " << i << " ... "; 673 674 // check whether we can add the current ray to the output rays 675 for (int k = 0; k < raysOut; ++ k) 676 { 677 BspRay *ray = mBspRays[k]; 678 679 for (int j = 0; j < (int)ray->intersections.size(); ++ j) 680 { 681 BspLeaf *leaf = ray->intersections[j].mLeaf; 682 683 if (vspBspLeaves[i]->GetViewCell() == leaf->GetViewCell()) 684 { 685 vcRays.push_back(ray->vssRay); 686 } 687 } 688 } 689 690 Intersectable::NewMail(); 691 692 BspViewCell *vc = dynamic_cast<BspViewCell *> 693 (vspBspLeaves[i]->GetViewCell()); 694 695 //bspLeaves[j]->Mail(); 696 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 697 698 Exporter *exporter = Exporter::GetExporter(s); 699 exporter->SetFilled(); 700 701 ObjectPvsMap::iterator it = vc->GetPvs().mEntries.begin(); 702 703 exporter->SetWireframe(); 704 //exporter->SetFilled(); 705 706 Material m;//= RandomMaterial(); 707 m.mDiffuseColor = RgbColor(0, 1, 0); 708 exporter->SetForcedMaterial(m); 709 710 if (vc->GetMesh()) 711 exporter->ExportViewCell(vc); 712 else 713 { 714 PolygonContainer vcGeom; 715 716 // export view cell geometry 717 mBspTree->ConstructGeometry(vc, vcGeom); 718 exporter->ExportPolygons(vcGeom); 719 CLEAR_CONTAINER(vcGeom); 720 } 721 722 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 723 << ", piercing rays=" << (int)vcRays.size() << endl; 724 725 // export rays piercing this view cell 726 if (exportRays) 727 { 728 //exporter->ExportRays(vcRays, RgbColor(1, 0, 0)); 729 exporter->ExportRays(vspBspLeaves[i]->mVssRays, RgbColor(1, 1, 1)); 730 } 731 732 m.mDiffuseColor = RgbColor(0, 1, 1); 733 exporter->SetForcedMaterial(m); 734 735 //exporter->SetWireframe(); 736 exporter->SetFilled(); 737 738 // output PVS of view cell 739 for (; it != vc->GetPvs().mEntries.end(); ++ it) 740 { 741 Intersectable *intersect = (*it).first; 742 if (!intersect->Mailed()) 743 { 744 exporter->ExportIntersectable(intersect); 745 intersect->Mail(); 746 } 747 } 748 Debug << "here1 exportgeom: " << exportGeometry << endl; 749 // output rest of the objects 750 if (exportGeometry) 751 { 752 Material m;//= RandomMaterial(); 753 m.mDiffuseColor = RgbColor(0, 0, 1); 754 exporter->SetForcedMaterial(m); 755 756 for (int j = 0; j < objects.size(); ++ j) 757 if (!objects[j]->Mailed()) 758 { 759 exporter->SetForcedMaterial(m); 760 exporter->ExportIntersectable(objects[j]); 761 objects[j]->Mail(); 762 } 763 } 764 DEL_PTR(exporter); 765 cout << "finished" << endl; 766 } 767 } 768 else 769 { 770 ViewCellContainer viewCells; 771 772 mBspTree->CollectViewCells(viewCells); 773 stable_sort(viewCells.begin(), viewCells.end(), vc_gt); 774 775 int limit = min(leafOut, (int)viewCells.size()); 776 777 for (int i = 0; i < limit; ++ i) 778 { 779 cout << "creating output for view cell " << i << " ... "; 780 VssRayContainer vcRays; 781 Intersectable::NewMail(); 782 BspViewCell *vc = dynamic_cast<BspViewCell *>(viewCells[i]); 783 784 cout << "creating output for view cell " << i << " ... "; 785 786 // check whether we can add the current ray to the output rays 787 for (int k = 0; k < raysOut; ++ k) 788 { 789 BspRay *ray = mBspRays[k]; 790 791 for (int j = 0; j < (int)ray->intersections.size(); ++ j) 792 { 793 BspLeaf *leaf = ray->intersections[j].mLeaf; 794 795 if (vc == leaf->GetViewCell()) 796 { 797 vcRays.push_back(ray->vssRay); 798 } 799 } 800 } 801 802 //bspLeaves[j]->Mail(); 803 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 804 805 Exporter *exporter = Exporter::GetExporter(s); 806 807 exporter->SetWireframe(); 808 809 Material m;//= RandomMaterial(); 810 m.mDiffuseColor = RgbColor(0, 1, 0); 811 exporter->SetForcedMaterial(m); 812 813 if (vc->GetMesh()) 814 exporter->ExportViewCell(vc); 815 else 816 { 817 PolygonContainer vcGeom; 818 // export view cell 819 mBspTree->ConstructGeometry(vc, vcGeom); 820 exporter->ExportPolygons(vcGeom); 821 CLEAR_CONTAINER(vcGeom); 822 } 823 824 825 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 826 << ", piercing rays=" << (int)vcRays.size() << endl; 827 828 829 // export rays piercing this view cell 830 exporter->ExportRays(vcRays, RgbColor(0, 1, 0)); 831 832 m.mDiffuseColor = RgbColor(1, 0, 0); 833 exporter->SetForcedMaterial(m); 834 835 ObjectPvsMap::const_iterator it, 836 it_end = vc->GetPvs().mEntries.end(); 837 838 // output PVS of view cell 839 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 840 { 841 Intersectable *intersect = (*it).first; 842 843 if (!intersect->Mailed()) 844 { 845 Material m = RandomMaterial(); 846 847 exporter->SetForcedMaterial(m); 848 849 exporter->ExportIntersectable(intersect); 850 intersect->Mail(); 851 } 852 } 822 853 823 DEL_PTR(exporter); 824 cout << "finished" << endl; 825 } 826 } 854 DEL_PTR(exporter); 855 cout << "finished" << endl; 856 } 857 } 858 859 Debug << endl; 827 860 } 828 861 … … 886 919 887 920 921 void BspViewCellsManager::ConstructBspRays(const VssRayContainer &rays, 922 const int numSamples) 923 { 924 VssRayContainer::const_iterator it, it_end = rays.end(); 925 926 for (it = rays.begin(); it != rays.end() && mBspRays.size() < numSamples; ++ it) 927 { 928 VssRay *vssRay = *it; 929 BspRay *ray = new BspRay(vssRay); 930 931 ViewCellContainer viewCells; 932 933 CastLineSegment(vssRay->mTermination, vssRay->mOrigin, viewCells); 934 935 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 936 937 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 938 { 939 BspViewCell *vc = dynamic_cast<BspViewCell *>(*vit); 940 ray->intersections.push_back(BspIntersection(0, vc->mLeaves[0])); 941 } 942 943 mBspRays.push_back(ray); 944 } 945 } 946 888 947 889 948 /**********************************************************************/ … … 900 959 // compute view cell area as subsititute for probability 901 960 AxisAlignedBox3 box = mKdTree->GetBox(mKdTree->GetRoot()); 902 961 #if 0 903 962 return GetArea(viewCell) / box.SurfaceArea(); 904 //return GetArea(viewCell) / GetTotalArea(); 963 #else 964 return GetArea(viewCell) / GetAccVcArea(); 965 #endif 905 966 } 906 967 … … 909 970 { 910 971 return viewCell->GetPvs().GetSize() * objRendercost; 972 } 973 974 AxisAlignedBox3 KdViewCellsManager::GetSceneBbox() const 975 { 976 return mKdTree->GetBox(); 911 977 } 912 978 … … 1160 1226 1161 1227 return GetArea(viewCell) / box.SurfaceArea(); 1162 //return GetArea(viewCell) / Get TotalArea();1228 //return GetArea(viewCell) / GetAccVcArea(); 1163 1229 } 1164 1230 … … 1219 1285 1220 1286 return 0; 1287 } 1288 1289 AxisAlignedBox3 VspKdViewCellsManager::GetSceneBbox() const 1290 { 1291 return mVspKdTree->GetBBox(mVspKdTree->GetRoot()); 1221 1292 } 1222 1293 … … 1354 1425 } 1355 1426 1427 1428 1356 1429 /**********************************************************************/ 1357 1430 /* VspBspViewCellsManager implementation */ … … 1365 1438 } 1366 1439 1440 1367 1441 VspBspViewCellsManager::~VspBspViewCellsManager() 1368 1442 { … … 1370 1444 } 1371 1445 1446 1372 1447 float VspBspViewCellsManager::GetProbability(ViewCell *viewCell) 1373 1448 { 1374 return GetArea(viewCell) / mVspBspTree->GetBoundingBox().SurfaceArea(); 1375 //return GetArea(viewCell) / GetTotalArea(); 1376 } 1449 #if 0 1450 return GetArea(viewCell) / mVspBspTree->GetBbox().SurfaceArea(); 1451 #else 1452 return GetArea(viewCell) / GetAccVcArea(); 1453 #endif 1454 } 1455 1377 1456 1378 1457 float VspBspViewCellsManager::GetArea(ViewCell *viewCell) const … … 1389 1468 } 1390 1469 1391 float VspBspViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost) const 1470 1471 float VspBspViewCellsManager::GetRendercost(ViewCell *viewCell, 1472 float objRendercost) const 1392 1473 { 1393 1474 return viewCell->GetPvs().GetSize() * objRendercost; 1475 } 1476 1477 1478 AxisAlignedBox3 VspBspViewCellsManager::GetSceneBbox() const 1479 { 1480 return mVspBspTree->GetBoundingBox(); 1394 1481 } 1395 1482 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h
r475 r477 160 160 virtual bool ViewCellsConstructed() const = 0; 161 161 162 /** cast line segment to get a list of unique viewcells which are intersected 163 by this line segment */ 162 /** cast line segment to get a list of unique viewcells which are intersected 163 by this line segment 164 */ 164 165 165 166 virtual int CastLineSegment(const Vector3 &origin, 166 167 const Vector3 &termination, 167 168 ViewCellContainer &viewcells 168 169 ) = 0; 169 170 170 virtual void GetPvsStatistics(PvsStatistics &stat); 171 172 virtual void 173 PrintPvsStatistics(ostream &s); 174 175 /** Returns probability that view point lies in one view cell. 171 virtual void GetPvsStatistics(PvsStatistics &stat); 172 173 virtual void PrintPvsStatistics(ostream &s); 174 175 /** Returns probability that view point lies in one view cell. 176 */ 177 virtual float GetProbability(ViewCell *viewCell) = 0; 178 179 /** Returns render cost of a single view cell given the render cost of an object. 180 */ 181 virtual float GetRendercost(ViewCell *viewCell, float objRendercost) const = 0; 182 183 /** Returns vector of loaded / generated view cells. 184 */ 185 ViewCellContainer &GetViewCells(); 186 187 /** Helper function used to split ray set into one used for view cell 188 construction and one cast after construction. 189 */ 190 void GetRaySets(const VssRayContainer &sourceRays, 191 VssRayContainer &constructionRays, 192 VssRayContainer &savedRays) const; 193 194 /** Returns accumulated area of all view cells. 176 195 */ 177 virtual float GetProbability(ViewCell *viewCell) = 0; 178 179 /** Returns render cost of a single view cell given the render cost of an object. 180 */ 181 virtual float GetRendercost(ViewCell *viewCell, float objRendercost) const = 0; 182 183 /** Returns vector of loaded / generated view cells. 184 */ 185 ViewCellContainer &GetViewCells(); 186 187 /** Helper function used to split ray set into one used for view cell 188 construction and one cast after construction. 189 */ 190 void GetRaySets(const VssRayContainer &sourceRays, 191 VssRayContainer &constructionRays, 192 VssRayContainer &savedRays) const; 193 194 /** Returns total area of view cells. 195 */ 196 float GetTotalArea(); 196 float GetAccVcArea(); 197 197 198 198 /** Returns area of one view cell. … … 203 203 */ 204 204 float GetVolume(ViewCell *viewCell) const; 205 206 virtual AxisAlignedBox3 GetSceneBbox() const = 0; 205 207 206 208 protected: … … 243 245 BspViewCellsManager(BspTree *tree, int constructionSamples); 244 246 247 ~BspViewCellsManager(); 248 245 249 int Construct(const ObjectContainer &objects, 246 250 const VssRayContainer &rays, … … 271 275 float GetArea(ViewCell *viewCell) const; 272 276 277 AxisAlignedBox3 GetSceneBbox() const; 278 273 279 protected: 274 280 … … 281 287 bool ShouldMerge(BspLeaf *front, BspLeaf *back) const; 282 288 289 void ConstructBspRays(const VssRayContainer &rays, 290 const int numSamples); 283 291 /// the BSP tree. 284 292 BspTree *mBspTree; … … 290 298 /** Exports visualization of the BSP splits. 291 299 */ 292 void ExportSplits(const ObjectContainer &objects , const VssRayContainer &sampleRays);300 void ExportSplits(const ObjectContainer &objects); 293 301 294 302 /** Exports visualization of the BSP PVS. 295 303 */ 296 void ExportBspPvs(const ObjectContainer &objects , const VssRayContainer &sampleRays);304 void ExportBspPvs(const ObjectContainer &objects); 297 305 298 306 }; … … 334 342 float GetProbability(ViewCell *viewCell); 335 343 float GetRendercost(ViewCell *viewCell, float objRendercost) const; 344 345 AxisAlignedBox3 GetSceneBbox() const; 336 346 337 347 protected: … … 385 395 float GetRendercost(ViewCell *viewCell, float objRendercost) const; 386 396 397 AxisAlignedBox3 GetSceneBbox() const; 398 387 399 protected: 388 400 … … 431 443 float GetArea(ViewCell *viewCell) const; 432 444 445 AxisAlignedBox3 GetSceneBbox() const; 446 433 447 protected: 434 448
Note: See TracChangeset
for help on using the changeset viewer.