Changeset 703 for GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
- Timestamp:
- 03/16/06 07:06:22 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r697 r703 544 544 } 545 545 546 /* 547 int ViewCellsManager::ConstructLocalMergeTree(vector<LocalMergeCandidate> candidates) 548 549 { 550 while(!candidates.empty()) 551 { 552 MergeCandidate mc = candidates.back(); 553 candidates.pop_back(); 554 EvalMergeCost(mc); 555 mergeQueue.push(mc); 556 } 557 558 ViewCell::NewMail(); 559 560 561 long startTime = GetTime(); 562 563 mergeStats.candidates = (int)mMergeQueue.size(); 564 565 // passes are needed for statistics, because we don't want to record 566 // every merge 567 int pass = 0; 568 int mergedPerPass = 0; 569 float realExpectedCost = mExpectedCost; 570 float realAvgRenderCost = mAvgRenderCost; 571 int realNumActiveViewCells = mNumActiveViewCells; 572 573 reset. 574 575 int numMergedViewCells = 0; 576 577 environment->GetIntValue("ViewCells.PostProcess.maxMergesPerPass", maxMergesPerPass); 578 environment->GetFloatValue("ViewCells.PostProcess.avgCostMaxDeviation", avgCostMaxDeviation); 579 580 cout << "actual merge starts now ... " << endl; 581 582 //-- use priority queue to merge leaf pairs 583 584 //const float maxAvgCost = 350; 585 while (!mMergeQueue.empty())//NumActiveViewCells > mMergeMinViewCells)) 586 { 587 //-- reset merge queue if the ratio of current expected cost / real expected cost 588 // too small or after a given number of merges 589 if ((mergedPerPass > maxMergesPerPass) || 590 (avgCostMaxDeviation > mAvgRenderCost / realAvgRenderCost)) 591 { 592 // adjust render cost 593 ++ pass; 594 595 mergedPerPass = 0; 596 mExpectedCost = realExpectedCost; 597 598 599 600 // refines the view cells 601 // then priorities are recomputed 602 // and the candidates are put back into merge queue 603 if (mRefineViewCells) 604 RefineViewCells(rays, objects); 605 else 606 ResetMergeQueue(); 607 608 Debug << "Values after reset: " 609 << " erc: " << mExpectedCost 610 << " avg: " << mAvgRenderCost 611 << " dev: " << mDeviation << endl; 612 613 if (mExportMergedViewCells) 614 { 615 ExportMergedViewCells(activeViewCells, objects, numMergedViewCells); 616 } 617 } 618 619 620 MergeCandidate mc = mMergeQueue.top(); 621 mMergeQueue.pop(); 622 623 // both view cells equal 624 // NOTE: do I really still need this? probably cannot happen!! 625 if (mc.mLeftViewCell == mc.mRightViewCell) 626 continue; 627 628 if (mc.IsValid()) 629 { 630 ViewCell::NewMail(); 631 632 //-- update statistical values 633 -- realNumActiveViewCells; 634 ++ mergeStats.merged; 635 ++ mergedPerPass; 636 637 const float renderCostIncr = mc.GetRenderCost(); 638 const float mergeCostIncr = mc.GetMergeCost(); 639 640 totalRenderCost += renderCostIncr; 641 mDeviation += mc.GetDeviationIncr(); 642 643 644 // merge the view cells of leaf1 and leaf2 645 int pvsDiff; 646 ViewCellInterior *mergedVc = 647 MergeViewCells(mc.mLeftViewCell, mc.mRightViewCell, pvsDiff); 648 649 650 // total render cost and deviation has changed 651 // real expected cost will be larger than expected cost used for the 652 // cost heuristics, but cannot recompute costs on each increase of the 653 // expected cost 654 totalPvs += pvsDiff; 655 realExpectedCost = totalRenderCost / (float)realNumActiveViewCells; 656 realAvgRenderCost = (float)totalPvs / (float)realNumActiveViewCells; 657 658 // set merge cost to this node 659 mergedVc->SetMergeCost(totalRenderCost); 660 661 //if (mViewCellsManager->EqualToSpatialNode(mergedVc)) 662 // ++ mergeStats.siblings; 663 mergedVc->SetCost(realExpectedCost); 664 665 if ((mergeStats.merged % statsOut) == 0) 666 cout << "merged " << mergeStats.merged << " view cells" << endl; 667 668 } 669 else 670 { 671 // merge candidate not valid, because one of the leaves was already 672 // merged with another one => validate and reinsert into queue 673 if (ValidateMergeCandidate(mc)) 674 { 675 EvalMergeCost(mc); 676 mMergeQueue.push(mc); 677 } 678 } 679 680 } 681 682 683 // adjust stats and reset queue one final time 684 mExpectedCost = realExpectedCost; 685 mAvgRenderCost = realAvgRenderCost; 686 mNumActiveViewCells = realNumActiveViewCells; 687 688 UpdateActiveViewCells(activeViewCells); 689 690 691 // refine view cells and reset costs 692 if (mRefineViewCells) 693 RefineViewCells(rays, objects); 694 else 695 ResetMergeQueue(); 696 697 // create a root node if the merge was not done till root level, 698 // else take the single node as new root 699 if ((int)activeViewCells.size() > 1) 700 { 701 Debug << "creating root of view cell hierarchy for " 702 << (int)activeViewCells.size() << " view cells" << endl; 703 704 ViewCellInterior *root = mViewCellsManager->MergeViewCells(activeViewCells); 705 root->SetMergeCost(totalRenderCost); 706 // $$JB keep this 0 temporarilly 707 root->SetCost(0.0f); 708 709 mRoot = root; 710 } 711 else if ((int)activeViewCells.size() == 1) 712 { 713 Debug << "setting root of the merge history" << endl; 714 mRoot = activeViewCells[0]; 715 } 716 717 //-- empty merge queue just in case 718 while (!mMergeQueue.empty()) 719 { 720 mMergeQueue.pop(); 721 } 722 723 // TODO delete because makes no sense here 724 mergeStats.expectedRenderCost = realExpectedCost; 725 mergeStats.deviation = mDeviation; 726 727 // we want to optimize this heuristics 728 mergeStats.heuristics = 729 mDeviation * (1.0f - mRenderCostWeight) + 730 mExpectedCost * mRenderCostWeight; 731 732 mergeStats.mergeTime = TimeDiff(startTime, GetTime()); 733 mergeStats.Stop(); 734 Debug << mergeStats << endl << endl; 735 736 // assign colors for the view cells so that at least one is always consistent 737 AssignRandomColors(); 738 739 //TODO: should return sample contributions? 740 return mergeStats.merged; 741 } 742 */ 546 743 547 744 bool ViewCellsManager::CheckValidity(ViewCell *vc,
Note: See TracChangeset
for help on using the changeset viewer.