Changeset 313


Ignore:
Timestamp:
10/10/05 04:19:59 (19 years ago)
Author:
mattausch
Message:

bsp viewcells now work

Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env

    r312 r313  
    5656 
    5757Sampling { 
    58         totalSamples    100000 
     58        totalSamples    200000 
    5959        samplesPerPass  10 
    6060} 
     
    6262ViewCells { 
    6363        hierarchyType bspTree 
    64         height 5.0 
     64        height 7.0 
     65        maxViewCells 20 
    6566        #hierarchyType kdTree 
    6667        #hierarchyType sceneDependent 
    67 #       filename ../data/atlanta/atlanta_viewcells_large.x3d 
    68         filename ../data/vienna/viewcells-25-sel.x3d 
     68        filename ../data/atlanta/atlanta_viewcells_large.x3d 
     69#       filename ../data/vienna/viewcells-25-sel.x3d 
    6970#       filename ../data/vienna/viewcells-25.x3d 
    7071#       filename ../data/vienna/viewcells-large-sel.x3d 
     
    8485        # vertical axis        = 64 
    8586         
    86         splitPlaneStrategy 8 
     87        splitPlaneStrategy 66 
    8788        # least splits + balanced polygons 
    8889        #splitPlaneStrategy 12 
     
    101102         
    102103        maxCandidates 50 
    103         maxViewCells 999999 
     104         
    104105        Termination { 
    105106                maxPolysForAxisAligned 100 
  • trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp

    r312 r313  
    16461646  return Rectangle3(v[0], v[1], v[2], v[3]); 
    16471647} 
     1648 
     1649// TODO: use a table to avoid normal and distance computations 
     1650Polygon3 *AxisAlignedBox3::BoundPlane(const Plane3 &plane) 
     1651{ 
     1652        Vector3 ptA, ptB; 
     1653        int sideA = 0, sideB = 0; 
     1654 
     1655        VertexContainer vertices; 
     1656 
     1657        int side[8]; 
     1658 
     1659        bool onFrontSide, onBackSide = false; 
     1660 
     1661        Vector3 vtx; 
     1662        for (int i = 0; i < 8; ++i) 
     1663        { 
     1664                GetVertex(i, vtx); 
     1665                side[i] = plane.Side(vtx, SIDE_TOLERANCE); 
     1666                if (side[i] > 0) 
     1667                        onFrontSide = true; 
     1668                else if (side[i] < 0) 
     1669                        onBackSide = true; 
     1670                else // vertex coincident => push_back 
     1671                        vertices.push_back(vtx); 
     1672        } 
     1673 
     1674        // does not intersect 
     1675        if (!onFrontSide && !onBackSide) 
     1676                return NULL; 
     1677 
     1678        for (int i = 0; i < 12; ++ i) 
     1679        { 
     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) 
     1698                { 
     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; 
     1716                } 
     1717        } 
     1718 
     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 
     1731        { 
     1732                for (int i = (int)vertices.size() - 1; i >= 0; -- i) 
     1733                        planePoly->mVertices.push_back(vertices[i]); 
     1734        } 
     1735 
     1736        //Debug << *planePoly << "\narea: " << planePoly->GetArea() << endl; 
     1737         
     1738        return planePoly; 
     1739} 
    16481740/* 
    16491741const int AxisAlignedBox3::complEdgeTbl[12][3] = 
     
    16631755}; 
    16641756*/ 
    1665 // TODO: use a table to avoid normal and distance computations 
    1666 Polygon3 *AxisAlignedBox3::BoundPlane(const Plane3 &plane) 
    1667 { 
    1668         Vector3 ptA, ptB; 
    1669         int sideA = 0, sideB = 0; 
    1670  
    1671         VertexContainer vertices; 
    1672  
    1673         int side[8]; 
    1674  
    1675         bool onFrontSide, onBackSide = false; 
    1676  
    1677         Vector3 vtx; 
    1678         for (int i = 0; i < 8; ++i) 
    1679         { 
    1680                 GetVertex(i, vtx); 
    1681                 side[i] = plane.Side(vtx, SIDE_TOLERANCE); 
    1682                 if (side[i] > 0) 
    1683                         onFrontSide = true; 
    1684                 else if (side[i] < 0) 
    1685                         onBackSide = true; 
    1686                 else // vertex coincident => push_back 
    1687                         vertices.push_back(vtx); 
    1688         } 
    1689  
    1690         // does not intersect 
    1691         if (!onFrontSide && !onBackSide) 
    1692                 return NULL; 
    1693  
    1694         for (int i = 0; i < 12; ++ i) 
    1695         { 
    1696                 int aIdx, bIdx; 
    1697                 GetEdge(i, aIdx, bIdx); 
    1698  
    1699                 ptA = GetVertex(aIdx); 
    1700                 ptB = GetVertex(bIdx); 
    1701  
    1702                 int sideA = side[aIdx]; 
    1703                 int sideB = side[bIdx]; 
    1704  
    1705                 if (((sideA > 0) && (sideB < 0)) || (sideA < 0) && (sideB > 0)) 
    1706                         vertices.push_back(plane.FindIntersection(ptA, ptB));    
    1707         } 
    1708  
    1709         if (vertices.size() == 4) 
    1710         { 
    1711                 float maxDist = 0; 
    1712                 int maxIdx = 0; 
    1713  
    1714                 for (int i = 1; i < 4; ++ i) 
    1715                 { 
    1716                         float dist = SqrDistance(vertices[0], vertices[i]); 
    1717                         if (dist > maxDist) 
    1718                         { 
    1719                                 maxDist = dist; 
    1720                                 maxIdx = i; 
    1721                         } 
    1722                 } 
    1723                 // illformed polygon = swap 
    1724                 if ((maxIdx == 1) || (maxIdx == 3) ) 
    1725                 { 
    1726                         Vector3 vtx = vertices[maxIdx]; 
    1727                         vertices[maxIdx] = vertices[2]; 
    1728                         vertices[2] = vtx; 
    1729                 } 
    1730         } 
    1731  
    1732         // wrong surface orientation? 
    1733     Vector3 norm = Normalize(CrossProd(vertices[0] - vertices[1], 
    1734                                                                            vertices[2] - vertices[1])); 
    1735  
    1736         Polygon3 *planePoly = new Polygon3(); 
    1737  
    1738         if (DotProd(norm, plane.mNormal) > 0) 
    1739                 for (int i = 0; i < (int)vertices.size(); ++ i) 
    1740                         planePoly->mVertices.push_back(vertices[i]); 
    1741         else 
    1742         { 
    1743                 for (int i = (int)vertices.size() - 1; i >= 0; -- i) 
    1744                         planePoly->mVertices.push_back(vertices[i]); 
    1745         } 
    1746  
    1747         //Debug << *planePoly << "\narea: " << planePoly->GetArea() << endl; 
    1748          
    1749         return planePoly; 
    1750 } 
     1757 
     1758/* 
     1759inline void addEdge(int idx, int ptAIdx, int ptBIdx) 
     1760{ 
     1761        edgeTable[idx].push_back(edge(ptAIdx, ptBIdx)); 
     1762} 
     1763int 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/Environment.cpp

    r312 r313  
    11951195          "20"); 
    11961196 
    1197   RegisterOption("BspTree.maxViewCells", 
     1197  RegisterOption("ViewCells.maxViewCells", 
    11981198          optInt, 
    1199           "-bsp_max_viewcells=", 
    1200           "999999"); 
     1199          "-view_cells_max_viewcells=", 
     1200          "0"); 
    12011201} 
    12021202 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h

    r312 r313  
    5555 
    5656  virtual void  
    57   ExportViewCells(ViewCellContainer *viewCells) = 0; 
     57  ExportViewCells(const ViewCellContainer &viewCells) = 0; 
    5858  virtual void  
    5959  ExportViewCell(ViewCell *viewCell) = 0; 
     
    6161  ExportIntersectable(Intersectable *object) = 0; 
    6262 
    63   virtual void ExportBspSplits(const BspTree &tree) = 0; 
    64  
     63  virtual void  
     64  ExportBspSplitPlanes(const BspTree &tree) = 0; 
     65  virtual void  
     66  ExportBspSplits(const BspTree &tree) = 0; 
     67         
    6568  void SetExportRayDensity(const bool d) { mExportRayDensity = d; } 
    6669   
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp

    r312 r313  
    2828{ 
    2929        X3dParser parser; 
     30        int maxViewCells = 0; 
    3031        environment->GetFloatValue("ViewCells.height", parser.mViewCellHeight); 
    31           
    32         return parser.ParseFile(filename, mViewCells); 
     32        environment->GetIntValue("ViewCells.maxViewCells", maxViewCells); 
     33 
     34        bool loaded = parser.ParseFile(filename, mViewCells); 
     35 
     36        if (maxViewCells > 0) 
     37        { 
     38                while (mViewCells.size() > maxViewCells) 
     39                { 
     40                        ViewCell *vc = mViewCells.back(); 
     41                        DEL_PTR(vc); 
     42                        mViewCells.pop_back(); 
     43                } 
     44        } 
     45        return loaded; 
    3346} 
    3447 
     
    8497 
    8598        int maxViewCells = 0; 
    86         environment->GetIntValue("BspTree.maxViewCells", maxViewCells); 
     99        environment->GetIntValue("ViewCells.maxViewCells", maxViewCells); 
    87100 
    88101        mSceneGraph->CollectObjects(&objects); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r312 r313  
    6767  
    6868        // add object to view cell 
    69         for (j=0; j < ray.viewCells.size(); j++)  
     69        for (j=0; j < ray.viewCells.size(); ++ j)  
    7070        {  
    7171                ViewCell *vc = ray.viewCells[j]; 
     72 
     73                for (int i = 0; i < 5; ++ i) 
     74                        if (vc == mViewCells[i]) 
     75                                Debug << "adding sample to vc " << i << endl; 
    7276                contributingSamples += vc->GetPvs().AddSample(obj); 
    7377        } 
    7478  
    7579        if (mPass > 1) 
    76                 for (j=1; j < ((int)ray.viewCells.size() - 1); j++)  
     80                for (j=1; j < ((int)ray.viewCells.size() - 1); ++ j)  
    7781                { 
    7882            ray.viewCells[j]->AddPassingRay(ray, contributingSamples ? 1 : 0); 
     
    112116                sampleContributions += AddObjectSamples(object, ray); 
    113117                                 
    114                 if (ray.intersections.size() > 0) // view cell found 
     118                if (ray.intersections.size() > 0) // second intersection found 
    115119                { 
    116120                        sampleContributions +=  
     
    230234 
    231235  int pvsOut = Min((int)objects.size(), 10); 
    232    
     236  int vcPvsOut = Min((int)mViewCells.size(), 5); 
     237 
    233238  vector<Ray> rays[10]; 
    234    
     239  vector<Ray> vcRays[5]; 
     240 
    235241  while (totalSamples < mTotalSamples) { 
    236242                int passContributingSamples = 0; 
     
    330336                                        sampleContributions = CastRay(object, ray); 
    331337                                         
     338                                        if (mViewCellsType == BSP_VIEW_CELLS)  
     339                                        { 
     340                                                // check whether we can add this to the rays 
     341                                                for (int k = 0; k < ray.viewCells.size(); ++ k) 
     342                                                        for (int j = 0; j < vcPvsOut; ++ j)  
     343                                                                if (mViewCells[j] == ray.viewCells[k])  
     344                                                                { 
     345                                                                        Debug << "Pushing back ray" << endl; 
     346                                                                        vcRays[j].push_back(ray); 
     347                                                                } 
     348                                        } 
    332349                                } 
    333350                        } else { 
     
    350367                                } 
    351368                        } 
    352                  
     369                         
    353370                        passSamples++; 
    354371                         
     
    369386                int pvsSize = 0; 
    370387         
    371                 if (mViewCellsType == BSP_VIEW_CELLS) 
    372                 { 
     388                if (mViewCellsType == BSP_VIEW_CELLS) { 
    373389                        for (i=0; i < mViewCells.size(); i++) { 
    374390                                ViewCell *vc = mViewCells[i]; 
    375391                                pvsSize += vc->GetPvs().GetSize(); 
    376392                        } 
    377                 } else 
    378                 { 
     393                } else  { 
    379394                        for (i=0; i < objects.size(); i++) { 
    380395                                Intersectable *object = objects[i]; 
     
    435450      if (mViewCellsType == BSP_VIEW_CELLS) 
    436451          { 
    437                    int limit = Min((int)mViewCells.size(), 1); 
    438  
    439                    //char s[64]; sprintf(s, "bsp-pvs%04d.x3d", k); 
    440                    Exporter *exporter = Exporter::GetExporter("bsp-pvs.x3d"); 
    441                    exporter->SetFilled(); 
    442  
    443                    Intersectable::NewMail(); 
    444  
    445                    for (int j = 0; j < limit; ++ j) 
    446                    {                    
    447                            // j random view cells 
    448                            int k = Random((int)mViewCells.size()); 
    449  
    450                            Debug << "next vc: " << k << endl; 
    451                            ViewCellPvsMap::iterator it = mViewCells[k]->GetPvs().mEntries.begin(); 
     452                   for (int j = 0; j < vcPvsOut; ++ j) 
     453                   { 
     454                           ViewCell *vc = mViewCells[j]; 
     455 
     456                           Intersectable::NewMail(); 
     457     
     458                           char s[64]; sprintf(s, "bsp-pvs%04d.x3d", j); 
     459                           Exporter *exporter = Exporter::GetExporter(s); 
     460                           exporter->SetFilled(); 
     461 
     462                           ViewCellPvsMap::iterator it = vc->GetPvs().mEntries.begin(); 
    452463 
    453464                           Material m;//= RandomMaterial(); 
     
    455466                           exporter->SetForcedMaterial(m); 
    456467 
    457                            exporter->ExportViewCell(mViewCells[k]); 
     468                           exporter->ExportViewCell(vc); 
     469 
     470                           Debug << "pvs size: " << (int)vc->GetPvs().GetSize() << " of " << objects.size(); 
     471                           Debug << " exporting rays: " << (int)vcRays[j].size() << endl; 
     472 
     473                           exporter->SetWireframe(); 
     474                            
     475                           m.mDiffuseColor = RgbColor(1, 0, 1); 
     476                           exporter->SetForcedMaterial(m); 
     477 
     478                           exporter->ExportBspTree(*mBspTree); 
     479                           exporter->ExportRays(vcRays[j], 1000, RgbColor(0, 1, 0)); 
    458480 
    459481                           m.mDiffuseColor = RgbColor(1, 0, 0); 
    460482                           exporter->SetForcedMaterial(m); 
    461483 
    462                            Debug << "pvs size: " << mViewCells[k]->GetPvs().GetSize() << " of " << objects.size() << endl; 
    463  
    464                            for (; it != mViewCells[k]->GetPvs().mEntries.end(); ++ it)  
     484                           // output pvs of view cell 
     485                           for (; it != vc->GetPvs().mEntries.end(); ++ it)  
    465486                           { 
    466487                                   Intersectable *intersect = (*it).first; 
     
    469490                                           exporter->ExportIntersectable(intersect); 
    470491                                           intersect->Mail(); 
    471                                    } 
    472                             
     492                                   }                     
    473493                           } 
     494 
     495                           // output rest of the objects 
     496                           if (1) 
     497                           { 
     498                                   Material m;//= RandomMaterial(); 
     499                                   m.mDiffuseColor = RgbColor(0, 0, 1); 
     500                                   exporter->SetForcedMaterial(m); 
     501                  
     502                                   for (int j = 0; j < objects.size(); ++ j) 
     503                                           if (!objects[j]->Mailed()) 
     504                                           { 
     505                                                   exporter->ExportIntersectable(objects[j]); 
     506                                                   objects[j]->Mail(); 
     507                                           } 
     508                           } 
     509                           DEL_PTR(exporter); 
    474510                   } 
    475                          
    476                    // output rest of the objects 
    477                    Material m;//= RandomMaterial(); 
    478                    m.mDiffuseColor = RgbColor(0, 0, 1); 
    479                    exporter->SetForcedMaterial(m); 
    480  
    481                    for (int j = 0; j < objects.size(); ++ j) 
    482                            if (!objects[j]->Mailed()) 
    483                            { 
    484                                    exporter->ExportIntersectable(objects[j]); 
    485                                    objects[j]->Mail(); 
    486                            } 
    487  
    488                    DEL_PTR(exporter); 
    489511          }        
    490512 
     
    529551  return true; 
    530552} 
    531  
    532    
    533  
    534      
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp

    r312 r313  
    6969        // add base vertices and calculate top vertices 
    7070        for (int i = 0; i < 3; ++i) 
    71                  mesh->mVertices.push_back(baseTri.mVertices[i] + height * 0.5 * triNorm); 
     71                 mesh->mVertices.push_back(baseTri.mVertices[i]); 
    7272         
    7373        // add top vertices      
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r312 r313  
    261261BspTree::BspTree(ViewCell *viewCell):  
    262262mRoot(NULL),  
    263 mViewCell(viewCell), 
     263mRootCell(viewCell), 
    264264//mStoreSplitPolys(true) 
    265265mStoreSplitPolys(false) 
     
    380380        BspNode *firstNode = mRoot ? mRoot : new BspLeaf(); 
    381381 
    382         tStack.push(BspTraversalData(firstNode, polys, 0, mViewCell)); 
     382        tStack.push(BspTraversalData(firstNode, polys, 0, mRootCell)); 
    383383 
    384384        while (!tStack.empty()) 
     
    410410                                 
    411411                                // extract view cells associated with the split polygons 
    412                                 ViewCell *frontViewCell = mViewCell; 
    413                                 ViewCell *backViewCell = mViewCell; 
     412                                ViewCell *frontViewCell = mRootCell; 
     413                                ViewCell *backViewCell = mRootCell; 
    414414         
    415415                                if (!viewCells) 
     
    517517                { 
    518518                        mBox.Include(object->GetBox()); // add to BSP tree aabb 
    519                         AddMeshToPolygons(mesh, polys, mViewCell); 
     519                        AddMeshToPolygons(mesh, polys, mRootCell); 
    520520                } 
    521521        } 
     
    561561        std::stack<BspTraversalData> tStack; 
    562562         
    563         BspTraversalData tData(new BspLeaf(), polys, 0, mViewCell); 
     563        BspTraversalData tData(new BspLeaf(), polys, 0, mRootCell); 
    564564        tStack.push(tData); 
    565565 
     
    601601                          << (int)tData.mPolygons->size() << endl; 
    602602#endif 
    603  
    604603                EvaluateLeafStats(tData); 
    605  
    606604                BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode); 
     605 
     606                // add view cell to leaf 
     607                leaf->SetViewCell(tData.mViewCell); 
    607608                 
    608                 // add view cell to leaf 
    609                 if (!leaf->GetViewCell()) 
    610                         leaf->SetViewCell(tData.mViewCell); 
    611  
    612609                // remaining polygons are discarded or added to node 
    613610                leaf->ProcessPolygons(tData.mPolygons, mStoreSplitPolys); 
     
    629626                                                                                  &coincident); 
    630627 
    631         ViewCell *frontViewCell = mViewCell; 
    632         ViewCell *backViewCell = mViewCell; 
     628        ViewCell *frontViewCell = mRootCell; 
     629        ViewCell *backViewCell = mRootCell; 
    633630 
    634631#ifdef _DEBUG    
     
    639636#endif 
    640637 
    641         //-- extract view cells from coincident polygons according to plane normal 
    642         ExtractViewCells(&backViewCell, &frontViewCell, coincident, interior->mPlane,  
    643                                                  frontPolys->empty(), backPolys->empty()); 
     638        // extract view cells from coincident polygons according to plane normal 
     639    // only if front or back polygons are empty 
     640        ExtractViewCells(&backViewCell,  
     641                                         &frontViewCell,  
     642                                         coincident,  
     643                                         interior->mPlane,  
     644                                         backPolys->empty(), 
     645                                         frontPolys->empty()); 
    644646         
    645647        // don't need coincident polygons anymore 
     
    647649 
    648650        // push the children on the stack 
    649         // split polygon is only needed in the back leaf 
     651        tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, backViewCell)); 
    650652        tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1, frontViewCell)); 
    651         tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, backViewCell)); 
    652653 
    653654        // cleanup 
     
    662663                                                           const PolygonContainer &coincident, 
    663664                                                           const Plane3 splitPlane,  
    664                                                            const bool extractFront,  
    665                                                            const bool extractBack) const 
     665                                                           const bool extractBack, 
     666                                                           const bool extractFront) const 
    666667{ 
    667668        bool foundFront = !extractFront, foundBack = !extractBack; 
     
    673674                (it != it_end); ++ it) 
    674675        { 
    675                 if (DotProd((*it)->GetSupportingPlane().mNormal, splitPlane.mNormal > 0)) 
     676                if (DotProd((*it)->GetSupportingPlane().mNormal, splitPlane.mNormal) > 0) 
    676677                { 
    677678                        *backViewCell = dynamic_cast<ViewCell *>((*it)->mParent); 
     
    11781179        // test with tree bounding box 
    11791180        if (!mBox.GetMinMaxT(ray, &mint, &maxt)) 
    1180         { 
    11811181                return 0; 
    1182         } 
    1183  
    1184         if (mint < 0) 
     1182 
     1183        if (mint < 0) // start ray from origin 
    11851184                mint = 0; 
    1186    
    1187         maxt += Limits::Threshold; 
     1185 
     1186        // bound ray 
     1187        if ((ray.GetType() == Ray::LOCAL_RAY)   &&  
     1188                ((int)ray.intersections.size() > 0) && 
     1189            (ray.intersections[0].mT <= maxt)) 
     1190        { 
     1191                maxt = ray.intersections[0].mT; 
     1192    } 
    11881193   
    11891194        Vector3 entp = ray.Extrap(mint); 
     
    11911196   
    11921197        BspNode *node = mRoot; 
    1193         BspNode *farChild; 
     1198        BspNode *farChild = NULL; 
    11941199         
    11951200        while (1) 
     
    12131218                                node = in->GetBack(); 
    12141219 
    1215                                 if(extSide <= 0)  
     1220                                if(extSide <= 0) // plane does not split ray => no far child 
    12161221                                        continue; 
    12171222                                         
     
    12221227                                node = in->GetFront(); 
    12231228 
    1224                                 if (extSide >= 0) 
     1229                                if (extSide >= 0) // plane does not split ray => no far child 
    12251230                                        continue; 
    12261231 
    1227                                 farChild = in->GetBack();        // plane splits ray                     
     1232                                farChild = in->GetBack(); // plane splits ray                    
    12281233                        } 
    12291234                        else // ray and plane are coincident // WHAT TO DO IN THIS CASE ? 
     
    12361241                        tStack.push(BspRayTraversalData(farChild, extp, maxt)); 
    12371242 
    1238                         // find intersection with plane between ray origin and exit point 
     1243                        // find intersection of ray segment with plane 
    12391244                        extp = splitPlane->FindIntersection(ray.GetLoc(), extp, &maxt); 
     1245                         
    12401246                } else // reached leaf => intersection with view cell 
    12411247                { 
    12421248                        BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
    1243                          
    1244                         //ray.mBspLeaves.push_back(leaf); 
    1245                         //Debug << "adding view cell" << leaf->mViewCell; 
     1249       
    12461250                        if (!leaf->mViewCell->Mailed()) 
    12471251                        { 
    12481252                                ray.viewCells.push_back(leaf->mViewCell); 
    1249                                 mViewCell->Mail(); 
     1253                                leaf->mViewCell->Mail(); 
    12501254                                ++ hits; 
    12511255                        } 
    1252                         //Debug << "view cell added" << endl; 
    1253                         // get the next node from the stack 
     1256                         
     1257                        //-- fetch the next far child from the stack 
    12541258                        if (tStack.empty()) 
    12551259                                break; 
    12561260       
    12571261                        entp = extp; 
    1258                         mint = maxt; 
    1259                         BspRayTraversalData &s  = tStack.top(); 
     1262                        mint = maxt; // NOTE: need this? 
     1263                        BspRayTraversalData &s = tStack.top(); 
    12601264 
    12611265                        node = s.mNode; 
    12621266                        extp = s.mExitPoint; 
    12631267                        maxt = s.mMaxT; 
     1268 
     1269                        //Debug << "leaf: new entrypt: " << entp << " new extp: " << extp << endl; 
    12641270 
    12651271                        tStack.pop(); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r312 r313  
    3030    BspRayTraversalData() {} 
    3131 
    32     BspRayTraversalData(BspNode *n, const Vector3 &p, const float maxt): 
    33     mNode(n), mExitPoint(p), mMaxT(maxt)  
     32    BspRayTraversalData(BspNode *n, const Vector3 &extp, const float maxt): 
     33    mNode(n), mExitPoint(extp), mMaxT(maxt)  
    3434        {} 
    3535}; 
     
    239239protected: 
    240240 
    241         /// polygonal representation of this viewcell 
    242         /// if NULL this note does not correspond to feasible viewcell 
     241        /// if NULL this does not correspond to feasible viewcell 
    243242        ViewCell *mViewCell; 
    244243}; 
     
    457456                @param coincident container of polygons coincident to the split plane 
    458457                @param splitPlane the split plane which decides about back and front 
     458                @param extractBack if a back view cell is extracted 
    459459                @param extractFront if a front view cell is extracted 
    460                 @param extractBack if a back view cell is extracted 
    461460        */ 
    462461        void ExtractViewCells(ViewCell **backViewCell,  
     
    464463                                                  const PolygonContainer &coincident, 
    465464                                                  const Plane3 splitPlane,  
    466                                                   const bool extractFront,  
    467                                                   const bool extractBack) const; 
     465                                                  const bool extractBack, 
     466                                                  const bool extractFront) const; 
    468467         
    469468        /** Computes best cost ratio for the suface area heuristics for axis aligned 
     
    518517 
    519518        /// view cell corresponding to unbounded space 
    520         ViewCell *mViewCell; 
     519        ViewCell *mRootCell; 
    521520 
    522521public: 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r312 r313  
    120120} 
    121121 
    122 void X3dExporter::ExportViewCells(ViewCellContainer *viewCells) 
    123 { 
    124         ViewCellContainer::iterator it, it_end = viewCells->end(); 
    125  
    126         for (it = viewCells->begin(); it != it_end; ++it) 
     122void  
     123X3dExporter::ExportViewCells(const ViewCellContainer &viewCells) 
     124{ 
     125        ViewCellContainer::const_iterator it, it_end = viewCells.end(); 
     126 
     127        for (it = viewCells.begin(); it != it_end; ++ it) 
    127128                ExportViewCell(*it); 
    128129} 
     130 
    129131void 
    130132X3dExporter::ExportViewCell(ViewCell *viewCell) 
     
    274276} 
    275277 
    276 void X3dExporter::ExportPolygons(PolygonContainer *polys) 
     278void X3dExporter::ExportPolygons(const PolygonContainer &polys) 
    277279{ 
    278280        stream << "<Shape>" << endl; 
     
    314316    VertexContainer::const_iterator vi;   
    315317         
    316         for (pit = polys->begin(); pit != polys->end(); ++pit) 
     318        for (pit = polys.begin(); pit != polys.end(); ++pit) 
    317319        { 
    318320                Polygon3 *poly = *pit; 
     
    327329         
    328330        stream << "<Coordinate  point=\"" << endl; 
    329         for (pit = polys->begin(); pit != polys->end(); ++pit) 
     331        for (pit = polys.begin(); pit != polys.end(); ++pit) 
    330332        { 
    331333                Polygon3 *poly = *pit; 
     
    453455                ViewCellContainer::iterator new_end = unique(foundViewCells.begin(), foundViewCells.end()); 
    454456                foundViewCells.erase(new_end, foundViewCells.end()); 
    455                 ExportViewCells(&foundViewCells); 
     457                ExportViewCells(foundViewCells); 
    456458 
    457459                Debug << "Number of view cells after erasing dublicates: " << (int)foundViewCells.size() << endl; 
     
    533535                        if (vc->mPassingRays.mRays)  
    534536                        { 
    535                                 float importance = vc->mPassingRays.mContributions/(float)vc->mPassingRays.mRays; 
     537                                float importance =  
     538                                        vc->mPassingRays.mContributions / (float)vc->mPassingRays.mRays; 
    536539 
    537540                                mForcedMaterial.mDiffuseColor.r = importance; 
     
    616619        BspNode *mNode; 
    617620 
    618         PolygonContainer *mPolygons; 
    619621        vector<Plane3 *> mPlanes; 
    620622        vector<bool> mSides; 
    621623        bool mIsFront; 
    622624 
    623         BspSplitData(BspNode *node, PolygonContainer *polys):  
    624         mNode(node), mPolygons(polys), mIsFront(false) 
     625        BspSplitData(BspNode *node):  
     626        mNode(node), mIsFront(false) 
    625627        {};      
    626628        BspSplitData(BspNode *node,  
    627                                  PolygonContainer *polys,  
    628629                                 vector<Plane3 *> planes,  
    629630                                 vector<bool> sides,  
    630631                                 bool isFront):  
    631         mNode(node), mPolygons(polys), mPlanes(planes),  
     632        mNode(node), mPlanes(planes),  
    632633        mSides(sides), mIsFront(isFront) 
    633634        {}; 
     
    636637void X3dExporter::ExportBspSplits(const BspTree &tree) 
    637638{ 
    638         int mask = Random(50000); 
    639          
    640639        std::stack<BspSplitData> tStack; 
    641640 
    642         BspSplitData tData(tree.GetRoot(), new PolygonContainer()); 
     641        BspSplitData tData(tree.GetRoot()); 
    643642        tStack.push(tData); 
    644643   
     644        PolygonContainer polys; 
     645 
    645646        while (!tStack.empty()) 
    646647        { 
     
    652653                { 
    653654                        BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode); 
    654  
    655                         tData.mPlanes.push_back(interior->GetPlane()); 
    656                         tData.mSides.push_back(tData.mIsFront); 
     655                        if (tData.mNode != tree.GetRoot()) 
     656                                tData.mSides.push_back(tData.mIsFront); // add current side 
    657657 
    658658                        // bounded plane is added to the polygons 
    659                         Polygon3 *planePoly = tree.GetBoundingBox().BoundPlane(*tData.mPlanes.back()); 
     659                        Polygon3 *planePoly = tree.GetBoundingBox().BoundPlane(*interior->GetPlane()); 
    660660                 
    661                         PolygonContainer *frontPolys = new PolygonContainer(); 
    662                         PolygonContainer *backPolys = new PolygonContainer(); 
    663                         PolygonContainer coincident; 
    664  
    665                         int splits = 0; 
    666                  
    667                         // split polygons with respect to split plane 
    668                         interior->SplitPolygons(tData.mPolygons,  
    669                                                                         frontPolys,  
    670                                                                         backPolys, 
    671                                                                         &coincident, 
    672                                                                         splits,  
    673                                                                         false); 
    674  
    675661                        // do all the splits with the previous planes 
    676662                        for (int i = 0; i < (int)tData.mPlanes.size(); ++i) 
     
    692678                                        else 
    693679                                        { 
    694                                                 Debug << "take backpoly" << endl; 
    695680                                                planePoly = backPoly; 
    696681                                                DEL_PTR(frontPoly); 
     
    699684                        } 
    700685 
    701                         PolygonContainer *polys; 
    702                         BspNode *next; 
    703                         bool side = false; 
    704  
    705                         // random decision 
    706                         if (mask & 1) 
    707                         { 
    708                                 next = interior->GetBack(); 
    709                                 polys = backPolys; 
    710                                 CLEAR_CONTAINER(*frontPolys); 
    711                                 DEL_PTR(frontPolys); 
    712                                 side = false; 
    713                         } 
     686                        tData.mPlanes.push_back(interior->GetPlane()); // add plane to split planes 
     687                        if (planePoly->Valid()) 
     688                                polys.push_back(planePoly); 
    714689                        else 
    715690                        { 
    716                                 next = interior->GetFront(); 
    717                                 polys = frontPolys; 
    718                                  
    719                                 CLEAR_CONTAINER(*backPolys); 
    720                                 DEL_PTR(backPolys); 
    721                                 side = true; 
     691                                Debug << "polygon not valid: " << *planePoly << " size: " << planePoly->mVertices.size() << endl; 
     692                                DEL_PTR(planePoly); 
    722693                        } 
    723  
    724                         mask = mask >> 1; 
    725                         polys->push_back(planePoly); 
    726  
    727694                        // push the children on the stack 
    728                         tStack.push(BspSplitData(next, polys, tData.mPlanes,  
    729                                                                          tData.mSides, side)); 
    730                         //tStack.push(BspSplitData(interior->GetBack(), backPolys,  
    731                         //                                               tData.mPlanes, tData.mSides, false)); 
    732  
    733                         // clean up 
    734                         CLEAR_CONTAINER(coincident); // NOTE: should contain nothing 
    735                         CLEAR_CONTAINER(*tData.mPolygons); 
    736                         DEL_PTR(tData.mPolygons); 
     695                        tStack.push(BspSplitData(interior->GetFront(), tData.mPlanes, tData.mSides, true)); 
     696                        tStack.push(BspSplitData(interior->GetBack(), tData.mPlanes, tData.mSides, false)); 
    737697                } 
    738                 else // reached leaf 
     698        }        
     699        ExportPolygons(polys); 
     700        CLEAR_CONTAINER(polys); 
     701} 
     702 
     703void X3dExporter::ExportBspSplitPlanes(const BspTree &tree) 
     704{ 
     705        std::stack<BspNode *> tStack; 
     706 
     707        tStack.push(tree.GetRoot()); 
     708   
     709        PolygonContainer polys; 
     710 
     711        while (!tStack.empty()) 
     712        { 
     713                // filter polygons donw the tree 
     714                BspNode *node = tStack.top(); 
     715            tStack.pop();        
     716                 
     717                if (!node->IsLeaf()) 
    739718                { 
    740                         //Debug << "\nsplits: " << endl; 
    741                         //for (int i = 0; i < (int)tData.mSides.size(); ++ i)Debug << " " << tData.mSides[i]; 
    742                         ExportPolygons(tData.mPolygons); 
    743                          
    744                         // clean up 
    745                         CLEAR_CONTAINER(*tData.mPolygons); 
    746                         DEL_PTR(tData.mPolygons); 
     719                        BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     720 
     721                        // bounded plane is added to the polygons 
     722                        polys.push_back(tree.GetBoundingBox().BoundPlane(*interior->GetPlane())); 
     723                 
     724                        // push the children on the stack 
     725                        tStack.push(interior->GetBack()); 
     726                        tStack.push(interior->GetFront()); 
    747727                } 
    748728        } 
    749 } 
     729 
     730        ExportPolygons(polys); 
     731        CLEAR_CONTAINER(polys); 
     732} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h

    r312 r313  
    5050  ExportPolygon(Polygon3 *poly); 
    5151 
    52   virtual void ExportPolygons(PolygonContainer *polys); 
     52  virtual void ExportPolygons(const PolygonContainer &polys); 
    5353 
    5454  virtual bool 
     
    6868 
    6969  virtual void  
    70   ExportViewCells(ViewCellContainer *viewCells); 
     70  ExportViewCells(const ViewCellContainer &viewCells); 
    7171 
    72   virtual void ExportBspSplits(const BspTree &tree); 
     72  virtual void  
     73  ExportBspSplitPlanes(const BspTree &tree); 
     74   
     75  virtual void  
     76  ExportBspSplits(const BspTree &tree); 
    7377 
    7478  static ViewCellContainer foundViewCells; // todo: remove this 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dParserXerces.h

    r312 r313  
    114114  //  Constructors and Destructor 
    115115  // ----------------------------------------------------------------------- 
    116   X3dViewCellsParseHandlers(ViewCellContainer *mViewCells, float viewCellHeight); 
     116  X3dViewCellsParseHandlers(ViewCellContainer *mViewCells,  
     117                                                        float viewCellHeight); 
    117118  ~X3dViewCellsParseHandlers(); 
    118119   
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r312 r313  
    6363          if (exporter)  
    6464          {      
    65                   Debug << "Exporting bsp splits" << endl; 
     65          Debug << "Exporting bsp splits" << endl; 
     66                  Material m;  
     67                  m.mDiffuseColor = RgbColor(1, 0, 0); 
     68                  exporter->SetForcedMaterial(m); 
     69                  exporter->SetWireframe(); 
    6670                  exporter->ExportBspSplits(*p->mBspTree); 
     71 
     72                  m.mDiffuseColor = RgbColor(0, 1, 0); 
     73                  exporter->SetForcedMaterial(m); 
     74                  exporter->SetFilled(); 
     75 
     76                  exporter->ExportViewCells(p->mViewCells); 
     77 
    6778                  delete exporter; 
    6879          } 
     
    8697          {      
    8798                  Debug << "Exporting complementary view cells" << endl; 
    88                   exporter->ExportViewCells(&vc_compl); // export view cells 
     99                  exporter->ExportViewCells(vc_compl); // export view cells 
    89100                  delete exporter; 
    90101          } 
Note: See TracChangeset for help on using the changeset viewer.