Changeset 379


Ignore:
Timestamp:
11/05/05 12:40:40 (19 years ago)
Author:
mattausch
Message:

worked on pvs heuristics

Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env

    r378 r379  
    5656 
    5757Sampling { 
    58         totalSamples    400000 
     58        totalSamples    300000 
    5959        samplesPerPass  3 
    6060} 
     
    7373                minPvs 10 
    7474                maxPvs 300 
    75                 samples 100000 
     75                samples 100 
    7676        } 
    7777 
     
    126126        #splitPlaneStrategy 130 
    127127         
    128         splitPlaneStrategy 130 
     128        splitPlaneStrategy 256 
    129129         
    130         maxCandidates 80 
     130        maxPolyCandidates 5 
     131        maxRayCandidates 50 
    131132         
    132133        Termination { 
    133134                # autopartition 
    134                 maxRays 30 
     135                maxRays 1000 
    135136                maxPolygons 1 
    136                 maxDepth 50 
     137                maxDepth 10 
    137138                 
    138139                # axis aligned splits 
    139140                AxisAligned { 
    140141                        maxPolys 5000 
    141                         maxRays 600 
     142                        maxRays 500 
    142143                        maxObjects 10 
    143144                        maxCostRatio 0.9 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp

    r378 r379  
    12031203          optInt, 
    12041204          "-bsp_postprocessing_samples=", 
    1205           "200000"); 
     1205          "206000"); 
    12061206 
    12071207  RegisterOption("BspTree.Construction.sideTolerance", 
     
    12611261 
    12621262  RegisterOption("BspTree.splitPlaneStrategy", 
    1263                                                                 optString, 
    1264                                                                 "-bsp_split_method=", 
    1265                                                                 "leastSplits"); 
    1266  
    1267   RegisterOption("BspTree.maxCandidates", 
     1263                optString, 
     1264                "-bsp_split_method=", 
     1265                "leastSplits"); 
     1266 
     1267  RegisterOption("BspTree.maxPolyCandidates", 
    12681268          optInt, 
    1269           "-bsp_max_candidates=", 
     1269          "-bsp_max_poly_candidates=", 
     1270          "20"); 
     1271 
     1272  RegisterOption("BspTree.maxRayCandidates", 
     1273          optInt, 
     1274          "-bsp_max_plane_candidates=", 
    12701275          "20"); 
    12711276 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h

    r373 r379  
    7979 
    8080  virtual void 
    81   ExportBspViewCellPartition(const BspTree &tree) = 0; 
     81  ExportBspViewCellPartition(const BspTree &tree, const int maxPvs = 0) = 0; 
    8282 
    8383  virtual void  
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r378 r379  
    551551                Debug << "original view cell partition:\n" << stat << endl; 
    552552                 
    553                 cout << "starting post processing using " << mSampleRays.size() << " samples ... "; 
     553                if (1) // export view cells 
     554                { 
     555                        cout << "exporting view cells ... "; 
     556                        Exporter *exporter = Exporter::GetExporter("view_cells.x3d"); 
     557                        if (exporter) 
     558                        { 
     559                                //exporter->ExportBspViewCellPartition(*mBspTree, stat.maxPvs); 
     560                                exporter->ExportBspViewCellPartition(*mBspTree, 0); 
     561                                delete exporter; 
     562                        } 
     563                        cout << "finished" << endl; 
     564                } 
     565 
     566                cout << "starting post processing using " << (int)mSampleRays.size() << " samples ... "; 
    554567                 
    555568                long startTime = GetTime(); 
     
    572585                cout << "render time: " << rt * 1e-3 << endl; 
    573586                Debug << "render time: " << rt * 1e-3 << endl; 
     587 
     588                if (1) // export view cells 
     589                { 
     590                        cout << "exporting view cells after merge ... "; 
     591                        Exporter *exporter = Exporter::GetExporter("merged_view_cells.x3d"); 
     592                        if (exporter) 
     593                        { 
     594                                //exporter->ExportBspViewCellPartition(*mBspTree, stat.maxPvs); 
     595                                exporter->ExportBspViewCellPartition(*mBspTree, 0); 
     596                                delete exporter; 
     597                        } 
     598 
     599                        cout << "finished" << endl; 
     600                } 
     601 
     602                //-- visualization of the bsp splits 
     603                bool exportSplits = false; 
     604                environment->GetBoolValue("BspTree.exportSplits", exportSplits); 
     605 
     606                 
     607                cout << "exporting splits ... "; 
     608                if (exportSplits) 
     609                        ExportSplits(objects); 
     610                cout << "finished" << endl; 
     611 
     612                // export the PVS of sample view cells 
     613                if (1) 
     614                        ExportBspPvs(objects); 
    574615        } 
    575616         
     
    603644        //-- several visualizations and statistics 
    604645        if (1) { 
    605                 if (mBspTree && (ViewCell::sHierarchy == ViewCell::BSP)) 
    606         { 
    607                 bool exportSplits = false; 
    608                 environment->GetBoolValue("BspTree.exportSplits", exportSplits); 
    609  
    610                 // export the bsp splits 
    611                 cout << "exporting splits ... "; 
    612                 if (exportSplits) 
    613                         ExportSplits(objects); 
    614                 cout << "finished" << endl; 
    615  
    616                 ExportBspPvs(objects); 
    617         } 
     646         
    618647   for (int k=0; k < pvsOut; k++) { 
    619648                 Intersectable *object = objects[k]; 
     
    901930                cout << "finished" << endl; 
    902931        } 
    903  
    904         if (1) // export view cells and leaves 
    905         { 
    906                 cout << "exporting view cells and leaves ... "; 
    907                 Exporter *exporter = Exporter::GetExporter("viewCells.x3d"); 
    908                 if (exporter) 
    909                 { 
    910                         exporter->ExportBspViewCellPartition(*mBspTree); 
    911                         delete exporter; 
    912                 } 
    913  
    914                 exporter = Exporter::GetExporter("bspLeaves.x3d"); 
    915  
    916                 if (exporter) 
    917                 { 
    918                         exporter->ExportBspLeaves(*mBspTree); 
    919                         delete exporter; 
    920                 } 
    921                 cout << "finished" << endl; 
    922         } 
    923  
    924932} 
    925933 
     
    940948        const float vcOverhead = 0.01f; 
    941949         
    942         float totalArea = 0; 
     950        // total area of view cells 
     951        float totalArea = 0;//= mKdTree->GetBox().SurfaceArea(); 
    943952 
    944953        ViewCellContainer viewCells; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r378 r379  
    1616int BspTree::sTermMaxPolygons = 10; 
    1717int BspTree::sTermMaxDepth = 20; 
    18 int BspTree::sMaxCandidates = 10; 
     18int BspTree::sMaxPolyCandidates = 10; 
     19int BspTree::sMaxRayCandidates = 10; 
    1920int BspTree::sSplitPlaneStrategy = BALANCED_POLYS;  
    2021int BspTree::sConstructionMethod = FROM_INPUT_VIEW_CELLS; 
     
    10501051                                                        const BoundedRayContainer &rays) 
    10511052{ 
    1052         if (polys.empty()) 
     1053        if (polys.empty() && rays.empty()) 
    10531054        { 
    10541055                Debug << "Warning: No autopartition polygon candidate available\n"; 
     
    10821083        if (sSplitPlaneStrategy & RANDOM_POLYGON) 
    10831084        { 
    1084                 return polys[Random((int)polys.size())]->GetSupportingPlane(); 
     1085                Vector3 pt[3]; 
     1086                for (int j = 0; j < 3; j ++) 
     1087                { 
     1088                        int idx = Random((int)rays.size()); 
     1089                        pt[j] = rays[idx]->mRay->Extrap(rays[idx]->mMaxT); 
     1090                } 
     1091 
     1092                return Plane3(pt[0], pt[1], pt[2]); 
     1093 
     1094        //return polys[Random((int)polys.size())]->GetSupportingPlane(); 
    10851095        } 
    10861096 
    10871097        // use heuristics to find appropriate plane 
    1088         return SelectPlaneHeuristics(polys, rays, sMaxCandidates); 
     1098        return SelectPlaneHeuristics(polys, rays, sMaxPolyCandidates, sMaxRayCandidates); 
    10891099} 
    10901100 
    10911101Plane3 BspTree::SelectPlaneHeuristics(PolygonContainer &polys, 
    10921102                                                                          const BoundedRayContainer &rays, 
    1093                                                                           const int maxTests) 
     1103                                                                          const int maxPolyCandidates, 
     1104                                                                          const int maxRayCandidates) 
    10941105{ 
    10951106        float lowestCost = MAX_FLOAT; 
    10961107        int bestPlaneIdx = 0; 
    10971108         
    1098         int limit = maxTests > 0 ? Min((int)polys.size(), maxTests) : (int)polys.size(); 
     1109        int limit = maxPolyCandidates > 0 ? Min((int)polys.size(), maxPolyCandidates) : (int)polys.size(); 
    10991110         
    11001111        int candidateIdx = limit; 
    1101          
    1102         for (int i = 0; i < limit; ++ i) 
     1112 
     1113        //Debug << endl; 
     1114        /*for (int i = 0; i < limit; ++ i) 
    11031115        { 
    11041116                candidateIdx = GetNextCandidateIdx(candidateIdx, polys); 
    11051117 
    11061118                Plane3 candidatePlane = polys[candidateIdx]->GetSupportingPlane(); 
    1107                  
     1119                //Debug << polys[candidateIdx] << endl; 
    11081120                // evaluate current candidate 
    11091121                float candidateCost = SplitPlaneCost(candidatePlane, polys, rays); 
     
    11141126                        lowestCost = candidateCost; 
    11151127                } 
    1116         } 
    1117          
     1128        }*/ 
     1129         
     1130        //limit = maxRaysCandidates > 0 ? Min((int)rays.size(), maxRayCandidates) : (int)rays.size(); 
     1131        bool chooseFromRays = false; 
     1132        int bestIdx[3]; 
     1133 
     1134        for (int i = 0; i < maxRayCandidates; ++ i) 
     1135        { 
     1136                Vector3 pt[3]; 
     1137                int idx[3]; 
     1138 
     1139                for (int j = 0; j < 3; j ++) 
     1140                { 
     1141                        idx[j] = Random((int)rays.size()); 
     1142                        pt[j] = rays[idx[j]]->mRay->Extrap(rays[idx[j]]->mMaxT); 
     1143                } 
     1144 
     1145                float candidateCost = SplitPlaneCost(Plane3(pt[0], pt[1], pt[2]), polys, rays); 
     1146 
     1147                if (candidateCost < lowestCost) 
     1148                { 
     1149                        chooseFromRays = true; 
     1150                        bestIdx[0] = idx[0]; bestIdx[1]= idx[1]; bestIdx[2] = idx[2]; 
     1151                         
     1152                        lowestCost = candidateCost; 
     1153                } 
     1154        } 
     1155 
     1156        if (chooseFromRays) 
     1157        { 
     1158                return Plane3(rays[bestIdx[0]]->mRay->Extrap(rays[bestIdx[0]]->mMaxT), 
     1159                                          rays[bestIdx[1]]->mRay->Extrap(rays[bestIdx[1]]->mMaxT), 
     1160                                          rays[bestIdx[2]]->mRay->Extrap(rays[bestIdx[2]]->mMaxT)); 
     1161        } 
     1162 
    11181163        //Debug << "Plane lowest cost: " << lowestCost << endl; 
    11191164        return polys[bestPlaneIdx]->GetSupportingPlane(); 
     
    11261171        // swap candidates to avoid testing same plane 2 times 
    11271172        std::swap(polys[currentIdx], polys[candidateIdx]); 
    1128  
    1129         /*Polygon3 *p = polys[candidateIdx]; 
    1130         polys[candidateIdx] = polys[currentIdx]; 
    1131         polys[currentIdx] = p;*/ 
    11321173         
    11331174        return currentIdx; 
     
    12811322        float sumBalancedRays = 0; 
    12821323        float sumRaySplits = 0; 
    1283         float pvsSize = 0; 
     1324        float frontPvs = 0; 
     1325        float backPvs = 0; 
     1326 
    12841327        float totalSize = 0; 
    1285  
    1286         // need three unique ids for small pvs criterium 
    1287         Intersectable::NewMail(); 
    1288         const int backId = ViewCell::sMailId; 
    1289         Intersectable::NewMail(); 
    1290         const int frontId = ViewCell::sMailId; 
    1291         Intersectable::NewMail(); 
    1292         const int frontAndBackId = ViewCell::sMailId; 
    1293         //Debug << "f " << frontId <<  " b " << backId << " fb " << frontAndBackId << endl; 
    1294  
     1328         
     1329        // create three unique ids for pvs heuristics 
     1330        Intersectable::NewMail(); const int backId = ViewCell::sMailId; 
     1331        Intersectable::NewMail(); const int frontId = ViewCell::sMailId; 
     1332        Intersectable::NewMail(); const int frontAndBackId = ViewCell::sMailId; 
     1333 
     1334        /*PolygonContainer cell; 
     1335        PolygonContainer front; 
     1336        PolygonContainer back; 
     1337 
     1338        ConstructGeometry(currentNode, cell); 
     1339        ConstructChildrenGeometry(front, cell, planes, sides); 
     1340        ConstructChildrenGeometry(back, cell, planes, sides);*/ 
     1341 
     1342 
     1343        int frontRays = 0; 
     1344        int backRays = 0; 
     1345 
     1346        // todo create geometry of left and right leaves 
     1347         
    12951348        BoundedRayContainer::const_iterator rit, rit_end = rays.end(); 
    12961349 
     
    13161369                if (sSplitPlaneStrategy & PVS) 
    13171370                { 
    1318                         vector<Ray::Intersection>::const_iterator it,  
    1319                                 it_end = ray->intersections.end(); 
    1320  
    13211371                        if (!ray->intersections.empty()) 
    13221372                        { 
    1323  
     1373                                // in case the ray intersects an objcrs 
    13241374                                // assure that we only count a object  
    13251375                                // once for the front and once for the back side of the plane 
    1326                                 pvsSize += PvsValue(*ray->intersections[0].mObject,  
    1327                                                                         cf,  
    1328                                                                         frontId,  
    1329                                                                         backId,  
    1330                                                                         frontAndBackId); 
    1331  
    1332                                 // always add 2 for each object (= maximal large PVS) 
    1333                                 //if (inc > 0.01)       totalSize += 2.0; 
     1376                                ComputePvs(*ray->intersections[0].mObject,  
     1377                                                   frontPvs,  
     1378                                               backPvs,  
     1379                                                   cf,  
     1380                                                   frontId,  
     1381                                                   backId,  
     1382                                                   frontAndBackId); 
    13341383                        } 
    1335                         //todo emerging obj 
     1384 
     1385                        // the source object in the origin of the ray 
     1386                        ComputePvs(*ray->sourceObject.mObject,  
     1387                                           frontPvs,  
     1388                                       backPvs,  
     1389                                           cf,  
     1390                                           frontId,  
     1391                                           backId,  
     1392                                           frontAndBackId); 
     1393 
     1394                        if ((cf == Ray::BACK) || (cf == Ray::FRONT_BACK) || (cf == Ray::BACK_FRONT)) 
     1395                                ++ backRays; 
     1396                        if ((cf == Ray::FRONT) || (cf == Ray::FRONT_BACK) || (cf == Ray::BACK_FRONT)) 
     1397                                ++ frontRays; 
    13361398                } 
    13371399        } 
     
    13461408 
    13471409        if (sSplitPlaneStrategy & PVS) 
    1348                 if (!rays.empty()) // HACK (should be maximal possible pvs) 
    1349                         val += sPvsFactor * pvsSize / (float)rays.size();  
     1410                if (!rays.empty()) // HACK (should divide by maximal possible pvs) 
     1411                        val += sPvsFactor * (frontPvs * (float)frontRays + (backPvs * (float)backRays)) /  
     1412                        (float)rays.size();  
    13501413 
    13511414        //Debug << "pvs: " << pvsSize << " val " << val << endl; 
     
    13541417 
    13551418 
    1356 float BspTree::PvsValue(Intersectable &obj,  
    1357                                             const int cf,  
    1358                                             const int frontId,  
    1359                                             const int backId,  
    1360                                             const int frontAndBackId) const 
    1361 { 
    1362         float pvsVal = 0; 
    1363  
     1419/*void BspTree::CreateChildrenGeometry(PolygonContainer &cell,  
     1420                                                                         PolygonContainer &front,  
     1421                                                                         PolygonContainer &back,  
     1422                                                                         Plane3 &splitPlane) 
     1423{ 
     1424}*/ 
     1425 
     1426void BspTree::ComputePvs(Intersectable &obj,  
     1427                                                 float &frontPvs, 
     1428                                                 float &backPvs, 
     1429                                                 const int cf,  
     1430                                                 const int frontId,  
     1431                                                 const int backId,  
     1432                                                 const int frontAndBackId) const 
     1433{ 
    13641434        if (cf == Ray::COINCIDENT) 
    1365                 return pvsVal; 
     1435                return; 
    13661436 
    13671437        if (cf == Ray::FRONT) 
     
    13691439                if ((obj.mMailbox != frontId) &&  
    13701440                        (obj.mMailbox != frontAndBackId)) 
    1371                         pvsVal = 1.0; 
     1441                        frontPvs += 1.0; 
    13721442 
    13731443                if (obj.mMailbox != backId) 
     
    13811451                        (obj.mMailbox != frontAndBackId)) 
    13821452                { 
    1383                         pvsVal = 1.0; 
     1453                        backPvs += 1.0; 
    13841454 
    13851455                        if (obj.mMailbox != frontId) 
     
    13911461        else if ((cf == Ray::FRONT_BACK) || (cf == Ray::BACK_FRONT)) 
    13921462        { 
    1393                 if ((obj.mMailbox == backId) || (obj.mMailbox == frontId)) 
    1394                         pvsVal = 1.0; 
    1395                 else if (obj.mMailbox != frontAndBackId) 
    1396                         pvsVal = 2.0; 
    1397                          
     1463                if (obj.mMailbox == backId) 
     1464                        frontPvs += 1.0; 
     1465                else if (obj.mMailbox == frontId) 
     1466                        backPvs += 1.0; 
     1467                else if (obj.mMailbox != frontAndBackId) // can add to both PVS 
     1468                { 
     1469                        frontPvs += 1.0; 
     1470                        backPvs += 1.0; 
     1471                } 
    13981472                obj.mMailbox = frontAndBackId; 
    13991473        } 
    1400  
    1401         return pvsVal; 
    14021474} 
    14031475 
     
    14771549                                                         sTermMaxObjectsForAxisAligned); 
    14781550        //-- partition criteria 
    1479         environment->GetIntValue("BspTree.maxCandidates", sMaxCandidates); 
     1551        environment->GetIntValue("BspTree.maxPolyCandidates", sMaxPolyCandidates); 
     1552        environment->GetIntValue("BspTree.maxRayCandidates", sMaxRayCandidates); 
    14801553        environment->GetIntValue("BspTree.splitPlaneStrategy", sSplitPlaneStrategy); 
    14811554        environment->GetFloatValue("BspTree.AxisAligned.splitBorder", sSplitBorder); 
     
    14931566    Debug << "BSP max depth: " << sTermMaxDepth << endl; 
    14941567        Debug << "BSP max polys: " << sTermMaxPolygons << endl; 
    1495         Debug << "BSP max candidates: " << sMaxCandidates << endl; 
    1496          
     1568        Debug << "BSP max rays: " << sTermMaxRays << endl; 
     1569        Debug << "BSP max polygon candidates: " << sMaxPolyCandidates << endl; 
     1570        Debug << "BSP max plane candidates: " << sMaxRayCandidates << endl; 
     1571 
    14971572        Debug << "Split plane strategy: "; 
    14981573        if (sSplitPlaneStrategy & RANDOM_POLYGON) 
     
    15121587        if (sSplitPlaneStrategy & BLOCKED_RAYS) 
    15131588                Debug << "blocked rays "; 
     1589        if (sSplitPlaneStrategy & LEAST_RAY_SPLITS) 
     1590                Debug << "least ray splits "; 
     1591        if (sSplitPlaneStrategy & BALANCED_RAYS) 
     1592                Debug << "balanced rays "; 
    15141593        if (sSplitPlaneStrategy & PVS) 
    15151594                Debug << "pvs"; 
     
    19392018} 
    19402019 
    1941 struct Candidate 
    1942 { 
    1943         Polygon3 *mPoly; 
    1944         Plane3 mPlane; 
    1945         bool mSide; 
    1946  
    1947         Candidate(Polygon3 *poly, const Plane3 &plane, const bool &side): 
    1948         mPoly(poly), mPlane(plane), mSide(side) 
    1949         {} 
    1950 }; 
    1951  
    1952 void BspTree::AddHalfspace(PolygonContainer &cell,  
    1953                                                    vector<Plane3> &planes, 
    1954                                                    vector<bool> &sides, 
    1955                                                    const Plane3 &halfspace,  
    1956                                                    const bool side) const 
    1957 { 
    1958         Polygon3 *poly = GetBoundingBox().CrossSection(halfspace); 
     2020bool BspTree::ComputeChildrenGeometry(PolygonContainer &newCell, 
     2021                                                                          const PolygonContainer &cell, 
     2022                                                                          const vector<Plane3> &planes, 
     2023                                                                          const vector<bool> &sides, 
     2024                                                                          const Plane3 &splitPlane, 
     2025                                                                          const bool side) const 
     2026{ 
     2027        // get cross section of new polygon 
     2028        Polygon3 *planePoly = GetBoundingBox().CrossSection(splitPlane); 
    19592029 
    19602030        bool inside = true; 
     
    19632033        for (int i = 0; (i < planes.size()) && inside; ++ i) 
    19642034        { 
    1965                 VertexContainer splitPts; 
    1966                 Polygon3 *frontPoly, *backPoly; 
    1967  
    1968                 const int cf = poly->ClassifyPlane(planes[i]); 
     2035                const int cf = planePoly->ClassifyPlane(planes[i]); 
    19692036                         
    19702037                // split new polygon with all previous planes 
     
    19722039                { 
    19732040                        case Polygon3::SPLIT: 
    1974                                 frontPoly = new Polygon3(); 
    1975                                 backPoly = new Polygon3(); 
    1976  
    1977                                 poly->Split(planes[i], *frontPoly, *backPoly, splitPts); 
    1978                                 DEL_PTR(poly); 
    1979  
    1980                                 if(sides[i] == true) 
    19812041                                { 
    1982                                         poly = frontPoly; 
    1983                                         DEL_PTR(backPoly); 
    1984                                 } 
     2042                                        VertexContainer splitPts; 
     2043                                 
     2044                                        Polygon3 *frontPoly = new Polygon3(); 
     2045                                        Polygon3 *backPoly = new Polygon3(); 
     2046 
     2047                                        planePoly->Split(planes[i], *frontPoly, *backPoly, splitPts); 
     2048                                        DEL_PTR(planePoly); 
     2049 
     2050                                        if(sides[i] == true) 
     2051                                        { 
     2052                                                planePoly = frontPoly; 
     2053                                                DEL_PTR(backPoly); 
     2054                                        } 
    19852055                                        else 
    19862056                                        { 
    1987                                                 poly = backPoly; 
     2057                                                planePoly = backPoly; 
    19882058                                                DEL_PTR(frontPoly); 
    19892059                                        } 
     2060                                         
    19902061                                        inside = true; 
    1991                                         break; 
     2062                                } 
     2063                                break; 
    19922064                        case Polygon3::BACK_SIDE: 
    19932065                                if (sides[i])  
     
    20022074                } 
    20032075        } 
     2076         
     2077        //-- finally add polygon 
     2078        if (inside) 
     2079                newCell.push_back(planePoly); 
     2080        else 
     2081        { 
     2082                //just copy polygons 
     2083                DEL_PTR(planePoly); 
     2084                PolygonContainer::const_iterator it, it_end = cell.end(); 
     2085                 
     2086                for (it = cell.begin(); it != it_end; ++ it) 
     2087                        newCell.push_back(*it); 
     2088 
     2089                return false; 
     2090        } 
    20042091 
    20052092        //-- plane poly splits all other candidates 
    2006  
    2007     // some polygons may fall out => rebuild cell 
    2008         vector<Candidate> candidates; 
    2009  
    20102093        for (int i = 0; i < (int)cell.size(); ++ i) 
    20112094        { 
    2012                 candidates.push_back(Candidate(cell[i], planes[i], sides[i])); 
    2013         } 
    2014  
    2015         cell.clear(); 
    2016         planes.clear(); 
    2017         sides.clear(); 
    2018  
    2019         for (int i = 0; i < (int)candidates.size(); ++ i) 
    2020         { 
    2021                 bool candidateInside = true; 
    2022  
    2023                 VertexContainer splitPts; 
    2024                 Polygon3 *frontPoly, *backPoly; 
    2025  
    2026                 const int cf = poly->ClassifyPlane(halfspace); 
     2095                inside = true; 
     2096                 
     2097                const int cf = cell[i]->ClassifyPlane(splitPlane); 
    20272098                         
    20282099                // split new polygon with all previous planes 
     
    20302101                { 
    20312102                        case Polygon3::SPLIT: 
    2032                                 frontPoly = new Polygon3(); 
    2033                                 backPoly = new Polygon3(); 
    2034  
    2035                                 poly->Split(halfspace, *frontPoly, *backPoly, splitPts); 
    2036                                 DEL_PTR(candidates[i].mPoly); 
    2037  
    2038                                 if (sides[i] == true) 
    20392103                                { 
    2040                                         candidates[i].mPoly = frontPoly; 
    2041                                         DEL_PTR(backPoly); 
     2104                                        Polygon3 *poly = new Polygon3(*cell[i]); 
     2105 
     2106                                        Polygon3 *frontPoly = new Polygon3(); 
     2107                                        Polygon3 *backPoly = new Polygon3(); 
     2108                                 
     2109                                        VertexContainer splitPts; 
     2110                                                 
     2111                                        poly->Split(splitPlane, *frontPoly, *backPoly, splitPts); 
     2112                                        DEL_PTR(poly); 
     2113 
     2114                                        if (sides[i] == true) 
     2115                                        { 
     2116                                                newCell.push_back(frontPoly); 
     2117                                                DEL_PTR(backPoly); 
     2118                                        } 
     2119                                        else 
     2120                                        { 
     2121                                                newCell.push_back(backPoly); 
     2122                                                DEL_PTR(frontPoly); 
     2123                                        } 
    20422124                                } 
    2043                                 else 
    2044                                 { 
    2045                                         candidates[i].mPoly = backPoly; 
    2046                                         DEL_PTR(frontPoly); 
    2047                                 } 
    2048                                 inside = true; 
    20492125                                break; 
    20502126                        case Polygon3::BACK_SIDE: 
    2051                                 if (candidates[i].mSide)  
    2052                                         candidateInside = false; 
     2127                                if (!sides[i])  
     2128                                        newCell.push_back(new Polygon3(*cell[i])); 
     2129                         
    20532130                                break; 
    20542131                        case Polygon3::FRONT_SIDE: 
    2055                                 if (!candidates[i].mSide) 
    2056                                         candidateInside = false; 
     2132                                if (sides[i]) 
     2133                                        newCell.push_back(new Polygon3(*cell[i])); 
     2134                                        inside = false; 
    20572135                                break; 
    20582136                        default: 
    20592137                                break; 
    20602138                } 
    2061                  
    2062                 if (candidateInside) 
    2063                 { 
    2064                         cell.push_back(candidates[i].mPoly); 
    2065                         sides.push_back(candidates[i].mSide); 
    2066                         planes.push_back(candidates[i].mPlane); 
    2067                 } 
    2068                 else 
    2069                 { 
    2070                         DEL_PTR(candidates[i].mPoly); 
    2071                 } 
    2072         } 
    2073  
    2074         //-- finally add polygon 
    2075         if (inside) 
    2076         { 
    2077                 cell.push_back(poly); 
    2078                 planes.push_back(halfspace); 
    2079                 sides.push_back(side); 
    2080         } 
    2081         else 
    2082         { 
    2083                 DEL_PTR(poly); 
    2084         } 
     2139        } 
     2140 
     2141        return true; 
    20852142} 
    20862143 
     
    23402397        return NULL; 
    23412398} 
    2342  
    2343 int BspTree::CountPvs(const BoundedRayContainer &rays) const 
    2344 { 
    2345         int pvsSize = 0; 
    2346  
    2347         BoundedRayContainer::const_iterator rit, rit_end = rays.end(); 
    2348         vector<Ray::BspIntersection>::const_iterator iit; 
    2349  
    2350         ViewCell::NewMail(); 
    2351  
    2352         for (rit = rays.begin(); rit != rit_end; ++ rit) 
    2353         { 
    2354                 Ray *ray = (*rit)->mRay; 
    2355                  
    2356                 for (iit = ray->bspIntersections.begin();  
    2357                          iit != ray->bspIntersections.end(); ++ iit) 
    2358                 { 
    2359                         BspViewCell *vc = (*iit).mLeaf->mViewCell; 
    2360  
    2361                         if (vc->Mailed()) 
    2362                         { 
    2363                                 pvsSize += vc->GetPvs().GetSize(); 
    2364                         } 
    2365                 } 
    2366         } 
    2367  
    2368         return pvsSize; 
    2369 } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r378 r379  
    455455        BspLeaf *GetRandomLeaf(const bool onlyUnmailed = false); 
    456456 
    457         /** Adds halfspace to cell definition. 
    458                 @param side indicates which side of halfspace is added 
    459         */ 
    460         void AddHalfspace(PolygonContainer &cell,  
    461                                           vector<Plane3> &planes, 
    462                                           vector<bool> &sides, 
    463                                           const Plane3 &halfspace,  
    464                                           const bool side) const; 
     457        /** Computes new cell based on the old cell definition and a new split plane 
     458                @param side indicates which side of the halfspace  
     459                @returns true if plane contributes to the cell. 
     460        */ 
     461        bool ComputeChildrenGeometry(PolygonContainer &newCell, 
     462                                                        const PolygonContainer &cell, 
     463                                                        const vector<Plane3> &planes, 
     464                                                        const vector<bool> &sides, 
     465                                                        const Plane3 &splitPlane, 
     466                                                        const bool side) const; 
     467 
    465468 
    466469        /** Returns true if merge criteria are reached. 
     
    602605                @param polygons container of polygons 
    603606                @param rays bundle of rays on which the split can be based 
    604                 @param maxTests the maximal number of candidate tests 
     607                @param maxPolyCandidates the maximal number of tested polygon candidates 
     608                @param maxRayCandidates the maximal number of ray candidates 
    605609        */ 
    606610        Plane3 SelectPlaneHeuristics(PolygonContainer &polys,  
    607611                                                                 const BoundedRayContainer &rays, 
    608                                                                  const int maxTests); 
     612                                                                 const int maxPolyCandidates, 
     613                                                                 const int maxRayCandidates); 
    609614 
    610615        /** Extracts the meshes of the objects and adds them to polygons.  
     
    710715        void ExtractSplitPlanes(BspNode *n, vector<Plane3 *> &planes, vector<bool> &sides) const; 
    711716 
    712         int CountPvs(const BoundedRayContainer &rays) const; 
    713          
    714         float PvsValue(Intersectable &obj,  
    715                                    const int cf,  
    716                                    const int frontId,  
    717                                    const int backId,  
    718                                    const int frontAndBackId) const; 
     717        /** Computes the pvs of the front and back leaf with a given classification. 
     718        */ 
     719        void ComputePvs(Intersectable &obj,  
     720                                        float &frontPvs, 
     721                                        float &backPvs, 
     722                                        const int cf,  
     723                                        const int frontId,  
     724                                        const int backId,  
     725                                        const int frontAndBackId) const; 
    719726         
    720727        /// Pointer to the root of the tree 
    721728        BspNode *mRoot; 
    722  
    723729                 
    724730        BspTreeStatistics mStat; 
     
    764770        static int sSplitPlaneStrategy; 
    765771        /// number of candidates evaluated for the next split plane 
    766         static int sMaxCandidates; 
     772        static int sMaxPolyCandidates; 
     773        static int sMaxRayCandidates; 
    767774        /// BSP tree construction method 
    768775        static int sConstructionMethod; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r378 r379  
    179179 
    180180void  
    181 X3dExporter::ExportBspViewCellPartition(const BspTree &tree) 
     181X3dExporter::ExportBspViewCellPartition(const BspTree &tree, const int maxPvs) 
    182182{ 
    183183        ViewCellContainer viewCells; 
     
    186186        ViewCellContainer::const_iterator it, it_end = viewCells.end(); 
    187187 
     188 
     189        if (maxPvs == 0) 
     190                mUseForcedMaterial = true; 
     191 
    188192        for (it = viewCells.begin(); it != it_end; ++ it) 
    189193        { 
     194                mForcedMaterial.mDiffuseColor.b = 1.0f; 
     195   
     196                float importance = 0; 
     197 
     198                if (maxPvs > 0) 
     199                        importance = (float)(*it)->GetPvs().GetSize() / (float)maxPvs; 
     200 
     201                mForcedMaterial.mDiffuseColor.r = importance; 
     202                mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r; 
     203                 
    190204                if ((*it)->GetMesh()) 
    191205                        ExportViewCell(*it); 
     
    194208                        PolygonContainer cell; 
    195209                        tree.ConstructGeometry(dynamic_cast<BspViewCell *>(*it), cell); 
     210 
    196211                        ExportPolygons(cell); 
    197212                } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h

    r373 r379  
    8686 
    8787  virtual void 
    88   ExportBspViewCellPartition(const BspTree &tree); 
     88  ExportBspViewCellPartition(const BspTree &tree, const int maxPvs = 0); 
    8989 
    9090  virtual void  
Note: See TracChangeset for help on using the changeset viewer.