Ignore:
Timestamp:
04/20/06 13:25:41 (18 years ago)
Author:
mattausch
Message:

after rendering workshop submissioin
x3dparser can use def - use constructs
implemented improved evaluation (samples are only stored in leaves, only propagate pvs size)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r746 r752  
    1818{ 
    1919public: 
    20         //bool operator() (HierarchyNode *v1, HierarchyNode *v2) const 
    2120        bool operator() (T v1, T v2) const 
    2221        { 
     
    3938 
    4039// pvs penalty can be different from pvs size 
    41 inline float EvalPvsPenalty(const int pvs, const int lower, const int upper) 
     40inline static float EvalPvsPenalty(const int pvs, const int lower, const int upper) 
    4241{ 
    4342        // clamp to minmax values 
    44 #if HAS_TO_BE_REDONE 
    4543        if (pvs < lower) 
    4644                return (float)lower; 
    4745        if (pvs > upper) 
    4846                return (float)upper; 
    49 #endif 
     47 
    5048        return (float)pvs; 
    5149} 
     
    7068 
    7169/// Fast computation of merged pvs size 
    72 int ComputeMergedPvsSize(const ObjectPvs &pvs1, const ObjectPvs &pvs2) 
     70static int ComputeMergedPvsSize(const ObjectPvs &pvs1, const ObjectPvs &pvs2) 
    7371{ 
    7472        // add first pvs 
     
    9997 
    10098// computet render cost of merge 
    101 float ViewCellsTree::ComputeMergedPvsCost(const ObjectPvs &pvs1, const ObjectPvs &pvs2) const 
     99float ViewCellsTree::ComputeMergedPvsCost(const ObjectPvs &pvs1,  
     100                                                                                  const ObjectPvs &pvs2) const 
    102101{ 
    103102        float renderCost = 0; 
     
    143142mParent(NULL), 
    144143mMergeCost(0), 
    145 mIsActive(false) 
     144mIsActive(false), 
     145mPvsSize(0), 
     146mPvsSizeValid(false) 
    146147{ 
    147148} 
     
    156157mMergeCost(0), 
    157158mIsActive(false), 
    158 mLastUpdated(sLastUpdated) 
     159mLastUpdated(sLastUpdated), 
     160mPvsSize(0), 
     161mPvsSizeValid(false) 
    159162{ 
    160163} 
     
    165168        return mPvs; 
    166169} 
     170 
    167171 
    168172ObjectPvs &ViewCell::GetPvs() 
     
    205209{ 
    206210        mArea = area; 
     211} 
     212 
     213 
     214void ViewCell::SetColor(const RgbColor &color)  
     215{ 
     216        mColor = color; 
     217} 
     218 
     219 
     220RgbColor ViewCell::GetColor() const  
     221{ 
     222        return mColor; 
    207223} 
    208224 
     
    367383mUseAreaForPvs(false), 
    368384mViewCellsManager(vcm), 
    369 mIsCompressed(false) 
     385#if 0 
     386mViewCellsStorage(PVS_IN_INTERIORS) 
     387#else 
     388mViewCellsStorage(PVS_IN_LEAVES) 
     389#endif 
    370390{ 
    371391        environment->GetBoolValue("ViewCells.Visualization.exportMergedViewCells", mExportMergedViewCells); 
     
    393413float ViewCellsTree::GetMemUsage() const 
    394414{ 
     415        // TODO 
    395416        return 0; 
    396417                /*(sizeof(ViewCellsTree) + 
     
    513534        // we start with the current view cells from the view cell manager.  
    514535        // The active view cells will change with subsequent merges 
    515         Debug << "here2" << endl; Debug.flush(); 
     536         
    516537        // todo: should rather take initial view cells 
    517538    ViewCellContainer &activeViewCells = mViewCellsManager->GetViewCells(); 
    518         //ViewCellContainer activeViewCells; 
    519          
    520         Debug << "here2.6" << endl; Debug.flush(); 
     539         
     540         
    521541        ViewCell::NewMail(); 
    522542 
     
    704724                Debug << "setting root of the merge history" << endl; 
    705725                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; 
    707731        } 
    708732         
     
    803827                        swap(viewCells[i], viewCells.back()); 
    804828                 
    805                 // mail view cell as it has not been merged 
     829                // mail view cell that it has not been merged 
    806830                viewCells[i]->Mail(); 
    807831 
     
    814838        // merged in the mean time 
    815839        ViewCellContainer::const_iterator ait, ait_end = mMergedViewCells.end(); 
     840 
    816841        for (ait = mMergedViewCells.begin(); ait != ait_end; ++ ait) 
    817842        { 
     
    825850        } 
    826851 
     852        // dispose old merged view cells 
    827853        mMergedViewCells.clear(); 
    828854 
     
    836862                const int lower = mViewCellsManager->GetMinPvsSize(); 
    837863                const int upper = mViewCellsManager->GetMaxPvsSize(); 
     864 
    838865                const float penalty = EvalPvsPenalty((*vit)->GetPvs().GetSize(), lower, upper); 
    839866                 
     
    905932        if (!vc) return NULL; 
    906933 
     934        // set to the new parent view cell 
    907935        l->SetParent(vc); 
    908936        r->SetParent(vc); 
     
    932960        pvsDiff = vc->GetPvs().GetSize() - pvs1 - pvs2; 
    933961 
     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 
    934982        return vc; 
    935983} 
    936  
    937984 
    938985 
     
    11891236        if (1) 
    11901237        { 
    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; 
    11931242        } 
    11941243 
     
    12331282bool ViewCellsTree::ValidateMergeCandidate(MergeCandidate &mc) const 
    12341283{ 
     1284        // propagate up so we have only the active view cells 
    12351285        while (mc.mLeftViewCell->mParent) 
    12361286        { 
     
    12431293        } 
    12441294 
     1295        // this view cell was already merged 
     1296        //return mc.mLeftViewCell && (mc.mLeftViewCell != mc.mRightViewCell); 
    12451297        return mc.mLeftViewCell != mc.mRightViewCell; 
    12461298} 
     
    12501302{ 
    12511303        //-- 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()); 
    12601309 
    12611310        const float newPenalty = EvalPvsPenalty(newPvs, 
     
    13051354} 
    13061355 
    1307 void ViewCellsTree::CompressViewCellsPvs() 
    1308 { 
    1309         if (!mIsCompressed) 
    1310         { 
    1311                 mIsCompressed = true; 
     1356 
     1357void ViewCellsTree::SetViewCellsStorage(int stype) 
     1358{ 
     1359        if (mViewCellsStorage == stype) 
     1360                return; 
     1361 
     1362        // TODO 
     1363        switch (stype) 
     1364        { 
     1365        case COMPRESSED: 
    13121366                CompressViewCellsPvs(mRoot); 
    1313         } 
    1314 } 
     1367                break; 
     1368        default: 
     1369                break; 
     1370        } 
     1371 
     1372        mViewCellsStorage = stype; 
     1373} 
     1374 
    13151375 
    13161376void ViewCellsTree::CompressViewCellsPvs(ViewCell *root) 
     
    13441404        const float vol = box.GetVolume(); 
    13451405 
     1406        const int rootPvs = GetPvsSize(mRoot); 
     1407 
    13461408        Debug << "vsb volume: " << vol << endl; 
    13471409        Debug << "root volume: " << mRoot->GetVolume() << endl; 
    1348         Debug << "root pvs: " << mRoot->GetPvs().GetSize() << endl; 
     1410        Debug << "root pvs: " << rootPvs << endl; 
    13491411 
    13501412        int totalPvs; 
     
    13521414 
    13531415        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; 
    13561418 
    13571419        ofstream stats; 
    13581420        stats.open(mergeStats.c_str()); 
    13591421 
     1422        //-- first view cell 
    13601423        stats  
    13611424                << "#Pass\n" << 0 << endl 
     
    13641427        << "#RenderCostDecrease\n" << 0 << endl // TODO 
    13651428                << "#TotalRenderCost\n" << totalRenderCost << endl 
    1366                 << "#CurrentPvs\n" << mRoot->GetPvs().GetSize() << endl 
     1429                << "#CurrentPvs\n" << rootPvs << endl 
    13671430                << "#ExpectedCost\n" << expectedCost << endl 
    13681431                << "#AvgRenderCost\n" << avgRenderCost << endl 
     
    13831446                        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
    13841447                         
    1385                         const int parentPvs = interior->GetPvs().GetSize(); 
     1448                        const int parentPvs = GetPvsSize(interior); 
    13861449                        const float parentCost = (float)parentPvs * interior->GetVolume(); 
    13871450                        float childCost = 0; 
     
    13941457                        for (it = interior->mChildren.begin(); it != it_end; ++ it) 
    13951458                        { 
    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; 
    13981462 
    13991463                                tqueue.push(*it); 
     
    14161480                                << "#RenderCostDecrease\n" << costDecr << endl // TODO 
    14171481                                << "#TotalRenderCost\n" << totalRenderCost << endl 
    1418                                 << "#CurrentPvs\n" << vc->GetPvs().GetSize() << endl 
     1482                                << "#CurrentPvs\n" << parentPvs << endl 
    14191483                                << "#ExpectedCost\n" << expectedCost << endl 
    14201484                                << "#AvgRenderCost\n" << avgRenderCost << endl 
     
    14321496 
    14331497 
    1434 #if 0 
    1435 float ViewCellsTree::ComputeVolume(ViewCell *vc) 
    1436 { 
    1437         if (vc->IsLeaf()) 
    1438         { 
    1439                 return vc->GetVolume(); 
    1440         } 
    1441         else 
    1442         { 
    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 #endif 
    1459  
    14601498void ViewCellsTree::SetRoot(ViewCell *root) 
    14611499{ 
     
    15581596        } 
    15591597 
    1560         int dummy = interior->GetPvs().GetSize(); 
     1598        /*int dummy = interior->GetPvs().GetSize(); 
    15611599 
    15621600        for (cit = interior->mChildren.begin(); cit != cit_end; ++ cit) 
    15631601        { 
    15641602                dummy += (*cit)->GetPvs().GetSize(); 
    1565         } 
    1566  
    1567 } 
    1568  
    1569  
     1603        }*/ 
     1604 
     1605} 
     1606 
     1607// TODO 
    15701608void ViewCellsTree::GetPvs(ViewCell *vc, ObjectPvs &pvs) const 
    15711609{ 
    15721610        Intersectable::NewMail(); 
    15731611 
    1574         if (!mIsCompressed) 
     1612        if (mViewCellsStorage == PVS_IN_INTERIORS) 
    15751613                pvs = vc->GetPvs(); 
    15761614 
     
    16121650int ViewCellsTree::GetPvsSize(ViewCell *vc) const 
    16131651{ 
     1652        int pvsSize = 0; 
     1653 
     1654        if (vc->IsLeaf()) 
     1655        { 
     1656                pvsSize = vc->GetPvs().GetSize(); 
     1657        } 
     1658         
     1659 
    16141660        Intersectable::NewMail(); 
    16151661 
    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                        //////////////////////// 
    16211704        //-- compressed pvs 
    16221705 
     1706                        if (vc->mPvsSizeValid) 
     1707                                return vc->mPvsSize; 
     1708 
     1709                        // if no pvs size stored: compute 
    16231710        int pvsSize = 0; 
    16241711        ViewCell *root = vc; 
     
    16531740                } 
    16541741        } 
     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        } 
    16551748 
    16561749        return pvsSize;   
    1657  
    16581750} 
    16591751 
     
    16721764        int pvsSize = 0; 
    16731765        // only count leaves for uncompressed method for fairness 
    1674         if (mIsCompressed || vc->IsLeaf()) 
     1766        if ((mViewCellsStorage == PVS_IN_INTERIORS) || vc->IsLeaf()) 
     1767        { 
    16751768                pvsSize = vc->GetPvs().GetSize(); 
     1769        } 
    16761770 
    16771771        if (!vc->IsLeaf()) 
     
    16911785 
    16921786 
    1693 bool ViewCellsTree::IsCompressed() const 
    1694 { 
    1695         return mIsCompressed; 
     1787int ViewCellsTree::ViewCellsStorage() const 
     1788{ 
     1789        return mViewCellsStorage; 
    16961790} 
    16971791 
     
    18451939        if (!vc->GetValid()) 
    18461940                ++ vcStat.invalid; 
    1847  
    1848         /*ViewCellsContainer leaves; 
    1849         CollectLeaves(vc, leaves); 
    1850  
    1851         vcStat.leaves = (int)leaves.size();*/ 
    18521941} 
    18531942 
     
    19692058void ViewCellsTree::SetActiveSetToLeaves() 
    19702059{ 
     2060        // todo 
    19712061} 
    19722062 
     
    20262116bool MergeCandidate::IsValid() const 
    20272117{ 
     2118        // if one has a parent, it was already merged 
    20282119        return !(mLeftViewCell->mParent || mRightViewCell->mParent); 
    20292120} 
Note: See TracChangeset for help on using the changeset viewer.