Changeset 366 for trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
- Timestamp:
- 11/01/05 20:02:22 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r362 r366 260 260 } 261 261 262 BspLeaf::BspLeaf( ViewCell *viewCell):262 BspLeaf::BspLeaf(BspViewCell *viewCell): 263 263 mViewCell(viewCell) 264 264 { … … 269 269 {} 270 270 271 BspLeaf::BspLeaf(BspInterior *parent, ViewCell *viewCell):271 BspLeaf::BspLeaf(BspInterior *parent, BspViewCell *viewCell): 272 272 BspNode(parent), mViewCell(viewCell) 273 273 { 274 274 } 275 275 276 ViewCell *BspLeaf::GetViewCell() 276 BspViewCell *BspLeaf::GetViewCell() const 277 277 { 278 278 return mViewCell; 279 279 } 280 280 281 void BspLeaf::SetViewCell( ViewCell *viewCell)281 void BspLeaf::SetViewCell(BspViewCell *viewCell) 282 282 { 283 283 mViewCell = viewCell; … … 297 297 contributingSamples = 0; 298 298 299 mViewCell = new ViewCell(); 299 mViewCell = dynamic_cast<BspViewCell *>(ViewCell::Generate()); 300 mViewCell->mBspLeaves.push_back(this); 300 301 301 302 BoundedRayContainer::const_iterator it, it_end = rays.end(); … … 320 321 } 321 322 322 ray->bsp Leaves.push_back(this);323 ray->bspIntersections.push_back(BspIntersection(this, (*it)->mMinT); 323 324 324 325 if (storeRays) … … 711 712 { 712 713 // add view cell to leaf 713 leaf->SetViewCell(tData.mViewCell); 714 leaf->SetViewCell(dynamic_cast<BspViewCell *>(tData.mViewCell)); 715 leaf->mViewCell->mBspLeaves.push_back(leaf); 714 716 } 715 717 … … 1244 1246 float sumBalancedRays = 0; 1245 1247 float sumRaySplits = 0; 1248 float pvsSize = 0; 1249 1250 Intersectable::NewMail(); 1246 1251 1247 1252 BoundedRayContainer::const_iterator rit, rit_end = rays.end(); … … 1264 1269 { 1265 1270 sumRaySplits += sLeastRaySplitsTable[classification]; 1271 } 1272 1273 if (sSplitPlaneStrategy & PVS) 1274 { 1275 vector<Ray::Intersection>::const_iterator it, 1276 it_end = ray->intersections.end(); 1277 1278 for (it = ray->intersections.begin(); it != it_end; ++ it) 1279 { 1280 if (!(*it).mObject->Mailed()) 1281 { 1282 (*it).mObject->Mail(); 1283 } 1284 } 1266 1285 } 1267 1286 } … … 1597 1616 } 1598 1617 1618 int BspTree::CountViewCellPvs() const 1619 { 1620 int count = 0; 1621 stack<BspNode *> nodeStack; 1622 nodeStack.push(mRoot); 1623 1624 ViewCell::NewMail(); 1625 1626 // exclude root cell 1627 mRootCell->Mail(); 1628 1629 while (!nodeStack.empty()) 1630 { 1631 BspNode *node = nodeStack.top(); 1632 nodeStack.pop(); 1633 1634 if (node->IsLeaf()) 1635 { 1636 ViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->mViewCell; 1637 1638 if (!viewCell->Mailed()) 1639 { 1640 viewCell->Mail(); 1641 count += viewCell->GetPvs().GetSize(); 1642 } 1643 } 1644 else 1645 { 1646 BspInterior *interior = dynamic_cast<BspInterior *>(node); 1647 1648 nodeStack.push(interior->mFront); 1649 nodeStack.push(interior->mBack); 1650 } 1651 } 1652 return count; 1653 } 1599 1654 1600 1655 bool BspTree::MergeViewCells(BspLeaf *front, BspLeaf *back) const 1601 1656 { 1602 ViewCell *viewCell = ViewCell::Merge(*front->mViewCell, *back->mViewCell); 1657 BspViewCell *viewCell = 1658 dynamic_cast<BspViewCell *>(ViewCell::Merge(*front->mViewCell, *back->mViewCell)); 1603 1659 1604 1660 if (!viewCell) 1605 1661 return false; 1606 1662 1607 DEL_PTR(front->mViewCell); 1608 DEL_PTR(back->mViewCell); 1609 1610 front->SetViewCell(viewCell); 1611 back->SetViewCell(viewCell); 1663 // change view cells of all leaves associated with the 1664 // previous view cells 1665 1666 BspViewCell *fVc = front->mViewCell; 1667 BspViewCell *bVc = back->mViewCell; 1668 1669 vector<BspLeaf *> fLeaves = fVc->mBspLeaves; 1670 vector<BspLeaf *> bLeaves = bVc->mBspLeaves; 1671 1672 vector<BspLeaf *>::const_iterator it; 1673 1674 for (it = fLeaves.begin(); it != fLeaves.end(); ++ it) 1675 { 1676 (*it)->SetViewCell(viewCell); 1677 viewCell->mBspLeaves.push_back(*it); 1678 } 1679 for (it = bLeaves.begin(); it != bLeaves.end(); ++ it) 1680 { 1681 (*it)->SetViewCell(viewCell); 1682 viewCell->mBspLeaves.push_back(*it); 1683 } 1684 1685 DEL_PTR(fVc); 1686 DEL_PTR(bVc); 1612 1687 1613 1688 return true; … … 1616 1691 bool BspTree::ShouldMerge(BspLeaf *front, BspLeaf *back) const 1617 1692 { 1618 if (front->mViewCell->GetPvs().Diff(back->mViewCell->GetPvs()) < 1619 sMinPvsDif) 1620 return true; 1621 1622 if (back->mViewCell->GetPvs().Diff(front->mViewCell->GetPvs()) < 1623 sMinPvsDif) 1693 ViewCell *fvc = front->mViewCell; 1694 ViewCell *bvc = back->mViewCell; 1695 1696 if ((fvc == mRootCell) || (bvc == mRootCell) || (fvc == bvc)) 1697 return false; 1698 1699 /*Debug << "merge (" << sMinPvsDif << ")" << endl; 1700 Debug << "size f: " << fvc->GetPvs().GetSize() << ", " 1701 << "size b: " << bvc->GetPvs().GetSize() << endl; 1702 1703 Debug << "diff f: " << fvc->GetPvs().Diff(bvc->GetPvs()) << ", " 1704 << "diff b: " << bvc->GetPvs().Diff(fvc->GetPvs()) << endl;*/ 1705 1706 if ((fvc->GetPvs().Diff(bvc->GetPvs()) < sMinPvsDif) && 1707 (bvc->GetPvs().Diff(fvc->GetPvs()) < sMinPvsDif)) 1624 1708 return true; 1625 1709 … … 1965 2049 } 1966 2050 2051 void BspTree::ConstructGeometry(BspViewCell *vc, PolygonContainer &cell) const 2052 { 2053 vector<BspLeaf *> leaves = vc->mBspLeaves; 2054 2055 vector<BspLeaf *>::const_iterator it, it_end = leaves.end(); 2056 2057 for (it = leaves.begin(); it != it_end; ++ it) 2058 ConstructGeometry(*it, cell); 2059 } 2060 1967 2061 int BspTree::FindNeighbors(BspNode *n, vector<BspLeaf *> &neighbors, 1968 2062 const bool onlyUnmailed) const … … 2121 2215 return NULL; 2122 2216 } 2217 2218 int BspTree::CountPvs(const BoundedRayContainer &rays) const 2219 { 2220 int pvsSize = 0; 2221 2222 BoundedRayContainer::const_iterator rit, rit_end = rays.end(); 2223 vector<BspLeaf *>::const_iterator lit; 2224 2225 ViewCell::NewMail(); 2226 2227 for (rit = rays.begin(); rit != rit_end; ++ rit) 2228 { 2229 Ray *ray = (*rit)->mRay; 2230 2231 for (lit = ray->bspLeaves.begin(); lit != ray->bspLeaves.end(); ++ lit) 2232 { 2233 if ((*lit)->mViewCell->Mailed()) 2234 { 2235 pvsSize += (*lit)->mViewCell->GetPvs().GetSize(); 2236 } 2237 } 2238 } 2239 2240 return pvsSize; 2241 }
Note: See TracChangeset
for help on using the changeset viewer.