Changeset 1551


Ignore:
Timestamp:
10/02/06 19:07:38 (18 years ago)
Author:
mattausch
Message:

updated view cells loading. probably no optimal for performance

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

Legend:

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

    r1548 r1551  
    14451445        { 
    14461446                VspViewCell *vc = dynamic_cast<VspViewCell *>(*vit); 
    1447                 VspLeaf *leaf = vc->mLeaf; 
     1447                VspLeaf *leaf = vc->mLeaves[0]; 
    14481448                SubdivisionCandidate *candidate = leaf->GetSubdivisionCandidate(); 
    14491449                 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp

    r1545 r1551  
    186186                VssRay *newRay = mRayCaster->CastRay(sray, mViewSpaceBox, false); 
    187187                //cout << "\np1: " << p1 << "\np : " <<  p << "\np2: " << p2 << endl; 
    188                 if (!newRay)  
    189                         return 0; 
    190 cout << "here42" << endl; 
     188                if (!newRay) return 0; 
     189 
    191190                const bool enqueued = HandleRay(newRay); 
    192191                 
     
    410409                ConstructViewCells(mViewSpaceBox); 
    411410                cout << "view cells loaded" << endl; 
     411        } 
     412        else if (1) 
     413        {        cout << "here2255566" << endl;  
     414                //-- load view cells from file 
     415                //-- test successful view cells loading by exporting them again 
     416                VssRayContainer dummies; 
     417                mViewCellsManager->Visualize(mObjects, dummies); 
     418                mViewCellsManager->ExportViewCells("test.xml.zip", mViewCellsManager->GetExportPvs(), mObjects); 
    412419        } 
    413420 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r1548 r1551  
    4242class Exporter; 
    4343 
    44 #if 0 
    45 template <typename T> class GtPriority 
    46 { 
    47 public: 
    48         bool operator() (const T c1, const T c2) const 
    49         { 
    50                 //return false; 
    51                 return c1->GetPriority() < c2->GetPriority(); 
    52         } 
    53 }; 
    54  
    55 typedef std::priority_queue<SubdivisionCandidate *,  
    56                                                         std::vector<SubdivisionCandidate *>,  
    57                                                         GtPriority<std::vector<SubdivisionCandidate *>::value_type> > SplitQueue; 
    58 #endif 
    59  
    60  
    61  
    62 /** View space partition statistics. 
     44 
     45 
     46/** View space / object space hierarchy statistics. 
    6347*/ 
    6448class HierarchyStatistics: public StatisticsBase 
  • GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp

    r1528 r1551  
    4141                hitA.mPoint = ray.Extrap(ray.intersections[0].mT); 
    4242                hitA.mNormal = ray.intersections[0].mNormal;  
    43         //      cout << "here91 " << hitA.mPoint << " !obj: " << hitA.mObject << endl; 
     43        //      cout << "hita: " << hitA.mPoint << " !obj: " << hitA.mObject << endl; 
    4444        } 
    4545         
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp

    r1415 r1551  
    10281028          leaf->mViewCell = viewCell; 
    10291029          // push back pointer to this leaf 
    1030           viewCell->mLeaf = leaf; 
     1030          viewCell->mLeaves[0] = leaf; 
    10311031      vc.push_back(viewCell); 
    10321032    } else { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp

    r1528 r1551  
    15851585                VspViewCell *vc = dynamic_cast<VspViewCell *>(*vit); 
    15861586 
    1587                 VspLeaf *leaf = vc->mLeaf; 
     1587                VspLeaf *leaf = vc->mLeaves[0]; 
    15881588                dirtyList.push_back(leaf->GetSubdivisionCandidate()); 
    15891589        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp

    r1545 r1551  
    103103                } 
    104104        } 
    105 //      cout << "here81 " << hitA.mObject << endl; 
     105 
    106106        const bool validA =  
    107107                ValidateRay(simpleRay.mOrigin, simpleRay.mDirection, box, hitA); 
     
    136136                        vssRays.push_back(vssRay); 
    137137                        ++ hits; 
    138                         //cout << "here70 vssray 1: " << *vssRay << " " << vssRay->mTermination - vssRay->mOrigin << endl; 
     138                        //cout << "vssray 1: " << *vssRay << " " << vssRay->mTermination - vssRay->mOrigin << endl; 
    139139                } 
    140140 
     
    152152                        vssRays.push_back(vssRay); 
    153153                        ++ hits; 
    154                         //cout << "here71 vssray 2: " << *vssRay << endl; 
     154                        //cout << "vssray 2: " << *vssRay << endl; 
    155155                } 
    156156        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1545 r1551  
    130130 
    131131 
     132ViewCell::~ViewCell() 
     133{ 
     134} 
     135 
     136 
    132137const ObjectPvs &ViewCell::GetPvs() const 
    133138{ 
     
    250255{ 
    251256        const bool result = mPvs.AddSample(sample, pdf, contribution); 
    252          
    253257        mPvsSizeValid = false; // have to recompute pvs size 
    254258 
     
    328332 
    329333 
     334 
    330335/************************************************************************/ 
    331336/*                class ViewCellsStatistics implementation              */ 
    332337/************************************************************************/ 
    333  
    334  
    335338 
    336339 
     
    22272230                tstack.pop(); 
    22282231 
    2229                 vc->SetId(currentId ++); 
     2232                if (vc->GetId() != -1) // out of bounds 
     2233                        vc->SetId(currentId ++); 
    22302234 
    22312235                if (!vc->IsLeaf()) 
     
    22662270                stream << "pvs=\""; 
    22672271                 
    2268                 //-- export pvs 
     2272                //-- export pvs, i.e., the ids of the objects in the pvs 
    22692273                if (exportPvs) 
    22702274                { 
    22712275                        ExportPvs(viewCell, stream); 
    22722276                } 
    2273  
    22742277                stream << "\" />" << endl; 
    22752278        } 
     
    22832286                stream << "pvs=\""; 
    22842287 
    2285                 //-- NOTE: do not export pvss for interior view cells because 
     2288                // NOTE: do not export pvss for interior view cells because 
    22862289                // they can be completely reconstructed from the leaf pvss 
    2287                 if (0) 
    2288                         ExportPvs(viewCell, stream); 
     2290                // on the other hand: we could store a tag with the compression scheme, 
     2291        // then some scheme were pvs is in the interiors could be used 
     2292                if (0) ExportPvs(viewCell, stream); 
    22892293                 
    22902294                stream << "\" >" << endl; 
     
    23272331                } 
    23282332        } 
     2333} 
     2334 
     2335 
     2336void ViewCellsTree::SetViewCellsManager(ViewCellsManager *vcm) 
     2337{ 
     2338        mViewCellsManager = vcm; 
    23292339} 
    23302340 
     
    24162426 
    24172427 
    2418  
    2419  
    24202428/************************************************************************/ 
    24212429/*                    MergeStatistics implementation                    */ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h

    r1545 r1551  
    107107        /** Default destructor. 
    108108        */ 
    109         virtual ~ViewCell() {} 
    110  
     109        virtual ~ViewCell(); 
    111110        /** Returns Pvs. 
    112111        */ 
    113112        const ObjectPvs &GetPvs() const; 
    114  
    115113        /** Returns pvs. 
    116114        */ 
    117115        ObjectPvs &GetPvs(); 
    118  
    119116        /** Completely substitutes the pvs. 
    120117        */ 
    121118        void SetPvs(const ObjectPvs &pvs); 
    122  
    123119        /** Type of view cells. 
    124120        */ 
    125121        int Type() const; 
    126  
    127          
    128122        /** Adds a passing ray to the passing ray container. 
    129123        */ 
    130124        void AddPassingRay(const Ray &ray, const int contributions); 
    131  
    132125        /** Returns volume of the view cell. 
    133126        */ 
    134127        float GetVolume() const; 
    135  
    136128        /** Returns area of the view cell. 
    137129        */ 
    138130        float GetArea() const; 
    139  
    140131        /** Sets the volume of the view cell. 
    141132        */ 
    142133        void SetVolume(float volume); 
    143          
    144134        /** Sets the area of the view cell. 
    145135        */ 
    146136        void SetArea(float area); 
    147  
    148  
    149137        /** if this view cell is the root of a view cell hierarchy 
    150138        */ 
    151139        bool IsRoot() const; 
    152  
    153140        /** Returns parent view cell. 
    154141        */ 
    155142        ViewCellInterior *GetParent() const; 
    156  
    157143        /** Sets parent of this view cell. 
    158144        */ 
    159145        void SetParent(ViewCellInterior *parent); 
    160  
    161  
    162146        /** Sets the mesh for this view cell. 
    163147        */ 
     
    231215 
    232216 
    233  
    234         //////////////// 
     217        ////////// 
    235218        //-- mailing stuff 
    236  
    237219 
    238220        static void NewMail(const int reserve = 1)  
     
    346328        } 
    347329 
    348         /** Returns if this view cell is active. 
     330        /** Returns active view cell, i.e. this view cell or 
     331                a parent view cell which is set as active view cell. 
    349332        */ 
    350333        ViewCell *GetActiveViewCell() const  
     
    355338        void SetActiveViewCell(ViewCell *vc) 
    356339        { mActiveViewCell = vc;} 
    357  
    358340         
    359341        /** points to the currently active view cell. This is the 
     
    375357        ViewCellLeaf(mesh) {  } 
    376358                 
    377  
    378359        bool IsLeaf() const 
    379360        { 
     
    381362        } 
    382363 
    383  
    384         /// Leaf of some hierarchy which is part of this view cell. 
    385         T mLeaf; 
     364        /// Leaves of some hierarchy which contains this view cell. 
     365        vector<T> mLeaves; 
    386366}; 
    387367 
     
    507487        void SetRoot(ViewCell *root); 
    508488 
    509         //float ComputeVolume(ViewCell *vc); 
    510  
    511489        /** Assignes unique ids to view cells. 
    512490        */ 
     
    521499        int CountKdPvs(const ViewCellLeaf *vc) const; 
    522500 
    523         void SetViewCellsManager(ViewCellsManager *vcm) 
    524         { 
    525                 mViewCellsManager = vcm; 
    526         } 
     501        /** Sets pointer to view cells manager. 
     502        */ 
     503        void SetViewCellsManager(ViewCellsManager *vcm); 
    527504 
    528505protected: 
     
    595572        void ResetMergeQueue(); 
    596573 
    597         /** Updates the current top level of view cells. 
     574        /** Updates the current cut of view cells. 
    598575                @returns number of newly merged view cells 
    599576        */ 
     
    643620        /// if the view cell tree hold compressed pvs 
    644621        int mViewCellsStorage; 
    645  
     622        /// pointer to the view cells manager 
    646623        ViewCellsManager *mViewCellsManager; 
     624        /// the root of the view cells hierarchy 
    647625        ViewCell *mRoot; 
    648626 
    649627        /// if merge visualization should be shown 
    650628        bool mExportMergedViewCells; 
    651  
    652          
    653629        /// intermediate container of merged view cells. 
    654630        ViewCellContainer mMergedViewCells; 
    655          
    656  
    657631        /// if merged view cells are refined. 
    658632        bool mRefineViewCells; 
    659  
    660633        /// weights between variance and render cost increase (must be between zero and one) 
    661634        float mRenderCostWeight; 
     
    666639    float mDeviation; 
    667640        float mAvgRenderCost; 
     641         
    668642        /// the area is used for pvs heuristics 
    669643        int mUseAreaForPvs; 
    670  
     644        /// number of currently active view cells (=current cut) 
    671645        int mNumActiveViewCells; 
    672  
    673646        /// minimal number of view cells 
    674647        int mMergeMinViewCells; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp

    r1545 r1551  
    420420        if (!mOutOfBoundsCellPartOfTree) 
    421421        { 
     422                cout << "here223" << endl; 
    422423                // out of bounds cell not part of tree => 
    423424                // delete manually 
    424425                DEL_PTR(mOutOfBoundsCell); 
    425         } 
     426        }else cout << "here991" << endl; 
    426427} 
    427428 
     
    583584   
    584585        int polysSize = 0; 
    585         cout << "here55 " << mBbox << endl; 
    586          
    587 cout << "here99"; 
     586 
    588587        for (int i = 0; i < limit; ++ i) 
    589         {cout << "q"; 
    590         Mesh *mesh = viewCells[i]->GetMesh(); 
     588        { 
     589                Mesh *mesh = viewCells[i]->GetMesh(); 
     590 
    591591                if (mesh)  
    592                 {cout << "w"; 
     592                { 
    593593                        // copy the mesh into polygons and add to BSP tree aabb 
    594594                        mBbox.Include(viewCells[i]->GetBox());  
     
    596596                } 
    597597        } 
    598 cout << "here155 " << mBbox << endl; 
     598 
    599599        return polysSize; 
    600600} 
     
    608608        int limit = (maxObjects > 0) ?  
    609609                Min((int)objects.size(), maxObjects) : (int)objects.size(); 
    610   cout << "here88"; 
     610   
    611611        for (int i = 0; i < limit; ++i) 
    612         {cout << "e"; 
     612        { 
    613613                Intersectable *object = objects[i]; 
    614614                Mesh *mesh = NULL; 
     
    638638                 
    639639        if (!mesh) continue; 
     640 
    640641                // copy the mesh data to polygons 
    641642                if (addToBbox) 
    642                 {cout << "b"; 
     643                { 
    643644                        mBbox.Include(object->GetBox()); // add to BSP tree aabb 
    644645                } 
     
    659660void BspTree::Construct(const ViewCellContainer &viewCells) 
    660661{ 
    661         cout << "here5500000000" << endl; 
    662662        // construct hierarchy over the given view cells 
    663663        mUsePredefinedViewCells = true; 
     
    10061006 
    10071007                leaf->SetViewCell(viewCell); 
    1008                 viewCell->mLeaf = leaf; 
     1008                viewCell->mLeaves.push_back(leaf); 
    10091009 
    10101010                //float probability = max(0.0f, tData.mProbability); 
     
    22412241                } 
    22422242        } 
    2243  
    2244         // also add out of bounds cell 
    2245         if (0 && !mOutOfBoundsCell->Mailed()) 
    2246         { 
    2247                 mOutOfBoundsCell->Mail(); 
    2248                 viewCells.push_back(mOutOfBoundsCell); 
    2249         } 
    2250  
    2251         cout << "here555 " << viewCells.size() << endl; 
    2252  
    22532243} 
    22542244 
     
    23892379        for (it = leaves.begin(); it != it_end; ++ it) 
    23902380        { 
    2391                 BspLeaf *l = dynamic_cast<BspViewCell *>(*it)->mLeaf; 
    2392                 ConstructGeometry(l, vcGeom); 
     2381                BspViewCell *bspVc = dynamic_cast<BspViewCell *>(*it); 
     2382                vector<BspLeaf *>::const_iterator bit, bit_end = bspVc->mLeaves.end(); 
     2383 
     2384                for (bit = bspVc->mLeaves.begin(); bit != bit_end; ++ bit) 
     2385                { 
     2386                        BspLeaf *l = *bit; 
     2387                        ConstructGeometry(l, vcGeom); 
     2388                } 
    23932389        } 
    23942390} 
     
    28102806                iit = ray->mViewCells.begin(); 
    28112807                BspViewCell *bspVc = dynamic_cast<BspViewCell *>(*(iit ++)); 
    2812                 BspLeaf *leaf = bspVc->mLeaf; 
     2808                BspLeaf *leaf = bspVc->mLeaves[0]; 
    28132809                 
    28142810                // traverse intersections  
     
    28192815                        BspLeaf *prevLeaf = leaf; 
    28202816                        bspVc = dynamic_cast<BspViewCell *>(*iit); 
    2821             leaf = bspVc->mLeaf; 
     2817            leaf = bspVc->mLeaves[0]; 
    28222818 
    28232819                        // view space not valid or same view cell 
     
    33383334 
    33393335 
    3340 bool BspTree::Export(ofstream &stream) 
     3336bool BspTree::Export(OUT_STREAM &stream) 
    33413337{ 
    33423338        ExportNode(mRoot, stream); 
    3343  
    33443339        return true; 
    33453340} 
    33463341 
    33473342 
    3348 void BspTree::ExportNode(BspNode *node, ofstream &stream) 
     3343void BspTree::ExportNode(BspNode *node, OUT_STREAM &stream) 
    33493344{ 
    33503345        if (node->IsLeaf()) 
    33513346        { 
    33523347                BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
    3353                          
    3354                 int id = -1; 
    3355                 if (leaf->GetViewCell() != mOutOfBoundsCell) 
    3356                 { 
    3357                         id = leaf->GetViewCell()->GetId(); 
    3358                 } 
     3348                ViewCell *viewCell = mViewCellsTree->GetActiveViewCell(leaf->GetViewCell()); 
     3349 
     3350                const int id = viewCell->GetId(); 
    33593351 
    33603352                stream << "<Leaf viewCellId=\"" << id << "\" />" << endl; 
     
    33763368} 
    33773369 
    3378 } 
     3370 
     3371} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h

    r1545 r1551  
    646646        */ 
    647647        void ConstructGeometry(ViewCell* vc, BspNodeGeometry &geom) const; 
    648  
    649648                         
    650649        /** Sets pointer to view cells manager. 
     
    675674        /** Exports Bsp tree to file. 
    676675        */ 
    677         bool Export(ofstream &stream); 
     676        bool Export(OUT_STREAM &stream); 
    678677 
    679678        /** Pointer to the view cells tree. 
     
    718717        }; 
    719718 
    720         void ExportNode(BspNode *node, ofstream &stream); 
     719        void ExportNode(BspNode *node, OUT_STREAM &stream); 
    721720 
    722721        /** Evaluates tree stats in the BSP tree leafs. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1548 r1551  
    3030 
    3131 
    32  
    3332namespace GtpVisibilityPreprocessor { 
    3433 
     
    667666        { 
    668667                //-- export bounding boxes 
    669  
    670668                stream << "<BoundingBoxes>" << endl; 
    671  
    672669                ObjectContainer::const_iterator oit, oit_end = objects.end(); 
    673670 
     
    677674                        const AxisAlignedBox3 box = mi->GetBox(); 
    678675 
     676                        //////////// 
    679677                        //-- the bounding boxes 
    680678                        stream << "<BoundingBox" << " id=\"" << mi->GetId() << "\"" 
     
    687685 
    688686         
     687        ///////////// 
    689688        //-- export the view cells and the pvs 
    690689 
    691690        const int numViewCells = mCurrentViewCellsStats.viewCells; 
    692  
    693691        stream << "<ViewCells number=\"" << numViewCells << "\" >" << endl; 
    694          
     692 
    695693        mViewCellsTree->Export(stream, exportPvs); 
    696694 
     
    698696 
    699697 
     698        ////////// 
    700699        //-- export the view space hierarchy 
    701700         
     
    753752        Debug << "stepsize: " << stepSize << endl; 
    754753         
    755  
    756754        const float totalRenderCost = mViewCellsTree->GetRoot()->GetRenderCost(); 
    757755        const float totalVol = GetViewSpaceBox().GetVolume(); 
    758756 
    759757        int currentPvs = minVal;//(int)ceil(minRenderCost); 
    760  
    761758         
    762759        int i = 0; 
    763760        int j = 0; 
    764  
    765761        float volSum = 0; 
    766762        int smallerSum = 0; 
     
    13101306        { 
    13111307                // set view space box to bounding box of the view cells 
    1312                 /*AxisAlignedBox3 bbox; 
     1308                AxisAlignedBox3 bbox; 
    13131309                bbox.Initialize(); 
    13141310                ViewCellContainer::iterator it = mViewCells.begin(), it_end = mViewCells.end(); 
     
    13171313                        bbox.Include(GetViewCellBox(*it)); 
    13181314                } 
    1319                 SetViewSpaceBox(bbox);*/ 
     1315                SetViewSpaceBox(bbox); 
    13201316         
    13211317                cout << "generated " << (int)mViewCells.size() << " view cells using the geometry from file " << filename << endl; 
     
    19651961        else // no view cells tree, handle view cells "myself" 
    19661962        { 
    1967                 for (int i = 0; i < (int)mViewCells.size(); ++ i) 
    1968                 { 
    1969                         mViewCells[i]->SetId(i); 
     1963                int i = 0; 
     1964                ViewCellContainer::const_iterator vit, vit_end = mViewCells.end(); 
     1965                for (vit = mViewCells.begin(); vit != vit_end; ++ vit) 
     1966                { 
     1967                        if ((*vit)->GetId() != -1)  
     1968                                mViewCells[i]->SetId(i ++); 
    19701969                } 
    19711970        } 
     
    25602559        } 
    25612560        else 
    2562         {       cout << "here222" << endl; 
     2561        {        
    25632562                // use predefined view cells geometry =>  
    25642563                // contruct bsp hierarchy over them 
     
    26202619 
    26212620 
    2622 void BspViewCellsManager::ExportMergedViewCells(const ObjectContainer &objects) 
     2621void ViewCellsManager::ExportMergedViewCells(const ObjectContainer &objects) 
    26232622{ 
    26242623        // save color code 
     
    27252724                ObjectPvs pvs; 
    27262725                UpdatePvsForEvaluation(root, pvs); 
    2727                  
    27282726        } 
    27292727 
     
    27462744        } 
    27472745 
    2748         ResetViewCells(); // reset view cells 
     2746        // recompute view cells and stats 
     2747        ResetViewCells(); 
    27492748        Debug << "\nView cells after merge:\n" << mCurrentViewCellsStats << endl; 
    27502749 
     2750        //  visualization of the view cells 
    27512751        if (1) ExportMergedViewCells(objects); 
    2752  
    2753         // only for debugging purpose: test if the subdivision is valid 
    2754         if (0) TestSubdivision(); 
    27552752 
    27562753        // compute final meshes and volume / area 
     
    27872784         
    27882785        int savedColorCode = mColorCode; 
    2789                  
     2786         
    27902787        if (1) // export final view cells 
    27912788        { 
     
    28072804                cout << "finished" << endl; 
    28082805        } 
     2806 
    28092807        // reset color code 
    28102808        mColorCode = savedColorCode; 
     
    29672965        { 
    29682966                BspNodeGeometry geom; 
    2969                 BspLeaf *leaf = dynamic_cast<BspViewCell *>(*it)->mLeaf; 
    2970                 mBspTree->ConstructGeometry(leaf, geom); 
     2967                mBspTree->ConstructGeometry(*it, geom); 
    29712968 
    29722969                const float lVol = geom.GetVolume(); 
    2973                  
    29742970                newVol += lVol; 
    29752971                subdivVol += (*it)->GetVolume(); 
    29762972 
    2977                 float thres = 0.9f; 
     2973                const float thres = 0.9f; 
    29782974                if ((lVol < ((*it)->GetVolume() * thres)) || 
    29792975                        (lVol * thres > ((*it)->GetVolume()))) 
     
    29912987                                                                                                 const AxisAlignedBox3 *sceneBox, 
    29922988                                                                                                 const AxisAlignedPlane *clipPlane 
    2993                                                                                                 ) const 
    2994 { 
     2989                                                                                                 ) const 
     2990{cout << "here55543 " << vc->GetId() << endl; 
     2991        // out of bounds cell 
     2992        if (vc->GetId() == -1) 
     2993                return; 
     2994 
    29952995        // export mesh if available 
    29962996        if (vc->GetMesh()) 
     
    29992999                return; 
    30003000        } 
     3001 
    30013002        // otherwise construct from leaves 
    30023003        if (clipPlane) 
     
    30113012                { 
    30123013                        BspNodeGeometry geom; 
    3013  
    30143014                        BspNodeGeometry front; 
    30153015                        BspNodeGeometry back; 
    30163016 
    3017                         BspLeaf *leaf = dynamic_cast<BspViewCell *>(*it)->mLeaf; 
    3018                         mBspTree->ConstructGeometry(leaf, geom); 
     3017                        mBspTree->ConstructGeometry(*it, geom); 
    30193018 
    30203019                        const float eps = 0.00000001f; 
     
    30333032                                                                   eps); 
    30343033         
    3035                                 //Debug << "geo size: " << geom.Size() << endl; 
    3036                                 //Debug << "size b: " << back.Size() << " f: " << front.Size() << endl; 
    30373034                                if (back.Valid()) 
    3038                                 { 
     3035                                {        
    30393036                                        exporter->ExportPolygons(back.GetPolys()); 
    30403037                                }                        
     
    30463043                BspNodeGeometry geom; 
    30473044                mBspTree->ConstructGeometry(vc, geom); 
    3048                          
    30493045                exporter->ExportPolygons(geom.GetPolys()); 
    30503046        } 
     
    30543050void BspViewCellsManager::CreateMesh(ViewCell *vc) 
    30553051{ 
    3056         // delete previous mesh 
    3057         ///DEL_PTR(vc->GetMesh()); 
     3052        // note: should previous mesh be deleted (via mesh manager?) 
    30583053        BspNodeGeometry geom; 
    30593054        mBspTree->ConstructGeometry(vc, geom); 
     
    30803075        { 
    30813076                BspNodeGeometry geom; 
    3082                 BspLeaf *leaf = dynamic_cast<BspViewCell *>(*it)->mLeaf; 
    3083                 mBspTree->ConstructGeometry(leaf, geom); 
     3077 
     3078                mBspTree->ConstructGeometry(*it, geom); 
    30843079 
    30853080                const float lVol = geom.GetVolume(); 
    30863081                const float lArea = geom.GetArea(); 
    30873082 
    3088                 //(*it)->SetVolume(vol); 
    3089                 //(*it)->SetArea(area); 
    3090  
    30913083                area += lArea; 
    30923084                volume += lVol; 
    3093  
    3094         CreateMesh(*it); 
     3085         
     3086                CreateMesh(*it); 
    30953087        } 
    30963088 
     
    31063098                return NULL; 
    31073099        } 
    3108  
    31093100        if (!mViewSpaceBox.IsInside(point)) 
    31103101        { 
    31113102                return NULL; 
    31123103        } 
    3113  
    31143104        return mBspTree->GetViewCell(point); 
    31153105} 
     
    31413131                                                                                  const ObjectContainer &objects) 
    31423132{ 
    3143 #if TODO 
     3133        if (!ViewCellsConstructed() || !ViewCellsTreeConstructed()) 
     3134        { 
     3135                return false; 
     3136        } 
     3137 
    31443138        cout << "exporting view cells to xml ... "; 
    3145         std::ofstream stream; 
     3139 
     3140        OUT_STREAM stream(filename.c_str()); 
    31463141 
    31473142        // for output we need unique ids for each view cell 
    31483143        CreateUniqueViewCellIds(); 
    31493144 
    3150  
    3151         stream.open(filename.c_str()); 
    31523145        stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"<<endl; 
    31533146        stream << "<VisibilitySolution>" << endl; 
    31543147 
    3155         //-- the view space bounding box 
    3156         stream << "<ViewSpaceBox"  
     3148        if (exportPvs)  
     3149        { 
     3150                ////////// 
     3151                //-- export bounding boxes: they are used to identify the objects from the pvs and 
     3152                //-- assign them to the entities in the rendering engine 
     3153 
     3154                stream << "<BoundingBoxes>" << endl; 
     3155                ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     3156 
     3157                for (oit = objects.begin(); oit != oit_end; ++ oit) 
     3158                { 
     3159                        MeshInstance *mi = dynamic_cast<MeshInstance *>(*oit); 
     3160                        const AxisAlignedBox3 box = mi->GetBox(); 
     3161                         
     3162                        stream << "<BoundingBox" << " id=\"" << mi->GetId() << "\"" 
     3163                                   << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 
     3164                                   << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 
     3165                } 
     3166 
     3167                stream << "</BoundingBoxes>" << endl; 
     3168        } 
     3169 
     3170        /////////// 
     3171        //-- export the view cells and the pvs 
     3172 
     3173        const int numViewCells = mCurrentViewCellsStats.viewCells; 
     3174        stream << "<ViewCells number=\"" << numViewCells << "\" >" << endl; 
     3175 
     3176        mViewCellsTree->Export(stream, exportPvs); 
     3177         
     3178        stream << "</ViewCells>" << endl; 
     3179 
     3180        ///////////// 
     3181        //-- export the view space hierarchy 
     3182        stream << "<ViewSpaceHierarchy type=\"bsp\"" 
    31573183                   << " min=\"" << mViewSpaceBox.Min().x << " " << mViewSpaceBox.Min().y << " " << mViewSpaceBox.Min().z << "\"" 
    3158                    << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\" />" << endl; 
    3159  
    3160         //-- the type of the view cells hierarchy 
    3161          
    3162         // NOTE: load in vsp bsp here because bsp and vsp bsp can use same tree and vsp bsp is bug free 
    3163         stream << "<Hierarchy name=\"vspBspTree\" >" << endl;  
    3164          
    3165         //-- load the view cells itself, i.e., the ids and the pvs 
    3166         stream << "<ViewCells>" << endl; 
    3167  
    3168         mViewCellsTree->Export(stream, exportPvs); 
    3169  
    3170         stream << "</ViewCells>" << endl; 
    3171  
    3172         //-- load the hierarchy 
    3173         stream << "<Hierarchy>" << endl; 
     3184                   << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\">" << endl; 
     3185 
    31743186        mBspTree->Export(stream); 
    3175         stream << endl << "</Hierarchy>" << endl; 
    3176  
     3187 
     3188        // end tags 
     3189        stream << "</ViewSpaceHierarchy>" << endl; 
    31773190        stream << "</VisibilitySolution>" << endl; 
     3191 
    31783192        stream.close(); 
    3179  
    31803193        cout << "finished" << endl; 
    3181 #endif 
     3194 
    31823195        return true; 
    31833196} 
     
    35163529        { 
    35173530                KdViewCell *kdVc = dynamic_cast<KdViewCell *>(*it); 
    3518                 exporter->ExportBox(mKdTree->GetBox(kdVc->mLeaf)); 
     3531                exporter->ExportBox(mKdTree->GetBox(kdVc->mLeaves[0])); 
    35193532        } 
    35203533} 
     
    38513864        { 
    38523865                BspViewCell *bspVc = dynamic_cast<BspViewCell *>(viewCell); 
    3853  
    3854                 return bspVc->mLeaf; 
     3866                return bspVc->mLeaves[0]; 
    38553867        } 
    38563868        else 
     
    40824094bool VspBspViewCellsManager::ViewPointValid(const Vector3 &viewPoint) const 
    40834095{ 
    4084   // $$JB -> implemented in viewcellsmanager (slower, but allows dynamic 
    4085   // validy update in preprocessor for all managers) 
    4086   return ViewCellsManager::ViewPointValid(viewPoint); 
    4087  
    4088   //    return mViewSpaceBox.IsInside(viewPoint) && 
    4089   //               mVspBspTree->ViewPointValid(viewPoint); 
     4096        // $$JB -> implemented in viewcellsmanager (slower, but allows dynamic 
     4097        // validy update in preprocessor for all managers) 
     4098        return ViewCellsManager::ViewPointValid(viewPoint); 
     4099 
     4100        //      return mViewSpaceBox.IsInside(viewPoint) && 
     4101        //                 mVspBspTree->ViewPointValid(viewPoint); 
    40904102} 
    40914103 
     
    40994111        VssRayContainer visRays; 
    41004112        GetRaySets(sampleRays, mVisualizationSamples, visRays); 
    4101  
    4102          
    4103         if (0)  
     4113         
     4114        if (1)  
    41044115        {        
    41054116                ////////////////// 
     
    41464157        } 
    41474158 
    4148         if (0) 
    4149         { 
    4150                 cout << "exporting depth map ... "; 
    4151  
    4152                 Exporter *exporter = Exporter::GetExporter("depth_map.x3d"); 
    4153                 if (exporter) 
    4154                 { 
    4155                         if (1) 
    4156                         { 
    4157                                 exporter->SetWireframe(); 
    4158                                 exporter->ExportBox(mViewSpaceBox); 
    4159                                 exporter->SetFilled(); 
    4160                         } 
    4161  
    4162                         if (mExportGeometry) 
    4163                         { 
    4164                                 exporter->ExportGeometry(objects); 
    4165                         } 
    4166  
    4167                         const int maxDepth = mVspBspTree->GetStatistics().maxDepth; 
    4168  
    4169                         ViewCellContainer::const_iterator vit, vit_end = mViewCells.end(); 
    4170  
    4171                         for (vit = mViewCells.begin(); vit != mViewCells.end(); ++ vit) 
    4172                         { 
    4173                                 ViewCell *vc = *vit; 
    4174  
    4175                                 ViewCellContainer leaves; 
    4176                                 mViewCellsTree->CollectLeaves(vc, leaves); 
    4177  
    4178                                 ViewCellContainer::const_iterator lit, lit_end = leaves.end(); 
    4179  
    4180                                 for (lit = leaves.begin(); lit != lit_end; ++ lit) 
    4181                                 { 
    4182                                         BspLeaf *leaf = dynamic_cast<BspViewCell *>(*lit)->mLeaf; 
    4183  
    4184                                         Material m;  
    4185  
    4186                                         float relDepth = (float)leaf->GetDepth() / (float)maxDepth; 
    4187                                         m.mDiffuseColor.r = relDepth; 
    4188                                         m.mDiffuseColor.g = 0.0f; 
    4189                                         m.mDiffuseColor.b = 1.0f - relDepth; 
    4190  
    4191                     exporter->SetForcedMaterial(m); 
    4192                                  
    4193  
    4194                                         BspNodeGeometry geom; 
    4195                                         mVspBspTree->ConstructGeometry(leaf, geom); 
    4196                                         exporter->ExportPolygons(geom.GetPolys()); 
    4197                                 } 
    4198                         } 
    4199  
    4200                         delete exporter; 
    4201                 } 
    4202  
    4203  
    4204                 cout << "finished" << endl; 
    4205         } 
    4206  
     4159        //////////////// 
    42074160        //-- visualization of the BSP splits 
     4161 
    42084162        bool exportSplits = false; 
    42094163        Environment::GetSingleton()->GetBoolValue("VspBspTree.Visualization.exportSplits", exportSplits); 
     
    42164170        } 
    42174171 
     4172        //////// 
    42184173        //-- export single view cells 
    42194174        ExportBspPvs(objects, visRays); 
     
    43084263                { 
    43094264                        // output rays stored with the view cells during subdivision 
    4310                         if (1) 
     4265                        VssRayContainer vcRays; 
     4266            VssRayContainer collectRays; 
     4267 
     4268                        raysOut = min((int)rays.size(), 100); 
     4269 
     4270                        // collect intial view cells 
     4271                        ViewCellContainer leaves; 
     4272                        mViewCellsTree->CollectLeaves(vc, leaves); 
     4273 
     4274                        ViewCellContainer::const_iterator vit, vit_end = leaves.end(); 
     4275        
     4276                        for (vit = leaves.begin(); vit != vit_end; ++ vit) 
    43114277                        { 
    4312                                 VssRayContainer vcRays; 
    4313                 VssRayContainer collectRays; 
    4314  
    4315                                 raysOut = min((int)rays.size(), 100); 
    4316  
    4317                                 // collect intial view cells 
    4318                                 ViewCellContainer leaves; 
    4319                                 mViewCellsTree->CollectLeaves(vc, leaves); 
    4320  
    4321                                 ViewCellContainer::const_iterator vit, vit_end = leaves.end(); 
    4322         
    4323                                 for (vit = leaves.begin(); vit != vit_end; ++ vit) 
     4278                                BspLeaf *vcLeaf = dynamic_cast<BspViewCell *>(*vit)->mLeaves[0]; 
     4279                                 
     4280                                VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); 
     4281 
     4282                                for (rit = vcLeaf->mVssRays.begin(); rit != rit_end; ++ rit) 
    43244283                                { 
    4325                                         BspLeaf *vcLeaf = dynamic_cast<BspViewCell *>(*vit)->mLeaf; 
    4326                                  
    4327                                         VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); 
    4328  
    4329                                         for (rit = vcLeaf->mVssRays.begin(); rit != rit_end; ++ rit) 
    4330                                         { 
    4331                                                 collectRays.push_back(*rit); 
    4332                                         } 
     4284                                        collectRays.push_back(*rit); 
    43334285                                } 
    4334  
    4335                                 VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 
    4336  
    4337                                 for (rit = collectRays.begin(); rit != rit_end; ++ rit) 
    4338                                 { 
    4339                                         float p = RandomValue(0.0f, (float)collectRays.size()); 
     4286                        } 
     4287 
     4288                        VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 
     4289 
     4290                        for (rit = collectRays.begin(); rit != rit_end; ++ rit) 
     4291                        { 
     4292                                float p = RandomValue(0.0f, (float)collectRays.size()); 
    43404293                         
    4341                                         if (p < raysOut) 
    4342                                                 vcRays.push_back(*rit); 
    4343                                 } 
    4344  
    4345                                 //Debug << "#rays: " << (int)vcRays.size() << endl; 
    4346  
    4347                                 //-- export rays piercing this view cell 
    4348                                 exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 
     4294                                if (p < raysOut) 
     4295                                        vcRays.push_back(*rit); 
    43494296                        } 
    4350                  
    4351                         // associate new rays with output view cell 
    4352                         if (0) 
    4353                         { 
    4354                                 VssRayContainer vcRays; 
    4355                                 raysOut = min((int)rays.size(), mVisualizationSamples); 
    4356  
    4357                                 // check whether we can add the current ray to the output rays 
    4358                                 for (int k = 0; k < raysOut; ++ k) 
    4359                                 { 
    4360                                         VssRay *ray = rays[k]; 
    4361                                         for     (int j = 0; j < (int)ray->mViewCells.size(); ++ j) 
    4362                                         { 
    4363                                                 ViewCell *rayvc = ray->mViewCells[j]; 
    4364          
    4365                                                 if (rayvc == vc) 
    4366                                                         vcRays.push_back(ray); 
    4367                                         } 
    4368                                 }        
    4369                                  
    4370                                 //-- export rays piercing this view cell 
    4371                                 exporter->ExportRays(vcRays, RgbColor(1, 1, 0)); 
    4372                         } 
    4373  
     4297 
     4298                        ////////// 
     4299                        //-- export rays piercing this view cell 
     4300                        exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 
    43744301                } 
    43754302                 
     
    43904317                        //////// 
    43914318                        //-- export pvs 
    4392                         ObjectPvsMap::const_iterator oit, 
    4393                                 oit_end = pvs.mEntries.end(); 
     4319                        ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 
    43944320 
    43954321                        Intersectable::NewMail(); 
     
    45734499                                                                                                        ) const 
    45744500{ 
     4501        // out of bounds cell 
     4502        if (vc->GetId() == -1) 
     4503                return; 
     4504 
    45754505        if (clipPlane) 
    45764506        { 
     
    45884518                        BspNodeGeometry back; 
    45894519 
    4590                         BspLeaf *leaf = dynamic_cast<BspViewCell *>(*it)->mLeaf; 
    4591                         mVspBspTree->ConstructGeometry(leaf, geom); 
     4520                        mVspBspTree->ConstructGeometry(*it, geom); 
    45924521 
    45934522                        const float eps = 0.0001f; 
     
    46054534                                                                   mViewSpaceBox,  
    46064535                                                                   eps); 
    4607          
    4608                                 //Debug << "geo size: " << geom.Size() << endl; 
    4609                                 //Debug << "size b: " << back.Size() << " f: " << front.Size() << endl; 
    46104536 
    46114537                                if (back.Valid()) 
     
    46464572                for (int j = 0; j < (int)leaves.size(); ++ j) 
    46474573                { 
    4648                         BspLeaf *leaf = dynamic_cast<BspViewCell *>(leaves[i])->mLeaf; 
     4574                        BspLeaf *leaf = dynamic_cast<BspViewCell *>(leaves[i])->mLeaves[0]; 
    46494575 
    46504576                        if (i != j) 
    46514577                        { 
    4652                                 BspLeaf *leaf2 =dynamic_cast<BspViewCell *>(leaves[j])->mLeaf; 
    4653                                  
    4654                                 int dist = mVspBspTree->TreeDistance(leaf, leaf2); 
     4578                                BspLeaf *leaf2 =dynamic_cast<BspViewCell *>(leaves[j])->mLeaves[0]; 
     4579                                const int dist = mVspBspTree->TreeDistance(leaf, leaf2); 
    46554580                                 
    46564581                                if (dist > maxDist) 
     
    46784603void VspBspViewCellsManager::CreateMesh(ViewCell *vc) 
    46794604{ 
    4680         //if (vc->GetMesh()) delete vc->GetMesh(); 
    46814605        BspNodeGeometry geom; 
    4682  
    46834606        mVspBspTree->ConstructGeometry(vc, geom); 
    46844607         
     
    47104633        { 
    47114634                BspNodeGeometry geom; 
    4712                 BspLeaf *leaf = dynamic_cast<BspViewCell *>(*it)->mLeaf; 
    4713                 mVspBspTree->ConstructGeometry(leaf, geom); 
     4635                mVspBspTree->ConstructGeometry(*it, geom); 
    47144636 
    47154637                const float lVol = geom.GetVolume(); 
    47164638                const float lArea = geom.GetArea(); 
    4717  
    4718                 //(*it)->SetVolume(vol); 
    4719                 //(*it)->SetArea(area); 
    47204639 
    47214640                area += lArea; 
     
    47444663        { 
    47454664                BspNodeGeometry geom; 
    4746                 BspLeaf *leaf = dynamic_cast<BspViewCell *>(*it)->mLeaf; 
    4747                 mVspBspTree->ConstructGeometry(leaf, geom); 
     4665                mVspBspTree->ConstructGeometry(*it, geom); 
    47484666 
    47494667                const float lVol = geom.GetVolume(); 
     
    50865004        { 
    50875005                VspViewCell *vspVc = dynamic_cast<VspViewCell *>(*it); 
    5088                 VspLeaf *l = vspVc->mLeaf; 
     5006                VspLeaf *l = vspVc->mLeaves[0]; 
    50895007 
    50905008                const AxisAlignedBox3 box =  
    5091                         mHierarchyManager->GetVspTree()->GetBoundingBox(vspVc->mLeaf); 
     5009                        mHierarchyManager->GetVspTree()->GetBoundingBox(vspVc->mLeaves[0]); 
    50925010                 
    50935011                if (sceneBox && !Overlap(*sceneBox, box)) 
     
    52725190                                for (vit = leaves.begin(); vit != vit_end; ++ vit) 
    52735191                                { 
    5274                                         VspLeaf *vcLeaf = dynamic_cast<VspViewCell *>(*vit)->mLeaf; 
     5192                                        VspLeaf *vcLeaf = dynamic_cast<VspViewCell *>(*vit)->mLeaves[0]; 
    52755193                                        VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); 
    52765194 
     
    54415359    for (it = leaves.begin(); it != it_end; ++ it) 
    54425360        { 
    5443                 VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLeaf; 
     5361                VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLeaves[0]; 
    54445362                const AxisAlignedBox3 box = mHierarchyManager->GetVspTree()->GetBoundingBox(leaf); 
    5445  
    54465363        IncludeBoxInMesh(box, *mesh); 
    54475364        } 
     
    54715388    for (it = leaves.begin(); it != it_end; ++ it) 
    54725389        { 
    5473                 VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLeaf; 
     5390                VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLeaves[0]; 
    54745391                 
    54755392                const AxisAlignedBox3 box = mHierarchyManager->GetVspTree()->GetBoundingBox(leaf); 
     
    54775394                const float lVol = box.GetVolume(); 
    54785395                const float lArea = box.SurfaceArea(); 
    5479  
    5480                 //(*it)->SetVolume(vol); 
    5481                 //(*it)->SetArea(area); 
    54825396 
    54835397                area += lArea; 
     
    57145628        disposeRays(evaluationSamples, NULL); 
    57155629} 
     5630 
    57165631#endif 
    5717  
    5718  
    5719 } 
     5632} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1545 r1551  
    578578        AxisAlignedPlane *GetClipPlane(); 
    579579         
     580        void ExportMergedViewCells(const ObjectContainer &objects); 
     581 
    580582        /////////////////////// 
    581583 
     
    777779        */ 
    778780        void TestSubdivision(); 
    779  
    780         void ExportMergedViewCells(const ObjectContainer &objects); 
    781781}; 
    782782 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp

    r1486 r1551  
    260260{ 
    261261        // sort view cells to help associating view cells according to their id 
    262         stable_sort(mViewCells.begin(), mViewCells.end(), vlt); 
     262        //stable_sort(mViewCells.begin(), mViewCells.end(), vlt); 
    263263 
    264264        // not parsing view cells anymore 
     
    393393        { 
    394394                cout << "["; 
    395                 StartViewCellInterior(attributes); 
     395                StartViewCell(attributes, false); 
    396396        } 
    397397 
     
    399399        { 
    400400                cout << "l"; 
    401                 StartViewCellLeaf(attributes); 
     401                StartViewCell(attributes, true); 
    402402        } 
    403403} 
     
    464464 
    465465 
    466 void ViewCellsParseHandlers::StartViewCellPvs(ViewCell *viewCell,  
    467                                                                                           AttributeList&  attributes) 
    468 { 
    469         int len = attributes.getLength(); 
     466void ViewCellsParseHandlers::StartViewCellPvs(ObjectPvs &pvs, const char *ptr) 
     467{ 
     468        // handle obect indices 
    470469        vector<int> objIndices; 
    471  
    472         for (int i = 0; i < len; ++ i)  
    473         { 
    474                 string attrName(StrX(attributes.getName(i)).LocalForm()); 
    475                  
    476                 if (attrName == "pvs")  
    477                 { 
    478                         StrX attrValue(attributes.getValue(i)); 
     470        char *endptr; 
    479471                         
    480                         // handle coordIndex 
    481                         objIndices.clear(); 
    482                         const char *ptr = attrValue.LocalForm(); 
    483                         char *endptr; 
    484                          
    485                         while (1) 
    486                         { 
    487                                 const int index = strtol(ptr, &endptr, 10); 
    488  
    489                                 if (ptr == endptr) break; 
    490  
    491                                 objIndices.push_back(index); 
    492  
    493                                 ptr = endptr; 
    494                         } 
    495  
    496                         //TODO: find objects and add them to pvs 
    497                         // TODO: get view cell with specified id 
    498                         MeshInstance dummyInst(NULL); 
    499  
    500                         vector<int>::const_iterator it, it_end = objIndices.end(); 
    501                         for (it = objIndices.begin(); it != it_end; ++ it) 
    502                         { 
    503                                 const int objId = *it;   
    504                                 dummyInst.SetId(objId); 
    505  
    506                                 ObjectContainer::iterator oit = 
    507                                         lower_bound(mObjects->begin(),  
    508                                                                 mObjects->end(),  
    509                                                                 (Intersectable *)&dummyInst, ilt);       
    510                                                          
    511                                 if ((oit != mObjects->end()) && ((*oit)->GetId() == objId)) 
    512                                 { 
    513                                         // $$JB we should store a float a per object which corresponds 
    514                                         // to sumof pdfs, i.e. its relative visibility 
    515                                         // temporarily set to 1.0f 
    516                                         viewCell->GetPvs().AddSample(*oit, 1.0f);                                
    517                                 } 
    518                                 else 
    519                                 { 
    520                                         cout << "error: object with id " << objId << " does not exist" << endl; 
    521                                 } 
    522                         } 
    523                 } 
    524                 else if (attrName == "id")  
    525                 { 
    526                         StrX attrValue(attributes.getValue(i)); 
    527                          
    528                         const char *ptr = attrValue.LocalForm(); 
    529                         char *endptr = NULL; 
    530                         const int id = strtol(ptr, &endptr, 10); 
    531  
    532                         viewCell->SetId(id); 
    533                 } 
    534                 /*else if (attrName == "active") 
    535                 { 
    536                         StrX attrValue(attributes.getValue(i)); 
    537                          
    538                         const char *ptr = attrValue.LocalForm(); 
    539                         char *endptr = NULL; 
    540                         const bool isActive = (bool)strtol(ptr, &endptr, 10); 
    541  
    542                         if (isActive) 
    543                                 viewCell->SetActive(); 
    544                 }*/ 
    545                 else if (attrName == "mergecost") 
    546                 { 
    547                         StrX attrValue(attributes.getValue(i)); 
    548                          
    549                         const char *ptr = attrValue.LocalForm(); 
    550                         char *endptr = NULL; 
    551                         const float cost = (float)strtod(ptr, &endptr); 
    552  
    553                         viewCell->SetMergeCost(cost); 
     472        while (1) 
     473        {       // read object ids 
     474                const int index = strtol(ptr, &endptr, 10); 
     475                if (ptr == endptr)  
     476                        break; 
     477                objIndices.push_back(index); 
     478                ptr = endptr; 
     479        } 
     480 
     481        // TODO:  
     482        // 1) find objects and add them to pvs 
     483        // 2) get view cell with specified id 
     484        MeshInstance dummyInst(NULL); 
     485 
     486        vector<int>::const_iterator it, it_end = objIndices.end(); 
     487        for (it = objIndices.begin(); it != it_end; ++ it) 
     488        { 
     489                const int objId = *it;   
     490                dummyInst.SetId(objId); 
     491 
     492                ObjectContainer::iterator oit = 
     493                        lower_bound(mObjects->begin(),  
     494                        mObjects->end(),  
     495                        (Intersectable *)&dummyInst, ilt);       
     496 
     497                if ((oit != mObjects->end()) && ((*oit)->GetId() == objId)) 
     498                { 
     499                        // $$JB we should store a float a per object which corresponds 
     500                        // to sumof pdfs, i.e. its relative visibility 
     501                        // temporarily set to 1.0f 
     502                        pvs.AddSample(*oit, 1.0f);                               
     503                } 
     504                else 
     505                { 
     506                        cout << "error: object with id " << objId << " does not exist" << endl; 
    554507                } 
    555508        } 
     
    705658        } 
    706659 
     660        /////////// 
    707661        //-- find associated view cell 
    708662 
     
    728682        { 
    729683                // TODO: get view cell with specified id 
    730                 ViewCellInterior dummyVc; 
    731                 dummyVc.SetId(viewCellId); 
    732  
    733                 ViewCellContainer::iterator vit = 
    734                         lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt); 
    735                          
    736                 BspViewCell *viewCell = dynamic_cast<BspViewCell *>(*vit); 
     684                ViewCellsMap::iterator vit = mViewCells.find(viewCellId); 
     685                BspViewCell *viewCell = dynamic_cast<BspViewCell *>((*vit).second); 
    737686         
    738687                if (viewCell->GetId() == viewCellId) 
     
    740689                        // create new view cell for bsp nodes 
    741690                        leaf->SetViewCell(viewCell); 
    742                         viewCell->mLeaf = leaf; 
     691                        viewCell->mLeaves.push_back(leaf); 
    743692                } 
    744693                else 
     
    793742 
    794743 
    795 void ViewCellsParseHandlers::StartViewCellLeaf(AttributeList& attributes) 
    796 { 
    797         ViewCellLeaf *viewCell = new ViewCellLeaf(); 
    798  
    799         if (mCurrentViewCell) // replace front or (if not NULL) back child 
    800         { 
    801                 ViewCellInterior *interior =  
    802                         dynamic_cast<ViewCellInterior *>(mCurrentViewCell); 
    803                 interior->SetupChildLink(viewCell); 
    804         } 
    805         else // root 
    806         { 
    807                 mViewCellsTree->SetRoot(viewCell); 
    808         } 
    809  
    810         StartViewCellPvs(viewCell, attributes); 
    811  
    812         // collect leaves 
    813         mViewCells.push_back(viewCell); 
    814 } 
    815  
    816  
    817 void ViewCellsParseHandlers::StartViewCellInterior(AttributeList& attributes) 
    818 { 
    819         ViewCellInterior* interior = new ViewCellInterior(); 
     744ViewCell *ViewCellsParseHandlers::GetOrCreateViewCell(const int id, const bool isLeaf) 
     745{ 
     746        ViewCellsMap::iterator vit = mViewCells.find(id); 
     747 
     748        if (vit != mViewCells.end()) 
     749        { 
     750                return (*vit).second; 
     751        } 
     752        else 
     753        { 
     754                ViewCell *vc; 
     755                if (isLeaf) 
     756                { 
     757                        vc = new ViewCellLeaf(); 
     758                } 
     759                else 
     760                { 
     761                        vc = new ViewCellInterior(); 
     762                } 
     763 
     764                vc->SetId(id); 
     765                mViewCells[id] = vc; 
     766                return vc; 
     767        } 
     768} 
     769 
     770 
     771void ViewCellsParseHandlers::StartViewCell(AttributeList& attributes, const bool isLeaf) 
     772{ 
     773        ViewCell *viewCell = NULL; 
    820774         
    821         if (mCurrentViewCell) // replace NULL child of parent with current node 
    822         { 
    823                 ViewCellInterior *current = dynamic_cast<ViewCellInterior *>(mCurrentViewCell); 
    824  
    825                 current->SetupChildLink(interior); 
    826         } 
    827         else 
    828         { 
    829                 mViewCellsTree->SetRoot(interior); 
    830         } 
    831  
    832         mCurrentViewCell = interior; 
    833  
    834         StartViewCellPvs(interior, attributes); 
     775        const int len = attributes.getLength(); 
     776        float mergeCost; 
     777        ObjectPvs pvs; 
     778 
     779        for (int i = 0; i < len; ++ i)  
     780        { 
     781                const string attrName(StrX(attributes.getName(i)).LocalForm()); 
     782         
     783                if (attrName == "id")  
     784                { 
     785                        const StrX attrValue(attributes.getValue(i)); 
     786                        const char *ptr = attrValue.LocalForm(); 
     787                        char *endptr = NULL; 
     788                        const int id = strtol(ptr, &endptr, 10); 
     789 
     790                        // create new view cell, otherwise use reference. 
     791                        viewCell = GetOrCreateViewCell(id, isLeaf); 
     792                         
     793                        if (mCurrentViewCell) // replace front or (if not NULL) back child 
     794                        {        
     795                                ViewCellInterior *interior =  
     796                                        dynamic_cast<ViewCellInterior *>(mCurrentViewCell); 
     797                                interior->SetupChildLink(viewCell); 
     798                        } 
     799                        else  
     800                        {       // set the new root 
     801                                mViewCellsTree->SetRoot(viewCell); 
     802                        } 
     803                         
     804                        if (!isLeaf) 
     805                        { 
     806                                mCurrentViewCell = viewCell; 
     807                        } 
     808                } 
     809                if (attrName == "pvs")  
     810                { 
     811                        StrX attrValue(attributes.getValue(i)); 
     812                        const char *ptr = attrValue.LocalForm(); 
     813 
     814                        // note: id must come before pvs!  
     815                        // otherwise view cell is undefined 
     816                        StartViewCellPvs(pvs, ptr); 
     817                } 
     818                else if (attrName == "active") 
     819                { 
     820                        StrX attrValue(attributes.getValue(i)); 
     821                        const char *ptr = attrValue.LocalForm(); 
     822                        char *endptr = NULL; 
     823                        const bool isActive = (bool)strtol(ptr, &endptr, 10); 
     824 
     825                        if (isActive) 
     826                        { 
     827                                // TODO 
     828                        } 
     829                } 
     830                else if (attrName == "mergecost") 
     831                { 
     832                        StrX attrValue(attributes.getValue(i)); 
     833                         
     834                        const char *ptr = attrValue.LocalForm(); 
     835                        char *endptr = NULL; 
     836                        mergeCost = (float)strtod(ptr, &endptr); 
     837                } 
     838        } 
     839 
     840        viewCell->SetMergeCost(mergeCost); 
     841        viewCell->SetPvs(pvs); 
    835842} 
    836843 
     
    841848        { 
    842849                cout << "hierarchy type: Bsp" << endl; 
    843  
    844850                mVspBspTree = new VspBspTree(); 
    845851 
     
    847853                mVspBspTree->mBox = mViewSpaceBox; 
    848854 
    849                 ViewCellContainer::iterator vit, vit_end = mViewCells.end(); 
    850  
    851                 // reset view cells using the current node type 
     855                ViewCellsMap::iterator vit, vit_end = mViewCells.end(); 
     856 
     857                // remove view cells and exchange them with the  
     858                // view cells specialized for the current hierarchy node type 
    852859                for (vit = mViewCells.begin(); vit != vit_end; ++ vit) 
    853860                { 
    854                         ViewCell *vc = *vit; 
    855  
     861                        ViewCell *vc = (*vit).second; 
     862                        if (!vc->IsLeaf()) // exchange only leaves 
     863                                continue; 
    856864                        BspViewCell *bspVc = new BspViewCell(); 
     865                        bspVc->SetId(vc->GetId()); 
    857866                        bspVc->SetPvs(vc->GetPvs()); 
    858                         bspVc->SetId(vc->GetId()); 
    859867 
    860868                        if (vc->IsRoot()) 
     
    868876 
    869877                        DEL_PTR(vc); 
    870                         (*vit) = bspVc; 
     878                        (*vit).second = bspVc; 
    871879                } 
    872880        } 
     
    874882        { 
    875883                cout << "hierarchy type: Vsp" << endl; 
    876  
    877884                mVspTree = new VspTree(); 
    878885 
     
    880887                mVspTree->mBoundingBox = mViewSpaceBox; 
    881888 
    882                 ViewCellContainer::iterator vit, vit_end = mViewCells.end(); 
     889                ViewCellsMap::iterator vit, vit_end = mViewCells.end(); 
    883890 
    884891                // reset view cells using the current node type 
    885892                for (vit = mViewCells.begin(); vit != vit_end; ++ vit) 
    886893                { 
    887                         ViewCell *vc = *vit; 
     894                        ViewCell *vc = (*vit).second; 
    888895 
    889896                        VspViewCell *vspVc = new VspViewCell(); 
    890897                        vspVc->SetPvs(vc->GetPvs()); 
    891898                        vspVc->SetId(vc->GetId()); 
     899 
     900                        if (!vc->IsLeaf()) // exchange only leaves 
     901                                continue; 
    892902 
    893903                        if (vc->IsRoot()) 
     
    901911                         
    902912                        DEL_PTR(vc); 
    903                         (*vit) = vspVc; 
     913                        (*vit).second = vspVc; 
    904914                } 
    905915 
     
    970980        } 
    971981 
    972         //-- find associated view cell 
     982        ///////////// 
     983        //-- find view cell associated with the id 
     984 
    973985        int viewCellId; 
    974986         
     
    9891001        } 
    9901002         
    991         if (viewCellId >= 0) // valid view cell 
     1003        if (viewCellId >= 0) // valid view cell found 
    9921004        { 
    9931005                // TODO: get view cell with specified id 
    994                 ViewCellInterior dummyVc; 
     1006                /*ViewCellInterior dummyVc; 
    9951007                dummyVc.SetId(viewCellId); 
    9961008 
    997                 //cout << "\nsearching view cell with id " << viewCellId << endl; 
    9981009                ViewCellContainer::iterator vit = 
    9991010                        lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt); 
    1000                          
     1011                */ 
     1012                ViewCellsMap::iterator vit = mViewCells.find(viewCellId); 
    10011013                if (vit == mViewCells.end()) 
    10021014                        cout << "error: view cell " << viewCellId << " not found" << endl; 
    10031015         
    1004                 VspViewCell *viewCell = dynamic_cast<VspViewCell *>(*vit); 
     1016                VspViewCell *viewCell = dynamic_cast<VspViewCell *>((*vit).second); 
    10051017                 
    10061018                if (viewCell->GetId() == viewCellId) 
    10071019                { 
    10081020                        leaf->SetViewCell(viewCell); 
    1009                         viewCell->mLeaf = leaf; 
     1021                        viewCell->mLeaves.push_back(leaf); 
    10101022                } 
    10111023                else 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h

    r1287 r1551  
    7575 
    7676 
     77  ///////////////////////// 
     78 
    7779  VspBspTree *mVspBspTree; 
    7880  HierarchyManager *mHierarchyManager; 
    79   //vHierarchy *mBvHierarchy; 
    80  
     81  
    8182  BspTree *mBspTree; 
    8283  ViewCellsTree *mViewCellsTree; 
     
    8788  KdNode *mCurrentOspNode; 
    8889  VspNode *mCurrentVspNode; 
    89   //KdNode *mCurrentKdNode; 
    90  
     90  
    9191  ViewCell *mCurrentViewCell; 
    9292     
     
    9595  ViewCell *mViewCellRoot; 
    9696 
    97   ViewCellContainer mViewCells; 
     97  typedef map<int, ViewCell *> ViewCellsMap; 
     98  ViewCellsMap mViewCells; 
     99 
    98100  ViewCellsManager *mViewCellsManager; 
    99101  ObjectContainer *mObjects; 
     
    117119  int mObjectSpaceHierarchyType; 
    118120 
     121  //////////////////////////////// 
     122 
     123 
    119124  // Handlers for X3D 
     125  ViewCell *GetOrCreateViewCell(const int id, const bool isLeaf); 
     126 
    120127  void StartBspLeaf(AttributeList& attributes); 
    121128  void StartBspInterior(AttributeList& attributes); 
     
    126133  void EndVspInterior(); 
    127134 
    128   void StartViewCellPvs(ViewCell *viewCell, AttributeList&  attributes); 
     135  void StartViewCellPvs(ObjectPvs &pvs, const char *ptr); 
     136 
    129137  void EndViewCells(); 
    130138  void EndBoundingBoxes(); 
     
    137145 
    138146  void StartBoundingBox(AttributeList& attributes); 
    139   void StartViewCellLeaf(AttributeList& attributes); 
    140   void StartViewCellInterior(AttributeList& attributes); 
     147  void StartViewCell(AttributeList& attributes, const bool isLeaf); 
    141148  void EndViewCellInterior(); 
    142149 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp

    r1528 r1551  
    128128                const Vector3 b = (*ri)->mTerminationObject ? (*ri)->GetTermination() : a + 1000 * Normalize((*ri)->GetDir()); 
    129129 
    130         //      cout << "here45 origin " << a << " termination: " << b << endl; 
    131130#if _DEBUG 
    132131                bool isnan = false; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r1545 r1551  
    875875                } 
    876876                 
    877         viewCell->mLeaf = leaf; 
     877                viewCell->mLeaves.push_back(leaf); 
    878878 
    879879                if (mUseAreaForPvs) 
     
    973973 
    974974 
     975        ////////////////// 
    975976        //-- terminate traversal and create new view cell 
    976977        if (newNode->IsLeaf()) 
     
    993994                mBspStats.sampleContributions +=(int) sampCon; 
    994995 
     996                viewCell->mLeaves.push_back(leaf); 
     997 
     998                /////////// 
    995999                //-- store additional info 
    9961000                if (mStoreRays) 
     
    10031007                        } 
    10041008                } 
    1005  
    1006                  
    1007                 viewCell->mLeaf = leaf; 
    1008  
     1009         
    10091010                if (mUseAreaForPvs) 
    10101011                        viewCell->SetArea(tData.mProbability); 
     
    29912992                                                                   BspNodeGeometry &vcGeom) const 
    29922993{ 
     2994        // if false, cannot construct geometry for interior leaf 
     2995        if (!mViewCellsTree) 
     2996                return; 
     2997 
    29932998        ViewCellContainer leaves; 
    2994          
    29952999        mViewCellsTree->CollectLeaves(vc, leaves); 
    29963000 
     
    29993003        for (it = leaves.begin(); it != it_end; ++ it) 
    30003004        { 
    3001                 BspLeaf *l = dynamic_cast<BspViewCell *>(*it)->mLeaf; 
    3002                  
    3003                 ConstructGeometry(l, vcGeom); 
     3005                BspViewCell *bspVc = dynamic_cast<BspViewCell *>(*it); 
     3006                vector<BspLeaf *>::const_iterator bit, bit_end = bspVc->mLeaves.end(); 
     3007 
     3008                for (bit = bspVc->mLeaves.begin(); bit != bit_end; ++ bit) 
     3009                { 
     3010                        BspLeaf *l = *bit; 
     3011                        ConstructGeometry(l, vcGeom); 
     3012                } 
    30043013        } 
    30053014} 
     
    38063815                if (ray->mViewCells.size() < 2) 
    38073816                        continue; 
    3808 //TODO viewcellhierarchy 
     3817 
    38093818                iit = ray->mViewCells.begin(); 
    38103819                BspViewCell *bspVc = dynamic_cast<BspViewCell *>(*(iit ++)); 
    3811                 BspLeaf *leaf = bspVc->mLeaf; 
     3820                BspLeaf *leaf = bspVc->mLeaves[0]; 
    38123821                 
    38133822                // traverse intersections  
     
    38183827                        BspLeaf *prevLeaf = leaf; 
    38193828                        bspVc = dynamic_cast<BspViewCell *>(*iit); 
    3820             leaf = bspVc->mLeaf; 
     3829            leaf = bspVc->mLeaves[0]; // exactly one leaf 
    38213830 
    38223831                        // view space not valid or same view cell 
     
    39843993{ 
    39853994        ExportNode(mRoot, stream); 
    3986  
    39873995        return true; 
    39883996} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r1545 r1551  
    614614                 
    615615        // set view cell values 
    616         viewCell->mLeaf = leaf; 
     616        viewCell->mLeaves.push_back(leaf); 
    617617 
    618618        viewCell->SetVolume(tData.mProbability); 
Note: See TracChangeset for help on using the changeset viewer.