Changeset 486


Ignore:
Timestamp:
12/30/05 16:37:41 (18 years ago)
Author:
mattausch
Message:
 
Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env

    r485 r486  
    146146        loadFromFile false 
    147147        #type kdTree 
    148         type vspKdTree 
     148        #type vspKdTree 
    149149        #type bspTree 
    150         #type vspBspTree 
     150        type vspBspTree 
    151151         
    152152        #type sceneDependent 
     
    217217        PostProcess { 
    218218                maxCostRatio 0.005 
    219                 minViewCells 200 
     219                minViewCells 100 
    220220                maxPvsSize   50000 
    221221        } 
     
    230230                samples 300000 
    231231                epsilon 0.005 
     232                randomize true 
    232233        } 
    233234 
     
    282283        PostProcess { 
    283284                maxCostRatio 0.1 
    284                 minViewCells 200 
     285                minViewCells 100 
    285286                maxPvsSize   500 
    286287                useRaysForMerge false 
  • trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp

    r482 r486  
    77#include "Ray.h" 
    88#include "Polygon3.h" 
     9#include "Mesh.h" 
    910 
    1011#define FATAL Debug 
     
    18651866} 
    18661867 
     1868 
     1869void AxisAlignedBox3::AddBoxToMesh(Mesh *mesh) const 
     1870{ 
     1871        // add 6 vertices of the box 
     1872        int index = (int)mesh->mVertices.size(); 
     1873         
     1874        for (int i=0; i < 8; i++)  
     1875        { 
     1876                Vector3 v; 
     1877                GetVertex(i, v); 
     1878                mesh->mVertices.push_back(v); 
     1879        } 
     1880         
     1881        mesh->AddFace(new Face(index + 0, index + 1, index + 3, index + 2) ); 
     1882        mesh->AddFace(new Face(index + 0, index + 2, index + 6, index + 4) ); 
     1883        mesh->AddFace(new Face(index + 4, index + 6, index + 7, index + 5) ); 
     1884         
     1885        mesh->AddFace(new Face(index + 3, index + 1, index + 5, index + 7) ); 
     1886        mesh->AddFace(new Face(index + 0, index + 4, index + 5, index + 1) ); 
     1887        mesh->AddFace(new Face(index + 2, index + 3, index + 7, index + 6) ); 
     1888 
     1889} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h

    r482 r486  
    99class Ray; 
    1010class Polygon3; 
    11  
     11class Mesh; 
    1212// -------------------------------------------------------- 
    1313// CAABox class. 
     
    329329                                                   const AxisAlignedBox3 &neighbour) const; 
    330330 
     331  /** Adds the box faces to the mesh. 
     332  */ 
     333  void AddBoxToMesh(Mesh *mesh) const; 
     334 
    331335#define __EXTENT_HACK 
    332336  // get the extent of face 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp

    r485 r486  
    17511751                "vsp_bsp_term_post_process_use_rays_for_merge=",  
    17521752                "false"); 
    1753          
     1753 
     1754        RegisterOption("VspBspTree.Construction.randomize",  
     1755                optBool,  
     1756                "vsp_bsp_construction_randomize=",  
     1757                "false"); 
    17541758        ////////////////////////////////////////////////////////////////////////////////// 
    17551759} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h

    r482 r486  
    2222class VspBspTree; 
    2323class RssTree; 
     24class Mesh; 
    2425 
    2526class Exporter 
     
    109110  ExportGeometry(const ObjectContainer &objects) = 0; 
    110111 
     112  virtual void 
     113  ExportMesh(Mesh *mesh) = 0; 
     114 
    111115  virtual bool 
    112116  ExportRssTree2(const RssTree &tree, 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r485 r486  
    197197mGenerateViewCells(true) 
    198198{ 
     199         
     200 
    199201        Randomize(); // initialise random generator for heuristics 
    200202 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp

    r485 r486  
    9090        int i = 0;       
    9191        for (it = rays.begin(); it != it_end; ++ it)  
    92         {       if ((i ++) % 50000 == 0) 
    93                         cout << "Computed 50000 samples" << endl; 
     92        {       Debug << "here " << i ++ << endl; 
    9493                ComputeSampleContributions(*(*it)); 
     94                Debug << "**" << endl; 
    9595        } 
    9696} 
     
    316316        Ray hray(ray); 
    317317        float tmin = 0, tmax = 1.0; 
    318         Debug << "here2" << endl; 
     318         
    319319        //hray.Init(ray.GetOrigin(), ray.GetDir(), Ray::LINE_SEGMENT); 
    320320        if (!GetSceneBbox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 
     
    344344                 
    345345                ray.mRelativePvsContribution += contribution; 
    346         }Debug << "here5" << endl; 
     346        } 
    347347} 
    348348 
     
    13401340         
    13411341        // collapse siblings belonging to the same view cell 
    1342         mVspKdTree->RefineViewCells(); 
     1342        mVspKdTree->RefineViewCells(rays); 
    13431343 
    13441344        // evaluale view cell stats 
     
    16141614        vector<VspKdLeaf *>::const_iterator it, it_end = kdVc->mLeaves.end(); 
    16151615 
     1616        Mesh m; 
    16161617        for (it = kdVc->mLeaves.begin(); it != it_end; ++ it) 
    1617                 exporter->ExportBox(mVspKdTree->GetBBox(*it)); 
     1618        { 
     1619                mVspKdTree->GetBBox(*it).AddBoxToMesh(&m); 
     1620        } 
     1621 
     1622        exporter->ExportMesh(&m); 
    16181623} 
    16191624 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp

    r485 r486  
    4747mOnlyDrivingAxis(false) 
    4848{ 
    49         Randomize(); // initialise random generator for heuristics 
     49        bool randomize = false; 
     50        environment->GetBoolValue("VspBspTree.Construction.randomize", randomize); 
     51        if (randomize) 
     52                Randomize(); // initialise random generator for heuristics 
    5053 
    5154        //-- termination criteria for autopartition 
     
    9699        Debug << "max polygon candidates: " << mMaxPolyCandidates << endl; 
    97100        Debug << "max plane candidates: " << mMaxRayCandidates << endl; 
     101        Debug << "randomize: " << randomize << endl; 
    98102 
    99103        Debug << "Split plane strategy: "; 
     
    19041908                        // find intersection of ray segment with plane 
    19051909                        extp = splitPlane.FindIntersection(origin, extp, &t); 
     1910                        //cout << "x"; 
    19061911                }  
    19071912                else 
    19081913                { 
     1914                        //cout << "o"; 
    19091915                        // reached leaf => intersection with view cell 
    19101916                        BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
     
    19311937                } 
    19321938        } 
    1933  
     1939        //cout << "!!!!!!!!!!!" << endl; 
    19341940        return hits; 
    19351941} 
     
    24282434                                                         BspViewCell *vc2) const 
    24292435{ 
    2430         //Debug << "old pvs: " << vc1->GetPvs().GetSize() + vc2->GetPvs().GetSize()  
    2431         //        << " (" << vc1->GetPvs().GetSize() << ", " << vc2->GetPvs().GetSize() << ")" << endl; 
    24322436        // compute new pvs and area 
    24332437        vc1->GetPvs().SubtractPvs(*leaf->mPvs); 
     
    24552459        }*/ 
    24562460 
    2457         leaf->SetViewCell(vc2);         // finally change view cell 
     2461        leaf->SetViewCell(vc2); // finally change view cell 
    24582462         
    24592463        //Debug << "new pvs: " << vc1->GetPvs().GetSize() + vc2->GetPvs().GetSize()  
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h

    r485 r486  
    529529        Plane3 ChooseCandidatePlane3(const RayInfoContainer &rays) const; 
    530530   
     531        /** Shuffles, i.e. takes border leaf from view cell 1 and adds it  
     532                to view cell 2. 
     533        */ 
    531534        void ShuffleLeaf(BspLeaf *leaf,  
    532535                                         BspViewCell *vc1,  
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp

    r485 r486  
    179179 
    180180 
    181 /**************************************************************/ 
    182 /*              class VspKdLeaf implementation            */ 
    183 /**************************************************************/ 
     181/*******************************************************************/ 
     182/*                   class VspKdLeaf implementation                */ 
     183/*******************************************************************/ 
    184184 
    185185 
     
    23512351 
    23522352 
    2353 void VspKdTree::RefineViewCells() 
    2354 { 
    2355         //TODO 
    2356 } 
     2353int VspKdTree::RefineViewCells(const VssRayContainer &rays) 
     2354{ 
     2355        int shuffled = 0; 
     2356 
     2357        Debug << "refining " << (int)mMergeQueue.size() << " candidates " << endl; 
     2358        BspLeaf::NewMail(); 
     2359 
     2360        // Use priority queue of remaining leaf pairs  
     2361        // These candidates either share the same view cells or 
     2362        // are border leaves which share a boundary. 
     2363        // We test if they can be shuffled, i.e., 
     2364        // either one leaf is made part of one view cell or the other 
     2365        // leaf is made part of the other view cell. It is tested if the 
     2366        // remaining view cells are "better" than the old ones. 
     2367        while (!mMergeQueue.empty()) 
     2368        { 
     2369                MergeCandidate mc = mMergeQueue.top(); 
     2370                mMergeQueue.pop(); 
     2371 
     2372                // both view cells equal or already shuffled 
     2373                if ((mc.GetLeaf1()->GetViewCell() == mc.GetLeaf2()->GetViewCell()) || 
     2374                        (mc.GetLeaf1()->Mailed()) || (mc.GetLeaf2()->Mailed())) 
     2375                        continue; 
     2376                 
     2377                // candidate for shuffling 
     2378                const bool wasShuffled = false; 
     2379                        //ShuffleLeaves(mc.GetLeaf1(), mc.GetLeaf2()); 
     2380                 
     2381                //-- stats 
     2382                if (wasShuffled) 
     2383                        ++ shuffled; 
     2384        } 
     2385 
     2386        return shuffled; 
     2387} 
     2388 
     2389 
     2390inline int AddedPvsSize(ObjectPvs pvs1, const ObjectPvs &pvs2) 
     2391{ 
     2392        return pvs1.AddPvs(pvs2); 
     2393} 
     2394 
     2395 
     2396inline int SubtractedPvsSize(ObjectPvs pvs1, const ObjectPvs &pvs2) 
     2397{ 
     2398        return pvs1.SubtractPvs(pvs2); 
     2399} 
     2400 
     2401 
     2402float GetShuffledVcCost(VspKdLeaf *leaf, VspKdViewCell *vc1, VspKdViewCell *vc2) 
     2403{ 
     2404#if 0 // TODO 
     2405        const int pvs1 = SubtractedPvsSize(vc1->GetPvs(), *leaf->mPvs); 
     2406        const int pvs2 = AddedPvsSize(vc2->GetPvs(), *leaf->mPvs); 
     2407 
     2408        const float area1 = vc1->GetArea() - leaf->mArea; 
     2409        const float area2 = vc2->GetArea() + leaf->mArea; 
     2410 
     2411        const float cost1 = pvs1 * area1; 
     2412        const float cost2 = pvs2 * area2; 
     2413 
     2414        return cost1 + cost2; 
     2415#else 
     2416        return -1; 
     2417#endif 
     2418} 
     2419 
     2420 
     2421void VspKdTree::ShuffleLeaf(VspKdLeaf *leaf,  
     2422                                                        VspKdViewCell *vc1,  
     2423                                                        VspKdViewCell *vc2) const 
     2424{ 
     2425#if 0 // TODO 
     2426        // compute new pvs and area 
     2427        vc1->GetPvs().SubtractPvs(*leaf->mPvs); 
     2428        vc2->GetPvs().AddPvs(*leaf->mPvs); 
     2429         
     2430        vc1->SetArea(vc1->GetArea() - leaf->mArea); 
     2431        vc2->SetArea(vc2->GetArea() + leaf->mArea); 
     2432 
     2433        /// add to second view cell 
     2434        vc2->mLeaves.push_back(leaf); 
     2435 
     2436        // erase leaf from old view cell 
     2437        vector<VspKdLeaf *>::iterator it = vc1->mLeaves.begin(); 
     2438 
     2439        for (; *it != leaf; ++ it); 
     2440        vc1->mLeaves.erase(it); 
     2441 
     2442        leaf->SetViewCell(vc2);  // finally change view cell 
     2443#endif 
     2444} 
     2445 
     2446 
     2447bool VspKdTree::ShuffleLeaves(VspKdLeaf *leaf1, VspKdLeaf *leaf2) const 
     2448{ 
     2449        VspKdViewCell *vc1 = leaf1->GetViewCell(); 
     2450        VspKdViewCell *vc2 = leaf2->GetViewCell(); 
     2451 
     2452        const float cost1 = vc1->GetPvs().GetSize() * vc1->GetArea(); 
     2453        const float cost2 = vc2->GetPvs().GetSize() * vc2->GetArea(); 
     2454 
     2455        const float oldCost = cost1 + cost2; 
     2456         
     2457        float shuffledCost1 = Limits::Infinity; 
     2458        float shuffledCost2 = Limits::Infinity; 
     2459 
     2460        // the view cell should not be empty after the shuffle 
     2461        if (vc1->mLeaves.size() > 1) 
     2462                shuffledCost1 = GetShuffledVcCost(leaf1, vc1, vc2); 
     2463        if (vc2->mLeaves.size() > 1) 
     2464                shuffledCost2 = GetShuffledVcCost(leaf2, vc2, vc1); 
     2465 
     2466        // shuffling unsuccessful 
     2467        if ((oldCost <= shuffledCost1) && (oldCost <= shuffledCost2)) 
     2468                return false; 
     2469         
     2470        if (shuffledCost1 < shuffledCost2) 
     2471        { 
     2472                ShuffleLeaf(leaf1, vc1, vc2); 
     2473                leaf1->Mail(); 
     2474        } 
     2475        else 
     2476        { 
     2477                ShuffleLeaf(leaf2, vc2, vc1); 
     2478                leaf2->Mail(); 
     2479        } 
     2480 
     2481        return true; 
     2482} 
     2483 
     2484 
    23572485 
    23582486 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h

    r485 r486  
    603603        */ 
    604604        void CollectViewCells(ViewCellContainer &viewCells) const; 
    605         /** Refines view cells in a post processing step. 
    606         */ 
    607         void RefineViewCells(); 
     605         
     606        /** Refines view cells using shuffling, i.e., border leaves  
     607                of two view cells are exchanged if the resulting view cells 
     608                are tested to be "better" than the old ones. 
     609                @returns number of refined view cells 
     610        */ 
     611        int RefineViewCells(const VssRayContainer &rays); 
    608612 
    609613        /** Collects candidates for the merge in the merge queue. 
     
    726730        void RepairVcLeafLists(); 
    727731 
     732        /** Shuffles the leaves, i.e., tests if exchanging 
     733                the view cells the leaves belong to helps in improving the view cells. 
     734        */ 
     735        bool ShuffleLeaves(VspKdLeaf *leaf1, VspKdLeaf *leaf2) const; 
     736 
     737        /** Shuffles, i.e. takes border leaf from view cell 1 and adds it  
     738                to view cell 2. 
     739        */ 
     740        void ShuffleLeaf(VspKdLeaf *leaf, 
     741                                         VspKdViewCell *vc1,  
     742                                         VspKdViewCell *vc2) const; 
    728743protected: 
    729744         
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r483 r486  
    678678 
    679679 
    680 void 
    681 X3dExporter::AddBoxToMesh(const AxisAlignedBox3 &box, 
    682                                                                                                         Mesh *mesh) 
    683 { 
    684         // add 6 vertices of the box 
    685         int index = (int)mesh->mVertices.size(); 
    686          
    687         for (int i=0; i < 8; i++) { 
    688                 Vector3 v; 
    689                 box.GetVertex(i, v); 
    690                 mesh->mVertices.push_back(v); 
    691         } 
    692          
    693         mesh->AddFace(new Face(index + 0, index + 1, index + 3, index + 2) ); 
    694         mesh->AddFace(new Face(index + 0, index + 2, index + 6, index + 4) ); 
    695         mesh->AddFace(new Face(index + 4, index + 6, index + 7, index + 5) ); 
    696          
    697         mesh->AddFace(new Face(index + 3, index + 1, index + 5, index + 7) ); 
    698         mesh->AddFace(new Face(index + 0, index + 4, index + 5, index + 1) ); 
    699         mesh->AddFace(new Face(index + 2, index + 3, index + 7, index + 6) ); 
    700  
    701 } 
     680 
    702681 
    703682bool 
     
    726705                        AxisAlignedBox3 box; 
    727706                        box = tree.GetBBox(leaf); 
    728                         AddBoxToMesh(box, mesh); 
     707                        box.AddBoxToMesh(mesh); 
    729708 
    730709                        if (tree.ValidLeaf(leaf)) { 
     
    829808                box = tree.GetBBox(leaf); 
    830809                Mesh *mesh = new Mesh; 
    831                 AddBoxToMesh(box, mesh); 
     810                box.AddBoxToMesh(mesh); 
    832811                 
    833812                // get 4 corners of the ray directions 
     
    12261205                box = tree.GetShrankedBBox(leaf); 
    12271206                Mesh *mesh = new Mesh; 
    1228                 AddBoxToMesh(box, mesh); 
     1207                box.AddBoxToMesh(mesh); 
    12291208                 
    12301209                // get 4 corners of the ray directions 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h

    r482 r486  
    133133  ExportBspTreeRayDensity(const BspTree &tree); 
    134134 
    135   void 
    136   AddBoxToMesh(const AxisAlignedBox3 &box, 
    137                            Mesh *mesh); 
    138  
    139135  void ExportBspNodeSplits(BspNode *root, 
    140136                                                   const AxisAlignedBox3 &box, 
Note: See TracChangeset for help on using the changeset viewer.