Changeset 422 for trunk


Ignore:
Timestamp:
11/18/05 16:29:31 (19 years ago)
Author:
mattausch
Message:

worded on vspkdtree

Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
10 edited

Legend:

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

    r421 r422  
    6868ViewCells { 
    6969        #hierarchy kdTree 
    70         #hierarchy vspTree 
    71         hierarchy bspTree 
     70        hierarchy vspTree 
     71        #hierarchy bspTree 
    7272        # hierarchy sceneDependent 
    7373         
     
    9191BspTree { 
    9292        Construction { 
    93                 input fromRays 
     93                input fromSamples 
    9494        #       input fromViewCells 
    9595        #       input fromSceneGeometry 
     
    219219 
    220220        splitType regular 
    221  
    222         numberOfEndPointDomains 10000 
     221#       splitType heuristics 
    223222        ct_div_ci       0.0 
    224223} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp

    r419 r422  
    1111mKdTree(NULL), 
    1212mBspTree(NULL), 
     13mVspKdTree(NULL), 
    1314mRenderSimulator(NULL) 
    1415{ 
     
    1819Preprocessor::~Preprocessor() 
    1920{ 
    20         DeleteViewCells(); 
    21                  
    2221        DEL_PTR(mBspTree); 
    2322        DEL_PTR(mKdTree); 
    2423 
    2524        DEL_PTR(mRenderSimulator); 
     25 
     26        DeleteViewCells(); 
    2627} 
    2728 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r421 r422  
    7373                mBspTree->Construct(objects); 
    7474                break; 
    75         case BspTree::FROM_RAYS: 
     75        case BspTree::FROM_SAMPLES: 
    7676                DeleteViewCells(); // we generate new view cells 
    7777                mBspTree->SetGenerateViewCells(true); 
     
    490490                                                                                        passSampleContributions); 
    491491 
    492                                                 //mVspKdTree->Construct(mSampleRays, mBoundingBox); 
    493492                                        } 
    494493                                        else if (ViewCell::sHierarchy == ViewCell::VSP) 
     
    555554   
    556555        //-- render simulation 
    557         cout << "\nevaluating bsp view cells render time before merge ... "; 
    558         GetRenderSimulator()->SimulateRendering(); 
    559          
    560         cout << " finished" << endl; 
    561  
    562         cout << GetRenderSimulator()->mStat << endl; 
    563         Debug << GetRenderSimulator()->mStat << endl; 
    564  
     556        RenderSimulator *rs = GetRenderSimulator(); 
     557 
     558        if (rs) 
     559        { 
     560                cout << "\nevaluating bsp view cells render time before merge ... "; 
     561 
     562                rs->SimulateRendering(); 
     563         
     564                cout << " finished" << endl; 
     565 
     566                cout << GetRenderSimulator()->mStat << endl; 
     567                Debug << GetRenderSimulator()->mStat << endl; 
     568        } 
    565569 
    566570        if (mBspTree) 
     
    618622 
    619623                //-- render simulation 
    620                 cout << "\nevaluating render time after merge ... "; 
    621                          
    622                 GetRenderSimulator()->SimulateRendering(); 
    623                 cout << " finished" << endl; 
    624  
    625                 cout << GetRenderSimulator()->mStat << endl; 
    626                 Debug << GetRenderSimulator()->mStat << endl; 
     624                 
     625                RenderSimulator *rs = GetRenderSimulator(); 
     626 
     627                if (rs) 
     628                { 
     629                        cout << "\nevaluating render time after merge ... "; 
     630                         
     631                        rs->SimulateRendering(); 
     632 
     633                        cout << " finished" << endl; 
     634 
     635                        cout << GetRenderSimulator()->mStat << endl; 
     636                        Debug << GetRenderSimulator()->mStat << endl; 
     637                } 
    627638 
    628639                if (1) // export view cells 
     
    659670                exporter->SetExportRayDensity(true); 
    660671                exporter->ExportKdTree(*mKdTree); 
    661  
    662                 if (mBspTree && (ViewCell::sHierarchy == ViewCell::VSP)) 
    663                         exporter->ExportVspKdTree(*mVspKdTree); 
    664  
     672                delete exporter; 
     673        } 
     674 
     675        if (mVspKdTree) 
     676        { 
     677                Exporter *exporter = Exporter::GetExporter("vspkdtree.x3d");  
     678                exporter->SetWireframe(); 
     679                exporter->ExportVspKdTree(*mVspKdTree); 
    665680                delete exporter; 
    666681        } 
     
    732747                                                                                           int &sampleContributions) 
    733748{ 
    734         // save rays for bsp tree construction 
    735749        if (!mVspKdTree) 
    736750        { 
     751                // store samples for vsp kd tree construction 
    737752                if ((int)mVspSampleRays.size() < mVspConstructionSamples) 
    738753                { 
    739                         MeshInstance *mi = dynamic_cast<MeshInstance *>(object); 
    740                          
    741754                        VssRay *sRay = new VssRay(ray); 
    742                         mVspSampleRays.push_back(sRay); 
     755                 
     756            mVspSampleRays.push_back(sRay); 
    743757                 
    744758                        // also add origin to sample 
     
    749763                        // construct VSP tree using the collected samples 
    750764                        cout << "building VSP tree from " << (int)mVspSampleRays.size() << " samples " << endl; 
     765                        mVspKdTree = new VspKdTree(); 
    751766                        mVspKdTree->Construct(mVspSampleRays); 
    752767                 
     
    779794        if (!mBspTree) 
    780795        { 
    781                 if ((BspTree::sConstructionMethod == BspTree::FROM_RAYS) && 
     796                if ((BspTree::sConstructionMethod == BspTree::FROM_SAMPLES) && 
    782797                        ((int)mSampleRays.size() < mBspConstructionSamples)) 
    783798                { 
     
    889904                                        outRays.push_back(mSampleRays[i]); 
    890905                        } 
    891                         if (BspTree::sConstructionMethod == BspTree::FROM_RAYS) 
     906                        if (BspTree::sConstructionMethod == BspTree::FROM_SAMPLES) 
    892907                        { 
    893908                                // export rays  
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r421 r422  
    300300 
    301301        //-- termination criteria for axis aligned split 
    302         environment->GetFloatValue("BspTree.Termination.AxisAligned.ct_div_ci", mCt_div_ci); 
     302        environment->GetFloatValue("BspTree.Termination.AxisAligned.ct_div_ci", mCtDivCi); 
    303303        environment->GetFloatValue("BspTree.Termination.AxisAligned.maxCostRatio", mMaxCostRatio); 
    304304        environment->GetIntValue("BspTree.Termination.AxisAligned.maxPolys",  
     
    370370        else if (strcmp(constructionMethodStr, "fromSceneGeometry") == 0) 
    371371                sConstructionMethod = FROM_SCENE_GEOMETRY; 
    372         else if (strcmp(constructionMethodStr, "fromRays") == 0) 
    373                 sConstructionMethod = FROM_RAYS; 
     372        else if (strcmp(constructionMethodStr, "fromSamples") == 0) 
     373                sConstructionMethod = FROM_SAMPLES; 
    374374        else  
    375375        { 
     
    826826                                                 tBackData, 
    827827                                                 coincident, 
    828                                                  interior->mPlane); 
    829                                                   
     828                                                 interior->mPlane);                       
    830829        } 
    831830 
     
    10361035   
    10371036        float oldCost = (float)polys.size(); 
    1038         float newCost = mCt_div_ci + minSum / boxArea; 
     1037        float newCost = mCtDivCi + minSum / boxArea; 
    10391038        float ratio = newCost / oldCost; 
    10401039 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r421 r422  
    447447 
    448448        /// bsp tree construction types 
    449         enum {FROM_INPUT_VIEW_CELLS, FROM_SCENE_GEOMETRY, FROM_RAYS}; 
     449        enum {FROM_INPUT_VIEW_CELLS, FROM_SCENE_GEOMETRY, FROM_SAMPLES}; 
    450450 
    451451        /** Returns statistics. 
     
    501501        /// BSP tree construction method 
    502502        static int sConstructionMethod; 
     503 
     504 
    503505protected: 
    504506 
     
    803805 
    804806        /// axis aligned split criteria 
    805         float mCt_div_ci; 
     807        float mCtDivCi; 
    806808        float mSplitBorder; 
    807809        float mMaxCostRatio; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp

    r421 r422  
    243243 
    244244// Constructor 
    245 VspKdTree::VspKdTree() 
     245VspKdTree::VspKdTree(): 
     246mOnlyDrivingAxis(true) 
    246247{          
    247248        environment->GetIntValue("VspKdTree.Termination.maxDepth", mTermMaxDepth); 
     
    250251        environment->GetFloatValue("VspKdTree.Termination.maxRayContribution", mTermMaxRayContribution); 
    251252        environment->GetFloatValue("VspKdTree.Termination.maxCostRatio", mTermMaxCostRatio); 
    252  
    253253        environment->GetFloatValue("VspKdTree.Termination.minSize", mTermMinSize); 
     254 
    254255        mTermMinSize = sqr(mTermMinSize); 
    255256 
    256         environment->GetFloatValue("VspKdTree.epsilon", epsilon); 
    257         environment->GetFloatValue("VspKdTree.ct_div_ci", ct_div_ci); 
    258          
    259         environment->GetFloatValue("VspKdTree.maxTotalMemory", maxTotalMemory); 
    260         environment->GetFloatValue("VspKdTree.maxStaticMemory", maxStaticMemory); 
    261    
    262    
    263         environment->GetIntValue("VspKdTree.accessTimeThreshold", accessTimeThreshold); 
    264         //= 1000; 
    265         environment->GetIntValue("VspKdTree.minCollapseDepth", minCollapseDepth); 
    266   
     257        environment->GetFloatValue("VspKdTree.epsilon", mEpsilon); 
     258        environment->GetFloatValue("VspKdTree.ct_div_ci", mCtDivCi); 
     259         
     260        environment->GetFloatValue("VspKdTree.maxTotalMemory", mMaxTotalMemory); 
     261        environment->GetFloatValue("VspKdTree.maxStaticMemory", mMaxStaticMemory); 
     262     
     263        environment->GetIntValue("VspKdTree.accessTimeThreshold", mAccessTimeThreshold); 
     264        environment->GetIntValue("VspKdTree.minCollapseDepth", mMinCollapseDepth); 
    267265 
    268266        // split type 
     
    284282        } 
    285283 
     284        Debug << "======= vsp kd tree options ========" << endl; 
     285        Debug << "max depth: "<< mTermMaxDepth << endl; 
     286        Debug << "min pvs: "<< mTermMinPvs << endl; 
     287        Debug << "min rays: "<< mTermMinRays << endl; 
     288        Debug << "max ray contribution: "<< mTermMaxRayContribution << endl; 
     289        Debug << "max cost ratio: "<< mTermMaxCostRatio << endl; 
     290        Debug << "min size: "<<mTermMinSize << endl; 
     291 
    286292        mRoot = NULL; 
    287293 
    288         splitCandidates = new vector<SortableEntry>; 
     294        mSplitCandidates = new vector<SortableEntry>; 
    289295} 
    290296 
     
    403409        mStat.Start(); 
    404410   
    405         maxMemory = maxStaticMemory; 
     411        mMaxMemory = mMaxStaticMemory; 
    406412 
    407413        DEL_PTR(mRoot); 
     
    411417        // first construct a leaf that will get subdivide 
    412418        VspKdTreeLeaf *leaf = dynamic_cast<VspKdTreeLeaf *>(mRoot); 
    413  
    414419         
    415420        mStat.nodes = 1; 
     
    428433                mBox = *forcedBoundingBox; 
    429434 
    430         cout << "Bbox = " << mBox << endl; 
     435        Debug << "bbox = " << mBox << endl; 
    431436         
    432437        mStat.rays = (int)leaf->mRays.size(); 
     
    438443        mRoot = Subdivide(TraversalData(leaf, mBox, 0)); 
    439444 
    440         if (splitCandidates)  
    441         { 
    442                 // force realease of this vector 
    443                 delete splitCandidates; 
    444                 splitCandidates = new vector<SortableEntry>; 
     445        if (mSplitCandidates)  
     446        { 
     447                // force release of this vector 
     448                delete mSplitCandidates; 
     449                mSplitCandidates = new vector<SortableEntry>; 
    445450        } 
    446451   
     
    476481                lastMem = (int)mem; 
    477482                 
    478                 if (  mem > maxMemory )  
     483                if (mem > mMaxMemory)  
    479484                { 
    480485                        // count statistics on unprocessed leafs 
     
    528533        float costRatio; 
    529534         
    530         if (splitType == ESplitRegular) { 
     535        if (splitType == ESplitRegular)  
     536        { 
    531537                costRatio = BestCostRatioRegular(leaf, 
    532538                                                                                 axis, 
     
    556562        if (costRatio > mTermMaxCostRatio)  
    557563        { 
    558                 //              cout<<"Too big cost ratio "<<costRatio<<endl; 
     564                cout<<"Too big cost ratio " << costRatio << endl; 
    559565                return -1; 
    560566        } 
    561567 
    562 #if 0    
    563         cout<< 
    564                 "pvs="<<leaf->mPvsSize<< 
    565                 " rays="<<leaf->mRays.size()<< 
    566                 " rc="<<leaf->GetAvgRayContribution()<< 
    567                 " axis="<<axis<<endl; 
     568#if 1    
     569        cout << 
     570                "pvs=" << leaf->mPvsSize << 
     571                " rays=" << (int)leaf->mRays.size() << 
     572                " rc=" << leaf->GetAvgRayContribution() << 
     573                " axis=" << axis << endl; 
    568574#endif 
    569575         
     
    624630                 
    625631        //              float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 
    626         float sum = pvsBack*(position - minBox) + pvsFront*(maxBox - position); 
    627  
    628         newCost = ct_div_ci + sum/sizeBox; 
     632        float sum = pvsBack*(position - minBox) + pvsFront * (maxBox - position); 
     633 
     634        newCost = mCtDivCi + sum  /sizeBox; 
    629635         
    630636        //      cout<<axis<<" "<<pvsSize<<" "<<pvsBack<<" "<<pvsFront<<endl; 
     
    637643} 
    638644 
    639 float 
    640 VspKdTree::BestCostRatioRegular(VspKdTreeLeaf *leaf, 
    641                                                                 int &axis, 
    642                                                                 float &position, 
    643                                                                 int &raysBack, 
    644                                                                 int &raysFront, 
    645                                                                 int &pvsBack, 
    646                                                                 int &pvsFront) 
    647 { 
    648         int nRaysBack[6], nRaysFront[6]; 
    649         int nPvsBack[6], nPvsFront[6]; 
    650         float nPosition[6]; 
    651         float nCostRatio[6]; 
     645float VspKdTree::BestCostRatioRegular(VspKdTreeLeaf *leaf, 
     646                                                                          int &axis, 
     647                                                                          float &position, 
     648                                                                          int &raysBack, 
     649                                                                          int &raysFront, 
     650                                                                          int &pvsBack, 
     651                                                                          int &pvsFront) 
     652{ 
     653        int nRaysBack[3], nRaysFront[3]; 
     654        int nPvsBack[3], nPvsFront[3]; 
     655 
     656        float nPosition[3]; 
     657        float nCostRatio[3]; 
    652658        int bestAxis = -1; 
    653659         
     
    656662        // int sAxis = box.Size().DrivingAxis(); 
    657663        int sAxis = sBox.Size().DrivingAxis(); 
    658          
    659         bool onlyDrivingAxis = true;  
    660  
    661         for (axis = 0; axis < 6; ++ axis)  
    662         { 
    663                 if (!onlyDrivingAxis || axis == sAxis)  
     664 
     665        for (axis = 0; axis < 3; ++ axis)  
     666        { 
     667                if (!mOnlyDrivingAxis || axis == sAxis)  
    664668                { 
    665669                        nPosition[axis] = (sBox.Min()[axis] + sBox.Max()[axis])*0.5f; 
     
    746750        Intersectable::NewMail(); 
    747751         
    748         for (vector<SortableEntry>::const_iterator ci = splitCandidates->begin(); 
    749                 ci < splitCandidates->end(); ++ ci)  
     752        for (vector<SortableEntry>::const_iterator ci = mSplitCandidates->begin(); 
     753                ci < mSplitCandidates->end(); ++ ci)  
    750754        { 
    751755                VssRay *ray; 
     
    805809 
    806810        float oldCost = (float)leaf->GetPvsSize(); 
    807         float newCost = ct_div_ci + minSum / sizeBox; 
     811        float newCost = mCtDivCi + minSum / sizeBox; 
    808812        float ratio = newCost / oldCost; 
    809813   
    810         //  cout<<"===================="<<endl; 
    811         //  cout<<"costRatio="<<ratio<<" pos="<<position<<" t="<<(position - minBox)/(maxBox - minBox) 
    812         //      <<"\t q=("<<queriesBack<<","<<queriesFront<<")\t r=("<<raysBack<<","<<raysFront<<")"<<endl; 
     814        //Debug << "costRatio=" << ratio << " pos=" << position << " t=" << (position - minBox) / (maxBox - minBox) 
     815        //     <<"\t q=(" << queriesBack << "," << queriesFront << ")\t r=(" << raysBack << "," << raysFront << ")" << endl; 
    813816         
    814817        return ratio; 
     
    818821                                                                        const int axis) 
    819822{ 
    820         splitCandidates->clear(); 
     823        mSplitCandidates->clear(); 
    821824   
    822825        int requestedSize = 2 * (int)(node->mRays.size()); 
    823826        // creates a sorted split candidates array 
    824         if (splitCandidates->capacity() > 500000 && 
    825                 requestedSize < (int)(splitCandidates->capacity()/10) )  
    826         { 
    827         delete splitCandidates; 
    828                 splitCandidates = new vector<SortableEntry>; 
    829         } 
    830    
    831         splitCandidates->reserve(requestedSize); 
     827        if (mSplitCandidates->capacity() > 500000 && 
     828                requestedSize < (int)(mSplitCandidates->capacity()/10) )  
     829        { 
     830        delete mSplitCandidates; 
     831                mSplitCandidates = new vector<SortableEntry>; 
     832        } 
     833   
     834        mSplitCandidates->reserve(requestedSize); 
    832835 
    833836        // insert all queries  
     
    836839        { 
    837840                bool positive = (*ri).mRay->HasPosDir(axis); 
    838                 splitCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMin : SortableEntry::ERayMax,  
    839                                                                                                  (*ri).ExtrapOrigin(axis), (void *)&*ri)); 
     841                mSplitCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMin : SortableEntry::ERayMax,  
     842                                                                                                  (*ri).ExtrapOrigin(axis), (void *)&*ri)); 
    840843                 
    841                 splitCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMax : SortableEntry::ERayMin, 
    842                                                                                                  (*ri).ExtrapTermination(axis), (void *)&*ri)); 
    843         } 
    844          
    845         stable_sort(splitCandidates->begin(), splitCandidates->end()); 
     844                mSplitCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMax : SortableEntry::ERayMin, 
     845                                                                                                  (*ri).ExtrapTermination(axis), (void *)&*ri)); 
     846        } 
     847         
     848        stable_sort(mSplitCandidates->begin(), mSplitCandidates->end()); 
    846849} 
    847850 
     
    891894        { 
    892895 
    893 #if 0 
    894                 if (leaf->mDepth >= termMaxDepth) { 
    895                         cout<<"Warning: max depth reached depth="<<(int)leaf->mDepth<<" rays="<<leaf->mRays.size()<<endl; 
    896                         cout<<"Bbox: "<<GetBBox(leaf)<<" dirbbox:"<<GetDirBBox(leaf)<<endl; 
     896#if 1 
     897                if (leaf->mDepth >= mTermMaxDepth)  
     898                { 
     899                        Debug << "Warning: max depth reached depth="<<(int)leaf->mDepth<<" rays=" << (int)leaf->mRays.size() << endl; 
     900                        Debug << "Bbox: " << GetBBox(leaf) << endl; 
    897901                } 
    898902#endif 
     
    10311035 
    10321036        // find a node in the tree which subtree will be collapsed 
    1033         int maxAccessTime = time - accessTimeThreshold; 
     1037        int maxAccessTime = time - mAccessTimeThreshold; 
    10341038        int released = 0; 
    10351039 
     
    10451049                        VspKdTreeInterior *in = dynamic_cast<VspKdTreeInterior *>(node); 
    10461050                        // cout<<"depth="<<(int)in->depth<<" time="<<in->lastAccessTime<<endl; 
    1047                         if (in->mDepth >= minCollapseDepth && in->mLastAccessTime <= maxAccessTime)  
     1051                        if (in->mDepth >= mMinCollapseDepth && in->mLastAccessTime <= maxAccessTime)  
    10481052                        { 
    10491053                                released = CollapseSubtree(node, time); 
     
    10921096        { 
    10931097        // memory check and realese... 
    1094                 if (GetMemUsage() > maxTotalMemory)  
     1098                if (GetMemUsage() > mMaxTotalMemory)  
    10951099                        ReleaseMemory(pass); 
    10961100                 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h

    r421 r422  
    258258        void UpdatePvsSize(); 
    259259 
    260         void Mail(); 
    261  
    262         bool Mailed() const; 
    263    
    264         bool Mailed(const int mail); 
    265  
    266260        /** Returns average contribution of a ray to the PVS 
    267261        */ 
     
    270264        */ 
    271265        inline float GetSqrRayContribution() const; 
     266 
     267        //-- mailing options 
     268 
     269        void Mail(); 
     270 
     271        bool Mailed() const; 
     272   
     273        bool Mailed(const int mail); 
    272274 
    273275        static void NewMail(); 
     
    520522 
    521523        // total number of nodes of the tree 
    522         int nodes; 
     524        int mNumNodes; 
    523525         
    524526        // axis aligned bounding box of the scene 
     
    526528 
    527529        // epsilon used for the construction 
    528         float epsilon; 
     530        float mEpsilon; 
    529531 
    530532        // ratio between traversal and intersection costs 
    531         float ct_div_ci; 
     533        float mCtDivCi; 
    532534         
    533535        // type of the splitting to use for the tree construction 
     
    536538         
    537539        // maximum alovable memory in MB 
    538         float maxTotalMemory; 
     540        float mMaxTotalMemory; 
    539541 
    540542        // maximum alovable memory for static kd tree in MB 
    541         float maxStaticMemory; 
     543        float mMaxStaticMemory; 
    542544 
    543545        // this is used during the construction depending 
    544546        // on the type of the tree and queries... 
    545         float maxMemory; 
     547        float mMaxMemory; 
    546548 
    547549        // minimal acess time for collapse 
    548         int accessTimeThreshold; 
     550        int mAccessTimeThreshold; 
    549551 
    550552        // minimal depth at which to perform collapse 
    551         int minCollapseDepth; 
     553        int mMinCollapseDepth; 
    552554         
    553555        // reusable array of split candidates 
    554         vector<SortableEntry> *splitCandidates; 
    555  
     556        vector<SortableEntry> *mSplitCandidates; 
    556557         
    557558        ///////////////////////////// 
     
    577578 
    578579 
     580        bool mOnlyDrivingAxis; 
    579581        ///////////////////////////// 
    580582        VspKdStatistics mStat;   
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h

    r411 r422  
    6161  } 
    6262         
    63         VssRay(const Ray &ray) 
    64                 :mOrigin(ray.GetLoc()),  
    65                 mTermination(ray.Extrap(ray.intersections[0].mT)), 
     63        VssRay(const Ray &ray): 
     64                mOrigin(ray.GetLoc()),  
    6665                mOriginObject(ray.sourceObject.mObject), 
    67                 mTerminationObject(ray.intersections[0].mObject), 
    6866                mRefCount(0), 
    6967                mFlags(0), 
    7068                mMailbox(-1) 
    71         {} 
     69        { 
     70                if (!ray.intersections.empty()) 
     71                { 
     72                        mTermination = ray.intersections[0].mT; 
     73                        mTerminationObject = ray.intersections[0].mObject; 
     74                } 
     75                else 
     76                { 
     77                        mTermination = Limits::Infinity; 
     78                        mTerminationObject = NULL; 
     79                } 
     80        } 
    7281 
    7382  void Precompute() { 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r419 r422  
    587587         /*if (mExportRayDensity) {       
    588588         return ExportKdTreeRayDensity(tree); }*/ 
    589       
    590          stack<VspKdTreeNode *> tStack; 
    591  
    592          tStack.push(tree.GetRoot()); 
    593  
    594          Mesh *mesh = new Mesh; 
    595    
    596          while (!tStack.empty())  
    597          { 
    598                  VspKdTreeNode *node = tStack.top(); 
     589 
     590        stack<VspKdTreeNode *> tStack; 
     591 
     592        tStack.push(tree.GetRoot()); 
     593 
     594        Mesh *mesh = new Mesh; 
     595   
     596        while (!tStack.empty())  
     597        { 
     598                VspKdTreeNode *node = tStack.top(); 
    599599     
    600                  tStack.pop(); 
    601                  AxisAlignedBox3 box = tree.GetBBox(node); 
    602  
    603                  // add 6 vertices of the box 
    604  
    605                  int index = (int)mesh->mVertices.size(); 
     600                tStack.pop(); 
     601                AxisAlignedBox3 box = tree.GetBBox(node); 
     602 
     603                // add 6 vertices of the box 
     604                int index = (int)mesh->mVertices.size(); 
    606605    
    607                  for (int i=0; i < 8; ++ i)  
    608                  { 
    609                          Vector3 v; 
    610                          box.GetVertex(i, v); 
    611                          mesh->mVertices.push_back(v); 
    612                  } 
    613  
    614                  mesh->AddFace(new Face(index + 0, index + 1, index + 3, index + 2) ); 
    615                  mesh->AddFace(new Face(index + 0, index + 2, index + 6, index + 4) ); 
    616                  mesh->AddFace(new Face(index + 4, index + 6, index + 7, index + 5) ); 
    617  
    618     
    619                  mesh->AddFace(new Face(index + 3, index + 1, index + 5, index + 7) ); 
    620                  mesh->AddFace(new Face(index + 0, index + 4, index + 5, index + 1) ); 
    621                  mesh->AddFace(new Face(index + 2, index + 3, index + 7, index + 6) ); 
    622  
    623                  if (!node->IsLeaf())  
    624                  { 
    625                          VspKdTreeInterior *interior = dynamic_cast<VspKdTreeInterior *>(node); 
    626                          tStack.push(interior->GetFront()); 
    627                          tStack.push(interior->GetBack()); 
    628                  } 
    629          } 
    630    
    631          ExportMesh(mesh); 
    632          DEL_PTR(mesh); 
    633  
    634          return true; 
     606                for (int i=0; i < 8; ++ i)  
     607                { 
     608                        Vector3 v; 
     609                        box.GetVertex(i, v); 
     610                        mesh->mVertices.push_back(v); 
     611                } 
     612 
     613                mesh->AddFace(new Face(index + 0, index + 1, index + 3, index + 2) ); 
     614                mesh->AddFace(new Face(index + 0, index + 2, index + 6, index + 4) ); 
     615                mesh->AddFace(new Face(index + 4, index + 6, index + 7, index + 5) ); 
     616 
     617                mesh->AddFace(new Face(index + 3, index + 1, index + 5, index + 7) ); 
     618                mesh->AddFace(new Face(index + 0, index + 4, index + 5, index + 1) ); 
     619                mesh->AddFace(new Face(index + 2, index + 3, index + 7, index + 6) ); 
     620 
     621        if (!node->IsLeaf())  
     622                { 
     623                        VspKdTreeInterior *interior = dynamic_cast<VspKdTreeInterior *>(node); 
     624                        tStack.push(interior->GetFront()); 
     625                        tStack.push(interior->GetBack()); 
     626                } 
     627        } 
     628   
     629        ExportMesh(mesh); 
     630        DEL_PTR(mesh); 
     631 
     632        return true; 
    635633} 
    636634 
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r421 r422  
    2323  environment->Parse(argc, argv, USE_EXE_PATH); 
    2424  MeshKdTree::ParseEnvironment(); 
    25   BspTree::ParseEnvironment(); 
    26   
     25    
    2726  char buff[128]; 
    2827   
     
    5857  p->ParseViewCellsOptions(); 
    5958 
    60   // construct tree immediately for "from view cells" or "from scene geometry" 
    61   // construction method. For "from rays" construction, wait until there is 
    62   // a certain number of rays collected 
    63   if (ViewCell::sHierarchy == ViewCell::BSP && 
    64           !(BspTree::sConstructionMethod == BspTree::FROM_RAYS))  
     59  if (ViewCell::sHierarchy == ViewCell::BSP) 
    6560  { 
    66           if (BspTree::sConstructionMethod == BspTree::FROM_INPUT_VIEW_CELLS) 
    67           { 
    68                   // view cells input file name 
    69                   environment->GetStringValue("ViewCells.filename", buff); 
    70                   string vcFilename(buff); 
    71                   p->LoadViewCells(vcFilename); 
    72                   Debug << (int)p->mViewCells.size() << " view cells loaded" << endl; 
     61          BspTree::ParseEnvironment(); 
     62 
     63          // We construct BSP tree immediately for "from view cells" or "from scene geometry" 
     64          // construction method.  
     65          // For the "from samples" option, construction is delayed until enough samples were collected 
     66          if (BspTree::sConstructionMethod != BspTree::FROM_SAMPLES) 
     67          {              
     68                  if (BspTree::sConstructionMethod == BspTree::FROM_INPUT_VIEW_CELLS) 
     69                  { 
     70                          //-- load view cells from file 
     71                          environment->GetStringValue("ViewCells.filename", buff); 
     72                          string vcFilename(buff); 
     73                          p->LoadViewCells(vcFilename); 
     74                          Debug << (int)p->mViewCells.size() << " view cells loaded" << endl; 
     75                  } 
     76                   
     77                  p->BuildBspTree(); 
     78         
     79                  p->Export("vc_bsptree.x3d", false, false, true); 
     80                  p->BspTreeStatistics(Debug); 
    7381          } 
    74          
    75           p->BuildBspTree(); 
    76          
    77           p->Export("vc_bsptree.x3d", false, false, true); 
    78           p->BspTreeStatistics(Debug); 
    7982  } 
    8083 
Note: See TracChangeset for help on using the changeset viewer.