Ignore:
Timestamp:
11/01/05 20:02:22 (19 years ago)
Author:
mattausch
Message:

some ideas abou saving bspleaves with the ray and t

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r362 r366  
    260260} 
    261261 
    262 BspLeaf::BspLeaf(ViewCell *viewCell):  
     262BspLeaf::BspLeaf(BspViewCell *viewCell):  
    263263mViewCell(viewCell) 
    264264{ 
     
    269269{} 
    270270 
    271 BspLeaf::BspLeaf(BspInterior *parent, ViewCell *viewCell):  
     271BspLeaf::BspLeaf(BspInterior *parent, BspViewCell *viewCell):  
    272272BspNode(parent), mViewCell(viewCell) 
    273273{ 
    274274} 
    275275 
    276 ViewCell *BspLeaf::GetViewCell() 
     276BspViewCell *BspLeaf::GetViewCell() const 
    277277{ 
    278278        return mViewCell; 
    279279} 
    280280 
    281 void BspLeaf::SetViewCell(ViewCell *viewCell) 
     281void BspLeaf::SetViewCell(BspViewCell *viewCell) 
    282282{ 
    283283        mViewCell = viewCell; 
     
    297297        contributingSamples = 0; 
    298298 
    299         mViewCell = new ViewCell(); 
     299        mViewCell = dynamic_cast<BspViewCell *>(ViewCell::Generate()); 
     300        mViewCell->mBspLeaves.push_back(this); 
    300301 
    301302    BoundedRayContainer::const_iterator it, it_end = rays.end(); 
     
    320321                } 
    321322 
    322                 ray->bspLeaves.push_back(this); 
     323                ray->bspIntersections.push_back(BspIntersection(this, (*it)->mMinT); 
    323324 
    324325                if (storeRays) 
     
    711712                { 
    712713                        // 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); 
    714716                } 
    715717 
     
    12441246        float sumBalancedRays = 0; 
    12451247        float sumRaySplits = 0; 
     1248        float pvsSize = 0; 
     1249 
     1250        Intersectable::NewMail(); 
    12461251 
    12471252        BoundedRayContainer::const_iterator rit, rit_end = rays.end(); 
     
    12641269                { 
    12651270                        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                        } 
    12661285                } 
    12671286        } 
     
    15971616} 
    15981617 
     1618int 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} 
    15991654 
    16001655bool BspTree::MergeViewCells(BspLeaf *front, BspLeaf *back) const 
    16011656{ 
    1602         ViewCell *viewCell = ViewCell::Merge(*front->mViewCell, *back->mViewCell); 
     1657        BspViewCell *viewCell =  
     1658                dynamic_cast<BspViewCell *>(ViewCell::Merge(*front->mViewCell, *back->mViewCell)); 
    16031659         
    16041660        if (!viewCell) 
    16051661                return false; 
    16061662 
    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); 
    16121687 
    16131688        return true; 
     
    16161691bool BspTree::ShouldMerge(BspLeaf *front, BspLeaf *back) const 
    16171692{ 
    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)) 
    16241708                return true; 
    16251709 
     
    19652049} 
    19662050 
     2051void 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 
    19672061int BspTree::FindNeighbors(BspNode *n, vector<BspLeaf *> &neighbors,  
    19682062                                                   const bool onlyUnmailed) const 
     
    21212215        return NULL; 
    21222216} 
     2217 
     2218int 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.