Ignore:
Timestamp:
06/02/08 04:11:30 (16 years ago)
Author:
mattausch
Message:

worked on gvs

File:
1 edited

Legend:

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

    r2728 r2729  
    159159{ 
    160160        // the predicted hitpoint: we expect to hit the same mesh again 
    161         const Vector3 predictedHit = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay); 
    162  
    163         const float predictedLen = Magnitude(predictedHit - currentRay.mOrigin); 
    164         const float len = Magnitude(currentRay.mTermination - currentRay.mOrigin); 
     161        Vector3 predictedHit = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay); 
     162 
     163        float predictedLen = Magnitude(predictedHit - currentRay.mOrigin); 
     164        float len = Magnitude(currentRay.mTermination - currentRay.mOrigin); 
    165165         
    166166        // distance large => this is likely to be a discontinuity 
    167         if ((predictedLen - len) > mThreshold)  
     167        if (!((predictedLen - len) > mThreshold)) 
    168168        // q: rather use relative distance? 
    169169        //if ((predictedLen / len) > mThreshold) 
    170         { 
    171 #if 0 
    172                 // apply reverse sampling to find the gap 
    173                 VssRay *newRay = ReverseSampling(currentRay, hitTriangle, oldRay); 
    174  
    175                 // check if reverse sampling was successful 
    176                 if (newRay) 
    177                 { 
    178                         // set flag for visualization 
    179                         if (0) newRay->mFlags |= VssRay::ReverseSample; 
    180                  
    181                         rayTimer.Entry(); 
    182                         // check if ray can be processed further 
    183                         // note: ray deletion handled by ray pool) 
    184                         HandleRay(newRay); 
    185                         rayTimer.Exit(); 
    186  
    187                         return 1; 
    188                 } 
    189 #else 
    190                 static VssRayContainer reverseRays; 
    191                 reverseRays.clear(); 
    192  
    193                 // apply reverse sampling to find the gap 
    194                 ReverseSampling2(currentRay, hitTriangle, oldRay, reverseRays); 
    195  
    196                 rayTimer.Entry(); 
    197  
    198                 int castRays = 0; 
    199                 // check if reverse sampling was successful 
    200                 for (size_t i = 0; i < reverseRays.size(); ++ i) 
    201                 { 
    202                         // check if ray can be processed further 
    203                         // note: ray deletion handled by ray pool) 
    204                         if (reverseRays[i]) 
    205                         { 
    206                                 ++ castRays; 
    207                                 HandleRay(reverseRays[i]); 
    208                         } 
    209                 } 
    210                  
    211                 rayTimer.Exit(); 
    212  
    213                 return castRays; 
    214  
    215 #endif 
    216         } 
    217  
    218         return 0; 
     170                return 0; 
     171 
     172        SimpleRay simpleRay; 
     173 
     174        // apply reverse sampling to find the gap 
     175        if (!ComputeReverseRay(currentRay, hitTriangle, oldRay, simpleRay)) 
     176                return 0; 
     177 
     178        static VssRayContainer reverseRays; 
     179        reverseRays.clear(); 
     180 
     181        if (0) 
     182        { 
     183                VssRay *reverseRay =  
     184                        mRayCaster->CastRay(simpleRay, mViewCellsManager->GetViewSpaceBox(), !mPerViewCell); 
     185 
     186                reverseRays.push_back(reverseRay); 
     187        } 
     188        else 
     189        { 
     190                if (0) 
     191                        CastRayBundle4(simpleRay, reverseRays, mViewCellsManager->GetViewSpaceBox()); 
     192                else 
     193                        CastRayBundle16(simpleRay, reverseRays); 
     194        } 
     195 
     196        mGvsStats.mReverseSamples += (int)reverseRays.size(); 
     197 
     198        EnqueueRays(reverseRays); 
     199 
     200        return (int)reverseRays.size(); 
    219201} 
    220202 
     
    422404        SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin, SamplingStrategy::GVS, 1.0f); 
    423405 
    424 #if 1 
     406        VssRay *newRay; 
     407 
     408        // cast single ray 
    425409        castTimer.Entry(); 
    426         // cast single ray to check if a triangle was missed 
    427         // note: not efficient!! 
    428         VssRay *newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox(), !mPerViewCell); 
     410 
     411        // cast single ray to check if a triangle was missed. note: not efficient!! 
     412        newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox(), !mPerViewCell); 
    429413        castTimer.Exit(); 
     414 
    430415        ++ castRays; 
    431416 
     
    440425 
    441426        rayTimer.Exit(); 
    442  
    443 #else 
    444  
    445         // cast ray into the new point 
    446         static SimpleRayContainer importanceRays; 
    447         importanceRays.clear(); 
    448  
    449         generationTimer.Entry(); 
    450  
    451          
    452         importanceRays.push_back(sray); 
    453  
    454         const int numRandomRays = 15; 
    455  
    456         GenerateJitteredRays(importanceRays, sray, numRandomRays, 0); 
    457         GenerateRays(numRandomRays, *mDistribution, importanceRays, sInvalidSamples); 
    458  
    459         generationTimer.Exit(); 
    460          
    461         // for the original implementation we don't cast double rays 
    462         const bool castDoubleRays = !mPerViewCell; 
    463         // cannot prune invalid rays because we have to compare adjacent rays 
    464         const bool pruneInvalidRays = false; 
    465  
    466         static VssRayContainer vssRays; 
    467         vssRays.clear(); 
    468  
    469         castTimer.Entry(); 
    470         CastRays(importanceRays, vssRays, castDoubleRays, pruneInvalidRays); 
    471         castTimer.Exit(); 
    472  
    473         castRays += (int)vssRays.size(); 
    474  
    475         VssRay *newRay = vssRays.empty() ? NULL : vssRays[0]; 
    476  
    477         // new triangle discovered? => add new ray to queue 
    478         rayTimer.Entry(); 
    479         for (size_t i = 0; i < vssRays.size(); ++ i) 
    480         { 
    481                 if (vssRays[i]) 
    482                         HandleRay(vssRays[i]); 
    483         } 
    484  
    485         rayTimer.Exit(); 
    486  
    487         // this ray will not be further processed 
    488         // note: ray deletion is handled by ray pool 
    489         if (!newRay) return castRays; 
    490 #endif 
    491  
     427         
    492428        //newRay->mFlags |= VssRay::BorderSample; 
    493429 
     
    516452 
    517453        //cout << "type: " << Intersectable::GetTypeName(tObj) << endl; 
    518  
    519         VertexContainer enlargedTriangle; 
    520          
     454        generationTimer.Entry(); 
     455 
     456        static VertexContainer enlargedTriangle; 
     457        enlargedTriangle.clear(); 
     458 
    521459        /// create 3 new hit points for each vertex 
    522460        EnlargeTriangle(enlargedTriangle, hitTriangle, currentRay); 
     
    525463        static SimpleRayContainer simpleRays; 
    526464        simpleRays.clear(); 
    527         //simpleRays.reserve(9); 
    528465 
    529466        VertexContainer::const_iterator vit, vit_end = enlargedTriangle.end(); 
     
    551488 
    552489        const int numRandomRays = 16 - (int)simpleRays.size(); 
    553         SimpleRay mainRay = SimpleRay(currentRay.GetOrigin(), currentRay.GetNormalizedDir(), SamplingStrategy::GVS, 1.0f); 
     490        SimpleRay mainRay = SimpleRay(currentRay.GetOrigin(),  
     491                                          currentRay.GetNormalizedDir(),  
     492                                                                  SamplingStrategy::GVS,  
     493                                                                  1.0f); 
    554494 
    555495        GenerateJitteredRays(simpleRays, mainRay, numRandomRays, 0); 
    556496        //GenerateRays(numRandomRays, *mDistribution, simpleRays, sInvalidSamples); 
    557497 
     498        generationTimer.Exit(); 
    558499 
    559500        ///////////////////// 
    560501        //-- cast rays to vertices and determine visibility 
    561502         
    562         VssRayContainer vssRays; 
     503        static VssRayContainer vssRays; 
     504        vssRays.clear(); 
    563505 
    564506        // for the original implementation we don't cast double rays 
     
    567509        const bool pruneInvalidRays = false; 
    568510 
     511        //gvsTimer.Entry(); 
    569512        castTimer.Entry(); 
     513 
    570514        CastRays(simpleRays, vssRays, castDoubleRays, pruneInvalidRays); 
     515         
    571516        castTimer.Exit(); 
     517        //gvsTimer.Exit(); 
    572518 
    573519        const int numBorderSamples = (int)vssRays.size() - numRandomRays; 
     
    576522        // handle cast rays 
    577523        EnqueueRays(vssRays); 
    578          
    579 #if 0 
    580         // set flags 
    581         VssRayContainer::const_iterator rit, rit_end = vssRays.end(); 
    582         for (rit = vssRays.begin(); rit != rit_end; ++ rit, ++ i) 
    583                 (*rit)->mFlags |= VssRay::BorderSample; 
    584 #endif 
    585  
     524 
     525        if (0) 
     526        { 
     527                // set flags 
     528                VssRayContainer::const_iterator rit, rit_end = vssRays.end(); 
     529         
     530                for (rit = vssRays.begin(); rit != rit_end; ++ rit) 
     531                        (*rit)->mFlags |= VssRay::BorderSample; 
     532        } 
    586533 
    587534    // recursivly subdivide each edge 
     
    602549 
    603550 
     551int GvsPreprocessor::AdaptiveBorderSamplingOpt(const VssRay &currentRay) 
     552{ 
     553        Intersectable *tObj = currentRay.mTerminationObject; 
     554 
     555        // question matt: can this be possible? 
     556        if (!tObj) return 0; 
     557 
     558        Triangle3 hitTriangle; 
     559 
     560        // other types not implemented yet 
     561        if (tObj->Type() == Intersectable::TRIANGLE_INTERSECTABLE) 
     562                hitTriangle = static_cast<TriangleIntersectable *>(tObj)->GetItem(); 
     563        else 
     564                cout << "border sampling: " << Intersectable::GetTypeName(tObj) << " not yet implemented" << endl; 
     565 
     566        generationTimer.Entry(); 
     567 
     568        static VertexContainer enlargedTriangle; 
     569        enlargedTriangle.clear(); 
     570         
     571        /// create 3 new hit points for each vertex 
     572        EnlargeTriangle(enlargedTriangle, hitTriangle, currentRay); 
     573 
     574        static VertexContainer subdivEnlargedTri;        
     575        subdivEnlargedTri.clear(); 
     576 
     577        for (size_t i = 0; i < enlargedTriangle.size(); ++ i) 
     578        { 
     579                const Vector3 p1 = enlargedTriangle[i]; 
     580                const Vector3 p2 = enlargedTriangle[(i + 1) % enlargedTriangle.size()]; 
     581 
     582                // the new subdivision point 
     583                const Vector3 p = (p1 + p2) * 0.5f; 
     584 
     585                subdivEnlargedTri.push_back(p1); 
     586                subdivEnlargedTri.push_back(p); 
     587        } 
     588 
     589        /// create rays from sample points and handle them 
     590        static SimpleRayContainer simpleRays; 
     591        simpleRays.clear(); 
     592         
     593        VertexContainer::const_iterator vit, vit_end = subdivEnlargedTri.end(); 
     594 
     595        for (vit = subdivEnlargedTri.begin(); vit != vit_end; ++ vit) 
     596        { 
     597                const Vector3 rayDir = (*vit) - currentRay.GetOrigin(); 
     598 
     599                SimpleRay sr(currentRay.GetOrigin(), rayDir, SamplingStrategy::GVS, 1.0f); 
     600                simpleRays.AddRay(sr);   
     601        } 
     602 
     603         
     604        ////////// 
     605        //-- fill up simple rays with random rays so we can cast 16 rays at a time 
     606 
     607        const int numRandomRays = 16 - ((int)simpleRays.size() % 16); 
     608 
     609        SimpleRay mainRay = SimpleRay(currentRay.GetOrigin(),  
     610                                                                  currentRay.GetNormalizedDir(),  
     611                                                                  SamplingStrategy::GVS, 1.0f); 
     612 
     613        GenerateJitteredRays(simpleRays, mainRay, numRandomRays, 0); 
     614        //GenerateRays(numRandomRays, *mDistribution, simpleRays, sInvalidSamples); 
     615 
     616        generationTimer.Exit(); 
     617 
     618 
     619        ///////////////////// 
     620        //-- cast rays to vertices and determine visibility 
     621         
     622        static VssRayContainer vssRays; 
     623        vssRays.clear(); 
     624 
     625        // for the original implementation we don't cast double rays 
     626        const bool castDoubleRays = !mPerViewCell; 
     627        // cannot prune invalid rays because we have to compare adjacent rays 
     628        const bool pruneInvalidRays = false; 
     629 
     630        //if ((simpleRays.size() % 16) != 0) cerr << "ray size not aligned" << endl; 
     631         
     632        //gvsTimer.Entry(); 
     633        castTimer.Entry(); 
     634 
     635        CastRays(simpleRays, vssRays, castDoubleRays, pruneInvalidRays); 
     636         
     637        castTimer.Exit(); 
     638        //gvsTimer.Exit(); 
     639 
     640        const int numBorderSamples = (int)vssRays.size() - numRandomRays; 
     641        int castRays = (int)simpleRays.size(); 
     642 
     643        // handle cast rays 
     644        EnqueueRays(vssRays); 
     645         
     646#if 0 
     647         
     648    // recursivly subdivide each edge 
     649        for (int i = 0; i < numBorderSamples; ++ i) 
     650        { 
     651                castRays += SubdivideEdge(hitTriangle, 
     652                                                                  subdivEnlargedTri[i],  
     653                                                                  subdivEnlargedTri[(i + 1) % numBorderSamples],  
     654                                                                  *vssRays[i],  
     655                                                                  *vssRays[(i + 1) % numBorderSamples], 
     656                                                                  currentRay); 
     657        } 
     658         
     659#endif 
     660 
     661 
     662        mGvsStats.mBorderSamples += castRays; 
     663         
     664        return castRays; 
     665} 
     666 
     667 
    604668bool GvsPreprocessor::GetPassingPoint(const VssRay &currentRay, 
    605669                                                                          const Triangle3 &occluder, 
     
    607671                                                                          Vector3 &newPoint) const 
    608672{ 
    609         //-- The plane p = (xp, hit(x), hit(xold)) is intersected 
     673        ///////////////////////// 
     674        //-- We interserct the plane p = (xp, hit(x), hit(xold)) 
    610675        //-- with the newly found occluder (xold is the previous ray from 
    611676        //-- which x was generated). On the intersecting line, we select a point 
     
    619684        Vector3 pt1, pt2; 
    620685 
    621         const bool intersects = occluder.GetPlaneIntersection(plane, pt1, pt2); 
    622  
    623         if (!intersects) 
    624         { 
    625                 //cerr << "big error!! no intersection " << pt1 << " " << pt2 << endl; 
     686        if (!occluder.GetPlaneIntersection(plane, pt1, pt2)) 
    626687                return false; 
    627         } 
    628688 
    629689        // get the intersection point on the old ray 
     
    635695        // evaluate new hitpoint just outside the triangle 
    636696        // the point is chosen to be on the side closer to the original ray 
    637         if (Distance(pt1, pt3) < Distance(pt2, pt3)) 
     697        if (SqrDistance(pt1, pt3) < SqrDistance(pt2, pt3)) 
    638698                newPoint = pt1 + mEps * (pt1 - pt2); 
    639699        else 
     
    645705 
    646706 
    647 VssRay *GvsPreprocessor::ReverseSampling(const VssRay &currentRay, 
    648                                                                                  const Triangle3 &hitTriangle, 
    649                                                                                  const VssRay &oldRay) 
     707bool GvsPreprocessor::ComputeReverseRay(const VssRay &currentRay, 
     708                                                                                const Triangle3 &hitTriangle, 
     709                                                                                const VssRay &oldRay, 
     710                                                                                SimpleRay &reverseRay) 
    650711{ 
    651712        // get triangle occluding the path to the hit mesh 
     
    655716        // q: why can this happen? 
    656717        if (!tObj) 
    657                 return NULL; 
     718                return false; 
    658719 
    659720        // other types not implemented yet 
     
    668729        // q: why is there sometimes no intersecton found? 
    669730        if (!GetPassingPoint(currentRay, occluder, oldRay, newPoint)) 
    670                 return NULL; 
    671  
    672         const Vector3 predicted = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay); 
    673  
    674         Vector3 newDir, newOrigin; 
    675  
    676         ////////////// 
    677         //-- Construct the mutated ray with xnew, 
    678         //-- dir = predicted(x)- pnew as direction vector 
    679  
    680         newDir = predicted - newPoint; 
    681  
    682         // take xnew, p = intersect(viewcell, line(pnew, predicted(x)) as origin ? 
    683         // difficult to say!! 
    684         const float offset = 0.5f; 
    685         newOrigin = newPoint - newDir * offset; 
    686          
    687  
    688         ////////////// 
    689         //-- for per view cell sampling, we must check for intersection 
    690         //-- with the current view cell 
    691  
    692     if (mPerViewCell) 
    693         { 
    694                 // send ray to view cell 
    695                 static Ray ray; 
    696                 ray.Clear(); 
    697                 ray.Init(newOrigin, -newDir, Ray::LOCAL_RAY); 
    698                  
    699                 //cout << "z"; 
    700                 // check if ray intersects view cell 
    701                 if (!mCurrentViewCell->CastRay(ray)) 
    702                         return NULL; 
    703  
    704                 Ray::Intersection &hit = ray.intersections[0]; 
    705          
    706                 //cout << "q"; 
    707                 // the ray starts from the view cell 
    708                 newOrigin = ray.Extrap(hit.mT); 
    709         } 
    710  
    711         ++ mGvsStats.mReverseSamples; 
    712  
    713         const SimpleRay simpleRay(newOrigin, newDir, SamplingStrategy::GVS, 1.0f); 
    714  
    715         VssRay *reverseRay =  
    716                 mRayCaster->CastRay(simpleRay, mViewCellsManager->GetViewSpaceBox(), !mPerViewCell); 
    717  
    718         return reverseRay; 
    719 } 
    720  
    721  
    722 bool GvsPreprocessor::ReverseSampling2(const VssRay &currentRay, 
    723                                                                            const Triangle3 &hitTriangle, 
    724                                                                            const VssRay &oldRay, 
    725                                                                            VssRayContainer &reverseRays) 
    726 { 
    727         // get triangle occluding the path to the hit mesh 
    728         Triangle3 occluder; 
    729         Intersectable *tObj = currentRay.mTerminationObject; 
    730  
    731         // q: why can this happen? 
    732         if (!tObj) 
    733                 return NULL; 
    734  
    735         // other types not implemented yet 
    736         if (tObj->Type() == Intersectable::TRIANGLE_INTERSECTABLE) 
    737                 occluder = static_cast<TriangleIntersectable *>(tObj)->GetItem(); 
    738         else 
    739                 cout << "reverse sampling: " << tObj->Type() << " not yet implemented" << endl; 
    740          
    741         // get a point which is passing just outside of the occluder 
    742     Vector3 newPoint; 
    743  
    744         // q: why is there sometimes no intersecton found? 
    745         if (!GetPassingPoint(currentRay, occluder, oldRay, newPoint)) 
    746                 return NULL; 
     731                return false; 
    747732 
    748733        const Vector3 predicted = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay); 
     
    784769        } 
    785770 
    786         static SimpleRayContainer reverseSimpleRays; 
    787         reverseSimpleRays.clear(); 
    788  
    789         SimpleRay mainRay = SimpleRay(newOrigin, newDir, SamplingStrategy::GVS, 1.0f); 
    790  
    791         reverseSimpleRays.push_back(mainRay); 
    792         GenerateJitteredRays(reverseSimpleRays, mainRay, 15, 0); 
    793  
    794         castTimer.Entry(); 
    795         CastRays(reverseSimpleRays, reverseRays, false, false); 
    796         castTimer.Exit(); 
    797  
    798         mGvsStats.mReverseSamples += (int)reverseRays.size(); 
     771        reverseRay = SimpleRay(newOrigin, newDir, SamplingStrategy::GVS, 1.0f); 
    799772 
    800773        return true; 
     
    818791 
    819792        // cast generated samples  
    820         static VssRayContainer samples; 
    821         samples.clear(); 
    822  
    823         const bool castDoubleRays = !mPerViewCell; 
    824         const bool pruneInvalidRays = true; 
    825          
    826 #if 0 
     793        static VssRayContainer vssRays; 
     794        vssRays.clear(); 
     795 
    827796        castTimer.Entry(); 
    828797 
    829         CastRays(simpleRays, samples, castDoubleRays, pruneInvalidRays); 
    830          
     798        if (0) 
     799        { 
     800                const bool castDoubleRays = !mPerViewCell; 
     801                const bool pruneInvalidRays = false; 
     802                //const bool pruneInvalidRays = true; 
     803                CastRays(simpleRays, vssRays, castDoubleRays, pruneInvalidRays); 
     804        } 
     805        else 
     806        { 
     807                if (0) 
     808                        // casting bundles of 4 rays generated from the simple rays 
     809                        CastRayBundles4(simpleRays, vssRays); 
     810                else 
     811                        CastRayBundles16(simpleRays, vssRays); 
     812        } 
     813 
    831814        castTimer.Exit(); 
    832815 
    833 #else 
    834         static SimpleRayContainer jitteredRays; 
    835  
    836         for (size_t i = 0; i < simpleRays.size(); ++ i) 
    837         { 
    838                 SimpleRay mainRay = simpleRays[i]; 
    839                  
    840                 jitteredRays.clear(); 
    841                 jitteredRays.push_back(mainRay); 
    842  
    843                 generationTimer.Entry(); 
    844  
    845                 GenerateJitteredRays(jitteredRays, mainRay, 15, 0); 
    846  
    847                 generationTimer.Exit(); 
    848                 castTimer.Entry(); 
    849  
    850                 CastRays(jitteredRays, samples, castDoubleRays, pruneInvalidRays); 
    851  
    852                 castTimer.Entry(); 
    853         } 
    854 #endif 
    855  
    856816        // add to ray queue 
    857         EnqueueRays(samples); 
     817        EnqueueRays(vssRays); 
    858818 
    859819        initialTimer.Exit(); 
    860820 
    861         return (int)samples.size(); 
     821        return (int)vssRays.size(); 
    862822} 
    863823 
     
    894854                mRayQueue.pop(); 
    895855                 
    896                 castSamples += AdaptiveBorderSampling(*ray); 
     856                if (1) 
     857                        castSamples += AdaptiveBorderSampling(*ray); 
     858                else 
     859                        castSamples += AdaptiveBorderSamplingOpt(*ray); 
    897860                // note: don't have to delete because handled by ray pool 
    898861        } 
     
    976939void GvsPreprocessor::VisualizeViewCells() 
    977940{ 
    978         char str[64]; sprintf(str, "tmp/pass%06d_%04d-", mProcessedViewCells, mPass); 
     941        char str[64]; sprintf_s(str, "tmp/pass%06d_%04d-", mProcessedViewCells, mPass); 
    979942                         
    980943        // visualization 
     
    14581421        // initialise 
    14591422        mGvsStats.mPerViewCellSamples = 0; 
     1423        mGvsStats.mRandomSamples = 0; 
     1424        mGvsStats.mGvsSamples = 0; 
    14601425 
    14611426        int oldContribution = 0; 
     
    16301595        mGvsStats.mTotalSamples += mGvsStats.mPerViewCellSamples; 
    16311596 
    1632         cout << "id: " << mCurrentViewCell->GetId() << " pvs cost: "  
    1633              << mGvsStats.mPvsCost << " pvs tri: " << mTrianglePvs.size() << endl; 
     1597        cout << "id: " << mCurrentViewCell->GetId() << endl; 
     1598        cout << "pvs cost "  << mGvsStats.mPvsCost / 1000000 << " M" << endl; 
     1599        cout << "pvs tri: " << mTrianglePvs.size() << endl; 
     1600        cout << "samples: " << mGvsStats.mTotalSamples / 1000000 << " M" << endl; 
     1601        printf("contri: %f tri / K rays\n", 1000.0f * (float)mTrianglePvs.size() / mGvsStats.mTotalSamples); 
    16341602 
    16351603        //cout << "invalid samples ratio: " << (float)sInvalidSamples / mGvsStats.mPerViewCellSamples << endl; 
    16361604 
    1637         float rayTime = rayTimer.TotalTime(); 
    1638         float kdPvsTime = kdPvsTimer.TotalTime(); 
    1639         float gvsTime = gvsTimer.TotalTime(); 
    1640         float initialTime = initialTimer.TotalTime(); 
    1641         float intersectionTime = intersectionTimer.TotalTime(); 
    1642         float preparationTime = preparationTimer.TotalTime(); 
    1643         float mainLoopTime = mainLoopTimer.TotalTime(); 
    1644         float contributionTime = contributionTimer.TotalTime(); 
    1645         float castTime = castTimer.TotalTime(); 
    1646         float generationTime = generationTimer.TotalTime(); 
     1605        double rayTime = rayTimer.TotalTime(); 
     1606        double kdPvsTime = kdPvsTimer.TotalTime(); 
     1607        double gvsTime = gvsTimer.TotalTime(); 
     1608        double initialTime = initialTimer.TotalTime(); 
     1609        double intersectionTime = intersectionTimer.TotalTime(); 
     1610        double preparationTime = preparationTimer.TotalTime(); 
     1611        double mainLoopTime = mainLoopTimer.TotalTime(); 
     1612        double contributionTime = contributionTimer.TotalTime(); 
     1613        double castTime = castTimer.TotalTime(); 
     1614        double generationTime = generationTimer.TotalTime(); 
     1615        double rawCastTime = mRayCaster->rawCastTimer.TotalTime(); 
    16471616 
    16481617        cout << "handleRay              : " << rayTime << endl; 
     
    16551624        cout << "has contribution       : " << contributionTime << endl; 
    16561625        cout << "cast time              : " << castTime << endl; 
    1657         cout << "generation time       : " << generationTime << endl; 
     1626        cout << "generation time        : " << generationTime << endl; 
     1627        cout << "raw cast time          : " << rawCastTime << endl; 
    16581628 
    16591629        float randomRaysPerSec = mGvsStats.mRandomSamples / (1e6f * initialTime); 
    16601630        float gvsRaysPerSec = mGvsStats.mGvsSamples / (1e6f * gvsTime); 
     1631        float rawRaysPerSec = mGvsStats.mPerViewCellSamples / (1e6f * rawCastTime); 
    16611632 
    16621633        cout << "cast " << randomRaysPerSec << " M random rays/s: " << endl; 
    16631634        cout << "cast " << gvsRaysPerSec << " M gvs rays/s: " << endl; 
    1664          
     1635        cout << "cast " << rawRaysPerSec << " M raw rays/s: " << endl; 
     1636 
    16651637        mGvsStats.Stop(); 
    16661638        mGvsStats.Print(mGvsStatsStream); 
    1667  
    1668 } 
    1669  
     1639} 
    16701640 
    16711641 
     
    17071677 
    17081678                mTrianglePvs.push_back(triObj); 
    1709                 //mDummyBuffer.push_back(mGvsStats.mGvsRuns); 
    17101679                mGenericStats[0] = (int)mTrianglePvs.size(); 
     1680 
    17111681                return true; 
    17121682        } 
     
    17161686 
    17171687 
    1718 void Preprocessor::CastRays4(SimpleRayContainer &rays, VssRayContainer &vssRays) 
    1719 { 
    1720         const int packetSize = 4; 
    1721  
    1722         static int hit_triangles[packetSize]; 
    1723         static float dist[packetSize]; 
    1724         static Vector3 dirs[packetSize]; 
    1725         static Vector3 shifts[packetSize]; 
    1726         static Vector3 origs[packetSize]; 
    1727  
     1688void GvsPreprocessor::CastRayBundles4(const SimpleRayContainer &rays, VssRayContainer &vssRays) 
     1689{ 
     1690        AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); 
    17281691 
    17291692        SimpleRayContainer::const_iterator it, it_end = rays.end(); 
    17301693 
    17311694        for (it = rays.begin(); it != it_end; ++ it) 
    1732         { 
    1733  
    1734                 SimpleRay mainRay = *it; 
    1735  
    1736                 origs[0] = mainRay.mOrigin; 
    1737                 dirs[0] = mainRay.mDirection; 
    1738  
    1739                 for (i = 1; i < packetSize; i++)  
     1695                CastRayBundle4(*it, vssRays, box); 
     1696} 
     1697 
     1698 
     1699void GvsPreprocessor::CastRayBundle4(const SimpleRay &ray,  
     1700                                                                         VssRayContainer &vssRays,  
     1701                                                                         const AxisAlignedBox3 &box) 
     1702{ 
     1703        const float pertubDir = 0.01f; 
     1704        static Vector3 pertub; 
     1705 
     1706        static int hit_triangles[4]; 
     1707        static float dist[4]; 
     1708        static Vector3 dirs[4]; 
     1709        static Vector3 origs[4]; 
     1710 
     1711        origs[0] = ray.mOrigin; 
     1712        dirs[0] = ray.mDirection; 
     1713 
     1714        for (int i = 1; i < 4; ++ i)  
     1715        { 
     1716                origs[i] = ray.mOrigin; 
     1717 
     1718                pertub.x = RandomValue(-pertubDir, pertubDir); 
     1719                pertub.y = RandomValue(-pertubDir, pertubDir); 
     1720                pertub.z = RandomValue(-pertubDir, pertubDir); 
     1721 
     1722                dirs[i] = ray.mDirection + pertub; 
     1723                dirs[i] *= 1.0f / Magnitude(dirs[i]); 
     1724        } 
     1725 
     1726        Cast4Rays(dist, dirs, origs, vssRays, box); 
     1727} 
     1728 
     1729 
     1730void GvsPreprocessor::CastRays4(const SimpleRayContainer &rays, VssRayContainer &vssRays) 
     1731{ 
     1732        SimpleRayContainer::const_iterator it, it_end = rays.end(); 
     1733         
     1734        static float dist[4]; 
     1735        static Vector3 dirs[4]; 
     1736        static Vector3 origs[4]; 
     1737 
     1738        AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); 
     1739 
     1740        for (it = rays.begin(); it != it_end; ++ it) 
     1741        { 
     1742                for (int i = 1; i < 4; ++ i)  
    17401743                { 
    1741                         origs[i] = mainRay.mOrigin; 
    1742  
    1743                         const float pertubDir = 0.01f; 
    1744                         Vector3 pertub; 
    1745  
    1746                         pertub.x = RandomValue(-pertubDir, pertubDir); 
    1747                         pertub.y = RandomValue(-pertubDir, pertubDir); 
    1748                         pertub.z = RandomValue(-pertubDir, pertubDir); 
    1749  
    1750                         dirs[i] = mainRay.mDirection + pertub; 
    1751                         const float c = Magnitude(newDir); 
    1752                         dirs{i] *= 1.0f / c; 
     1744                        origs[i] = rays[i].mOrigin; 
     1745                        dirs[i] = rays[i].mDirection; 
    17531746                } 
    1754  
    1755                 AxisAlignedBox3 box; 
    1756                 preprocessor->mRayCaster->CastRaysPacket4(box.Min(), 
    1757                                                                                                   box.Max(), 
    1758                                                                                                   origs, 
    1759                                                                                                   dirs, 
    1760                                                                                                   hit_triangles, 
    1761                                                                                                   dist);        
    1762         } 
    1763  
    1764         DeterminePvsObjects(vssRays); 
    1765 } 
    1766  
    1767  
    1768 } 
     1747        } 
     1748 
     1749        Cast4Rays(dist, dirs, origs, vssRays, box); 
     1750} 
     1751 
     1752 
     1753void GvsPreprocessor::Cast4Rays(float *dist, 
     1754                                                                Vector3 *dirs, 
     1755                                                                Vector3 *origs, 
     1756                                                                VssRayContainer &vssRays, 
     1757                                                                const AxisAlignedBox3 &box) 
     1758{ 
     1759        static int hit_triangles[4]; 
     1760 
     1761        mRayCaster->CastRaysPacket4(box.Min(), box.Max(), origs, dirs, hit_triangles,   dist);        
     1762 
     1763        VssRay *ray; 
     1764 
     1765        for (int i = 0; i < 4; ++ i) 
     1766        { 
     1767                if (hit_triangles[i] != -1) 
     1768                { 
     1769                        TriangleIntersectable *triObj = static_cast<TriangleIntersectable *>(mObjects[hit_triangles[i]]); 
     1770 
     1771                        if (DotProd(triObj->GetItem().GetNormal(), dirs[i] >= 0)) 
     1772                                ray = NULL; 
     1773                        else 
     1774                                ray = mRayCaster->RequestRay(origs[i], origs[i] + dirs[i] * dist[i], NULL, triObj, mPass, 1.0f); 
     1775                } 
     1776                else 
     1777                { 
     1778                        ray = NULL; 
     1779                } 
     1780 
     1781                vssRays.push_back(ray); 
     1782        } 
     1783} 
     1784 
     1785 
     1786void GvsPreprocessor::CastRayBundle16(const SimpleRay &ray, VssRayContainer &vssRays) 
     1787{ 
     1788        static SimpleRayContainer simpleRays; 
     1789        simpleRays.clear(); 
     1790 
     1791        simpleRays.push_back(ray); 
     1792        GenerateJitteredRays(simpleRays, ray, 15, 0); 
     1793 
     1794        CastRays(simpleRays, vssRays, false, false); 
     1795} 
     1796 
     1797 
     1798void GvsPreprocessor::CastRayBundles16(const SimpleRayContainer &rays, VssRayContainer &vssRays) 
     1799{ 
     1800        SimpleRayContainer::const_iterator it, it_end = rays.end(); 
     1801 
     1802        for (it = rays.begin(); it != it_end; ++ it) 
     1803                CastRayBundle16(*it, vssRays); 
     1804} 
     1805 
     1806} 
Note: See TracChangeset for help on using the changeset viewer.