Ignore:
Timestamp:
11/08/05 19:00:49 (19 years ago)
Author:
mattausch
Message:

changed bsp splitplane choosing functions

File:
1 edited

Legend:

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

    r384 r390  
    44#include "Mesh.h" 
    55#include "Containers.h" 
     6#include "Polygon3.h" 
    67#include <stack> 
    78 
     
    1112class BspTree;   
    1213class BspInterior; 
    13 class Polygon3; 
     14//class Polygon3; 
    1415class AxisAlignedBox3; 
    1516class Ray; 
     17 
     18class BspNodeGeometry 
     19{ 
     20public: 
     21        BspNodeGeometry() 
     22        {}; 
     23 
     24        BspNodeGeometry(const PolygonContainer &polys,  
     25                                        const vector<Plane3> &planes,  
     26                                        const vector<bool> &sides); 
     27        BspNodeGeometry(const vector<Plane3> &planes,  
     28                                        const vector<bool> &sides);         
     29 
     30        ~BspNodeGeometry(); 
     31 
     32        float GetArea() const; 
     33         
     34        /** Computes new cell based on the old cell definition and a new split plane 
     35                @param side indicates which side of the halfspace  
     36                @returns true if plane contributes to the cell. 
     37        */ 
     38        BspNodeGeometry *ConstructChild(const BspTree &tree, 
     39                                                                        const Plane3 &splitPlane, 
     40                                                                        const bool side) const; 
     41 
     42        vector<Plane3> mPlanes; 
     43        vector<bool> mSides; 
     44        PolygonContainer mPolys; 
     45}; 
    1646 
    1747/** Data structure used for optimized ray casting. 
     
    176206public: 
    177207        BspNode(); 
    178         virtual ~BspNode(); 
     208        virtual ~BspNode(){}; 
    179209        BspNode(BspInterior *parent); 
    180210 
     
    192222        */ 
    193223        BspInterior *GetParent(); 
     224 
    194225        /** Sets parent node. 
    195226        */ 
    196227        void SetParent(BspInterior *parent); 
    197228 
    198         /** Returns pointer to polygons. 
    199         */ 
    200         PolygonContainer *GetPolygons(); 
    201         /** Stores polygons in node or discards them according to storePolys. 
    202         */ 
    203         void ProcessPolygons(PolygonContainer *polys, const bool storePolys); 
    204  
     229         
    205230        static int mailID; 
    206231        int mailbox; 
     
    210235        bool Mailed() const { return mailbox == mailID; } 
    211236 
    212 //int mViewCellIdx; 
    213237protected: 
    214238 
    215239        /// parent of this node 
    216240        BspInterior *mParent; 
    217  
    218         /// store polygons created during BSP splits 
    219         PolygonContainer *mPolygons; 
    220241}; 
    221242 
     
    247268                @param backPolys returns the polygons in the back of the split plane 
    248269                @param coincident returns the polygons coincident to the split plane 
    249                 @param storePolys if the polygons should be stored in the node 
    250                  
     270 
    251271                @returns the number of splits    
    252272        */ 
     
    254274                                          PolygonContainer &frontPolys,  
    255275                                          PolygonContainer &backPolys,  
    256                                           PolygonContainer &coincident, 
    257                                           const bool storePolys = false); 
    258  
    259         /** Stores polygon in node or discards them according to storePolys. 
    260                 @param polys the polygons 
    261                 @param storePolys if the polygons should be stored or discarded 
    262         */ 
    263         void ProcessPolygon(Polygon3 **poly, const bool storePolys); 
     276                                          PolygonContainer &coincident); 
    264277 
    265278        friend ostream &operator<<(ostream &s, const BspInterior &A) 
     
    337350                /// rays piercing this node 
    338351                BoundedRayContainer *mRays; 
    339  
     352                /// area of current node 
     353                float mArea; 
     354                BspNodeGeometry *mCell; 
     355 
     356                /// pvs size 
     357                int mPvs; 
     358                 
    340359                BspTraversalData(): 
    341360                mNode(NULL), 
     
    343362                mDepth(0), 
    344363                mViewCell(NULL), 
    345                 mRays(NULL) 
     364                mRays(NULL), 
     365                mPvs(0), 
     366                mArea(0.0), 
     367                mCell(NULL) 
    346368                {} 
    347369                 
     
    350372                                                 const int depth,  
    351373                                                 ViewCell *viewCell, 
    352                                                  BoundedRayContainer *rays):  
     374                                                 BoundedRayContainer *rays, 
     375                                                 int pvs, 
     376                                                 float area, 
     377                                                 BspNodeGeometry *cell):  
    353378                mNode(node),  
    354379                mPolygons(polys),  
    355380                mDepth(depth),  
    356381                mViewCell(viewCell), 
    357                 mRays(rays) 
     382                mRays(rays), 
     383                mPvs(pvs), 
     384                mArea(area), 
     385                mCell(cell) 
    358386                {} 
    359387    }; 
     
    445473        void ConstructGeometry(BspViewCell *vc, PolygonContainer &cell) const; 
    446474 
     475        void ConstructGeometry(BspNode *n, BspNodeGeometry &cell) const; 
     476 
    447477        /** Returns random leaf of BSP tree. 
    448478                @param halfspace defines the halfspace from which the leaf is taken. 
     
    454484        */ 
    455485        BspLeaf *GetRandomLeaf(const bool onlyUnmailed = false); 
    456  
    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 ConstructChildGeometry(PolygonContainer &childCell, 
    462                                                             const PolygonContainer &cell, 
    463                                                             const vector<Plane3 *> &planes, 
    464                                                             const vector<bool> &sides, 
    465                                                             const Plane3 &splitPlane, 
    466                                                             const bool side) const; 
    467  
    468486 
    469487        /** Returns true if merge criteria are reached. 
     
    530548        */ 
    531549        Plane3 SelectPlane(BspLeaf *leaf,  
    532                                            PolygonContainer &polys, 
    533                                            const BoundedRayContainer &ray); 
     550                                           BspTraversalData &data, 
     551                                           BspTraversalData &frontData, 
     552                                           BspTraversalData &backData); 
    534553 
    535554        /** Evaluates the contribution of the candidate split plane. 
     
    542561        */ 
    543562        float SplitPlaneCost(const Plane3 &candidatePlane, 
    544                                                  const PolygonContainer &polys,                                                   
    545                                                  const BoundedRayContainer &rays, 
    546                                                  const PolygonContainer &cell, 
    547                                                  const vector<Plane3 *> &plane, 
    548                                                  const vector<bool> &sides, 
    549                                                  const int pvsSize) const; 
     563                                                 BspTraversalData &data, 
     564                                                 BspTraversalData &frontData, 
     565                                                 BspTraversalData &backData) const; 
    550566 
    551567        /** Strategies where the effect of the split plane is tested 
     
    557573 
    558574        /** Strategies where the effect of the split plane is tested 
    559             on all input polygons. 
     575            on all input rays. 
    560576 
    561577                @returns the cost of the candidate split plane 
    562578        */ 
    563         float SplitPlaneCost(const Plane3 &candidatePlane, 
     579        float SplitPlaneCost(const Plane3 &candidatePlane,  
    564580                                                 const BoundedRayContainer &rays, 
    565                                                  const float frontArea, 
    566                                                  const float backArea, 
    567                                                  const int pvsSize) const; 
     581                                                 const int pvs, 
     582                                                 const float area, 
     583                                                 const BspNodeGeometry &cell,  
     584                                                 BspTraversalData &frontData, 
     585                                                 BspTraversalData &backData) const; 
    568586 
    569587        /** Filters next view cell down the tree and inserts it into the appropriate leaves 
     
    589607                @returns the root of the subdivision 
    590608        */ 
    591         BspInterior *SubdivideNode(BspLeaf *leaf,  
    592                                                            PolygonContainer &polys, 
    593                                                            PolygonContainer &frontPolys, 
    594                                                            PolygonContainer &backPolys, 
    595                                                            PolygonContainer &coincident, 
    596                                                            BoundedRayContainer &rays, 
    597                                                            BoundedRayContainer &frontRays, 
    598                                                            BoundedRayContainer &backRays); 
     609 
     610        BspInterior *SubdivideNode(BspTraversalData &tData, 
     611                                                           BspTraversalData &frontData, 
     612                                                           BspTraversalData &backData, 
     613                                                           PolygonContainer &coincident); 
    599614 
    600615        /** Filters polygons down the tree. 
     
    614629                @param polygons container of polygons 
    615630                @param rays bundle of rays on which the split can be based 
    616                 @param maxPolyCandidates the maximal number of tested polygon candidates 
    617                 @param maxRayCandidates the maximal number of ray candidates 
    618631        */ 
    619632        Plane3 SelectPlaneHeuristics(BspLeaf *leaf, 
    620                                          PolygonContainer &polys,  
    621                                                                  const BoundedRayContainer &rays, 
    622                                                                  const int maxPolyCandidates, 
    623                                                                  const int maxRayCandidates); 
     633                                                                 BspTraversalData &data, 
     634                                                                 BspTraversalData &frontData, 
     635                                                                 BspTraversalData &backData); 
    624636 
    625637        /** Extracts the meshes of the objects and adds them to polygons.  
     
    663675                @param extractFront if a front view cell is extracted 
    664676        */ 
    665         void ExtractViewCells(ViewCell **backViewCell,  
    666                                                   ViewCell **frontViewCell, 
     677        void ExtractViewCells(BspTraversalData &frontData, 
     678                                                  BspTraversalData &backData,  
    667679                                                  const PolygonContainer &coincident, 
    668                                                   const Plane3 splitPlane,  
    669                                                   const bool extractBack, 
    670                                                   const bool extractFront) const; 
     680                                                  const Plane3 splitPlane) const; 
    671681         
    672682        /** Computes best cost ratio for the suface area heuristics for axis aligned 
     
    723733        /** Extracts the split planes representing the space bounded by node n. 
    724734        */ 
    725         void ExtractSplitPlanes(BspNode *n, vector<Plane3 *> &planes, vector<bool> &sides) const; 
     735        void ExtractSplitPlanes(BspNode *n, vector<Plane3> &planes, vector<bool> &sides) const; 
    726736 
    727737        /** Computes the pvs of the front and back leaf with a given classification. 
    728738        */ 
    729739        void AddToPvs(Intersectable &obj,  
    730                                         float &frontPvs, 
    731                                         float &backPvs, 
    732                                         const int cf,  
    733                                         const int frontId,  
    734                                         const int backId,  
    735                                         const int frontAndBackId) const; 
     740                                  int &frontPvs, 
     741                                  int &backPvs, 
     742                                  const int cf,  
     743                                  const int frontId,  
     744                                  const int backId,  
     745                                  const int frontAndBackId) const; 
    736746         
    737747        int ComputePvsSize(const BoundedRayContainer &rays) const; 
     
    779789        /// maximal possible depth 
    780790        static int sTermMaxDepth; 
     791        /// mininam pvs 
     792        static int sTermMinPvs; 
    781793        /// strategy to get the best split plane 
    782794        static int sSplitPlaneStrategy; 
     
    809821        static float sPvsFactor; 
    810822 
    811         /// if polygons should be stored in the tree 
    812         static bool sStoreSplitPolys; 
    813  
    814823        //-- thresholds used for view cells are merging 
    815824        static int sMinPvsDif; 
Note: See TracChangeset for help on using the changeset viewer.