Changeset 1603


Ignore:
Timestamp:
10/10/06 16:42:52 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
5 edited

Legend:

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

    r1586 r1603  
    621621                        const int numMergedViewCells = UpdateActiveViewCells(activeViewCells); 
    622622                 
    623                          
    624                         //-- resets / refines the view cells 
     623                        ///////////////// 
     624                        //-- reset / refine the view cells 
    625625                        //-- priorities are recomputed 
    626626                        //-- the candidates are put back into merge queue 
     627 
    627628                        if (mRefineViewCells) 
    628629                                RefineViewCells(rays, objects); 
     
    687688 
    688689                        // check if "siblings (back and front node of the same parent) 
    689                         if (0 && mViewCellsManager->EqualToSpatialNode(mergedVc)) 
     690                        if (0) 
    690691                                ++ mergeStats.siblings; 
    691692                        // set the coŽst for rendering a view cell 
     
    15311532 
    15321533        Debug << "******** Export stats **********" << endl; 
    1533         /*Debug << "vsb volume: " << vol << endl; 
    1534         Debug << "root volume: " << mRoot->GetVolume() << endl; 
    1535         Debug << "root pvs: " << rootPvs << endl; 
    1536         */ 
    1537  
     1534         
    15381535        float totalRenderCost, avgRenderCost, expectedCost; 
    15391536 
     
    15471544        stats.open(mergeStats.c_str()); 
    15481545 
     1546        ///////////// 
    15491547        //-- first view cell 
     1548 
    15501549        UpdateStats(stats, 
    15511550                                0, numViewCells, 0, totalRenderCost,  
     
    15951594                        } 
    15961595 
    1597  
     1596                        // update stats for this view cell 
    15981597                        const float costDecr = (parentCost - childCost) / vol; 
    15991598 
     
    21712170/** Get costs resulting from each merge step.  
    21722171*/ 
    2173 void 
    2174 ViewCellsTree::GetCostFunction(vector<float> &costFunction) 
    2175 { 
    2176   TraversalQueue tqueue; 
    2177   tqueue.push(mRoot); 
    2178    
    2179   while (!tqueue.empty())  
    2180         { 
    2181           ViewCell *vc = tqueue.top(); 
    2182           tqueue.pop(); 
    2183           // save the view cells if it is a leaf or if enough view cells have already been traversed 
    2184           // because of the priority queue, this will be the optimal set of v 
    2185           if (!vc->IsLeaf()) {   
    2186                 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
    2187                 costFunction.push_back(interior->GetMergeCost()); 
     2172void ViewCellsTree::GetCostFunction(vector<float> &costFunction) 
     2173{ 
     2174        TraversalQueue tqueue; 
     2175        tqueue.push(mRoot); 
     2176 
     2177        int numViewCells = 1; 
     2178 
     2179        const float vol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 
     2180        const int rootPvs = GetPvsSize(mRoot); 
     2181         
     2182        float totalRenderCost; 
     2183 
     2184        int totalPvs = rootPvs; 
     2185        totalRenderCost = (float)rootPvs; 
     2186 
     2187        costFunction.push_back(totalRenderCost); 
     2188 
     2189        //-- go through tree in the order of render cost decrease 
     2190        //-- which is the same order as the view cells were merged 
     2191        //-- or the reverse order of subdivision for subdivision-only  
     2192        //-- view cell hierarchies. 
     2193 
     2194        while (!tqueue.empty()) 
     2195        { 
     2196                ViewCell *vc = tqueue.top(); 
     2197                tqueue.pop(); 
     2198 
     2199                if (!vc->IsLeaf())  
     2200                {        
     2201                        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
     2202 
     2203                        const int parentPvs = GetPvsSize(interior); 
     2204                        const float parentCost = (float)parentPvs * interior->GetVolume(); 
     2205 
     2206                        -- numViewCells; 
     2207 
     2208                        float childCost = 0; 
     2209                        int childPvs = 0; 
     2210                         
     2211                        ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     2212 
     2213                        for (it = interior->mChildren.begin(); it != it_end; ++ it) 
     2214                        { 
     2215                                ViewCell *vc = *it; 
     2216 
     2217                                const int pvsSize = GetPvsSize(vc); 
     2218                                 
     2219                                childCost += (float) pvsSize * vc->GetVolume(); 
     2220                                childPvs += pvsSize; 
     2221                                 
     2222                                tqueue.push(vc); 
     2223                                ++ numViewCells; 
     2224                        } 
     2225 
     2226                        // update stats for this view cell 
     2227                        const float costDecr = (parentCost - childCost) / vol; 
     2228                        totalRenderCost -= costDecr; 
     2229                        const float expectedCost = totalRenderCost ;/// (float)numViewCells; 
    21882230                 
    2189                 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
    2190                  
    2191                 for (it = interior->mChildren.begin(); it != it_end; ++ it) { 
    2192                   tqueue.push(*it); 
    2193                 } 
    2194                  
    2195           } 
    2196         } 
    2197 } 
     2231                        costFunction.push_back(expectedCost); 
     2232                } 
     2233        } 
     2234} 
     2235 
     2236 
     2237/** Get storage costs resulting from each merge step.  
     2238*/ 
     2239void ViewCellsTree::GetStorageFunction(vector<int> &storageFunction) 
     2240{ 
     2241        TraversalQueue tqueue; 
     2242        tqueue.push(mRoot); 
     2243 
     2244        int numViewCells = 1; 
     2245 
     2246        const float vol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 
     2247        const int rootEntries = GetPvsEntries(mRoot); 
     2248 
     2249        int entriesInPvs = rootEntries; 
     2250    const int entryStorage = 1;//sizeof(PvsData) + sizeof(int); // one entry into the pvs 
     2251 
     2252        storageFunction.push_back(rootEntries); 
     2253 
     2254        //////////// 
     2255        //-- go through tree in the order of render cost decrease 
     2256        //-- which is the same order as the view cells were merged 
     2257        //-- or the reverse order of subdivision for subdivision-only  
     2258        //-- view cell hierarchies. 
     2259 
     2260        while (!tqueue.empty()) 
     2261        { 
     2262                ViewCell *vc = tqueue.top(); 
     2263                tqueue.pop(); 
     2264 
     2265                if (!vc->IsLeaf())  
     2266                {        
     2267                        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
     2268 
     2269                        const int parentPvs = GetPvsSize(interior); 
     2270                        const int parentPvsEntries = GetPvsEntries(interior); 
     2271            const float parentCost = (float)parentPvs * interior->GetVolume(); 
     2272 
     2273                        float childCost = 0; 
     2274                        int childPvs = 0; 
     2275                        int childPvsEntries = 0; 
     2276 
     2277                        -- numViewCells; 
     2278 
     2279                        ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     2280 
     2281                        for (it = interior->mChildren.begin(); it != it_end; ++ it) 
     2282                        { 
     2283                                ViewCell *vc = *it; 
     2284 
     2285                                //const int pvsSize = GetPvsSize(vc); 
     2286                                const int pvsEntries = GetPvsEntries(vc); 
     2287 
     2288                                //childPvs += pvsSize; 
     2289                                childPvsEntries += pvsEntries; 
     2290 
     2291                                tqueue.push(vc); 
     2292                                ++ numViewCells; 
     2293                        } 
     2294 
     2295                        // update stats for this view cell 
     2296                        const float costDecr = (parentCost - childCost) / vol; 
     2297 
     2298                        //totalPvs += childPvs - parentPvs; 
     2299                        entriesInPvs += childPvsEntries - parentPvsEntries; 
     2300 
     2301                        const int storageCost = entriesInPvs * entryStorage; 
     2302                        storageFunction.push_back(storageCost); 
     2303                } 
     2304        } 
     2305} 
     2306 
    21982307 
    21992308 
     
    23582467} 
    23592468 
     2469 
     2470 
    23602471/**************************************************************************/ 
    23612472/*                     MergeCandidate implementation                      */ 
     
    24382549 
    24392550 
    2440  
    24412551/************************************************************************/ 
    24422552/*                    MergeStatistics implementation                    */ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h

    r1586 r1603  
    416416        */ 
    417417        void GetCostFunction(vector<float> &costFunction); 
    418    
     418         
     419        /** Returns storage cost resulting from each merge step. 
     420        */ 
     421        void GetStorageFunction(vector<int> &storageCost); 
     422 
    419423        /** Returns optimal set of view cells for a given number of view cells. 
    420424        */ 
     
    504508        void SetViewCellsManager(ViewCellsManager *vcm); 
    505509 
     510        void Update(); 
    506511 
    507512protected: 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1594 r1603  
    258258 
    259259 
    260 bool ViewCellsManager::EqualToSpatialNode(ViewCell *viewCell) const  
    261 {  
    262         return false; 
    263 } 
    264  
    265  
    266260int ViewCellsManager::CastPassSamples(const int samplesPerPass,  
    267261                                                                          const int sampleType,  
     
    851845 
    852846        // should directional sampling be used? 
    853         bool dirSamples = (mEvaluationSamplingType == SamplingStrategy::DIRECTION_BASED_DISTRIBUTION); 
     847        bool dirSamples =  
     848                (mEvaluationSamplingType == SamplingStrategy::DIRECTION_BASED_DISTRIBUTION); 
    854849 
    855850        cout << "reseting pvs ... "; 
     
    914909                cout << "compute new statistics ... " << endl; 
    915910         
    916                 ///////////////7 
     911                /////////////// 
    917912                //-- propagate pvs or pvs size information 
    918913 
     
    39483943 
    39493944        mColorCode = savedColorCode; 
    3950  
    3951 } 
    3952  
    3953  
    3954 bool VspBspViewCellsManager::EqualToSpatialNode(ViewCell *viewCell) const 
    3955 { 
    3956         return GetSpatialNode(viewCell) != NULL; 
    3957 } 
    3958  
    3959  
    3960 BspNode *VspBspViewCellsManager::GetSpatialNode(ViewCell *viewCell) const 
    3961 { 
    3962         if (!viewCell->IsLeaf()) 
    3963         { 
    3964                 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(viewCell); 
    3965                 return bspVc->mLeaves[0]; 
    3966         } 
    3967         else 
    3968         { 
    3969                 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(viewCell); 
    3970  
    3971                 // cannot be node of binary tree 
    3972                 if (interior->mChildren.size() != 2) 
    3973                         return NULL; 
    3974  
    3975                 ViewCell *left = interior->mChildren[0]; 
    3976                 ViewCell *right = interior->mChildren[1]; 
    3977  
    3978                 BspNode *leftNode = GetSpatialNode(left); 
    3979                 BspNode *rightNode = GetSpatialNode(right); 
    3980  
    3981                 if (leftNode && rightNode && leftNode->IsSibling(rightNode)) 
    3982                 { 
    3983                         return leftNode->GetParent();  
    3984                 } 
    3985         } 
    3986  
    3987         return NULL; 
    39883945} 
    39893946 
     
    57135670        cout << "finished" << endl; 
    57145671 
     5672        vector<int> storageFunc; 
     5673        mViewCellsTree->GetStorageFunction(storageFunc); 
     5674 
     5675        vector<float> costFunc; 
     5676        mViewCellsTree->GetCostFunction(costFunc); 
     5677 
     5678        ofstream outstr("out.txt"); 
     5679 
     5680        for (int i = 0; i < storageFunc.size(); ++ i) 
     5681                outstr << i << ": " << storageFunc[i] << endl; 
     5682outstr << endl; 
     5683        for (int i = 0; i < costFunc.size(); ++ i) 
     5684                outstr << i << ": " << costFunc[i] << endl; 
    57155685        if (0) 
    57165686        for (int i = 0; i <50; ++ i) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1582 r1603  
    479479        ////////////////////////////////////////////////////////////////// 
    480480 
    481  
    482         /** Returns true if the view cell is equivalent to a  
    483                 node of the spatial hierarchy. This function can be used for merged 
    484                 view cell. 
    485                 e.g. to see if the spatial tree can be reduced on this location 
    486                 note: not implemented 
    487         */ 
    488         virtual bool EqualToSpatialNode(ViewCell *viewCell) const; 
    489  
    490481        /** If true, the kd nodes are stored instead of the object pvs. 
    491482        */ 
     
    966957        void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates); 
    967958 
    968         /** Returns true if this view cell is equivavalent to a spatial node. 
    969         */ 
    970         bool EqualToSpatialNode(ViewCell *viewCell) const; 
    971  
    972  
    973959        void ExportSingleViewCells( 
    974960                const ObjectContainer &objects, 
     
    986972        int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const; 
    987973         
    988         /** Returns node of the spatial hierarchy corresponding to the view cell 
    989                 if such a node exists. 
    990         */ 
    991         BspNode *GetSpatialNode(ViewCell *viewCell) const; 
    992  
    993974        /** Merges view cells according to some criteria 
    994975        */ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r1586 r1603  
    1717#include "ViewCellsManager.h" 
    1818#include "Beam.h" 
     19#include "IntersectableWrapper.h" 
    1920 
    2021 
     
    243244                                                                  MeshInstance *parent) 
    244245{ 
     246        if (!mesh) 
     247                return 0; 
     248 
    245249        FaceContainer::const_iterator fi; 
    246250 
     
    260264                } 
    261265        } 
     266 
    262267        return (int)mesh->mFaces.size(); 
    263268} 
     
    268273                                                                 int maxObjects) 
    269274{ 
    270         int limit = (maxObjects > 0) ? 
     275        const int limit = (maxObjects > 0) ? 
    271276                Min((int)viewCells.size(), maxObjects) : (int)viewCells.size(); 
    272277 
     
    277282                Mesh *mesh = viewCells[i]->GetMesh(); 
    278283                if (mesh)  
    279                 {       // // copy the mesh into polygons and add to BSP tree aabb 
     284                {       // copy the mesh into polygons and add to BSP tree aabb 
    280285                        mBoundingBox.Include(viewCells[i]->GetBox());  
    281286                        polysSize += AddMeshToPolygons(mesh, 
     
    293298                                                                 int maxObjects) 
    294299{ 
    295         int limit = (maxObjects > 0) ? 
     300        const int limit = (maxObjects > 0) ? 
    296301                Min((int)objects.size(), maxObjects) : (int)objects.size(); 
    297302 
     
    305310                case Intersectable::MESH_INSTANCE: 
    306311                        mesh = dynamic_cast<MeshInstance *>(object)->GetMesh(); 
     312                        AddMeshToPolygons(mesh, polys, NULL); 
    307313                        break; 
    308314                case Intersectable::VIEW_CELL: 
    309315                        mesh = dynamic_cast<ViewCell *>(object)->GetMesh(); 
     316                        AddMeshToPolygons(mesh, polys, NULL); 
    310317                        break; 
    311318                case Intersectable::TRANSFORMED_MESH_INSTANCE: 
    312319                        { 
    313                                 TransformedMeshInstance *mi = dynamic_cast<TransformedMeshInstance *>(object); 
    314  
    315                                 if (!mi->GetMesh())      
    316                                         break; 
    317                                 mesh = new Mesh(); 
    318                                 mi->GetTransformedMesh(*mesh); 
    319                                  
     320                                TransformedMeshInstance *mi =  
     321                                        dynamic_cast<TransformedMeshInstance *>(object); 
     322 
     323                                Mesh mesh; 
     324                                mi->GetTransformedMesh(mesh); 
     325                                AddMeshToPolygons(&mesh, polys, NULL); 
    320326                break; 
    321327                        } 
     328                case Intersectable::TRIANGLE_INTERSECTABLE: 
     329                        { 
     330                                TriangleIntersectable *intersect =  
     331                                        dynamic_cast<TriangleIntersectable *>(object); 
     332 
     333                                Polygon3 *poly = new Polygon3(intersect->GetItem()); 
     334 
     335                                if (poly->Valid(mEpsilon))       
     336                                        polys.push_back(poly); 
     337                                else 
     338                                        delete poly; 
     339                        } 
    322340                default: 
    323                         Debug << "intersectable type not supported" << endl; 
     341                                Debug << "intersectable type not supported" << endl; 
    324342                        break; 
    325343                } 
    326344 
    327         if (mesh) // copy the mesh data to polygons 
    328                 { 
    329                         mBoundingBox.Include(object->GetBox()); // add to BSP tree aabb 
    330                         AddMeshToPolygons(mesh, polys, NULL); 
    331  
    332                         // cleanup 
    333                         if (object->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE) 
    334                                 DEL_PTR(mesh); 
    335                 } 
     345                mBoundingBox.Include(object->GetBox()); // add to BSP tree aabb 
    336346        } 
    337347 
     
    413423                                                } 
    414424                                                break; 
     425 
    415426                                        case Intersectable::MESH_INSTANCE: 
    416427                                                { 
     
    419430                                                } 
    420431                                                break; 
     432 
    421433                                        case Intersectable::TRIANGLE_INTERSECTABLE: 
    422434                                                { 
    423                                                         // TODO 
    424                                                         cout << "not implemented yet" << endl; 
     435                                                        TriangleIntersectable *intersect =  
     436                                                                        dynamic_cast<TriangleIntersectable *>(obj); 
     437 
     438                                                        Polygon3 *poly = new Polygon3(intersect->GetItem()); 
     439 
     440                                                        if (poly->Valid(mEpsilon))       
     441                                                                polys.push_back(poly); 
     442                                                        else 
     443                                                                delete poly; 
    425444                                                } 
     445                                                break; 
     446 
    426447                                        default: 
     448                                                cout << "not implemented yet" << endl; 
    427449                                                break; 
    428450                                } 
     
    430452                                ++ numObj; 
    431453 
     454                                ///////// 
    432455                                //-- compute bounding box 
     456 
    433457                                if (!forcedBoundingBox) 
     458                                { 
    434459                                        mBoundingBox.Include(ray->mTermination); 
     460                                } 
    435461                        } 
    436462 
Note: See TracChangeset for help on using the changeset viewer.