Changeset 582 for trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp
- Timestamp:
- 02/02/06 19:16:39 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp
r581 r582 308 308 { 309 309 environment->GetBoolValue("ViewCells.Visualization.exportMergedViewCells", mExportMergedViewCells); 310 environment->GetFloatValue("ViewCells.maxStaticMemory", mMaxMemory); 310 311 311 312 //-- merge options … … 314 315 environment->GetFloatValue("ViewCells.PostProcess.maxCostRatio", mMergeMaxCostRatio); 315 316 317 318 Debug << "========= view cell tree options ================\n"; 319 Debug << "minimum view cells: " << mMergeMinViewCells << endl; 320 Debug << "max cost ratio: " << mMergeMaxCostRatio << endl; 321 Debug << "max memory: " << mMaxMemory << endl; 322 316 323 MergeCandidate::sRenderCostWeight = mRenderCostWeight; 317 324 318 325 mStats.open("mergeStats.log"); 326 } 327 328 329 // return memory usage in MB 330 float ViewCellsTree::GetMemUsage() const 331 { 332 return 0; 333 /*(sizeof(ViewCellsTree) + 334 mBspStats.Leaves() * sizeof(BspLeaf) + 335 mBspStats.Interior() * sizeof(BspInterior) + 336 mBspStats.accumRays * sizeof(RayInfo)) / (1024.0f * 1024.0f);*/ 319 337 } 320 338 … … 387 405 const ObjectContainer &objects) 388 406 { 389 // number of view cells equals the number of leaves 390 // (without the invalid ones ) 391 //mNumViewCells = mBspStats.Leaves();//- mBspStats.invalidLeaves; 392 mNumViewCells = (int)mViewCellsManager->GetViewCells().size(); 407 mNumActiveViewCells = (int)mViewCellsManager->GetViewCells().size(); 393 408 394 409 float variance = 0; … … 432 447 // view cell manager. They will change with 433 448 // subsequent merges 434 ViewCellContainer & viewCells = mViewCellsManager->GetViewCells();449 ViewCellContainer &activeViewCells = mViewCellsManager->GetViewCells(); 435 450 436 451 … … 455 470 float realExpectedCost = mExpectedCost; 456 471 float realAvgRenderCost = mAvgRenderCost; 457 int realNum ViewCells = mNumViewCells;472 int realNumActiveViewCells = mNumActiveViewCells; 458 473 459 474 // maximal ratio of old expected render cost to expected render … … 461 476 float avgCostMaxDeviation; 462 477 int maxMergesPerPass; 463 int num ActiveViewCells = 0;478 int numMergedViewCells = 0; 464 479 465 480 environment->GetIntValue("ViewCells.PostProcess.maxMergesPerPass", maxMergesPerPass); … … 472 487 //-- use priority queue to merge leaf pairs 473 488 474 while (!mMergeQueue.empty() && (realNumViewCells > mMergeMinViewCells))489 while (!mMergeQueue.empty())// && (realNumActiveViewCells > mMergeMinViewCells)) 475 490 { 476 491 //-- reset merge queue if the ratio of current expected cost / real expected cost … … 495 510 mExpectedCost = realExpectedCost; 496 511 mAvgRenderCost = realAvgRenderCost; 497 mNum ViewCells = realNumViewCells;512 mNumActiveViewCells = realNumActiveViewCells; 498 513 499 const int numActiveViewCells = UpdateMergedViewCells(viewCells); 500 514 const int numMergedViewCells = UpdateActiveViewCells(activeViewCells); 515 516 // recompute priorities => reset render cost 501 517 ResetMergeQueue(); 502 518 … … 509 525 if (mExportMergedViewCells) 510 526 { 511 ExportMergedViewCells( viewCells, objects, numActiveViewCells);527 ExportMergedViewCells(activeViewCells, objects, numMergedViewCells); 512 528 } 513 529 } … … 524 540 mMergeQueue.pop(); 525 541 526 // both view cells equal! 542 // both view cells equal 543 // NOTE: do I really still need this? probably cannot happen!! 527 544 if (mc.mLeftViewCell == mc.mRightViewCell) 528 545 continue; … … 532 549 ViewCell::NewMail(); 533 550 534 -- realNum ViewCells;551 -- realNumActiveViewCells; 535 552 ++ mergeStats.merged; 536 553 ++ mergedPerPass; … … 547 564 mDeviation += mc.GetDeviationIncr(); 548 565 549 realExpectedCost = totalCost / (float)realNum ViewCells;566 realExpectedCost = totalCost / (float)realNumActiveViewCells; 550 567 551 568 const float currentMergeCost = mc.GetMergeCost(); … … 557 574 558 575 totalPvs += pvsDiff; 576 559 577 // set timestamp 560 578 mergedVc->SetTimeStamp(mergeStats.merged); 561 579 562 realAvgRenderCost = (float)totalPvs / (float)realNum ViewCells;580 realAvgRenderCost = (float)totalPvs / (float)realNumActiveViewCells; 563 581 #if VC_HISTORY 564 582 if (mc.mLeftViewCell->IsSibling(mc.mRightViewCell)) … … 566 584 #endif 567 585 if (((mergeStats.merged % statsOut) == 0) || 568 (realNum ViewCells == mMergeMinViewCells))586 (realNumActiveViewCells == mMergeMinViewCells)) 569 587 { 570 588 cout << "merged " << mergeStats.merged << " view cells" << endl; … … 573 591 << "#Pass\n" << pass << endl 574 592 << "#Merged\n" << mergeStats.merged << endl 575 << "#Viewcells\n" << realNum ViewCells << endl593 << "#Viewcells\n" << realNumActiveViewCells << endl 576 594 << "#CurrentCost\n" << currentMergeCost << endl 577 595 << "#RelativeCost\n" << currentMergeCost / mOverallCost << endl … … 584 602 << "#AvgRenderCost\n" << mAvgRenderCost << endl 585 603 << "#expectedCostRatio\n" << mExpectedCost / realExpectedCost << endl 586 << "#Deviation\n" << mDeviation / (float)realNum ViewCells << endl604 << "#Deviation\n" << mDeviation / (float)realNumActiveViewCells << endl 587 605 << "#TotalDeviation\n" << mDeviation<< endl; 588 606 } … … 592 610 // merge candidate not valid, because one of the leaves was already 593 611 // merged with another one => validate and reinsert into queue 594 SetMergeCandidateValid(mc); 595 mMergeQueue.push(mc); 612 if (ValidateMergeCandidate(mc)) 613 { 614 EvalMergeCost(mc); 615 mMergeQueue.push(mc); 616 } 596 617 } 597 618 } … … 600 621 mExpectedCost = realExpectedCost; 601 622 mAvgRenderCost = realAvgRenderCost; 602 mNum ViewCells = realNumViewCells;603 604 Update MergedViewCells(viewCells);623 mNumActiveViewCells = realNumActiveViewCells; 624 625 UpdateActiveViewCells(activeViewCells); 605 626 ResetMergeQueue(); 606 607 627 608 628 // create a root node if the merge was not done till root level, 609 629 // else take the single node as new root 610 if ((int)viewCells.size() > 1) 611 { 612 Debug << "here888" << endl; 613 ViewCellInterior *root = new ViewCellInterior(); 630 if ((int)activeViewCells.size() > 1) 631 { 632 Debug << "creating root of view cell hierarchy for " << (int)activeViewCells.size() << " view cells" << endl; 633 for (int i = 0; i < activeViewCells.size(); ++ i){ 634 Debug << "here233 " << activeViewCells[i]->GetParent() << endl; 635 Debug << "here233 " << activeViewCells[i] << endl; 636 } 637 ViewCellInterior *root = mViewCellsManager->MergeViewCells(activeViewCells); 614 638 615 639 root->SetTimeStamp(mergeStats.merged + 1); 616 617 ViewCellContainer::const_iterator it, it_end = viewCells.end();618 for (it = viewCells.begin(); it != it_end; ++ it)619 root->SetupChildLink(*it);620 621 640 mRoot = root; 622 641 } 623 else if ((int) viewCells.size() == 1)624 { 625 Debug << " here555" << endl;626 mRoot = viewCells[0];642 else if ((int)activeViewCells.size() == 1) 643 { 644 Debug << "setting root of the merge history" << endl; 645 mRoot = activeViewCells[0]; 627 646 } 628 647 … … 668 687 669 688 // recalculate cost 670 SetMergeCandidateValid(mc); 671 buf.push_back(mc); 689 if (ValidateMergeCandidate(mc)) 690 { 691 EvalMergeCost(mc); 692 buf.push_back(mc); 693 } 672 694 } 673 695 … … 684 706 685 707 686 int ViewCellsTree::UpdateMergedViewCells(ViewCellContainer &viewCells) 687 { 688 int numActiveViewCells = 0; 689 708 int ViewCellsTree::UpdateActiveViewCells(ViewCellContainer &viewCells) 709 { 710 int numMergedViewCells = 0; 711 712 Debug << "updating active vc: " << viewCells.size() << endl; 690 713 // find all already merged view cells and remove them from view cells 714 715 // sort out all view cells which are not active anymore, i.e., they 716 // were already part of a merge 691 717 int i = 0; 692 718 719 ViewCell::NewMail(); 720 693 721 while (1) 694 722 { 695 while (!viewCells.empty() && (!viewCells.back()->GetParent())) 723 // remove all merged view cells from end of the vector 724 while (!viewCells.empty() && (viewCells.back()->GetParent())) 696 725 { 697 726 viewCells.pop_back(); … … 703 732 704 733 // already merged view cell, put it to end of vector 705 if ( !viewCells[i]->IsRoot())734 if (viewCells[i]->GetParent()) 706 735 swap(viewCells[i], viewCells.back()); 707 736 708 ++ i; 709 } 737 viewCells[i ++]->Mail(); 738 } 739 710 740 711 741 // add new view cells to container only if they don't have been 712 742 // merged in the mean time 713 while (!mActiveViewCells.empty()) 714 { 715 if (!mActiveViewCells.back()->GetParent()) 716 { 717 viewCells.push_back(mActiveViewCells.back()); 718 ++ numActiveViewCells; 719 } 720 721 mActiveViewCells.pop_back(); 722 } 743 ViewCellContainer::const_iterator ait, ait_end = mMergedViewCells.end(); 744 for (ait = mMergedViewCells.begin(); ait != ait_end; ++ ait) 745 { 746 ViewCell *vc = mMergedViewCells.back(); 747 if (!vc->GetParent() && !vc->Mailed()) 748 { 749 vc->Mail(); 750 viewCells.push_back(vc); 751 ++ numMergedViewCells; 752 } 753 } 754 755 mMergedViewCells.clear(); 723 756 724 757 // update standard deviation … … 737 770 738 771 mDeviation /= (float)viewCells.size(); 739 740 // clear the view cells which were merged 741 mInactiveViewCells.clear(); 742 // remove the new view cells 743 mActiveViewCells.clear(); 744 745 return numActiveViewCells; 772 773 return numMergedViewCells; 746 774 } 747 775 … … 749 777 void ViewCellsTree::ExportMergedViewCells(ViewCellContainer &viewCells, 750 778 const ObjectContainer &objects, 751 const int num ActiveViewCells)779 const int numMergedViewCells) 752 780 { 753 781 … … 771 799 // assign special material to new view cells 772 800 // new view cells are on the back of container 773 if (i ++ >= (viewCells.size() - num ActiveViewCells))801 if (i ++ >= (viewCells.size() - numMergedViewCells)) 774 802 { 775 803 //m = RandomMaterial(); … … 798 826 ViewCellInterior *ViewCellsTree::MergeViewCells(ViewCell *l, ViewCell *r, int &pvsDiff) //const 799 827 { 800 ViewCellInterior *vc = mViewCellsManager->MergeViewCells( *l, *r);828 ViewCellInterior *vc = mViewCellsManager->MergeViewCells(l, r); 801 829 802 830 // if merge was unsuccessful … … 817 845 818 846 819 //-- clean up old view cells 820 if (0 && !mExportMergedViewCells) 821 { 822 DEL_PTR(l); 823 DEL_PTR(r); 824 } 825 else 826 { 827 mInactiveViewCells.push_back(l); 828 mInactiveViewCells.push_back(r); 829 830 mActiveViewCells.push_back(vc); 831 } 847 // new view cells are stored in this vector 848 mMergedViewCells.push_back(vc); 832 849 833 850 pvsDiff = vc->GetPvs().GetSize() - pvs1 - pvs2; … … 1018 1035 1019 1036 return mRenderCostWeight * (renderCost1 + renderCost2) + 1020 (1.0f - mRenderCostWeight) * (dev1 + dev2) / (float)mNum ViewCells;1037 (1.0f - mRenderCostWeight) * (dev1 + dev2) / (float)mNumActiveViewCells; 1021 1038 } 1022 1039 … … 1112 1129 { 1113 1130 const float penalty = EvalPvsPenalty(vc->GetPvs().GetSize(), lower, upper); 1114 return (mAvgRenderCost - penalty) * (mAvgRenderCost - penalty) / (float)mNum ViewCells;1131 return (mAvgRenderCost - penalty) * (mAvgRenderCost - penalty) / (float)mNumActiveViewCells; 1115 1132 } 1116 1133 … … 1128 1145 { 1129 1146 const float penalty = EvalPvsPenalty(vc->GetPvs().GetSize(), lower, upper); 1130 return fabs(mAvgRenderCost - penalty) / (float)mNum ViewCells;1147 return fabs(mAvgRenderCost - penalty) / (float)mNumActiveViewCells; 1131 1148 } 1132 1149 … … 1153 1170 1154 1171 1155 void ViewCellsTree::SetMergeCandidateValid(MergeCandidate &mc) const1172 bool ViewCellsTree::ValidateMergeCandidate(MergeCandidate &mc) const 1156 1173 { 1157 1174 while (mc.mLeftViewCell->mParent) … … 1165 1182 } 1166 1183 1167 EvalMergeCost(mc);1184 return mc.mLeftViewCell != mc.mRightViewCell; 1168 1185 } 1169 1186 … … 1210 1227 1211 1228 if (1) 1212 newDev = fabs(mAvgRenderCost - newPenalty) / (float)mNum ViewCells;1229 newDev = fabs(mAvgRenderCost - newPenalty) / (float)mNumActiveViewCells; 1213 1230 else 1214 newDev = fabs(mExpectedCost - newCost) / (float)mNum ViewCells;1231 newDev = fabs(mExpectedCost - newCost) / (float)mNumActiveViewCells; 1215 1232 1216 1233 oldDev = GetDeviation(vc1) + GetDeviation(vc2); … … 1251 1268 TraversalQueue tqueue; 1252 1269 tqueue.push(mRoot); 1253 Debug << "here34 " << numViewCells << endl;1270 1254 1271 while (!tqueue.empty()) 1255 1272 { 1256 1273 ViewCell *vc = tqueue.top(); 1257 tqueue.pop();1258 Debug << "here7 " << vc->GetTimeStamp() << endl;1259 if (vc->IsLeaf())1260 {1261 Debug << "here6" << endl;1274 1275 // save the view cells if it is a leaf or if enough view cells have already been traversed 1276 // because of the priority queue, this will be the optimal set of v 1277 if (vc->IsLeaf() || ((viewCells.size() + tqueue.size()) >= numViewCells)) 1278 { 1262 1279 viewCells.push_back(vc); 1263 1280 } 1264 else if (viewCells.size() + tqueue.size() < numViewCells)1265 { Debug << "here4" << endl;1281 else 1282 { 1266 1283 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 1267 1284 … … 1273 1290 } 1274 1291 } 1292 1293 tqueue.pop(); 1275 1294 } 1276 1295 } … … 1390 1409 bool MergeCandidate::IsValid() const 1391 1410 { 1392 return !(mLeftViewCell->mParent &&mRightViewCell->mParent);1411 return !(mLeftViewCell->mParent || mRightViewCell->mParent); 1393 1412 } 1394 1413
Note: See TracChangeset
for help on using the changeset viewer.