Changeset 318


Ignore:
Timestamp:
10/11/05 19:25:27 (19 years ago)
Author:
mattausch
Message:

VisibilityInfo?: query sort operators as templates
X3dExporter: Fixed polygon wire frame, bsp splits, and bsp split planes visualization
ViewCellBsp?: Added rays to split criteria (not finished yet)
OgreOctreeSceneManager?: fixed error (mNumOctants instead of mNumOctrees)

Location:
trunk/VUT
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibility/include/VisibilityInfo.h

    r316 r318  
    3030        void SetProjectedPixels(int vis); 
    3131         
    32         /** Computes ratio of visible to projected pixels. */ 
     32        /** Computes ratio of visible to projected pixels.  
     33        */ 
    3334        float ComputeRelativeVisibility(); 
    3435 
     
    3940        */ 
    4041        void AddVisibility(const int visiblePixels, const int projectedPixels); 
     42 
     43        bool operator<(const VisibilityInfo<T> &b) const  
     44        { 
     45                return mSource < b.mSource; 
     46        } 
     47 
     48        bool operator==(const VisibilityInfo<T> &b) const  
     49        { 
     50                return mSource == b.mSource; 
     51        } 
    4152 
    4253protected: 
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env

    r313 r318  
    6363        hierarchyType bspTree 
    6464        height 7.0 
    65         maxViewCells 20 
     65        maxViewCells 0 
    6666        #hierarchyType kdTree 
    6767        #hierarchyType sceneDependent 
    6868        filename ../data/atlanta/atlanta_viewcells_large.x3d 
    6969#       filename ../data/vienna/viewcells-25-sel.x3d 
    70 #       filename ../data/vienna/viewcells-25.x3d 
     70        filename ../data/vienna/viewcells-25.x3d 
    7171#       filename ../data/vienna/viewcells-large-sel.x3d 
    7272} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp

    r313 r318  
    16471647} 
    16481648 
     1649struct VertexData 
     1650{ 
     1651        Vector3 mVertex; 
     1652        float mAngle; 
     1653         
     1654        VertexData(Vector3 vtx, float angle): mVertex(vtx), mAngle(angle) 
     1655        {} 
     1656 
     1657        bool operator<(const VertexData &b) const  
     1658        { 
     1659                return mAngle < b.mAngle; 
     1660        } 
     1661}; 
     1662 
    16491663// TODO: use a table to avoid normal and distance computations 
    1650 Polygon3 *AxisAlignedBox3::BoundPlane(const Plane3 &plane) 
    1651 { 
    1652         Vector3 ptA, ptB; 
    1653         int sideA = 0, sideB = 0; 
    1654  
    1655         VertexContainer vertices; 
    1656  
     1664Polygon3 *AxisAlignedBox3::CrossSection(const Plane3 &plane) 
     1665{ 
     1666        Polygon3 *planePoly = new Polygon3(); 
     1667         
    16571668        int side[8]; 
    1658  
    1659         bool onFrontSide, onBackSide = false; 
    1660  
     1669        bool onFrontSide = false, onBackSide = false; 
     1670         
    16611671        Vector3 vtx; 
     1672        //-- compute classification of vertices 
    16621673        for (int i = 0; i < 8; ++i) 
    16631674        { 
     
    16691680                        onBackSide = true; 
    16701681                else // vertex coincident => push_back 
    1671                         vertices.push_back(vtx); 
     1682                        planePoly->mVertices.push_back(vtx); 
    16721683        } 
    16731684 
    1674         // does not intersect 
    1675         if (!onFrontSide && !onBackSide) 
    1676                 return NULL; 
    1677  
    1678         for (int i = 0; i < 12; ++ i) 
     1685        //-- find intersections 
     1686        if (onFrontSide && onBackSide) 
    16791687        { 
    1680                 int aIdx, bIdx; 
    1681                 GetEdge(i, aIdx, bIdx); 
    1682  
    1683                 ptA = GetVertex(aIdx); 
    1684                 ptB = GetVertex(bIdx); 
    1685  
    1686                 int sideA = side[aIdx]; 
    1687                 int sideB = side[bIdx]; 
    1688  
    1689                 if (((sideA > 0) && (sideB < 0)) || (sideA < 0) && (sideB > 0)) 
    1690                         vertices.push_back(plane.FindIntersection(ptA, ptB));    
    1691         } 
    1692  
    1693         // illformed polygon => swap 
    1694         // HACK: cannot work in abitrary cases 
    1695         if (vertices.size() > 3) 
    1696         { 
    1697                 for (int j = 0; j < (int)vertices.size() - 1; ++j) 
     1688                Vector3 ptA, ptB; 
     1689                for (int i = 0; i < 12; ++ i) 
    16981690                { 
    1699                         float minDist = 99999; 
    1700                         int minIdx = j; 
    1701  
    1702                         for (int i = j + 1; i < vertices.size(); ++i) 
    1703                         { 
    1704                                 float dist = SqrDistance(vertices[j], vertices[i]); 
    1705                                  
    1706                                 if (dist < minDist) 
    1707                                 { 
    1708                                         minDist = dist; 
    1709                                         minIdx = i; 
    1710                                 } 
    1711                         } 
    1712  
    1713                         Vector3 vtx = vertices[minIdx]; 
    1714                         vertices[minIdx] = vertices[j + 1]; 
    1715                         vertices[j + 1] = vtx; 
     1691                        int aIdx, bIdx; 
     1692                        GetEdge(i, aIdx, bIdx); 
     1693 
     1694                        ptA = GetVertex(aIdx); 
     1695                        ptB = GetVertex(bIdx); 
     1696 
     1697                        int sideA = side[aIdx]; 
     1698                        int sideB = side[bIdx]; 
     1699 
     1700                        if (((sideA > 0) && (sideB < 0)) || (sideA < 0) && (sideB > 0)) 
     1701                                planePoly->mVertices.push_back(plane.FindIntersection(ptA, ptB));        
    17161702                } 
    17171703        } 
    17181704 
    1719         Polygon3 *planePoly = new Polygon3(); 
    1720          
    1721         // wrong surface orientation? 
    1722     Vector3 norm = Normalize(CrossProd(vertices[0] - vertices[1], 
    1723                                                                            vertices[2] - vertices[1])); 
    1724  
    1725          
    1726  
    1727         if (DotProd(norm, plane.mNormal) > 0) 
    1728                 for (int i = 0; i < (int)vertices.size(); ++ i) 
    1729                         planePoly->mVertices.push_back(vertices[i]); 
    1730         else 
     1705        // order intersectioins  
     1706        if (planePoly->mVertices.size() > 3) 
    17311707        { 
    1732                 for (int i = (int)vertices.size() - 1; i >= 0; -- i) 
    1733                         planePoly->mVertices.push_back(vertices[i]); 
     1708                Vector3 centerOfMass(0); 
     1709 
     1710                // compute center of mass 
     1711                for (int i = 0; i < (int)planePoly->mVertices.size(); ++ i) 
     1712                        centerOfMass += planePoly->mVertices[i]; 
     1713                 
     1714                centerOfMass /= (float)planePoly->mVertices.size(); 
     1715 
     1716                vector<VertexData> vertexData; 
     1717                 
     1718                Vector3 refVec = Normalize(centerOfMass - planePoly->mVertices[0]); 
     1719 
     1720                // compute angle to reference point 
     1721                for (int i = 1; i < (int)planePoly->mVertices.size(); ++ i) 
     1722                { 
     1723                        float angle =  
     1724                                Angle(refVec, centerOfMass - planePoly->mVertices[i], plane.mNormal); 
     1725 
     1726                        vertexData.push_back(VertexData(planePoly->mVertices[i], angle)); 
     1727                } 
     1728                 
     1729                std::stable_sort(vertexData.begin(), vertexData.end()); 
     1730 
     1731                // update vertices 
     1732                for (int i = 1; i < (int)planePoly->mVertices.size(); ++ i) 
     1733                        planePoly->mVertices[i] = vertexData[i - 1].mVertex; 
    17341734        } 
    1735  
    1736         //Debug << *planePoly << "\narea: " << planePoly->GetArea() << endl; 
     1735        else if (planePoly->mVertices.size() == 3) 
     1736        { 
     1737                // fix orientation if needed 
     1738                if (DotProd(planePoly->GetNormal(), plane.mNormal) < 0) 
     1739                { 
     1740                        Vector3 v = planePoly->mVertices[1]; 
     1741                        planePoly->mVertices[1] = planePoly->mVertices[2]; 
     1742                        planePoly->mVertices[2] = v; 
     1743                } 
     1744        } 
    17371745         
    17381746        return planePoly; 
    17391747} 
    1740 /* 
    1741 const int AxisAlignedBox3::complEdgeTbl[12][3] = 
    1742 { 
    1743         {3, 4, 5}, 
    1744         {3, 4, 5}, 
    1745         {3, 4, 5}, 
    1746         {0, 1, 2}, 
    1747         {0, 1, 2}, 
    1748         {0, 1, 2}, 
    1749         {9, 10, 11}, 
    1750         {8, 9, 10}, 
    1751         {7, 10, 11}, 
    1752         {6, 7, 11}, 
    1753         {6, 7, 8}, 
    1754         {6, 8, 9}, 
    1755 }; 
    1756 */ 
    1757  
    1758 /* 
    1759 inline void addEdge(int idx, int ptAIdx, int ptBIdx) 
    1760 { 
    1761         edgeTable[idx].push_back(edge(ptAIdx, ptBIdx)); 
    1762 } 
    1763 int AxisAlignedBox3::CreateEdgeTable() 
    1764 { 
    1765         //-- four vertices pattern 1 (3 + reflection) 
    1766         int idx = getIdx(1) + getIdx(2) + getIdx(5) + getIdx(6);  
    1767         addEdge(idx, 1, 0); addEdge(idx, 3, 2); addEdge(idx, 7, 6; addEdge(idx, 4, 5); 
    1768         int idx = 255 - idx; 
    1769         addEdge(idx, 4, 5); addEdge(idx, 7, 6);  addEdge(idx, 3, 2); addEdge(idx, 1, 0);  
    1770  
    1771         int idx = getIdx(0) + getIdx(1) + getIdx(2) + getIdx(3);  
    1772         addEdge(idx, 0, 4); addEdge(idx, 3, 7); addEdge(idx, 2, 6); addEdge(idx, 1, 5); 
    1773         int idx = 255 - idx; 
    1774         addEdge(idx, 1, 5); addEdge(idx, 2, 6); addEdge(idx, 3, 7); addEdge(idx, 0, 4);  
    1775  
    1776         int idx = getIdx(2) + getIdx(6) + getIdx(7) + getIdx(3); 
    1777         addEdge(idx, 0, 3); addEdge(idx, 4, 7); addEdge(idx, 5, 6); addEdge(idx, 1, 2); 
    1778         int idx = 255 - idx; 
    1779         addEdge(idx, 1, 2); addEdge(idx, 5, 6); addEdge(idx, 4, 7); addEdge(idx, 0, 3);  
    1780  
    1781  
    1782         //-- four vertices pattern 2 (12 + reflection 
    1783         int idx = getIdx(0) + getIdx(4); 
    1784         addEdge(idx, 0, 1); addEdge(idx, 0, 3); addEdge(idx, 4, 7; addEdge(idx, 4, 5); 
    1785 } 
    1786 */ 
  • trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h

    r312 r318  
    305305  void GetEdge(const int edge, int  &aIdx, int &bIdx) const; 
    306306 
    307   /** Bounds plane with box. Returns polygon resulting from the bounded 
    308           plane. 
     307  /** Computes cross section of plane with box (i.e., bounds box).  
     308          @returns the cross section 
    309309  */ 
    310   Polygon3 *BoundPlane(const Plane3 &plane); 
     310  Polygon3 *CrossSection(const Plane3 &plane); 
    311311 
    312312#define __EXTENT_HACK 
     
    360360  static const int fsvertices[27][9]; 
    361361 
    362   // table storing the complementary edges of each edge 
    363   //static const int complEdgeTbl[12][3]; 
    364  
    365362  // input and output operator with stream 
    366363  friend ostream& operator<<(ostream &s, const AxisAlignedBox3 &A); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Containers.h

    r263 r318  
    1212class Intersectable; 
    1313class Polygon3; 
     14class Ray; 
    1415 
    15 /** Container storing polygons used during BSP tree construction 
     16/** Container storing polygons used during BSP tree construction. 
    1617*/ 
    1718typedef vector<Polygon3 *> PolygonContainer; 
     19 
     20/** Container storing a bundle of rays. 
     21*/ 
     22typedef vector<Ray *> RayContainer; 
    1823 
    1924/** Container for Mesh pointers primarily for the use within the kDTree and 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp

    r317 r318  
    5656        VertexContainer::const_iterator it; 
    5757         
     58        bool foundSplit = false; 
    5859        // find line - plane intersections 
    5960        for (it = mVertices.begin(); it != mVertices.end(); ++ it) 
     
    7172                         
    7273                                // test if split point not too close to previous split point 
    73                                 if ((splitPts.size() == 0) ||  
     74                                if (!foundSplit ||  
    7475                                        (SqrDistance(splitPt, splitPts.back()) > SIDE_TOLERANCE_SQRD)) 
    7576                                { 
     
    7980                                         
    8081                                        splitPts.push_back(splitPt); 
     82                                        foundSplit = true; 
    8183                                } 
    8284                        } 
     
    9193                                // test if split point not too close to other split point 
    9294                                        // test if split point not too close to previous split point 
    93                                 if ((splitPts.size() == 0) ||  
     95                                if (!foundSplit ||  
    9496                                        (SqrDistance(splitPt, splitPts.back()) > SIDE_TOLERANCE_SQRD)) 
    9597                                { 
     
    99101 
    100102                                        splitPts.push_back(splitPt); 
     103                                        foundSplit = true; 
    101104                                }        
    102105                        } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r316 r318  
    400400                                 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 
    401401                                 << pvsSize/(float)objects.size() << endl  
    402                                  << "avg ray contrib=" << passSampleContributions/(float)passContributingSamples << endl; 
     402                                 << "avg ray contrib=" <<  
     403                                 ((passContributingSamples > 0) ? passSampleContributions/(float)passContributingSamples : 0) 
     404                                 << endl; 
    403405                 
    404406                 
     
    410412                        "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 
    411413                        "#AvgPVS\n"<< pvsSize/(float)objects.size() << endl << 
    412                         "#AvgRayContrib\n" << passSampleContributions/(float)passContributingSamples << endl; 
     414                        "#AvgRayContrib\n" <<  
     415                        ((passContributingSamples > 0) ? passSampleContributions/(float)passContributingSamples : 0) 
     416                        << endl; 
    413417        } 
    414418   
  • trunk/VUT/GtpVisibilityPreprocessor/src/Vector3.h

    r176 r318  
    299299} 
    300300 
     301// angle between two vectors with respect to a surface normal in the 
     302// range [0 .. 2 * pi] 
     303inline float 
     304Angle(const Vector3 &A, const Vector3 &B, const Vector3 &norm) 
     305{ 
     306        Vector3 cross = CrossProd(A, B); 
     307 
     308        float signedAngle; 
     309 
     310        if (DotProd(cross, norm) > 0) 
     311                signedAngle = atan2(-Magnitude(CrossProd(A, B)), DotProd(A, B)); 
     312        else 
     313                signedAngle = atan2(Magnitude(CrossProd(A, B)), DotProd(A, B)); 
     314 
     315        if (signedAngle < 0) 
     316                return 2 * PI + signedAngle; 
     317 
     318        return signedAngle; 
     319} 
     320 
    301321inline Vector3 
    302322Vector3::operator+() const 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r313 r318  
    149149} 
    150150 
    151 void BspInterior::SplitPolygons(PolygonContainer *polys,  
    152                                                                 PolygonContainer *frontPolys,  
    153                                                                 PolygonContainer *backPolys,  
    154                                                                 PolygonContainer *coincident, 
     151void BspInterior::SplitPolygons(PolygonContainer &polys,  
     152                                                                PolygonContainer &frontPolys,  
     153                                                                PolygonContainer &backPolys,  
     154                                                                PolygonContainer &coincident, 
    155155                                                                int &splits,  
    156156                                                                bool storePolys) 
     
    160160        Debug << "splitting polygons of node " << this << " with plane " << mPlane << endl; 
    161161#endif 
    162         while (!polys->empty()) 
    163         { 
    164                 Polygon3 *poly = polys->back(); 
    165                 polys->pop_back(); 
     162        while (!polys.empty()) 
     163        { 
     164                Polygon3 *poly = polys.back(); 
     165                polys.pop_back(); 
    166166 
    167167                //Debug << "New polygon with plane: " << poly->GetSupportingPlane() << "\n"; 
     
    179179                        case Polygon3::COINCIDENT: 
    180180                                //Debug << "coincident" << endl;         
    181                                 coincident->push_back(poly); 
     181                                coincident.push_back(poly); 
    182182                                break;                   
    183183                        case Polygon3::FRONT_SIDE:       
    184184                                //Debug << "front" << endl; 
    185                                 frontPolys->push_back(poly); 
     185                                frontPolys.push_back(poly); 
    186186                                break; 
    187187                        case Polygon3::BACK_SIDE: 
    188188                                //Debug << "back" << endl; 
    189                                 backPolys->push_back(poly); 
     189                                backPolys.push_back(poly); 
    190190                                break; 
    191191                        case Polygon3::SPLIT: 
     
    200200                                // check if polygons still valid  
    201201                                if (front_piece->Valid()) 
    202                                         frontPolys->push_back(front_piece); 
     202                                        frontPolys.push_back(front_piece); 
    203203                                else 
    204204                                        DEL_PTR(front_piece); 
    205205                                 
    206206                                if (back_piece->Valid()) 
    207                                         backPolys->push_back(back_piece); 
     207                                        backPolys.push_back(back_piece); 
    208208                                else                             
    209209                                        DEL_PTR(back_piece); 
     
    402402                 
    403403                                // split viewcell polygons with respect to split plane 
    404                                 interior->SplitPolygons(tData.mPolygons,  
    405                                                                                 frontPolys,  
    406                                                                                 backPolys, 
    407                                                                                 &coincident, 
     404                                interior->SplitPolygons(*tData.mPolygons,  
     405                                                                                *frontPolys,  
     406                                                                                *backPolys, 
     407                                                                                coincident, 
    408408                                                                                splits,  
    409409                                                                                mStoreSplitPolys); 
     
    475475} 
    476476 
    477 int BspTree::Copy2PolygonSoup(const ViewCellContainer &viewCells, PolygonContainer &polys, int maxObjects) 
     477int BspTree::AddToPolygonSoup(const ViewCellContainer &viewCells, PolygonContainer &polys, int maxObjects) 
    478478{ 
    479479        int limit = (maxObjects > 0) ? Min((int)viewCells.size(), maxObjects) : (int)viewCells.size(); 
     
    491491} 
    492492 
    493 int BspTree::Copy2PolygonSoup(const ObjectContainer &objects, PolygonContainer &polys, int maxObjects) 
     493int BspTree::AddToPolygonSoup(const ObjectContainer &objects, PolygonContainer &polys, int maxObjects) 
    494494{ 
    495495        int limit = (maxObjects > 0) ? Min((int)objects.size(), maxObjects) : (int)objects.size(); 
     
    531531        // copy view cell meshes into one big polygon soup 
    532532        PolygonContainer *polys = new PolygonContainer(); 
    533         mStat.polys = Copy2PolygonSoup(viewCells, *polys); 
     533        mStat.polys = AddToPolygonSoup(viewCells, *polys); 
    534534 
    535535        // construct tree from viewcell polygons 
     
    546546         
    547547        // copy mesh instance polygons into one big polygon soup 
    548         mStat.polys = Copy2PolygonSoup(objects, *polys); 
     548        mStat.polys = AddToPolygonSoup(objects, *polys); 
    549549 
    550550        // construct tree from polygon soup 
     
    607607                leaf->SetViewCell(tData.mViewCell); 
    608608                 
     609                //-- clean up 
     610 
    609611                // remaining polygons are discarded or added to node 
    610612                leaf->ProcessPolygons(tData.mPolygons, mStoreSplitPolys); 
    611613                DEL_PTR(tData.mPolygons); 
     614 
     615        CLEAR_CONTAINER(*tData.mRays); 
     616                DEL_PTR(tData.mRays); 
    612617 
    613618                return leaf; 
     
    621626        // create new interior node and two leaf nodes 
    622627        BspInterior *interior = SubdivideNode(dynamic_cast<BspLeaf *>(tData.mNode), 
    623                                                                                   tData.mPolygons, 
    624                                                                                   frontPolys, 
    625                                                                                   backPolys,  
    626                                                                                   &coincident); 
     628                                                                                  *tData.mPolygons, 
     629                                                                                  *frontPolys, 
     630                                                                                  *backPolys,  
     631                                                                                  coincident, 
     632                                                                                  *tData.mRays); 
    627633 
    628634        ViewCell *frontViewCell = mRootCell; 
     
    648654        interior->ProcessPolygons(&coincident, mStoreSplitPolys); 
    649655 
     656        // split rays 
     657        RayContainer *frontRays = NULL; 
     658        RayContainer *backRays = NULL; 
     659 
     660        if (tData.mRays->size() > 0) 
     661        { 
     662                RayContainer *frontRays = new RayContainer(); 
     663                RayContainer *backRays = new RayContainer(); 
     664 
     665                Plane3 plane; 
     666                SplitRays(plane, *tData.mRays, *frontRays, *backRays); 
     667        } 
     668 
    650669        // push the children on the stack 
    651         tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, backViewCell)); 
    652         tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1, frontViewCell)); 
     670        tStack.push(BspTraversalData(interior->GetBack(),  
     671                                                                 backPolys,  
     672                                                                 tData.mDepth + 1,  
     673                                                                 backViewCell,  
     674                                                                 backRays)); 
     675 
     676        tStack.push(BspTraversalData(interior->GetFront(),  
     677                                                                 frontPolys,  
     678                                                                 tData.mDepth + 1,  
     679                                                                 frontViewCell,  
     680                                                                 frontRays)); 
    653681 
    654682        // cleanup 
    655683        DEL_PTR(tData.mNode); 
    656684        DEL_PTR(tData.mPolygons); 
     685        DEL_PTR(tData.mRays); 
    657686 
    658687        return interior; 
     
    684713                        foundFront = true; 
    685714                } 
    686                 //if (foundFront) Debug << "front viewCell: " << *frontViewCell << endl; 
    687                 //if (foundBack) Debug << "back viewCell: " << *backViewCell << endl; 
    688715        } 
    689716} 
    690717 
    691718BspInterior *BspTree::SubdivideNode(BspLeaf *leaf,  
    692                                                                         PolygonContainer *polys,  
    693                                                                         PolygonContainer *frontPolys, 
    694                                                                         PolygonContainer *backPolys,  
    695                                                                         PolygonContainer *coincident) 
     719                                                                        PolygonContainer &polys,  
     720                                                                        PolygonContainer &frontPolys, 
     721                                                                        PolygonContainer &backPolys,  
     722                                                                        PolygonContainer &coincident, 
     723                                                                        const RayContainer &rays) 
    696724{ 
    697725        mStat.nodes += 2; 
    698726 
    699727        // add the new nodes to the tree + select subdivision plane 
    700         BspInterior *interior = new BspInterior(SelectPlane(leaf, *polys));  
     728        BspInterior *interior = new BspInterior(SelectPlane(leaf, polys, rays));  
    701729 
    702730#ifdef _DEBUG 
     
    707735        int splits = 0; 
    708736         
    709         interior->SplitPolygons(polys, frontPolys, backPolys, coincident, splits, mStoreSplitPolys); 
     737        interior->SplitPolygons(polys,  
     738                                                        frontPolys,  
     739                                                        backPolys,  
     740                                                        coincident,  
     741                                                        splits,  
     742                                                        mStoreSplitPolys); 
    710743         
    711744        mStat.splits += splits; 
     
    829862} 
    830863 
    831 Plane3 BspTree::SelectPlane(BspLeaf *leaf, PolygonContainer &polys) 
     864Plane3 BspTree::SelectPlane(BspLeaf *leaf,  
     865                                                        PolygonContainer &polys,  
     866                                                        const RayContainer &rays) 
    832867{ 
    833868        if (polys.size() == 0) 
     
    882917 
    883918        // use heuristics to find appropriate plane 
    884         return SelectPlaneHeuristics(polys, sMaxCandidates); 
    885 } 
    886  
    887 Plane3 BspTree::SelectPlaneHeuristics(PolygonContainer &polys, int maxTests) 
     919        return SelectPlaneHeuristics(polys, rays, sMaxCandidates); 
     920} 
     921 
     922Plane3 BspTree::SelectPlaneHeuristics(PolygonContainer &polys, 
     923                                                                          const RayContainer &rays, 
     924                                                                          const int maxTests) 
    888925{ 
    889926        float lowestCost = MAX_FLOAT; 
     
    901938                 
    902939                // evaluate current candidate 
    903                 float candidateCost = EvalSplitPlane(polys, candidatePlane); 
     940                float candidateCost = EvalSplitPlane(polys, candidatePlane, rays); 
    904941                         
    905942                if (candidateCost < lowestCost) 
     
    928965} 
    929966 
    930 float BspTree::EvalSplitPlane(PolygonContainer &polys, const Plane3 &candidatePlane) 
     967float BspTree::EvalSplitPlane(PolygonContainer &polys,  
     968                                                          const Plane3 &candidatePlane,  
     969                                                          const RayContainer &rays) 
    931970{ 
    932971        float val = 0; 
     
    13181357        } 
    13191358} 
     1359 
     1360void BspTree::SplitRays(const Plane3 plane, 
     1361                                                RayContainer &rays,  
     1362                                                RayContainer &frontRays,  
     1363                                                RayContainer &backRays) 
     1364{ 
     1365        while (!rays.empty()) 
     1366        { 
     1367                //TODO 
     1368        } 
     1369} 
    13201370//} // GtpVisibilityPreprocessor 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r313 r318  
    88class ViewCell; 
    99class Plane3; 
    10 //class Mesh; 
    1110class BspTree;   
    1211class BspInterior; 
     
    1413class AxisAlignedBox3; 
    1514class Ray; 
    16  
    17 //namespace GtpVisibilityPreprocessor { 
    18  
    19 /** Container storing a soup of polygons used during BSP tree construction 
    20 */ 
    21 typedef vector<Polygon3 *> PolygonContainer; 
    22 typedef vector<Ray *> RayContainer; 
    2315 
    2416struct BspRayTraversalData  
     
    179171        void SetupChildLinks(BspNode *b, BspNode *f); 
    180172 
    181         /** Splits polygons. 
    182                 @param polys the polygons to be split 
     173        /** Splits polygons with respect to the split plane. 
     174                @param polys the polygons to be split. the polygons are consumed and 
     175                           distributed to the containers frontPolys, backPolys, coincident. 
    183176                @param frontPolys returns the polygons in the front of the split plane 
    184177                @param backPolys returns the polygons in the back of the split plane 
     
    187180                @param storePolys if the polygons should be stored in the node 
    188181        */ 
    189         void SplitPolygons(PolygonContainer *polys,  
    190                                            PolygonContainer *frontPolys,  
    191                                            PolygonContainer *backPolys,  
    192                                            PolygonContainer *coincident,  
    193                                            int &splits,  
     182        void SplitPolygons(PolygonContainer &polys,  
     183                                           PolygonContainer &frontPolys,  
     184                                           PolygonContainer &backPolys,  
     185                                           PolygonContainer &coincident, 
     186                                           int &splits, 
    194187                                           bool storePolys = false); 
    195188 
     
    261254                /// the view cell associated with this subdivsion 
    262255                ViewCell *mViewCell; 
    263                 /// if the node is an inside or outside node with respect to the parent plane 
    264                 //bool mIsInside; 
    265                 BspTraversalData() {} 
     256                /// rays piercing this node 
     257                RayContainer *mRays; 
     258 
     259                BspTraversalData(): 
     260                mNode(NULL), 
     261                mPolygons(NULL), 
     262                mDepth(0), 
     263                mViewCell(NULL), 
     264                mRays(NULL) 
     265                {} 
    266266                 
    267                 BspTraversalData(BspNode *node, PolygonContainer *polys, const int depth, ViewCell *viewCell):  
    268                 mNode(node), mPolygons(polys), mDepth(depth), mViewCell(viewCell) {} 
     267                BspTraversalData(BspNode *node,  
     268                                                 PolygonContainer *polys,  
     269                                                 const int depth,  
     270                                                 ViewCell *viewCell, 
     271                                                 RayContainer *rays = NULL):  
     272                mNode(node),  
     273                mPolygons(polys),  
     274                mDepth(depth),  
     275                mViewCell(viewCell), 
     276                mRays(rays) 
     277                {} 
    269278    }; 
    270279 
     
    364373 
    365374        /** Evaluates the contribution of the candidate split plane. 
     375                @note the polygons can be reordered in the process. 
    366376                @returns the cost of the candidate split plane 
    367377        */ 
    368         float EvalSplitPlane(PolygonContainer &polys, const Plane3 &candidatePlane); 
     378        float EvalSplitPlane(PolygonContainer &polys,  
     379                                                 const Plane3 &candidatePlane, 
     380                                                 const RayContainer &rays); 
    369381 
    370382        /** Evaluates tree stats in the BSP tree leafs. 
     
    382394                @param leaf the leaf to be split 
    383395                @param polys the polygon list on which the split decition is based 
    384         */ 
    385         Plane3 SelectPlane(BspLeaf *leaf, PolygonContainer &polys); 
     396                @param rays ray container on which selection may be based 
     397                Returns the split plane 
     398        */ 
     399        Plane3 SelectPlane(BspLeaf *leaf,  
     400                                           PolygonContainer &polys, 
     401                                           const RayContainer &ray); 
    386402 
    387403        /** Filters next view cell down the tree and inserts it into the appropriate leaves 
     
    401417                @param backPolys returns the polygons in the back of the split plane 
    402418                @param coincident returns the polygons coincident to the split plane 
     419                @param rays ray container used to guide the split process 
    403420                @returns the root of the subdivision 
    404421        */ 
    405422        BspInterior *SubdivideNode(BspLeaf *leaf,  
    406                                                            PolygonContainer *polys,  
    407                                                            PolygonContainer *frontPolys,  
    408                                                            PolygonContainer *backPolys,  
    409                                                            PolygonContainer *coincident); 
     423                                                           PolygonContainer &polys,  
     424                                                           PolygonContainer &frontPolys, 
     425                                                           PolygonContainer &backPolys,  
     426                                                           PolygonContainer &coincident, 
     427                                                           const RayContainer &rays); 
    410428 
    411429        /** Filters polygons down the tree. 
     
    418436                                                PolygonContainer *frontPolys, PolygonContainer *backPolys); 
    419437 
    420         /** Selects the split plane in order to get a balanced tree. 
     438        /** Selects the split plane in order to construct a tree with 
     439                certain characteristics (e.g., balanced tree, least splits,  
     440                2.5d aligned) 
    421441                @param polygons container of polygons 
     442                @param rays bundle of rays on which the split can be based 
    422443                @param maxTests the maximal number of candidate tests 
    423444        */ 
    424         Plane3 SelectPlaneHeuristics(PolygonContainer &polys, const int maxTests); 
    425  
    426         /** Extracts the meshes of the objects and copies them into the mesh.  
     445        Plane3 SelectPlaneHeuristics(PolygonContainer &polys,  
     446                                                                 const RayContainer &rays, 
     447                                                                 const int maxTests); 
     448 
     449        /** Extracts the meshes of the objects and adds them to polygons.  
    427450                Adds object aabb to the aabb of the tree. 
    428451                @param maxPolys the maximal number of objects to be stored as polygons 
    429452                @returns the number of polygons 
    430453        */ 
    431         int Copy2PolygonSoup(const ObjectContainer &objects, PolygonContainer &polys, int maxObjects = 0); 
    432         /** Extracts the meshes of the view cells and copies them into the mesh.  
     454        int AddToPolygonSoup(const ObjectContainer &objects,  
     455                                                 PolygonContainer &polys,  
     456                                                 int maxObjects = 0); 
     457 
     458        /** Extracts the meshes of the view cells and and adds them to polygons. 
    433459                Adds view cell aabb to the aabb of the tree. 
    434460                @param maxPolys the maximal number of objects to be stored as polygons 
    435461                @returns the number of polygons 
    436462        */ 
    437         int Copy2PolygonSoup(const ViewCellContainer &viewCells, PolygonContainer &polys, int maxObjects = 0); 
     463        int AddToPolygonSoup(const ViewCellContainer &viewCells,  
     464                                                 PolygonContainer &polys,  
     465                                                 int maxObjects = 0); 
    438466 
    439467        /** Extract polygons of this mesh and add to polygon container. 
     
    491519                                                         vector<SortableEntry> &splitCandidates) const; 
    492520 
     521        /** Splits the rays into front and back rays according to split plane 
     522                @param rays contains the rays to be split. The rays are  
     523                           distributed to front and back rays. 
     524                @param frontRays returns rays on the front side of the plane 
     525                @param backRays returns rays on the back side of the plane 
     526        */ 
     527        void BspTree::SplitRays(const Plane3 plane, 
     528                                                        RayContainer &rays,  
     529                                                        RayContainer &frontRays,  
     530                                                        RayContainer &backRays); 
     531 
    493532        /// Pointer to the root of the tree 
    494533        BspNode *mRoot; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r316 r318  
    249249        VertexContainer::const_iterator vi;   
    250250         
    251         for (vi = poly->mVertices.begin(); vi != poly->mVertices.end(); ++vi)  
    252         { 
    253                 stream << index ++ << " "; 
    254         } 
     251        for (int index = 0; index < (int)poly->mVertices.size(); ++ index)  
     252                stream << index << " "; 
     253         
     254        if (mWireframe) // final line to finish polygon 
     255                stream << "0 "; 
     256 
    255257        stream << "-1" << endl; 
    256  
    257258        stream << "\" >" << endl; 
    258259         
     
    278279void X3dExporter::ExportPolygons(const PolygonContainer &polys) 
    279280{ 
    280         stream << "<Shape>" << endl; 
     281        stream << "<Shape>" << endl; 
    281282        stream << "<Appearance>" << endl; 
    282283   
     
    319320        { 
    320321                Polygon3 *poly = *pit; 
     322                int startIdx = index; 
    321323                for (vi = poly->mVertices.begin(); vi != poly->mVertices.end(); ++vi)  
    322324                { 
    323325                        stream << index ++ << " "; 
    324326                } 
     327 
     328                stream << startIdx << " ";// finish line 
    325329                stream << "-1" << endl; 
    326330        } 
     
    329333         
    330334        stream << "<Coordinate  point=\"" << endl; 
    331         for (pit = polys.begin(); pit != polys.end(); ++pit) 
     335        for (pit = polys.begin(); pit != polys.end(); ++ pit) 
    332336        { 
    333337                Polygon3 *poly = *pit; 
     
    657661 
    658662                        // bounded plane is added to the polygons 
    659                         Polygon3 *planePoly = tree.GetBoundingBox().BoundPlane(*interior->GetPlane()); 
     663                        Polygon3 *planePoly = tree.GetBoundingBox().CrossSection(*interior->GetPlane()); 
    660664                 
    661665                        // do all the splits with the previous planes 
     
    689693                        else 
    690694                        { 
    691                                 Debug << "polygon not valid: " << *planePoly << " size: " << (int)planePoly->mVertices.size() << endl; 
     695                                //Debug << "polygon not valid: " << *planePoly << " size: " << (int)planePoly->mVertices.size() << endl; 
    692696                                DEL_PTR(planePoly); 
    693697                        } 
     
    720724 
    721725                        // bounded plane is added to the polygons 
    722                         polys.push_back(tree.GetBoundingBox().BoundPlane(*interior->GetPlane())); 
     726                        polys.push_back(tree.GetBoundingBox().CrossSection(*interior->GetPlane())); 
    723727                 
    724728                        // push the children on the stack 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.cpp

    r312 r318  
    484484                                ptr = endptr; 
    485485                                 
    486                                 float y = strtod(ptr, &endptr); 
     486                                float y = (float)strtod(ptr, &endptr); 
    487487 
    488488                                 
     
    491491                                ptr = endptr; 
    492492 
    493                                 float z = strtod(ptr, &endptr); 
     493                                float z = (float)strtod(ptr, &endptr); 
    494494 
    495495                                if (ptr == endptr) 
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r315 r318  
    6666                  m.mDiffuseColor = RgbColor(1, 0, 0); 
    6767                  exporter->SetForcedMaterial(m); 
    68                   exporter->SetWireframe(); 
     68                  exporter->SetWireframe();//exporter->SetFilled(); 
    6969                  exporter->ExportBspSplits(*p->mBspTree); 
    7070 
    71                   m.mDiffuseColor = RgbColor(0, 1, 0); 
    72                   exporter->SetForcedMaterial(m); 
     71                  //m.mDiffuseColor = RgbColor(0, 1, 0); 
     72                  //exporter->SetForcedMaterial(m); 
    7373                  exporter->SetFilled(); 
    7474 
     75                  exporter->ResetForcedMaterial(); 
    7576                  exporter->ExportViewCells(p->mViewCells); 
    7677 
  • trunk/VUT/Ogre/src/OgreOcclusionQueriesQueryManager.cpp

    r316 r318  
    77 
    88namespace Ogre { 
    9  
    10 //----------------------------------------------------------------------- 
    11 bool nodeinfo_eq(const GtpVisibility::NodeInfo &a, const GtpVisibility::NodeInfo &b) 
    12 { 
    13         return a.GetSource() == b.GetSource(); 
    14 }  
    15 bool nodeinfo_lt(const GtpVisibility::NodeInfo &a, const GtpVisibility::NodeInfo &b) 
    16 { 
    17         return a.GetSource() < b.GetSource(); 
    18 } 
    19 bool meshinfo_eq(const GtpVisibility::MeshInfo &a, const GtpVisibility::MeshInfo &b) 
    20 { 
    21         return a.GetSource() == b.GetSource(); 
    22 }  
    23 bool meshinfo_lt(const GtpVisibility::MeshInfo &a, const GtpVisibility::MeshInfo &b) 
    24 {        
    25         return a.GetSource() < b.GetSource(); 
    26 } 
    27 bool patchinfo_eq(const GtpVisibility::PatchInfo &a, const GtpVisibility::PatchInfo &b) 
    28 { 
    29         return a.GetSource() == b.GetSource(); 
    30 }  
    31 bool patchinfo_lt(const GtpVisibility::PatchInfo &a, const GtpVisibility::PatchInfo &b) 
    32 { 
    33         return a.GetSource() < b.GetSource(); 
    34 } 
    359 
    3610//-----------------------------------------------------------------------  
     
    408382                                        GtpVisibility::NodeInfoContainer *visibleNodes) 
    409383{ 
    410         sort(visibleNodes->begin(), visibleNodes->end(), nodeinfo_lt); 
     384        stable_sort(visibleNodes->begin(), visibleNodes->end()/*, nodeinfo_lt*/); 
    411385 
    412386        GtpVisibility::NodeInfoContainer::iterator visibleNodesIt, 
     
    429403         
    430404        // physically delete duplicates 
    431         visibleNodes->erase(std::unique(visibleNodes->begin(), visibleNodes->end(), nodeinfo_eq), 
     405        visibleNodes->erase(std::unique(visibleNodes->begin(), visibleNodes->end()), 
    432406                                                visibleNodes->end()); 
    433407} 
     
    436410                                GtpVisibility::MeshInfoContainer *visibleGeometry) 
    437411{ 
    438         sort(visibleGeometry->begin(), visibleGeometry->end(), meshinfo_lt); 
     412        stable_sort(visibleGeometry->begin(), visibleGeometry->end()); 
    439413         
    440414        GtpVisibility::MeshInfoContainer::iterator visibleGeomIt, 
     
    457431 
    458432        // physically delete duplicates 
    459         visibleGeometry->erase(std::unique(visibleGeometry->begin(), visibleGeometry->end(), meshinfo_eq),  
     433        visibleGeometry->erase(std::unique(visibleGeometry->begin(), visibleGeometry->end()),  
    460434                                                   visibleGeometry->end()); 
    461435} 
     
    464438                                GtpVisibility::PatchInfoContainer *visiblePatches) 
    465439{ 
    466         sort(visiblePatches->begin(), visiblePatches->end(), patchinfo_lt); 
     440        stable_sort(visiblePatches->begin(), visiblePatches->end()); 
    467441         
    468442        GtpVisibility::PatchInfoContainer::iterator visiblePatchIt, 
     
    485459 
    486460        // physically delete duplicates 
    487         visiblePatches->erase(std::unique(visiblePatches->begin(), visiblePatches->end(), patchinfo_eq),  
     461        visiblePatches->erase(std::unique(visiblePatches->begin(), visiblePatches->end()),  
    488462                                                  visiblePatches->end()); 
    489463} 
  • trunk/VUT/work/ogre_changes/Plugins/OctreeSceneManager/src/OgreOctreeSceneManager.cpp

    r316 r318  
    10341034 
    10351035#ifdef GTP_VISIBILITY_MODIFIED_OGRE 
    1036         mNumOctreeNodes = 1; 
     1036        mNumOctants = 1; 
    10371037#endif // GTP_VISIBILITY_MODIFIED_OGRE 
    10381038 
Note: See TracChangeset for help on using the changeset viewer.