Changeset 752 for GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
- Timestamp:
- 04/20/06 13:25:41 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r746 r752 18 18 { 19 19 public: 20 //bool operator() (HierarchyNode *v1, HierarchyNode *v2) const21 20 bool operator() (T v1, T v2) const 22 21 { … … 39 38 40 39 // pvs penalty can be different from pvs size 41 inline float EvalPvsPenalty(const int pvs, const int lower, const int upper)40 inline static float EvalPvsPenalty(const int pvs, const int lower, const int upper) 42 41 { 43 42 // clamp to minmax values 44 #if HAS_TO_BE_REDONE45 43 if (pvs < lower) 46 44 return (float)lower; 47 45 if (pvs > upper) 48 46 return (float)upper; 49 #endif 47 50 48 return (float)pvs; 51 49 } … … 70 68 71 69 /// Fast computation of merged pvs size 72 int ComputeMergedPvsSize(const ObjectPvs &pvs1, const ObjectPvs &pvs2)70 static int ComputeMergedPvsSize(const ObjectPvs &pvs1, const ObjectPvs &pvs2) 73 71 { 74 72 // add first pvs … … 99 97 100 98 // computet render cost of merge 101 float ViewCellsTree::ComputeMergedPvsCost(const ObjectPvs &pvs1, const ObjectPvs &pvs2) const 99 float ViewCellsTree::ComputeMergedPvsCost(const ObjectPvs &pvs1, 100 const ObjectPvs &pvs2) const 102 101 { 103 102 float renderCost = 0; … … 143 142 mParent(NULL), 144 143 mMergeCost(0), 145 mIsActive(false) 144 mIsActive(false), 145 mPvsSize(0), 146 mPvsSizeValid(false) 146 147 { 147 148 } … … 156 157 mMergeCost(0), 157 158 mIsActive(false), 158 mLastUpdated(sLastUpdated) 159 mLastUpdated(sLastUpdated), 160 mPvsSize(0), 161 mPvsSizeValid(false) 159 162 { 160 163 } … … 165 168 return mPvs; 166 169 } 170 167 171 168 172 ObjectPvs &ViewCell::GetPvs() … … 205 209 { 206 210 mArea = area; 211 } 212 213 214 void ViewCell::SetColor(const RgbColor &color) 215 { 216 mColor = color; 217 } 218 219 220 RgbColor ViewCell::GetColor() const 221 { 222 return mColor; 207 223 } 208 224 … … 367 383 mUseAreaForPvs(false), 368 384 mViewCellsManager(vcm), 369 mIsCompressed(false) 385 #if 0 386 mViewCellsStorage(PVS_IN_INTERIORS) 387 #else 388 mViewCellsStorage(PVS_IN_LEAVES) 389 #endif 370 390 { 371 391 environment->GetBoolValue("ViewCells.Visualization.exportMergedViewCells", mExportMergedViewCells); … … 393 413 float ViewCellsTree::GetMemUsage() const 394 414 { 415 // TODO 395 416 return 0; 396 417 /*(sizeof(ViewCellsTree) + … … 513 534 // we start with the current view cells from the view cell manager. 514 535 // The active view cells will change with subsequent merges 515 Debug << "here2" << endl; Debug.flush();536 516 537 // todo: should rather take initial view cells 517 538 ViewCellContainer &activeViewCells = mViewCellsManager->GetViewCells(); 518 //ViewCellContainer activeViewCells; 519 520 Debug << "here2.6" << endl; Debug.flush(); 539 540 521 541 ViewCell::NewMail(); 522 542 … … 704 724 Debug << "setting root of the merge history" << endl; 705 725 mRoot = activeViewCells[0]; 706 Debug << "rootvc volume: " << mRoot->GetVolume() << endl; 726 Debug << "volume of the root view cell: " << mRoot->GetVolume() << " " << mViewCellsManager->GetViewSpaceBox().GetVolume() << endl; 727 } 728 else 729 { 730 Debug << "big error, root is NULL" << endl; 707 731 } 708 732 … … 803 827 swap(viewCells[i], viewCells.back()); 804 828 805 // mail view cell asit has not been merged829 // mail view cell that it has not been merged 806 830 viewCells[i]->Mail(); 807 831 … … 814 838 // merged in the mean time 815 839 ViewCellContainer::const_iterator ait, ait_end = mMergedViewCells.end(); 840 816 841 for (ait = mMergedViewCells.begin(); ait != ait_end; ++ ait) 817 842 { … … 825 850 } 826 851 852 // dispose old merged view cells 827 853 mMergedViewCells.clear(); 828 854 … … 836 862 const int lower = mViewCellsManager->GetMinPvsSize(); 837 863 const int upper = mViewCellsManager->GetMaxPvsSize(); 864 838 865 const float penalty = EvalPvsPenalty((*vit)->GetPvs().GetSize(), lower, upper); 839 866 … … 905 932 if (!vc) return NULL; 906 933 934 // set to the new parent view cell 907 935 l->SetParent(vc); 908 936 r->SetParent(vc); … … 932 960 pvsDiff = vc->GetPvs().GetSize() - pvs1 - pvs2; 933 961 962 963 964 //Ždon't store intermediate pvs 965 if (mViewCellsStorage == PVS_IN_LEAVES) 966 { 967 l->mPvsSize = l->GetPvs().GetSize(); 968 l->mPvsSizeValid = true; 969 970 if (!l->IsLeaf()) 971 l->GetPvs().Clear(); 972 973 r->mPvsSize = r->GetPvs().GetSize(); 974 r->mPvsSizeValid = true; 975 976 if (!r->IsLeaf()) 977 r->GetPvs().Clear(); 978 979 } 980 981 934 982 return vc; 935 983 } 936 937 984 938 985 … … 1189 1236 if (1) 1190 1237 { 1191 const float penalty = EvalPvsPenalty(vc->GetPvs().GetSize(), lower, upper); 1192 return (mAvgRenderCost - penalty) * (mAvgRenderCost - penalty) / (float)mNumActiveViewCells; 1238 const float penalty = 1239 EvalPvsPenalty(vc->GetPvs().GetSize(), lower, upper); 1240 return (mAvgRenderCost - penalty) * (mAvgRenderCost - penalty) / 1241 (float)mNumActiveViewCells; 1193 1242 } 1194 1243 … … 1233 1282 bool ViewCellsTree::ValidateMergeCandidate(MergeCandidate &mc) const 1234 1283 { 1284 // propagate up so we have only the active view cells 1235 1285 while (mc.mLeftViewCell->mParent) 1236 1286 { … … 1243 1293 } 1244 1294 1295 // this view cell was already merged 1296 //return mc.mLeftViewCell && (mc.mLeftViewCell != mc.mRightViewCell); 1245 1297 return mc.mLeftViewCell != mc.mRightViewCell; 1246 1298 } … … 1250 1302 { 1251 1303 //-- compute pvs difference 1252 const float newPvs = 1253 #if 1 // not valid if not using const cost per object!! 1254 ComputeMergedPvsSize(mc.mLeftViewCell->GetPvs(), 1255 mc.mRightViewCell->GetPvs()); 1256 #else 1257 ComputeMergedPvsCost(mc.mLeftViewCell->GetPvs(), 1258 mc.mRightViewCell->GetPvs()); 1259 #endif 1304 int newPvs; 1305 if (1) // not valid if not using const cost per object!! 1306 newPvs = ComputeMergedPvsSize(mc.mLeftViewCell->GetPvs(), mc.mRightViewCell->GetPvs()); 1307 else 1308 newPvs = (int)ComputeMergedPvsCost(mc.mLeftViewCell->GetPvs(), mc.mRightViewCell->GetPvs()); 1260 1309 1261 1310 const float newPenalty = EvalPvsPenalty(newPvs, … … 1305 1354 } 1306 1355 1307 void ViewCellsTree::CompressViewCellsPvs() 1308 { 1309 if (!mIsCompressed) 1310 { 1311 mIsCompressed = true; 1356 1357 void ViewCellsTree::SetViewCellsStorage(int stype) 1358 { 1359 if (mViewCellsStorage == stype) 1360 return; 1361 1362 // TODO 1363 switch (stype) 1364 { 1365 case COMPRESSED: 1312 1366 CompressViewCellsPvs(mRoot); 1313 } 1314 } 1367 break; 1368 default: 1369 break; 1370 } 1371 1372 mViewCellsStorage = stype; 1373 } 1374 1315 1375 1316 1376 void ViewCellsTree::CompressViewCellsPvs(ViewCell *root) … … 1344 1404 const float vol = box.GetVolume(); 1345 1405 1406 const int rootPvs = GetPvsSize(mRoot); 1407 1346 1408 Debug << "vsb volume: " << vol << endl; 1347 1409 Debug << "root volume: " << mRoot->GetVolume() << endl; 1348 Debug << "root pvs: " << mRoot->GetPvs().GetSize()<< endl;1410 Debug << "root pvs: " << rootPvs << endl; 1349 1411 1350 1412 int totalPvs; … … 1352 1414 1353 1415 float deviation = 0; 1354 totalPvs = (int)mRoot->GetPvs().GetSize();1355 totalRenderCost = avgRenderCost = expectedCost = (float) mRoot->GetPvs().GetSize();1416 totalPvs = rootPvs; 1417 totalRenderCost = avgRenderCost = expectedCost = (float)rootPvs; 1356 1418 1357 1419 ofstream stats; 1358 1420 stats.open(mergeStats.c_str()); 1359 1421 1422 //-- first view cell 1360 1423 stats 1361 1424 << "#Pass\n" << 0 << endl … … 1364 1427 << "#RenderCostDecrease\n" << 0 << endl // TODO 1365 1428 << "#TotalRenderCost\n" << totalRenderCost << endl 1366 << "#CurrentPvs\n" << mRoot->GetPvs().GetSize()<< endl1429 << "#CurrentPvs\n" << rootPvs << endl 1367 1430 << "#ExpectedCost\n" << expectedCost << endl 1368 1431 << "#AvgRenderCost\n" << avgRenderCost << endl … … 1383 1446 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 1384 1447 1385 const int parentPvs = interior->GetPvs().GetSize();1448 const int parentPvs = GetPvsSize(interior); 1386 1449 const float parentCost = (float)parentPvs * interior->GetVolume(); 1387 1450 float childCost = 0; … … 1394 1457 for (it = interior->mChildren.begin(); it != it_end; ++ it) 1395 1458 { 1396 childCost += (float)(*it)->GetPvs().GetSize() * (*it)->GetVolume(); 1397 childPvs += (*it)->GetPvs().GetSize(); 1459 int pvsSize = GetPvsSize(*it); 1460 childCost += (float) pvsSize * (*it)->GetVolume(); 1461 childPvs += pvsSize; 1398 1462 1399 1463 tqueue.push(*it); … … 1416 1480 << "#RenderCostDecrease\n" << costDecr << endl // TODO 1417 1481 << "#TotalRenderCost\n" << totalRenderCost << endl 1418 << "#CurrentPvs\n" << vc->GetPvs().GetSize()<< endl1482 << "#CurrentPvs\n" << parentPvs << endl 1419 1483 << "#ExpectedCost\n" << expectedCost << endl 1420 1484 << "#AvgRenderCost\n" << avgRenderCost << endl … … 1432 1496 1433 1497 1434 #if 01435 float ViewCellsTree::ComputeVolume(ViewCell *vc)1436 {1437 if (vc->IsLeaf())1438 {1439 return vc->GetVolume();1440 }1441 else1442 {1443 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);1444 1445 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();1446 1447 float volume = 0;1448 1449 for (it = interior->mChildren.begin(); it != it_end; ++ it)1450 {1451 volume += ComputeVolume(*it);1452 }1453 1454 interior->SetVolume(volume);1455 return volume;1456 }1457 }1458 #endif1459 1460 1498 void ViewCellsTree::SetRoot(ViewCell *root) 1461 1499 { … … 1558 1596 } 1559 1597 1560 int dummy = interior->GetPvs().GetSize();1598 /*int dummy = interior->GetPvs().GetSize(); 1561 1599 1562 1600 for (cit = interior->mChildren.begin(); cit != cit_end; ++ cit) 1563 1601 { 1564 1602 dummy += (*cit)->GetPvs().GetSize(); 1565 } 1566 1567 } 1568 1569 1603 }*/ 1604 1605 } 1606 1607 // TODO 1570 1608 void ViewCellsTree::GetPvs(ViewCell *vc, ObjectPvs &pvs) const 1571 1609 { 1572 1610 Intersectable::NewMail(); 1573 1611 1574 if ( !mIsCompressed)1612 if (mViewCellsStorage == PVS_IN_INTERIORS) 1575 1613 pvs = vc->GetPvs(); 1576 1614 … … 1612 1650 int ViewCellsTree::GetPvsSize(ViewCell *vc) const 1613 1651 { 1652 int pvsSize = 0; 1653 1654 if (vc->IsLeaf()) 1655 { 1656 pvsSize = vc->GetPvs().GetSize(); 1657 } 1658 1659 1614 1660 Intersectable::NewMail(); 1615 1661 1616 if (!mIsCompressed) 1617 return vc->GetPvs().GetSize(); 1618 1619 1620 ////////////////////////777 1662 ////////////////////////// 1663 switch (mViewCellsStorage) 1664 { 1665 case PVS_IN_LEAVES: //-- store pvs only in leaves 1666 { 1667 if (vc->mPvsSizeValid) 1668 { 1669 pvsSize = vc->mPvsSize; 1670 break; 1671 } 1672 1673 //-- if no valid pvs size stored as a scalar=> compute new pvs size 1674 ViewCellContainer leaves; 1675 CollectLeaves(vc, leaves); 1676 1677 ViewCellContainer::const_iterator it, it_end = leaves.end(); 1678 1679 Intersectable::NewMail(); 1680 1681 // sum different intersectables 1682 for (it = leaves.begin(); it != it_end; ++ it) 1683 { 1684 ObjectPvsMap::iterator oit, oit_end = (*it)->GetPvs().mEntries.end(); 1685 1686 // mail all from first pvs 1687 for (oit = (*it)->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 1688 { 1689 Intersectable *intersect = (*oit).first; 1690 1691 if (!intersect->Mailed()) 1692 { 1693 ++ pvsSize; 1694 intersect->Mail(); 1695 } 1696 } 1697 } 1698 1699 break; 1700 } 1701 case COMPRESSED: 1702 { 1703 //////////////////////// 1621 1704 //-- compressed pvs 1622 1705 1706 if (vc->mPvsSizeValid) 1707 return vc->mPvsSize; 1708 1709 // if no pvs size stored: compute 1623 1710 int pvsSize = 0; 1624 1711 ViewCell *root = vc; … … 1653 1740 } 1654 1741 } 1742 break; 1743 } 1744 case PVS_IN_INTERIORS: 1745 default:Debug << "in interiors: " << vc->mPvsSize << " $$ " << vc->GetPvs().GetSize() << endl; 1746 pvsSize = vc->GetPvs().GetSize(); 1747 } 1655 1748 1656 1749 return pvsSize; 1657 1658 1750 } 1659 1751 … … 1672 1764 int pvsSize = 0; 1673 1765 // only count leaves for uncompressed method for fairness 1674 if (mIsCompressed || vc->IsLeaf()) 1766 if ((mViewCellsStorage == PVS_IN_INTERIORS) || vc->IsLeaf()) 1767 { 1675 1768 pvsSize = vc->GetPvs().GetSize(); 1769 } 1676 1770 1677 1771 if (!vc->IsLeaf()) … … 1691 1785 1692 1786 1693 bool ViewCellsTree::IsCompressed() const1694 { 1695 return m IsCompressed;1787 int ViewCellsTree::ViewCellsStorage() const 1788 { 1789 return mViewCellsStorage; 1696 1790 } 1697 1791 … … 1845 1939 if (!vc->GetValid()) 1846 1940 ++ vcStat.invalid; 1847 1848 /*ViewCellsContainer leaves;1849 CollectLeaves(vc, leaves);1850 1851 vcStat.leaves = (int)leaves.size();*/1852 1941 } 1853 1942 … … 1969 2058 void ViewCellsTree::SetActiveSetToLeaves() 1970 2059 { 2060 // todo 1971 2061 } 1972 2062 … … 2026 2116 bool MergeCandidate::IsValid() const 2027 2117 { 2118 // if one has a parent, it was already merged 2028 2119 return !(mLeftViewCell->mParent || mRightViewCell->mParent); 2029 2120 }
Note: See TracChangeset
for help on using the changeset viewer.