Changeset 328


Ignore:
Timestamp:
10/14/05 02:05:13 (19 years ago)
Author:
mattausch
Message:

completed ray based split stuff (but not debugged yet)

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

Legend:

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

    r327 r328  
    3535  invDir.SetValue(0.0); 
    3636   
    37   SetID(); 
     37  SetId(); 
    3838} 
    3939 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h

    r327 r328  
    140140 
    141141  // returns ID of this ray (use for mailboxes) 
    142   int GetID() const { return ID; } 
     142  int GetId() const { return ID; } 
    143143 
    144144  // returns the transfrom ID of the ray (use for ray transformations) 
     
    149149   
    150150  // set unique ID for a given ray - always avoid setting to zero 
    151   void SetID() { 
     151  void SetId() { 
    152152    if ((ID = ++genID) == 0) 
    153153      ID = ++genID; 
     
    156156  // set ID to explicit value - it can be even 0 for rays transformed 
    157157  // to the canonical object space to supress the mailbox failure. 
    158   void SetID(int newID) { 
     158  void SetId(int newID) { 
    159159    ID = newID; 
    160160    // note that transfID is not changed! 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r327 r328  
    153153} 
    154154 
    155 void BspInterior::SplitPolygons(PolygonContainer &polys,  
    156                                                                 PolygonContainer &frontPolys,  
    157                                                                 PolygonContainer &backPolys,  
    158                                                                 PolygonContainer &coincident, 
    159                                                                 int &splits,  
    160                                                                 bool storePolys) 
     155void BspInterior::SplitRays(RayContainer &rays,  
     156                                                        RayContainer &frontRays,  
     157                                                        RayContainer &backRays) 
     158{ 
     159        while (!rays.empty()) 
     160        { 
     161                Ray *ray = rays.back(); 
     162                rays.pop_back(); 
     163 
     164                //-- ray-plane intersection 
     165                float maxT = 1e6; 
     166                float minT = 0; 
     167         
     168                // test with tree bounding box 
     169/*              if (!mBox.GetMinMaxT(*ray, &minT, &maxT)) 
     170                        continue; 
     171                if (minT < 0) // start ray from origin 
     172                        minT = 0; 
     173*/ 
     174                // bound ray 
     175                if ((ray->GetType() == Ray::LOCAL_RAY) &&  
     176                        (ray->intersections.empty())      && 
     177                        (ray->intersections[0].mT <= maxT)) 
     178                { 
     179                        maxT = ray->intersections[0].mT; 
     180                } 
     181                 
     182                int classification = ray->ClassifyPlane(mPlane, minT, maxT); 
     183                 
     184                switch (classification) 
     185                { 
     186                case Plane3::COINCIDENT: 
     187                        break; 
     188                case Plane3::BACK_SIDE: 
     189                        ray->SetId(BACK_RAY); 
     190                        backRays.push_back(ray); 
     191                        break; 
     192                case Plane3::FRONT_SIDE: 
     193                        ray->SetId(FRONT_RAY); 
     194                        frontRays.push_back(ray); 
     195                        break; 
     196                case Plane3::SPLIT: 
     197                        ray->SetId(SPLIT_RAY); 
     198                        frontRays.push_back(ray); 
     199                        backRays.push_back(ray); 
     200                        //extp = splitPlane->FindIntersection(ray.GetLoc(), extp, &maxt); 
     201                        break; 
     202                default: 
     203                        break; 
     204                } 
     205        } 
     206} 
     207 
     208int BspInterior::SplitPolygons(PolygonContainer &polys,  
     209                                                           PolygonContainer &frontPolys,  
     210                                                           PolygonContainer &backPolys,  
     211                                                           PolygonContainer &coincident, 
     212                                                           bool storePolys) 
    161213{ 
    162214        Polygon3 *splitPoly = NULL; 
     215 
     216        int splits = 0; 
    163217 
    164218#ifdef _Debug 
     
    196250 
    197251                                //-- split polygon into front and back part 
    198                                 poly->Split(mPlane, *front_piece, *back_piece, splitVertices); 
    199  
     252                                poly->Split(mPlane,  
     253                                                        *front_piece,  
     254                                                        *back_piece,  
     255                                                        splitVertices); 
     256                                         
    200257                                ++ splits; // increase number of splits 
     258 
     259                                //-- inherit rays 
     260                                if (poly->mPiercingRays) 
     261                                        InheritRays(*poly, *front_piece, *back_piece); 
    201262 
    202263                                // check if polygons still valid  
     
    222283                } 
    223284        } 
     285 
     286        return splits; 
     287} 
     288void BspInterior::InheritRays(const Polygon3 &poly,  
     289                                                      Polygon3 &front_piece,  
     290                                                      Polygon3 &back_piece) 
     291{ 
     292        RayContainer *rays = poly.mPiercingRays; 
     293 
     294        RayContainer::const_iterator it, it_end = rays->end(); 
     295 
     296        for (it = rays->begin(); it != it_end; ++ it) 
     297        { 
     298                switch((*it)->GetId()) 
     299                { 
     300                case BACK_RAY: 
     301                        back_piece.GetPiercingRays()->push_back(*it); 
     302                        break; 
     303                case FRONT_RAY: 
     304                        front_piece.GetPiercingRays()->push_back(*it); 
     305                        break; 
     306                } 
     307        } 
    224308} 
    225309 
     
    347431        BspNode *firstNode = mRoot ? mRoot : new BspLeaf(); 
    348432 
    349         tStack.push(BspTraversalData(firstNode, polys, 0, mRootCell)); 
     433        tStack.push(BspTraversalData(firstNode, polys, 0, mRootCell, new RayContainer())); 
    350434 
    351435        while (!tStack.empty()) 
     
    369453                 
    370454                                // split viewcell polygons with respect to split plane 
    371                                 interior->SplitPolygons(*tData.mPolygons,  
    372                                                                                 *frontPolys,  
    373                                                                                 *backPolys, 
    374                                                                                 coincident, 
    375                                                                                 splits,  
    376                                                                                 sStoreSplitPolys); 
     455                                splits += interior->SplitPolygons(*tData.mPolygons,  
     456                                                                                                  *frontPolys,  
     457                                                                                                  *backPolys, 
     458                                                                                                  coincident, 
     459                                                                                                  sStoreSplitPolys); 
    377460                                 
    378461                                // extract view cells associated with the split polygons 
     
    399482                                                                                         frontPolys,  
    400483                                                                                         tData.mDepth + 1,  
    401                                                                                          frontViewCell)); 
     484                                                                                         frontViewCell, 
     485                                                                                         tData.mRays)); 
    402486 
    403487                                tStack.push(BspTraversalData(interior->GetBack(),  
    404488                                                                                         backPolys,  
    405489                                                                                         tData.mDepth + 1,  
    406                                                                                          backViewCell)); 
     490                                                                                         backViewCell, 
     491                                                                                         new RayContainer())); 
    407492                        } 
    408493 
     
    543628                Ray *ray = *rit; 
    544629         
     630                ray->SetId(-1); // reset id 
     631 
    545632                for (int i = 0; i < (int)ray->intersections.size(); ++ i) 
    546633                { 
     
    637724        } 
    638725 
     726 
    639727        //-- continue subdivision 
    640         PolygonContainer *backPolys = new PolygonContainer(); 
    641         PolygonContainer *frontPolys = new PolygonContainer(); 
    642728        PolygonContainer coincident; 
    643          
     729 
     730        BspSplitData splitData; 
     731                 
     732        splitData.mPolys = tData.mPolygons; 
     733        splitData.mFrontPolys = new PolygonContainer(), 
     734        splitData.mBackPolys = new PolygonContainer(); 
     735        splitData.mCoincident = &coincident; 
     736         
     737        splitData.mRays = tData.mRays; 
     738        splitData.mFrontRays = new RayContainer(); 
     739        splitData.mBackRays = new RayContainer(); 
     740 
    644741        // create new interior node and two leaf nodes 
    645         BspInterior *interior = SubdivideNode(dynamic_cast<BspLeaf *>(tData.mNode), 
    646                                                                                   *tData.mPolygons, 
    647                                                                                   *frontPolys, 
    648                                                                                   *backPolys,  
    649                                                                                   coincident, 
    650                                                                                   *tData.mRays); 
     742        BspInterior *interior =  
     743                SubdivideNode(dynamic_cast<BspLeaf *>(tData.mNode), splitData); 
    651744 
    652745        ViewCell *frontViewCell = mRootCell; 
     
    664757        ExtractViewCells(&backViewCell, 
    665758                                         &frontViewCell, 
    666                                          coincident, 
     759                                         *splitData.mCoincident, 
    667760                                         interior->mPlane, 
    668                                          backPolys->empty(), 
    669                                          frontPolys->empty()); 
     761                                         splitData.mBackPolys->empty(), 
     762                                         splitData.mFrontPolys->empty()); 
    670763         
    671764        // don't need coincident polygons anymore 
    672765        interior->ProcessPolygons(&coincident, sStoreSplitPolys); 
    673766 
    674         // split rays 
    675         RayContainer *frontRays = NULL; 
    676         RayContainer *backRays = NULL; 
    677  
    678         if (tData.mRays) 
    679         { 
    680                 RayContainer *frontRays = new RayContainer(); 
    681                 RayContainer *backRays = new RayContainer(); 
    682  
    683                 SplitRays(interior->mPlane, *tData.mRays, *frontRays, *backRays); 
    684         } 
    685  
    686767        // push the children on the stack 
    687768        tStack.push(BspTraversalData(interior->GetBack(),  
    688                                                                  backPolys,  
     769                                                                 splitData.mBackPolys,  
    689770                                                                 tData.mDepth + 1,  
    690771                                                                 backViewCell,  
    691                                                                  backRays)); 
     772                                                                 splitData.mBackRays)); 
    692773 
    693774        tStack.push(BspTraversalData(interior->GetFront(),  
    694                                                                  frontPolys,  
     775                                                                 splitData.mFrontPolys,  
    695776                                                                 tData.mDepth + 1,  
    696777                                                                 frontViewCell,  
    697                                                                  frontRays)); 
     778                                                                 splitData.mFrontRays)); 
    698779 
    699780        // cleanup 
     
    736817 
    737818BspInterior *BspTree::SubdivideNode(BspLeaf *leaf,  
    738                                                                         PolygonContainer &polys,  
    739                                                                         PolygonContainer &frontPolys, 
    740                                                                         PolygonContainer &backPolys,  
    741                                                                         PolygonContainer &coincident, 
    742                                                                         const RayContainer &rays) 
     819                                                                        BspSplitData &splitData) 
    743820{ 
    744821        mStat.nodes += 2; 
    745822 
    746         // add the new nodes to the tree + select subdivision plane 
    747         BspInterior *interior = new BspInterior(SelectPlane(leaf, polys, rays));  
     823        // select subdivision plane 
     824        BspInterior *interior =  
     825                new BspInterior(SelectPlane(leaf, *splitData.mPolys, *splitData.mRays));  
    748826 
    749827#ifdef _DEBUG 
     
    751829#endif 
    752830 
    753         // split polygon according to current plane 
    754         int splits = 0; 
    755          
    756         interior->SplitPolygons(polys,  
    757                                                         frontPolys,  
    758                                                         backPolys,  
    759                                                         coincident,  
    760                                                         splits,  
    761                                                         sStoreSplitPolys); 
    762          
    763         mStat.splits += splits; 
     831        // partition rays 
     832        interior->SplitRays(*splitData.mRays,  
     833                                                *splitData.mFrontRays,  
     834                                                *splitData.mBackRays); 
     835         
     836        // split polygons with split plane 
     837        mStat.splits +=interior->SplitPolygons(*splitData.mPolys,  
     838                                                                               *splitData.mFrontPolys,  
     839                                                                       *splitData.mBackPolys,  
     840                                                                       *splitData.mCoincident,  
     841                                                                       sStoreSplitPolys); 
    764842 
    765843        BspInterior *parent = leaf->GetParent(); 
     
    13931471} 
    13941472 
    1395  
    1396 void BspTree::SplitRays(const Plane3 plane, 
    1397                                            RayContainer &rays,  
    1398                                            RayContainer &frontRays,  
    1399                                            RayContainer &backRays) 
    1400 { 
    1401         while (!rays.empty()) 
    1402         { 
    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                 } 
    1445         } 
    1446 } 
    14471473//} // GtpVisibilityPreprocessor 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r327 r328  
    157157                @param backPolys returns the polygons in the back of the split plane 
    158158                @param coincident returns the polygons coincident to the split plane 
    159                 @param splits returns the splits number of splits        
    160159                @param storePolys if the polygons should be stored in the node 
    161         */ 
    162         void SplitPolygons(PolygonContainer &polys,  
    163                                            PolygonContainer &frontPolys,  
    164                                            PolygonContainer &backPolys,  
    165                                            PolygonContainer &coincident, 
    166                                            int &splits, 
    167                                            bool storePolys = false); 
     160                @returns the number of splits    
     161        */ 
     162        int SplitPolygons(PolygonContainer &polys,  
     163                                          PolygonContainer &frontPolys,  
     164                                          PolygonContainer &backPolys,  
     165                                          PolygonContainer &coincident, 
     166                                          bool storePolys = false); 
     167 
     168        /** Splits the rays into front and back rays according to split plane 
     169                @param rays contains the rays to be split. The rays are  
     170                           distributed to front and back rays. 
     171                @param frontRays returns rays on the front side of the plane 
     172                @param backRays returns rays on the back side of the plane 
     173        */ 
     174        void SplitRays(RayContainer &rays,  
     175                                   RayContainer &frontRays,  
     176                                   RayContainer &backRays); 
    168177 
    169178        /** Stores polygon in node or discards them according to storePolys. 
     
    179188 
    180189protected:       
    181          
     190 
     191        /** The piercing rays of the polygon are inherited by the child fragments 
     192                @param poly the parent polygon 
     193                @parm front_piece the front fragment inheriting the front rays 
     194                @param back_piece the back fragment inheriting the back rays 
     195        */ 
     196        void InheritRays(const Polygon3 &poly,  
     197                                         Polygon3 &front_piece,  
     198                                         Polygon3 &back_piece); 
     199 
     200        enum {BACK_RAY, FRONT_RAY, SPLIT_RAY}; 
    182201        /// Splitting plane corresponding to this node 
    183202        Plane3 mPlane; 
     
    249268                                                 const int depth,  
    250269                                                 ViewCell *viewCell, 
    251                                                  RayContainer *rays = NULL):  
     270                                                 RayContainer *rays):  
    252271                mNode(node),  
    253272                mPolygons(polys),  
     
    257276                {} 
    258277    }; 
     278 
     279        /** given as argument for a node subdivision. 
     280                Stores the polyons and rays and the returned  
     281                front and back fragments. 
     282        */ 
     283        struct BspSplitData 
     284        { 
     285                PolygonContainer *mPolys; 
     286                PolygonContainer *mFrontPolys; 
     287                PolygonContainer *mBackPolys; 
     288                PolygonContainer *mCoincident; 
     289                RayContainer *mRays; 
     290                RayContainer *mBackRays; 
     291                RayContainer *mFrontRays; 
     292        }; 
    259293 
    260294        typedef std::stack<BspTraversalData> BspTraversalStack; 
     
    393427        /** Subdivide leaf. 
    394428                @param leaf the leaf to be subdivided 
    395                 @param polys the input polygons 
    396                 @param frontPolys returns the polygons in the front of the split plane 
    397                 @param backPolys returns the polygons in the back of the split plane 
    398                 @param coincident returns the polygons coincident to the split plane 
    399                 @param rays ray container used to guide the split process 
     429                @param splitData data relevant for the splti 
    400430                @returns the root of the subdivision 
    401431        */ 
    402432        BspInterior *SubdivideNode(BspLeaf *leaf,  
    403                                                            PolygonContainer &polys,  
    404                                                            PolygonContainer &frontPolys, 
    405                                                            PolygonContainer &backPolys,  
    406                                                            PolygonContainer &coincident, 
    407                                                            const RayContainer &rays); 
     433                                                           BspSplitData &splitData); 
    408434 
    409435        /** Filters polygons down the tree. 
     
    501527                                                         vector<SortableEntry> &splitCandidates) const; 
    502528 
    503         /** Splits the rays into front and back rays according to split plane 
    504                 @param rays contains the rays to be split. The rays are  
    505                            distributed to front and back rays. 
    506                 @param frontRays returns rays on the front side of the plane 
    507                 @param backRays returns rays on the back side of the plane 
    508         */ 
    509         void BspTree::SplitRays(const Plane3 plane, 
    510                                                         RayContainer &rays,  
    511                                                         RayContainer &frontRays,  
    512                                                         RayContainer &backRays); 
    513529 
    514530        /// Pointer to the root of the tree 
Note: See TracChangeset for help on using the changeset viewer.