Changeset 651


Ignore:
Timestamp:
02/18/06 18:02:12 (18 years ago)
Author:
mattausch
Message:

exporting / loading full merge hierarchy

Location:
GTP/trunk/Lib/Vis/Preprocessing
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/scripts/default.env

    r650 r651  
    3636        loadInitialSamples  false 
    3737        storeInitialSamples false 
    38         useViewSpaceBox false 
     38        useViewSpaceBox true 
    3939#       testBeamSampling true 
    4040} 
     
    185185 
    186186        exportToFile false 
    187         loadFromFile false 
     187        loadFromFile true 
    188188 
    189189        #type kdTree 
    190190        #type vspKdTree 
    191         type bspTree 
    192         #type vspBspTree 
     191        #type bspTree 
     192        type vspBspTree 
    193193         
    194194        #type sceneDependent 
     
    288288VspBspTree { 
    289289        Construction { 
    290                 samples 500000 
     290                samples 50000 
    291291                epsilon 0.00005 
    292292                randomize false 
     
    420420                minProbability 0.00001 
    421421                maxRayContribution 9999 
    422                 maxViewCells    100 
     422                maxViewCells    1000 
    423423 
    424424                # used for pvs criterium 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r650 r651  
    12621262 
    12631263        int totalPvs; 
    1264         float totalRenderCost, float avgRenderCost, float expectedCost; 
     1264        float totalRenderCost, avgRenderCost, expectedCost; 
    12651265 
    12661266        float deviation = 0; 
     
    12701270        ofstream stats; 
    12711271        stats.open("mergeStats.log"); 
    1272  
    1273         Debug << "here343" << endl; 
    12741272 
    12751273        stats  
     
    13471345 
    13481346 
    1349 /*float ViewCellsTree::ComputeVolume(ViewCell *vc) 
     1347#if 0 
     1348float ViewCellsTree::ComputeVolume(ViewCell *vc) 
    13501349{ 
    13511350        if (vc->IsLeaf()) 
     
    13691368                return volume; 
    13701369        } 
    1371 }*/ 
    1372  
     1370} 
     1371#endif 
    13731372 
    13741373void ViewCellsTree::SetRoot(ViewCell *root) 
     
    16211620 
    16221621 
    1623 void ViewCellsTree::PropagateUpPvs(ViewCell *vc) 
     1622void ViewCellsTree::PropagatePvs(ViewCell *vc) 
    16241623{ 
    16251624        while (vc->GetParent()) 
     
    16271626                vc->GetParent()->GetPvs().Merge(vc->GetPvs()); 
    16281627                vc = vc->GetParent(); 
     1628        } 
     1629 
     1630        if (vc->IsLeaf()) 
     1631                return; 
     1632 
     1633        stack<ViewCell *> tstack; 
     1634 
     1635        tstack.push(vc); 
     1636 
     1637        while (!tstack.empty()) 
     1638        { 
     1639                ViewCell *viewCell = tstack.top(); 
     1640                tstack.pop(); 
     1641 
     1642                if (viewCell != vc) 
     1643                { 
     1644                        viewCell->GetPvs().Merge(vc->GetPvs()); 
     1645                } 
     1646 
     1647                if (!viewCell->IsLeaf()) 
     1648                { 
     1649                        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(viewCell); 
     1650                        ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     1651 
     1652                        for (it = interior->mChildren.begin(); it != it_end; ++ it) 
     1653                        { 
     1654                                tstack.push(*it); 
     1655                        } 
     1656                } 
    16291657        } 
    16301658} 
     
    17271755 
    17281756 
     1757void ViewCellsTree::CreateUniqueViewCellsIds() 
     1758{ 
     1759        stack<ViewCell *> tstack; 
     1760 
     1761        int currentId = 0; 
     1762 
     1763        tstack.push(mRoot); 
     1764 
     1765        while (!tstack.empty()) 
     1766        { 
     1767                ViewCell *vc = tstack.top(); 
     1768                tstack.pop(); 
     1769 
     1770                vc->SetId(currentId ++); 
     1771 
     1772                if (!vc->IsLeaf()) 
     1773                { 
     1774                        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
     1775                        ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     1776                        for (it = interior->mChildren.begin(); it != it_end; ++ it) 
     1777                        { 
     1778                                tstack.push(*it); 
     1779                        } 
     1780                } 
     1781        } 
     1782} 
     1783 
     1784 
    17291785void ViewCellsTree::ExportViewCell(ViewCell *viewCell, ofstream &stream) 
    17301786{ 
    17311787        ObjectPvsMap::iterator it, it_end = viewCell->GetPvs().mEntries.end(); 
    1732  
    1733         if (0) // test with empty pvs 
    1734         for (it = viewCell->GetPvs().mEntries.begin(); it != it_end; ++ it) 
    1735         { 
    1736                 stream << (*it).first->GetId() << " "; 
    1737         } 
    1738  
    1739         stream << "\" />" << endl; 
    17401788 
    17411789        if (viewCell->IsLeaf()) 
     
    17461794                stream << "mergecost=\"" << viewCell->GetMergeCost() << "\" "; 
    17471795                stream << "pvs=\""; 
    1748                 stream << "</Leaf>" << endl; 
     1796                if (0)// test with empty pvs 
     1797                        for (it = viewCell->GetPvs().mEntries.begin(); it != it_end; ++ it) 
     1798                        { 
     1799                                stream << (*it).first->GetId() << " "; 
     1800                        } 
     1801 
     1802         
     1803                stream << "\" />" << endl; 
     1804                //stream << " </Leaf>" << endl; 
    17491805        } 
    17501806        else 
     
    17571813                stream << "mergecost=\"" << viewCell->GetMergeCost() << "\" "; 
    17581814                stream << "pvs=\""; 
     1815 
     1816                if (0)// test with empty pvs 
     1817                        for (it = viewCell->GetPvs().mEntries.begin(); it != it_end; ++ it) 
     1818                        { 
     1819                                stream << (*it).first->GetId() << " "; 
     1820                        } 
     1821 
     1822                stream << "\" >" << endl; 
    17591823 
    17601824                ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h

    r650 r651  
    301301        */ 
    302302        int RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects); 
    303  
    304   /** Assign colors to the viewcells so that they can be renderered interactively without 
     303         
     304        /** Assign colors to the viewcells so that they can be renderered interactively without 
    305305          color flickering. 
    306   */ 
    307   void AssignRandomColors(); 
     306          */ 
     307        void AssignRandomColors(); 
     308 
    308309        /** Updates view cell stats for this particular view cell 
    309310        */ 
     
    311312         
    312313 
    313   /** Get costs resulting from each merge step. */ 
    314   void GetCostFunction(vector<float> &costFunction); 
     314        /** Get costs resulting from each merge step. */ 
     315        void GetCostFunction(vector<float> &costFunction); 
    315316   
    316317 
     
    351352        ViewCell *GetActiveViewCell(ViewCell *vc) const; 
    352353 
    353         /** Propagates pvs up the tree to the root. 
    354         */ 
    355         void PropagateUpPvs(ViewCell *vc); 
     354        /** Propagates pvs up the tree to the root and downwards the tree. 
     355        */ 
     356        void PropagatePvs(ViewCell *vc); 
    356357 
    357358        bool Export(ofstream &stream); 
     
    366367 
    367368        //float ComputeVolume(ViewCell *vc); 
     369 
     370        /** Assignes unique ids to view cells. 
     371        */ 
     372        void CreateUniqueViewCellsIds(); 
     373 
    368374 
    369375protected: 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r650 r651  
    908908void ViewCellsManager::CreateUniqueViewCellIds() 
    909909{ 
    910         for (int i = 0; i < (int)mViewCells.size(); ++ i) 
    911                 mViewCells[i]->SetId(i); 
     910        if (ViewCellsTreeConstructed()) 
     911                mViewCellsTree->CreateUniqueViewCellsIds(); 
     912        else 
     913                for (int i = 0; i < (int)mViewCells.size(); ++ i) 
     914                        mViewCells[i]->SetId(i); 
    912915} 
    913916 
     
    29482951 
    29492952         
    2950         if (0) // export view cells 
     2953        if (1) // export view cells 
    29512954        {       // hack pvs 
    29522955                int savedColorCode = mColorCode; 
    2953                 mColorCode = 1; 
     2956                mColorCode = 0; 
    29542957                Exporter *exporter = Exporter::GetExporter("final_view_cells.x3d"); 
    29552958                 
     
    31693172                                exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 
    31703173                        } 
    3171  
    3172                          
     3174                 
    31733175 
    31743176                        if (1) 
     
    31953197                } 
    31963198                 
    3197                  
    3198  
    31993199 
    32003200                exporter->SetWireframe(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r650 r651  
    531531protected: 
    532532 
    533         struct TraversalData 
    534         {   
    535                 ViewCellInterior *mParentViewCell; 
    536                 BspNode *mNode; 
    537                  
    538  
    539                 TraversalData() {} 
    540                 TraversalData(BspNode *node, ViewCellInterior *vc): 
    541                          mNode(node), mParentViewCell(vc) 
    542                 {} 
    543     
    544                 bool operator<(const TraversalData &b) const  
    545                 { 
    546                         return mNode->mTimeStamp < b.mNode->mTimeStamp; 
    547                 } 
    548         }; 
    549  
    550         typedef priority_queue<TraversalData> TraversalQueue; 
    551533 
    552534        /** HACK 
     
    765747protected: 
    766748 
    767         struct TraversalData 
    768         {   
    769                 ViewCellInterior *mParentViewCell; 
    770                 BspNode *mNode; 
    771                  
    772  
    773                 TraversalData() {} 
    774                 TraversalData(BspNode *node, ViewCellInterior *vc): 
    775                          mNode(node), mParentViewCell(vc) 
    776                 {} 
    777     
    778                 bool operator<(const TraversalData &b) const  
    779                 { 
    780                         return mNode->mTimeStamp < b.mNode->mTimeStamp; 
    781                 } 
    782         }; 
    783  
    784         typedef priority_queue<TraversalData> TraversalQueue; 
    785  
     749         
    786750        /** Returns node of the spatial hierarchy corresponding to the view cell 
    787751                if such a node exists. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp

    r590 r651  
    7070  , mVspBspTree(NULL) 
    7171  , mBspTree(NULL) 
     72  , mViewCellsTree(NULL) 
     73  , mParseViewCells(true) 
     74  , mCurrentViewCell(NULL) 
     75  , mCurrentBspNode(NULL) 
    7276{ 
    7377        mObjects = objects; 
     
    8993  StrX lname(name); 
    9094  string element(lname.LocalForm()); 
    91   if (element == "Interior") 
    92           EndBspInterior(); 
     95 
    9396  if (element == "ViewCells") 
    9497          EndViewCells(); 
     98 
     99  if (mParseViewCells) 
     100  { 
     101          if (element == "Interior") 
     102                  EndViewCellInterior(); 
     103  } 
     104  else 
     105  { 
     106        if (element == "Interior") 
     107                  EndBspInterior(); 
     108  } 
    95109} 
    96110 
     
    105119} 
    106120 
     121 
     122void ViewCellsParseHandlers::EndViewCellInterior() 
     123{ 
     124        // go one up in the tree 
     125        if (mCurrentViewCell->GetParent()) 
     126        {       cout << "]"; 
     127                mCurrentViewCell = mCurrentViewCell->GetParent(); 
     128        } 
     129} 
    107130 
    108131inline bool vlt(ViewCell *v1, ViewCell *v2) 
     
    151174        if (element == "Leaf")  
    152175        { 
     176                cout << "l"; 
     177                Debug << "leaf" << endl; 
    153178                StartBspLeaf(attributes); 
    154179        } 
     
    163188 
    164189        // decides the used view cell hierarchy 
     190        if (element == "ViewCells") 
     191        { 
     192                cout << "parsing view cells" << endl; 
     193                mParseViewCells = true; 
     194        } 
     195 
    165196        if (element == "Hierarchy") 
    166197        { 
    167                 cout << "h"; 
     198                cout << "parsing spatial hierarchy" << endl; 
     199                mParseViewCells = false; 
    168200                StartHierarchy(attributes); 
    169201        } 
     
    172204        if (element == "ViewSpaceBox") 
    173205        { 
    174                 cout << "vsb"; 
     206                cout << "b"; 
    175207                StartViewSpaceBox(attributes); 
    176208        } 
    177209 
    178         if (element == "ViewCell") 
    179         { 
    180                 cout << "v"; 
    181                 StartViewCell(attributes); 
    182         } 
    183210 
    184211        // use different methods for the given view cell hierarchy types 
    185         if (mViewCellsManager) 
    186         { 
    187                 switch (mViewCellsManager->GetType()) 
    188                 { 
    189                 case ViewCellsManager::BSP: 
    190                 case ViewCellsManager::VSP_BSP: 
    191                         startBspElement(element, attributes); 
    192                         break; 
     212        if (!mParseViewCells) 
     213        { 
     214                if (mViewCellsManager) 
     215                { 
     216                        switch (mViewCellsManager->GetType()) 
     217                        { 
     218                        case ViewCellsManager::BSP: 
     219                        case ViewCellsManager::VSP_BSP: 
     220                                startBspElement(element, attributes); 
     221                                break; 
    193222         
    194                 default: 
    195                         Debug << "not implemented" << endl; 
    196                         break; 
     223                        default: 
     224                                Debug << "not implemented" << endl; 
     225                                break; 
     226                        } 
     227                } 
     228        } 
     229        else 
     230        { 
     231                if (element == "Interior")  
     232                { 
     233                        cout << "["; 
     234                        StartViewCellInterior(attributes); 
     235                } 
     236 
     237                if (element == "Leaf")  
     238                { 
     239                        cout << "l"; 
     240                        StartViewCellLeaf(attributes); 
    197241                } 
    198242        } 
     
    209253 
    210254 
    211 void ViewCellsParseHandlers::StartViewCell(AttributeList&  attributes) 
     255void ViewCellsParseHandlers::StartViewCell(ViewCell *viewCell, AttributeList&  attributes) 
    212256{ 
    213257        int len = attributes.getLength(); 
    214258        vector<int> objIndices; 
    215    
    216 //hack!! 
    217          
    218         ViewCell *viewCell = new ViewCellInterior();//mViewCellsManager->GenerateViewCell(); 
    219         viewCell->mIsActive = true; 
    220  
    221         mViewCells.push_back(viewCell); 
    222          
     259 
    223260        for (int i = 0; i < len; ++ i)  
    224261        { 
     
    284321                        viewCell->SetId(id); 
    285322                } 
     323                else if (attrName == "active") 
     324                { 
     325                        StrX attrValue(attributes.getValue(i)); 
     326                         
     327                        const char *ptr = attrValue.LocalForm(); 
     328                        char *endptr = NULL; 
     329                        const bool isActive = (bool)strtol(ptr, &endptr, 10); 
     330 
     331                        viewCell->mIsActive = isActive; 
     332                } 
     333                else if (attrName == "mergecost") 
     334                { 
     335                        StrX attrValue(attributes.getValue(i)); 
     336                         
     337                        const char *ptr = attrValue.LocalForm(); 
     338                        char *endptr = NULL; 
     339                        const float cost = (float)strtod(ptr, &endptr); 
     340 
     341                        viewCell->SetMergeCost(cost); 
     342                } 
    286343        } 
    287344} 
     
    357414                } 
    358415        } 
    359  
     416Debug << "here22" << endl; 
    360417         
    361418        if (viewCellId >= 0) // valid view cell 
     
    368425                        lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt); 
    369426                         
    370                 ViewCellInterior *viewCell = dynamic_cast<ViewCellInterior *>(*vit); 
    371  
    372                 // giant hack!! 
    373                 BspViewCell *l = dynamic_cast<BspViewCell *>(mViewCellsManager->GenerateViewCell()); 
    374                 viewCell->SetupChildLink(l); 
     427                BspViewCell *viewCell = dynamic_cast<BspViewCell *>(*vit); 
     428 
     429                Debug << "here44" << endl; 
    375430 
    376431                if (viewCell->GetId() == viewCellId) 
    377432                { 
    378                         leaf->SetViewCell(l); 
    379                         l->mLeaf = leaf; 
     433                        leaf->SetViewCell(viewCell); 
     434                        viewCell->mLeaf = leaf; 
    380435                } 
    381436                else 
     
    392447                        mVspBspTree->PropagateUpValidity(leaf); 
    393448                } 
    394         } 
     449        }Debug << "here33" << endl; 
    395450} 
    396451 
     
    439494 
    440495 
     496void ViewCellsParseHandlers::StartViewCellLeaf(AttributeList& attributes) 
     497{ 
     498        Debug << "here111" << endl; 
     499        BspViewCell *viewCell = new BspViewCell(); 
     500 
     501        if (mCurrentViewCell) // replace front or (if not NULL) back child 
     502        { 
     503                ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(mCurrentViewCell); 
     504                interior->SetupChildLink(viewCell); 
     505        } 
     506        else // root 
     507        { 
     508                mViewCellsTree->SetRoot(viewCell); 
     509        } 
     510 
     511        StartViewCell(viewCell, attributes); 
     512 
     513        // collect leaves 
     514        mViewCells.push_back(viewCell); 
     515} 
     516 
     517 
     518void ViewCellsParseHandlers::StartViewCellInterior(AttributeList& attributes) 
     519{ 
     520        Debug << "here222" << endl; 
     521        ViewCellInterior* interior = new ViewCellInterior(); 
     522         
     523        if (mCurrentViewCell) // replace NULL child of parent with current node 
     524        { 
     525                ViewCellInterior *current = dynamic_cast<ViewCellInterior *>(mCurrentViewCell); 
     526 
     527                current->SetupChildLink(interior); 
     528        } 
     529        else 
     530        { 
     531                mViewCellsTree->SetRoot(interior); 
     532        } 
     533 
     534        mCurrentViewCell = interior; 
     535 
     536        StartViewCell(interior, attributes); 
     537} 
     538 
     539 
    441540 
    442541void ViewCellsParseHandlers::CreateViewCellsManager(const char *name) 
     
    448547                mBspTree = new BspTree(); 
    449548                mBspTree->mBox = mViewSpaceBox; 
    450                 mCurrentBspNode = mBspTree->GetRoot(); 
     549                //mCurrentBspNode = mBspTree->GetRoot(); 
    451550 
    452551                mViewCellsManager = new BspViewCellsManager(mBspTree); 
     
    457556 
    458557                mVspBspTree = new VspBspTree(); 
    459                 mCurrentBspNode = mVspBspTree->GetRoot(); 
     558                //mCurrentBspNode = mVspBspTree->GetRoot(); 
    460559 
    461560                mViewCellsManager = new VspBspViewCellsManager(mVspBspTree); 
     
    476575        } 
    477576 
     577        mViewCellsTree = mViewCellsManager->GetViewCellsTree(); 
    478578        mViewCellsManager->SetViewSpaceBox(mViewSpaceBox); 
    479579} 
     
    625725   // assign new view cells manager 
    626726  *viewCells = handler.mViewCellsManager; 
    627  
     727   
    628728  if (errorCount > 0) 
    629729    return false; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h

    r590 r651  
    1717class BspTree; 
    1818class ViewCellsManager; 
     19class ViewCellsTree; 
    1920 
    2021class ViewCellsParseHandlers: public HandlerBase 
     
    6768  VspKdTree *mVspKdTree; 
    6869  BspTree *mBspTree; 
    69    
     70  ViewCellsTree *mViewCellsTree; 
     71 
    7072  BspNode *mCurrentBspNode; 
     73  ViewCell *mCurrentViewCell; 
     74 
    7175  ViewCellContainer mViewCells; 
    7276  ViewCellsManager *mViewCellsManager; 
     
    7579  AxisAlignedBox3 mViewSpaceBox; 
    7680 
     81  bool mParseViewCells; 
     82 
    7783  // Handlers for X3D 
    7884  void StartBspLeaf(AttributeList& attributes); 
     
    8086  void EndBspInterior(); 
    8187  
    82   void StartViewCell(AttributeList&  attributes); 
     88  void StartViewCell(ViewCell *viewCell, AttributeList&  attributes); 
    8389  void EndViewCells(); 
    84  
     90         
    8591  void StartHierarchy(AttributeList& attributes); 
    8692 
    8793  void startBspElement(string element, AttributeList& attributes); 
    8894  void StartViewSpaceBox(AttributeList&  attributes); 
     95 
     96  void StartViewCellLeaf(AttributeList& attributes); 
     97  void StartViewCellInterior(AttributeList& attributes); 
     98  void EndViewCellInterior(); 
     99 
     100 
    89101  // ----------------------------------------------------------------------- 
    90102  //  Handlers for the SAX ErrorHandler interface 
    91103  // ----------------------------------------------------------------------- 
     104 
    92105  void warning(const SAXParseException& exc); 
    93106  void error(const SAXParseException& exc); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp

    r639 r651  
    568568  } 
    569569  else 
    570   { 
    571           
     570  {       
    572571          VssRayContainer dummies; 
    573572          mViewCellsManager->Visualize(mObjects, dummies); 
    574573          mViewCellsManager->ExportViewCells("test.xml"); 
    575574  } 
     575 
    576576  VssTree *vssTree = NULL; 
    577  
    578577   
    579578 
     
    624623                cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
    625624                cout << "#TotalSamples=" << totalSamples/1000 
    626                         << "k   #SampleContributions=" << passSampleContributions << " (" 
     625                        << "#SampleContributions=" << passSampleContributions << " (" 
    627626                        << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 
    628627                        << pvsSize/(float)mObjects.size() << endl 
Note: See TracChangeset for help on using the changeset viewer.