Changeset 1977


Ignore:
Timestamp:
01/15/07 08:37:28 (17 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
7 edited

Legend:

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

    r1976 r1977  
    8787                newRay->mFlags |= VssRay::ReverseSample; 
    8888                 
    89                 // if ray is not further processed => can delete ray 
     89                // if ray is not further processed => delete ray 
    9090                if (!HandleRay(newRay)) 
    9191                { 
     
    111111        const bool storeRaysForViz = GVS_DEBUG; 
    112112 
    113         mViewCellsManager->ComputeSampleContribution(*vssRay,  
    114                                                                                                  true,  
    115                                                                                                  storeRaysForViz); 
     113        if (!mPerViewCell) 
     114        { 
     115                mViewCellsManager->ComputeSampleContribution(*vssRay,  
     116                                                                                                         true,  
     117                                                                                                         storeRaysForViz); 
     118        } 
     119        else 
     120        { 
     121                mViewCellsManager->ComputeSampleContribution(*vssRay,  
     122                                                                                                         true,  
     123                                                                                                         mCurrentViewCell); 
     124        } 
    116125 
    117126        // some pvs contribution for this ray? 
    118         if (vssRay->mPvsContribution > 0) 
    119         { 
    120                 // add new ray to ray queue 
    121                 mRayQueue.push(vssRay); 
    122  
    123                 if (storeRaysForViz) 
    124                 { 
    125                         VssRay *nray = new VssRay(*vssRay); 
    126                         nray->mFlags = vssRay->mFlags; 
    127  
    128                         // store ray in contributing view cell 
    129                         ViewCellContainer::const_iterator vit, vit_end = vssRay->mViewCells.end(); 
    130                         for (vit = vssRay->mViewCells.begin(); vit != vit_end; ++ vit) 
    131                         {                        
    132                                 (*vit)->GetOrCreateRays()->push_back(nray);                              
    133                         } 
     127        if (!vssRay->mPvsContribution) 
     128                return false; 
     129 
     130        // add new ray to ray queue 
     131        mRayQueue.push(vssRay); 
     132 
     133        if (storeRaysForViz) 
     134        { 
     135                VssRay *nray = new VssRay(*vssRay); 
     136                nray->mFlags = vssRay->mFlags; 
     137 
     138                // store ray in contributing view cell 
     139                ViewCellContainer::const_iterator vit, vit_end = vssRay->mViewCells.end(); 
     140                for (vit = vssRay->mViewCells.begin(); vit != vit_end; ++ vit) 
     141                {                        
     142                        (*vit)->GetOrCreateRays()->push_back(nray);                              
    134143                } 
    135  
    136         ++ mGvsStats.mPassContribution; 
    137  
    138                 return true; 
    139         } 
    140  
    141         return false; 
     144        } 
     145 
     146        ++ mGvsStats.mPassContribution; 
     147 
     148        return true; 
    142149} 
    143150 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h

    r1976 r1977  
    201201        bool mPerViewCell; 
    202202        bool mOnlyRandomSampling; 
     203 
     204        ViewCell *mCurrentViewCell; 
    203205}; 
    204206 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj

    r1968 r1977  
    489489                        </File> 
    490490                        <File 
    491                                 RelativePath="..\src\Intersectable.h"> 
     491                                RelativePath=".\Intersectable.h"> 
    492492                        </File> 
    493493                        <File 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1974 r1977  
    20272027                stat.avgPvs += pvsCost; 
    20282028 
    2029                 const float pvsEntries = mViewCellsTree->GetPvsEntries(viewcell); 
     2029                const float pvsEntries = (float)mViewCellsTree->GetPvsEntries(viewcell); 
    20302030                stat.avgPvsEntries += pvsEntries; 
    20312031                 
    2032  
    20332032                if (mPerViewCellStat[i].pvsSize > 0.0f) 
    20342033                  mPerViewCellStat[i].relPvsIncrease = (pvsCost - mPerViewCellStat[i].pvsSize)/mPerViewCellStat[i].pvsSize; 
     
    22802279          } 
    22812280         
     2281} 
     2282 
     2283 
     2284float ViewCellsManager::ComputeSampleContribution(VssRay &ray, 
     2285                                                                                                  const bool addRays, 
     2286                                                                                                  ViewCell *currentViewCell) 
     2287{ 
     2288        ray.mPvsContribution = 0; 
     2289        ray.mRelativePvsContribution = 0.0f; 
     2290 
     2291        if (!ray.mTerminationObject) 
     2292                return 0.0f; 
     2293 
     2294        static Ray hray; 
     2295        hray.Init(ray); 
     2296 
     2297        float tmin = 0, tmax = 1.0; 
     2298 
     2299        if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 
     2300        { 
     2301                // cerr<<"ray outside view space box\n"; 
     2302                return 0; 
     2303        } 
     2304 
     2305        Vector3 origin = hray.Extrap(tmin); 
     2306        Vector3 termination = hray.Extrap(tmax); 
     2307 
     2308        // traverse the view space subdivision 
     2309        if (!LineSegmentIntersects(origin,  
     2310                                                           termination,  
     2311                                                           currentViewCell)) 
     2312        { 
     2313                return 0; 
     2314        } 
     2315         
     2316        // optain pvs entry (can be different from hit object) 
     2317        Intersectable *terminationObj = GetIntersectable(ray, true); 
     2318 
     2319        ComputeViewCellContribution(currentViewCell,  
     2320                                                                ray,  
     2321                                                                terminationObj,  
     2322                                                                ray.mTermination,  
     2323                                                                addRays); 
     2324         
     2325#if USE_RAY_LENGTH_AS_CONTRIBUTION 
     2326        float c = 0.0f; 
     2327        if (terminationObj)  
     2328          c = ray.Length(); 
     2329        ray.mRelativePvsContribution = ray.mPvsContribution = c; 
     2330        return c; 
     2331#else 
     2332        return ABS_CONTRIBUTION_WEIGHT*ray.mPvsContribution + 
     2333          (1.0f - ABS_CONTRIBUTION_WEIGHT)*ray.mRelativePvsContribution; 
     2334#endif 
    22822335} 
    22832336 
     
    33303383 
    33313384 
     3385bool BspViewCellsManager::LineSegmentIntersects(const Vector3 &origin,  
     3386                                                                                                const Vector3 &termination,  
     3387                                                                                                ViewCell *viewCell) 
     3388{ 
     3389        return false; 
     3390} 
     3391 
     3392 
    33323393void ViewCellsManager::ExportMergedViewCells(const ObjectContainer &objects) 
    33333394{ 
     
    43164377 
    43174378 
     4379bool KdViewCellsManager::LineSegmentIntersects(const Vector3 &origin,  
     4380                                                                                           const Vector3 &termination,  
     4381                                                                                           ViewCell *viewCell) 
     4382{ 
     4383        return false; 
     4384} 
     4385 
     4386 
    43184387void KdViewCellsManager::CreateMesh(ViewCell *vc) 
    43194388{ 
     
    50895158{ 
    50905159        return mVspBspTree->CastLineSegment(origin, termination, viewcells); 
     5160} 
     5161 
     5162 
     5163bool VspBspViewCellsManager::LineSegmentIntersects(const Vector3 &origin,  
     5164                                                                                                   const Vector3 &termination,  
     5165                                                                                                   ViewCell *viewCell) 
     5166{ 
     5167        return false; 
    50915168} 
    50925169 
     
    61056182                                                                                        ViewCellContainer &viewcells) 
    61066183{ 
    6107         return mHierarchyManager->GetVspTree()->CastLineSegment(origin, termination, viewcells); 
     6184        return mHierarchyManager-> 
     6185                GetVspTree()->CastLineSegment(origin, termination, viewcells); 
     6186} 
     6187 
     6188 
     6189bool VspOspViewCellsManager::LineSegmentIntersects(const Vector3 &origin,  
     6190                                                                                                   const Vector3 &termination,  
     6191                                                                                                   ViewCell *viewCell) 
     6192{ 
     6193        return mHierarchyManager-> 
     6194                GetVspTree()->LineSegmentIntersects(origin, termination, viewCell); 
    61086195} 
    61096196 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1974 r1977  
    156156                                                                                        const bool storeViewCells); 
    157157 
    158         //virtual void AddSampleContributions(VssRay &ray); 
     158        /** Compute sample contribution only for current view cell. 
     159        */ 
     160        virtual float ComputeSampleContribution(VssRay &ray,  
     161                                                                                        const bool addRays, 
     162                                                                                        ViewCell *currentViewCell); 
    159163 
    160164        /** Prints out statistics of the view cells. 
     
    251255                by this line segment  
    252256        */ 
    253    
    254         virtual int CastLineSegment(const Vector3 &origin, 
     257        virtual int CastLineSegment(const Vector3 &origin, 
    255258                                                          const Vector3 &termination, 
    256259                                                          ViewCellContainer &viewcells 
    257260                                                          ) = 0; 
     261 
     262        /** Tests if this line segment intersects a particular view cell. 
     263        */ 
     264        virtual bool LineSegmentIntersects(const Vector3 &origin, 
     265                                                                           const Vector3 &termination, 
     266                                                                           ViewCell *viewCell) = 0; 
    258267 
    259268        /** Returns a stats about the global pvs. 
     
    883892                                                           VssRayContainer *visRays = NULL); 
    884893 
     894        bool LineSegmentIntersects(const Vector3 &origin, 
     895                                                           const Vector3 &termination, 
     896                                                           ViewCell *viewCell); 
     897 
    885898protected: 
    886899 
     
    964977                                                           VssRayContainer *visRays = NULL); 
    965978 
     979        bool LineSegmentIntersects(const Vector3 &origin, 
     980                                                           const Vector3 &termination, 
     981                                                           ViewCell *viewCell); 
     982 
    966983protected: 
    967984 
     
    10511068 
    10521069         
     1070        bool LineSegmentIntersects(const Vector3 &origin, 
     1071                                                           const Vector3 &termination, 
     1072                                                           ViewCell *viewCell); 
     1073 
    10531074protected: 
    10541075 
     
    11171138{ 
    11181139        friend class ViewCellsParseHandlers; 
     1140 
    11191141public: 
    11201142 
     
    11361158        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const; 
    11371159 
    1138   virtual Intersectable * 
    1139   GetIntersectable(const VssRay &ray, const bool isTermination) const; 
     1160        virtual Intersectable *GetIntersectable( 
     1161                const VssRay &ray, const bool isTermination) const; 
    11401162 
    11411163        bool ViewCellsConstructed() const; 
     
    11461168                                                ViewCellContainer &viewcells); 
    11471169 
     1170        bool LineSegmentIntersects(const Vector3 &origin,  
     1171                                                           const Vector3 &termination,  
     1172                                                           ViewCell *viewCell); 
     1173 
    11481174        float GetProbability(ViewCell *viewCell); 
    11491175         
     
    11641190        void Finalize(ViewCell *viewCell, const bool createMesh); 
    11651191 
    1166         /** Stores sample contribution for kd cells or objects. 
    1167         */ 
    1168   //    virtual float ComputeSampleContribution(VssRay &ray,  
    1169   //                                                                                    const bool addRays, 
    1170   //                                                                                    const bool storeViewCells); 
    1171  
    1172         ViewCellsManager *LoadViewCells(const string &filename,  
     1192        ViewCellsManager *LoadViewCells(const string &filename,  
    11731193                                                                        ObjectContainer *objects, 
    11741194                                                                        const bool finalizeViewCells, 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r1919 r1977  
    35023502} 
    35033503 
    3504 } 
     3504 
     3505bool VspTree::LineSegmentIntersects(const Vector3 &origin,  
     3506                                                                        const Vector3 &termination,  
     3507                                                                        ViewCell *viewCell) 
     3508{ 
     3509        /*float mint = 0.0f, maxt = 1.0f; 
     3510        const Vector3 dir = termination - origin; 
     3511 
     3512        stack<LineTraversalData> tStack; 
     3513 
     3514        Vector3 entp = origin; 
     3515        Vector3 extp = termination; 
     3516 
     3517        VspNode *node = mRoot; 
     3518        VspNode *farChild; 
     3519 
     3520        float position; 
     3521        int axis; 
     3522 
     3523        while (1) 
     3524        { 
     3525                if (!node->IsLeaf()) 
     3526                { 
     3527                        VspInterior *in = dynamic_cast<VspInterior *>(node); 
     3528                        position = in->GetPosition(); 
     3529                        axis = in->GetAxis(); 
     3530 
     3531                        if (entp[axis] <= position) 
     3532                        { 
     3533                                if (extp[axis] <= position) 
     3534                                { 
     3535                                        node = in->GetBack(); 
     3536                                        // cases N1,N2,N3,P5,Z2,Z3 
     3537                                        continue; 
     3538                                } else 
     3539                                { 
     3540                                        // case N4 
     3541                                        node = in->GetBack(); 
     3542                                        farChild = in->GetFront(); 
     3543                                } 
     3544                        } 
     3545                        else 
     3546                        { 
     3547                                if (position <= extp[axis]) 
     3548                                { 
     3549                                        node = in->GetFront(); 
     3550                                        // cases P1,P2,P3,N5,Z1 
     3551                                        continue; 
     3552                                } 
     3553                                else 
     3554                                { 
     3555                                        node = in->GetFront(); 
     3556                                        farChild = in->GetBack(); 
     3557                                        // case P4 
     3558                                } 
     3559                        } 
     3560 
     3561                        // $$ modification 3.5.2004 - hints from Kamil Ghais 
     3562                        // case N4 or P4 
     3563                        const float tdist = (position - origin[axis]) / dir[axis]; 
     3564                        tStack.push(LineTraversalData(farChild, extp, maxt)); //TODO 
     3565 
     3566                        extp = origin + dir * tdist; 
     3567                        maxt = tdist; 
     3568                } 
     3569                else 
     3570                { 
     3571                        // compute intersection with all objects in this leaf 
     3572                        VspLeaf *leaf = dynamic_cast<VspLeaf *>(node); 
     3573                        ViewCell *viewCell; 
     3574                        if (0) 
     3575                                viewCell = mViewCellsTree->GetActiveViewCell(leaf->GetViewCell()); 
     3576                        else 
     3577                                viewCell = leaf->GetViewCell(); 
     3578 
     3579                        if (viewCell == currentViewCell) 
     3580                                return true; 
     3581                 
     3582                        // get the next node from the stack 
     3583                        if (tStack.empty()) 
     3584                                break; 
     3585 
     3586                        entp = extp; 
     3587                        mint = maxt; 
     3588                         
     3589                        LineTraversalData &s  = tStack.top(); 
     3590                        node = s.mNode; 
     3591                        extp = s.mExitPoint; 
     3592                        maxt = s.mMaxT; 
     3593 
     3594                        tStack.pop(); 
     3595                } 
     3596        } 
     3597*/ 
     3598        return false; 
     3599} 
     3600 
     3601 
     3602} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h

    r1913 r1977  
    701701        VspNode *SubdivideAndCopy(SplitQueue &tQueue, SubdivisionCandidate *splitCandidate); 
    702702 
     703        bool LineSegmentIntersects(const Vector3 &origin,  
     704                                                           const Vector3 &termination,  
     705                                                           ViewCell *viewCell); 
    703706protected: 
    704707 
Note: See TracChangeset for help on using the changeset viewer.