Ignore:
Timestamp:
08/24/06 18:05:53 (18 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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} 
Note: See TracChangeset for help on using the changeset viewer.