Ignore:
Timestamp:
11/06/05 01:24:55 (19 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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} 
Note: See TracChangeset for help on using the changeset viewer.