Changeset 586 for trunk/VUT/GtpVisibilityPreprocessor/src
- Timestamp:
- 02/03/06 23:02:07 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r582 r586 1235 1235 "false"); 1236 1236 1237 RegisterOption("ViewCells.PostProcess.refine", 1238 optBool, 1239 "view_cells_refine", 1240 "false"); 1241 1242 1243 RegisterOption("ViewCells.PostProcess.compress", 1244 optBool, 1245 "view_cells_compress", 1246 "false"); 1247 1237 1248 RegisterOption("ViewCells.exportToFile", 1238 1249 optBool, -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp
r585 r586 279 279 280 280 281 void ViewCellInterior::RemoveChildLink(ViewCell *l) 282 { 283 // erase leaf from old view cell 284 ViewCellContainer::iterator it = mChildren.begin(); 285 286 for (; (*it) != l; ++ it); 287 if (it == mChildren.end()) 288 Debug << "error" << endl; 289 else 290 mChildren.erase(it); 291 } 281 292 282 293 /************************************************************************/ … … 335 346 environment->GetIntValue("ViewCells.PostProcess.minViewCells", mMergeMinViewCells); 336 347 environment->GetFloatValue("ViewCells.PostProcess.maxCostRatio", mMergeMaxCostRatio); 337 348 environment->GetBoolValue("ViewCells.PostProcess.refine", mRefineViewCells); 349 338 350 339 351 Debug << "========= view cell tree options ================\n"; … … 341 353 Debug << "max cost ratio: " << mMergeMaxCostRatio << endl; 342 354 Debug << "max memory: " << mMaxMemory << endl; 355 Debug << "refining view cells: " << mRefineViewCells << endl; 343 356 344 357 MergeCandidate::sRenderCostWeight = mRenderCostWeight; … … 504 517 cout << "actual merge starts now ... " << endl; 505 518 506 //ResetMergeQueue();507 519 508 520 //-- use priority queue to merge leaf pairs … … 535 547 const int numMergedViewCells = UpdateActiveViewCells(activeViewCells); 536 548 537 // recompute priorities => reset render cost 538 ResetMergeQueue(); 549 // refines the view cells 550 // then priorities are recomputed 551 // and the candidates are put back into merge queue 552 if (mRefineViewCells) 553 RefineViewCells(rays, objects); 554 else 555 ResetMergeQueue(); 539 556 540 557 … … 645 662 646 663 UpdateActiveViewCells(activeViewCells); 647 ResetMergeQueue(); 664 665 // refine view cells and reset costs 666 if (mRefineViewCells) 667 RefineViewCells(rays, objects); 668 else 669 ResetMergeQueue(); 648 670 649 671 // create a root node if the merge was not done till root level, … … 652 674 { 653 675 Debug << "creating root of view cell hierarchy for " << (int)activeViewCells.size() << " view cells" << endl; 654 for (int i = 0; i < activeViewCells.size(); ++ i){655 Debug << " here233" << activeViewCells[i]->GetParent() << endl;656 Debug << " here233 " << activeViewCells[i] << endl;676 /*for (int i = 0; i < activeViewCells.size(); ++ i){ 677 Debug << "parent " << activeViewCells[i]->GetParent() << endl; 678 Debug << "viewcell " << activeViewCells[i] << endl;*/ 657 679 } 658 680 ViewCellInterior *root = mViewCellsManager->MergeViewCells(activeViewCells); … … 845 867 846 868 // TODO: should be done in view cells manager 847 ViewCellInterior *ViewCellsTree::MergeViewCells(ViewCell *l, ViewCell *r, int &pvsDiff) //const 869 ViewCellInterior *ViewCellsTree::MergeViewCells(ViewCell *l, 870 ViewCell *r, 871 int &pvsDiff) //const 848 872 { 849 873 ViewCellInterior *vc = mViewCellsManager->MergeViewCells(l, r); … … 876 900 877 901 878 879 int ViewCellsTree::RefineViewCells(const VssRayContainer &rays,const ObjectContainer &objects)902 int ViewCellsTree::RefineViewCells(const VssRayContainer &rays, 903 const ObjectContainer &objects) 880 904 { 881 905 Debug << "refining " << (int)mMergeQueue.size() << " candidates " << endl; 882 906 907 // intermediate buffer for shuffled view cells 908 vector<MergeCandidate> buf; 909 buf.reserve(mMergeQueue.size()); 910 883 911 // Use priority queue of remaining leaf pairs 884 912 // The candidates either share the same view cells or … … 888 916 // leaf is made part of the other view cell. It is tested if the 889 917 // remaining view cells are "better" than the old ones. 890 // 891 // repeat the merging test numPasses times. For example, it could be 892 // that a shuffle only makes sense if another pair was shuffled before. 893 // Therefore we keep two queues and shift the merge candidates between 894 // those two queues until numPasses is reached 895 896 queue<MergeCandidate> queue1; 897 queue<MergeCandidate> queue2; 898 899 queue<MergeCandidate> *shuffleQueue = &queue1; 900 queue<MergeCandidate> *backQueue = &queue2; 901 902 while (!mMergeQueue.empty()) 903 { 904 MergeCandidate mc = mMergeQueue.top(); 905 shuffleQueue->push(mc); 906 mMergeQueue.pop(); 907 } 908 909 const int numPasses = 5; 918 919 const int numPasses = 3; 910 920 int pass = 0; 911 921 int passShuffled = 0; … … 915 925 ViewCell::NewMail(); 916 926 917 do 918 { 919 passShuffled = 0; 920 while (!shuffleQueue->empty()) 921 { 922 MergeCandidate mc = shuffleQueue->front(); 923 shuffleQueue->pop(); 924 925 // both view cells equal or already shuffled 926 if ((mc.GetLeftViewCell() == mc.GetRightViewCell()) || 927 (GetSize(mc.GetLeftViewCell()) == 1) || 928 (GetSize(mc.GetRightViewCell()) == 1)) 929 { 930 continue; 927 while (!mMergeQueue.empty()) 928 { 929 MergeCandidate mc = mMergeQueue.top(); 930 mMergeQueue.pop(); 931 932 // both view cells equal or already shuffled 933 if ((mc.GetLeftViewCell() == mc.GetRightViewCell()) || 934 mc.GetLeftViewCell()->IsLeaf() || mc.GetRightViewCell()->IsLeaf()) 935 { 936 continue; 937 } 938 939 // candidate for shuffling 940 const bool wasShuffled = ShuffleLeaves(mc); 941 942 // shuffled or put into other queue for further refine 943 if (wasShuffled) 944 { 945 ++ passShuffled; 946 947 if (!mc.GetLeftViewCell()->Mailed()) 948 { 949 mc.GetLeftViewCell()->Mail(); 950 ++ shuffledViewCells; 931 951 } 932 933 // candidate for shuffling 934 const bool wasShuffled = 935 ShuffleLeaves(mc.GetLeftViewCell(), mc.GetRightViewCell()); 936 937 // shuffled or put into other queue for further refine 938 if (wasShuffled) 952 if (!mc.GetRightViewCell()->Mailed()) 939 953 { 940 ++ passShuffled; 941 942 if (!mc.GetLeftViewCell()->Mailed()) 943 { 944 mc.GetLeftViewCell()->Mail(); 945 ++ shuffledViewCells; 946 } 947 if (!mc.GetRightViewCell()->Mailed()) 948 { 949 mc.GetRightViewCell()->Mail(); 950 ++ shuffledViewCells; 951 } 954 mc.GetRightViewCell()->Mail(); 955 ++ shuffledViewCells; 952 956 } 953 else 954 { 955 backQueue->push(mc); 956 } 957 } 958 959 // now the back queue is the current shuffle queue 960 swap(shuffleQueue, backQueue); 961 shuffled += passShuffled; 962 Debug << "shuffled in pass: " << passShuffled << endl; 963 } 964 while (((++ pass) < numPasses) && passShuffled); 965 966 while (!shuffleQueue->empty()) 967 { 968 shuffleQueue->pop(); 969 } 957 } 958 959 // put back into intermediate vector 960 buf.push_back(mc); 961 } 962 963 964 //-- in the end, the candidates must be in the mergequeue again 965 // with the correct cost 966 967 cout << "reset merge queue ... "; 968 969 970 vector<MergeCandidate>::const_iterator bit, bit_end = buf.end(); 971 972 for (bit = buf.begin(); bit != bit_end; ++ bit) 973 { 974 MergeCandidate mc = *bit; 975 // recalculate cost 976 if (ValidateMergeCandidate(mc)) 977 { 978 EvalMergeCost(mc); 979 mMergeQueue.push(mc); 980 } 981 } 982 983 cout << "finished" << endl; 970 984 971 985 return shuffledViewCells; … … 1003 1017 1004 1018 float ViewCellsTree::EvalShuffleCost(ViewCell *leaf, 1005 ViewCell *vc1,1006 ViewCell *vc2) const1019 ViewCellInterior *vc1, 1020 ViewCellInterior *vc2) const 1007 1021 { 1008 1022 //const int pvs1 = SubtractedPvsSize(vc1, leaf, *leaf->mPvs); … … 1061 1075 1062 1076 void ViewCellsTree::ShuffleLeaf(ViewCell *leaf, 1063 ViewCell *vc1,1064 ViewCell *vc2) const1077 ViewCellInterior *vc1, 1078 ViewCellInterior *vc2) const 1065 1079 { 1066 1080 // compute new pvs and area 1081 // TODO change 1067 1082 vc1->GetPvs().SubtractPvs(leaf->GetPvs()); 1068 1083 vc2->GetPvs().AddPvs(leaf->GetPvs()); … … 1079 1094 } 1080 1095 1081 // TODO 1082 #if VC_HISTORY 1083 /// add to second view cell 1084 vc2->mLeaves.push_back(leaf); 1085 1086 // erase leaf from old view cell 1087 vector<BspLeaf *>::iterator it = vc1->mLeaves.begin(); 1088 1089 for (; *it != leaf; ++ it); 1090 vc1->mLeaves.erase(it); 1091 1092 /*vc1->GetPvs().mEntries.clear(); 1093 for (; it != vc1->mLeaves.end(); ++ it) 1094 { 1095 if (*it == leaf) 1096 vc1->mLeaves.erase(it); 1097 else 1098 vc1->GetPvs().AddPvs(*(*it)->mPvs); 1099 }*/ 1100 1101 leaf->SetViewCell(vc2); // finally change view cell 1102 #endif 1103 } 1104 1105 1106 bool ViewCellsTree::ShuffleLeaves(ViewCell *l, ViewCell *r) const 1096 1097 ViewCellInterior *p = dynamic_cast<ViewCellInterior *>(leaf->GetParent()); 1098 1099 p->RemoveChildLink(leaf); 1100 vc2->SetupChildLink(leaf); 1101 } 1102 1103 1104 bool ViewCellsTree::ShuffleLeaves(MergeCandidate &mc) const 1107 1105 { 1108 1106 float cost1, cost2; 1109 1107 1108 ViewCellInterior *vc1 = dynamic_cast<ViewCellInterior *>(mc.GetLeftViewCell()); 1109 ViewCellInterior *vc2 = dynamic_cast<ViewCellInterior *>(mc.GetRightViewCell()); 1110 1111 ViewCell *leaf1 = mc.GetInitialLeftViewCell(); 1112 ViewCell *leaf2 = mc.GetInitialRightViewCell(); 1113 1110 1114 //-- first test if shuffling would decrease cost 1111 cost1 = GetCostHeuristics( l);1112 cost2 = GetCostHeuristics( r);1115 cost1 = GetCostHeuristics(vc1); 1116 cost2 = GetCostHeuristics(vc2); 1113 1117 1114 1118 const float oldCost = cost1 + cost2; … … 1117 1121 float shuffledCost2 = Limits::Infinity; 1118 1122 1119 // the view cell should not be empty after the shuffle1120 #if VC_HISTORY 1121 shuffledCost1 = EvalShuffleCost(l, vc1, vc2);1122 /shuffledCost2 = EvalShuffleCost(r, vc2, vc1);1123 if (leaf1) 1124 shuffledCost1 = EvalShuffleCost(leaf1, vc1, vc2); 1125 if (leaf2) 1126 shuffledCost2 = EvalShuffleCost(leaf2, vc2, vc1); 1123 1127 1124 1128 // if cost of shuffle is less than old cost => shuffle … … 1126 1130 return false; 1127 1131 1128 1129 1132 if (shuffledCost1 < shuffledCost2) 1130 1133 { 1131 ShuffleLeaf(leaf1, vc1, vc2); 1132 leaf1->Mail(); 1134 if (leaf1) 1135 ShuffleLeaf(leaf1, vc1, vc2); 1136 mc.mInitialLeftViewCell = NULL; 1133 1137 } 1134 1138 else 1135 1139 { 1136 ShuffleLeaf(leaf2, vc2, vc1); 1137 leaf2->Mail(); 1138 } 1139 #endif 1140 if (leaf2) 1141 ShuffleLeaf(leaf2, vc2, vc1); 1142 mc.mInitialRightViewCell = NULL; 1143 } 1144 1140 1145 return true; 1141 1146 } … … 1529 1534 mDeviationIncr(0), 1530 1535 mLeftViewCell(l), 1531 mRightViewCell(r) 1536 mRightViewCell(r), 1537 mInitialLeftViewCell(l), 1538 mInitialRightViewCell(r) 1532 1539 { 1533 1540 //EvalMergeCost(); -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h
r584 r586 217 217 */ 218 218 void SetupChildLink(ViewCell *l); 219 void RemoveChildLink(ViewCell *l); 219 220 bool IsLeaf() const; 220 221 … … 362 363 to view cell 2. 363 364 */ 364 void ShuffleLeaf(ViewCell *leaf, ViewCell *vc1, ViewCell*vc2) const;365 void ShuffleLeaf(ViewCell *leaf, ViewCellInterior *vc1, ViewCellInterior *vc2) const; 365 366 366 367 /** Shuffles the leaves, i.e., tests if exchanging 367 368 the leaves helps in improving the view cells. 368 369 */ 369 bool ShuffleLeaves( ViewCell *l, ViewCell *r) const;370 bool ShuffleLeaves(MergeCandidate &mc) const; 370 371 371 372 /** Calculates cost for merge of view cell 1 and 2. 372 373 */ 373 float EvalShuffleCost(ViewCell *leaf, ViewCell *vc1, ViewCell *vc2) const; 374 float EvalShuffleCost(ViewCell *leaf, 375 ViewCellInterior *vc1, 376 ViewCellInterior *vc2) const; 374 377 375 378 /** Exports a snapshot of the merged view cells to disc. … … 411 414 ViewCellContainer mMergedViewCells; 412 415 416 417 bool mRefineViewCells; 413 418 414 419 /// weights between variance and render cost increase (must be between zero and one) -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r585 r586 57 57 58 58 environment->GetIntValue("ViewCells.active", mNumMergedViewCells); 59 environment->GetBoolValue("ViewCells.PostProcess.compress", mCompressViewCells); 59 60 60 61 mMinPvsSize = emptyViewCells ? 1 : 0; … … 2364 2365 2365 2366 //-- refines the merged view cells 2366 RefineViewCells(postProcessRays, objects); 2367 2368 int pvsEntries = mViewCellsTree->GetNumPvsEntries(mViewCellsTree->GetRoot()); 2369 Debug << "number of entries before compress: " << pvsEntries << endl; 2370 2371 mViewCellsTree->CompressViewCellsPvs(); 2372 2373 pvsEntries = mViewCellsTree->GetNumPvsEntries(mViewCellsTree->GetRoot()); 2374 Debug << "number of entries after compress: " << pvsEntries << endl; 2367 if (0) 2368 RefineViewCells(postProcessRays, objects); 2369 2370 if (mCompressViewCells) 2371 { 2372 int pvsEntries = mViewCellsTree->GetNumPvsEntries(mViewCellsTree->GetRoot()); 2373 Debug << "number of entries before compress: " << pvsEntries << endl; 2374 2375 mViewCellsTree->CompressViewCellsPvs(); 2376 2377 pvsEntries = mViewCellsTree->GetNumPvsEntries(mViewCellsTree->GetRoot()); 2378 Debug << "number of entries after compress: " << pvsEntries << endl; 2379 } 2375 2380 2376 2381 if (1) … … 2392 2397 2393 2398 //-- export shuffled view cells 2394 if ( 1)2399 if (0) 2395 2400 { 2396 2401 cout << "exporting shuffled view cells ... "; … … 2456 2461 2457 2462 // collapse sibling leaves that share the same view cell 2458 mVspBspTree->CollapseTree(); 2463 if (0) 2464 mVspBspTree->CollapseTree(); 2465 2459 2466 // recompute view cell list and statistics 2460 2467 ResetViewCells(); … … 2732 2739 2733 2740 2734 Debug << i << ": pvs size=" << (int) vc->GetPvs().GetSize()2741 Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) 2735 2742 << ", piercing rays=" << (int)vcRays.size() << endl; 2736 2743 // << ", leaves=" << (int)vc->mLeaves.size() << endl; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h
r582 r586 436 436 int mNumMergedViewCells; 437 437 438 bool mCompressViewCells; 439 438 440 ViewCellsStatistics mViewCellsStats; 439 441 /// the scene bounding box
Note: See TracChangeset
for help on using the changeset viewer.