Ignore:
Timestamp:
11/06/05 01:24:55 (19 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r380 r383  
    10841084        if (sSplitPlaneStrategy & RANDOM_POLYGON) 
    10851085        { 
    1086                 Vector3 pt[3]; 
    1087                 for (int j = 0; j < 3; j ++) 
    1088                 { 
    1089                         int idx = Random((int)rays.size()); 
    1090                         pt[j] = rays[idx]->mRay->Extrap(rays[idx]->mMaxT); 
    1091                 } 
    1092  
    1093                 return Plane3(pt[0], pt[1], pt[2]); 
    1094  
    1095         //return polys[Random((int)polys.size())]->GetSupportingPlane(); 
     1086                return polys[Random((int)polys.size())]->GetSupportingPlane(); 
    10961087        } 
    10971088 
    10981089        // use heuristics to find appropriate plane 
    1099         return SelectPlaneHeuristics(polys, rays, sMaxPolyCandidates, sMaxRayCandidates); 
    1100 } 
    1101  
    1102 Plane3 BspTree::SelectPlaneHeuristics(PolygonContainer &polys, 
     1090        return SelectPlaneHeuristics(leaf,  
     1091                                         polys,  
     1092                                                                 rays,  
     1093                                                                 sMaxPolyCandidates,  
     1094                                                                 sMaxRayCandidates); 
     1095} 
     1096 
     1097Plane3 BspTree::SelectPlaneHeuristics(BspLeaf *leaf, 
     1098                                                                          PolygonContainer &polys, 
    11031099                                                                          const BoundedRayContainer &rays, 
    11041100                                                                          const int maxPolyCandidates, 
     
    11081104        int bestPlaneIdx = 0; 
    11091105         
    1110         int limit = maxPolyCandidates > 0 ? Min((int)polys.size(), maxPolyCandidates) : (int)polys.size(); 
     1106        int limit = maxPolyCandidates > 0 ?  
     1107                Min((int)polys.size(), maxPolyCandidates) : (int)polys.size(); 
    11111108         
    11121109        int candidateIdx = limit; 
    11131110 
    1114         //Debug << endl; 
    1115         /*for (int i = 0; i < limit; ++ i) 
     1111        for (int i = 0; i < limit; ++ i) 
    11161112        { 
    11171113                candidateIdx = GetNextCandidateIdx(candidateIdx, polys); 
    1118  
    1119                 Plane3 candidatePlane = polys[candidateIdx]->GetSupportingPlane(); 
     1114                 
     1115                // evaluate current candidate 
     1116                const float candidateCost =  
     1117                        SplitPlaneCost(leaf, 
     1118                                       polys[candidateIdx]->GetSupportingPlane(),  
     1119                                                   polys, rays); 
     1120 
    11201121                //Debug << polys[candidateIdx] << endl; 
    1121                 // evaluate current candidate 
    1122                 float candidateCost = SplitPlaneCost(candidatePlane, polys, rays); 
    1123                          
    11241122                if (candidateCost < lowestCost) 
    11251123                { 
     
    11271125                        lowestCost = candidateCost; 
    11281126                } 
    1129         }*/ 
     1127        } 
    11301128         
    11311129        //limit = maxRaysCandidates > 0 ? Min((int)rays.size(), maxRayCandidates) : (int)rays.size(); 
     
    11401138                for (int j = 0; j < 3; j ++) 
    11411139                { 
    1142                         idx[j] = Random((int)rays.size()); 
    1143                         pt[j] = rays[idx[j]]->mRay->Extrap(rays[idx[j]]->mMaxT); 
    1144                 } 
    1145  
    1146                 float candidateCost = SplitPlaneCost(Plane3(pt[0], pt[1], pt[2]), polys, rays); 
     1140                        idx[j] = Random((int)rays.size() * 2); 
     1141                                 
     1142                        if (idx[j] < (int)rays.size()) 
     1143                                pt[j] = rays[idx[j]]->mRay->Extrap(rays[idx[j]]->mMinT); 
     1144                        else 
     1145                        { 
     1146                                idx[j] -= (int)rays.size(); 
     1147                                pt[j] = rays[idx[j]]->mRay->Extrap(rays[idx[j]]->mMaxT); 
     1148                        } 
     1149                                         
     1150                } 
     1151 
     1152                const float candidateCost = 
     1153                        SplitPlaneCost(leaf, Plane3(pt[0], pt[1], pt[2]),  
     1154                                                   polys, rays); 
    11471155 
    11481156                if (candidateCost < lowestCost) 
     
    11571165        if (chooseFromRays) 
    11581166        { 
     1167                Debug << "choose ray plane: " << lowestCost << endl; 
    11591168                return Plane3(rays[bestIdx[0]]->mRay->Extrap(rays[bestIdx[0]]->mMaxT), 
    11601169                                          rays[bestIdx[1]]->mRay->Extrap(rays[bestIdx[1]]->mMaxT), 
     
    11771186} 
    11781187 
    1179 float BspTree::SplitPlaneCost(const Plane3 &candidatePlane,  
     1188float BspTree::SplitPlaneCost(BspLeaf *leaf,  
     1189                                                          const Plane3 &candidatePlane,  
    11801190                                                          const PolygonContainer &polys) const 
    11811191{ 
     
    13161326} 
    13171327 
    1318 float BspTree::SplitPlaneCost(const Plane3 &candidatePlane,  
     1328float BspTree::SplitPlaneCost(BspLeaf *leaf, 
     1329                                                          const Plane3 &candidatePlane,  
    13191330                                                          const BoundedRayContainer &rays) const 
    13201331{ 
     
    13331344        Intersectable::NewMail(); const int frontAndBackId = ViewCell::sMailId; 
    13341345 
    1335         /*PolygonContainer cell; 
     1346        PolygonContainer cell; 
    13361347        PolygonContainer front; 
    13371348        PolygonContainer back; 
    13381349 
    1339         ConstructGeometry(currentNode, cell); 
    1340         ConstructChildrenGeometry(front, cell, planes, sides); 
    1341         ConstructChildrenGeometry(back, cell, planes, sides);*/ 
    1342  
    1343  
     1350        vector<Plane3 *> planes; 
     1351        vector<bool> sides; 
     1352 
     1353        ExtractSplitPlanes(leaf, planes, sides); 
     1354 
     1355        ConstructGeometry(leaf, cell); 
     1356        ConstructChildGeometry(front, cell, planes, sides, candidatePlane, true); 
     1357        ConstructChildGeometry(back, cell, planes, sides, candidatePlane, false); 
     1358 
     1359        CLEAR_CONTAINER(cell); 
     1360        CLEAR_CONTAINER(front); 
     1361        CLEAR_CONTAINER(back); 
     1362         
    13441363        int frontRays = 0; 
    13451364        int backRays = 0; 
     
    14751494} 
    14761495 
    1477 float BspTree::SplitPlaneCost(const Plane3 &candidatePlane,  
     1496float BspTree::SplitPlaneCost(BspLeaf *leaf, 
     1497                                                          const Plane3 &candidatePlane,  
    14781498                                                          const PolygonContainer &polys,                                                           
    14791499                                                          const BoundedRayContainer &rays) const 
     
    14971517                (sSplitPlaneStrategy & BLOCKED_RAYS)) 
    14981518        { 
    1499         val += SplitPlaneCost(candidatePlane, polys); 
     1519        val += SplitPlaneCost(leaf, candidatePlane, polys); 
    15001520        } 
    15011521 
     
    15051525                (sSplitPlaneStrategy & PVS)) 
    15061526        { 
    1507                 val += SplitPlaneCost(candidatePlane, rays); 
     1527                val += SplitPlaneCost(leaf, candidatePlane, rays); 
    15081528        } 
    15091529 
     
    20192039} 
    20202040 
    2021 bool BspTree::ComputeChildrenGeometry(PolygonContainer &newCell, 
    2022                                                                           const PolygonContainer &cell, 
    2023                                                                           const vector<Plane3> &planes, 
    2024                                                                           const vector<bool> &sides, 
    2025                                                                           const Plane3 &splitPlane, 
    2026                                                                           const bool side) const 
     2041bool BspTree::ConstructChildGeometry(PolygonContainer &newCell, 
     2042                                                                         const PolygonContainer &cell, 
     2043                                                                         const vector<Plane3 *> &planes, 
     2044                                                                         const vector<bool> &sides, 
     2045                                                                         const Plane3 &splitPlane, 
     2046                                                                         const bool side) const 
    20272047{ 
    20282048        // get cross section of new polygon 
     
    20342054        for (int i = 0; (i < planes.size()) && inside; ++ i) 
    20352055        { 
    2036                 const int cf = planePoly->ClassifyPlane(planes[i]); 
     2056                const int cf = planePoly->ClassifyPlane(*planes[i]); 
    20372057                         
    20382058                // split new polygon with all previous planes 
     
    20462066                                        Polygon3 *backPoly = new Polygon3(); 
    20472067 
    2048                                         planePoly->Split(planes[i], *frontPoly, *backPoly, splitPts); 
     2068                                        planePoly->Split(*planes[i], *frontPoly, *backPoly, splitPts); 
    20492069                                        DEL_PTR(planePoly); 
    20502070 
Note: See TracChangeset for help on using the changeset viewer.