Changeset 574 for trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
- Timestamp:
- 01/25/06 01:44:46 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r573 r574 178 178 const BspTreeStatistics &VspBspTree::GetStatistics() const 179 179 { 180 return m Stat;180 return mBspStats; 181 181 } 182 182 … … 273 273 AxisAlignedBox3 *forcedBoundingBox) 274 274 { 275 m Stat.nodes = 1;275 mBspStats.nodes = 1; 276 276 mBox.Initialize(); // initialise BSP tree bounding box 277 277 … … 353 353 mTermMinProbability *= mBox.GetVolume(); 354 354 355 m Stat.polys = (int)polys.size();355 mBspStats.polys = (int)polys.size(); 356 356 357 357 cout << "finished" << endl; … … 373 373 return 374 374 (sizeof(VspBspTree) + 375 m Stat.Leaves() * sizeof(BspLeaf) +376 m Stat.Interior() * sizeof(BspInterior) +377 m Stat.accumRays * sizeof(RayInfo)) / (1024.0f * 1024.0f);375 mBspStats.Leaves() * sizeof(BspLeaf) + 376 mBspStats.Interior() * sizeof(BspInterior) + 377 mBspStats.accumRays * sizeof(RayInfo)) / (1024.0f * 1024.0f); 378 378 } 379 379 … … 405 405 tStack.push(tData); 406 406 407 m Stat.Start();407 mBspStats.Start(); 408 408 cout << "Contructing vsp bsp tree ... \n"; 409 409 … … 439 439 << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 440 440 441 if (m Stat.Leaves() >= nleaves)441 if (mBspStats.Leaves() >= nleaves) 442 442 { 443 443 nleaves += 500; 444 444 445 cout << "leaves=" << m Stat.Leaves() << endl;445 cout << "leaves=" << mBspStats.Leaves() << endl; 446 446 Debug << "needed " 447 447 << TimeDiff(interTime, GetTime())*1e-3 << " secs to create 500 leaves" << endl; … … 453 453 cout << "finished\n"; 454 454 455 m Stat.Stop();455 mBspStats.Stop(); 456 456 } 457 457 … … 463 463 (data.mPvs <= mTermMinPvs) || 464 464 (data.mProbability <= mTermMinProbability) || 465 (m Stat.Leaves() >= mMaxViewCells) ||465 (mBspStats.Leaves() >= mMaxViewCells) || 466 466 (data.GetAvgRayContribution() > mTermMaxRayContribution) || 467 467 (data.mDepth >= mTermMaxDepth)); … … 509 509 AddToPvs(leaf, *tData.mRays, sampCon, conSamp); 510 510 511 m Stat.contributingSamples += conSamp;512 m Stat.sampleContributions +=(int) sampCon;511 mBspStats.contributingSamples += conSamp; 512 mBspStats.sampleContributions +=(int) sampCon; 513 513 514 514 //-- store additional info … … 526 526 PropagateUpValidity(leaf); 527 527 528 ++ m Stat.invalidLeaves;528 ++ mBspStats.invalidLeaves; 529 529 } 530 530 … … 572 572 { 573 573 // terminate branch because of max cost 574 ++ m Stat.maxCostNodes;574 ++ mBspStats.maxCostNodes; 575 575 return leaf; 576 576 } 577 577 } 578 578 579 m Stat.nodes += 2;579 mBspStats.nodes += 2; 580 580 581 581 //-- subdivide further … … 1160 1160 1161 1161 //! error also computed if cost ratio is missed 1162 ++ m Stat.splits[axis];1162 ++ mBspStats.splits[axis]; 1163 1163 isAxisAlignedSplit = true; 1164 1164 } … … 1509 1509 1510 1510 // store maximal and minimal depth 1511 if (data.mDepth > m Stat.maxDepth)1512 m Stat.maxDepth = data.mDepth;1513 1514 if (data.mPvs > m Stat.maxPvs)1515 m Stat.maxPvs = data.mPvs;1516 1517 if (data.mDepth < m Stat.minDepth)1518 m Stat.minDepth = data.mDepth;1511 if (data.mDepth > mBspStats.maxDepth) 1512 mBspStats.maxDepth = data.mDepth; 1513 1514 if (data.mPvs > mBspStats.maxPvs) 1515 mBspStats.maxPvs = data.mPvs; 1516 1517 if (data.mDepth < mBspStats.minDepth) 1518 mBspStats.minDepth = data.mDepth; 1519 1519 1520 1520 if (data.mDepth >= mTermMaxDepth) 1521 ++ m Stat.maxDepthNodes;1521 ++ mBspStats.maxDepthNodes; 1522 1522 // accumulate rays to compute rays / leaf 1523 m Stat.accumRays += (int)data.mRays->size();1523 mBspStats.accumRays += (int)data.mRays->size(); 1524 1524 1525 1525 if (data.mPvs < mTermMinPvs) 1526 ++ m Stat.minPvsNodes;1526 ++ mBspStats.minPvsNodes; 1527 1527 1528 1528 if ((int)data.mRays->size() < mTermMinRays) 1529 ++ m Stat.minRaysNodes;1529 ++ mBspStats.minRaysNodes; 1530 1530 1531 1531 if (data.GetAvgRayContribution() > mTermMaxRayContribution) 1532 ++ m Stat.maxRayContribNodes;1532 ++ mBspStats.maxRayContribNodes; 1533 1533 1534 1534 if (data.mProbability <= mTermMinProbability) 1535 ++ m Stat.minProbabilityNodes;1535 ++ mBspStats.minProbabilityNodes; 1536 1536 1537 1537 // accumulate depth to compute average depth 1538 m Stat.accumDepth += data.mDepth;1538 mBspStats.accumDepth += data.mDepth; 1539 1539 1540 1540 #ifdef _DEBUG … … 1655 1655 1656 1656 1657 void VspBspTree:: ValidateTree()1657 void VspBspTree::CollapseViewCells() 1658 1658 { 1659 1659 stack<BspNode *> nodeStack; … … 1664 1664 nodeStack.push(mRoot); 1665 1665 1666 const bool addToUnbounded = false;1667 1668 1666 while (!nodeStack.empty()) 1669 1667 { … … 1672 1670 1673 1671 if (node->IsLeaf()) 1674 1675 Bsp Leaf *leaf = dynamic_cast<BspLeaf *>(node);1676 1677 if (! addToUnbounded && node->TreeValid())1672 { 1673 BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 1674 1675 if (!viewCell->GetValid()) 1678 1676 { 1679 1677 BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 1680 1678 1681 if (!mViewCellsManager->CheckValidity(viewCell, 1682 mViewCellsManager->GetMinPvsSize(), 1683 mViewCellsManager->GetMaxPvsSize())) 1679 vector<BspLeaf *>::const_iterator it, it_end = viewCell->mLeaves.end(); 1680 for (it = viewCell->mLeaves.begin();it != it_end; ++ it) 1684 1681 { 1685 vector<BspLeaf *>::const_iterator it, it_end = viewCell->mLeaves.end(); 1686 for (it = viewCell->mLeaves.begin();it != it_end; ++ it) 1687 { 1688 BspLeaf *l = *it; 1689 1690 l->SetTreeValid(false); 1691 PropagateUpValidity(l); 1692 1693 if (addToUnbounded) 1694 l->SetViewCell(GetOrCreateOutOfBoundsCell()); 1695 1696 ++ mStat.invalidLeaves; 1697 } 1698 1699 // add to unbounded view cell or set to invalid 1700 if (addToUnbounded) 1701 { 1702 GetOrCreateOutOfBoundsCell()->GetPvs().AddPvs(viewCell->GetPvs()); 1703 DEL_PTR(viewCell); 1704 } 1705 else 1706 { 1707 viewCell->SetValid(false); 1708 } 1682 BspLeaf *l = *it; 1683 l->SetViewCell(GetOrCreateOutOfBoundsCell()); 1684 ++ mBspStats.invalidLeaves; 1709 1685 } 1686 1687 // add to unbounded view cell 1688 GetOrCreateOutOfBoundsCell()->GetPvs().AddPvs(viewCell->GetPvs()); 1689 DEL_PTR(viewCell); 1710 1690 } 1711 1691 } … … 1719 1699 } 1720 1700 1721 Debug << "invalid leaves: " << mStat.invalidLeaves << endl; 1722 } 1701 Debug << "invalid leaves: " << mBspStats.invalidLeaves << endl; 1702 } 1703 1704 1705 void VspBspTree::ValidateTree() 1706 { 1707 stack<BspNode *> nodeStack; 1708 1709 if (!mRoot) 1710 return; 1711 1712 nodeStack.push(mRoot); 1713 1714 mBspStats.invalidLeaves = 0; 1715 while (!nodeStack.empty()) 1716 { 1717 BspNode *node = nodeStack.top(); 1718 nodeStack.pop(); 1719 1720 if (node->IsLeaf()) 1721 { 1722 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 1723 1724 if (!leaf->GetViewCell()->GetValid()) 1725 ++ mBspStats.invalidLeaves; 1726 1727 // validity flags don't match => repair 1728 if (leaf->GetViewCell()->GetValid() != leaf->TreeValid()) 1729 { 1730 leaf->SetTreeValid(leaf->GetViewCell()->GetValid()); 1731 PropagateUpValidity(leaf); 1732 } 1733 } 1734 else 1735 { 1736 BspInterior *interior = dynamic_cast<BspInterior *>(node); 1737 1738 nodeStack.push(interior->GetFront()); 1739 nodeStack.push(interior->GetBack()); 1740 } 1741 } 1742 1743 Debug << "invalid leaves: " << mBspStats.invalidLeaves << endl; 1744 } 1745 1723 1746 1724 1747 … … 1784 1807 int splits = 0; 1785 1808 1786 while (!rays.empty()) 1787 { 1788 RayInfo bRay = rays.back(); 1789 rays.pop_back(); 1790 1809 RayInfoContainer::const_iterator it, it_end = rays.end(); 1810 1811 for (it = rays.begin(); it != it_end; ++ it) 1812 { 1813 RayInfo bRay = *it; 1814 1791 1815 VssRay *ray = bRay.mRay; 1792 1816 float t; … … 2213 2237 int splits = 0; 2214 2238 2215 while (!polys.empty()) 2216 { 2217 Polygon3 *poly = polys.back(); 2218 polys.pop_back(); 2239 PolygonContainer::const_iterator it, it_end = polys.end(); 2240 2241 for (it = polys.begin(); it != polys.end(); ++ it) 2242 { 2243 Polygon3 *poly = *it; 2219 2244 2220 2245 // classify polygon … … 2632 2657 BspLeaf *leaf = *it; 2633 2658 2634 /// create leaf pvs (needed for post processing 2659 /// create leaf pvs (needed for post processing) 2635 2660 leaf->mPvs = new ObjectPvs(leaf->GetViewCell()->GetPvs()); 2636 2661 … … 2674 2699 int VspBspTree::CollectMergeCandidates(const VssRayContainer &rays) 2675 2700 { 2676 vector<BspRay *> bspRays;2677 2678 2701 ViewCell::NewMail(); 2679 2702 long startTime = GetTime(); 2680 ConstructBspRays(bspRays, rays); 2681 Debug << (int)bspRays.size() << " bsp rays constructed in " 2682 << TimeDiff(startTime, GetTime()) * 1e-3f << " secs" << endl; 2683 2703 2684 2704 map<BspLeaf *, vector<BspLeaf*> > neighborMap; 2685 vector<BspIntersection>::const_iterator iit;2705 ViewCellContainer::const_iterator iit; 2686 2706 2687 2707 int numLeaves = 0; … … 2689 2709 BspLeaf::NewMail(); 2690 2710 2691 for (int i = 0; i < (int) bspRays.size(); ++ i)2711 for (int i = 0; i < (int)rays.size(); ++ i) 2692 2712 { 2693 BspRay *ray = bspRays[i];2713 VssRay *ray = rays[i]; 2694 2714 2695 2715 // traverse leaves stored in the rays and compare and 2696 2716 // merge consecutive leaves (i.e., the neighbors in the tree) 2697 if (ray-> intersections.size() < 2)2717 if (ray->mViewCells.size() < 2) 2698 2718 continue; 2699 2719 2700 iit = ray->intersections.begin(); 2701 BspLeaf *leaf = (*(iit ++)).mLeaf; 2720 iit = ray->mViewCells.begin(); 2721 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(*(iit ++)); 2722 BspLeaf *leaf = bspVc->mLeaves[0]; 2702 2723 2703 2724 // create leaf pvs (needed for post processing) … … 2715 2736 // traverse intersections 2716 2737 // consecutive leaves are neighbors => add them to queue 2717 for (; iit != ray-> intersections.end(); ++ iit)2738 for (; iit != ray->mViewCells.end(); ++ iit) 2718 2739 { 2719 2740 // next pair 2720 2741 BspLeaf *prevLeaf = leaf; 2721 leaf = (*iit).mLeaf; 2742 bspVc = dynamic_cast<BspViewCell *>(*iit); 2743 leaf = bspVc->mLeaves[0]; 2722 2744 2723 2745 // view space not valid or same view cell … … 2781 2803 Debug << "overall cost: " << BspMergeCandidate::sOverallCost << endl; 2782 2804 2783 CLEAR_CONTAINER(bspRays);2784 2785 2805 //-- collect the leaves which haven't been found by ray casting 2786 2806 if (0) … … 2857 2877 mergeStats.Start(); 2858 2878 2859 //BspMergeCandidate::sOverallCost = mBox.SurfaceArea() * m Stat.maxPvs;2879 //BspMergeCandidate::sOverallCost = mBox.SurfaceArea() * mBspStats.maxPvs; 2860 2880 long startTime = GetTime(); 2861 2881 2862 cout << "collecting merge candidates ... " ;2882 cout << "collecting merge candidates ... " << endl; 2863 2883 2864 2884 if (mUseRaysForMerge) … … 2880 2900 2881 2901 // number of view cells withouth the invalid ones 2882 int nViewCells = m Stat.Leaves() - mStat.invalidLeaves;2902 int nViewCells = mBspStats.Leaves() - mBspStats.invalidLeaves; 2883 2903 2884 2904 … … 3370 3390 void VspBspTree::PropagateUpValidity(BspNode *node) 3371 3391 { 3372 while (!node->IsRoot() && node->GetParent()->TreeValid()) 3373 { 3374 node = node->GetParent(); 3375 node->SetTreeValid(false); 3392 const bool isValid = node->TreeValid(); 3393 3394 // propagative up invalid flag until only invalid nodes exist over this node 3395 if (!isValid) 3396 { 3397 while (!node->IsRoot() && node->GetParent()->TreeValid()) 3398 { 3399 node = node->GetParent(); 3400 node->SetTreeValid(false); 3401 } 3402 } 3403 else 3404 { 3405 // propagative up valid flag until one of the subtrees is invalid 3406 while (!node->IsRoot() && !node->TreeValid()) 3407 { 3408 node = node->GetParent(); 3409 BspInterior *interior = dynamic_cast<BspInterior *>(node); 3410 3411 // the parent is valid iff both leaves are valid 3412 node->SetTreeValid(interior->GetBack()->TreeValid() && 3413 interior->GetFront()->TreeValid()); 3414 } 3376 3415 } 3377 3416 }
Note: See TracChangeset
for help on using the changeset viewer.