Ignore:
Timestamp:
11/06/05 01:24:55 (19 years ago)
Author:
mattausch
Message:
 
Location:
trunk/VUT/GtpVisibilityPreprocessor/src
Files:
7 edited

Legend:

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

    r379 r383  
    7171  ExportBspSplitPlanes(const BspTree &tree) = 0; 
    7272  virtual void  
    73   ExportBspSplits(const BspTree &tree) = 0; 
     73  ExportBspSplits(const BspTree &tree, const bool exportDepth = false) = 0; 
    7474  virtual void 
    7575  ExportLeavesGeometry(const BspTree &tree, const vector<BspLeaf *> &leaves) = 0; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r380 r383  
    600600                } 
    601601 
    602                 //-- visualization of the bsp splits 
     602                //-- visualization of the BSP splits 
    603603                bool exportSplits = false; 
    604604                environment->GetBoolValue("BspTree.exportSplits", exportSplits); 
     
    703703                                                         
    704704                        mSampleRays.push_back(new Ray(ray)); 
    705                         Debug << "abba " << mSampleRays.size() << endl; 
    706705                } 
    707706                else 
     
    727726        else if ((int)mSampleRays.size() < mPostProcessSamples) 
    728727        { 
    729                 Debug << "police " << mSampleRays.size() << endl; 
    730728                mSampleRays.push_back(new Ray(ray)); 
    731729        } 
     
    779777                exporter->SetForcedMaterial(m); 
    780778                exporter->SetWireframe(); 
    781                 exporter->ExportBspSplits(*mBspTree); 
     779                exporter->ExportBspSplits(*mBspTree, true); 
    782780 
    783781                // take forced material, else big scenes cannot be viewed 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r380 r383  
    10841084        if (sSplitPlaneStrategy & RANDOM_POLYGON) 
    10851085        { 
    1086                 Vector3 pt[3]; 
    1087                 for (int j = 0; j < 3; j ++) 
    1088                 { 
    1089                         int idx = Random((int)rays.size()); 
    1090                         pt[j] = rays[idx]->mRay->Extrap(rays[idx]->mMaxT); 
    1091                 } 
    1092  
    1093                 return Plane3(pt[0], pt[1], pt[2]); 
    1094  
    1095         //return polys[Random((int)polys.size())]->GetSupportingPlane(); 
     1086                return polys[Random((int)polys.size())]->GetSupportingPlane(); 
    10961087        } 
    10971088 
    10981089        // use heuristics to find appropriate plane 
    1099         return SelectPlaneHeuristics(polys, rays, sMaxPolyCandidates, sMaxRayCandidates); 
    1100 } 
    1101  
    1102 Plane3 BspTree::SelectPlaneHeuristics(PolygonContainer &polys, 
     1090        return SelectPlaneHeuristics(leaf,  
     1091                                         polys,  
     1092                                                                 rays,  
     1093                                                                 sMaxPolyCandidates,  
     1094                                                                 sMaxRayCandidates); 
     1095} 
     1096 
     1097Plane3 BspTree::SelectPlaneHeuristics(BspLeaf *leaf, 
     1098                                                                          PolygonContainer &polys, 
    11031099                                                                          const BoundedRayContainer &rays, 
    11041100                                                                          const int maxPolyCandidates, 
     
    11081104        int bestPlaneIdx = 0; 
    11091105         
    1110         int limit = maxPolyCandidates > 0 ? Min((int)polys.size(), maxPolyCandidates) : (int)polys.size(); 
     1106        int limit = maxPolyCandidates > 0 ?  
     1107                Min((int)polys.size(), maxPolyCandidates) : (int)polys.size(); 
    11111108         
    11121109        int candidateIdx = limit; 
    11131110 
    1114         //Debug << endl; 
    1115         /*for (int i = 0; i < limit; ++ i) 
     1111        for (int i = 0; i < limit; ++ i) 
    11161112        { 
    11171113                candidateIdx = GetNextCandidateIdx(candidateIdx, polys); 
    1118  
    1119                 Plane3 candidatePlane = polys[candidateIdx]->GetSupportingPlane(); 
     1114                 
     1115                // evaluate current candidate 
     1116                const float candidateCost =  
     1117                        SplitPlaneCost(leaf, 
     1118                                       polys[candidateIdx]->GetSupportingPlane(),  
     1119                                                   polys, rays); 
     1120 
    11201121                //Debug << polys[candidateIdx] << endl; 
    1121                 // evaluate current candidate 
    1122                 float candidateCost = SplitPlaneCost(candidatePlane, polys, rays); 
    1123                          
    11241122                if (candidateCost < lowestCost) 
    11251123                { 
     
    11271125                        lowestCost = candidateCost; 
    11281126                } 
    1129         }*/ 
     1127        } 
    11301128         
    11311129        //limit = maxRaysCandidates > 0 ? Min((int)rays.size(), maxRayCandidates) : (int)rays.size(); 
     
    11401138                for (int j = 0; j < 3; j ++) 
    11411139                { 
    1142                         idx[j] = Random((int)rays.size()); 
    1143                         pt[j] = rays[idx[j]]->mRay->Extrap(rays[idx[j]]->mMaxT); 
    1144                 } 
    1145  
    1146                 float candidateCost = SplitPlaneCost(Plane3(pt[0], pt[1], pt[2]), polys, rays); 
     1140                        idx[j] = Random((int)rays.size() * 2); 
     1141                                 
     1142                        if (idx[j] < (int)rays.size()) 
     1143                                pt[j] = rays[idx[j]]->mRay->Extrap(rays[idx[j]]->mMinT); 
     1144                        else 
     1145                        { 
     1146                                idx[j] -= (int)rays.size(); 
     1147                                pt[j] = rays[idx[j]]->mRay->Extrap(rays[idx[j]]->mMaxT); 
     1148                        } 
     1149                                         
     1150                } 
     1151 
     1152                const float candidateCost = 
     1153                        SplitPlaneCost(leaf, Plane3(pt[0], pt[1], pt[2]),  
     1154                                                   polys, rays); 
    11471155 
    11481156                if (candidateCost < lowestCost) 
     
    11571165        if (chooseFromRays) 
    11581166        { 
     1167                Debug << "choose ray plane: " << lowestCost << endl; 
    11591168                return Plane3(rays[bestIdx[0]]->mRay->Extrap(rays[bestIdx[0]]->mMaxT), 
    11601169                                          rays[bestIdx[1]]->mRay->Extrap(rays[bestIdx[1]]->mMaxT), 
     
    11771186} 
    11781187 
    1179 float BspTree::SplitPlaneCost(const Plane3 &candidatePlane,  
     1188float BspTree::SplitPlaneCost(BspLeaf *leaf,  
     1189                                                          const Plane3 &candidatePlane,  
    11801190                                                          const PolygonContainer &polys) const 
    11811191{ 
     
    13161326} 
    13171327 
    1318 float BspTree::SplitPlaneCost(const Plane3 &candidatePlane,  
     1328float BspTree::SplitPlaneCost(BspLeaf *leaf, 
     1329                                                          const Plane3 &candidatePlane,  
    13191330                                                          const BoundedRayContainer &rays) const 
    13201331{ 
     
    13331344        Intersectable::NewMail(); const int frontAndBackId = ViewCell::sMailId; 
    13341345 
    1335         /*PolygonContainer cell; 
     1346        PolygonContainer cell; 
    13361347        PolygonContainer front; 
    13371348        PolygonContainer back; 
    13381349 
    1339         ConstructGeometry(currentNode, cell); 
    1340         ConstructChildrenGeometry(front, cell, planes, sides); 
    1341         ConstructChildrenGeometry(back, cell, planes, sides);*/ 
    1342  
    1343  
     1350        vector<Plane3 *> planes; 
     1351        vector<bool> sides; 
     1352 
     1353        ExtractSplitPlanes(leaf, planes, sides); 
     1354 
     1355        ConstructGeometry(leaf, cell); 
     1356        ConstructChildGeometry(front, cell, planes, sides, candidatePlane, true); 
     1357        ConstructChildGeometry(back, cell, planes, sides, candidatePlane, false); 
     1358 
     1359        CLEAR_CONTAINER(cell); 
     1360        CLEAR_CONTAINER(front); 
     1361        CLEAR_CONTAINER(back); 
     1362         
    13441363        int frontRays = 0; 
    13451364        int backRays = 0; 
     
    14751494} 
    14761495 
    1477 float BspTree::SplitPlaneCost(const Plane3 &candidatePlane,  
     1496float BspTree::SplitPlaneCost(BspLeaf *leaf, 
     1497                                                          const Plane3 &candidatePlane,  
    14781498                                                          const PolygonContainer &polys,                                                           
    14791499                                                          const BoundedRayContainer &rays) const 
     
    14971517                (sSplitPlaneStrategy & BLOCKED_RAYS)) 
    14981518        { 
    1499         val += SplitPlaneCost(candidatePlane, polys); 
     1519        val += SplitPlaneCost(leaf, candidatePlane, polys); 
    15001520        } 
    15011521 
     
    15051525                (sSplitPlaneStrategy & PVS)) 
    15061526        { 
    1507                 val += SplitPlaneCost(candidatePlane, rays); 
     1527                val += SplitPlaneCost(leaf, candidatePlane, rays); 
    15081528        } 
    15091529 
     
    20192039} 
    20202040 
    2021 bool BspTree::ComputeChildrenGeometry(PolygonContainer &newCell, 
    2022                                                                           const PolygonContainer &cell, 
    2023                                                                           const vector<Plane3> &planes, 
    2024                                                                           const vector<bool> &sides, 
    2025                                                                           const Plane3 &splitPlane, 
    2026                                                                           const bool side) const 
     2041bool BspTree::ConstructChildGeometry(PolygonContainer &newCell, 
     2042                                                                         const PolygonContainer &cell, 
     2043                                                                         const vector<Plane3 *> &planes, 
     2044                                                                         const vector<bool> &sides, 
     2045                                                                         const Plane3 &splitPlane, 
     2046                                                                         const bool side) const 
    20272047{ 
    20282048        // get cross section of new polygon 
     
    20342054        for (int i = 0; (i < planes.size()) && inside; ++ i) 
    20352055        { 
    2036                 const int cf = planePoly->ClassifyPlane(planes[i]); 
     2056                const int cf = planePoly->ClassifyPlane(*planes[i]); 
    20372057                         
    20382058                // split new polygon with all previous planes 
     
    20462066                                        Polygon3 *backPoly = new Polygon3(); 
    20472067 
    2048                                         planePoly->Split(planes[i], *frontPoly, *backPoly, splitPts); 
     2068                                        planePoly->Split(*planes[i], *frontPoly, *backPoly, splitPts); 
    20492069                                        DEL_PTR(planePoly); 
    20502070 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r379 r383  
    459459                @returns true if plane contributes to the cell. 
    460460        */ 
    461         bool ComputeChildrenGeometry(PolygonContainer &newCell, 
    462                                                         const PolygonContainer &cell, 
    463                                                         const vector<Plane3> &planes, 
    464                                                         const vector<bool> &sides, 
    465                                                         const Plane3 &splitPlane, 
    466                                                         const bool side) const; 
     461        bool ConstructChildGeometry(PolygonContainer &newCell, 
     462                                                            const PolygonContainer &cell, 
     463                                                            const vector<Plane3 *> &planes, 
     464                                                            const vector<bool> &sides, 
     465                                                            const Plane3 &splitPlane, 
     466                                                            const bool side) const; 
    467467 
    468468 
     
    540540                @returns the cost of the candidate split plane 
    541541        */ 
    542         float SplitPlaneCost(const Plane3 &candidatePlane, 
     542        float SplitPlaneCost(BspLeaf *leaf,  
     543                                 const Plane3 &candidatePlane, 
    543544                                                 const PolygonContainer &polys,                                                   
    544545                                                 const BoundedRayContainer &rays) const; 
     
    548549                @returns the cost of the candidate split plane 
    549550        */ 
    550         float SplitPlaneCost(const Plane3 &candidatePlane, 
     551        float SplitPlaneCost(BspLeaf *leaf,  
     552                                 const Plane3 &candidatePlane, 
    551553                                                 const PolygonContainer &polys) const; 
    552554 
     
    555557                @returns the cost of the candidate split plane 
    556558        */ 
    557         float SplitPlaneCost(const Plane3 &candidatePlane, 
     559        float SplitPlaneCost(BspLeaf *leaf, 
     560                                 const Plane3 &candidatePlane, 
    558561                                                 const BoundedRayContainer &polys) const; 
    559562 
     
    608611                @param maxRayCandidates the maximal number of ray candidates 
    609612        */ 
    610         Plane3 SelectPlaneHeuristics(PolygonContainer &polys,  
     613        Plane3 SelectPlaneHeuristics(BspLeaf *leaf, 
     614                                         PolygonContainer &polys,  
    611615                                                                 const BoundedRayContainer &rays, 
    612616                                                                 const int maxPolyCandidates, 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp

    r382 r383  
    131131  long startTime = GetTime(); 
    132132   
    133   int i; 
    134133  int totalSamples = 0; 
    135134 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r380 r383  
    696696        vector<bool> mSides; 
    697697        bool mIsFront; 
     698        int mDepth; 
    698699 
    699700        BspSplitData(BspNode *node):  
    700         mNode(node), mIsFront(false) 
     701        mNode(node), mIsFront(false), mDepth(0) 
    701702        {};      
     703 
    702704        BspSplitData(BspNode *node,  
    703705                                vector<Plane3 *> planes,  
    704706                                vector<bool> sides,  
    705                                 bool isFront):  
    706         mNode(node), mPlanes(planes),  
    707         mSides(sides), mIsFront(isFront) 
     707                                const bool isFront, 
     708                                const int depth):  
     709        mNode(node), mPlanes(planes), mSides(sides),  
     710        mIsFront(isFront), mDepth(depth) 
    708711        {}; 
    709712}; 
    710713 
    711 void X3dExporter::ExportLeavesGeometry(const BspTree &tree, const vector<BspLeaf *> &leaves) 
     714void X3dExporter::ExportLeavesGeometry(const BspTree &tree,  
     715                                                                           const vector<BspLeaf *> &leaves) 
    712716{ 
    713717        vector<BspLeaf *>::const_iterator it, it_end = leaves.end(); 
     
    724728} 
    725729 
    726 void X3dExporter::ExportBspSplits(const BspTree &tree) 
     730void X3dExporter::ExportBspSplits(const BspTree &tree, 
     731                                                                  const bool exportDepth) 
    727732{ 
    728733        std::stack<BspSplitData> tStack; 
     
    732737   
    733738        PolygonContainer polys; 
     739        vector <int> depths; 
     740 
     741        int maxDepth = 0; 
    734742 
    735743        while (!tStack.empty()) 
     
    739747            tStack.pop();        
    740748                 
    741                 if (!tData.mNode->IsLeaf()) 
     749                if (tData.mNode->IsLeaf()) 
     750                { 
     751                        if (tData.mDepth > maxDepth) 
     752                                maxDepth = tData.mDepth; 
     753                } 
     754                else 
    742755                { 
    743756                        BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode); 
    744757 
     758                        // add current side of split plane 
    745759                        if (tData.mNode != tree.GetRoot()) 
    746                                 tData.mSides.push_back(tData.mIsFront); // add current side of split plane 
     760                                tData.mSides.push_back(tData.mIsFront); 
    747761 
    748762                        // bounded plane is added to the polygons 
    749                         Polygon3 *planePoly = tree.GetBoundingBox().CrossSection(*interior->GetPlane()); 
     763                        Polygon3 *planePoly =  
     764                                tree.GetBoundingBox().CrossSection(*interior->GetPlane()); 
    750765                 
    751766                        // do all the splits with the previous planes 
     
    778793 
    779794                        if (planePoly->Valid()) 
     795                        { 
    780796                                polys.push_back(planePoly); 
     797                                depths.push_back(tData.mDepth); 
     798                        } 
    781799                        else 
    782800                                DEL_PTR(planePoly); 
    783801                         
    784802                        // push the children on the stack 
    785                         tStack.push(BspSplitData(interior->GetFront(), tData.mPlanes, tData.mSides, true)); 
    786                         tStack.push(BspSplitData(interior->GetBack(), tData.mPlanes, tData.mSides, false)); 
    787                 } 
    788         }        
    789         ExportPolygons(polys); 
     803                        tStack.push(BspSplitData(interior->GetFront(), tData.mPlanes,  
     804                                                     tData.mSides, true, tData.mDepth + 1)); 
     805                        tStack.push(BspSplitData(interior->GetBack(), tData.mPlanes,  
     806                                                     tData.mSides, false, tData.mDepth + 1)); 
     807                } 
     808        } 
     809 
     810        if (maxDepth > 0) 
     811        {        
     812                mUseForcedMaterial = true; 
     813                         
     814                for (int i = 0; i < (int)polys.size(); ++ i) 
     815                { 
     816                        mForcedMaterial.mDiffuseColor.b = 1.0f; 
     817                        float importance =  (float)depths[i]/ (float)maxDepth; 
     818             
     819                        mForcedMaterial.mDiffuseColor.r = importance; 
     820                        mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r; 
     821 
     822                        ExportPolygon(polys[i]); 
     823                } 
     824        } 
     825        else 
     826        { 
     827                ExportPolygons(polys); 
     828        } 
     829 
    790830        CLEAR_CONTAINER(polys); 
    791831} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h

    r379 r383  
    7575   
    7676  virtual void  
    77   ExportBspSplits(const BspTree &tree); 
     77  ExportBspSplits(const BspTree &tree, const bool exportDepth); 
    7878 
    7979  virtual void 
Note: See TracChangeset for help on using the changeset viewer.