Changeset 1414


Ignore:
Timestamp:
09/18/06 10:52:24 (18 years ago)
Author:
mattausch
Message:

fixed kd tree loading / exporting

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

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h

    r1112 r1414  
    3232    mMin = nMin; mMax = nMax; 
    3333  } 
    34  
    35   //  AxisAlignedBox3(const Vector3 &center, const float radius):min(center - Vector3(radius)), 
    36   //                                                  max(center + Vector3(radius)) {} 
    3734 
    3835  /** initialization to the non existing bounding box 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp

    r1408 r1414  
    808808   
    809809#ifdef _DEBUG 
    810         cout << "\n\nobjects=(" << objectsBack.size() << "," << objectsFront.size() << " of " << tData.mNode->mObjects.size() << ")\t area=("  
     810        cout << "\n\nobjects=(" << (int)objectsBack.size() << "," << (int)objectsFront.size() << " of "  
     811                 << (int)tData.mNode->mObjects.size() << ")\t area=("  
    811812                 << areaLeft << "," << areaRight << ")" << endl; 
    812813        cout << "cost= " << minSum << endl; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp

    r1379 r1414  
    11431143                 "true"); 
    11441144 
    1145  
    11461145  RegisterOption("MeshKdTree.Termination.minCost", 
    11471146                 optInt, 
     
    14261425                                        "false"); 
    14271426 
    1428         RegisterOption("ViewCells.pruneEmptyViewCells", 
    1429                                         optBool, 
    1430                                         "view_cells_prune_empty=", 
    1431                                         "false"); 
    1432  
    14331427        RegisterOption("ViewCells.processOnlyValidViewCells", 
    14341428                                        optBool, 
     
    14361430                                        "false"); 
    14371431 
    1438          
    14391432        RegisterOption("ViewCells.PostProcess.maxCostRatio", 
    14401433                        optFloat, 
     
    17451738                                        "20"); 
    17461739 
     1740        RegisterOption("Preprocessor.exportKdTree",  
     1741                                        optBool, 
     1742                                        "preprocessor_export_kd_tree=", 
     1743                                        "false"); 
     1744 
     1745        RegisterOption("Preprocessor.loadKdTree",  
     1746                                        optBool, 
     1747                                        "preprocessor_load_kd_tree=", 
     1748                                        "false"); 
     1749 
     1750 
    17471751 
    17481752        /************************************************************************************/ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp

    r1387 r1414  
    13191319        if (!stream.is_open()) return false; 
    13201320 
     1321        // sort objects by their id 
    13211322        std::stable_sort(objects.begin(), objects.end(), ilt); 
    13221323 
     
    13241325        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
    13251326 
    1326         //-- compute bounding box 
     1327 
     1328        /////////////////////////// 
     1329        //-- compute bounding box of object space 
    13271330    for (oit = objects.begin(); oit != oit_end; ++ oit) 
    13281331        { 
    1329                 Intersectable *obj = *oit; 
    1330                 // compute bounding box of view space 
    1331                 mBox.Include(obj->GetBox()); 
    1332         } 
    1333  
    1334         DEL_PTR(mRoot); // we make a new root 
     1332                const AxisAlignedBox3 box = (*oit)->GetBox(); 
     1333                mBox.Include(box); 
     1334        } 
     1335 
     1336        // hack: we make a new root 
     1337        DEL_PTR(mRoot); 
    13351338   
    13361339        KdNode *node = LoadNextNode(stream, NULL, objects); 
     
    13771380                { 
    13781381                        EvaluateLeafStats(tData); 
    1379                         //Debug << "l" << endl; 
     1382                        cout << "l"; 
    13801383                } 
    13811384        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1405 r1414  
    580580 
    581581 
    582 bool Preprocessor::LoadKdTree() 
    583 { 
    584         return true; 
    585 } 
    586  
    587 bool Preprocessor::ExportKdTree() 
    588 { 
    589         return true; 
     582bool Preprocessor::LoadKdTree(const string filename) 
     583{ 
     584        mKdTree = new KdTree(); 
     585        return mKdTree->LoadBinTree(filename.c_str(), mObjects); 
     586} 
     587 
     588 
     589bool Preprocessor::ExportKdTree(const string filename) 
     590{ 
     591        return mKdTree->ExportBinTree(filename.c_str()); 
    590592} 
    591593 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r1381 r1414  
    120120  bool ExportSamples(const VssRayContainer &samples) const; 
    121121 
    122   bool LoadKdTree(); 
    123   bool ExportKdTree(); 
     122  bool LoadKdTree(const string filename); 
     123  bool ExportKdTree(const string filename); 
    124124 
    125125  /** Get Sample rays of particular type, returns false if this 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1404 r1414  
    7777        Environment::GetSingleton()->GetFloatValue("ViewCells.maxPvsRatio", mMaxPvsRatio); 
    7878         
    79         Environment::GetSingleton()->GetBoolValue("ViewCells.pruneEmptyViewCells", mPruneEmptyViewCells); 
    80  
    81         // HACK 
    82         if (0) 
    83                 mMinPvsSize = mPruneEmptyViewCells ? 1 : 0; 
    84         else 
    85                 mMinPvsSize = 0; 
    86  
    8779        Environment::GetSingleton()->GetBoolValue("ViewCells.processOnlyValidViewCells", mOnlyValidViewCells); 
    8880 
     
    196188        Debug << "export geometry: " << mExportGeometry << endl; 
    197189        Debug << "max pvs ratio: " << mMaxPvsRatio << endl; 
    198          
    199         Debug << "prune empty view cells: " << mPruneEmptyViewCells << endl; 
    200190         
    201191        Debug << "process only valid view cells: " << mOnlyValidViewCells << endl; 
     
    338328         
    339329        long startTime = GetTime(); 
    340  
    341330        cout << "view cell construction: casting " << mInitialSamples << " initial samples ... "; 
     331 
    342332        // cast initial samples 
    343333        CastPassSamples(mInitialSamples, mSamplingType, initialSamples); 
     
    366356         
    367357        ResetViewCells(); 
    368         Debug << "\nView cells after initial sampling:\n" << mCurrentViewCellsStats << endl; 
    369  
    370  
    371         //-- optionally export initial view cells 
     358        if (0) Debug << "\nView cells after initial sampling:\n" << mCurrentViewCellsStats << endl; 
     359 
     360        //-- optionally export initial view cell partition 
    372361        if (0)  
    373362        { 
    374                 const char filename[] = "view_cells.wrl"; 
    375                 Exporter *exporter = Exporter::GetExporter(filename); 
     363                const string filename("viewcells.wrl"); 
     364                Exporter *exporter = Exporter::GetExporter(filename.c_str()); 
    376365         
    377366                if (exporter) 
    378367                { 
    379                         cout << "exporting initial view cells (=leaves) to " << filename << " ... "; 
     368                        cout << "exporting initial view cells (=leaves) to " << filename.c_str() << " ... "; 
     369 
    380370                        if (mExportGeometry) 
    381371                        { 
     
    399389        //-- note: guided rays could be used for this task 
    400390 
    401         // time spent after initial construction 
     391        // time spent after construction of the initial partition 
    402392        startTime = GetTime(); 
    403  
    404393        const int n = mConstructionSamples; //+initialSamples; 
    405394        // should we use directional samples? 
     
    439428 
    440429         
     430#if 0 
    441431        //////////////////////////////////////////////// 
    442432        //-- get stats after the additional sampling step 
     
    452442 
    453443    Debug << ss << endl; 
    454  
     444#endif 
    455445 
    456446 
     
    479469        PostProcess(preprocessor->mObjects, postProcessSamples); 
    480470 
    481         cout << "time needed for post processing (merge) step: " 
    482                  << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl; 
    483  
    484         Debug << "time needed for post processing (merge) step: " 
    485                  << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl; 
    486  
     471        const float secs = TimeDiff(startTime, GetTime()) * 1e-3f; 
     472        cout << "post processing (=merge) finished in " << secs << " secs" << endl; 
     473 
     474        Debug << "post processing time: " << secs << endl; 
    487475        disposeRays(postProcessSamples, outRays); 
    488476 
    489477         
    490         ///////////////////////////////////////////////////////////////////// 
     478        ////////////////////////////////////////////////////////////// 
    491479        //-- Evaluation of the resulting view cell partition.  
    492480        //-- We cast a number of new samples and measure the render cost 
     
    26162604        } 
    26172605         
    2618         // view cells already finished before post processing step (i.e. because they were loaded) 
     2606        // view cells already finished before post processing step, 
     2607        // i.e., because they were loaded from disc 
    26192608        if (mViewCellsFinished) 
    26202609        { 
     
    26252614        } 
    26262615 
    2627         /////////////////////////////////////// 
    2628         //-- post processing of bsp view cells 
    2629  
    26302616    int vcSize = 0; 
    26312617        int pvsSize = 0; 
    26322618 
    2633         //-- merge view cells 
    2634  
     2619         
     2620        /////////////////////// 
     2621        //-- merge leaves of the view cell hierarchy     
     2622         
    26352623        cout << "starting post processing using " << mPostProcessSamples << " samples ... "; 
    26362624        long startTime = GetTime(); 
     
    27482736        } 
    27492737         
    2750         // export bounding boxes 
    2751         if (0 && mExportBboxesForPvs) 
    2752         { 
    2753                 char filename[100]; 
    2754                 Environment::GetSingleton()->GetStringValue("ViewCells.boxesFilename", filename); 
    2755                 ExportBoundingBoxes(filename, objects); 
    2756         } 
    2757  
    2758  
    27592738        return 0; 
    27602739} 
     
    38333812                                                                                         const ObjectContainer &objects) 
    38343813{ 
    3835         Debug << "render time before refine:" << endl; 
    38363814        mRenderer->RenderScene(); 
    38373815        SimulationStatistics ss; 
    38383816        dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 
    3839     Debug << ss << endl; 
    3840  
     3817    Debug << "render time before refine\n" << ss << endl; 
     3818 
     3819        const long startTime = GetTime(); 
    38413820        cout << "Refining the merged view cells ... "; 
    3842         long startTime = GetTime(); 
    38433821 
    38443822        // refining the merged view cells 
     
    38853863        else 
    38863864        { 
    3887                 minPvs = mPruneEmptyViewCells ? 1 : 0; 
     3865                // problem matt: why did I start here from zero? 
     3866                minPvs = 0; 
    38883867                maxPvs = mMaxPvsSize; 
    38893868        } 
     
    39043883        Debug << "post processing using " << (int)postProcessRays.size() << " samples" << endl; 
    39053884 
    3906  
    3907         // should maybe be done here to allow merge working with area or volume 
    3908         // and to correct the rendering statistics 
     3885        // should maybe be done here to allow merge working  
     3886        // with area or volume and to correct the rendering statistics 
    39093887        if (0) FinalizeViewCells(false); 
    39103888                 
     3889        ////////////////////////////////////// 
    39113890        //-- merge the individual view cells 
    39123891        MergeViewCells(postProcessRays, objects); 
    39133892         
    3914  
    3915         // only for debugging purpose: test if the subdivision is valid 
    3916         if (0) TestSubdivision(); 
    3917  
     3893        ///////////////////////////////// 
    39183894        //-- refines the merged view cells 
    39193895        if (0) RefineViewCells(postProcessRays, objects); 
    39203896 
    3921          
     3897        /////////////////////////////////////////// 
    39223898        //-- render simulation after merge + refine 
    3923         cout << "\nevaluating bsp view cells render time before compress ... "; 
     3899 
     3900        cout << "\nview cells partition render time before compress"; 
    39243901        dynamic_cast<RenderSimulator *>(mRenderer)->RenderScene(); 
    39253902        SimulationStatistics ss; 
    39263903        dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 
    3927    
    3928  
    3929         cout << " finished" << endl; 
     3904  
    39303905        cout << ss << endl; 
    3931         Debug << ss << endl; 
    3932  
    3933  
     3906         
     3907 
     3908        /////////////////// 
    39343909        //-- compression 
     3910 
    39353911        if (ViewCellsTreeConstructed() && mCompressViewCells) 
    39363912        { 
     
    39603936                Environment::GetSingleton()->GetStringValue("ViewCells.filename", filename); 
    39613937                ExportViewCells(filename, mExportPvs, objects); 
    3962         } 
    3963  
    3964          
    3965         // export bounding boxes 
    3966         if (mExportBboxesForPvs) 
    3967         { 
    3968                 char filename[100]; 
    3969                 Environment::GetSingleton()->GetStringValue("ViewCells.boxesFilename", filename); 
    3970          
    3971                 ExportBoundingBoxes(filename, objects); 
    39723938        } 
    39733939 
     
    49064872        else 
    49074873        { 
    4908                 minPvs = mPruneEmptyViewCells ? 1 : 0; 
     4874                // problem matt: why did I start here from zero? 
     4875                minPvs = 0; 
    49094876                maxPvs = mMaxPvsSize; 
    49104877        } 
     
    49164883 
    49174884         
    4918         // area has to be recomputed 
     4885        // area is not up to date, has to be recomputed 
    49194886        mTotalAreaValid = false; 
    49204887        VssRayContainer postProcessRays; 
     
    49324899        mViewCellsTree->SetRoot(root); 
    49334900 
    4934         // compute pvs 
     4901        //////////////////////////////////// 
     4902        //-- update pvs in the whole hierarchy 
    49354903        ObjectPvs pvs; 
    49364904        UpdatePvsForEvaluation(root, pvs); 
    49374905 
    4938          
     4906 
     4907        /////////////////////////////////////////// 
    49394908        //-- render simulation after merge + refine 
    4940         cout << "\nevaluating bsp view cells render time before compress ... "; 
     4909 
     4910        cout << "\nview cells partition render time before compress"; 
    49414911        dynamic_cast<RenderSimulator *>(mRenderer)->RenderScene(); 
    49424912        SimulationStatistics ss; 
    49434913        dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 
    4944    
    4945  
    4946         cout << " finished" << endl; 
    49474914        cout << ss << endl; 
    4948         Debug << ss << endl; 
    4949  
    4950  
     4915         
     4916        /////////////////////// 
    49514917        //-- compression 
    49524918 
     
    49624928        } 
    49634929 
    4964         // compute final meshes and volume / area 
     4930        ///////////////////////////////////// 
     4931        //-- compute final meshes and volume / area 
    49654932        if (1) FinalizeViewCells(true); 
    49664933 
    4967         // write view cells to disc 
     4934 
     4935        // write out view cells 
    49684936        if (mExportViewCells) 
    49694937        { 
     
    49724940                ExportViewCells(filename, mExportPvs, objects); 
    49734941        } 
    4974  
    49754942 
    49764943        return 0; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1294 r1414  
    614614        /// the corresponding view cell tree holding the logical description of view cells 
    615615        ViewCellsTree *mViewCellsTree; 
    616         /// if empty view cells should be pruned (i.e., invalidated) from this point on 
    617         bool mPruneEmptyViewCells; 
    618  
     616         
    619617        /// if the values in the view cell leaves and the interiors are up to date 
    620618        /// this is meant for lazy storing of the pvs, where only a scalar indicating 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp

    r1404 r1414  
    593593  cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 
    594594 
    595   ExportRays("kdtree.x3d", mVssRays, 10); 
     595  if (0) ExportRays("kdtree.x3d", mVssRays, 10); 
    596596 
    597597  if (0) 
     
    692692  if (0) 
    693693  { 
    694         VssRayContainer viewCellRays; 
    695         // compute rays used for view cells construction 
    696         const int numRays = mViewCellsManager->GetVisualizationSamples(); 
    697         vssTree->CollectRays(viewCellRays, numRays); 
    698   } 
    699  
    700   //-- render simulation after merge 
    701   cout << "\nevaluating bsp view cells render time after sampling ... "; 
    702   Debug << "\nStatistics after sampling: " << endl; 
     694          VssRayContainer viewCellRays; 
     695          // compute rays used for view cells construction 
     696          const int numRays = mViewCellsManager->GetVisualizationSamples(); 
     697          vssTree->CollectRays(viewCellRays, numRays); 
     698  } 
     699 
     700 
     701  ////////////////////////////////// 
     702  //-- render simulation after  
    703703 
    704704  mRenderSimulator->RenderScene(); 
    705705  SimulationStatistics ss; 
    706706  mRenderSimulator->GetStatistics(ss); 
    707    
    708   cout << " finished" << endl; 
    709   cout << ss << endl; 
    710   Debug << ss << endl; 
     707  Debug << "\nFinal view cells partition render time\n" << ss << endl; 
     708  cout << "\nFinal view cells partition render time\n" << ss << endl; 
    711709 
    712710  delete vssTree; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r1408 r1414  
    180180        Environment::GetSingleton()->GetBoolValue("Preprocessor.loadKdTree", loadKdTree); 
    181181 
     182        const string kdtreename("kd.bin.gz"); 
     183 
    182184        if (!loadKdTree) 
    183185        { 
    184                 //-- build kd tree from scene geometry 
     186                //-- build new kd tree from scene geometry 
    185187                preprocessor->BuildKdTree(); 
    186188                preprocessor->KdTreeStatistics(cout); 
     
    188190        else 
    189191        { 
     192                const long startTime = GetTime(); 
    190193                cout << "loading kd tree ... "; 
     194 
     195                if (!preprocessor->LoadKdTree(kdtreename)) 
     196                { 
     197                        cout << "error loading kd tree with filename " << kdtreename << endl; 
     198                        Cleanup(); 
     199                        exit(1); 
     200                } 
     201                cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     202 
     203                if (0) 
     204                { 
     205                        Exporter *exporter = Exporter::GetExporter("dummykd.x3d"); 
     206                         
     207                        if (exporter) 
     208                        { 
     209                                exporter->ExportKdTree(*preprocessor->mKdTree, true); 
     210                                delete exporter; 
     211                        } 
     212                } 
     213        } 
     214 
     215        Environment::GetSingleton()->GetBoolValue("Preprocessor.exportKdTree", exportKdTree); 
     216 
     217        if (exportKdTree) 
     218        { 
    191219                const long startTime = GetTime(); 
    192                 preprocessor->mKdTree->LoadBinTree("kd.bin.gz", preprocessor->mObjects); 
    193                          
    194                 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    195         } 
    196  
    197         Environment::GetSingleton()->GetBoolValue("Preprocessor.exportKdTree", exportKdTree); 
    198  
    199         if (exportKdTree) 
    200         { 
    201220                cout << "exporting kd tree ... "; 
    202                 preprocessor->mKdTree->ExportBinTree("kd.bin.gz"); 
    203                 cout << "finished" << endl; 
     221                if (!preprocessor->ExportKdTree(kdtreename)) 
     222                { 
     223                        cout << " error exporting kd tree with filename " << kdtreename << endl; 
     224                } 
     225                else 
     226                { 
     227                        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     228                } 
    204229        } 
    205230 
Note: See TracChangeset for help on using the changeset viewer.