Changeset 3265


Ignore:
Timestamp:
01/11/09 02:43:59 (15 years ago)
Author:
mattausch
Message:

worked on bvh constructor

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter2.cpp

    r3262 r3265  
    510510 
    511511 
    512         int entityCount = 1; 
     512        int entityCount = mNumShapes; 
    513513        ofile.write(reinterpret_cast<char *>(&entityCount), sizeof(int)); 
    514514 
    515515 
    516516        ////////// 
    517         //-- write single scene entity 
    518  
    519         // no transformation 
    520         bool hasTrafo = false; 
    521         ofile.write(reinterpret_cast<char *>(&hasTrafo), sizeof(bool)); 
    522  
    523         // a dummy lod 
    524         int numLODs = 1; 
    525         ofile.write(reinterpret_cast<char *>(&numLODs), sizeof(int)); 
    526  
    527         float dist = 0; 
    528         ofile.write(reinterpret_cast<char *>(&dist), sizeof(float)); 
    529  
    530         ofile.write(reinterpret_cast<char *>(&mNumShapes), sizeof(int)); 
     517        //-- write scene entities 
    531518 
    532519        // all shapes belong to this scene entity 
    533520        for (int i = 0; i < mNumShapes; ++ i) 
    534521        { 
     522                // no transformation 
     523                bool hasTrafo = false; 
     524                ofile.write(reinterpret_cast<char *>(&hasTrafo), sizeof(bool)); 
     525 
     526                // a dummy lod 
     527                int numLODs = 1; 
     528                ofile.write(reinterpret_cast<char *>(&numLODs), sizeof(int)); 
     529 
     530                float dist = 0; 
     531                ofile.write(reinterpret_cast<char *>(&dist), sizeof(float)); 
     532 
     533                int numShapes = 1; 
     534                ofile.write(reinterpret_cast<char *>(&numShapes), sizeof(int)); 
     535 
    535536                int shapeId = i; 
    536537                ofile.write(reinterpret_cast<char *>(&shapeId), sizeof(int)); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/main.cpp

    r3262 r3265  
    3232         
    3333        //const int numFiles = 879; 
    34         const int numFiles = 300; 
     34        const int numFiles = 10; 
    3535 
    3636        vector<string> filenames; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp

    r3264 r3265  
    266266 
    267267        mVboId = -1; 
    268         // bound the maximal depth of the dynamic branch 
    269         mMaxDepthForDynamicBranch = 1; 
     268        // bounds the maximal depth of the dynamic branch 
     269        mMaxDepthForDynamicBranch = 10; 
    270270} 
    271271 
     
    13571357    while (1) 
    13581358        { 
    1359                 while (mGeometry[i]->GetWorldCenter()[axis] < position) ++ i; 
    1360                 //while ((j > 0) && (position < mGeometry[j]->GetWorldCenter()[axis])) -- j; 
    1361                 while (position < mGeometry[j]->GetWorldCenter()[axis]) -- j; 
     1359                //while (mGeometry[i]->GetWorldCenter()[axis] < position) ++ i; 
     1360                //while (position < mGeometry[j]->GetWorldCenter()[axis]) -- j; 
     1361 
     1362                while ((i < leaf->mLast) && (mGeometry[i]->GetWorldCenter()[axis] < position)) ++ i; 
     1363                while ((j > leaf->mFirst) && (position < mGeometry[j]->GetWorldCenter()[axis])) -- j; 
    13621364 
    13631365                // sorting finished 
     
    13911393        if (TerminationCriteriaMet(leaf)) 
    13921394        { 
    1393                 //cout << "leaf constructed:" << leaf->mBox << " " << leaf->mFirst << " " << leaf->mLast << endl; 
     1395                if (leaf->CountPrimitives() == 0) 
     1396                        cout << "error: leaf constructed:" << leaf->mBox << " " << leaf->mFirst << " " << leaf->mLast << endl; 
     1397                 
    13941398                return leaf; 
    13951399        } 
     
    14091413        pos = leaf->mBox.Center()[axis]; 
    14101414         
     1415        //if ((split >= leaf->mLast) || (split < leaf->mFirst)) 
    14111416        if (split == leaf->mLast) 
    14121417        { 
    14131418                // no split could be achieved => just halve number of objects 
    1414                 split = (leaf->mLast - leaf->mFirst) / 2; 
    1415                 cerr << "no reduction " << leaf->CountPrimitives() << " " << leaf->mFirst << " " << leaf->mLast << endl; 
     1419                split = (leaf->mLast + leaf->mFirst) / 2; 
     1420                cerr << "no reduction " << leaf->CountPrimitives() << " " << leaf->mFirst << " " << leaf->mLast << " " << split << endl; 
    14161421        } 
    14171422 
     
    14361441        front->mDepth = leaf->mDepth + 1; 
    14371442 
     1443        if (leaf->mFirst > leaf->mLast) 
     1444                cerr << "erorr!!! " << leaf->CountPrimitives() << " " << leaf->mFirst << " " << leaf->mLast << " " << split << endl; 
     1445 
    14381446        leaf->mLast = split; 
    14391447        leaf->mDepth = front->mDepth; 
     
    14551463        const bool criteriaMet =  
    14561464                (leaf->mDepth > mMaxDepthForDynamicBranch) || 
    1457                 (leaf->CountPrimitives() == 1); 
     1465                (leaf->CountPrimitives() <= 1); 
    14581466 
    14591467        return criteriaMet; 
     
    15011509        -- mNumNodes; 
    15021510 
    1503 #if 0 
     1511#if 1 
    15041512        BvhConstructor bvhConstructor(mGeometry, (int)mStaticGeometrySize, (int)mGeometrySize - 1); 
    15051513 
     
    15101518 
    15111519#else 
     1520 
    15121521        BvhLeaf *l = new BvhLeaf(mRoot); 
    15131522        mDynamicRoot = l; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhConstructor.cpp

    r3262 r3265  
    4040 
    4141int BvhConstructor::SortTriangles(BvhLeaf *leaf,  
    42                                                                   int axis,  
    43                                                                   float position) 
     42                                           int axis,  
     43                                           float position 
     44                                           ) 
    4445{ 
    4546        int i = leaf->mFirst; 
     
    4849    while (1) 
    4950        { 
    50                 while (mEntities[i]->GetWorldCenter()[axis] < position) ++ i; 
    51                 //while ((j > 0) && (position < mGeometry[j]->GetWorldCenter()[axis])) -- j; 
    52                 while (position < mEntities[j]->GetWorldCenter()[axis]) -- j; 
     51                //while (mEntities[i]->GetWorldCenter()[axis] < position) ++ i; 
     52                //while (position < mEntities[j]->GetWorldCenter()[axis]) -- j; 
     53 
     54                while ((i < leaf->mLast) && (mEntities[i]->GetWorldCenter()[axis] < position)) ++ i; 
     55                while ((j > leaf->mFirst) && (position < mEntities[j]->GetWorldCenter()[axis])) -- j; 
    5356 
    5457                // sorting finished 
     
    8184        if (TerminationCriteriaMet(leaf)) 
    8285        { 
    83                 cout << "leaf constructed:" << leaf->mBox << " " << leaf->mFirst << " " << leaf->mLast << endl; 
     86                if (leaf->CountPrimitives() <= 0) 
     87                        cout << "leaf constructed:" << leaf->mBox << " " << leaf->mFirst << " " << leaf->mLast << endl; 
    8488                return leaf; 
    8589        } 
     
    101105        { 
    102106                // no split could be achieved => just halve number of objects 
    103                 split = (leaf->mLast - leaf->mFirst) / 2; 
     107                split = (leaf->mLast + leaf->mFirst) / 2; 
    104108                cerr << "no reduction " << leaf->CountPrimitives() << " " << leaf->mFirst << " " << leaf->mLast << endl; 
    105109        } 
Note: See TracChangeset for help on using the changeset viewer.