Ignore:
Timestamp:
11/25/05 17:16:26 (19 years ago)
Author:
mattausch
Message:

bsptree view cells working in VssPreprocessor?

Location:
trunk/VUT/GtpVisibilityPreprocessor/src
Files:
7 edited

Legend:

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

    r404 r436  
    4242void Polygon3::Split(const Plane3 &partition,  
    4343                                         Polygon3 &front,  
    44                                          Polygon3 &back,  
    45                                          VertexContainer &splitPts) 
     44                                         Polygon3 &back) 
    4645{ 
    4746        Vector3 ptA = mVertices.back(); 
     
    5150        VertexContainer::const_iterator it; 
    5251         
     52        Vector3 lastSplit; 
     53 
    5354        bool foundSplit = false; 
    5455        // find line - plane intersections 
     
    6869                                // test if split point not too close to previous split point 
    6970                                if (!foundSplit ||  
    70                                         (SqrDistance(splitPt, splitPts.back()) > Vector3::sDistToleranceSqrt)) 
     71                                        (SqrDistance(splitPt, lastSplit) > Vector3::sDistToleranceSqrt)) 
    7172                                { 
    7273                                        // add vertex to both polygons 
     
    7475                                        back.mVertices.push_back(splitPt); 
    7576                                         
    76                                         splitPts.push_back(splitPt); 
     77                                        lastSplit = splitPt; 
    7778                                        foundSplit = true; 
    7879                                } 
     
    8990                                        // test if split point not too close to previous split point 
    9091                                if (!foundSplit ||  
    91                                         (SqrDistance(splitPt, splitPts.back()) > Vector3::sDistToleranceSqrt)) 
     92                                        (SqrDistance(splitPt, lastSplit) > Vector3::sDistToleranceSqrt)) 
    9293                                { 
    9394                                        // add vertex to both polygons 
     
    9596                                        back.mVertices.push_back(splitPt); 
    9697 
    97                                         splitPts.push_back(splitPt); 
     98                                        lastSplit = splitPt; 
    9899                                        foundSplit = true; 
    99100                                }        
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h

    r404 r436  
    5050                @param front returns the front the front polygon 
    5151                @param back returns the back polygon 
    52                 @param splitPts returns the split points 
    5352        */ 
    5453        void Split(const Plane3 &partition,  
    5554                           Polygon3 &front,  
    56                            Polygon3 &back,  
    57                            VertexContainer &splitPts); 
     55                           Polygon3 &back); 
    5856 
    5957        /** Returns the area of this polygon. 
     
    6563        */ 
    6664        int ClassifyPlane(const Plane3 &plane) const; 
    67  
    6865 
    6966         
  • trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp

    r433 r436  
    229229                dir = vssRay.GetDir() / dist; 
    230230 
    231         if (!vssRay.mTerminationObject) 
    232                 Debug << "error!" << endl; 
    233  
    234231        intersections.push_back(Intersection(dist, vssRay.mTerminationObject, 0)); 
    235232 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r433 r436  
    143143                Polygon3 *front_piece = NULL; 
    144144                Polygon3 *back_piece = NULL; 
    145          
    146                 VertexContainer splitVertices; 
    147145 
    148146                switch (cf) 
     
    164162                                poly->Split(mPlane,  
    165163                                                        *front_piece,  
    166                                                         *back_piece,  
    167                                                         splitVertices); 
     164                                                        *back_piece); 
    168165                                         
    169166                                ++ splits; // increase number of splits 
     
    698695        facePolyMap.clear(); 
    699696 
    700         // compue bounding box 
     697        // compute bounding box 
    701698        Polygon3::IncludeInBox(*polys, mBox); 
    702699 
     
    721718} 
    722719 
     720void BspTree::Construct(const ObjectContainer &objects, const RayContainer &sampleRays) 
     721{ 
     722    mStat.nodes = 1; 
     723        mBox.Initialize();      // initialise BSP tree bounding box 
     724         
     725        BoundedRayContainer *rays = new BoundedRayContainer(); 
     726        PolygonContainer *polys = new PolygonContainer(); 
     727         
     728        // copy mesh instance polygons into one big polygon soup 
     729        mStat.polys = AddToPolygonSoup(objects, *polys); 
     730 
     731        RayContainer::const_iterator rit, rit_end = sampleRays.end(); 
     732 
     733        //-- store rays 
     734        for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 
     735        { 
     736                Ray *ray = *rit; 
     737        ray->SetId(-1); // reset id 
     738 
     739                float minT, maxT; 
     740                if (BoundRay(*ray, minT, maxT)) 
     741                        rays->push_back(new BoundedRay(ray, minT, maxT)); 
     742        } 
     743 
     744        Debug << "tree has " << (int)polys->size() << " polys, " << (int)sampleRays.size() << " rays" << endl; 
     745        Construct(polys, rays); 
     746} 
     747 
    723748void BspTree::Construct(PolygonContainer *polys, BoundedRayContainer *rays) 
    724749{ 
     
    736761 
    737762        mStat.Start(); 
    738         cout << "**** Contructing bsp tree ****\n"; 
    739  
     763        cout << "Contructing bsp tree ... "; 
     764        long startTime = GetTime(); 
    740765        while (!tStack.empty())  
    741766        { 
    742767                tData = tStack.top(); 
     768 
    743769            tStack.pop(); 
    744770 
    745771                // subdivide leaf node 
    746                 BspNode *subRoot = Subdivide(tStack, tData); 
    747         } 
     772                BspNode *r = Subdivide(tStack, tData); 
     773 
     774                if (r == mRoot) 
     775                        Debug << "BSP tree construction time spent at root: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
     776        } 
     777 
     778        cout << "finished\n"; 
    748779 
    749780        mStat.Stop(); 
     
    14521483        float pFront = 0; 
    14531484        float pBack = 0; 
    1454 Debug << "here" << endl; 
     1485 
    14551486        if (mSplitPlaneStrategy & PVS) 
    14561487        { 
     
    15731604 
    15741605                // give penalty to unbalanced split 
    1575                 if (0) 
     1606                if (1) 
    15761607                if (((pFront * 0.2 + Limits::Small) > pBack) || (pFront < (pBack * 0.2 + Limits::Small))) 
    15771608                        val += 0.5; 
     
    15831614                  << " backpvs: " << backPvs << " pBack: " << pBack << endl << endl; 
    15841615#endif 
    1585         Debug << "here2" << endl; 
    15861616        return val; 
    15871617} 
     
    21952225                                        backPoly = new Polygon3(); 
    21962226 
    2197                                         candidatePolys[i]->Split(halfSpaces[j], *frontPoly,  
    2198                                                                                          *backPoly, splitPts); 
     2227                                        candidatePolys[i]->Split(halfSpaces[j],  
     2228                                                                                         *frontPoly,  
     2229                                                                                         *backPoly); 
    21992230 
    22002231                                        DEL_PTR(candidatePolys[i]); 
     
    24502481                                        Polygon3 *backPoly = new Polygon3(); 
    24512482                                 
    2452                                         VertexContainer splitPts; 
    2453                                                  
    2454                                         poly->Split(splitPlane, *frontPoly, *backPoly, splitPts); 
     2483                                        poly->Split(splitPlane, *frontPoly, *backPoly); 
    24552484 
    24562485                                        DEL_PTR(poly); 
     
    25072536                        case Polygon3::SPLIT: 
    25082537                                { 
    2509                                         VertexContainer splitPts; 
    2510                                  
    25112538                                        Polygon3 *frontPoly = new Polygon3(); 
    25122539                                        Polygon3 *backPoly = new Polygon3(); 
    25132540 
    2514                                         planePoly->Split(plane, *frontPoly, *backPoly, splitPts); 
     2541                                        planePoly->Split(plane, *frontPoly, *backPoly); 
    25152542                                        DEL_PTR(planePoly); 
    25162543 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r428 r436  
    434434        void Construct(const ObjectContainer &objects); 
    435435 
     436        void Construct(const ObjectContainer &objects, 
     437                                   const RayContainer &sampleRays); 
     438 
    436439        /** Constructs the tree from a given set of rays. 
    437440                @param sampleRays the set of sample rays the construction is based on 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp

    r434 r436  
    440440  cout << "#totalRayStackSize=" << mVssRays.size() << endl <<flush; 
    441441         
    442   int numExportRays = 10000; 
    443   //int numExportRays = 0; 
     442  //int numExportRays = 10000; 
     443  int numExportRays = 0; 
    444444 
    445445  if (numExportRays) { 
     
    451451  //-- construct BSP view cells 
    452452  if (ViewCell::sHierarchy == ViewCell::BSP)  
    453         { 
     453  { 
    454454          const int bspSamples = min((int)mVssRays.size(), mBspConstructionSamples); 
    455455                 
     456          Debug << "bpssamples: " << bspSamples << endl; 
    456457          for (int i = 0; i < bspSamples; ++ i) 
    457                 bspRays.push_back(new Ray(*mVssRays[i])); 
    458  
     458                  bspRays.push_back(new Ray(*mVssRays[i])); 
     459          
    459460          //-- construct BSP tree using the samples 
    460461          mBspTree = new BspTree(&mUnbounded);   
    461462 
     463          ObjectContainer objects; 
     464          mSceneGraph->CollectObjects(&objects); 
     465           
    462466          mBspTree->SetGenerateViewCells(true); 
    463           mBspTree->Construct(bspRays); 
    464  
    465           Exporter *exporter = Exporter::GetExporter("vccbsprays.x3d"); 
    466                          
    467           // export rays piercing this view cell 
    468           exporter->ExportRays(bspRays, 1000, RgbColor(0, 1, 0)); 
    469  
    470           // cast remaining initial rays into BSP tree 
    471           for (int i = bspSamples; i < (int)mVssRays.size(); ++ i) 
    472                 CastRay(*mBspTree, *mVssRays[i]); 
     467          mBspTree->Construct(objects, bspRays); 
    473468        } 
    474469 
     
    587582  //-- cast ray to BSP tree to get intersection with view cells 
    588583  Ray ray(vssRay); 
    589  
    590   Debug << ray << endl; 
    591   if (ray.intersections.empty()) 
    592         Debug << "empty ray" << endl; 
    593   else  
    594         Debug << "intersection: " << ray.intersections[0].mT << " " << ray.intersections[0].mObject << endl; 
    595  
    596584  mBspTree->CastRay(ray); 
    597585                                 
     
    601589                         
    602590  if (!ray.intersections.empty()) // second intersection found 
    603         { 
     591  { 
    604592          //sampleContributions +=  
    605593          AddObjectSamples(ray.intersections[0].mObject, ray); 
    606         } 
     594  } 
    607595} 
    608596 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r435 r436  
    965965                        // do all the splits with the previous planes 
    966966                        for (int i = 0; i < (int)tData.mPlanes.size(); ++ i) 
    967                         { 
    968                                 VertexContainer splitPts; 
    969                                  
     967                        {                                
    970968                                if (planePoly->ClassifyPlane(*tData.mPlanes[i]) == Polygon3::SPLIT) 
    971969                                { 
     
    973971                                        Polygon3 *backPoly = new Polygon3(); 
    974972 
    975                                         planePoly->Split(*tData.mPlanes[i], *frontPoly, *backPoly, splitPts); 
     973                                        planePoly->Split(*tData.mPlanes[i], *frontPoly, *backPoly); 
    976974                                        DEL_PTR(planePoly); 
    977975 
Note: See TracChangeset for help on using the changeset viewer.