Changeset 3244 for GTP


Ignore:
Timestamp:
01/03/09 17:32:10 (15 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp

    r3236 r3244  
    11611161        mBox = mRoot->GetBox(); 
    11621162 
    1163         // compute and print stats 
     1163        // compute and print stats for whole (static + dynamic) bvh 
    11641164        ComputeBvhStats(mRoot, mBvhStats); 
    11651165        PrintBvhStats(mBvhStats); 
    11661166 
     1167        // also output dynamic stats 
    11671168        if (mDynamicGeometrySize) 
    11681169        { 
     
    14751476        l->mArea = l->mBox.SurfaceArea(); 
    14761477         
    1477         cout << "updating dynamic branch " << l->mFirst << " " << l->mLast << endl; 
     1478        cout << "creating dynamic bvh branch" << endl; 
    14781479 
    14791480        if (mDynamicGeometrySize) 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp

    r3242 r3244  
    7272        if (!stream.is_open()) return NULL; 
    7373 
    74         cout << "loading bvh" << endl; 
     74        cout << "\n*******************\nloading bvh ..." << endl; 
    7575 
    7676        Bvh *bvh = new Bvh(staticEntities, dynamicEntities, maxDepthForTestingChildren); 
     
    8282        bvh->mNumNodes = 3; 
    8383 
    84         cout << "*******************\nbox: " << root->mBox << " area: " << root->mArea << endl; 
     84        cout << "static bvh bb: " << root->mBox << endl; 
    8585 
    8686        tQueue.push(root); 
     
    111111        } 
    112112 
     113        cout << "... finished loading " << bvh->mNumNodes - 2 << " static bvh nodes" << endl; 
     114 
     115 
    113116        /////////// 
    114117        //-- create dynamic part of the hierarchy 
     
    121124        bvh->PostProcess(); 
    122125 
    123         cout << "... finished loading " << bvh->mNumNodes << " nodes" << endl; 
    124         cout << "scene box: " << bvh->mBox << endl; 
     126        cout << "bvh bb: " << bvh->mBox << endl; 
    125127 
    126128        return bvh; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp

    r3102 r3244  
    5555mRenderDynamicObjects(true) 
    5656{ 
     57        mStats.Reset(); 
    5758} 
    5859 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.cpp

    r3243 r3244  
    2424        while (!node->IsLeaf())  
    2525        { 
     26                //cout << "pt: " << point[node->mAxis] << " " << node->mPosition << endl; 
    2627                if (point[node->mAxis] < node->mPosition) 
    2728                        node = node->mBack; 
     
    2930                        node = node->mFront; 
    3031        } 
     32 
     33        //cout << "vc: " << node->mViewCell->GetBox() << " pvs " << node->mViewCell->mPvs.Size() << endl; 
    3134 
    3235        return node->mViewCell; 
     
    3639bool ViewCellsTree::LoadFromFile(const std::string &filename) 
    3740{ 
    38         cout << "Info: Loading view cells from file '" + filename + "'"; 
     41        cout << "Loading view cells from file '" + filename + "'"; 
    3942 
    4043        FILE *fr = fopen(filename.c_str(), "rb"); 
     
    4851        bool result = _LoadFromFile(fr); 
    4952 
    50         cout << "Info: done. " << endl; 
     53        cout << "finished loading view cells. " << endl; 
    5154        fclose(fr); 
    5255 
     
    5861{ 
    5962        int buffer[256];  
    60         fread(buffer, sizeof(int), 3, fr); 
     63        fread(buffer, sizeof(int), 2, fr); 
    6164 
    6265        if (buffer[0] != MAGIC)  
     
    7578        fread(&mBox, sizeof(AxisAlignedBox3), 1, fr); 
    7679 
     80        Vector3 v1(mBox.Min().x, -mBox.Min().z, mBox.Min().y); 
     81        Vector3 v2(mBox.Max().x, -mBox.Max().z, mBox.Max().y); 
     82         
     83        Vector3 newMin = v1; 
     84        Vector3 newMax = v2; 
     85 
     86        Minimize(newMin, v2); 
     87        Maximize(newMax, v1); 
     88 
     89        mBox.SetMin(newMin); 
     90        mBox.SetMax(newMax); 
     91 
    7792        stack<ViewCellsTreeNode **> nodeStack; 
     93        nodeStack.push(&mRoot); 
    7894 
    79         nodeStack.push(&mRoot); 
     95        cout << "view cells bounds " << mBox << endl; 
     96 
     97        int numViewCells = 0; 
    8098 
    8199        while (!nodeStack.empty())  
     
    85103                node = new ViewCellsTreeNode(); 
    86104 
    87                 fread(&node->mAxis, sizeof(int), 1, fr); 
     105                ++ numViewCells; 
     106 
     107                int axis; 
     108                fread(&axis, sizeof(int), 1, fr); 
     109 
     110                // exchange y and z axis like we have to do for the scene 
     111                if (axis == 2) axis = 1; 
     112                else if (axis == 1) axis = 2; 
     113 
     114                node->mAxis = axis; 
     115 
     116                if (node->mAxis > 2 || node->mAxis < -1) cout << "a " << node->mAxis << " "; 
    88117 
    89118                if (!node->IsLeaf()) 
    90119                { 
    91                         fread(&node->mPosition, sizeof(float), 1, fr); 
     120                        float pos; 
     121                        fread(&pos, sizeof(float), 1, fr); 
     122 
     123                        if (axis == 1) pos = -pos; 
     124                        node->mPosition = pos; 
     125                         
    92126                        nodeStack.push(&node->mFront); 
    93127                        nodeStack.push(&node->mBack); 
     
    95129        } 
    96130 
     131        cout << "loaded " << numViewCells << " view cells" << endl; 
    97132        return true; 
    98133} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.h

    r3243 r3244  
    2525        void SetBox(const AxisAlignedBox3 &box) { mBox = box; } 
    2626 
     27        AxisAlignedBox3 GetBox() const { return mBox; } 
    2728 
    2829        // the pvs associated with the viewcell 
     
    4243        ViewCellsTreeNode(): mAxis(-1), mViewCell(NULL) {} 
    4344 
    44         bool IsLeaf() { return mViewCell != NULL; } 
     45        bool IsLeaf() { return mAxis == -1; } 
    4546 
    4647 
    4748        /////////////////////// 
     49 
     50        /// split mAxis  
     51        int mAxis; 
    4852 
    4953        union  
     
    5862        ViewCellsTreeNode *mBack; 
    5963        ViewCellsTreeNode *mFront; 
    60  
    61         /// split mAxis  
    62         int mAxis; 
    6364}; 
    6465 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp

    r3243 r3244  
    2020        FILE *fr = fopen(filename.c_str(), "rb"); 
    2121   
    22         cout << "Info: Loading visibility solution from file '" + filename + "'" << endl; 
     22        cout << "Loading visibility solution from file '" + filename + "'" << endl; 
    2323   
    2424        if (fr == NULL)  
     
    3434        fread(&totalTime, sizeof(float), 1, fr); 
    3535 
     36        cout << "loading view cells" << endl; 
     37 
    3638        ViewCellsTree *viewCellsTree = new ViewCellsTree(); 
    3739 
    3840        bool ok = viewCellsTree->_LoadFromFile(fr); 
     41 
     42        cout << "finished loading view cells" << endl; 
     43 
    3944   
    4045        if (ok)  
    4146        { 
    42                 // skip bvh loading 
     47                // skip loading of bvh nodes 
    4348                int buffer[6];  
    4449                fread(buffer, sizeof(int), 6, fr); 
    4550 
    46                 const size_t numNodes = buffer[5]; 
    47                  
     51                const int numNodes = buffer[5]; 
     52                const int numTriangleIds = buffer[2]; 
     53 
     54                // skip triangle ids 
     55                cout << "skipping " << numTriangleIds << " triangle ids" << endl; 
     56 
     57                int tid; 
     58                for (int i = 0; i < numTriangleIds; ++ i)  
     59                        fread(&tid, sizeof(int), 1, fr); 
     60         
     61                cout << "skipping " << numNodes << " bvh nodes" << endl; 
     62 
    4863                for (int i = 0; i < numNodes; ++ i) 
    4964                        fread(buffer, sizeof(int), 4, fr); 
    5065 
     66 
     67                cout << "allocating view cells" << endl; 
     68 
    5169                AllocateLeafViewCells(viewCellsTree); 
    5270                 
     71                cout << "loading pvss" << endl; 
     72 
    5373                ok = LoadPvs(fr, bvh); 
     74 
     75                cout << "finished loading pvss" << endl; 
    5476        } 
    5577 
     
    5779 
    5880        if (ok)  
    59                 cerr << "Info: visibility solution loaded" << endl; 
     81                cout << "Visibility solution loaded" << endl; 
    6082        else 
    61                 cerr << "Info: loading visibility solution failed." << endl; 
     83                cerr << "Error: loading visibility solution failed." << endl; 
    6284 
    6385        return viewCellsTree; 
     
    99121        fread(&number, sizeof(int), 1, fw); 
    100122 
    101         if (number == 0)  
    102         { 
    103                 cerr << "Info: Warning empty PVSs in visibility solution" << endl; 
     123        if (!number)  
     124        { 
     125                cerr << "Warning: empty PVSs in visibility solution" << endl; 
    104126                return true; 
    105127        } 
     
    107129        if (number != mViewCells.size())  
    108130        { 
    109                 cerr << "Info: Number of view cells does not match when loading PVSs!" << endl; 
     131                cerr << "Warning: Number of view cells (" << number << ", " << (int)mViewCells.size() << ") does not match when loading PVSs!" << endl; 
    110132                return false; 
    111133        } 
     
    160182                if (node->IsLeaf())  
    161183                { 
    162                         if (node->mViewCell == NULL)  
     184                        if (!node->mViewCell)  
    163185                        { 
    164186                                node->mViewCell = new ViewCell(); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3243 r3244  
    139139bool makeSnapShot = false; 
    140140 
     141ViewCellsTree *viewCellsTree = NULL; 
     142 
    141143 
    142144/// the technique used for rendering 
     
    267269int maxBatchSize = 50; 
    268270int trianglesPerVirtualLeaf = INITIAL_TRIANGLES_PER_VIRTUAL_LEAVES; 
     271 
    269272 
    270273////////////// 
     
    349352SceneQuery *GetOrCreateSceneQuery(); 
    350353 
     354void RenderPvs(); 
     355 
    351356 
    352357// new view projection matrix of the camera 
     
    619624        VisibilitySolutionLoader visLoader; 
    620625 
    621         ViewCellsTree *viewCellsTree = visLoader.Load(vis_filename, bvh); 
     626        viewCellsTree = visLoader.Load(vis_filename, bvh); 
    622627 
    623628 
     
    12491254        { 
    12501255                // actually render the scene geometry using the specified algorithm 
    1251                 traverser->RenderScene(); 
     1256                //traverser->RenderScene(); 
     1257 
     1258                RenderPvs(); 
    12521259        } 
    12531260 
     
    12561263        //-- do the rest of the rendering 
    12571264         
    1258         // reset depth pass and render visible objects 
     1265        // return from depth pass and render visible objects 
    12591266        if ((renderMethod == RENDER_DEPTH_PASS) || 
    12601267                (renderMethod == RENDER_DEPTH_PASS_DEFERRED)) 
     
    20352042        DEL_PTR(walkThroughPlayer); 
    20362043        DEL_PTR(statsWriter); 
     2044        DEL_PTR(viewCellsTree); 
    20372045 
    20382046        ResourceManager::DelSingleton(); 
     
    25082516        return sampleCount; 
    25092517} 
     2518 
     2519 
     2520void RenderPvs() 
     2521{ 
     2522        ViewCell *vc = viewCellsTree->GetViewCell(camera->GetPosition()); 
     2523 
     2524        for (int i = 0; i < vc->mPvs.Size(); ++ i) 
     2525        { 
     2526                SceneEntity *ent = vc->mPvs.GetEntry(i); 
     2527                ent->Render(&renderState); 
     2528        } 
     2529} 
Note: See TracChangeset for help on using the changeset viewer.