Changeset 1634


Ignore:
Timestamp:
10/18/06 01:49:50 (18 years ago)
Author:
mattausch
Message:

multiple path support for kd

Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp

    r1633 r1634  
    581581inline bool BvHierarchy::LocalTerminationCriteriaMet(const BvhTraversalData &data) const 
    582582{ 
    583         // matt: TODO 
    584583        return ( 0 
    585                 || ((int)data.mNode->mObjects.size() <= mTermMinObjects) 
    586                 //|| (data.mProbability <= mTermMinProbability) 
    587                 //|| (data.mNumRays <= mTermMinRays) 
     584                        || ((int)data.mNode->mObjects.size() <= mTermMinObjects) 
     585                        //|| (data.mProbability <= mTermMinProbability) 
     586                        //|| (data.mNumRays <= mTermMinRays) 
    588587                 ); 
    589588} 
     
    12291228                                        HierarchyManager::KD_BASED_VIEWSPACE_SUBDIV) 
    12301229                                { 
     1230                                        /////////// 
    12311231                                        //-- heuristics using objects weighted by view cells volume 
    12321232                                        nCostRatio[axis] = 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1633 r1634  
    330330 
    331331        // number of initial splits 
    332         int maxSteps = 200; 
    333         float renderCostDecr = 0; 
     332        int minSteps = 200; 
     333        float renderCostDecr = Limits::Infinity; 
    334334 
    335335        SubdivisionCandidate *osc =  
     
    347347        // has started, use render cost heuristics instead 
    348348        const int ospSteps =  
    349                 RunConstruction(objectSpaceQueue, dirtyVspList, renderCostDecr, maxSteps); 
     349                RunConstruction(objectSpaceQueue, dirtyVspList, renderCostDecr, minSteps); 
    350350 
    351351        cout << ospSteps << " object space partition steps taken" << endl; 
     
    376376                { 
    377377                        // use splits of one kind until rendercost slope is reached 
    378                         renderCostDecr = mHierarchyStats.mRenderCostDecrease; 
     378                        //renderCostDecr = mHierarchyStats.mRenderCostDecrease; 
     379                         
     380                        // lower number of minsteps: this should be solved  
     381                        // with render cost decrease from now 
     382                        //minSteps = 5;  
    379383 
    380384                        // dirtied view space candidates 
     
    385389                        // has started, use render cost heuristics instead 
    386390                        const int ospSteps =  
    387                                 RunConstruction(objectSpaceQueue, dirtyVspList, renderCostDecr, maxSteps); 
     391                                RunConstruction(objectSpaceQueue, dirtyVspList, renderCostDecr, minSteps); 
    388392 
    389393                        cout << ospSteps << " object space partition steps taken" << endl; 
     
    400404                { 
    401405                        // use splits of one kind until rendercost slope is reached 
    402                         renderCostDecr = mHierarchyStats.mRenderCostDecrease; 
     406                //      renderCostDecr = mHierarchyStats.mRenderCostDecrease; 
    403407 
    404408                        ///////////////// 
     
    409413                        // process view space candidates 
    410414                        const int vspSteps =  
    411                                 RunConstruction(viewSpaceQueue, dirtyOspList, renderCostDecr, maxSteps); 
     415                                RunConstruction(viewSpaceQueue, dirtyOspList, renderCostDecr, minSteps); 
    412416 
    413417                        cout << vspSteps << " view space partition steps taken" << endl; 
     
    480484 
    481485        // begin subdivision 
    482         RunConstruction(mRepairQueue, sampleRays, objects, forcedViewSpace); 
     486        RunConstruction(mRepairQueue,  
     487                                        sampleRays,  
     488                                        objects,  
     489                                        forcedViewSpace//,  
     490                                        /*vspSc*/); 
    483491         
    484492        cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     
    760768                                                                          SubdivisionCandidateContainer &dirtyCandidates, 
    761769                                                                          const float minRenderCostDecr, 
    762                                                                           const int maxSteps) 
     770                                                                          const int minSteps) 
    763771{ 
    764772        int steps = 0; 
     
    766774 
    767775        // main loop 
    768         while (!splitQueue.Empty() && (steps < maxSteps)) 
     776        while (!splitQueue.Empty()) 
    769777        { 
    770778                SubdivisionCandidate *sc = NextSubdivisionCandidate(splitQueue);  
    771779                 
    772780                // minimum slope reached 
    773                 //if (sc->GetRenderCostDecrease() < minRenderCostDecr)  break; 
     781                if ((sc->GetRenderCostDecrease() < minRenderCostDecr) && 
     782                        !(steps < minSteps)) 
     783                        break; 
    774784 
    775785                //////// 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r1633 r1634  
    263263                                                SubdivisionCandidateContainer &chosenCandidates, 
    264264                                                const float minRenderCostDecr, 
    265                                                 const int maxSteps); 
     265                                                const int minSteps); 
    266266 
    267267        /** Default subdivision method. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1633 r1634  
    822822{ 
    823823        // always try to load the kd tree 
    824         bool loadKdTree = true; 
    825         //Environment::GetSingleton()->GetBoolValue("Preprocessor.loadKdTree", loadKdTree); 
    826                  
    827         if (!loadKdTree) 
    828         {        
     824        cout << "loading kd tree file " << internKdTree << " ... "; 
     825 
     826        if (!LoadKdTree(internKdTree)) 
     827        { 
     828                cout << "error loading kd tree with filename " << internKdTree << ", rebuilding it instead ... " << endl; 
    829829                // build new kd tree from scene geometry 
    830830                BuildKdTree(); 
    831         } 
    832         else 
    833         { 
    834                 cout << "loading kd tree file " << internKdTree << " ... "; 
    835  
    836                 if (!LoadKdTree(internKdTree)) 
    837                 { 
    838                         cout << "error loading kd tree with filename " << internKdTree << ", rebuilding it instead ... " << endl; 
    839                         BuildKdTree(); 
    840                 } 
    841831 
    842832                // export kd tree? 
     
    866856                        delete exporter; 
    867857                } 
    868  
    869                 /*ofstream objstr("objects.txt"); 
    870  
    871                 vector<KdLeaf *> leaves; 
    872                 mKdTree->CollectLeaves(leaves); 
    873  
    874                 vector<KdLeaf *>::const_iterator lit, lit_end = leaves.end(); 
    875                 for (lit = leaves.begin(); lit != lit_end; ++ lit) 
    876                 { 
    877                         objstr << "objects: " << (*lit)->mObjects.size() << " bb " << mKdTree->GetBox(*lit) << endl; 
    878                 }*/ 
    879         } 
    880  
     858        } 
    881859 
    882860        int rayCastMethod; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/common.cpp

    r863 r1634  
    218218 
    219219char * 
     220StripPath(const char *s) 
     221{ 
     222        const int len = strlen(s); 
     223 
     224        int i = len; 
     225        for (; i>0; i--) { 
     226                if (s[i]=='/' || s[i]=='\\') 
     227                        break; 
     228        } 
     229 
     230        char *filename = new char[len - i]; 
     231        int j = 0; 
     232 
     233        for (; j < len - i; ++ j) 
     234                filename[j] = s[i + j + 1]; 
     235        //filename[j] = 0; 
     236 
     237        return filename; 
     238} 
     239 
     240char * 
    220241strdup(char *a) 
    221242{ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/common.h

    r1557 r1634  
    499499GetPath(const char *s); 
    500500 
     501char * 
     502StripPath(const char *s); 
    501503} 
    502504 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r1633 r1634  
    2020#include "MeshKdTree.h" 
    2121#include "Preprocessor.h" 
    22  
     22#include "common.h" 
    2323 
    2424#include "PreprocessorThread.h" 
     
    7373 
    7474 
    75 static string GetInternKdTreeName(string &filename) 
    76 { 
    77         //Environment::GetSingleton()->GetStringValue("Preprocessor.kdTreeFilename", internKdTree); 
    78         string suffix; 
    79  
    80         if (preprocessor->mLoadMeshes) 
    81         { 
    82                 suffix = ".kdm";         
    83         } 
    84         else 
    85         { 
    86                 suffix = ".kdt"; 
    87         } 
    88  
    89         // hack! should take any extension 
    90     if (strstr(filename.c_str(), ".x3d"))  
    91         { 
    92                 return ReplaceSuffix(filename, ".x3d", suffix); 
    93         }  
    94         else if (strstr(filename.c_str(), ".dat")) 
    95         { 
    96                 return ReplaceSuffix(filename, ".dat", suffix); 
    97         }  
    98         else if (strstr(filename.c_str(), ".obj")) 
    99         { 
    100                 return ReplaceSuffix(filename, ".dat", suffix); 
    101         } 
    102  
    103         cerr << "Error: Currently unsupported format for kd, filename " << filename << endl; 
    104  
    105         // return empty string 
    106         return string(); 
     75static int SplitFilenames(const string str, vector<string> &filenames) 
     76{ 
     77        int pos = 0; 
     78 
     79        while(1) { 
     80                int npos = (int)str.find(';', pos); 
     81                 
     82                if (npos < 0 || npos - pos < 1) 
     83                        break; 
     84                filenames.push_back(string(str, pos, npos - pos)); 
     85                pos = npos + 1; 
     86        } 
     87         
     88        filenames.push_back(string(str, pos, str.size() - pos)); 
     89        return (int)filenames.size(); 
     90} 
     91 
     92 
     93static string GetInternKdTreeName(const string &filename) 
     94{ 
     95        vector<string> filenames; 
     96        const int files = SplitFilenames(filename, filenames); 
     97 
     98        vector<string>::const_iterator sit, sit_end = filenames.end(); 
     99        string kdFilename; 
     100 
     101        int i = 0; 
     102        for (sit = filenames.begin(); sit != sit_end; ++ sit, ++ i) 
     103        { 
     104                string currentFile = *sit; 
     105                //cout << "here6 " << currentFile << endl; 
     106                string strippedFilename; 
     107 
     108                if (i == 0) 
     109                {        
     110                        strippedFilename = currentFile; 
     111                } 
     112                else 
     113                { 
     114                        strippedFilename = string(StripPath(currentFile.c_str())); 
     115                } 
     116                 
     117                string suffix("_"); 
     118 
     119                if (i == (int)filenames.size() - 1) 
     120                { 
     121                        if (preprocessor->mLoadMeshes) 
     122                        { 
     123                                suffix = ".kdm";         
     124                        } 
     125                        else 
     126                        { 
     127                                suffix = ".kdt"; 
     128                        } 
     129                } 
     130 
     131                if (strstr(strippedFilename.c_str(), ".x3d"))  
     132                { 
     133                        kdFilename += ReplaceSuffix(strippedFilename, ".x3d", suffix); 
     134                } 
     135        else if (strstr(strippedFilename.c_str(), ".dat")) 
     136                { 
     137                        kdFilename += ReplaceSuffix(strippedFilename, ".dat", suffix); 
     138                }  
     139                else if (strstr(strippedFilename.c_str(), ".obj")) 
     140                { 
     141                        kdFilename += ReplaceSuffix(strippedFilename, ".dat", suffix); 
     142                } 
     143                else 
     144                { 
     145                        cerr << "Error: Currently unsupported format for kd, filename " << currentFile << endl; 
     146                } 
     147        } 
     148 
     149        //cout << "kdfilename: " << kdFilename << endl; 
     150        return kdFilename; 
    107151} 
    108152 
     
    150194        Environment::GetSingleton()->GetStringValue("Scene.filename", buff); 
    151195        string filename(buff); 
     196        const string dummyname = GetInternKdTreeName(filename); 
    152197 
    153198        if (!preprocessor->LoadScene(filename)) 
Note: See TracChangeset for help on using the changeset viewer.