Ignore:
Timestamp:
10/13/05 17:58:37 (19 years ago)
Author:
mattausch
Message:

worked on the ray based subdivision. finished extracting polygons from rays

File:
1 edited

Legend:

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

    r326 r327  
    1212#include <iomanip> 
    1313#include "Exporter.h" 
     14#include "Plane3.h" 
    1415 
    1516int BspTree::sTermMaxPolygons = 10; 
     
    160161{ 
    161162        Polygon3 *splitPoly = NULL; 
     163 
    162164#ifdef _Debug 
    163165        Debug << "splitting polygons of node " << this << " with plane " << mPlane << endl; 
     
    170172                //Debug << "New polygon with plane: " << poly->GetSupportingPlane() << "\n"; 
    171173 
    172                 // get polygon classification 
     174                // classify polygon 
    173175                int classification = poly->ClassifyPlane(mPlane); 
    174176 
     
    180182                switch (classification) 
    181183                { 
    182                         case Polygon3::COINCIDENT: 
     184                        case Plane3::COINCIDENT: 
    183185                                coincident.push_back(poly); 
    184186                                break;                   
    185                         case Polygon3::FRONT_SIDE:       
     187                        case Plane3::FRONT_SIDE:         
    186188                                frontPolys.push_back(poly); 
    187189                                break; 
    188                         case Polygon3::BACK_SIDE: 
     190                        case Plane3::BACK_SIDE: 
    189191                                backPolys.push_back(poly); 
    190192                                break; 
    191                         case Polygon3::SPLIT: 
     193                        case Plane3::SPLIT: 
    192194                                front_piece = new Polygon3(poly->mParent); 
    193195                                back_piece = new Polygon3(poly->mParent); 
     
    505507        mStat.polys = AddToPolygonSoup(viewCells, *polys); 
    506508 
    507         // construct tree from viewcell polygons 
    508         Construct(polys); 
     509        // construct tree from the view cell polygons 
     510        Construct(polys, NULL); 
    509511} 
    510512 
     
    521523 
    522524        // construct tree from polygon soup 
    523         Construct(polys, viewCells); 
    524 } 
    525  
    526 void BspTree::Construct(const ObjectContainer &objects, 
    527                                                 const RayContainer &rays,  
     525        Construct(polys, NULL, viewCells); 
     526} 
     527 
     528void BspTree::Construct(RayContainer *rays,  
    528529                                                ViewCellContainer *viewCells) 
    529530{ 
    530531        PolygonContainer *polys = new PolygonContainer(); 
    531532         
    532         // copy mesh instance polygons into one big polygon soup 
    533         mStat.polys = AddToPolygonSoup(objects, *polys); 
    534  
    535         RayContainer::const_iterator rit, rit_end = rays.end(); 
     533        RayContainer::const_iterator rit, rit_end = rays->end(); 
    536534 
    537535        long startTime = GetTime(); 
    538         Debug << "**** Casting rays into polygons ****\n"; 
    539  
    540         //-- cast rays into all polygons 
    541         for (rit = rays.begin(); rit != rays.end(); ++ rit) 
     536        Debug << "**** Extracting polygons from rays ****\n"; 
     537 
     538        std::map<Face *, Polygon3 *> facePolyMap; 
     539 
     540        //-- extract polygons from faces stored in the rays 
     541        for (rit = rays->begin(); rit != rit_end; ++ rit) 
    542542        { 
    543543                Ray *ray = *rit; 
    544  
    545                 PolygonContainer::const_iterator pit, pit_end = polys->end(); 
    546                  
    547                 for (pit = polys->begin(); pit != pit_end; ++ pit) 
    548                 { 
    549                         Polygon3 *poly = *pit; 
     544         
     545                for (int i = 0; i < (int)ray->intersections.size(); ++ i) 
     546                { 
     547                        MeshInstance *obj = dynamic_cast<MeshInstance *>(ray->intersections[i].mObject); 
     548                        Face *face = obj->GetMesh()->mFaces[i]; 
    550549                         
    551                         float t = 0; 
    552                         float nearestT = 0; 
    553  
    554                         if (poly->CastRay(*ray, t, nearestT) > 0) 
    555                                 poly->AddPiercingRay(ray); 
    556                 } 
    557         } 
    558  
    559         Debug << "**** Finished ray casting ****\n"; 
     550                         std::map<Face *, Polygon3 *>::iterator it= facePolyMap.find(face); 
     551 
     552                         if (it != facePolyMap.end())  
     553                         { 
     554                                 (*it).second->AddPiercingRay(ray); 
     555                         }  
     556                         else 
     557                         { 
     558                                 Polygon3 *poly = new Polygon3(face, obj->GetMesh()); 
     559                                 polys->push_back(poly); 
     560                                 poly->AddPiercingRay(ray); 
     561 
     562                                 facePolyMap[face] = poly; 
     563                         } 
     564                } 
     565        } 
     566 
     567         
     568        mStat.polys = (int)polys->size(); 
     569 
     570        Debug << "**** Finished polygon extraction ****\n"; 
    560571        Debug << "ray casting time: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
    561572 
    562         Construct(polys, viewCells); 
    563 } 
    564  
    565 void BspTree::Construct(PolygonContainer *polys, ViewCellContainer *viewCells) 
     573        Construct(polys, rays, viewCells); 
     574} 
     575 
     576void BspTree::Construct(PolygonContainer *polys, RayContainer *rays, ViewCellContainer *viewCells) 
    566577{ 
    567578        std::stack<BspTraversalData> tStack; 
    568579         
    569         BspTraversalData tData(new BspLeaf(), polys, 0, mRootCell); 
     580        BspTraversalData tData(new BspLeaf(), polys, 0, mRootCell, rays); 
    570581        tStack.push(tData); 
    571582 
     
    670681                RayContainer *backRays = new RayContainer(); 
    671682 
    672                 Plane3 plane; 
    673                 SplitRays(plane, *tData.mRays, *frontRays, *backRays); 
     683                SplitRays(interior->mPlane, *tData.mRays, *frontRays, *backRays); 
    674684        } 
    675685 
     
    10221032                if (sSplitPlaneStrategy & LARGEST_POLY_AREA) 
    10231033                { 
    1024                         if (classification == Polygon3::COINCIDENT) 
     1034                        if (classification == Plane3::COINCIDENT) 
    10251035                                sumPolyArea += (*it)->GetArea(); 
    10261036                        //totalArea += area; 
     
    10311041                { 
    10321042                        float blockedRays = (float)(*it)->GetPiercingRays()->size(); 
    1033                         if (classification == Polygon3::COINCIDENT) 
     1043                        if (classification == Plane3::COINCIDENT) 
    10341044                        { 
    10351045                                sumBlockedRays += blockedRays; 
     
    10441054                        MeshInstance *viewCell = (*it)->mParent; 
    10451055                 
    1046                         if (classification == Polygon3::FRONT_SIDE) 
     1056                        if (classification == Plane3::FRONT_SIDE) 
    10471057                                frontViewCells.push_back(viewCell); 
    1048                         else if (viewCell && (classification == Polygon3::BACK_SIDE)) 
     1058                        else if (viewCell && (classification == Plane3::BACK_SIDE)) 
    10491059                                backViewCells.push_back(viewCell); 
    10501060                } 
     
    12491259 
    12501260        // bound ray 
    1251         if ((ray.GetType() == Ray::LOCAL_RAY)   &&  
    1252                 ((int)ray.intersections.size() > 0) && 
     1261        if ((ray.GetType() == Ray::LOCAL_RAY) &&  
     1262                (!ray.intersections.empty())      && 
    12531263            (ray.intersections[0].mT <= maxt)) 
    12541264        { 
     
    13831393} 
    13841394 
     1395 
    13851396void BspTree::SplitRays(const Plane3 plane, 
    1386                                                 RayContainer &rays,  
    1387                                                 RayContainer &frontRays,  
    1388                                                 RayContainer &backRays) 
     1397                                           RayContainer &rays,  
     1398                                           RayContainer &frontRays,  
     1399                                           RayContainer &backRays) 
    13891400{ 
    13901401        while (!rays.empty()) 
    13911402        { 
    1392                 //TODO 
     1403                Ray *ray = rays.back(); 
     1404                rays.pop_back(); 
     1405 
     1406                //-- ray-plane intersection 
     1407                float maxT = 1e6; 
     1408                float minT = 0; 
     1409         
     1410                // test with tree bounding box 
     1411                if (!mBox.GetMinMaxT(*ray, &minT, &maxT)) 
     1412                        continue; 
     1413 
     1414                if (minT < 0) // start ray from origin 
     1415                        minT = 0; 
     1416 
     1417                // bound ray 
     1418                if ((ray->GetType() == Ray::LOCAL_RAY) &&  
     1419                        (ray->intersections.empty())      && 
     1420                        (ray->intersections[0].mT <= maxT)) 
     1421                { 
     1422                        maxT = ray->intersections[0].mT; 
     1423                } 
     1424                 
     1425                int classification = ray->ClassifyPlane(plane, minT, maxT); 
     1426                 
     1427                switch (classification) 
     1428                { 
     1429                case Plane3::COINCIDENT: 
     1430                        break; 
     1431                case Plane3::BACK_SIDE: 
     1432                        backRays.push_back(ray); 
     1433                        break; 
     1434                case Plane3::FRONT_SIDE: 
     1435                        frontRays.push_back(ray); 
     1436                        break; 
     1437                case Plane3::SPLIT: 
     1438                        frontRays.push_back(ray); 
     1439                        backRays.push_back(ray); 
     1440                        //extp = splitPlane->FindIntersection(ray.GetLoc(), extp, &maxt); 
     1441                        break; 
     1442                default: 
     1443                        break; 
     1444                } 
    13931445        } 
    13941446} 
Note: See TracChangeset for help on using the changeset viewer.