Ignore:
Timestamp:
10/12/05 01:15:22 (19 years ago)
Author:
mattausch
Message:

changed the from rays construction (not finished yet)

File:
1 edited

Legend:

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

    r318 r319  
    1616int BspTree::sTermMaxDepth = 20; 
    1717int BspTree::sMaxCandidates = 10; 
    18 int BspTree::sSplitPlaneStrategy = NEXT_POLYGON;  
     18int BspTree::sSplitPlaneStrategy = BALANCED_POLYS;  
    1919int BspTree::sConstructionMethod = FROM_INPUT_VIEW_CELLS; 
    2020int BspTree::sTermMaxPolysForAxisAligned = 50; 
     
    3030float BspTree::sVerticalSplitsFactor = 1.0f; // very important criterium for 2.5d scenes 
    3131float BspTree::sLargestPolyAreaFactor = 1.0f; 
     32float BspTree::sBlockedRaysFactor = 1.0f; 
    3233 
    3334/** Evaluates split plane classification with respect to the plane's  
     
    552553} 
    553554 
    554 void BspTree::Construct(const RayContainer &rays, ViewCellContainer *viewCells) 
    555 { 
    556         // TODO 
     555void BspTree::Construct(const ObjectContainer &objects, 
     556                                                const RayContainer &rays,  
     557                                                ViewCellContainer *viewCells) 
     558{ 
     559        PolygonContainer *polys = new PolygonContainer(); 
     560         
     561        // copy mesh instance polygons into one big polygon soup 
     562        mStat.polys = AddToPolygonSoup(objects, *polys); 
     563 
     564        RayContainer::const_iterator rit, rit_end = rays.end(); 
     565 
     566        long startTime = GetTime(); 
     567        Debug << "**** Casting rays into polygons ****\n"; 
     568 
     569        //-- cast rays into all polygons 
     570        for (rit = rays.begin(); rit != rays.end(); ++ rit) 
     571        { 
     572                Ray *ray = *rit; 
     573 
     574                PolygonContainer::const_iterator pit, pit_end = polys->end(); 
     575                 
     576                for (pit = polys->begin(); pit != pit_end; ++ pit) 
     577                { 
     578                        Polygon3 *poly = *pit; 
     579                         
     580                        float t = 0; 
     581                        float nearestT = 0; 
     582 
     583                        if (poly->CastRay(*ray, t, nearestT) > 0) 
     584                                poly->AddPiercingRay(ray); 
     585                } 
     586        } 
     587 
     588        Debug << "**** Finished ray casting ****\n"; 
     589        Debug << "ray casting time: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
     590 
     591        Construct(polys, viewCells); 
    557592} 
    558593 
     
    565600 
    566601        long startTime = GetTime(); 
    567         Debug << "**** Contructing tree using objects ****\n"; 
     602        Debug << "**** Contructing tree using scene geometry ****\n"; 
    568603        while (!tStack.empty())  
    569604        { 
     
    607642                leaf->SetViewCell(tData.mViewCell); 
    608643                 
    609                 //-- clean up 
    610  
     644                // clean up 
    611645                // remaining polygons are discarded or added to node 
    612646                leaf->ProcessPolygons(tData.mPolygons, mStoreSplitPolys); 
    613647                DEL_PTR(tData.mPolygons); 
    614  
    615         CLEAR_CONTAINER(*tData.mRays); 
    616                 DEL_PTR(tData.mRays); 
    617648 
    618649                return leaf; 
     
    629660                                                                                  *frontPolys, 
    630661                                                                                  *backPolys,  
    631                                                                                   coincident, 
    632                                                                                   *tData.mRays); 
     662                                                                                  coincident); 
    633663 
    634664        ViewCell *frontViewCell = mRootCell; 
     
    644674        // extract view cells from coincident polygons according to plane normal 
    645675    // only if front or back polygons are empty 
    646         ExtractViewCells(&backViewCell,  
    647                                          &frontViewCell,  
    648                                          coincident,  
    649                                          interior->mPlane,  
     676        ExtractViewCells(&backViewCell, 
     677                                         &frontViewCell, 
     678                                         coincident, 
     679                                         interior->mPlane, 
    650680                                         backPolys->empty(), 
    651681                                         frontPolys->empty()); 
     
    653683        // don't need coincident polygons anymore 
    654684        interior->ProcessPolygons(&coincident, mStoreSplitPolys); 
    655  
    656         // split rays 
    657         RayContainer *frontRays = NULL; 
    658         RayContainer *backRays = NULL; 
    659  
    660         if (tData.mRays->size() > 0) 
    661         { 
    662                 RayContainer *frontRays = new RayContainer(); 
    663                 RayContainer *backRays = new RayContainer(); 
    664  
    665                 Plane3 plane; 
    666                 SplitRays(plane, *tData.mRays, *frontRays, *backRays); 
    667         } 
    668685 
    669686        // push the children on the stack 
     
    671688                                                                 backPolys,  
    672689                                                                 tData.mDepth + 1,  
    673                                                                  backViewCell,  
    674                                                                  backRays)); 
     690                                                                 backViewCell)); 
    675691 
    676692        tStack.push(BspTraversalData(interior->GetFront(),  
    677693                                                                 frontPolys,  
    678694                                                                 tData.mDepth + 1,  
    679                                                                  frontViewCell,  
    680                                                                  frontRays)); 
     695                                                                 frontViewCell)); 
    681696 
    682697        // cleanup 
    683698        DEL_PTR(tData.mNode); 
    684699        DEL_PTR(tData.mPolygons); 
    685         DEL_PTR(tData.mRays); 
    686700 
    687701        return interior; 
     
    720734                                                                        PolygonContainer &frontPolys, 
    721735                                                                        PolygonContainer &backPolys,  
    722                                                                         PolygonContainer &coincident, 
    723                                                                         const RayContainer &rays) 
     736                                                                        PolygonContainer &coincident) 
    724737{ 
    725738        mStat.nodes += 2; 
    726739 
    727740        // add the new nodes to the tree + select subdivision plane 
    728         BspInterior *interior = new BspInterior(SelectPlane(leaf, polys, rays));  
     741        BspInterior *interior = new BspInterior(SelectPlane(leaf, polys));  
    729742 
    730743#ifdef _DEBUG 
     
    863876 
    864877Plane3 BspTree::SelectPlane(BspLeaf *leaf,  
    865                                                         PolygonContainer &polys,  
    866                                                         const RayContainer &rays) 
     878                                                        PolygonContainer &polys) 
    867879{ 
    868880        if (polys.size() == 0) 
     
    917929 
    918930        // use heuristics to find appropriate plane 
    919         return SelectPlaneHeuristics(polys, rays, sMaxCandidates); 
     931        return SelectPlaneHeuristics(polys, sMaxCandidates); 
    920932} 
    921933 
    922934Plane3 BspTree::SelectPlaneHeuristics(PolygonContainer &polys, 
    923                                                                           const RayContainer &rays, 
    924935                                                                          const int maxTests) 
    925936{ 
     
    938949                 
    939950                // evaluate current candidate 
    940                 float candidateCost = EvalSplitPlane(polys, candidatePlane, rays); 
     951                float candidateCost = EvalSplitPlane(polys, candidatePlane); 
    941952                         
    942953                if (candidateCost < lowestCost) 
     
    966977 
    967978float BspTree::EvalSplitPlane(PolygonContainer &polys,  
    968                                                           const Plane3 &candidatePlane,  
    969                                                           const RayContainer &rays) 
     979                                                          const Plane3 &candidatePlane) 
    970980{ 
    971981        float val = 0; 
     
    980990        } 
    981991 
    982         //-- strategies where the effect of the split plane on the polygons is tested 
    983         if (!((sSplitPlaneStrategy & BALANCED_POLYS) || 
    984                   (sSplitPlaneStrategy & LEAST_SPLITS)   || 
    985                   (sSplitPlaneStrategy & LARGEST_POLY_AREA) || 
    986                   (sSplitPlaneStrategy & BALANCED_VIEW_CELLS))) 
     992        // strategies where the effect of the split plane is tested 
     993        // on all input polygons  
     994        if (!((sSplitPlaneStrategy & BALANCED_POLYS)      || 
     995                  (sSplitPlaneStrategy & LEAST_SPLITS)        || 
     996                  (sSplitPlaneStrategy & LARGEST_POLY_AREA)   || 
     997                  (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) || 
     998                  (sSplitPlaneStrategy & BLOCKED_RAYS))) 
     999        { 
    9871000                return val; 
    988          
    989         PolygonContainer::const_iterator it, it_end = polys.end(); 
     1001        } 
     1002 
    9901003        float sumBalancedPolys = 0; 
    9911004        float sumSplits = 0; 
    9921005        float sumPolyArea = 0; 
    9931006        float sumBalancedViewCells = 0; 
     1007        float sumBlockedRays = 0; 
     1008 
     1009        float totalBlockedRays = 0; 
    9941010        //float totalArea = 0; 
    9951011 
    996         // container for view cells 
     1012        // container for balanced view cells criterium 
    9971013        ObjectContainer frontViewCells; 
    9981014        ObjectContainer backViewCells; 
     1015 
     1016        PolygonContainer::const_iterator it, it_end = polys.end(); 
    9991017 
    10001018        for (it = polys.begin(); it != it_end; ++ it) 
     
    10191037                } 
    10201038 
     1039                 
     1040                if (sSplitPlaneStrategy & BLOCKED_RAYS) 
     1041                { 
     1042                        float blockedRays = (float)(*it)->GetPiercingRays()->size(); 
     1043                        if (classification == Polygon3::COINCIDENT) 
     1044                        { 
     1045                                sumBlockedRays += blockedRays; 
     1046                        } 
     1047 
     1048                        totalBlockedRays += blockedRays; 
     1049                } 
     1050 
    10211051                // assign view cells to back or front according to classificaion 
    10221052                if (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) 
     
    10311061        } 
    10321062 
     1063        // all values should be approx. between 0 and 1 so they can be combined 
     1064        // and scaled with the factors according to their importance 
    10331065        if (sSplitPlaneStrategy & BALANCED_POLYS) 
    10341066                val += sBalancedPolysFactor * fabs(sumBalancedPolys) / (float)polys.size(); 
     
    10381070 
    10391071        if (sSplitPlaneStrategy & LARGEST_POLY_AREA)  
    1040                 val += sLargestPolyAreaFactor * (float)polys.size() / sumPolyArea; // HACK 
     1072                // HACK (polys.size should be totalArea) 
     1073                val += sLargestPolyAreaFactor * (float)polys.size() / sumPolyArea; 
     1074 
     1075        if (sSplitPlaneStrategy & BLOCKED_RAYS) 
     1076                if (totalBlockedRays > 0) 
     1077                        val += sBlockedRaysFactor * sumBlockedRays / totalBlockedRays; 
    10411078 
    10421079        if (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) 
     
    11331170        if (sSplitPlaneStrategy & VERTICAL_AXIS) 
    11341171                Debug << "vertical axis "; 
     1172        if (sSplitPlaneStrategy & BLOCKED_RAYS) 
     1173                Debug << "blocked rays "; 
    11351174 
    11361175        Debug << endl; 
     
    13571396        } 
    13581397} 
    1359  
    1360 void BspTree::SplitRays(const Plane3 plane, 
    1361                                                 RayContainer &rays,  
    1362                                                 RayContainer &frontRays,  
    1363                                                 RayContainer &backRays) 
    1364 { 
    1365         while (!rays.empty()) 
    1366         { 
    1367                 //TODO 
    1368         } 
    1369 } 
    13701398//} // GtpVisibilityPreprocessor 
Note: See TracChangeset for help on using the changeset viewer.