Ignore:
Timestamp:
12/05/05 20:33:53 (19 years ago)
Author:
mattausch
Message:

started to add view cell merging to vsp kd tree

File:
1 edited

Legend:

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

    r449 r452  
    180180/**************************************************************/ 
    181181VspKdTreeLeaf::VspKdTreeLeaf(VspKdTreeInterior *p,      const int nRays): 
    182 VspKdTreeNode(p), mRays(), mPvsSize(0), mValidPvs(false)  
     182VspKdTreeNode(p), mRays(), mPvsSize(0), mValidPvs(false), mViewCell(NULL) 
    183183{ 
    184184        mRays.reserve(nRays); 
     
    447447VspKdTree::Construct(const VssRayContainer &rays, 
    448448                                         AxisAlignedBox3 *forcedBoundingBox) 
    449 {Debug << "here888" << endl; 
     449{ 
    450450        mStat.Start(); 
    451   Debug << "here1000" << endl; 
     451  
    452452        mMaxMemory = mMaxStaticMemory; 
    453         Debug << "here1" << endl; 
    454453        DEL_PTR(mRoot); 
    455454 
     
    461460        mStat.nodes = 1; 
    462461        mBox.Initialize(); 
    463 Debug << "here2" << endl; 
     462 
    464463        //-- compute bounding box 
    465464        if (forcedBoundingBox) 
     
    468467                for (VssRayContainer::const_iterator ri = rays.begin(); ri != rays.end(); ++ ri) 
    469468                { 
    470                         mBox.Include((*ri)->GetOrigin()); 
    471                         mBox.Include((*ri)->GetTermination());  
     469                        if ((*ri)->mOriginObject) 
     470                mBox.Include((*ri)->GetOrigin()); 
     471                        if ((*ri)->mTerminationObject) 
     472                                mBox.Include((*ri)->GetTermination());  
    472473                } 
    473474 
     
    676677        }        
    677678 
    678         float ratio = 0; 
    679          
    680679        if (0) 
    681680        { 
     
    702701                const float oldCost = (float)pvsSize; 
    703702                 
    704                 float ratio = newCost / oldCost; 
    705         } 
    706          
    707         return ratio; 
     703                return newCost / oldCost; 
     704        } 
    708705} 
    709706 
     
    731728                if (!mOnlyDrivingAxis || axis == sAxis)  
    732729                { 
     730                         
    733731                        nPosition[axis] = (sBox.Min()[axis] + sBox.Max()[axis]) * 0.5f; 
    734732                                                 
     
    740738                                                                                         nPvsBack[axis], 
    741739                                                                                         nPvsFront[axis]); 
     740                        if (bestAxis == -1) 
     741                        { 
     742                                bestAxis = axis; 
     743                        } 
     744                        else if (nCostRatio[axis] < nCostRatio[bestAxis]) 
     745                        { 
     746                                /*Debug << "pvs front " << nPvsBack[axis]  
     747                                          << " pvs back " << nPvsFront[axis] 
     748                                          << " overall pvs " << leaf->GetPvsSize() << endl;*/ 
     749                                bestAxis = axis; 
     750                        } 
    742751                         
    743                         if (bestAxis == -1) 
    744                                 bestAxis = axis; 
    745                         else 
    746                                 if (nCostRatio[axis] < nCostRatio[bestAxis]) 
    747                                 { 
    748                                         Debug << "pvs front " << nPvsBack[axis] 
    749                                                   << " pvs back " << nPvsFront[axis] 
    750                                                   << " overall pvs " << leaf->GetPvsSize() << endl; 
    751                                         bestAxis = axis; 
    752                                 } 
    753752                } 
    754753        } 
     
    17861785        } 
    17871786} 
     1787 
     1788int VspKdTree::FindNeighbors(VspKdTreeLeaf *n, 
     1789                                                         vector<VspKdTreeLeaf *> &neighbors, 
     1790                                                         bool onlyUnmailed) 
     1791{ 
     1792        stack<VspKdTreeNode *> nodeStack; 
     1793   
     1794        nodeStack.push(mRoot); 
     1795 
     1796        AxisAlignedBox3 box = GetBBox(n); 
     1797 
     1798        while (!nodeStack.empty())  
     1799        { 
     1800                VspKdTreeNode *node = nodeStack.top(); 
     1801                nodeStack.pop(); 
     1802 
     1803                if (node->IsLeaf())  
     1804                { 
     1805                        VspKdTreeLeaf *leaf = dynamic_cast<VspKdTreeLeaf *>(node); 
     1806 
     1807                        if (leaf != n && (!onlyUnmailed || !leaf->Mailed()))  
     1808                                neighbors.push_back(leaf); 
     1809                }  
     1810                else  
     1811                { 
     1812                        VspKdTreeInterior *interior = dynamic_cast<VspKdTreeInterior *>(node); 
     1813 
     1814                        if (interior->mPosition > box.Max(interior->mAxis)) 
     1815                                nodeStack.push(interior->mBack); 
     1816                        else 
     1817                        { 
     1818                                if (interior->mPosition < box.Min(interior->mAxis)) 
     1819                                        nodeStack.push(interior->mFront); 
     1820                                else  
     1821                                { 
     1822                                        // random decision 
     1823                                        nodeStack.push(interior->mBack); 
     1824                                        nodeStack.push(interior->mFront); 
     1825                                } 
     1826                        } 
     1827                } 
     1828        } 
     1829 
     1830        return (int)neighbors.size(); 
     1831} 
     1832 
     1833void VspKdTree::MergeLeaves() 
     1834{ 
     1835        vector<VspKdTreeLeaf *> leaves; 
     1836        priority_queue<LeafPair> mergeCandidates; 
     1837        vector<VspKdTreeLeaf *> neighbors; 
     1838 
     1839        CollectLeaves(leaves); 
     1840 
     1841        VspKdTreeLeaf::NewMail(); 
     1842 
     1843        vector<VspKdTreeLeaf *>::const_iterator it, it_end = leaves.end(); 
     1844 
     1845 
     1846        for (it = leaves.begin(); it != it_end; ++ it) 
     1847        { 
     1848                VspKdTreeLeaf *leaf = *it; 
     1849 
     1850                if (!leaf->Mailed()) 
     1851                { 
     1852                        FindNeighbors(leaf, neighbors, true); 
     1853 
     1854                        vector<VspKdTreeLeaf *>::const_iterator nit, nit_end = neighbors.end(); 
     1855 
     1856                        for (nit = neighbors.begin(); nit != neighbors.end(); ++ nit) 
     1857                                mergeCandidates.push(LeafPair(leaf, *nit)); 
     1858                         
     1859                        leaf->Mail(); 
     1860                } 
     1861        } 
     1862} 
     1863 
     1864 
     1865 
     1866/*********************************************************************/ 
     1867/*                MergeCandidate implementation                      */ 
     1868/*********************************************************************/ 
     1869 
     1870 
     1871MergeCandidate::MergeCandidate(VspKdTreeLeaf *l1, VspKdTreeLeaf *l2): 
     1872mLeaf1(l1), mLeaf2(l2) 
     1873{} 
     1874 
     1875int MergeCandidate::ComputePvsDifference() const 
     1876{ 
     1877        return 0; 
     1878} 
     1879 
     1880float MergeCandidate::EvaluateMergeCost() const 
     1881{ 
     1882        return 0; 
     1883} 
Note: See TracChangeset for help on using the changeset viewer.