Changeset 1279


Ignore:
Timestamp:
08/24/06 18:05:53 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
5 edited

Legend:

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

    r1272 r1279  
    499499        if ((int)(leaf->mObjects.size()) > mBvhStats.maxObjectRefs) 
    500500                mBvhStats.maxObjectRefs = (int)leaf->mObjects.size(); 
    501  
    502501} 
    503502 
     
    15941593} 
    15951594 
    1596 } 
    1597  
     1595 
     1596void BvhStatistics::Print(ostream &app) const 
     1597{ 
     1598        app << "=========== OspTree statistics ===============\n"; 
     1599 
     1600        app << setprecision(4); 
     1601 
     1602        app << "#N_CTIME  ( Construction time [s] )\n" << Time() << " \n"; 
     1603 
     1604        app << "#N_NODES ( Number of nodes )\n" << nodes << "\n"; 
     1605 
     1606        app << "#N_INTERIORS ( Number of interior nodes )\n" << Interior() << "\n"; 
     1607 
     1608        app << "#N_LEAVES ( Number of leaves )\n" << Leaves() << "\n"; 
     1609 
     1610        app << "#AXIS_ALIGNED_SPLITS (number of axis aligned splits)\n" << splits << endl; 
     1611 
     1612         
     1613        app << "#N_PMAXDEPTHLEAVES ( Percentage of leaves at maximum depth )\n"  
     1614                <<      maxDepthNodes * 100 / (double)Leaves() << endl; 
     1615 
     1616        app << "#N_PMINPVSLEAVES  ( Percentage of leaves with mininimal PVS )\n"  
     1617                << minPvsNodes * 100 / (double)Leaves() << endl; 
     1618 
     1619        app << "#N_MAXCOSTNODES  ( Percentage of leaves with terminated because of max cost ratio )\n" 
     1620                << maxCostNodes * 100 / (double)Leaves() << endl; 
     1621 
     1622        app << "#N_PMINPROBABILITYLEAVES  ( Percentage of leaves with mininum probability )\n" 
     1623                << minProbabilityNodes * 100 / (double)Leaves() << endl; 
     1624 
     1625        app << "#N_PMAXDEPTH ( Maximal reached depth )\n" << maxDepth << endl; 
     1626 
     1627        app << "#N_PMINDEPTH ( Minimal reached depth )\n" << minDepth << endl; 
     1628 
     1629        app << "#AVGDEPTH ( average depth )\n" << AvgDepth() << endl; 
     1630 
     1631        app << "#N_INVALIDLEAVES (number of invalid leaves )\n" << invalidLeaves << endl; 
     1632 
     1633        app << "#N_MAXOBJECTREFS  ( Max number of object refs / leaf )\n" << maxObjectRefs << "\n"; 
     1634 
     1635        //app << "#N_RAYS (number of rays / leaf)\n" << AvgRays() << endl; 
     1636         
     1637        app << "========== END OF VspTree statistics ==========\n"; 
     1638} 
     1639 
     1640 
     1641} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1264 r1279  
    3434 
    3535 
    36 HierarchyManager::HierarchyManager(VspTree &vspTree, OspTree &ospTree) 
    37 //:mVspTree(vspTree), mOspTree(ospTree) 
    38 { 
     36HierarchyManager::HierarchyManager(VspTree *vspTree,  
     37                                                                   const int objectSpaceSubdivisionType): 
     38mObjectSpaceSubdivisonType(objectSpaceSubdivisionType), 
     39mVspTree(vspTree),  
     40mOspTree(NULL),  
     41mBvHierarchy(NULL) 
     42{ 
     43        switch(mObjectSpaceSubdivisonType) 
     44        { 
     45        case KD_BASED_OBJ_SUBDIV: 
     46                mOspTree = new OspTree(); 
     47                mOspTree->mVspTree = mVspTree; 
     48                //mOspTree->mHierarchyManager = this; 
     49                Debug << "creating osp tree" << endl; 
     50                break; 
     51        case BV_BASED_OBJ_SUBDIV: 
     52        mBvHierarchy = new BvHierarchy(); 
     53                mBvHierarchy->mVspTree = mVspTree; 
     54                //mBvHierarchy->mHierarchyManager = this; 
     55                Debug << "creating bv hierachy" << endl; 
     56                break; 
     57        default: 
     58                break; 
     59        } 
     60 
     61        if (mVspTree) 
     62                mVspTree->mHierarchyManager = this; 
     63 
    3964        char subdivisionStatsLog[100]; 
    4065        Environment::GetSingleton()->GetStringValue("Hierarchy.subdivisionStats",  
    4166                subdivisionStatsLog); 
    4267        mSubdivisionStats.open(subdivisionStatsLog); 
     68} 
     69 
     70 
     71HierarchyManager::HierarchyManager(VspTree *vspTree, KdTree *kdTree):  
     72mObjectSpaceSubdivisonType(KD_BASED_OBJ_SUBDIV), 
     73mVspTree(vspTree),  
     74mBvHierarchy(NULL) 
     75{ 
     76        mOspTree = new OspTree(*kdTree); 
     77        mOspTree->mVspTree = mVspTree; 
     78 
     79        //mOspTree->mHierarchyManager = this; 
     80        Debug << "creating osp tree" << endl; 
     81 
     82        if (mVspTree) 
     83                mVspTree->mHierarchyManager = this; 
     84 
     85        char subdivisionStatsLog[100]; 
     86        Environment::GetSingleton()->GetStringValue("Hierarchy.subdivisionStats",  
     87                subdivisionStatsLog); 
     88        mSubdivisionStats.open(subdivisionStatsLog); 
     89} 
     90 
     91 
     92HierarchyManager::~HierarchyManager() 
     93{ 
     94        DEL_PTR(mOspTree); 
     95        //DEL_PTR(mVspTree); 
     96        DEL_PTR(mBvHierarchy); 
     97} 
     98 
     99 
     100void HierarchyManager::SetViewCellsManager(ViewCellsManager *vcm) 
     101{ 
     102        mVspTree->SetViewCellsManager(vcm); 
     103 
     104        if (mOspTree) 
     105                mOspTree->SetViewCellsManager(vcm); 
     106        if (mBvHierarchy) 
     107                mBvHierarchy->SetViewCellsManager(vcm); 
     108} 
     109 
     110 
     111void HierarchyManager::SetViewCellsTree(ViewCellsTree *vcTree) 
     112{ 
     113        mVspTree->SetViewCellsTree(vcTree); 
    43114} 
    44115 
     
    211282        mVspTree.mStoreObjectPvs = false; 
    212283#endif 
    213  
    214284        SubdivisionCandidate *vsc =  
    215285                mVspTree->PrepareConstruction(sampleRays, forcedViewSpace, *viewSpaceRays); 
    216  
     286         
    217287        // add to queue 
    218288        mTQueue.Push(vsc); 
     
    409479 
    410480 
    411 } 
     481void HierarchyManager::ExportObjectSpaceHierarchy(OUT_STREAM &stream) 
     482{ 
     483        // the type of the view cells hierarchy 
     484        switch (mObjectSpaceSubdivisonType) 
     485        { 
     486        case KD_BASED_OBJ_SUBDIV: 
     487                stream << "<ObjectSpaceHierarchy type=\"osp\">" << endl; 
     488                mOspTree->Export(stream); 
     489                stream << endl << "</ObjectSpaceHierarchy>" << endl; 
     490                break; 
     491                 
     492        case BV_BASED_OBJ_SUBDIV: 
     493                stream << "<ObjectSpaceHierarchy type=\"bvh\">" << endl; 
     494                mBvHierarchy->Export(stream); 
     495                stream << endl << "</ObjectSpaceHierarchy>" << endl; 
     496                break; 
     497        } 
     498} 
     499 
     500 
     501bool HierarchyManager::AddSampleToPvs(Intersectable *obj,  
     502                                                                          const Vector3 &hitPoint, 
     503                                                                          ViewCell *vc, 
     504                                                                          const float pdf,  
     505                                                                          float &contribution) const 
     506{ 
     507        if (!obj) return false; 
     508 
     509        switch (mObjectSpaceSubdivisonType) 
     510        { 
     511        case NO_OBJ_SUBDIV: 
     512                // potentially visible objects 
     513                return vc->AddPvsSample(obj, pdf, contribution); 
     514 
     515        case KD_BASED_OBJ_SUBDIV: 
     516                { 
     517                        // potentially visible kd cells 
     518                        KdLeaf *leaf = mOspTree->GetLeaf(hitPoint/*ray->mOriginNode*/); 
     519                        return mOspTree->AddLeafToPvs(leaf, vc, pdf, contribution); 
     520                } 
     521        case BV_BASED_OBJ_SUBDIV: 
     522                { 
     523                        BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 
     524                        return mBvHierarchy->AddLeafToPvs(leaf, vc, pdf, contribution); 
     525                } 
     526        default: 
     527                return false; 
     528        } 
     529} 
     530 
     531 
     532void HierarchyManager::PrintObjectSpaceHierarchyStatistics(ofstream &stream) const 
     533{ 
     534        switch (mObjectSpaceSubdivisonType) 
     535        { 
     536        case KD_BASED_OBJ_SUBDIV: 
     537                { 
     538                        stream << mOspTree->GetStatistics(); 
     539                        break; 
     540                } 
     541        case BV_BASED_OBJ_SUBDIV: 
     542                { 
     543                        stream << mBvHierarchy->GetStatistics(); 
     544                        break; 
     545                } 
     546        default: 
     547                break; 
     548        } 
     549} 
     550 
     551 
     552void HierarchyManager::ExportObjectSpaceHierarchyForViz(const ObjectContainer &objects) const 
     553{ 
     554        if (mOspTree && mOspTree->GetRoot())  
     555        {        
     556                //-- export final object partition 
     557                Exporter *exporter = Exporter::GetExporter("final_object_partition.wrl"); 
     558                 
     559                if (exporter) 
     560                { 
     561                        cout << "exporting object space partition ... "; 
     562 
     563                        if (1) 
     564                        { 
     565                                exporter->ExportGeometry(objects); 
     566                        } 
     567                         
     568#if 0            
     569                        // export rays 
     570                        exporter->ExportRays(visRays, RgbColor(0, 1, 0)); 
     571#endif 
     572 
     573                        exporter->SetWireframe(); 
     574         
     575                        const int colorCode = 0; 
     576                        const int maxPvs = 200;//mOspTree.GetStatistics().maxPvs; 
     577 
     578                        exporter->ExportOspTree(*mOspTree, colorCode == 0 ? 0 : maxPvs); 
     579 
     580                        delete exporter; 
     581 
     582                        cout << "finished" << endl; 
     583                } 
     584        } 
     585} 
     586 
     587} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r1259 r1279  
    8989        friend OspTree; 
    9090        friend BvHierarchy; 
     91        friend ViewCellsParseHandlers; 
    9192 
    9293public: 
    93         /** Constructor taking an object space partition and a view space partition tree. 
    94         */ 
    95         HierarchyManager(VspTree &vspTree, OspTree &ospTree); 
     94        /** Constructor with the object space hierarchy type as argument. 
     95        */ 
     96        HierarchyManager(VspTree *vspTree, const int objectSpaceHierarchyType); 
     97        /** Hack: OspTree will copy the content from this kd tree. 
     98                Only view space hierarchy will be constructed. 
     99        */ 
     100        HierarchyManager(VspTree *vspTree, KdTree *kdTree); 
    96101 
    97102        /** Constructs the view space and object space subdivision from a given set of rays 
     
    130135        } 
    131136         
     137        void SetViewCellsManager(ViewCellsManager *vcm); 
     138 
     139        void SetViewCellsTree(ViewCellsTree *vcTree); 
     140 
     141        void ExportObjectSpaceHierarchy(OUT_STREAM &stream); 
     142 
     143        bool AddSampleToPvs( 
     144                Intersectable *obj,  
     145                const Vector3 &hitPoint, 
     146                ViewCell *vc, 
     147                const float pdf,  
     148                float &contribution) const; 
     149 
     150        void PrintObjectSpaceHierarchyStatistics(ofstream &stream) const; 
     151 
     152        VspTree *GetVspTree() { return mVspTree; } 
     153 
     154        void ExportObjectSpaceHierarchyForViz(const ObjectContainer &objects) const; 
     155 
    132156protected: 
    133157 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1272 r1279  
    1717#include "ObjParser.h" 
    1818#include "BvHierarchy.h" 
     19#include "HierarchyManager.h" 
    1920 
    2021#ifdef GTP_INTERNAL 
     
    125126mVspBspTree(NULL), 
    126127mVspTree(NULL), 
    127 mOspTree(NULL), 
    128 mBvHierarchy(NULL), 
     128mHierarchyManager(NULL), 
    129129mViewCellsManager(NULL), 
    130130mRenderSimulator(NULL), 
    131 mPass(0) 
     131mPass(0), 
     132mRayCastMethod(0) 
    132133{ 
    133134        Environment::GetSingleton()->GetBoolValue("Preprocessor.useGlRenderer", mUseGlRenderer); 
     
    142143        Environment::GetSingleton()->GetBoolValue("Preprocessor.detectEmptyViewSpace", mDetectEmptyViewSpace); 
    143144        Environment::GetSingleton()->GetBoolValue("Preprocessor.exportVisibility", mExportVisibility ); 
     145//#if GTP_INTERNAL // choose other ray cast method 
    144146        Environment::GetSingleton()->GetIntValue("Preprocessor.rayCastMethod", mRayCastMethod); 
    145  
     147//#endif 
    146148        char buffer[256]; 
    147149        Environment::GetSingleton()->GetStringValue("Preprocessor.visibilityFile",  buffer); 
     
    177179  cout << "done.\n"; 
    178180 
    179   cout << "Deleting osp tree...\n"; 
    180   DEL_PTR(mOspTree); 
     181  cout << "Deleting hierarchy manager...\n"; 
     182  DEL_PTR(mHierarchyManager); 
    181183  cout << "done.\n"; 
    182184 
     
    479481        { 
    480482                mVspTree = new VspTree(); 
    481                 //mOspTree = new OspTree(); 
    482                  
     483                                 
    483484                // HACK for testing if per kd evaluation works!! 
    484                 mOspTree = new OspTree(*mKdTree); 
    485  
    486                 mViewCellsManager = new VspOspViewCellsManager(vcTree, mVspTree, mOspTree); 
     485                const bool ishack = true; 
     486 
     487                if (ishack) 
     488                { 
     489                        mHierarchyManager = new HierarchyManager(mVspTree, mKdTree); 
     490                } 
     491                else 
     492                { 
     493                        mHierarchyManager = new HierarchyManager(mVspTree, HierarchyManager::KD_BASED_OBJ_SUBDIV); 
     494                } 
     495 
     496                mViewCellsManager = new VspOspViewCellsManager(vcTree, mHierarchyManager); 
    487497        } 
    488498        else if (strcmp(name, "sceneDependent") == 0) 
     
    500510        } 
    501511 
    502         //vcTree->SetViewCellsManager(mViewCellsManager); 
    503512        return mViewCellsManager; 
    504513} 
     
    767776        //      return new ObjectsInteriorDistribution(*this); 
    768777        default: // no valid strategy 
     778                Debug << "warning: no valid sampling strategy" << endl; 
    769779                return NULL; 
    770780        } 
     
    844854                //Debug << "intel ray: " << *vssRay << endl; 
    845855        } 
     856 
    846857        //cout << "a"; 
    847858        return hits; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r1272 r1279  
    2525class GlRendererBuffer; 
    2626class VspTree; 
    27 class OspTree; 
     27class HierarchyManager; 
    2828class BvHierarchy; 
    2929class Intersectable; 
     
    178178  // view space partition tree 
    179179  VspTree *mVspTree; 
    180   /// object space partition tree 
    181   OspTree *mOspTree; 
     180  HierarchyManager *mHierarchyManager; 
    182181  /// BSP tree representing the viewcells 
    183182  BspTree *mBspTree; 
    184  
    185   BvHierarchy *mBvHierarchy; 
    186183   
    187184  /// list of all loaded occluders 
Note: See TracChangeset for help on using the changeset viewer.