Ignore:
Timestamp:
04/30/08 10:09:52 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r2667 r2669  
    2020   
    2121#define GVS_DEBUG 0 
    22  
     22#define NOT_ACCOUNTED_OBJECT 0 
     23#define ACCOUNTED_OBJECT 2 
     24#define SHOW_QT_VISUALIZATION 0 
     25 
     26static const float MIN_DIST = 0.001f; 
     27 
     28static ObjectContainer myobjects; 
     29 
     30 
     31/** Visualization structure for the GVS algorithm. 
     32*/ 
    2333struct VizStruct 
    2434{ 
     
    2838}; 
    2939 
    30  
    31 static const float MIN_DIST = 0.001f; 
    32  
    33 static ObjectContainer myobjects; 
    3440static vector<VizStruct> vizContainer; 
     41 
     42 
    3543 
    3644 
     
    153161                //newRay->mFlags |= VssRay::ReverseSample; 
    154162                 
    155                 // if ray is not further processed => delete ray 
    156                 if (!HandleRay(newRay)) 
    157                 { 
    158                         //delete newRay; 
    159                 } 
     163                // check if ray is not further processed (ray not deleted because using ray pool) 
     164                HandleRay(newRay); 
    160165                 
    161166                return 1; 
     
    164169        return 0; 
    165170} 
     171 
     172 
     173void GvsPreprocessor::CountObject(Intersectable *triObj) 
     174{ 
     175        if ((triObj->mCounter != (NOT_ACCOUNTED_OBJECT + 1)) && (triObj->mCounter != (ACCOUNTED_OBJECT + 1))) 
     176        { 
     177                ++ triObj->mCounter; 
     178                ++ mGenericStats2; 
     179        } 
     180} 
     181 
     182 
     183void GvsPreprocessor::UpdateStatsForVisualization(KdIntersectable *kdInt) 
     184{ 
     185        mViewCellsManager->UpdateStatsForViewCell(mCurrentViewCell, kdInt); 
     186 
     187        // count new objects in pvs due to kd node conversion    
     188        myobjects.clear(); 
     189        mKdTree->CollectObjects(kdInt->GetItem(), myobjects); 
     190 
     191        ObjectContainer::const_iterator oit, oit_end = myobjects.end(); 
     192 
     193        for (oit = myobjects.begin(); oit != oit_end; ++ oit) 
     194                CountObject(*oit); 
     195}        
    166196 
    167197 
     
    189219                Intersectable *obj = ray.mTerminationObject; 
    190220 
    191                 if (obj->mCounter < 2) 
     221                // counter < 2 => not accounted for yet 
     222                if (obj->mCounter < ACCOUNTED_OBJECT) 
    192223                { 
    193                         obj->mCounter += 2; 
     224                        obj->mCounter += ACCOUNTED_OBJECT; 
    194225                        mTrianglePvs.push_back(obj); 
    195226                 
    196227                        mGenericStats = mTrianglePvs.size(); 
    197228 
    198                         // if using kd pvs, exchange the triangle with the node in the pvs 
     229                        // exchange the triangle with the node in the pvs for kd pvs 
    199230                        if (mUseKdPvs) 
    200231                        { 
     
    203234                                if (!node->Mailed()) 
    204235                                { 
     236                                        // add to pvs 
    205237                                        node->Mail(); 
    206238                                        KdIntersectable *kdInt = mKdTree->GetOrCreateKdIntersectable(node); 
    207239                                        mCurrentViewCell->GetPvs().AddSampleDirty(kdInt, 1.0f); 
    208                                         //mCurrentViewCell->GetPvs().AddSampleDirtyCheck(kdInt, 1.0f); 
    209                                          
    210                                         mViewCellsManager->UpdateStatsForViewCell(mCurrentViewCell, kdInt); 
    211                                         myobjects.clear(); 
    212                                         mKdTree->CollectObjects(node, myobjects); 
    213  
    214                                         // account for kd object pvs 
    215                                         ObjectContainer::const_iterator oit, oit_end = myobjects.end(); 
    216  
    217                                         for (oit = myobjects.begin(); oit != oit_end; ++ oit) 
    218                                         { 
    219                                                 TriangleIntersectable *triObj = static_cast<TriangleIntersectable *>(*oit); 
    220  
    221                                                 if ((triObj->mCounter != 1) && (triObj->mCounter != 3)) 
    222                                                 { 
    223                                                         ++ triObj->mCounter; 
    224                                                         ++ mGenericStats2; 
    225                                                 } 
    226                                         } 
    227                                 }                        
     240                                 
     241                                        if (SHOW_QT_VISUALIZATION) UpdateStatsForVisualization(kdInt);   
     242                                } 
    228243                        } 
    229244 
     
    902917        ObjectContainer kdobjects; 
    903918        mKdTree->CollectKdObjects(box, kdobjects); 
    904         //vector<KdLeaf *>::const_iterator lit, lit_end = leaves.end(); 
    905         //for (lit = leaves.begin(); lit != lit_end; ++ lit) 
     919 
    906920        ObjectContainer::const_iterator oit, oit_end = kdobjects.end(); 
     921 
    907922        for (oit = kdobjects.begin(); oit != oit_end; ++ oit) 
    908923        { 
     
    912927                //mCurrentViewCell->GetPvs().AddSampleDirty(kdInt, 1.0f); 
    913928                mCurrentViewCell->GetPvs().AddSampleDirtyCheck(kdInt, 1.0f); 
     929 
    914930                mViewCellsManager->UpdateStatsForViewCell(mCurrentViewCell, kdInt); 
    915931 
     
    924940                        TriangleIntersectable *triObj = static_cast<TriangleIntersectable *>(*oit); 
    925941             
    926                         // account for the overall pvs 
    927                         if ((triObj->mCounter != 1) && (triObj->mCounter != 3)) 
    928                         { 
    929                                 ++ triObj->mCounter; 
    930                                 ++ mGenericStats2; 
    931                         } 
     942                        CountObject(triObj); 
    932943             
    933944                        // the triangle itself intersects 
    934945                        if (box.Intersects(triObj->GetItem())) 
    935946                        { 
    936                                 if ((triObj->mCounter < 2)) 
     947                                if ((triObj->mCounter < ACCOUNTED_OBJECT)) 
    937948                                { 
    938                                         triObj->mCounter += 2; 
     949                                        triObj->mCounter += ACCOUNTED_OBJECT; 
    939950 
    940951                                        mTrianglePvs.push_back(triObj); 
     
    957968 
    958969                for (oit = mObjects.begin(); oit != oit_end; ++ oit) 
    959                         (*oit)->mCounter = 0; 
     970                        (*oit)->mCounter = NOT_ACCOUNTED_OBJECT; 
    960971 
    961972        ComputeViewCell(vc); 
     
    986997 
    987998                for (oit = mObjects.begin(); oit != oit_end; ++ oit) 
    988                         (*oit)->mCounter = 0; 
     999                        (*oit)->mCounter = NOT_ACCOUNTED_OBJECT; 
    9891000 
    9901001                ComputeViewCell(vc); 
     
    10491060 
    10501061                // hack: reset counter 
    1051                 (*oit)->mCounter = 0; 
     1062                (*oit)->mCounter = NOT_ACCOUNTED_OBJECT; 
    10521063 
    10531064                if (!bv || bv->Mailed()) 
     
    12521263        ProcessViewCell(); 
    12531264 
    1254         //mGvsStats.mTrianglePvs = mCurrentViewCell->GetPvs().GetSize(); 
    12551265        mGvsStats.mTrianglePvs = (int)mTrianglePvs.size(); 
    12561266        mGvsStats.mTotalTrianglePvs += mGvsStats.mTrianglePvs; 
Note: See TracChangeset for help on using the changeset viewer.