Changeset 295 for trunk/VUT


Ignore:
Timestamp:
09/21/05 10:29:41 (19 years ago)
Author:
mattausch
Message:

put out debug output. added new subdivision strategies

Location:
trunk/VUT
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibility/src/CoherentHierarchicalCullingManager.cpp

    r259 r295  
    1313//----------------------------------------------------------------------- 
    1414CoherentHierarchicalCullingManager::CoherentHierarchicalCullingManager(const unsigned int  
    15                                                                                                                                                 assumedVisibility) 
     15                                                                                                                                           assumedVisibility) 
    1616{ 
    1717        SetAssumedVisibility(assumedVisibility); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp

    r209 r295  
    66#include "AxisAlignedBox3.h" 
    77#include "Ray.h" 
     8#include "Polygon3.h" 
    89 
    910#define FATAL Debug 
     
    4344  Minimize(mMin, newpt); 
    4445  Maximize(mMax, newpt); 
     46} 
     47 
     48void 
     49AxisAlignedBox3::Include(const Polygon3 &newpoly) 
     50{ 
     51        VertexContainer::const_iterator it, it_end = newpoly.mVertices.end(); 
     52 
     53        for (it = newpoly.mVertices.begin(); it != it_end; ++ it) 
     54                Include(*it); 
    4555} 
    4656 
  • trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h

    r265 r295  
    99class Plane3; 
    1010class Ray; 
    11  
     11class Polygon3; 
    1212 
    1313// -------------------------------------------------------- 
     
    9191 
    9292  // the size of the box along all the axes 
    93   Vector3 Size() const { return mMax -mMin; } 
     93  Vector3 Size() const { return mMax - mMin; } 
    9494 
    9595  // Return whether the box is unbounded.  Unbounded boxes appear 
     
    9999  // Expand the axis-aligned box to include the given object. 
    100100  void Include(const Vector3 &newpt); 
     101  void Include(const Polygon3 &newpoly); 
    101102  void Include(const AxisAlignedBox3 &bbox); 
    102103  // Expand the axis-aligned box to include given values in particular axis 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp

    r294 r295  
    33#include "ViewCellBsp.h" // TODO: erase this 
    44#include "Intersectable.h" 
     5#include "AxisAlignedBox3.h" 
    56 
    67// tolerance value for side relation 
     
    212213        return true; 
    213214} 
     215 
     216void Polygon3::IncludeInBox(const PolygonContainer &polys, AxisAlignedBox3 &box) 
     217{ 
     218        PolygonContainer::const_iterator it, it_end = polys.end(); 
     219 
     220        for (it = polys.begin(); it != it_end; ++ it) 
     221                box.Include(*(*it)); 
     222} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h

    r289 r295  
    1414class Face; 
    1515class Intersectable; 
    16  
     16class AxisAlignedBox3; 
    1717//typedef Vertex3 Vector3; 
    1818 
     
    6565        bool CheckValid() const;  
    6666 
     67        /** Includes polygons to axis aligned box. 
     68        */ 
     69        static void IncludeInBox(const PolygonContainer &polys, AxisAlignedBox3 &box); 
     70 
    6771        /// vertices are connected in counterclockwise order. 
    6872        VertexContainer mVertices; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r294 r295  
    245245 
    246246BspTree::BspTree():  
    247 mTermMaxPolygons(0),  
    248 mTermMaxDepth(0),  
    249247mRoot(NULL),  
    250248mVerticalAxis(Vector3(0, 0, 1)), 
     
    425423} 
    426424 
    427 void BspTree::InitTree(int maxPolygons, int maxDepth) 
    428 { 
    429         mTermMaxPolygons = maxPolygons; 
    430         mTermMaxDepth = maxDepth; 
    431         mStat.nodes = 1; 
    432          
    433         mBox.Initialize();      // initialise bsp tree bounding box 
    434 } 
    435  
    436  
    437  
    438425int BspTree::AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys, Intersectable *parent) 
    439426{ 
     
    506493void BspTree::Construct(const ViewCellContainer &viewCells) 
    507494{ 
    508         InitTree(sTermMaxPolygons, sTermMaxDepth); 
     495        mStat.nodes = 1; 
     496        mBox.Initialize();      // initialise bsp tree bounding box 
    509497 
    510498        // copy view cell meshes into one big polygon soup 
     
    520508void BspTree::Construct(const ObjectContainer &objects, ViewCellContainer *viewCells) 
    521509{ 
    522         // take termination criteria from globals 
    523         InitTree(sTermMaxPolygons, sTermMaxDepth); 
     510        mStat.nodes = 1; 
     511        mBox.Initialize();      // initialise bsp tree bounding box 
    524512         
    525513        PolygonContainer *polys = new PolygonContainer(); 
     
    569557{ 
    570558        //-- terminate traversal   
    571         if ((tData.mPolygons->size() <= mTermMaxPolygons) || (tData.mDepth >= mTermMaxDepth)) 
     559        if ((tData.mPolygons->size() <= sTermMaxPolygons) || (tData.mDepth >= sTermMaxDepth)) 
    572560        { 
    573561#ifdef _DEBUG 
     
    643631 
    644632        // add the new nodes to the tree + select subdivision plane 
    645         BspInterior *interior = new BspInterior(SelectPlane(polys));  
     633        BspInterior *interior = new BspInterior(SelectPlane(*polys));  
    646634 
    647635#ifdef _DEBUG 
     
    671659} 
    672660 
    673 Plane3 BspTree::SelectPlane(PolygonContainer *polys)  const 
    674 { 
    675         if (polys->size() == 0) 
     661Plane3 BspTree::SelectPlane(const PolygonContainer &polys)  const 
     662{ 
     663        if (polys.size() == 0) 
    676664        { 
    677665                Debug << "Warning: No split candidate available\n"; 
     
    682670        if (sSplitPlaneStrategy & NEXT_POLYGON) 
    683671        { 
    684                 return polys->front()->GetSupportingPlane(); 
    685         } 
    686          
    687     if (sSplitPlaneStrategy & VERTICAL_AXIS) 
     672                return polys.front()->GetSupportingPlane(); 
     673        } 
     674         
     675        if (sSplitPlaneStrategy & AXIS_ALIGNED) 
     676        { 
     677                AxisAlignedBox3 box; 
     678                box.Initialize(); 
     679         
     680                Polygon3::IncludeInBox(polys, box); 
     681         
     682                int axis = box.Size().DrivingAxis(); 
     683                Vector3 norm(0,0,0); norm[axis] = 1; 
     684 
     685                Vector3 pt = (box.Min()[axis] + box.Max()[axis]) * 0.5f; 
     686 
     687                return Plane3(norm, pt); 
     688        } 
     689 
     690        /*if (sSplitPlaneStrategy & DRIVING_AXIS) 
    688691        { 
    689692                const float dot_thres = 0.999; 
     
    695698                                return (*it)->GetSupportingPlane(); 
    696699                } 
    697         } 
     700        }*/ 
     701         
    698702        // use heuristics to find appropriate plane 
    699703        return SelectPlaneHeuristics(polys, sMaxCandidates); 
    700704} 
    701705 
    702 Plane3 BspTree::SelectPlaneHeuristics(PolygonContainer *polygons, int maxTests) const 
     706Plane3 BspTree::SelectPlaneHeuristics(const PolygonContainer &polys, int maxTests) const 
    703707{ 
    704708        float lowestCost = MAX_FLOAT; 
    705709        int bestPlaneIdx = 0; 
    706710         
    707         int limit = Min((int)polygons->size(), maxTests); 
     711        int limit = Min((int)polys.size(), maxTests); 
    708712 
    709713        for (int i = 0; i < limit; ++ i) 
    710714        { 
    711                 int candidateIdx = Random((int)polygons->size()); // TODO: avoid testing same plane 2 times 
    712                 Plane3 candidatePlane = (*polygons)[candidateIdx]->GetSupportingPlane(); 
     715                int candidateIdx = GetNextCandidateIdx((int)polys.size()); 
     716                Plane3 candidatePlane = polys[candidateIdx]->GetSupportingPlane(); 
    713717                 
    714718                // evaluate current candidate 
    715                 float candidateCost = EvalSplitPlane(polygons, candidatePlane); 
     719                float candidateCost = EvalSplitPlane(polys, candidatePlane); 
    716720                         
    717721                if (candidateCost < lowestCost) 
     
    723727        //Debug << "Plane lowest cost: " << lowestCost << endl; 
    724728         
    725         return (*polygons)[bestPlaneIdx]->GetSupportingPlane(); 
    726 } 
    727  
    728 float BspTree::EvalSplitPlane(PolygonContainer *polygons, const Plane3 &candidatePlane) const 
    729 { 
    730         PolygonContainer::const_iterator it; 
    731  
    732         float sumBalanced = 0, sumLeastSplits = 0; 
    733  
    734         for (it = polygons->begin(); it != polygons->end(); ++ it) 
    735         { 
    736                 int classification = (*it)->ClassifyPlane(candidatePlane); 
     729        return polys[bestPlaneIdx]->GetSupportingPlane(); 
     730} 
     731 
     732int BspTree::GetNextCandidateIdx(const int max) const 
     733{ 
     734        return Random(max); // TODO: avoid testing same plane 2 times 
     735} 
     736 
     737float BspTree::EvalSplitPlane(const PolygonContainer &polys, const Plane3 &candidatePlane) const 
     738{ 
     739        float sumBalanced = 0, sumLeastSplits, drivingAxis = 0; 
     740         
     741        if (sSplitPlaneStrategy & DRIVING_AXIS) 
     742        { 
     743        drivingAxis = (candidatePlane.mNormal.DrivingAxis() == mBox.Size().DrivingAxis()) ? 
     744                        99.0f : 0.0f; // always prefer driving axis => very high value 
     745        } 
     746        if ((sSplitPlaneStrategy & BALANCED_TREE) || (sSplitPlaneStrategy & LEAST_SPLITS)) 
     747        { 
     748                PolygonContainer::const_iterator it, it_end = polys.end(); 
    737749                 
    738                 if (sSplitPlaneStrategy & BALANCED_TREE) 
    739                 { 
    740                         sumBalanced += sBalancedTreeTable[classification]; 
    741                 } 
    742                  
    743                 if (sSplitPlaneStrategy & LEAST_SPLITS) 
    744                 { 
    745                         sumLeastSplits += sLeastSplitsTable[classification]; 
    746                 } 
    747         } 
    748  
    749         // return linear combination of both sums 
    750         return fabs(sumBalanced) + fabs(sumLeastSplits); 
     750                for (it = polys.begin(); it != it_end; ++ it) 
     751                { 
     752                        int classification = (*it)->ClassifyPlane(candidatePlane); 
     753 
     754                        if (sSplitPlaneStrategy & BALANCED_TREE) 
     755                                sumBalanced += sBalancedTreeTable[classification]; 
     756         
     757                        if (sSplitPlaneStrategy & LEAST_SPLITS) 
     758                                sumLeastSplits += sLeastSplitsTable[classification]; 
     759                } 
     760        } 
     761 
     762        // return linear combination of the sums 
     763        return fabs(sumBalanced) + sumLeastSplits + drivingAxis; 
    751764} 
    752765 
     
    879892        BspLeaf *leaf = dynamic_cast<BspLeaf *>(data.mNode); 
    880893 
    881         if (data.mDepth >= mTermMaxDepth) 
     894        if (data.mDepth >= sTermMaxDepth) 
    882895        { 
    883896                ++ mStat.maxDepthNodes; 
     
    898911#ifdef _DEBUG 
    899912        Debug << "BSP Traversal data. Depth: " << data.mDepth << " (max: " << mTermMaxDepth << "), #polygons: " <<  
    900           data.mPolygons->size() << " (max: " << mTermMaxPolygons << ")" << endl; 
     913          data.mPolygons->size() << " (max: " << sTermMaxPolygons << ")" << endl; 
    901914#endif 
    902915} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r294 r295  
    329329protected: 
    330330         
    331         /** Initialises BSP tree. 
    332                 @param maxPolygons the maximal polygon count before termination of  
    333                 subdivision 
    334                 @param maxDepth the maximal depth before termination of  
    335                 subdivision 
    336         */ 
    337         void InitTree(int maxPolygons, int maxDepth); 
    338  
    339331        /** Constructs the tree from the given list of polygons. 
    340332                @param viewCells if not NULL, new view cells are  
     
    346338                @returns the cost of the candidate split plane 
    347339        */ 
    348         float EvalSplitPlane(PolygonContainer *polygons, const Plane3 &candidatePlane) const; 
     340        float EvalSplitPlane(const PolygonContainer &polys, const Plane3 &candidatePlane) const; 
    349341 
    350342        /** Evaluates tree stats in the BSP tree leafs. 
     
    363355                @param polys the polygon list on which the split decition is based 
    364356        */ 
    365         Plane3 SelectPlane(PolygonContainer *polys) const; 
     357        Plane3 SelectPlane(const PolygonContainer &polys) const; 
    366358 
    367359        /** Filters next view cell down the tree and inserts it into the appropriate leaves 
     
    402394                @param maxTests the maximal number of candidate tests 
    403395        */ 
    404         Plane3 SelectPlaneHeuristics(PolygonContainer *polygons, int maxTests) const; 
     396        Plane3 SelectPlaneHeuristics(const PolygonContainer &polys, const int maxTests) const; 
    405397 
    406398        /** Extracts the meshes of the objects and copies them into the mesh.  
     
    430422        int CastRay(Ray &ray); 
    431423 
     424        /** returns next candidate index 
     425                @param max the range of candidates 
     426        */ 
     427        inline int GetNextCandidateIdx(const int max) const; 
     428 
    432429        /// Pointer to the root of the tree 
    433430        BspNode *mRoot; 
     
    438435        BspTreeStatistics mStat; 
    439436 
    440         /// local maximal polygons (changes depending on method) 
    441         int mTermMaxPolygons; 
    442         int mTermMaxDepth; 
    443  
    444437        /// Strategies for choosing next split plane. 
    445438        enum {NEXT_POLYGON = 0,  
    446439                  LEAST_SPLITS = 2,  
    447440                  BALANCED_TREE = 4,  
    448                   VERTICAL_AXIS = 8,  
     441                  DRIVING_AXIS = 8,  
    449442                  AXIS_ALIGNED = 16}; 
    450443 
     
    457450        /// vertical axis of scene 
    458451        Vector3 mVerticalAxis; 
     452 
    459453public: 
    460454        /// Parses the environment and stores the global BSP tree parameters 
Note: See TracChangeset for help on using the changeset viewer.