Changeset 360


Ignore:
Timestamp:
10/28/05 18:13:22 (19 years ago)
Author:
mattausch
Message:

added findneighbours method

Location:
trunk/VUT
Files:
9 edited

Legend:

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

    r349 r360  
    1515class AxisAlignedBox3; 
    1616class Intersectable; 
     17class BspLeaf; 
    1718 
    1819class Exporter 
     
    7071  virtual void  
    7172  ExportBspSplits(const BspTree &tree) = 0; 
     73  virtual void 
     74  ExportLeavesGeometry(const BspTree &tree, const vector<BspLeaf *> &leaves) = 0; 
    7275         
    7376  void SetExportRayDensity(const bool d) { mExportRayDensity = d; } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp

    r349 r360  
    375375        } 
    376376} 
     377 
     378int Polygon3::ClassifyPlane(const PolygonContainer &polys, const Plane3 &plane) 
     379{ 
     380        PolygonContainer::const_iterator it; 
     381 
     382        bool onFrontSide = false; 
     383        bool onBackSide = false; 
     384         
     385        int count = 0; 
     386 
     387        // find possible line-plane intersections 
     388        for (it = polys.begin(); it != polys.end(); ++ it) 
     389        { 
     390        int cf = (*it)->ClassifyPlane(plane); 
     391                 
     392        if (cf == FRONT_SIDE) 
     393                        onFrontSide = true; 
     394                else if (cf == BACK_SIDE) 
     395                        onBackSide = true; 
     396                 
     397                //TODO: check if split goes through vertex 
     398                if ((cf == SPLIT) || (onFrontSide && onBackSide)) // split  
     399                { 
     400                        return SPLIT; 
     401                } 
     402        } 
     403 
     404        if (onBackSide) 
     405        { 
     406                return BACK_SIDE; 
     407        } 
     408        else if (onFrontSide) 
     409        { 
     410                return FRONT_SIDE; 
     411        } 
     412         
     413        return COINCIDENT; // plane and polygon are coincident 
     414} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h

    r349 r360  
    9595        int CastRay(const Ray &ray, float &t, const float nearestT); 
    9696 
     97        /** Classify polygons with respect to the plane. 
     98            @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT 
     99        */ 
     100        static int ClassifyPlane(const PolygonContainer &polys, const Plane3 &plane); 
     101 
    97102        /// vertices are connected in counterclockwise order. 
    98103        VertexContainer mVertices; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r359 r360  
    617617          if (exportSplits) 
    618618                  ExportSplits(objects); 
    619                   
     619         
     620          Exporter *exporter = Exporter::GetExporter("viewCells.x3d"); 
     621 
     622          if (exporter) 
     623          { 
     624          //exporter->ExportLeavesGeometry(mBspTree, leaves);            
     625 
     626                  delete exporter; 
     627          } 
     628 
    620629          for (int j = 0; j < pvsViewCells.size(); ++ j) 
    621630          { 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r353 r360  
    3939 
    4040bool BspTree::sStoreSplitPolys = false; 
     41 
     42int BspNode::mailID = 1; 
    4143 
    4244/** Evaluates split plane classification with respect to the plane's  
     
    492494        { 
    493495                Polygon3 *poly = new Polygon3((*fi), mesh); 
    494                 poly->mParent = parent; // set parent intersectable 
    495                 polys.push_back(poly); 
     496                 
     497                if (poly->Valid()) 
     498                { 
     499                        poly->mParent = parent; // set parent intersectable 
     500                        polys.push_back(poly); 
     501                } 
     502                else 
     503                        DEL_PTR(poly); 
    496504        } 
    497505        return (int)mesh->mFaces.size(); 
     
    512520                { 
    513521                        mBox.Include(viewCells[i]->GetBox()); // add to BSP tree aabb 
    514                         polysSize += AddMeshToPolygons(viewCells[i]->GetMesh(),  
    515                                                                                    polys, viewCells[i]); 
     522                        polysSize += AddMeshToPolygons(viewCells[i]->GetMesh(), polys, viewCells[i]); 
    516523                } 
    517524        } 
     
    16781685        return splits; 
    16791686} 
    1680 /* 
    1681 void BspTree::ExtractSplitPlanes(BspNode *n, vector<Plane *> planes) 
     1687 
     1688void BspTree::ExtractSplitPlanes(BspNode *n, vector<Plane3 *> planes, vector<bool> sides) const 
    16821689{ 
    16831690        while (!n->IsRoot()) 
    16841691        { 
    16851692                if (!n->IsLeaf()) 
    1686                         planes.push_back(dynamic_cast<BspInterior *>(n)->GetPlane(); 
     1693                        planes.push_back(dynamic_cast<BspInterior *>(n)->GetPlane()); 
     1694 
     1695                sides.push_back(n->GetParent()->mFront == n); 
    16871696 
    16881697                n = n->GetParent(); 
     
    16901699} 
    16911700 
    1692 void BspTree::ExtractGeometry(BspNode *n, PolygonContainer &polys) 
    1693 { 
    1694         vector<Plane *> planes; 
    1695         ExtractSplitPlanes(n, planes); 
    1696  
    1697                 while (!tStack.empty()) 
    1698         { 
    1699                 // filter polygons donw the tree 
    1700                 BspSplitData tData = tStack.top(); 
    1701             tStack.pop();        
    1702                  
    1703                 if (!tData.mNode->IsLeaf()) 
    1704                 { 
    1705                         BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode); 
    1706                         if (tData.mNode != tree.GetRoot()) 
    1707                                 tData.mSides.push_back(tData.mIsFront); // add current side 
    1708  
    1709                         // bounded plane is added to the polygons 
    1710                         Polygon3 *planePoly = tree.GetBoundingBox().CrossSection(*interior->GetPlane()); 
    1711                  
    1712                         // do all the splits with the previous planes 
    1713                         for (int i = 0; i < (int)tData.mPlanes.size(); ++i) 
     1701void BspTree::ConstructGeometry(BspNode *n, PolygonContainer &cell) const 
     1702{ 
     1703        stack<BspNode *> tStack; 
     1704 
     1705        vector<Plane3 *> planes; 
     1706        vector<bool> sides; 
     1707 
     1708        ExtractSplitPlanes(n, planes, sides); 
     1709 
     1710        PolygonContainer candidatePolys; 
     1711 
     1712        // bounded plane is added to the polygons 
     1713        for (int i = 0; i < (int)planes.size(); ++ i) 
     1714        { 
     1715                candidatePolys.push_back(GetBoundingBox().CrossSection(*planes[i])); 
     1716        } 
     1717 
     1718        for (int i = 0; i < 6; ++ i) 
     1719        { 
     1720                VertexContainer vertices; 
     1721         
     1722                for (int j = 0; j < 4; ++ j) 
     1723                        vertices.push_back(mBox.GetFace(i).mVertices[j]); 
     1724 
     1725                candidatePolys.push_back(new Polygon3(vertices)); 
     1726        } 
     1727 
     1728        for (int i = 0; i < (int)candidatePolys.size(); ++ i) 
     1729        { 
     1730                bool inside = true; 
     1731 
     1732                // polygon is split with all other planes 
     1733                for (int j = 0; (j < planes.size()) && inside; ++ j) 
     1734                { 
     1735                        Plane3 *plane = planes[j]; 
     1736 
     1737                        if (i == j) // same plane 
     1738                                continue; 
     1739 
     1740                        VertexContainer splitPts; 
     1741                        Polygon3 *frontPoly, *backPoly; 
     1742 
     1743                        int cf = candidatePolys[i]->ClassifyPlane(*plane); 
     1744                         
     1745                        // split new polygon with all previous planes 
     1746                        switch(cf) 
    17141747                        { 
    1715                                 VertexContainer splitPts; 
    1716                                 Polygon3 *frontPoly = new Polygon3(); 
    1717                                 Polygon3 *backPoly = new Polygon3(); 
    1718  
    1719                                 if (planePoly->ClassifyPlane(*tData.mPlanes[i]) == Polygon3::SPLIT) 
    1720                                 { 
    1721                                         planePoly->Split(*tData.mPlanes[i], *frontPoly, *backPoly, splitPts); 
    1722                                         DEL_PTR(planePoly); 
    1723  
    1724                                         if(tData.mSides[i] == true) 
     1748                                case Polygon3::SPLIT: 
     1749                                        frontPoly = new Polygon3(); 
     1750                                        backPoly = new Polygon3(); 
     1751 
     1752                                        candidatePolys[i]->Split(*plane, *frontPoly, *backPoly, splitPts); 
     1753                                        DEL_PTR(candidatePolys[i]); 
     1754 
     1755                                        if(sides[j] == true) 
    17251756                                        { 
    1726                                                 planePoly = frontPoly; 
     1757                                                candidatePolys[i] = frontPoly; 
    17271758                                                DEL_PTR(backPoly); 
    17281759                                        } 
    17291760                                        else 
    17301761                                        { 
    1731                                                 planePoly = backPoly; 
     1762                                                candidatePolys[i] = backPoly; 
    17321763                                                DEL_PTR(frontPoly); 
    17331764                                        } 
    1734                                 } 
     1765                                        break; 
     1766 
     1767                                case Polygon3::BACK_SIDE: 
     1768                                        if (sides[i])  
     1769                                                inside = false; 
     1770                                        break; 
     1771                                case Polygon3::FRONT_SIDE: 
     1772                                        if (!sides[i]) 
     1773                                                inside = false; 
     1774                                        break; 
     1775                                default: 
     1776                                        break; 
    17351777                        } 
    1736  
    1737                         tData.mPlanes.push_back(interior->GetPlane()); // add plane to split planes 
    1738  
    1739                         if (planePoly->Valid()) 
    1740                                 polys.push_back(planePoly); 
    1741                         else 
    1742                         { 
    1743                                 //Debug << "polygon not valid: " << *planePoly << " size: " << (int)planePoly->mVertices.size() << endl; 
    1744                                 DEL_PTR(planePoly); 
    1745                         } 
    1746                         // push the children on the stack 
    1747                         tStack.push(BspSplitData(interior->GetFront(), tData.mPlanes, tData.mSides, true)); 
    1748                         tStack.push(BspSplitData(interior->GetBack(), tData.mPlanes, tData.mSides, false)); 
    1749                 } 
    1750         }        
    1751         ExportPolygons(polys); 
    1752         CLEAR_CONTAINER(polys); 
     1778                } 
     1779                 
     1780                if (inside) 
     1781                        cell.push_back(candidatePolys[i]); 
     1782                else 
     1783                        DEL_PTR(candidatePolys[i]); 
     1784        } 
    17531785} 
    17541786 
    17551787int BspTree::FindNeighbors(BspNode *n, vector<BspNode *> &neighbors, bool onlyUnmailed) 
    17561788{ 
     1789        PolygonContainer cell; 
     1790 
     1791        ConstructGeometry(n, cell); 
     1792 
    17571793        stack<BspNode *> nodeStack; 
    17581794        nodeStack.push(mRoot); 
    1759  
    1760         AxisAlignedBox3 box = GetBox(n); 
    17611795 
    17621796        while (!nodeStack.empty())  
     
    17721806                else  
    17731807                { 
    1774                         KdInterior *interior = (KdInterior *)node; 
    1775                          
    1776                         if (interior->mPosition > box.Max(interior->mAxis)) 
     1808                        BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     1809         
     1810                        const int cf = Polygon3::ClassifyPlane(cell, interior->mPlane); 
     1811 
     1812                        if (cf == Polygon3::FRONT_SIDE) 
    17771813                                nodeStack.push(interior->mBack); 
    17781814                        else 
    1779                                 if (interior->mPosition < box.Min(interior->mAxis)) 
     1815                                if (cf == Polygon3::BACK_SIDE) 
    17801816                                        nodeStack.push(interior->mFront); 
    17811817                                else  
     
    17881824         
    17891825        } 
    1790         return neighbors.size(); 
    1791 }*/ 
     1826        return (int)neighbors.size(); 
     1827} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r359 r360  
    129129        void ProcessPolygons(PolygonContainer *polys, const bool storePolys); 
    130130 
     131        static int mailID; 
     132        int mailbox; 
     133   
     134        void Mail() { mailbox = mailID; } 
     135        static void NewMail() { mailID++; } 
     136        bool Mailed() const { return mailbox == mailID; } 
     137 
    131138//int mViewCellIdx; 
    132139protected: 
     
    356363        BspTreeStatistics &GetStat(); 
    357364 
     365        /** finds neighbouring leaves of this tree node. 
     366        */ 
     367        int FindNeighbors(BspNode *n, vector<BspNode *> &neighbors, bool onlyUnmailed); 
     368 
     369        /** Extracts geometry associated with the split plane leading to this node. 
     370        */ 
     371        void ConstructGeometry(BspNode *n, PolygonContainer &polys) const; 
     372 
    358373protected: 
    359374 
     
    585600                                  RayContainer &backRays); 
    586601 
     602 
     603        /** Extracts the split planes representing the space bounded by node n. 
     604        */ 
     605        void ExtractSplitPlanes(BspNode *n, vector<Plane3 *> planes, vector<bool> sides) const; 
     606 
    587607        /// Pointer to the root of the tree 
    588608        BspNode *mRoot; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r349 r360  
    687687}; 
    688688 
     689void X3dExporter::ExportLeavesGeometry(const BspTree &tree, const vector<BspLeaf *> &leaves) 
     690{ 
     691        vector<BspLeaf *>::const_iterator it, it_end = leaves.end(); 
     692 
     693        for (it = leaves.begin(); it != it_end; ++ it) 
     694        { 
     695                PolygonContainer cell; 
     696                tree.ConstructGeometry(*it, cell); 
     697                 
     698                ExportPolygons(cell); 
     699 
     700                CLEAR_CONTAINER(cell); 
     701        } 
     702} 
     703 
    689704void X3dExporter::ExportBspSplits(const BspTree &tree) 
    690705{ 
     
    705720                { 
    706721                        BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode); 
     722 
    707723                        if (tData.mNode != tree.GetRoot()) 
    708                                 tData.mSides.push_back(tData.mIsFront); // add current side 
     724                                tData.mSides.push_back(tData.mIsFront); // add current side of split plane 
    709725 
    710726                        // bounded plane is added to the polygons 
     
    712728                 
    713729                        // do all the splits with the previous planes 
    714                         for (int i = 0; i < (int)tData.mPlanes.size(); ++i) 
     730                        for (int i = 0; i < (int)tData.mPlanes.size(); ++ i) 
    715731                        { 
    716732                                VertexContainer splitPts; 
    717                                 Polygon3 *frontPoly = new Polygon3(); 
    718                                 Polygon3 *backPoly = new Polygon3(); 
    719  
     733                                 
    720734                                if (planePoly->ClassifyPlane(*tData.mPlanes[i]) == Polygon3::SPLIT) 
    721735                                { 
     736                                        Polygon3 *frontPoly = new Polygon3(); 
     737                                        Polygon3 *backPoly = new Polygon3(); 
     738 
    722739                                        planePoly->Split(*tData.mPlanes[i], *frontPoly, *backPoly, splitPts); 
    723740                                        DEL_PTR(planePoly); 
     
    741758                                polys.push_back(planePoly); 
    742759                        else 
    743                         { 
    744                                 //Debug << "polygon not valid: " << *planePoly << " size: " << (int)planePoly->mVertices.size() << endl; 
    745760                                DEL_PTR(planePoly); 
    746                         } 
     761                         
    747762                        // push the children on the stack 
    748763                        tStack.push(BspSplitData(interior->GetFront(), tData.mPlanes, tData.mSides, true)); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h

    r349 r360  
    7676  ExportBspSplits(const BspTree &tree); 
    7777 
     78  virtual void 
     79  ExportLeavesGeometry(const BspTree &tree, const vector<BspLeaf *> &leaves); 
     80 
    7881  bool 
    7982  ExportRays(const RayContainer &rays, 
Note: See TracChangeset for help on using the changeset viewer.