Changeset 1999


Ignore:
Timestamp:
01/20/07 00:14:25 (17 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
18 edited

Legend:

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

    r1981 r1999  
    99#include "Mesh.h" 
    1010#include "Halton.h" 
     11#include "Triangle3.h" 
     12 
    1113 
    1214namespace GtpVisibilityPreprocessor { 
     
    556558AxisAlignedBox3::IsInside(const Vector3 &v) const 
    557559{ 
    558   return ! (v.x < mMin.x || 
    559             v.x > mMax.x || 
    560             v.y < mMin.y || 
    561             v.y > mMax.y || 
    562             v.z < mMin.z || 
    563             v.z > mMax.z); 
     560  return ! ((v.x < mMin.x) || 
     561            (v.x > mMax.x) || 
     562            (v.y < mMin.y) || 
     563            (v.y > mMax.y) || 
     564            (v.z < mMin.z) || 
     565            (v.z > mMax.z)); 
    564566} 
    565567#endif 
     
    23532355} 
    23542356 
     2357 
     2358 bool AxisAlignedBox3::Intersects(const Mesh &mesh) const 
     2359 { 
     2360         VertexContainer::const_iterator vit, vit_end = mesh.mVertices.end(); 
     2361 
     2362         for (vit = mesh.mVertices.begin(); vit != vit_end; ++ vit) 
     2363         { 
     2364                if (IsInside(*vit)) 
     2365                        return true; 
     2366         } 
     2367          
     2368         return false; 
     2369 } 
     2370 
     2371 
     2372 bool AxisAlignedBox3::Intersects(const Triangle3 &tri) const 
     2373 { 
     2374         if (IsInside(tri.mVertices[0]) || 
     2375                 IsInside(tri.mVertices[1]) || 
     2376                 IsInside(tri.mVertices[2])) 
     2377         { 
     2378                        return true; 
     2379         } 
     2380 
     2381         return false; 
     2382 } 
     2383 
    23552384/* 
    23562385int inline GetIntersection(const float fDst1,  
  • GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h

    r1995 r1999  
    1313class Polygon3; 
    1414class Mesh; 
     15struct Triangle3; 
    1516 
    1617/** 
     
    358359  void ExtractPolys(PolygonContainer &polys) const; 
    359360 
     361  /** Returns true if the mesh intersects the bounding box. 
     362  */ 
     363  bool Intersects(const Mesh &mesh) const; 
     364   /** Returns true if the triangle intersects the bounding box. 
     365  */ 
     366  bool Intersects(const Triangle3 &tri) const; 
    360367  /** Splits the box into two separate boxes with respect to the split plane 
    361368  */ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp

    r1941 r1999  
    205205 
    206206BvhInterior::~BvhInterior()  
    207 {  
     207{ 
    208208        DEL_PTR(mFront);  
    209209        DEL_PTR(mBack); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp

    r1996 r1999  
    1616{ 
    1717   
    18 #define GVS_DEBUG 0 
     18#define GVS_DEBUG 1 
    1919 
    2020struct VizStruct 
     
    3131GvsPreprocessor::GvsPreprocessor():  
    3232Preprocessor(),  
    33 mSamplingType(SamplingStrategy::VIEWCELL_BASED_DISTRIBUTION), 
    34 //mSamplingType(SamplingStrategy::DIRECTION_BASED_DISTRIBUTION), 
     33//mSamplingType(SamplingStrategy::VIEWCELL_BASED_DISTRIBUTION), 
     34mSamplingType(SamplingStrategy::DIRECTION_BASED_DISTRIBUTION), 
    3535mProcessedViewCells(0), 
    3636mCurrentViewCell(NULL) 
     
    144144                        delete newRay; 
    145145                } 
    146                 else if (0 && GVS_DEBUG && (mVssRays.size() < 9)) 
     146                 
     147 
     148                return 1; 
     149        } 
     150 
     151        return 0; 
     152} 
     153 
     154// #id: 1270 
     155bool GvsPreprocessor::HasContribution(VssRay &ray) 
     156{ 
     157        if (!ray.mTerminationObject) 
     158                return false; 
     159 
     160        bool result; 
     161 
     162        if (!mPerViewCell) 
     163        { 
     164                // store the rays + the intersected view cells 
     165                const bool storeViewCells = false; //GVS_DEBUG; 
     166 
     167                mViewCellsManager->ComputeSampleContribution(ray,  
     168                                                                                                         true,  
     169                                                                                                         storeViewCells, 
     170                                                                                                         true); 
     171 
     172                result = ray.mPvsContribution > 0; 
     173        } 
     174        else 
     175        { 
     176                Intersectable *obj = ray.mTerminationObject; 
     177 
     178                if (!obj->mCounter) 
    147179                { 
    148                         mVssRays.push_back(new VssRay(oldRay)); 
    149                         mVssRays.push_back(new VssRay(currentRay)); 
    150                         mVssRays.push_back(new VssRay(*newRay)); 
    151                 } 
    152  
    153                 return 1; 
    154         } 
    155  
    156         return 0; 
    157 } 
    158  
    159  
    160 bool GvsPreprocessor::HandleRay(VssRay *vssRay) 
    161 { 
    162         // store the rays + the intersected view cells 
    163         const bool storeRaysForViz = false; //GVS_DEBUG; 
    164  
    165         if (!mPerViewCell) 
    166         { 
    167                 mViewCellsManager->ComputeSampleContribution(*vssRay,  
    168                                                                                                          true,  
    169                                                                                                          storeRaysForViz, 
    170                                                                                                          true); 
    171         } 
    172         else 
    173         { 
    174                 mViewCellsManager->ComputeSampleContribution(*vssRay,  
     180                        obj->mCounter = 1; 
     181                        mTrianglePvs.push_back(obj); 
     182 
     183                        /*mViewCellsManager->ComputeSampleContribution(ray,  
    175184                                                                                                         true,  
    176185                                                                                                         mCurrentViewCell, 
    177                                                                                                          true); 
    178         } 
    179  
    180         // some pvs contribution for this ray? 
    181         if (!vssRay->mPvsContribution) 
     186                                                                                                         true);*/ 
     187                         
     188                        result = true; 
     189                } 
     190                else 
     191                { 
     192                        result = false; 
     193                } 
     194        } 
     195 
     196        return result; 
     197} 
     198 
     199 
     200bool GvsPreprocessor::HandleRay(VssRay *vssRay) 
     201{ 
     202        if (!HasContribution(*vssRay)) 
    182203                return false; 
    183204 
    184         if (GVS_DEBUG) 
     205        if (0 && GVS_DEBUG) 
    185206                mVssRays.push_back(new VssRay(*vssRay)); 
    186207 
    187208        // add new ray to ray queue 
    188209        mRayQueue.push(vssRay); 
    189  
    190         if (storeRaysForViz) 
    191         { 
    192                 VssRay *nray = new VssRay(*vssRay); 
    193                 nray->mFlags = vssRay->mFlags; 
    194  
    195                 // store ray in contributing view cell 
    196                 ViewCellContainer::const_iterator vit, vit_end = vssRay->mViewCells.end(); 
    197                 for (vit = vssRay->mViewCells.begin(); vit != vit_end; ++ vit) 
    198                 {                        
    199                         (*vit)->GetOrCreateRays()->push_back(nray);                              
    200                 } 
    201         } 
    202210 
    203211        ++ mGvsStats.mTotalContribution; 
     
    399407        } 
    400408 
     409        int castRays = (int)simpleRays.size(); 
     410 
     411        VssRayContainer invalidSamples; 
     412 
    401413        // handle rays 
    402         EnqueueRays(vssRays); 
    403          
    404         int castRays = simpleRays.size(); 
    405          
     414        EnqueueRays(vssRays, invalidSamples); 
     415 
    406416    // recursivly subdivide each edge 
    407417        for (int i = 0; i < numBorderSamples; ++ i) 
     
    414424                                                                  currentRay); 
    415425        } 
    416  
     426         
    417427        mGvsStats.mBorderSamples += castRays; 
     428 
     429        CLEAR_CONTAINER(invalidSamples); 
    418430 
    419431        return castRays; 
     
    442454        if (!intersects) 
    443455        { 
    444                 cerr << "big error!! no intersection " << pt1 << " " << pt2 << endl; 
     456                //cerr << "big error!! no intersection " << pt1 << " " << pt2 << endl; 
    445457                return false; 
    446458        } 
     
    562574        CastRays(simpleRays, samples, castDoubleRays, pruneInvalidRays); 
    563575         
     576        VssRayContainer invalidSamples; 
     577 
    564578        // add to ray queue 
    565         EnqueueRays(samples); 
    566  
     579        EnqueueRays(samples, invalidSamples); 
     580 
     581        CLEAR_CONTAINER(invalidSamples); 
    567582        //Debug << "generated " <<  numSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    568583        return (int)simpleRays.size(); 
     
    570585 
    571586 
    572 void GvsPreprocessor::EnqueueRays(VssRayContainer &samples) 
     587void GvsPreprocessor::EnqueueRays(VssRayContainer &samples, VssRayContainer &invalidSamples) 
    573588{ 
    574589        // add samples to ray queue 
     
    576591        for (vit = samples.begin(); vit != vit_end; ++ vit) 
    577592        { 
    578                 HandleRay(*vit); 
     593                VssRay *ray = *vit; 
     594 
     595                if (!HandleRay(ray)) 
     596                        invalidSamples.push_back(ray); 
    579597        } 
    580598} 
     
    597615                castSamples += newSamples; 
    598616 
    599                 //cout << newSamples << " ";     
     617                //cout << "new samples: " << newSamples << " " << "queue: "  << (int)mRayQueue.size() << endl; 
    600618                delete ray; 
    601619        } 
     
    639657 
    640658 
    641 void GvsPreprocessor::VisualizeViewCell(ViewCell *vc) 
     659//void GvsPreprocessor::VisualizeViewCell(ViewCell *vc) 
     660void GvsPreprocessor::VisualizeViewCell(const ObjectContainer &objects) 
    642661{ 
    643662    Intersectable::NewMail(); 
     
    651670                return; 
    652671 
    653         ObjectPvsIterator pit = vc->GetPvs().GetIterator(); 
     672        /*ObjectPvsIterator pit = vc->GetPvs().GetIterator(); 
    654673 
    655674        // output PVS of view cell 
     
    669688 
    670689                exporter->ExportIntersectable(intersect); 
     690        }*/ 
     691        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     692 
     693        for (oit = objects.begin(); oit != oit_end; ++ oit) 
     694        { 
     695                Intersectable *intersect = *oit; 
     696                 
     697                m = RandomMaterial(); 
     698                exporter->SetForcedMaterial(m); 
     699                exporter->ExportIntersectable(intersect); 
    671700        } 
    672701 
     
    682711        exporter->SetForcedMaterial(m); 
    683712 
    684         mViewCellsManager->ExportViewCellGeometry(exporter, vc, NULL, NULL); 
     713        //mViewCellsManager->ExportViewCellGeometry(exporter, vc, NULL, NULL); 
     714        //mViewCellsManager->ExportViewCellGeometry(exporter, mCurrentViewCell, NULL, NULL); 
     715 
     716        AxisAlignedBox3 bbox = mCurrentViewCell->GetMesh()->mBox; 
     717        exporter->ExportBox(bbox); 
    685718        //exporter->SetFilled(); 
    686719 
     
    720753void GvsPreprocessor::ProcessViewCell() 
    721754{ 
     755        //Intersectable::NewMail(); 
     756        // compute direct intersections with view cell 
     757        IntersectWithViewCell(); 
     758 
    722759        mGvsStats.mPerViewCellSamples = 0; 
    723760        int oldContribution = mGvsStats.mTotalContribution; 
     
    736773                passSamples += newSamples; 
    737774                mGvsStats.mPerViewCellSamples += newSamples; 
    738                 //cout << "here4 " << passSamples % (mSamplesPerPass + 1) << endl; 
     775                //cout << "here2 " << passSamples % (mSamplesPerPass + 1) << endl; 
    739776 
    740777                if (passSamples >= mSamplesPerPass) 
     
    774811                { 
    775812                        mViewCells.push_back(mViewCellsManager->GetViewCell((int)mViewCells.size())); 
     813                        continue; 
    776814                } 
    777                 else 
     815                 
     816                // HACK 
     817                const int tries = 10000; 
     818                int i = 0; 
     819 
     820                for (i = 0; i < tries; ++ i) 
    778821                { 
    779                         // HACK 
    780                         const int tries = 10000; 
    781                         int i = 0; 
    782  
    783                         for (i = 0; i < tries; ++ i) 
     822                        const int idx = (int)RandomValue(0.0f, (float)mViewCellsManager->GetNumViewCells() - 0.5f); 
     823         
     824                        ViewCell *viewCell = mViewCellsManager->GetViewCell(idx); 
     825 
     826                        if (!viewCell->Mailed()) 
    784827                        { 
    785                                 const int idx = (int)RandomValue(0.0f, (float)mViewCellsManager->GetNumViewCells() - 0.5f); 
    786          
    787                                 ViewCell *viewCell = mViewCellsManager->GetViewCell(idx); 
    788  
    789                                 if (!viewCell->Mailed()) 
     828                                viewCell->Mail(); 
     829                                break; 
     830                        } 
     831 
     832                        mViewCells.push_back(viewCell); 
     833                } 
     834 
     835                if (i == tries) 
     836                { 
     837                        cerr << "big error! no view cell found" << endl; 
     838                        return; 
     839                } 
     840        } 
     841} 
     842 
     843 
     844void GvsPreprocessor::IntersectWithViewCell() 
     845{ 
     846        mCurrentViewCell->GetMesh()->ComputeBoundingBox(); 
     847        AxisAlignedBox3 box = mCurrentViewCell->GetMesh()->mBox; 
     848        //cout << "box: " << box << endl; 
     849        vector<KdLeaf *> leaves; 
     850 
     851        mKdTree->GetBoxIntersections(box, leaves); 
     852 
     853        vector<KdLeaf *>::const_iterator lit, lit_end = leaves.end(); 
     854 
     855        for (lit = leaves.begin(); lit != leaves.end(); ++ lit) 
     856        { 
     857                KdLeaf *leaf = *lit; 
     858                ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
     859 
     860                for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
     861                { 
     862                        TriangleIntersectable *triObj = dynamic_cast<TriangleIntersectable *>(*oit); 
     863 
     864                        if (box.Intersects(triObj->GetItem())) 
     865                        { 
     866                                if (!triObj->mCounter) 
    790867                                { 
    791                                         viewCell->Mail(); 
    792                                         break; 
     868                                        triObj->mCounter = 1; 
     869                                        mTrianglePvs.push_back(triObj); 
    793870                                } 
    794  
    795                                 mViewCells.push_back(viewCell); 
    796                         } 
    797  
    798                         if (i == tries) 
    799                         { 
    800                                 cerr << "big error! no view cell found" << endl; 
    801                                 return; 
    802871                        } 
    803872                } 
     
    808877void GvsPreprocessor::PerViewCellComputation() 
    809878{ 
     879        // hack: reset counter 
     880        ObjectContainer::const_iterator oit, oit_end = mObjects.end(); 
     881 
     882        for (oit = mObjects.begin(); oit != oit_end; ++ oit) 
     883        { 
     884                (*oit)->mCounter = 0; 
     885        } 
     886 
    810887        while (NextViewCell()) 
    811888        { 
    812                 cout << "\n***********************\nprocessing view cell " << mProcessedViewCells << endl; 
     889                cout << "\n***********************\n"  
     890                         << "processing view cell " << mProcessedViewCells  
     891                         << " (id: " << mCurrentViewCell->GetId() << ")" << endl; 
    813892 
    814893                // compute the pvs of the current view cell 
    815894                ProcessViewCell(); 
    816895 
    817                 mGvsStats.mTrianglePvs = mCurrentViewCell->GetPvs().GetSize(); 
     896                //mGvsStats.mTrianglePvs = mCurrentViewCell->GetPvs().GetSize(); 
     897                mGvsStats.mTrianglePvs = (int)mTrianglePvs.size(); 
     898 
     899                ObjectContainer objectPvs; 
    818900 
    819901                // exchange triangle pvs with objects 
    820                 UpdatePvs(mCurrentViewCell); 
    821  
    822                 if (GVS_DEBUG) 
    823                 { 
    824                         VisualizeViewCell(mCurrentViewCell); 
    825                         CLEAR_CONTAINER(mVssRays); 
    826                 } 
     902                //UpdatePvs(mCurrentViewCell); 
     903                GetObjectPvs(objectPvs); 
     904 
     905                cout << "triangle pvs of " << (int)mTrianglePvs.size() << " was converted to object pvs of " << (int)objectPvs.size() << endl; 
    827906 
    828907                //////// 
     
    830909                 
    831910                mGvsStats.mViewCells = mProcessedViewCells;//mPass; 
    832                 mGvsStats.mPerViewCellPvs = mCurrentViewCell->GetPvs().GetSize(); 
    833                 mGvsStats.mTotalPvs += mCurrentViewCell->GetPvs().GetSize(); 
     911                //mGvsStats.mPerViewCellPvs = mCurrentViewCell->GetPvs().GetSize(); 
     912                mGvsStats.mPerViewCellPvs = (int)mTrianglePvs.size(); 
     913 
     914                mGvsStats.mTotalPvs += mGvsStats.mPerViewCellPvs; 
    834915                mGvsStats.mTotalSamples += mGvsStats.mPerViewCellSamples; 
    835916 
    836917                mGvsStats.Stop(); 
    837918                mGvsStats.Print(mGvsStatsStream); 
     919 
     920                mTrianglePvs.clear(); 
     921 
     922                if (GVS_DEBUG) 
     923                { 
     924                        //VisualizeViewCell(mCurrentViewCell); 
     925                        VisualizeViewCell(objectPvs); 
     926                        CLEAR_CONTAINER(mVssRays); 
     927                } 
    838928 
    839929                // is this really necessary? 
     
    871961 
    872962        currentViewCell->SetPvs(newPvs); 
     963} 
     964 
     965  
     966void GvsPreprocessor::GetObjectPvs(ObjectContainer &objectPvs) const 
     967{ 
     968        BvhLeaf::NewMail(); 
     969 
     970        ObjectContainer::const_iterator oit, oit_end = mTrianglePvs.end(); 
     971 
     972        for (oit = mTrianglePvs.begin(); oit != oit_end; ++ oit) 
     973        { 
     974                Intersectable *intersect = *oit; 
     975         
     976                BvhLeaf *bv = intersect->mBvhLeaf; 
     977 
     978                if (!bv || bv->Mailed()) 
     979                        continue; 
     980                 
     981                bv->Mail(); 
     982 
     983                objectPvs.push_back(bv); 
     984                // hack: reset counter 
     985                (*oit)->mCounter = 0; 
     986        } 
    873987} 
    874988 
     
    9781092         
    9791093        vector<VizStruct>::const_iterator vit, vit_end = vizContainer.end(); 
     1094         
    9801095        for (vit = vizContainer.begin(); vit != vit_end; ++ vit) 
    9811096        { 
     
    9891104 
    9901105        VssRayContainer::const_iterator rit, rit_end = mVssRays.end(); 
     1106 
    9911107        for (rit = mVssRays.begin(); rit != rit_end; ++ rit) 
    9921108        { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h

    r1996 r1999  
    150150                with respect to the previous ray. 
    151151        */ 
    152         void EnqueueRays(VssRayContainer &samples); 
     152        void EnqueueRays(VssRayContainer &samples, VssRayContainer &invalidSamples); 
    153153 
    154154        /** Hepler function for adaptive border sampling. It finds  
     
    191191 
    192192        void VisualizeViewCell(ViewCell *vc); 
     193        void VisualizeViewCell(const ObjectContainer &objects); 
    193194 
    194195        /** Exchanges view cell triangle pvs with bvh leaf pvs. 
     
    201202        void CompileViewCellsList(); 
    202203 
     204        void GetObjectPvs(ObjectContainer &trianglePvs) const; 
     205 
     206        bool HasContribution(VssRay &ray); 
     207 
     208        void IntersectWithViewCell(); 
    203209 
    204210        ////////////////////// 
     
    220226        // stats 
    221227 
    222         /*int mSampleContriPerPass; 
    223         int mTotalSampleContri; 
    224         int mReverseSamples; 
    225         int mBorderSamples; 
    226         int mGvsPass;*/ 
    227  
    228228        ofstream mGvsStatsStream; 
    229229        GvsStatistics mGvsStats; 
     
    241241 
    242242        int mMaxViewCells; 
     243 
     244        ObjectContainer mTrianglePvs; 
    243245}; 
    244246 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp

    r1996 r1999  
    7373        if (castDoubleRay) 
    7474        { 
    75           cerr<<"HERE"<<endl; 
     75          //cerr<<"HERE"<<endl; 
    7676          Vector3 dir = -simpleRay.mDirection; 
    7777                hittriangle = mlrtaIntersectAS( 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h

    r1990 r1999  
    3232class Intersectable { 
    3333public: 
    34   // last mail id -> warning not thread safe! 
    35   // both mailId and mailbox should be unique for each thread!!! 
    36   static int sMailId; 
    37   static int sReservedMailboxes; 
    38  
    39   /// Mailbox used for traversals 
    40   int mMailbox; 
    41    
     34  
    4235  /// unique object Id 
    4336  int mId; 
     
    10194  int IncMail() { return ++ mMailbox - sMailId; } 
    10295 
     96   // last mail id -> warning not thread safe! 
     97  // both mailId and mailbox should be unique for each thread!!! 
     98  static int sMailId; 
     99  static int sReservedMailboxes; 
     100 
     101  /// Mailbox used for traversals 
     102  int mMailbox; 
     103   
     104 
    103105  //////////////////////////////////////////////////// 
    104106  virtual AxisAlignedBox3 GetBox() const = 0; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h

    r1877 r1999  
    197197 
    198198        float GetArea() const {return mItem.GetArea();} 
     199 
    199200        int Type() const 
    200201        { 
     
    219220 
    220221 
    221  
    222  
    223222} 
    224223 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp

    r1995 r1999  
    3838        DEL_PTR(mFront); 
    3939        DEL_PTR(mBack); 
     40} 
     41 
     42 
     43KdLeaf::~KdLeaf() 
     44{ 
     45        DEL_PTR(mViewCell);   
    4046} 
    4147 
     
    7783KdTree::~KdTree() 
    7884{ 
    79         DEL_PTR(mRoot); 
     85    DEL_PTR(mRoot); 
     86 
     87        CLEAR_CONTAINER(mKdIntersectables); 
    8088} 
    8189 
     
    14391447} 
    14401448 
     1449 
    14411450KdIntersectable * 
    14421451KdTree::GetOrCreateKdIntersectable(KdNode *node) 
     
    15321541 
    15331542 
    1534 void KdTree::InsertObjects(KdNode *node, const ObjectContainer &objects) 
    1535 {/* 
    1536         stack<KdObjectsTraversalData> tStack; 
     1543void KdTree::GetBoxIntersections(const AxisAlignedBox3 &box, 
     1544                                                                 vector<KdLeaf *> &leaves) 
     1545{ 
     1546        stack<KdNode *> tStack; 
     1547 
     1548        tStack.push(mRoot); 
    15371549 
    15381550        while (!tStack.empty()) 
    15391551        { 
    1540                 KdObjectsTraversalData tData = tStack.top(); 
    1541         tStack.pop(); 
    1542  
    1543                 KdNode *node = tData.node; 
     1552                KdNode *node = tStack.top(); 
     1553                tStack.pop(); 
    15441554                 
    15451555                if (node->IsLeaf()) 
    15461556                { 
    1547                         KdLeaf *leaf = dynamic_cast<KdLeaf *>(node); 
    1548  
    1549                         ObjectContainer::const_iterator oit, oit_end = tData.objects->end(); 
    1550  
    1551                         for (oit = tData.objects->begin(); oit != oit_end; ++ oit) 
    1552                         { 
    1553                                 leaf->mObjects.push_back(*oit); 
    1554                         } 
     1557                        leaves.push_back(dynamic_cast<KdLeaf *>(node)); 
    15551558                } 
    15561559                else // interior 
    15571560                { 
    1558                         KdObjectsTraversalData frontData, backData; 
    15591561                        KdInterior *interior = dynamic_cast<KdInterior *>(node); 
    15601562 
    1561                         frontData.objects = new ObjectContainer(); 
    1562                         backData.objects = new ObjectContainer(); 
    1563  
    1564                         ObjectContainer::const_iterator oit, oit_end = tData.objects->end(); 
    1565                          
    1566                     for (oit = tData.objects->begin(); oit != oit_end; ++ oit)  
     1563                        if (box.Max(interior->mAxis) >= interior->mPosition) 
    15671564                        { 
    1568                                 Intersectable *object = *oit; 
    1569                  
    1570                                 // determine the side of this ray with respect to the plane 
    1571                                 const AxisAlignedBox3 box = object->GetBox(); 
    1572  
    1573                                 if (box.Max(interior->mAxis) >= interior->mPosition) 
    1574                                 { 
    1575                                         frontData.objects->push_back(object); 
    1576                                 } 
    1577  
    1578                                 if (box.Min(interior->mAxis) < interior->mPosition) 
    1579                                 { 
    1580                                         backData.objects->push_back(object); 
    1581                                 } 
     1565                                tStack.push(interior->mFront); 
    15821566                        } 
    15831567 
    1584                         tStack.push(backData); 
    1585                         tStack.push(frontData); 
    1586                 } 
    1587  
    1588                 DEL_PTR(tData.objects); 
    1589         }*/ 
    1590 } 
    1591  
    1592 } 
     1568                        if (box.Min(interior->mAxis) < interior->mPosition) 
     1569                        { 
     1570                                tStack.push(interior->mBack); 
     1571                        } 
     1572                } 
     1573        } 
     1574} 
     1575 
     1576 
     1577 
     1578} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h

    r1989 r1999  
    192192  } 
    193193 
    194   ~KdLeaf() { DEL_PTR(mViewCell);  } 
     194  ~KdLeaf(); 
    195195         
    196196        void AddPassingRay2(const Ray &ray, 
     
    411411  KdNode * 
    412412  GetNode(const Vector3 &point, const float maxArea) const; 
     413 
     414  void GetBoxIntersections(const AxisAlignedBox3 &box,  
     415                                                  vector<KdLeaf *> &leaves); 
    413416 
    414417  int 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1996 r1999  
    211211        DEL_PTR(renderer); 
    212212        DEL_PTR(mRayCaster); 
     213 
    213214#ifdef USE_CG 
    214215        DEL_PTR(mGlobalLinesRenderer); 
     
    11101111        cout << mKdTree->GetBox() << endl; 
    11111112 
    1112         if (0) 
    1113         { 
    1114                 Exporter *exporter = Exporter::GetExporter("dummykd.x3d"); 
    1115                          
    1116                 if (exporter) 
    1117                 { 
    1118                         exporter->ExportKdTree(*mKdTree, true); 
    1119                         delete exporter; 
    1120                 } 
    1121         } 
    1122  
    11231113        int rayCastMethod; 
    11241114        Environment::GetSingleton()-> 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp

    r1996 r1999  
    233233        Vector3 point; 
    234234        Vector3 normal; 
    235         //cout << "y"; 
     235         
    236236        const int i = (int)RandomValue(0, (float)mPreprocessor.mObjects.size() - 0.5f); 
    237237 
     
    347347        Vector3 point; 
    348348        Vector3 normal; 
    349         //cout << "y"; 
     349         
    350350        const int i = (int)RandomValue(0, (float)mPreprocessor.mObjects.size() - 0.5f); 
    351351 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1890 r1999  
    517517 
    518518ViewCellsTree::~ViewCellsTree() 
    519 { 
     519{cout<<"here1002"; 
    520520        DEL_PTR(mRoot); 
    521521} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h

    r1867 r1999  
    108108         
    109109        int mPvsSizeDecr; 
    110  
    111110   
    112111        float mVolume; 
     
    153152 
    154153public: 
     154 
    155155        ViewCell(); 
    156156 
     
    243243        } 
    244244 
    245   static bool GreaterOrEqualPvs(const ViewCell *a, const ViewCell *b) { 
    246         return !SmallerPvs(a, b); 
    247   } 
     245        static bool GreaterOrEqualPvs(const ViewCell *a, const ViewCell *b)  
     246        { 
     247                return !SmallerPvs(a, b); 
     248        } 
    248249 
    249250        static bool SmallerRenderCost(const ViewCell *a, const ViewCell *b)  
     
    260261                @hack The function is available for leaves also to have a common interface, 
    261262                but it should be less than zero for leaves. 
    262                 */ 
     263        */ 
    263264        void SetMergeCost(const float mergeCost); 
    264265 
     
    269270        float GetMergeCost() const; 
    270271 
    271   void UpdatePvsCost() { 
    272         mPvsCost = GetPvs().EvalPvsCost(); 
    273   } 
    274  
    275   void SetPvsCost(const float c) { 
    276         mPvsCost = c; 
    277   } 
    278  
    279   float GetPvsCost() const { 
    280         return mPvsCost; 
    281   } 
     272        void UpdatePvsCost() { 
     273                mPvsCost = GetPvs().EvalPvsCost(); 
     274        } 
     275 
     276        void SetPvsCost(const float c) { 
     277                mPvsCost = c; 
     278        } 
     279 
     280        float GetPvsCost() const { 
     281                return mPvsCost; 
     282        } 
    282283 
    283284        ////////// 
    284285        //-- mailing stuff 
    285286 
    286   //    static void NewMail(const int reserve = 1)  
    287   //    { 
    288   //            sMailId += sReservedMailboxes; 
    289   //            sReservedMailboxes = reserve; 
    290   //    } 
    291  
    292   //    void Mail() { mMailbox = sMailId; } 
    293   //    bool Mailed() const { return mMailbox == sMailId; } 
    294  
    295   //    void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } 
    296   //    bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 
    297  
    298   //    int IncMail() { return ++ mMailbox - sMailId; } 
     287        //      static void NewMail(const int reserve = 1)  
     288        //      { 
     289        //              sMailId += sReservedMailboxes; 
     290        //              sReservedMailboxes = reserve; 
     291        //      } 
     292 
     293        //      void Mail() { mMailbox = sMailId; } 
     294        //      bool Mailed() const { return mMailbox == sMailId; } 
     295 
     296        //      void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } 
     297        //      bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 
     298 
     299        //      int IncMail() { return ++ mMailbox - sMailId; } 
    299300 
    300301 
     
    302303        // both mailId and mailbox should be unique for each thread!!! 
    303304 
    304   //static int sMailId; 
    305   //static int sReservedMailboxes; 
    306          
    307   int GetFilteredPvsSize() const { 
    308         return mFilteredPvsSize; 
    309   } 
    310  
    311   void SetFilteredPvsSize(const int s) { 
    312         mFilteredPvsSize = s; 
     305        //static int sMailId; 
     306        //static int sReservedMailboxes; 
     307 
     308        int GetFilteredPvsSize() const  
     309        { 
     310                return mFilteredPvsSize; 
     311        } 
     312 
     313        void SetFilteredPvsSize(const int s) { 
     314                mFilteredPvsSize = s; 
    313315  } 
    314316 
     
    341343        bool mPvsSizeValid; 
    342344 
    343   /// Filter cost of the pvs 
    344   int mFilteredPvsSize; 
     345 
     346        /// Filter cost of the pvs 
     347        int mFilteredPvsSize; 
    345348 
    346349}; 
     
    356359 
    357360        ViewCellInterior(Mesh *mesh); 
    358          
     361 
    359362        /** Sets pointer from parent to child and vice versa. 
    360363        */ 
     
    368371                mCost = c; 
    369372        } 
    370          
     373 
    371374        float GetCost() const { 
    372375                return mCost; 
    373376        } 
    374    
    375   ViewCellContainer mChildren; 
     377 
     378        ViewCellContainer mChildren; 
    376379 
    377380protected: 
    378   /** overall cost resulting from the merge */ 
    379   float mCost; 
     381 
     382        /// Pverall cost resulting from the merge. 
     383        float mCost; 
    380384}; 
    381385 
     
    449453 
    450454public: 
     455 
    451456        ViewCellsTree(); 
     457 
    452458        /** View cells tree constructor taking a view cell mnanager as parameter 
    453459        */ 
     
    509515        float GetPvsCost(ViewCell *vc) const; 
    510516   
    511  
    512517        /** Returns number of entries associated with this view cell.  
    513518 
     
    587592        void ReadEnvironment(); 
    588593 
    589         ///////////////////////////////////////////////////////////////// 
    590         //                    merge related stuff                      // 
    591         ///////////////////////////////////////////////////////////////// 
     594 
     595        ////////////////////////////////////////////////////////////// 
     596        //                    merge related stuff                   // 
     597        ////////////////////////////////////////////////////////////// 
     598 
    592599 
    593600        /** Computes render cost of the merged pvs. 
     
    623630                @returns difference in pvs size 
    624631        */ 
    625         ViewCellInterior *MergeViewCells(ViewCell *l, ViewCell *r, float &pvsDiff); //const; 
     632        ViewCellInterior *MergeViewCells(ViewCell *l, ViewCell *r, float &pvsDiff); 
    626633 
    627634        /** Shuffles, i.e. takes border leaf from view cell 1 and adds it  
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1990 r1999  
    311311        // question: rather create view cells resource manager? 
    312312        if (!ViewCellsTreeConstructed()) 
    313         { 
     313        {cout << "here6" << endl; 
    314314                CLEAR_CONTAINER(mViewCells); 
    315315        } 
    316316        else 
    317         { 
     317        {cout << "here7" << endl; 
    318318                DEL_PTR(mViewCellsTree); 
    319319        } 
     
    682682        if (success) 
    683683        { 
    684                 //vm->ResetViewCells(); 
    685                 //hack 
    686                 vm->mViewCells.clear(); 
    687                 ViewCellContainer leaves; 
    688                 vm->mViewCellsTree->CollectLeaves(vm->mViewCellsTree->GetRoot(), leaves); 
    689  
    690                 ViewCellContainer::const_iterator it, it_end = leaves.end(); 
    691  
    692                 for (it = leaves.begin(); it != it_end; ++ it) 
    693                 { 
    694                         vm->mViewCells.push_back(*it); 
    695                 } 
     684                if (0) 
     685                { 
     686                        vm->ResetViewCells(); 
     687                } 
     688                else 
     689                { 
     690                        //hack: should work with reset function 
     691                        ViewCellContainer leaves; 
     692 
     693                        vm->mViewCells.clear(); 
     694                        vm->mViewCellsTree->CollectLeaves(vm->mViewCellsTree->GetRoot(), leaves); 
     695                 
     696                        ViewCellContainer::const_iterator it, it_end = leaves.end(); 
     697 
     698                        for (it = leaves.begin(); it != it_end; ++ it) 
     699                        { 
     700                                vm->mViewCells.push_back(*it); 
     701                        } 
     702                } 
     703 
    696704                vm->mViewCellsFinished = true; 
    697705                vm->mMaxPvsSize = (int)objects->size(); 
     
    29432951                                                           ) 
    29442952{ 
    2945   //cout<<"y"; 
    29462953  PvsFilterStatistics stats; 
    29472954 
     
    63876394        ViewCellsManager *vm =  
    63886395                ViewCellsManager::LoadViewCells(filename, objects, finalizeViewCells, bconverter); 
    6389 #if 0 
    6390         // insert scene objects in tree 
    6391         mOspTree->InsertObjects(mOspTree->GetRoot(), *objects); 
    6392 #endif 
     6396 
    63936397        return vm; 
    63946398} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp

    r1928 r1999  
    883883 
    884884                Debug << "exchanging boxes" << endl; 
    885 int i = 0; 
     885                int i = 0; 
    886886                // remove view cells and exchange them with the  
    887887                // view cells specialized for the current hierarchy node type 
     
    910910                        } 
    911911 
     912                        // delete old view cell 
    912913                        DEL_PTR(vc); 
     914 
    913915//                      (*vit).second = bspVc; 
    914916                        (*vit) = bspVc; 
     
    924926                mVspTree->mBoundingBox = mViewSpaceBox; 
    925927 
    926 //              ViewCellsMap::iterator vit, vit_end = mViewCells.end(); 
    927 ViewCellContainer::iterator vit, vit_end = mViewCells.end(); 
     928                // ViewCellsMap::iterator vit, vit_end = mViewCells.end(); 
     929                ViewCellContainer::iterator vit, vit_end = mViewCells.end(); 
     930 
    928931                // reset view cells using the current node type 
    929932                for (vit = mViewCells.begin(); vit != vit_end; ++ vit) 
    930933                { 
    931934                        //ViewCell *vc = (*vit).second; 
    932         ViewCell *vc = (*vit); 
     935                        ViewCell *vc = (*vit); 
     936                         
     937                        if (!vc->IsLeaf()) // exchange only leaves 
     938                                continue; 
     939 
    933940                        VspViewCell *vspVc = new VspViewCell(); 
     941 
    934942                        vspVc->SetPvs(vc->GetPvs()); 
    935943                        vspVc->SetId(vc->GetId()); 
    936  
    937                         if (!vc->IsLeaf()) // exchange only leaves 
    938                                 continue; 
    939944 
    940945                        if (vc->IsRoot()) 
     
    947952                        } 
    948953                         
    949                         //DEL_PTR(vc); 
     954                        // exchange view cell with new one 
     955                        DEL_PTR(vc); 
     956 
    950957                        //(*vit).second = vspVc; 
    951958                        (*vit) = vspVc; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h

    r1623 r1999  
    9797 // typedef map<int, ViewCell *> ViewCellsMap; 
    9898  //ViewCellsMap mViewCells; 
    99 ViewCellContainer mViewCells; 
     99  ViewCellContainer mViewCells; 
    100100 
    101101  ViewCellsManager *mViewCellsManager; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r1970 r1999  
    211211        //////////// 
    212212        //-- initialize external ray caster 
    213          
     213 
    214214        if (preprocessor->InitRayCast(externKdTree, internKdTree)) 
    215215        { 
     
    258258        } 
    259259         
    260          
     260 
    261261        bool useHwGlobalLines; 
    262262        Environment::GetSingleton()->GetBoolValue("Preprocessor.useHwGlobalLines", 
     
    272272         
    273273        preprocessor->PrepareHwGlobalLines(); 
    274  
    275274        globalLinesRenderer->Run(); 
    276275 
     
    367366        }        
    368367#endif 
     368 
    369369        // release memory 
    370370        Cleanup(); 
     371        delete pt; 
    371372 
    372373        return returnCode; 
Note: See TracChangeset for help on using the changeset viewer.