Changeset 3238


Ignore:
Timestamp:
01/02/09 03:37:07 (15 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj

    r3232 r3238  
    888888                        </File> 
    889889                </Filter> 
    890                 <File 
    891                         RelativePath=".\default.env" 
    892                         > 
    893                 </File> 
    894                 <File 
    895                         RelativePath=".\ReadMe.txt" 
    896                         > 
    897                 </File> 
    898890        </Files> 
    899891        <Globals> 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/MainApp.vcproj

    r3019 r3238  
    196196                                > 
    197197                        </File> 
     198                        <File 
     199                                RelativePath=".\default.env" 
     200                                > 
     201                        </File> 
     202                        <File 
     203                                RelativePath=".\Readme.txt" 
     204                                > 
     205                        </File> 
    198206                </Filter> 
    199207                <Filter 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.cpp

    r3236 r3238  
    1414 
    1515#define BVH_VERSION 2.1 
     16 
     17const int maxVertices = 20000000; 
     18 
     19 
     20 
     21static string ReplaceSuffix(const string &str,  
     22                                                        const string &a,  
     23                                                        const string &b) 
     24{ 
     25        string result = str; 
     26 
     27        int pos = (int)str.rfind(a, (int)str.size() - 1); 
     28        if (pos == str.size() - a.size())  
     29        { 
     30                result.replace(pos, a.size(), b); 
     31        } 
     32 
     33        return result; 
     34} 
    1635 
    1736 
     
    92111                if (indices.size() > 2) 
    93112                { 
    94                         // change orientation of faces? 
    95 #if 1 
    96113                        int idx1 = 0; 
    97114                        int idx2 = (int)indices.size() - 2; 
    98115                        int idx3 = (int)indices.size() - 1; 
    99 #else 
    100                         int idx3 = 0; 
    101                         int idx2 = (int)indices.size() - 2; 
    102                         int idx1 = (int)indices.size() - 1; 
    103 #endif 
     116 
    104117                        faceVertices.push_back(vertices[indices[idx1]]); 
    105118                        faceVertices.push_back(vertices[indices[idx2]]); 
     
    172185        geom->mTexcoordCount = (int)texCoords.size(); 
    173186 
    174         cout << "number of vertices=" << numElements << endl; 
     187        //cout << "number of vertices=" << numElements << endl; 
    175188 
    176189        for (int i = 0; i < numElements; ++ i) 
    177190        { 
    178 #if 1 
    179191                // convert to our camera system: change y and z 
    180192                geom->mVertices[i].x =  vertices[i].x; 
     
    186198                geom->mNormals[i].z =  normals[i].y; 
    187199 
    188 #else 
    189                 geom->mVertices[i].x = vertices[i].x; 
    190                 geom->mVertices[i].y = vertices[i].y; 
    191                 geom->mVertices[i].z = vertices[i].z; 
    192          
    193                 geom->mNormals[i].x = normals[i].x; 
    194                 geom->mNormals[i].y = normals[i].y; 
    195                 geom->mNormals[i].z = normals[i].z; 
    196  
    197 #endif 
    198  
    199200                if (i < geom->mTexcoordCount) 
    200201                { 
     
    229230        if (!LoadSolution(bvhInputFilename)) 
    230231        { 
    231                 cerr << "could not read file" << endl; 
     232                cerr << "could not read solution file" << endl; 
    232233                return false; 
    233234        } 
     
    255256 
    256257 
    257 bool VisibilitySolutionConverter::ReadScene(const string &filename)  
     258bool VisibilitySolutionConverter::ReadScene(const string &filename) 
     259{ 
     260        VertexArray vertices; 
     261        VertexArray normals; 
     262        vector<TexCoord> texCoords; 
     263 
     264        if (ReadSimpleObj(filename, vertices, normals, texCoords)) 
     265        //if (ReadObj(filename, vertices, normals, texCoords))  
     266        { 
     267                ConstructBvhObjects(vertices, normals, texCoords); 
     268                return true; 
     269        } 
     270 
     271        return false; 
     272} 
     273 
     274 
     275bool VisibilitySolutionConverter::ReadObj(const string &filename, 
     276                                                                                  VertexArray &vertices, 
     277                                                                                  VertexArray &normals, 
     278                                                                                  vector<TexCoord> &texcoords)  
    258279{ 
    259280        FILE *file; 
    260281 
    261         if ((file = fopen(filename.c_str(), "r")) == NULL) 
    262         {        
    263                 return false; 
    264         } 
    265          
    266         VertexArray faceVertices;  
    267         VertexArray faceNormals; 
    268         vector<TexCoord> faceTexcoords; 
    269  
    270         VertexArray vertices;  
    271         VertexArray normals; 
    272         vector<TexCoord> texcoords; 
     282        if ((file = fopen(filename.c_str(), "r")) == NULL) return false; 
     283         
     284        VertexArray tempVertices;  
     285        VertexArray tempNormals; 
     286        vector<TexCoord> tempTexcoords; 
    273287 
    274288        vector<int> indices; 
     
    280294        while (fgets(str, len, file) != NULL) 
    281295        { 
    282                 if (line % 1000000 == 0) 
     296                if (line % 500000 == 0) 
    283297                        cout << line << " " << str << endl; 
    284298 
     
    291305                                float x, y, z; 
    292306 
    293                                 if (vertices.size() >= 1000000 * 3) continue; 
     307                                //if (tempVertices.size() >= maxVertices * 3) continue; 
    294308 
    295309                                switch (str[1])  
     
    297311                                case 'n' : 
    298312                                        sscanf(str + 2, "%f %f %f", &x, &y, &z); 
    299                                         normals.push_back(SimpleVec(x, y, z)); 
     313                                        tempNormals.push_back(SimpleVec(x, y, z)); 
    300314                                        break; 
    301315                                case 't': 
    302316                                        sscanf(str + 2, "%f %f", &x, &y); 
    303                                         texcoords.push_back(pair<float, float>(x, y)); 
     317                                        tempTexcoords.push_back(pair<float, float>(x, y)); 
    304318                                        break; 
    305319                                default: 
     
    307321                                        //const float scale = 5e-3f; 
    308322                                        const float scale = 0.1f; 
    309                                         vertices.push_back(SimpleVec(x * scale, y * scale, z * scale)); 
     323                                        tempVertices.push_back(SimpleVec(x * scale, y * scale, z * scale)); 
    310324                                        //cout <<"v " << x << " " << y << " "<< z << " "; 
    311325                                } 
     
    317331                                //-- indices in the current line 
    318332 
    319                                 if (faceVertices.size() >= 1000000 * 3) continue; 
    320  
     333                                //if (tempVertices.size() >= maxVertices * 3) continue; 
    321334                                LoadIndices(str,  
    322                                                 vertices, normals, texcoords,  
    323                                                 faceVertices, faceNormals, faceTexcoords); 
     335                                                tempVertices, tempNormals, tempTexcoords,  
     336                                                vertices, normals, texcoords); 
    324337 
    325338                                break; 
     
    332345        } 
    333346 
    334         if (!faceVertices.empty()) 
    335         { 
    336                 ++ mNumShapes; 
    337  
    338                 ConstructBvhObjects(faceVertices, faceNormals, faceTexcoords); 
    339  
    340                 faceVertices.clear(); 
    341                 faceNormals.clear(); 
    342                 faceTexcoords.clear(); 
    343         } 
    344  
    345347        fclose(file); 
    346          
    347         return true; 
    348 } 
     348 
     349        return !vertices.empty(); 
     350} 
     351 
     352 
     353bool VisibilitySolutionConverter::ReadSimpleObj(const string &filename, 
     354                                                                                                VertexArray &vertices, 
     355                                                                                                VertexArray &normals, 
     356                                                                                                vector<TexCoord> &texcoords) 
     357{ 
     358        const string binFilename = ReplaceSuffix(filename, ".obj", ".bn"); 
     359 
     360        if (!ReadBinObj(binFilename, vertices, 1)) 
     361        { 
     362                cout << "binary dump " << binFilename << " not available, loading ascii obj" << endl; 
     363 
     364                FILE *file; 
     365                if ((file = fopen(filename.c_str(), "r")) == NULL) return false; 
     366 
     367                int line = 0; 
     368                const int len = 10000; 
     369                char str[len]; 
     370 
     371                while (fgets(str, len, file) != NULL) 
     372                { 
     373                        if (line % 500000 == 0) 
     374                                cout << line << " " << str << endl; 
     375 
     376                        ++ line; 
     377 
     378                        switch (str[0]) 
     379                        { 
     380                        case 'v': // vertex or normal 
     381                                { 
     382                                        float x, y, z; 
     383 
     384                                        sscanf(str + 1, "%f %f %f", &x, &y, &z); 
     385                                        const float scale = 0.1f; 
     386                                        vertices.push_back(SimpleVec(x * scale, y * scale, z * scale)); 
     387                                        break; 
     388                                } 
     389                        default: 
     390                                // throw away line 
     391                                break; 
     392                        } 
     393                } 
     394 
     395                fclose(file); 
     396 
     397                cout << "dumping " << vertices.size() << " to binary " << binFilename << endl; 
     398                ExportBinObj(binFilename, vertices); 
     399        } 
     400 
     401        for (size_t i = 0; i < vertices.size(); i += 3) 
     402        { 
     403                // no face normals? => create normals 
     404                const SimpleTri tri(vertices[i + 0], 
     405                            vertices[i + 1],  
     406                                                        vertices[i + 2]); 
     407 
     408                const SimpleVec n = tri.GetNormal(); 
     409 
     410                normals.push_back(n); 
     411                normals.push_back(n); 
     412                normals.push_back(n); 
     413        } 
     414 
     415        return !vertices.empty(); 
     416} 
     417 
    349418 
    350419 
     
    473542                                                                                                          const vector<TexCoord> &texCoords) 
    474543{ 
    475         cout << "vtx: " << vertices.size() << endl; 
     544        VertexArray _vertices; 
     545        VertexArray _normals; 
     546        vector<TexCoord> _texCoords; 
    476547 
    477548        for (size_t i = 0; i < mBvhNodes.size(); ++ i) 
    478549        { 
    479                 VertexArray _vertices; 
    480                 VertexArray _normals; 
    481                 vector<TexCoord> _texCoords; 
    482  
    483550                BvhNode *node = mBvhNodes[i]; 
    484551 
    485552                //for (size_t j = 0; j < node->mTriangleIds.size(); ++ j) 
    486                 for (int j = node->first; j < node->last; ++ j) 
     553                for (int j = node->first; j <= node->last; ++ j) 
    487554                { 
    488555                        const int idx = 3 * mGlobalTriangleIds[j]; 
    489556 
    490                         //cout << "idx: " << idx << " "; 
    491  
    492                         if (idx < 1000000 * 3) 
     557                        //if (idx >= maxVertices * 3) continue; 
     558 
     559                        for (int k = 0; k < 3; ++ k) 
    493560                        { 
    494                                 for (int k = 0; k < 3; ++ k) 
    495                                 { 
    496                                         _vertices.push_back(vertices[idx + k]); 
    497                                         _normals.push_back(normals[idx + k]); 
    498                                         //_texCoords.push_back(texCoords[idx + k]); 
    499                                 } 
     561                                _vertices.push_back(vertices[idx + k]); 
     562                                _normals.push_back(normals[idx + k]); 
     563                                //_texCoords.push_back(texCoords[idx + k]); 
    500564                        } 
    501565                } 
     
    506570                        LoadShape(_vertices, _normals, _texCoords); 
    507571                } 
     572 
     573                _vertices.clear(); 
     574                _normals.clear(); 
     575                _texCoords.clear(); 
    508576        } 
    509577} 
     
    663731        fread(&totalTime, sizeof(float), 1, fr); 
    664732 
    665         //viewCellsTree = new ViewCellsTree; 
    666         //bool ok = viewCellsTree->_LoadFromFile(fr); 
    667  
     733        // just need to convert objects => read dummy visibility tree 
    668734        bool ok = ReadDummyTree(fr); 
    669735 
    670         if (ok)  
    671         { 
    672                 //AllocateLeafViewCells(); 
    673                  
    674                 //objectsTree = new Bvh(*scene); 
    675                 //ok = objectsTree->_LoadFromFile(fr); 
    676                 ok = ReadBvh(fr); 
    677  
    678                 /*if (ok)  
    679                 {  
    680                     AllocatePvsObjects(); 
    681                         ok = LoadPvs(fr); 
    682                 } 
    683                 */ 
    684         } 
     736        // read bvh to optain objects (= the leaves of the bvh) 
     737        if (ok) ok = ReadBvh(fr); 
    685738 
    686739        fclose(fr); 
     
    695748 
    696749 
    697 #if 0 
    698 bool VisibilitySolution::LoadPvs(FILE *fw) 
    699  
    700         int number, entries; 
    701    
    702         fread(&number, sizeof(int), 1, fw); 
    703  
    704         if (number == 0)  
    705         { 
    706                 Message("Info: Warning empty PVSs in visibility solution"); 
    707                 return true; 
    708         } 
    709  
    710         if (number != viewCells.size())  
    711         { 
    712                 Message("Info: Number of view cells does not match when loading PVSs!"); 
    713                 return false; 
    714         } 
    715  
    716         for (int i=0; i < number; i++)  
    717         { 
    718                 fread(&entries, sizeof(int), 1, fw); 
     750bool VisibilitySolutionConverter::ReadBinObj(const string &filename, 
     751                                                                                         VertexArray &vertices, 
     752                                                                                         float scale) 
     753{ 
     754        igzstream inStream(filename.c_str()); 
     755         
     756        if (!inStream.is_open()) return false; 
     757 
     758        cout << "binary obj dump available, loading " << filename.c_str() << endl; 
     759         
     760        // read in triangle size 
     761        int numTriangles; 
     762 
     763        const int t = 500000; 
     764        inStream.read(reinterpret_cast<char *>(&numTriangles), sizeof(int)); 
     765        vertices.reserve(numTriangles * 3); 
     766        cout << "loading " << numTriangles * 3 << " vertices ("  
     767                 << numTriangles * 3 * sizeof(SimpleVec) /      (1024 * 1024) << " MB)" << endl; 
     768 
     769        int i = 0; 
     770 
     771        while (1) 
     772        { 
     773                SimpleVec v; 
    719774                 
    720                 for (int j=0; j < entries; j++)  
    721                 { 
    722                         int objectId; 
    723                         float time; 
    724                         fread(&objectId, sizeof(int), 1, fw); 
    725                         fread(&time, sizeof(float), 1, fw); 
    726                         viewCells[i]->pvs.Insert(objectId, time); 
    727                 } 
    728         } 
     775                inStream.read(reinterpret_cast<char *>(&v), sizeof(SimpleVec)); 
     776 
     777                // end of file reached 
     778                if (inStream.eof())     break; 
     779                 
     780                //v *= scale; 
     781                vertices.push_back(v); 
     782 
     783                if (((i ++) % t) == 0) 
     784                         cout << "\r" << i << "/" << numTriangles * 3 << "\r"; 
     785        } 
     786         
     787        cout << "finished loading vertices" << endl; 
     788 
     789        if (i != numTriangles * 3) 
     790                cerr << "warning: " << numTriangles * 3 << " != " << i << endl; 
     791 
     792        inStream.close(); 
     793 
    729794        return true; 
    730795} 
    731796 
    732797 
    733 bool ViewCellsTree::_LoadFromFile(FILE *fr) 
    734 { 
    735         int buffer[256];  
    736         fread(buffer, sizeof(int), 3, fr); 
    737  
    738         if (buffer[0] != MAGIC)  
    739         { 
    740                 Message( "Error: Wrong file type"); 
    741                 return false; 
    742         } 
    743  
    744         if (buffer[1] != (int)(1000*VIEWCELLS_VERSION))  
    745         { 
    746                 Message( "Error: Wrong viewcells version" ); 
    747                  
    748                 return false; 
    749         } 
    750  
    751         // get the bounding box 
    752         fread(&box, sizeof(AxisAlignedBox3), 1, fr); 
    753  
    754         stack<ViewCellsTreeNode **> nodeStack; 
    755         nodeStack.push(&root); 
    756  
    757         while(!nodeStack.empty())  
    758         { 
    759                 ViewCellsTreeNode *&node = *nodeStack.top(); 
    760                  
    761                 nodeStack.pop(); 
    762                 node = new ViewCellsTreeNode; 
    763                  
    764                 fread(&node->axis, sizeof(int), 1, fr); 
    765                  
    766                 if (!node->IsLeaf())  
    767                 { 
    768                         fread(&node->position, sizeof(float), 1, fr); 
    769                          
    770                         nodeStack.push(&node->front); 
    771                         nodeStack.push(&node->back); 
    772                 } 
    773         } 
    774    
     798bool VisibilitySolutionConverter::ExportBinObj(const string &filename, 
     799                                                                                           const VertexArray &vertices) 
     800{        
     801        ogzstream ofile(filename.c_str()); 
     802        if (!ofile.is_open()) return false; 
     803 
     804        int numTriangles = (int)vertices.size() / 3; 
     805 
     806        ofile.write(reinterpret_cast<char *>(&numTriangles), sizeof(int)); 
     807 
     808        VertexArray::const_iterator it, it_end = vertices.end(); 
     809 
     810        for (it = vertices.begin(); it != it_end; ++ it) 
     811        { 
     812                SimpleVec v = *it; 
     813                ofile.write(reinterpret_cast<char *>(&v), sizeof(SimpleVec)); 
     814        } 
     815 
     816        cout << "exported " << numTriangles * 3 << " vertices" << endl; 
     817 
     818        ofile.close(); 
     819 
    775820        return true; 
    776821} 
    777 #endif 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.h

    r3235 r3238  
    110110        bool ReadDummyTree(FILE *fr); 
    111111 
     112        bool ReadObj(const std::string &filename, 
     113                         VertexArray &vertices, 
     114                                 VertexArray &normals, 
     115                                 std::vector<TexCoord> &texcoords); 
     116         
     117        bool ReadSimpleObj(const std::string &filename, 
     118                               VertexArray &vertices, 
     119                                           VertexArray &normals, 
     120                                           std::vector<TexCoord> &texcoords); 
    112121 
     122        bool ReadBinObj(const std::string &filename, 
     123                    VertexArray &vertices, 
     124                                        float scale); 
     125 
     126        bool ExportBinObj(const std::string &filename, 
     127                      const VertexArray &vertices); 
    113128 
    114129        ////////////////////////////////// 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/main.cpp

    r3235 r3238  
    2323        } 
    2424         
    25         std::cin.get(); 
     25        //std::cin.get(); 
    2626        cout << "conversion successful" << endl; 
    2727 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env

    r3230 r3238  
    77# misc stuff 
    88 
     9filename=city 
    910useLODs=1 
    1011# shadow map size 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp

    r3114 r3238  
    5050        if (tech->IsDepthWriteEnabled() != mBuckets[idx]->mDepthWriteEnabled) { return false; } 
    5151 
    52         //if (tech->IsColorWriteEnabled()) cout << "x"; 
    53  
    5452        const bool hasTexture = (tech->GetTexture() != NULL); 
    5553 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp

    r3237 r3238  
    109109                        int shapeId; 
    110110                        str.read(reinterpret_cast<char *>(&shapeId), sizeof(int)); 
    111 cout<<"x"; 
    112111 
    113112                        Geometry *geom = mGeometryTable[shapeId]; 
    114 cout<<"y"; 
    115  
    116113                        Material *mat = mMaterialTable[shapeId]; 
    117 cout<<"z"; 
    118114                        // create shape 
    119115                        Shape *shape = new Shape(geom, mat); 
    120 cout<<"w"; 
    121116 
    122117                        mShapes.push_back(shape); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp

    r3236 r3238  
    1515mGeometry(geometry),  
    1616mMaterial(mat) 
    17 {       std::cout<<"i"; 
     17{        
    1818        mCenter = GetBoundingBox().Center(); 
    19         std::cout<<"R"; 
     19         
    2020} 
    2121 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3237 r3238  
    5858#include "WalkThroughRecorder.h" 
    5959#include "StatsWriter.h" 
    60 #include "Halton.h" 
    6160 
    6261 
     
    127126string statsFilename("stats"); 
    128127 
     128string filename("city"); 
     129 
     130 
    129131/// the walkThroughRecorder 
    130132WalkThroughRecorder *walkThroughRecorder = NULL; 
     
    428430                env.GetStringParam(string("recordedFramesSuffix"), recordedFramesSuffix); 
    429431                env.GetStringParam(string("statsFilename"), statsFilename); 
     432                env.GetStringParam(string("filename"), filename); 
    430433 
    431434                //env.GetStringParam(string("modelPath"), model_path); 
     
    458461                cout << "recorded frames suffix: " << recordedFramesSuffix << endl; 
    459462                cout << "stats filename: " << statsFilename << endl; 
     463                cout << "filename: " << filename << endl; 
    460464 
    461465                //cout << "model path: " << model_path << endl; 
     
    528532        //-- load the static scene geometry 
    529533 
    530         LoadModel("city.dem", sceneEntities); 
     534        LoadModel(filename + ".dem", sceneEntities); 
    531535 
    532536 
     
    587591        //-- load the associated static bvh 
    588592 
    589         const string bvh_filename = string(model_path + "city.bvh"); 
     593        const string bvh_filename = string(model_path + filename + ".bvh"); 
    590594 
    591595        BvhLoader bvhLoader; 
     
    660664        frameTimer.Start(); 
    661665 
    662         Halton::TestHalton(7, 1); 
    663         Halton::TestHalton(7, 2); 
    664  
    665         HaltonSequence::TestHalton(15, 2); 
    666         HaltonSequence::TestHalton(15, 1); 
    667  
    668         Halton::TestPrime(); 
     666        //Halton::TestHalton(7, 2); 
     667        //HaltonSequence::TestHalton(15, 2); 
     668        //Halton::TestPrime(); 
    669669 
    670670        // the rendering loop 
Note: See TracChangeset for help on using the changeset viewer.