Ignore:
Timestamp:
01/04/06 10:02:28 (19 years ago)
Author:
mattausch
Message:

fixed bug in tree collapse

File:
1 edited

Legend:

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

    r492 r495  
    3535float BspMergeCandidate::sOverallCost = 0; 
    3636 
    37  
    38 /// Adds object to the pvs of the front and back node 
    39 inline void AddObject2Pvs(Intersectable *object, 
    40                                                   const int side, 
    41                                                   int &pvsBack, 
    42                                                   int &pvsFront) 
    43 { 
    44         if (!object) 
    45                 return; 
    46  
    47         if (side <= 0) 
    48         { 
    49                 if (!object->Mailed() && !object->Mailed(2)) 
    50                 { 
    51                         ++ pvsBack; 
    52  
    53                         if (object->Mailed(1)) 
    54                                 object->Mail(2); 
    55                         else 
    56                                 object->Mail(); 
    57                 } 
    58         } 
    59  
    60         if (side >= 0) 
    61         { 
    62                 if (!object->Mailed(1) && !object->Mailed(2)) 
    63                 { 
    64                         ++ pvsFront; 
    65  
    66                         if (object->Mailed()) 
    67                                 object->Mail(2); 
    68                         else 
    69                                 object->Mail(1); 
    70                 } 
    71         } 
    72 } 
    73  
    74  
    7537/****************************************************************/ 
    7638/*                  class VspBspTree implementation             */ 
     
    8345mViewCellsManager(NULL), 
    8446mStoreRays(false), 
    85 mOnlyDrivingAxis(false), 
    8647mOutOfBoundsCell(NULL) 
    8748{ 
     
    794755float VspBspTree::SelectAxisAlignedPlane(Plane3 &plane, 
    795756                                                                                 const VspBspTraversalData &tData, 
    796                                                                                  int &bestAxis) 
     757                                                                                 int &axis, 
     758                                                                                 float &position, 
     759                                                                                 int &raysBack, 
     760                                                                                 int &raysFront, 
     761                                                                                 int &pvsBack, 
     762                                                                                 int &pvsFront) 
    797763{ 
    798764        AxisAlignedBox3 box; 
     
    810776        float nPosition[3]; 
    811777        float nCostRatio[3]; 
    812         bestAxis = -1; 
     778        int bestAxis = -1; 
    813779 
    814780        const int sAxis = box.Size().DrivingAxis(); 
    815781 
    816         for (int axis = 0; axis < 3; ++ axis) 
     782        for (axis = 0; axis < 3; ++ axis) 
    817783        { 
    818784                if (!mOnlyDrivingAxis || axis == sAxis) 
     
    851817        } 
    852818 
    853         //-- assign best axis 
     819        //-- assign values 
     820        axis = bestAxis; 
     821        position = nPosition[bestAxis]; 
     822 
     823        raysBack = 0;//nRaysBack[bestAxis]; 
     824        raysFront = 0;//nRaysFront[bestAxis]; 
     825 
     826        pvsBack = 0;//nPvsBack[bestAxis]; 
     827        pvsFront = 0;//nPvsFront[bestAxis]; 
     828 
    854829        Vector3 normal(0,0,0); normal[bestAxis] = 1; 
    855830        plane = Plane3(normal, nPosition[bestAxis]); 
     
    10701045} 
    10711046 
     1047 
    10721048bool VspBspTree::SelectPlaneHeuristics(Plane3 &bestPlane, 
    10731049                                                                           BspLeaf *leaf, 
     
    10861062        for (int i = 0; i < limit; ++ i) 
    10871063        { 
    1088                 // assure that no index is taken twice 
     1064                //-- assure that no index is taken twice 
    10891065                const int candidateIdx = (int)RandomValue(0, (Real)(-- maxIdx)); 
    1090                 //Debug << "current Idx: " << maxIdx << " cand idx " << candidateIdx << endl; 
    1091  
    10921066                Polygon3 *poly = (*data.mPolygons)[candidateIdx]; 
    10931067 
     
    11091083        //-- axis aligned splits 
    11101084        int axis; 
    1111         candidateCost = SelectAxisAlignedPlane(plane, data, axis); 
     1085        float position; 
     1086        int raysBack; 
     1087        int raysFront; 
     1088        int pvsFront; 
     1089        int pvsBack; 
     1090 
     1091        candidateCost = SelectAxisAlignedPlane(plane,  
     1092                                                                                   data,  
     1093                                                                                   axis, 
     1094                                                                                   position, 
     1095                                                                                   raysBack, 
     1096                                                                                   raysFront, 
     1097                                                                                   pvsFront, 
     1098                                                                                   pvsBack); 
    11121099 
    11131100        if (candidateCost < lowestCost) 
     
    11161103                { 
    11171104                        useAxisAlignedPlane = true; 
     1105                        //if (data.mPolygons->size() > 0) 
     1106                        //      Debug << "haha" << endl; 
    11181107                        //! error also computed if cost ratio is missed 
    11191108                        ++ mStat.splits[axis]; 
     
    11421131        Intersectable::NewMail(); sFrontAndBackId = ViewCell::sMailId; 
    11431132} 
     1133 
    11441134 
    11451135float VspBspTree::SplitPlaneCost(const Plane3 &candidatePlane, 
     
    11591149        float pBack = 0; 
    11601150 
    1161         const bool pvsUseLen = false; 
    1162  
    11631151        if (mSplitPlaneStrategy & PVS) 
    11641152        { 
    1165 // matt: change back!! 
    1166 Intersectable::NewMail(3); 
    11671153                // create unique ids for pvs heuristics 
    1168                 //GenerateUniqueIdsForPvs(); 
     1154                GenerateUniqueIdsForPvs(); 
    11691155 
    11701156                if (mPvsUseArea) // use front and back cell areas to approximate volume 
     
    12271213                        // assure that we only count the object 
    12281214                        // once for the front and once for the back side of the plane 
    1229  
    1230                         // add the termination object 
    1231                         //AddObjToPvs(ray->mTerminationObject, cf, frontPvs, backPvs); 
    1232                         AddObject2Pvs(ray->mTerminationObject, cf, frontPvs, backPvs); 
    1233                         // add the source object 
    1234                         //AddObjToPvs(ray->mOriginObject, cf, frontPvs, backPvs); 
     1215                        AddObjToPvs(ray->mTerminationObject, cf, frontPvs, backPvs); 
     1216                        AddObjToPvs(ray->mOriginObject, cf, frontPvs, backPvs); 
    12351217 
    12361218                        // use number of rays to approximate volume 
    12371219                        if (!mPvsUseArea) 
    12381220                        { 
    1239                                 ++ pOverall; 
     1221                                pOverall = (float)data.mRays->size(); 
    12401222 
    12411223                                if (cf >= 0) 
     
    12531235 
    12541236        if (mSplitPlaneStrategy & BALANCED_RAYS) 
    1255                 cost += mBalancedRaysFactor * fabs(sumBalancedRays) /  raysSize; 
     1237                cost += mBalancedRaysFactor * fabs(sumBalancedRays) / raysSize; 
    12561238 
    12571239        // pvs criterium 
     
    21252107BspNode *VspBspTree::CollapseTree(BspNode *node) 
    21262108{ 
    2127     if (node->IsLeaf()) 
     2109        if (node->IsLeaf()) 
    21282110                return node; 
    21292111 
     
    21562138        } 
    21572139 
     2140        return node; 
     2141} 
     2142 
     2143 
     2144void VspBspTree::CollapseTree() 
     2145{ 
     2146        CollapseTree(mRoot); 
    21582147        // revalidate leaves 
    21592148        RepairVcLeafLists(); 
    2160  
    2161         return node; 
    21622149} 
    21632150 
Note: See TracChangeset for help on using the changeset viewer.