Ignore:
Timestamp:
08/18/06 17:25:57 (18 years ago)
Author:
szydlowski
Message:
 
Location:
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTree.cpp

    r1215 r1220  
    3030                                .addOpt("l","logfile", ARGUMENT_REQUIRED) 
    3131                                .addOpt("d","demomode", ARGUMENT_NONE) 
     32                                .addOpt("","buildmode", ARGUMENT_REQUIRED) 
    3233                                .addOpt("","maxdepth", ARGUMENT_REQUIRED) 
    3334                                .addOpt("","kt", ARGUMENT_REQUIRED) 
     
    4950                        std::stringstream s; 
    5051 
     52                        if (cmdparser.getOpt("buildmode", tmp)) 
     53                        { 
     54                                int bm = KdTree::KDBM_NOTSET; 
     55                                for (int i = 0; i < KdTree::KDBM_SIZE; i ++) 
     56                                { 
     57                                        if (tmp == KdTreeAppListener::BUILDMETHOD[i]) 
     58                                                bm = i; 
     59                                } 
     60                                if (bm != KdTree::KDBM_NOTSET) 
     61                                { 
     62                                        options.mBuildMethod = bm; 
     63                                } 
     64                                else 
     65                                { 
     66                                        MessageBox(NULL, ("Invalid argument for option --buildmode: " + tmp).c_str(), "Error", MB_OK | MB_ICONERROR ); 
     67                                        return -1; 
     68                                } 
     69                        } 
     70 
    5171                        if (cmdparser.getOpt("maxdepth", tmp)) 
    5272                        { 
     
    7292                        if (cmdparser.getOpt("r",tmp)) 
    7393                        { 
    74                                 if (tmp == "INT" || tmp == "VFC" || tmp == "SWC" || tmp == "CHC") 
    75                                 { 
    76                                         options.mRenderMethod = tmp; 
     94                                int rm = KdTree::KDRM_NOTSET; 
     95                                for (int i = 0; i < KdTree::KDRM_SIZE; i ++) 
     96                                { 
     97                                        if (tmp == KdTreeAppListener::RENDERMETHOD[i]) 
     98                                                rm = i; 
     99                                } 
     100                                if (rm != KdTree::KDRM_NOTSET) 
     101                                { 
     102                                        options.mRenderMethod = rm; 
    77103                                } 
    78104                                else 
    79105                                { 
    80                                         MessageBox(NULL, ("Invalid argument for option --rendermethod: " + tmp).c_str(), "Error", MB_OK | MB_ICONERROR ); 
     106                                        MessageBox(NULL, ("Invalid argument for option --rendermode: " + tmp).c_str(), "Error", MB_OK | MB_ICONERROR ); 
    81107                                        return -1; 
    82108                                } 
     
    85111                        if (cmdparser.getOpt("s",tmp)) 
    86112                        { 
    87                                 if (tmp == "KDT" || tmp == "OCT" || tmp == "OCM" || tmp == "GEN") 
    88                                 { 
    89                                         options.mSceneManager = tmp; 
     113                                int sm = KdTreeAppListener::SM_NOTSET; 
     114                                for (int i = 0; i < KdTreeAppListener::SM_SIZE; i ++) 
     115                                { 
     116                                        if (tmp == KdTreeAppListener::SCENEMANAGER[i]) 
     117                                                sm = i; 
     118                                } 
     119                                if (sm != KdTreeAppListener::SM_NOTSET) 
     120                                { 
     121                                        options.mSceneManager = sm; 
    90122                                } 
    91123                                else 
     
    149181        cfDeath.load("testKdTree.cfg"); 
    150182 
    151         mSelectedSceneManager = cfDeath.getSetting("scenemanager"); 
    152183        mSceneFiles = cfDeath.getSetting("scene"); 
    153184 
     
    194225                mOptions.mDemoOutfileName = cfDeath.getSetting("demooutfile"); 
    195226 
    196         // set default demo output name to avoid SNAFUs 
    197         //if (mOptions.mDemoOutfileName.empty()) 
    198         //      mOptions.mDemoOutfileName = "demo.bin"; 
    199  
    200227        if (mOptions.mDemoLogfileName.empty()) 
    201228                mOptions.mDemoLogfileName = cfDeath.getSetting("demologfile"); 
    202  
    203         // set default demo logfile name to avoid SNAFUs 
    204         //if (mOptions.mDemoLogfileName.empty()) 
    205         //      mOptions.mDemoLogfileName = "demo.csv"; 
    206  
    207         // override scene manager set in config file 
    208         if (!mOptions.mSceneManager.empty()) 
    209         { 
    210                 if (mOptions.mSceneManager == "KDT") 
    211                         mSelectedSceneManager = "KdTreeSceneManager"; 
    212                 else if (mOptions.mSceneManager == "OCT") 
    213                         mSelectedSceneManager = "OctreeSceneManager"; 
    214                 else if (mOptions.mSceneManager == "OCM") 
    215                         mSelectedSceneManager = "OcclusionCullingSceneManager"; 
    216                 else if (mOptions.mSceneManager == "GEN") 
    217                         mSelectedSceneManager = "DefaultSceneManager"; 
    218         } 
    219         // the other way round for log 
    220         else 
    221         { 
    222                 if (mSelectedSceneManager == "KdTreeSceneManager") 
    223                         mOptions.mSceneManager = "KDT"; 
    224                 else if (mSelectedSceneManager == "OctreeSceneManager") 
    225                         mOptions.mSceneManager = "OCT"; 
    226                 else if (mSelectedSceneManager == "OcclusionCullingSceneManager") 
    227                         mOptions.mSceneManager = "OCM"; 
    228                 else if (mSelectedSceneManager == "DefaultSceneManager") 
    229                         mOptions.mSceneManager = "GEN"; 
    230         } 
    231229 
    232230        ExampleApplication::setupResources(); 
     
    416414{ 
    417415        // Get the SceneManager 
    418         mSceneMgr = mRoot->createSceneManager(mSelectedSceneManager,"MySceneManager"); 
    419         // set params 
    420         mSceneMgr->setOption("KdTreeMaxDepth", &mOptions.mMaxDepth); 
    421         mSceneMgr->setOption("KT", &mOptions.mKT); 
    422         mSceneMgr->setOption("KI", &mOptions.mKI); 
    423         mSceneMgr->setOption("RenderMethod", &mOptions.mRenderMethod); 
    424         mSceneMgr->setOption("EnhancedVisibility", &mOptions.mEnhancedVisibility); 
     416        mSceneMgr = mRoot->createSceneManager( 
     417                KdTreeAppListener::SCENEMANAGERNAME[mOptions.mSceneManager], 
     418                "MySceneManager"); 
     419        // set params depending on scene manager 
     420        if (mOptions.mSceneManager == KdTreeAppListener::SM_KDT) 
     421        { 
     422                mSceneMgr->setOption("BuildMethod", &mOptions.mBuildMethod); 
     423                mSceneMgr->setOption("KdTreeMaxDepth", &mOptions.mMaxDepth); 
     424                mSceneMgr->setOption("KT", &mOptions.mKT); 
     425                mSceneMgr->setOption("KI", &mOptions.mKI); 
     426                mSceneMgr->setOption("RenderMethod", &mOptions.mRenderMethod); 
     427                mSceneMgr->setOption("EnhancedVisibility", &mOptions.mEnhancedVisibility); 
     428        } 
     429        // set algorithm when scene manager is OCM - numbering is different though 
     430        if (mOptions.mSceneManager == KdTreeAppListener::SM_OCM) 
     431        { 
     432                int alg = CONV_KDT_TO_OCM_ALG(mOptions.mRenderMethod); 
     433                mSceneMgr->setOption("Algorithm", &alg); 
     434        } 
    425435} 
    426436 
     
    452462        mTopCam->setDirection(0,0,-1); 
    453463        mTopCam->pitch(Radian(-Math::HALF_PI)); 
    454         //mTopCam->setCullingFrustum(mCamera); 
     464        mTopCam->setCullingFrustum(mCamera); 
    455465        mTopCam->setNearClipDistance(1); 
    456466 
  • GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTreeAppListener.cpp

    r1215 r1220  
    66#include <windows.h> 
    77 
     8const Real       KdTreeAppListener::DEMO_WAIT = 5.0; 
    89const String KdTreeAppListener::NA = ": N/A"; 
    9 const Real KdTreeAppListener::DEMO_WAIT = 5.0; 
     10const String KdTreeAppListener::RENDERMETHOD[] = { "INT", "VFC", "SWC", "CHC" }; 
     11const String KdTreeAppListener::RENDERMETHODCAPTION[] = 
     12{ 
     13        "Internal Frustum Culling", 
     14        "View Frustum Culling",  
     15        "Stop and Wait Culling", 
     16        "Coherent Hierarchical Culling" 
     17}; 
     18const String KdTreeAppListener::BUILDMETHOD[] = { "RE", "PQ" }; 
     19const String KdTreeAppListener::BUILDMETHODCAPTION[] = { "Recursive", "Priority Queue" }; 
     20const String KdTreeAppListener::SCENEMANAGER[] = { "KDT", "OCM", "OCT", "GEN" }; 
     21const String KdTreeAppListener::SCENEMANAGERNAME[] = 
     22{ 
     23        "KdTreeSceneManager", 
     24        "OcclusionCullingSceneManager", 
     25        "OctreeSceneManager", 
     26        "DefaultSceneManager" 
     27}; 
    1028 
    1129void KdTreeAppListener::updateStats(void) 
     
    220238        const int border_height = 10; 
    221239        const int vert_space = 15; 
     240        int top = border_height; 
     241 
     242        String ext = "KdTree/"; 
    222243        String sMD, sKT, sKI, sHL, sBM, sRM, sFM, sTC, sEV; 
    223  
    224         int top = border_height; 
    225  
    226         String ext = "KdTree/"; 
    227244 
    228245        int maxd; 
     
    252269                sHL = ": off"; 
    253270 
    254         String bm; 
     271        int bm; 
    255272        if (mSceneMgr->getOption("BuildMethod", &bm)) 
    256                 sBM = ": " + bm; 
     273                sBM = ": " + BUILDMETHODCAPTION[bm]; 
    257274        else 
    258275                sBM = NA; 
    259276 
    260         String rm; 
     277        int rm; 
    261278        if (mSceneMgr->getOption("RenderMethod", &rm)) 
    262         { 
    263                 if (rm == "INT") 
    264                         sRM = ": Internal Frustum Culling"; 
    265                 else if (rm == "VFC") 
    266                         sRM = ": View Frustum Culling"; 
    267                 else if (rm == "SWC") 
    268                         sRM = ": Stop and Wait Culling"; 
    269                 else if (rm == "CHC") 
    270                         sRM = ": Coherent Hierarchical Culling"; 
    271                 else 
    272                         sRM = NA; 
    273         } 
     279                sRM = ": " + RENDERMETHODCAPTION[rm]; 
    274280        else 
    275281                sRM = NA; 
     282 
     283        // hack to allow mode switching in OCM 
     284        if (mOptions.mSceneManager == SM_OCM) 
     285        { 
     286                rm = CONV_KDT_TO_OCM_ALG(mOptions.mRenderMethod); 
     287                sRM = ": " + RENDERMETHODCAPTION[CONV_OCM_TO_KDT_ALG(rm)]; 
     288        } 
    276289 
    277290        bool enh; 
     
    430443void KdTreeAppListener::toggleBuildMethod() 
    431444{ 
    432         static String bmOptions[] = { "Recursive", "PriorityQueue" }; 
    433         static String bmOptionCaptions[] = { ": Recursive", ": PriorityQueue" }; 
    434         static int bmOptionsSize = sizeof(bmOptions) / sizeof(String); 
    435         static int bmCurrent = 0; 
    436  
    437         String bm; 
     445        int bm; 
     446 
    438447        if (mSceneMgr->getOption("BuildMethod", &bm)) 
    439448        { 
    440                 for (int idx = 0; idx < bmOptionsSize; idx++) 
    441                         if (bmOptions[idx] == bm) 
    442                                 bmCurrent = idx; 
    443                 bmCurrent = (bmCurrent + 1) % bmOptionsSize; 
    444                 if (mSceneMgr->setOption("BuildMethod", &bmOptions[bmCurrent])) 
    445                         mBuildMethodInfo->setCaption(bmOptionCaptions[bmCurrent]); 
     449                bm = (bm + 1) % KdTree::KDBM_SIZE; 
     450                if (mSceneMgr->setOption("BuildMethod", &bm)) 
     451                        mBuildMethodInfo->setCaption(": " + BUILDMETHODCAPTION[bm]); 
    446452        } 
    447453        else 
     
    453459void KdTreeAppListener::toggleRenderMethod() 
    454460{ 
    455         static String rmOptions[] = { "INT", "VFC", "SWC", "CHC" }; 
    456         static String rmOptionCaptions[] = 
    457         { 
    458                 ": Internal Frustum Culling", 
    459                 ": View Frustum Culling",  
    460                 ": Stop and Wait Culling", 
    461                 ": Coherent Hierarchical Culling" 
    462         }; 
    463         static int rmOptionsSize = sizeof(rmOptions) / sizeof (String); 
    464         static int rmCurrent = 0; 
    465  
    466         String rm; 
     461        int rm; 
     462 
    467463        if (mSceneMgr->getOption("RenderMethod", &rm)) 
    468464        { 
    469                 for (int idx = 0; idx < rmOptionsSize; idx++) 
    470                         if (rmOptions[idx] == rm) 
    471                                 rmCurrent = idx; 
    472                 rmCurrent = (rmCurrent + 1) % rmOptionsSize; 
    473                 if (mSceneMgr->setOption("RenderMethod", &rmOptions[rmCurrent])) 
    474                         mRenderMethodInfo->setCaption(rmOptionCaptions[rmCurrent]); 
     465                rm = (rm + 1) % KdTree::KDRM_SIZE; 
     466                if (mSceneMgr->setOption("RenderMethod", &rm)) 
     467                        mRenderMethodInfo->setCaption(": " + RENDERMETHODCAPTION[rm]); 
    475468        } 
    476469        else 
    477470        { 
    478471                mRenderMethodInfo->setCaption(NA); 
     472        } 
     473 
     474        // hack to allow mode switching in OCM, cannot extract setting from sm 
     475        if (mOptions.mSceneManager == SM_OCM) 
     476        { 
     477                static int alg = CONV_KDT_TO_OCM_ALG(mOptions.mRenderMethod); 
     478                alg = (alg + 1) % 3; 
     479                if (mSceneMgr->setOption("Algorithm", &alg)) 
     480                        mRenderMethodInfo->setCaption(": " + RENDERMETHODCAPTION[CONV_OCM_TO_KDT_ALG(alg)]); 
    479481        } 
    480482} 
     
    539541        } 
    540542 
    541         if (mInputDevice->isKeyDown(KC_F11) && mTimeUntilNextToggle <= 0) 
     543        if (mInputDevice->isKeyDown(KC_0) && mTimeUntilNextToggle <= 0) 
    542544        { 
    543545                toggleBuildMethod(); 
     
    15001502        { 
    15011503                // demo settings 
    1502                 logwrite << mOptions.mSceneManager; 
    1503                 if (mOptions.mSceneManager == "KDT") 
    1504                 { 
    1505                         logwrite << ds << mOptions.mRenderMethod << ds << mOptions.mMaxDepth << ds  
     1504                logwrite << SCENEMANAGER[mOptions.mSceneManager]; 
     1505                if (mOptions.mSceneManager == SM_KDT) 
     1506                { 
     1507                        logwrite << ds << RENDERMETHOD[mOptions.mRenderMethod] << ds << mOptions.mMaxDepth << ds  
    15061508                                << mOptions.mKT << ds << mOptions.mKI; 
    15071509                } 
    1508                 //else if (mOptions.mSceneManager == "OCM" && mOptions.mRenderMethod != "INT") 
    1509                 //{ 
    1510                 //      logwrite << ds << mOptions.mRenderMethod; 
    1511                 //} 
     1510                else if (mOptions.mSceneManager == SM_OCM && mOptions.mRenderMethod != KdTree::KDRM_INTERNAL) 
     1511                { 
     1512                        logwrite << ds << RENDERMETHOD[(mOptions.mRenderMethod+3)%3]; 
     1513                } 
    15121514                logwrite << fs; 
    15131515                // per second stats 
Note: See TracChangeset for help on using the changeset viewer.