Changeset 2544 for GTP/trunk/Lib/Vis


Ignore:
Timestamp:
08/22/07 08:01:21 (17 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp

    r2543 r2544  
    16861686        const bool finalizeViewCells = false; 
    16871687 
     1688 
    16881689        ///////////// 
    16891690        //-- load the view cells assigning the found objects to the pvss 
     
    17411742        {                
    17421743                GtpVisibilityPreprocessor::Intersectable *obj = pit.Next(); 
    1743                 // no associated geometry found 
    1744                 if (!obj) continue; 
    1745                 SetObjectVisible(obj, loadObjects); 
     1744                if (obj) SetObjectVisible(obj, loadObjects); 
    17461745        } 
    17471746} 
     
    17571756        GtpVisibilityPreprocessor::ViewCell *viewCell =  
    17581757                mViewCellsManager->GetViewCell(viewPoint); 
     1758 
     1759        //std::stringstream d; d << "vp: " << viewPoint << " vc: " << viewCell; 
     1760        //LogManager::getSingleton().logMessage(d.str()); 
     1761         
    17591762 
    17601763        // view cell did not change => don't change pvs 
     
    17741777void OcclusionCullingSceneManager::CreateViewCellsGeometry() 
    17751778{ 
    1776         //LogManager::getSingleton().logMessage("creating view cells geometry"); 
    17771779        if (mViewCellsGeometryLoaded) return; 
    17781780 
     
    18351837        } 
    18361838} 
    1837  
    18381839//------------------------------------------------------------------------- 
    18391840void OcclusionCullingSceneManager::UpdateVisibility(Entity *ent) 
  • GTP/trunk/Lib/Vis/Preprocessing/scripts/mypreprocess_visibility.sh

    r2543 r2544  
    11#!/bin/sh 
    22 
    3 ./preprocess_visibility_internal.sh ../data/vienna/vienna_cropped.obj ../data/vienna/vienna_cropped-seq-3000-false-20-viewcells.xml.gz vienna-visibility.bn 
     3./preprocess_visibility_internal.sh ../data/vienna/vienna_cropped.obj ../data/vienna/vienna_cropped-seq-3000-false-20-viewcells.xml.gz vienna-visibility2.bn 
  • GTP/trunk/Lib/Vis/Preprocessing/scripts/preprocess_visibility_internal.sh

    r2543 r2544  
    1414 
    1515#NUM_SAMPLE_RAYS=200000000 
    16 #NUM_SAMPLE_RAYS=10000000 
    17 NUM_SAMPLE_RAYS=10000 
     16NUM_SAMPLE_RAYS=30000000 
     17#NUM_SAMPLE_RAYS=10000 
    1818 
    1919$PREPROCESSOR -total_samples=$NUM_SAMPLE_RAYS \ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp

    r2543 r2544  
    371371GlRenderer::SetupCamera() 
    372372{ 
    373   Vector3 target = mViewPoint + mViewDirection; 
    374   //cout << "vp: " << mViewPoint << " dr: " << mViewDirection << endl; 
    375   //cout<<"box: " << mKdTree->GetBox()<<endl; 
    376   Vector3 up(0,1,0); 
    377    
    378   if (abs(DotProd(mViewDirection, up)) > 0.99f) 
    379         up = Vector3(1, 0, 0); 
    380    
    381   glLoadIdentity(); 
    382   gluLookAt(mViewPoint.x, mViewPoint.y, mViewPoint.z, 
    383                         target.x, target.y, target.z, 
    384                         up.x, up.y, up.z); 
     373        Vector3 target = mViewPoint + mViewDirection; 
     374 
     375        Vector3 up(0,1,0); 
     376 
     377        if (abs(DotProd(mViewDirection, up)) > 0.99f) 
     378                up = Vector3(1, 0, 0); 
     379 
     380        glLoadIdentity(); 
     381        gluLookAt(mViewPoint.x, mViewPoint.y, mViewPoint.z, 
     382                target.x, target.y, target.z, 
     383                up.x, up.y, up.z); 
    385384} 
    386385 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp

    r2187 r2544  
    857857        mCurrentViewCell->GetMesh()->ComputeBoundingBox(); 
    858858        AxisAlignedBox3 box = mCurrentViewCell->GetMesh()->mBox; 
    859         //cout << "box: " << box << endl; 
     859         
    860860        vector<KdLeaf *> leaves; 
    861  
    862861        mKdTree->GetBoxIntersections(box, leaves); 
    863862 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntersectionBoundingBoxConverter.cpp

    r2116 r2544  
    4040 
    4141bool IntersectionBoundingBoxConverter::IdentifyObjects( 
    42                         const IndexedBoundingBoxContainer &iboxes, 
    43                         ObjectContainer &objects) const 
     42                                                const IndexedBoundingBoxContainer &iboxes, 
     43                                                                                        ObjectContainer &objects) const 
    4444{ 
    4545        GtpVisibilityPreprocessor::IndexedBoundingBoxContainer:: 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r2543 r2544  
    3333 
    3434 
     35inline static bool ilt(Intersectable *obj1, Intersectable *obj2) 
     36{ 
     37        return obj1->mId < obj2->mId; 
     38} 
     39 
     40 
    3541Preprocessor *preprocessor = NULL; 
    3642   
     
    403409          ((rayCastMethod == RayCaster::INTEL_RAYCASTER) && mLoadMeshes) ? 
    404410          &mFaceParents : NULL; 
    405          
     411 
    406412        if (files == 1)  
    407           { 
     413        { 
    408414                if (strstr(filename.c_str(), ".x3d")) 
    409                   { 
     415                { 
    410416                        parser = new X3dParser; 
    411                          
     417 
    412418                        result = parser->ParseFile(filename,  
    413                                                                            mSceneGraph->GetRoot(), 
    414                                                                            mLoadMeshes, 
    415                                                                            fi); 
     419                                mSceneGraph->GetRoot(), 
     420                                mLoadMeshes, 
     421                                fi); 
    416422                        delete parser; 
    417423                } 
     
    421427 
    422428                        result = parser->ParseFile(filename,  
    423                                                                            mSceneGraph->GetRoot(), 
    424                                                                            mLoadMeshes, 
    425                                                                            fi); 
     429                                mSceneGraph->GetRoot(), 
     430                                mLoadMeshes, 
     431                                fi); 
    426432                        delete parser; 
    427433                } 
     
    432438                        // hack: load binary dump 
    433439                        const string bnFile = ReplaceSuffix(filename, ".obj", ".bn"); 
    434                          
     440 
    435441                        if (!mLoadMeshes) 
    436442                        { 
     
    439445 
    440446                        // parse obj 
    441             if (!result) 
     447                        if (!result) 
    442448                        { 
    443449                                cout << "no binary dump available or loading full meshes, parsing file" << endl; 
    444450                                parser = new ObjParser; 
    445                  
    446                                 result = parser->ParseFile(filename,  
    447                                                                    mSceneGraph->GetRoot(), 
    448                                                                    mLoadMeshes, 
    449                                                                    fi); 
    450                                                  
     451 
     452                                result = parser->ParseFile(filename, mSceneGraph->GetRoot(), mLoadMeshes, fi); 
     453 
    451454                                cout << "loaded " << (int)mSceneGraph->GetRoot()->mGeometry.size() << " entities" << endl; 
    452455 
     
    457460 
    458461                                        ExportBinaryObj(bnFile, mSceneGraph->GetRoot()); 
    459                                  
     462 
    460463                                        cout << "finished" << endl; 
    461464                                } 
     
    467470                { 
    468471                        parser = new UnigraphicsParser; 
    469                         result = parser->ParseFile(filename,  
    470                                                                            mSceneGraph->GetRoot(), 
    471                                                                            mLoadMeshes,                                                            
    472                                                                            fi); 
     472                        result = parser->ParseFile(filename, mSceneGraph->GetRoot(), mLoadMeshes, fi); 
    473473                        delete parser; 
    474474                } 
    475                  
     475 
    476476                cout << filename << endl; 
    477477        }  
     
    479479        { 
    480480                vector<string>::const_iterator fit, fit_end = filenames.end(); 
    481                  
     481 
    482482                for (fit = filenames.begin(); fit != fit_end; ++ fit)  
    483483                { 
     
    506506                } 
    507507        } 
    508          
     508 
    509509        if (result)  
    510         {  
    511                 mSceneGraph->AssignObjectIds(); 
    512   
     510        {   
    513511                int intersectables, faces; 
    514512                mSceneGraph->GetStatistics(intersectables, faces); 
     
    520518                mObjects.reserve(intersectables); 
    521519                mSceneGraph->CollectObjects(&mObjects); 
    522                  
    523                 // temp hack 
    524                 //ExportObj("cropped_vienna.obj", mObjects); 
     520         
     521                mSceneGraph->AssignObjectIds(); 
     522 
    525523                mSceneGraph->GetRoot()->UpdateBox(); 
    526524                                 
     
    605603bool 
    606604Preprocessor::Export( const string &filename, 
    607                                           const bool scene, 
    608                                           const bool kdtree 
    609                                           ) 
    610 { 
    611   Exporter *exporter = Exporter::GetExporter(filename); 
    612          
    613   if (exporter) { 
    614     if (2 && scene) 
    615       exporter->ExportScene(mSceneGraph->GetRoot()); 
    616  
    617     if (1 && kdtree) { 
    618       exporter->SetWireframe(); 
    619       exporter->ExportKdTree(*mKdTree); 
    620     } 
    621  
    622     delete exporter; 
    623     return true; 
    624   } 
    625  
    626   return false; 
     605                                         const bool scene, 
     606                                         const bool kdtree 
     607                                         ) 
     608{ 
     609        Exporter *exporter = Exporter::GetExporter(filename); 
     610 
     611        if (exporter) { 
     612                if (2 && scene) 
     613                        exporter->ExportScene(mSceneGraph->GetRoot()); 
     614 
     615                if (1 && kdtree) { 
     616                        exporter->SetWireframe(); 
     617                        exporter->ExportKdTree(*mKdTree); 
     618                } 
     619 
     620                delete exporter; 
     621                return true; 
     622        } 
     623 
     624        return false; 
    627625} 
    628626 
     
    631629{ 
    632630        // load the view cells assigning the found objects to the pvss 
    633 #if 1 
     631#if 0 
    634632        cerr << "loading binary view cells" << endl; 
    635633        ViewCellsManager *dummyViewCellsManager =  
     
    816814// use ascii format to store rays 
    817815#define USE_ASCII 0 
    818  
    819  
    820 static inline bool ilt(Intersectable *obj1, Intersectable *obj2) 
    821 { 
    822         return obj1->mId < obj2->mId; 
    823 } 
    824816 
    825817 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp

    r2176 r2544  
    100100SceneGraph::AssignObjectIds() 
    101101{ 
    102   int id = 1; 
    103   stack<SceneGraphNode *> nodeStack; 
    104    
    105   nodeStack.push(mRoot); 
     102        // matt: rather start with id zero 
     103        int id = 0; 
     104        stack<SceneGraphNode *> nodeStack; 
    106105 
    107   while (!nodeStack.empty()) { 
    108     SceneGraphNode *node = nodeStack.top(); 
    109     nodeStack.pop(); 
    110                  
    111     ObjectContainer::iterator mi = node->mGeometry.begin(); 
    112     for (; mi != node->mGeometry.end(); mi++) { 
    113                 (*mi)->SetId(id++); 
     106        nodeStack.push(mRoot); 
     107 
     108        while (!nodeStack.empty())  
     109        { 
     110                SceneGraphNode *node = nodeStack.top(); 
     111                nodeStack.pop(); 
     112 
     113                ObjectContainer::iterator mi = node->mGeometry.begin(); 
     114 
     115                for (; mi != node->mGeometry.end(); mi ++)  
     116                { 
     117                        (*mi)->SetId(id ++); 
     118                } 
     119 
     120                SceneGraphNodeContainer::iterator ni = node->mChildren.begin(); 
     121                for (; ni != node->mChildren.end(); ni ++)  
     122                { 
     123                        nodeStack.push(*ni); 
     124                } 
    114125        } 
    115      
    116     SceneGraphNodeContainer::iterator ni = node->mChildren.begin(); 
    117     for (; ni != node->mChildren.end(); ni++) { 
    118       nodeStack.push(*ni); 
    119     } 
    120   } 
    121    
    122   // return max id 
    123   return id; 
     126 
     127        // return max id 
     128        return id; 
    124129} 
    125130 
  • GTP/trunk/Lib/Vis/Preprocessing/src/TraversalTree.cpp

    r2176 r2544  
    480480                AxisAlignedBox3 box = (*mi)->GetBox(); 
    481481 
    482                 //cout << "box: " << box << endl; 
    483                 splitCandidates->push_back(new SortableEntry(SortableEntry::BOX_MAX, 
    484                         box.Max(axis), 
    485                         *mi) 
    486                         ); 
     482                splitCandidates->push_back(new SortableEntry(SortableEntry::BOX_MAX, box.Max(axis),     *mi)); 
    487483        } 
    488484 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r2543 r2544  
    1414#include "Exporter.h" 
    1515#include "BvHierarchy.h" 
    16  
     16#include "Timer/PerfTimer.h" 
    1717 
    1818 
     
    2222#define TYPE_INTERIOR -2 
    2323#define TYPE_LEAF -3 
     24 
     25static PerfTimer sPvsTimer; 
     26static PerfTimer sSearchTimer; 
     27 
    2428 
    2529 
     
    26702674                                                                                   const ObjectContainer &pvsObjects) 
    26712675{ 
    2672         int leafId = TYPE_LEAF; 
    2673         int objId = leafId; 
     2676        VspViewCell *leaf = new VspViewCell(); 
     2677 
     2678        Intersectable *obj; 
     2679 
     2680        sPvsTimer.Entry(); 
     2681 
    26742682        int pvsSize; 
    2675  
    26762683        stream.read(reinterpret_cast<char *>(&pvsSize), sizeof(int)); 
    2677         VspViewCell *leaf = new VspViewCell(); 
    2678  
    2679         //cerr << "\npvs size: " << pvsSize << endl; 
    2680  
    2681         MeshInstance dummyInst(NULL); 
    2682          
     2684        stream.read(reinterpret_cast<char *>(mPvsIds), sizeof(int) * pvsSize); 
     2685 
     2686        // just add pvs dirty, there won't be any duplicates 
     2687        ObjectPvs &pvs = leaf->GetPvs(); 
     2688        pvs.Reserve(pvsSize); 
     2689 
    26832690        // read object ids 
    26842691        for (int i = 0; i < pvsSize; ++ i) 
    26852692        {        
    2686                 stream.read(reinterpret_cast<char *>(&objId), sizeof(int)); 
    2687  
    2688                 // load the object 
    2689                 dummyInst.SetId(objId); 
    2690  
    2691                 ObjectContainer::const_iterator oit = 
    2692                         lower_bound(pvsObjects.begin(), pvsObjects.end(), (Intersectable *)&dummyInst, ilt); 
    2693                                                                  
    2694                 if ((oit != pvsObjects.end()) && ((*oit)->GetId() == objId)) 
    2695                 { 
    2696                         //cerr << "o"; 
    2697                         leaf->GetPvs().AddSample(*oit, 0); 
    2698                 } 
    2699                 else 
    2700                 { 
    2701                         cerr << "x " << objId << " ";//error: object with id " << objId << " does not exist" << endl; 
    2702                 } 
    2703         } 
     2693                obj = pvsObjects[mPvsIds[i]]; 
     2694                if (obj) pvs.AddSampleDirty(obj, 0); 
     2695        } 
     2696 
     2697        sPvsTimer.Exit(); 
    27042698 
    27052699        return leaf; 
     
    27362730        queue<ViewCell *> tStack; 
    27372731 
     2732        sPvsTimer.Start(); 
     2733 
     2734        mPvsIds = new int[pvsObjects.size()]; 
     2735 
    27382736        // hack: we make a new root 
    27392737        DEL_PTR(mRoot); 
     
    27412739        mRoot = ImportNextNode(stream, NULL, pvsObjects); 
    27422740 
    2743         cerr << "root: " << mRoot << endl; 
     2741        //cerr << "root: " << mRoot << endl; 
    27442742        tStack.push(mRoot); 
    27452743 
     
    27682766        } 
    27692767 
     2768        Debug << "needed " << sPvsTimer.TotalTime() << " secs for pvs loading" << endl; 
     2769 
     2770        delete mPvsIds; 
     2771 
    27702772        return true; 
    27712773} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h

    r2539 r2544  
    2525 
    2626 
    27 //class ObjectPvs; 
    28  
    2927 
    3028/** Statistics for a view cell partition. 
    3129*/ 
    32  
    3330class ViewCellsStatistics: public StatisticsBase 
    3431{ 
     
    8481 
    8582 
     83/** Statistics for a view cells tree. 
     84*/ 
    8685class ViewCellsTreeStats 
    8786{ 
     
    142141 
    143142 
    144 /** 
    145         A view cell. View cells are regions in space. The visibility informations, 
    146         i.e., the primitives seen by the view cell are stored in a PVs. 
    147         A view cell can be represented in many different ways, e.g., 
    148         a mesh representation. 
     143/** This class represents a view cell, which is a region in view space.  
     144        The objects seen by the view cell are stored in a pvs. 
     145        A view cell can be represented in many different ways, e.g., as a mesh. 
    149146*/ 
    150147class ViewCell: public MeshInstance 
     
    156153 
    157154        ViewCell(); 
    158  
    159155        /** Constructor taking a mesh representing the shape of the viewcell. 
    160156        */ 
    161157        ViewCell(Mesh *mesh); 
    162  
    163158        /** Default destructor. 
    164159        */ 
    165160        virtual ~ViewCell(); 
    166         /** Returns Pvs. 
     161        /** Returns const reference to pvs. 
    167162        */ 
    168163        const ObjectPvs &GetPvs() const; 
    169         /** Returns pvs. 
     164        /** Returns reference to pvs. 
    170165        */ 
    171166        ObjectPvs &GetPvs(); 
     
    222217        */ 
    223218        bool GetValid() const; 
    224  
    225219        /** Returns estimated render cost of this view cell. 
    226220        */ 
    227221        float GetRenderCost() const; 
    228  
    229222        /** set color for visiualizations. 
    230223        */ 
    231224        void SetColor(const RgbColor &color); 
    232  
    233225        /** get color for visualuzations. 
    234226        */ 
    235227    RgbColor GetColor() const; 
    236  
    237228        /** Adds a sample to the pvs. 
    238229                @param sample the sample to be added 
     
    241232        */ 
    242233        bool AddPvsSample(Intersectable *sample, const float pdf, float &contribution); 
    243  
    244234        /** if this is a view cell correspending to a leaf in a hierarchy. 
    245235        */ 
     
    257247        */ 
    258248        void SetMergeCost(const float mergeCost); 
    259  
    260249        /** Returns merge cost needed to merge this leaf from other cells. 
    261250                @hack The function is available for leaves also to have a common interface, 
     
    391380{ 
    392381public: 
    393         ViewCellLeaf()  {  mActiveViewCell = this; } 
    394         ViewCellLeaf(Mesh *mesh): 
    395         ViewCell(mesh) { mActiveViewCell = this; } 
     382         
     383        ViewCellLeaf()   
     384        {   
     385                mActiveViewCell = this;  
     386        } 
     387         
     388        ViewCellLeaf(Mesh *mesh): ViewCell(mesh)  
     389        {  
     390                mActiveViewCell = this;  
     391        } 
    396392 
    397393        bool IsLeaf() const 
     
    454450public: 
    455451 
     452        /** Default constructor. 
     453        */ 
    456454        ViewCellsTree(); 
    457  
    458455        /** View cells tree constructor taking a view cell mnanager as parameter 
    459456        */ 
    460457        ViewCellsTree(ViewCellsManager *vcm); 
     458        /** Destructor. 
     459        */ 
    461460        ~ViewCellsTree(); 
    462  
    463461        /** Returns number of leaves this view cell consists of. 
    464462        */ 
    465463        int GetNumInitialViewCells(ViewCell *vc) const; 
    466  
    467464        /** Collects leaves corresponding to a view cell. 
    468465        */ 
    469466        void CollectLeaves(ViewCell *vc, ViewCellContainer &leaves) const; 
    470  
    471467        /** Merges view cells according to some cost heuristics. 
    472468        */ 
    473469        int ConstructMergeTree(const VssRayContainer &rays, const ObjectContainer &objects); 
    474          
    475470        /** Refines view cells using shuffling, i.e., border leaves  
    476471                of two view cells are exchanged if the resulting view cells 
     
    479474        */ 
    480475        int RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects); 
    481          
    482476        /** Assign colors to the viewcells so that they can be renderered interactively without 
    483477            color flickering.   
    484478        */ 
    485479        void AssignRandomColors(); 
    486  
    487480        /** Updates view cell stats for this particular view cell. 
    488481        */ 
    489482        void UpdateViewCellsStats(ViewCell *vc, ViewCellsStatistics &vcStat); 
    490  
    491483        /** Get costs resulting from each merge step.  
    492484        */ 
    493485        void GetCostFunction(vector<float> &costFunction); 
    494          
    495486        /** Returns storage cost resulting from each merge step. 
    496487        */ 
    497488        void GetStorageFunction(vector<int> &storageCost); 
    498  
    499489        /** Returns optimal set of view cells for a given number of view cells. 
    500490        */ 
    501491        void CollectBestViewCellSet(ViewCellContainer &viewCells, const int numViewCells); 
    502  
    503492        /** Root of view cells tree. 
    504493        */ 
    505494        ViewCell *GetRoot() const; 
    506  
    507495        /** Returns pvs of view cell. 
    508496                @note pvs is returned per reference if tree is not compressed, 
     
    510498        */ 
    511499        void GetPvs(ViewCell *vc, ObjectPvs &pvs) const; 
    512  
    513500        /** Returns pvs size (i.e. the render cost of the stored objects) 
    514501        */ 
    515502        float GetTrianglesInPvs(ViewCell *vc) const; 
    516    
    517503        /** Returns number of entries associated with this view cell.  
    518504 
     
    522508        */ 
    523509        int GetPvsEntries(ViewCell *vc) const; 
    524  
    525510        /** Returns the number of physically stored entries in the view cells sub tree. 
    526511                This can vary based on the current storage method 
    527512        */ 
    528513        int CountStoredPvsEntries(ViewCell *root) const; 
    529  
    530514        /** Returns memory cost of this view cell. 
    531515        */ 
    532516        float GetMemoryCost(ViewCell *vc) const; 
    533  
    534517        /** Sets method of storage for view cells. 
    535518        */ 
    536519        void SetViewCellsStorage(int type); 
    537  
    538520        /** pvs storage methods  
    539521        */ 
    540522        enum {PVS_IN_INTERIORS, COMPRESSED, PVS_IN_LEAVES}; 
    541  
    542523        /** If view cells in this tree have compressed pvs. 
    543524        */ 
    544525        int ViewCellsStorage() const; 
    545  
    546526        /** Returns active view cell that is in the path of this view cell. 
    547527        */ 
     
    736716        int mMaxMergesPerPass; 
    737717        float mAvgCostMaxDeviation; 
     718 
     719        int *mPvsIds; 
     720        ObjectContainer mTempObjects; 
    738721}; 
    739722 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r2543 r2544  
    10211021        if (!Debug.is_open()) Debug.open("debug.log"); 
    10221022 
    1023         Debug << "here23" << endl; 
    10241023        // give just an empty container as parameter: 
    10251024        // this loading function is used in the engine, thus it 
     
    10401039        stream.read(reinterpret_cast<char *>(&numBoxes), sizeof(int)); 
    10411040 
     1041        iboxes.reserve(numBoxes); 
     1042 
     1043        Vector3 bmin; 
     1044        Vector3 bmax; 
     1045        int id; 
     1046 
     1047        PerfTimer boxTimer; 
     1048 
     1049        boxTimer.Start(); 
     1050        boxTimer.Entry(); 
     1051         
    10421052        for (int i = 0; i < numBoxes; ++ i) 
    10431053        { 
    1044                 Vector3 bmin; 
    1045                 Vector3 bmax; 
    1046                 int id; 
    1047  
    10481054                stream.read(reinterpret_cast<char *>(&bmin), sizeof(Vector3)); 
    10491055                stream.read(reinterpret_cast<char *>(&bmax), sizeof(Vector3)); 
    10501056                stream.read(reinterpret_cast<char *>(&id), sizeof(int)); 
    10511057 
    1052                 AxisAlignedBox3 box(bmin, bmax); 
    1053                 iboxes.push_back(IndexedBoundingBox(id, box)); 
    1054         } 
     1058                iboxes.push_back(IndexedBoundingBox(id, AxisAlignedBox3(bmin, bmax))); 
     1059        } 
     1060 
     1061 
     1062        boxTimer.Exit(); 
     1063 
     1064        Debug << numBoxes << " boxes loaded in " << boxTimer.TotalTime() << " secs" << endl; 
    10551065} 
    10561066 
     
    66036613                return false; 
    66046614 
    6605         /*if (strstr(filename.c_str(), ".bn")) 
    6606         { 
    6607                 cout << "exporting view cells to binary format" << endl; 
     6615        if (strstr(filename.c_str(), ".bn")) 
     6616        { 
    66086617                return ExportViewCellsBinary(filename, exportPvs, objects); 
    6609         }*/ 
    6610  
    6611         cout << "exporting binary" << endl; string fname("test.vc"); return ExportViewCellsBinary(fname, exportPvs, objects); 
     6618        } 
     6619 
     6620        //cout << "exporting binary" << endl; string fname("test.vc"); return ExportViewCellsBinary(fname, exportPvs, objects); 
    66126621 
    66136622        const long starttime = GetTime(); 
     
    67676776        stream.close(); 
    67686777         
    6769         mHierarchyManager->GetVspTree()->TestOutput("output.txt"); 
     6778        //mHierarchyManager->GetVspTree()->TestOutput("output.txt"); 
    67706779 
    67716780        cout << "finished in " << TimeDiff(starttime, GetTime()) * 1e-3 << " secs" << endl; 
     
    71217130        const long startTime = GetTime(); 
    71227131 
     7132        // load all the bounding boxes 
    71237133        IndexedBoundingBoxContainer iboxes; 
    71247134        ViewCellsManager::LoadIndexedBoundingBoxesBinary(stream, iboxes); 
    71257135 
    7126         Debug << (int)iboxes.size() << " boxes loaded" << endl; 
    7127  
    7128         /*IndexedBoundingBoxContainer::const_iterator bit, bit_end = iboxes.end(); 
    7129         for (bit = iboxes.begin(); bit != bit_end; ++ bit) 
    7130         { 
    7131                 IndexedBoundingBox ibox = *bit; 
    7132                 cerr << "box: " << ibox.first << " " << ibox.second << endl; 
    7133         }*/ 
    7134  
     7136        pvsObjects.reserve(iboxes.size()); 
    71357137 
    71367138        if (bconverter) 
    71377139        { 
    7138                 // all bounding boxes gathered in this step =>  
    71397140                // associate object ids with bounding boxes 
    71407141                bconverter->IdentifyObjects(iboxes, pvsObjects); 
     
    71427143 
    71437144        // sort objects by id 
    7144         sort(pvsObjects.begin(), pvsObjects.end(), ilt); 
    7145          
     7145        //sort(pvsObjects.begin(), pvsObjects.end(), ilt); 
     7146 
     7147 
     7148        ObjectContainer pvsLookup; 
     7149        pvsLookup.resize(iboxes.size()); 
     7150 
     7151        for (size_t i = 0; i < pvsLookup.size(); ++ i) 
     7152        { 
     7153                pvsLookup[i] = NULL; 
     7154        } 
     7155 
     7156        for (size_t i = 0; i < pvsObjects.size(); ++ i) 
     7157        { 
     7158                pvsLookup[pvsObjects[i]->GetId()] = pvsObjects[i]; 
     7159        } 
     7160 
    71467161 
    71477162        ///////////// 
     
    71647179    ViewCellsTree *vcTree = new ViewCellsTree(); 
    71657180 
    7166         if (!vcTree->ImportBinary(stream, pvsObjects)) 
     7181        if (!vcTree->ImportBinary(stream, pvsLookup)) 
    71677182        { 
    71687183                Debug << "Error: loading view cells tree failed!" << endl; 
     
    71777192        vspTree->mBoundingBox = viewSpaceBox; 
    71787193 
    7179         if (!vspTree->ImportBinary(stream, pvsObjects)) 
     7194        if (!vspTree->ImportBinary(stream)) 
    71807195        { 
    71817196                Debug << "Error: loading vsp tree failed!" << endl; 
     
    71987213 
    71997214 
    7200  
    72017215        ////////////// 
    72027216        //-- do some more preparation 
    72037217 
     7218        vm->mViewSpaceBox = viewSpaceBox; 
    72047219        vm->mViewCells.clear(); 
    72057220 
     
    72327247                vc->mLeaves.push_back(leaf); 
    72337248        } 
     7249 
     7250         
     7251        /*for (cit = viewCells.begin(); cit != cit_end; ++ cit) 
     7252        { 
     7253                Debug << "pvssize: " << (*cit)->GetPvs().GetSize(); 
     7254        }*/ 
    72347255 
    72357256 
     
    72477268                  << TimeDiff(startTime, GetTime()) * 1e-6f << " secs" << endl; 
    72487269 
    7249         vspTree->TestOutput("input.txt"); 
     7270        //vspTree->TestOutput("input.txt"); 
    72507271 
    72517272        return vm; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r2543 r2544  
    4646 
    4747 
     48 
     49inline static bool ilt(Intersectable *obj1, Intersectable *obj2) 
     50{ 
     51        return obj1->mId < obj2->mId; 
     52} 
     53 
     54 
    4855// pvs penalty can be different from pvs size 
    4956inline static float EvalPvsPenalty(const float pvs,  
     
    28232830                if (node->IsLeaf())  
    28242831                { 
    2825                         /*const AxisAlignedBox3 box = GetBoundingBox(static_cast<VspLeaf *>(node)); 
     2832                        const AxisAlignedBox3 box = GetBoundingBox(static_cast<VspLeaf *>(node)); 
     2833 
    28262834                        if (!box.IsInside(point)) 
    2827                                 cerr << "error, point " << point << " should be in view cell " << box << endl; 
    2828                         */       
     2835                                Debug << "error, point " << point << " should be in view cell " << box << endl; 
     2836                         
    28292837                        viewcell = static_cast<VspLeaf *>(node)->GetViewCell(); 
    28302838                        break; 
     
    39193927 
    39203928VspLeaf *VspTree::ImportBinLeaf(IN_STREAM &stream,  
    3921                                                                 VspInterior *parent, 
    3922                                                                 const ObjectContainer &pvsObjects) 
     3929                                                                VspInterior *parent) 
    39233930{ 
    39243931        int leafId = TYPE_LEAF; 
     
    39333940 
    39343941VspNode *VspTree::ImportNextNode(IN_STREAM &stream,  
    3935                                                                  VspInterior *parent, 
    3936                                                                  const ObjectContainer &objects) 
     3942                                                                 VspInterior *parent) 
    39373943{ 
    39383944        int nodeType; 
     
    39423948        { 
    39433949                //cerr << "l"; 
    3944                 return ImportBinLeaf(stream, static_cast<VspInterior *>(parent), objects); 
     3950                return ImportBinLeaf(stream, static_cast<VspInterior *>(parent)); 
    39453951        } 
    39463952 
     
    39783984 
    39793985 
    3980 bool VspTree::ImportBinary(IN_STREAM &stream, ObjectContainer &pvsObjects) 
     3986bool VspTree::ImportBinary(IN_STREAM &stream) 
    39813987{ 
    39823988        // export binary version of mesh 
     
    39883994        // hack: we make a new root 
    39893995        DEL_PTR(mRoot); 
    3990         mRoot = ImportNextNode(stream, NULL, pvsObjects); 
     3996        mRoot = ImportNextNode(stream, NULL); 
    39913997 
    39923998        tStack.push(MyTraversalData(mRoot, 0, mBoundingBox)); 
     
    40084014                        interior->SetBoundingBox(tData.mBox); 
    40094015 
    4010             VspNode *front = ImportNextNode(stream, interior, pvsObjects); 
    4011                         VspNode *back = ImportNextNode(stream, interior, pvsObjects); 
    4012          
    4013                         interior->SetupChildLinks(back, front); 
     4016            VspNode *front = ImportNextNode(stream, interior); 
     4017                        VspNode *back = ImportNextNode(stream, interior); 
     4018         
     4019                        interior->SetupChildLinks(front, back); 
    40144020 
    40154021                        ++ mVspStats.splits[interior->GetAxis()]; 
     
    40444050        CollectLeaves(vspLeaves); 
    40454051 
     4052        str << "root: " << mBoundingBox << endl; 
     4053 
    40464054        vector<VspLeaf *>::const_iterator vit, vit_end = vspLeaves.end(); 
    40474055 
     
    40534061                str << "\nleaf: " << GetBoundingBox(leaf) << endl; 
    40544062 
     4063                ObjectContainer pvsObjects; 
     4064 
    40554065                ObjectPvsIterator pit = vc->GetPvs().GetIterator(); 
    40564066 
     
    40584068                { 
    40594069                        Intersectable *obj = pit.Next(); 
    4060                         str << obj->GetId() << " "; 
    4061                 } 
    4062         } 
    4063 } 
    4064  
    4065  
    4066 } 
     4070                        pvsObjects.push_back(obj); 
     4071                } 
     4072 
     4073                sort(pvsObjects.begin(), pvsObjects.end(), ilt); 
     4074                str << "pvs: " << pvsObjects.size() << endl; 
     4075                 
     4076                for (int i = 0; i < pvsObjects.size(); ++ i) 
     4077                        str << pvsObjects[i]->GetId() << " "; 
     4078        } 
     4079} 
     4080 
     4081 
     4082} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h

    r2543 r2544  
    258258        */ 
    259259        void SetupChildLinks(VspNode *front, VspNode *back); 
    260         /** Returns boundiŽng box of this node. 
     260        /** Returns bounding box of this node. 
    261261        */ 
    262262        AxisAlignedBox3 GetBoundingBox() const; 
     
    661661        /** Imports tree from binary format. 
    662662        */ 
    663         bool ImportBinary(IN_STREAM &stream, ObjectContainer &pvsObjects); 
     663        bool ImportBinary(IN_STREAM &stream); 
    664664 
    665665        void TestOutput(const std::string &filename); 
     
    867867 
    868868        VspInterior *ImportBinInterior(IN_STREAM  &stream, VspInterior *parent); 
    869         VspLeaf *ImportBinLeaf(IN_STREAM &stream, VspInterior *parent, const ObjectContainer &pvsObjects); 
     869        VspLeaf *ImportBinLeaf(IN_STREAM &stream, VspInterior *parent); 
    870870 
    871871        VspNode *ImportNextNode(IN_STREAM &stream,  
    872                                                         VspInterior *parent, 
    873                                                         const ObjectContainer &pvsObjects); 
     872                                                        VspInterior *parent); 
    874873 
    875874 
Note: See TracChangeset for help on using the changeset viewer.