Changeset 1586


Ignore:
Timestamp:
10/09/06 15:57:28 (18 years ago)
Author:
mattausch
Message:

resolved bug for object space distribution using triangles
fixed biasing bug for mesh::GetRandomSurfacePoint? method and
GetRandomVisibleSurfacePoint?.

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

Legend:

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

    r1291 r1586  
    141141                // don't stop until cursor is placed one element behind 
    142142                // or end of vector is reached 
    143                 StatsContainer::const_iterator equalCostIt = std::upper_bound(firstStats.begin(), firstStats.end(), *it, vlt); 
     143                StatsContainer::const_iterator equalCostIt =  
     144                        std::upper_bound(firstStats.begin(), firstStats.end(), *it, vlt); 
    144145 
    145146                int j = (int)(equalCostIt - firstStats.begin()); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp

    r1344 r1586  
    5555} 
    5656 
     57int 
     58TriangleIntersectable::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) 
     59{ 
     60        // random barycentric coordinates 
     61        const float a = RandomValue(0, 1); 
     62        const float b = RandomValue(0, 1); 
     63        const float c = 1.0 - a - b; 
     64         
     65        point = mItem.mVertices[0] + a * (mItem.mVertices[1] - mItem.mVertices[0]) + 
     66                        mItem.mVertices[0] + b * (mItem.mVertices[2] - mItem.mVertices[0]) + 
     67                        mItem.mVertices[1] + c * (mItem.mVertices[2] - mItem.mVertices[1]); 
     68         
     69        normal = mItem.GetNormal(); 
     70 
     71        return 0; 
     72} 
     73 
    5774  
    5875} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h

    r1581 r1586  
    185185                return Intersectable::TRIANGLE_INTERSECTABLE; 
    186186        } 
     187 
     188        int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 
    187189}; 
    188190 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp

    r1449 r1586  
    422422Mesh::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) 
    423423{ 
    424   const int faceIndex = (int)RandomValue(0, (Real)((int)mFaces.size()-1)); 
    425    
     424  //const int faceIndex = (int)RandomValue(0, (Real)((int)mFaces.size()-1)); 
     425        const int faceIndex = (int)RandomValue(0, (Real)mFaces.size() - 0.5f); 
     426 
    426427  // assume the face is convex and generate a convex combination 
    427428  // 
     
    450451{ 
    451452  Plane3 plane; 
    452   int faceIndex = (int)RandomValue(0, (Real)((int)mFaces.size()-1)); 
     453  const int faceIndex = (int)RandomValue(0, (Real)mFaces.size() - 0.5f); 
    453454        int tries; 
    454455  for (tries = 0; tries < maxTries; tries++) { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp

    r1486 r1586  
    2323        We eliminate already accounted kd nodes and objects using mailboxing.  
    2424*/ 
    25 static int CountNewObjectsInKdNode(KdIntersectable *kdobj) 
     25static int EvalKdNodeContribution(KdIntersectable *kdobj) 
    2626{ 
    2727        int pvs = 0; 
     
    7676 
    7777 
    78 /** the pvs is the number of different objects in the node leaves 
     78/** Returns the the number of different objects in the leaves of the node. 
    7979        We eliminate already accounted kd nodes and objects using mailboxing.  
    8080*/ 
    81 static int CountNewObjectsInBvhNode(BvhIntersectable *bvhobj) 
     81static int EvalBvhNodeContribution(BvhIntersectable *bvhobj) 
    8282{ 
    8383        BvhNode *node= bvhobj->GetItem(); 
     
    113113                        { 
    114114                                BvhLeaf *leaf = dynamic_cast<BvhLeaf *>(node); 
    115                         
     115 
    116116                                // add #objects exclusivly in this node 
    117117                                pvs += (int)leaf->mObjects.size(); 
     
    126126                } 
    127127        } 
     128 
    128129        return pvs; 
    129130} 
     
    151152                                        // found kd node 
    152153                                        KdIntersectable *kdObj = dynamic_cast<KdIntersectable *>(obj); 
    153                                         pvs += CountNewObjectsInKdNode(kdObj);   
     154                                        pvs += EvalKdNodeContribution(kdObj);    
    154155                                        break; 
    155156                                } 
     
    157158                                { 
    158159                                        BvhIntersectable *bvhObj = dynamic_cast<BvhIntersectable *>(obj); 
    159                                         pvs += CountNewObjectsInBvhNode(bvhObj); 
     160                                        pvs += EvalBvhNodeContribution(bvhObj); 
    160161                                        break; 
    161162                                } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h

    r1528 r1586  
    505505{ 
    506506public: 
    507         /** Counts object int the pvs. Different to GetSize(), not 
     507        /** Counts object int the pvs. Different to method "GetSize", not 
    508508                only the raw container size is returned, 
    509509                but the individual contributions of the entries are summed up. 
     
    512512}; 
    513513 
     514 
     515//////////// 
    514516//-- typedefs 
    515517 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.cpp

    r1421 r1586  
    4747        ////////////// 
    4848        // specialised triangle ray casting version 
    49  
    50         /////////// 
    51         //-- calc ray-plane intersection 
     49        // using ray-plane intersection 
    5250         
    5351        // get triangle edge vectors and plane normal 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1585 r1586  
    5353} 
    5454 
    55 /// Counts differences between pvss. 
    56 inline int CountDiffPvs(ViewCell *vc) 
     55/** Counts contribution of the view cell to the pvs. 
     56*/ 
     57inline int CountPvsContribution(ViewCell *vc) 
    5758{ 
    5859        int count = 0; 
     
    257258{ 
    258259        const bool result = mPvs.AddSample(sample, pdf, contribution); 
    259         mPvsSizeValid = false; // have to recompute pvs size 
     260        // have to recompute pvs size 
     261        mPvsSizeValid = false; 
    260262 
    261263        return result; 
     
    10381040                // set scalars 
    10391041                mViewCellsManager->UpdateScalarPvsSize(left,  
    1040                         left->GetPvs().CountObjectsInPvs(),  
    1041                         left->GetPvs().GetSize()); 
     1042                                left->GetPvs().CountObjectsInPvs(),  
     1043                                left->GetPvs().GetSize()); 
    10421044                         
    10431045                // remove pvs, we don't store interior pvss 
     
    13841386void ViewCellsTree::EvalMergeCost(MergeCandidate &mc) const 
    13851387{ 
     1388        /////////////////// 
    13861389        //-- compute pvs difference 
     1390 
    13871391        int newPvs; 
     1392         
    13881393        if (1) // not valid if not using const cost per object!! 
     1394        { 
    13891395                newPvs = ComputeMergedPvsSize(mc.mLeftViewCell->GetPvs(), mc.mRightViewCell->GetPvs()); 
     1396        } 
    13901397        else 
     1398        { 
    13911399                newPvs = (int)ComputeMergedPvsCost(mc.mLeftViewCell->GetPvs(), mc.mRightViewCell->GetPvs()); 
     1400        } 
    13921401 
    13931402        const float newPenalty = EvalPvsPenalty(newPvs,  
     
    13991408 
    14001409        //-- compute ratio of old cost 
    1401         //  (i.e., added size of left and right view cell times pvs size) 
    1402         //  to new rendering cost (i.e, size of merged view cell times pvs size) 
     1410        //-- (i.e., added size of left and right view cell times pvs size) 
     1411        //-- to new rendering cost (i.e, size of merged view cell times pvs size) 
    14031412        const float oldCost = GetRenderCost(vc1) + GetRenderCost(vc2); 
    14041413 
     
    14191428        }        
    14201429         
    1421  
     1430        /////////////////////////// 
    14221431        //-- merge cost also takes deviation into account 
     1432 
    14231433        float newDev, oldDev; 
    14241434 
     
    17881798        ObjectPvs newPvs; 
    17891799 
    1790         // sum different intersectables 
     1800        // sum up uniquely found intersectables 
    17911801        for (it = leaves.begin(); it != it_end; ++ it) 
    17921802        { 
     
    18811891         
    18821892                // matt: bug! must evaluate kd pvss also 
    1883                 pvsSize += CountDiffPvs(root); 
     1893                pvsSize += CountPvsContribution(root); 
    18841894        } 
    18851895 
     
    18921902                tstack.pop(); 
    18931903                // matt: bug! must evaluate kd pvss also 
    1894                 pvsSize += CountDiffPvs(vc); 
     1904                pvsSize += CountPvsContribution(vc); 
    18951905 
    18961906                if (!vc->IsLeaf()) 
     
    19151925        int pvsSize = 0; 
    19161926 
     1927        ///////////////// 
    19171928        //-- compressed pvs 
    19181929 
     
    19311942                root = root->GetParent(); 
    19321943                // count the pvs entries different from the already found ones   
    1933                 pvsSize += CountDiffPvs(root); 
     1944                pvsSize += CountPvsContribution(root); 
    19341945        } 
    19351946 
     
    19431954         
    19441955                // count the pvs entries different from the already found ones   
    1945                 pvsSize += CountDiffPvs(vc); 
     1956                pvsSize += CountPvsContribution(vc); 
    19461957 
    19471958                if (!vc->IsLeaf()) 
     
    20292040                sizeof(PvsData) + sizeof(Intersectable *); 
    20302041 
    2031         return (float)GetStoredPvsEntriesNum(vc) * entrySize; 
    2032 } 
    2033  
    2034  
    2035 int ViewCellsTree::GetStoredPvsEntriesNum(ViewCell *root) const 
     2042        return (float)CountStoredPvsEntries(vc) * entrySize; 
     2043} 
     2044 
     2045//#if HAS_TO_BE_REDONE 
     2046int ViewCellsTree::CountStoredPvsEntries(ViewCell *root) const 
    20362047{ 
    20372048        int pvsSize = root->GetPvs().GetSize(); 
     
    20462057                for (it = interior->mChildren.begin(); it != it_end; ++ it) 
    20472058                { 
    2048                         pvsSize += GetStoredPvsEntriesNum(*it); 
     2059                        pvsSize += CountStoredPvsEntries(*it); 
    20492060                } 
    20502061        } 
     
    20522063        return pvsSize;          
    20532064} 
    2054  
     2065//#endif 
    20552066 
    20562067int ViewCellsTree::ViewCellsStorage() const 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h

    r1551 r1586  
    275275        */ 
    276276        bool mPvsSizeValid; 
    277  
    278277}; 
    279278 
     
    432431        void GetPvs(ViewCell *vc, ObjectPvs &pvs) const; 
    433432 
    434         /** Returns pvs size (i.e. the number of stored objects 
     433        /** Returns pvs size (i.e. the number of stored objects) 
    435434        */ 
    436435        int GetPvsSize(ViewCell *vc) const; 
    437436 
    438437        /** Returns number of entries associated with this view cell.  
    439                 This returns the same value as the GetPvsSize function for object pvs, 
    440                 but most likely different values for kd node based pvs. 
     438 
     439                This returns the same value as the "GetPvsSize" function for object pvs 
     440                but most likely different values if we use object space grouping. 
     441                E.g., using bounding volumes. 
    441442        */ 
    442443        int GetPvsEntries(ViewCell *vc) const; 
    443444 
    444         /** Returns the actual number of stored entries in the view cells sub tree. 
    445         */ 
    446         int GetStoredPvsEntriesNum(ViewCell *root) const; 
     445        /** Returns the number of physically stored entries in the view cells sub tree. 
     446                This can vary based on the current storage method 
     447        */ 
     448        int CountStoredPvsEntries(ViewCell *root) const; 
    447449 
    448450        /** Returns memory cost of this view cell. 
     
    458460        enum {PVS_IN_INTERIORS, COMPRESSED, PVS_IN_LEAVES}; 
    459461 
    460          
    461462        /** If view cells in this tree have compressed pvs. 
    462463        */ 
     
    503504        void SetViewCellsManager(ViewCellsManager *vcm); 
    504505 
     506 
    505507protected: 
    506508 
     509        /** Reads the environment and sets member variables. 
     510        */ 
    507511        void ReadEnvironment(); 
    508512 
     
    598602        void ExportPvs(ViewCell *viewCell, OUT_STREAM &stream); 
    599603 
     604        /** Counts the logical number of entries in the pvs this view cell. 
     605                The pvs is assumed to be stored using lossless compression. 
     606        */ 
    600607        int GetEntriesInPvsForCompressedStorage(ViewCell *vc) const; 
     608 
     609        /** Computes pvs size of this view cell. 
     610                The pvs is assumed to be stored using lossless compression. 
     611        */ 
    601612        int GetPvsSizeForCompressedStorage(ViewCell *vc) const; 
     613         
     614        /** Computes pvs size of this view cell. 
     615                The pvs is assumed to be stored in the leaves. 
     616        */ 
    602617        int GetPvsSizeForLeafStorage(ViewCell *vc) const; 
     618 
     619        /** Counts the logical number of entries in the pvs this view cell. 
     620                The pvs is assumed to be stored using the leaves. 
     621        */ 
    603622        int GetEntriesInPvsForLeafStorage(ViewCell *vc) const; 
    604623 
     624        /** Update stats for the log. 
     625        */ 
    605626        void UpdateStats( 
    606627                ofstream &stats, 
     
    618639                const float volume); 
    619640 
     641 
     642        ////////////////////////////////////// 
     643 
    620644        /// if the view cell tree hold compressed pvs 
    621645        int mViewCellsStorage; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1584 r1586  
    911911                cout << "compute new statistics ... " << endl; 
    912912         
     913                ///////////////7 
    913914                //-- propagate pvs or pvs size information 
     915 
    914916                ObjectPvs pvs; 
    915917                UpdatePvsForEvaluation(mViewCellsTree->GetRoot(), pvs); 
    916918 
     919                /////////// 
    917920                //-- output stats 
    918921                sprintf(str, "-%09d-eval.log", castSamples); 
     
    11281131                                                                           ) const 
    11291132{ 
    1130   if (!vc->IsLeaf() && vc->GetMergeCost() < 0.0f) { 
    1131         ViewCellInterior *vci = (ViewCellInterior *) vc; 
    1132         ViewCellContainer::const_iterator it, it_end = vci->mChildren.end(); 
    1133          
    1134         for (it = vci->mChildren.begin(); it != it_end; ++ it) 
    1135           DeleteLocalMergeTree(*it); 
    1136         vci->mChildren.clear(); 
    1137         delete vci; 
     1133        if (!vc->IsLeaf() && vc->GetMergeCost() < 0.0f)  
     1134        {        
     1135                ViewCellInterior *vci = (ViewCellInterior *) vc; 
     1136                ViewCellContainer::const_iterator it, it_end = vci->mChildren.end(); 
     1137 
     1138        for (it = vci->mChildren.begin(); it != it_end; ++ it) 
     1139                        DeleteLocalMergeTree(*it); 
     1140                 
     1141                vci->mChildren.clear(); 
     1142                 
     1143                delete vci; 
    11381144  } 
    11391145} 
     
    14891495        //-- extrude new vertices for top of prism 
    14901496 
    1491         Vector3 triNorm = baseTri.GetNormal(); 
     1497        const Vector3 triNorm = baseTri.GetNormal(); 
    14921498        Triangle3 topTri; 
    14931499 
     
    22362242        if (viewSpaceFilterSize >= 0.0f) { 
    22372243 
    2238   bool usePrVS = false; 
     2244  const bool usePrVS = false; 
    22392245 
    22402246  if (!usePrVS) { 
     
    23512357 
    23522358        // $$ warning collect objects takes only unmailed ones! 
    2353         kdTree->CollectObjects(box, 
    2354                                                    objects); 
     2359        kdTree->CollectObjects(box, objects); 
    23552360        //      cout<<"collected objects="<<objects.size()<<endl; 
    23562361        ObjectContainer::const_iterator noi = objects.begin(); 
    2357         for (; noi != objects.end(); ++noi) { 
    2358           Intersectable *o = *noi; 
    2359           // $$ JB warning: pdfs are not correct at this point! 
    2360           nPvs.AddSample(o, Limits::Small); 
    2361           nPvsSize++; 
     2362        for (; noi != objects.end(); ++ noi)  
     2363        { 
     2364                Intersectable *o = *noi; 
     2365                // $$ JB warning: pdfs are not correct at this point!      
     2366                nPvs.AddSample(o, Limits::Small); 
     2367                nPvsSize ++; 
    23622368        } 
    23632369  } 
     
    24552461        } 
    24562462         
    2457         //-- interior node => propagate pvs up 
     2463        //////////////// 
     2464        //-- interior node => propagate pvs up the tree 
     2465 
    24582466        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(root); 
    24592467        interior->GetPvs().Clear(); 
     
    24672475                ObjectPvs objPvs; 
    24682476                 
     2477                ////////////////// 
    24692478                //-- recursivly compute child pvss 
     2479 
    24702480                UpdatePvsForEvaluation(*vit, objPvs); 
    24712481 
     
    24782488 
    24792489        //-- faster way of computing pvs: 
    2480         //   construct merged pvs by adding  
    2481         //   and only those of the next pvs which were not mailed. 
    2482         //   note: sumpdf is not correct!! 
     2490        //-- construct merged pvs by adding 
     2491        //-- and only those of the next pvs which were not mailed. 
     2492        //-- note: sumpdf is not correct!! 
     2493 
    24832494        vector<ObjectPvs>::iterator oit = pvsList.begin(); 
    24842495 
     
    25082519        UpdateScalarPvsSize(interior, pvs.CountObjectsInPvs(), pvs.GetSize()); 
    25092520         
    2510  
    2511 #else // really merge cells: slow put sumPdf is correct 
     2521#else  
     2522        // really merge cells: slow put sumPdf is correct 
    25122523        viewCellInterior->GetPvs().Merge(backVc->GetPvs()); 
    25132524        viewCellInterior->GetPvs().Merge(frontVc->GetPvs()); 
     
    25612572 
    25622573        const float prop = (float)limit / ((float)rays.size() + Limits::Small); 
     2574 
    25632575        for (it = rays.begin(); it != it_end; ++ it) 
    25642576        { 
     
    40464058        //////////// 
    40474059        //-- compression 
    4048  
     4060//#if HAS_TO_BE_REDONE 
    40494061        if (ViewCellsTreeConstructed() && mCompressViewCells) 
    40504062        { 
    4051                 int pvsEntries = mViewCellsTree->GetStoredPvsEntriesNum(mViewCellsTree->GetRoot()); 
     4063                int pvsEntries = mViewCellsTree->CountStoredPvsEntries(mViewCellsTree->GetRoot()); 
    40524064                Debug << "number of entries before compress: " << pvsEntries << endl; 
    40534065 
    40544066                mViewCellsTree->SetViewCellsStorage(ViewCellsTree::COMPRESSED); 
    40554067 
    4056                 pvsEntries = mViewCellsTree->GetStoredPvsEntriesNum(mViewCellsTree->GetRoot()); 
     4068                pvsEntries = mViewCellsTree->CountStoredPvsEntries(mViewCellsTree->GetRoot()); 
    40574069                Debug << "number of entries after compress: " << pvsEntries << endl; 
    40584070        } 
    4059  
     4071//#endif 
    40604072 
    40614073        // collapse sibling leaves that share the same view cell 
     
    49194931         
    49204932 
    4921         /////////////// 
     4933        /////////// 
    49224934        //-- compression 
    49234935 
     4936//#if HAS_TO_BE_REDONE 
    49244937        if (ViewCellsTreeConstructed() && mCompressViewCells) 
    49254938        { 
    4926                 int pvsEntries = mViewCellsTree->GetStoredPvsEntriesNum(mViewCellsTree->GetRoot()); 
     4939                int pvsEntries = mViewCellsTree->CountStoredPvsEntries(mViewCellsTree->GetRoot()); 
    49274940                Debug << "number of entries before compress: " << pvsEntries << endl; 
    49284941 
    49294942                mViewCellsTree->SetViewCellsStorage(ViewCellsTree::COMPRESSED); 
    49304943 
    4931                 pvsEntries = mViewCellsTree->GetStoredPvsEntriesNum(mViewCellsTree->GetRoot()); 
     4944                pvsEntries = mViewCellsTree->CountStoredPvsEntries(mViewCellsTree->GetRoot()); 
    49324945                Debug << "number of entries after compress: " << pvsEntries << endl; 
    49334946        } 
     4947//#endif 
    49344948 
    49354949        ///////////// 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp

    r1581 r1586  
    983983 
    984984        int viewCellId; 
    985          
    986         int len = attributes.getLength(); 
     985        const int len = attributes.getLength(); 
    987986           
    988987        for (int i = 0; i < len; ++ i)  
     
    10381037{ 
    10391038        AxisAlignedPlane plane; 
    1040         int len = attributes.getLength(); 
     1039        const int len = attributes.getLength(); 
    10411040 
    10421041        for (int i = 0; i < len; ++ i)  
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r1580 r1586  
    930930                VspBspTraversalData tBackData; 
    931931 
     932                //////////////////// 
    932933                //-- continue subdivision 
    933934                 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r1580 r1586  
    23392339                        // compute intersection with all objects in this leaf 
    23402340                        VspLeaf *leaf = dynamic_cast<VspLeaf *>(node); 
    2341                         ViewCell *vc = leaf->GetViewCell(); 
     2341                        ViewCell *viewCell; 
     2342                        if (0) 
     2343                                viewCell = mViewCellsTree->GetActiveViewCell(leaf->GetViewCell()); 
     2344                        else 
     2345                                viewCell = leaf->GetViewCell(); 
    23422346 
    23432347                        // don't have to mail if each view cell belongs to exactly one leaf 
    2344                         if (!useMailboxing || !vc->Mailed()) 
     2348                        if (!useMailboxing || !viewCell->Mailed()) 
    23452349                        { 
    23462350                                if (useMailboxing) 
    2347                                         vc->Mail(); 
    2348  
    2349                                 viewcells.push_back(vc); 
     2351                                        viewCell->Mail(); 
     2352 
     2353                                viewcells.push_back(viewCell); 
    23502354                                ++ hits; 
    23512355                        } 
    2352 #if 0 
    2353                         leaf->mRays.push_back(RayInfo(new VssRay(origin, termination, NULL, NULL, 0))); 
    2354 #endif 
     2356 
    23552357                        // get the next node from the stack 
    23562358                        if (tStack.empty()) 
     
    23642366                        extp = s.mExitPoint; 
    23652367                        maxt = s.mMaxT; 
     2368 
    23662369                        tStack.pop(); 
    23672370                } 
     
    25112514   
    25122515        if (active) 
     2516        { 
    25132517                return mViewCellsTree->GetActiveViewCell(viewcell); 
     2518        } 
    25142519        else 
     2520        { 
    25152521                return viewcell; 
     2522        } 
    25162523} 
    25172524 
Note: See TracChangeset for help on using the changeset viewer.