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

worked on gvs

Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/GtpVisibility05.vcproj

    r2727 r2729  
    102102                        <Tool 
    103103                                Name="VCCLCompilerTool" 
     104                                Optimization="3" 
     105                                InlineFunctionExpansion="2" 
     106                                EnableIntrinsicFunctions="true" 
     107                                FavorSizeOrSpeed="1" 
     108                                OmitFramePointers="true" 
    104109                                AdditionalIncludeDirectories="..\src;Timer;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;&quot;..\..\..\..\..\..\NonGTP\Xerces\xerces-c_2_8_0\include&quot;;..\..\..\..\..\..\NonGTP\Boost;..\src\havran;..\MultiLevelRayTracing;&quot;$(CG_INC_PATH)&quot;" 
    105110                                PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;USE_VERBOSE_PVS;USE_QT;GTP_INTERNAL;USE_CG" 
     111                                StringPooling="true" 
    106112                                RuntimeLibrary="2" 
     113                                BufferSecurityCheck="false" 
     114                                RuntimeTypeInfo="false" 
    107115                                WarningLevel="3" 
    108116                                Detect64BitPortabilityProblems="true" 
  • 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} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h

    r2728 r2729  
    146146        */ 
    147147        inline bool HandleRay(VssRay *ray); 
    148  
    149148        /** The adaptive border sampling step. It aims to find neighbouring  
    150149                triangles of the one hit by the current ray. 
    151150        */       
    152151        int AdaptiveBorderSampling(const VssRay &currentRay); 
    153          
     152        int AdaptiveBorderSamplingOpt(const VssRay &currentRay); 
    154153        /** The reverse sampling step. It is started once the cast 
    155154                ray finds a discontinuity, i.e., a closer triangle. 
     
    157156                triangle passing through a gap. 
    158157        */ 
    159         VssRay *ReverseSampling(const VssRay &currentRay, 
    160                                                         const Triangle3 &hitTriangle, 
    161                                                         const VssRay &oldRay); 
    162  
    163         bool ReverseSampling2(const VssRay &currentRay, 
    164                           const Triangle3 &hitTriangle, 
    165                                                   const VssRay &oldRay, 
    166                                                   VssRayContainer &reverseRays); 
    167  
    168         virtual void CastRays4(SimpleRayContainer &rays, 
    169                                                    VssRayContainer &vssRays); 
    170  
     158        bool ComputeReverseRay(const VssRay &currentRay, 
     159                                 const Triangle3 &hitTriangle, 
     160                                                         const VssRay &oldRay, 
     161                                                         SimpleRay &reverseRay); 
    171162        /** Returns true if we sampled a closer triangle than with the previous ray.  
    172163                Does reverse sampling if gap found. 
     
    175166                                                   const Triangle3 &hitTriangle, 
    176167                                                   const VssRay &oldRay); 
    177  
    178168        /** Adds new samples to the ray queue and classifies them 
    179169                with respect to the previous ray. 
    180170        */ 
    181171        void EnqueueRays(VssRayContainer &samples); 
    182  
    183172        /** Hepler function for adaptive border sampling. It finds  
    184173                new sample points around a triangle in a eps environment 
     
    264253 
    265254        inline void AddKdNodeToPvs(const Vector3 &termination); 
     255        /** For all rayys of the ray container, generates a ray bundle of 4 jittered rays  
     256                and casts them using optimized 4 eye ray casting. 
     257        */ 
     258        void CastRayBundles4(const SimpleRayContainer &rays, VssRayContainer &vssRays); 
     259         
     260        void CastRayBundles16(const SimpleRayContainer &rays, VssRayContainer &vssRays); 
     261 
     262        /** Generates a ray bundle of 4 jittered rays and casts them using optimized 4 eye ray casting. 
     263        */ 
     264        void CastRayBundle4(const SimpleRay &ray, VssRayContainer &vssRays, const AxisAlignedBox3 &box); 
     265        /**  Cast rays using the optimized 4 eye ray casting routine. 
     266        */ 
     267        void CastRays4(const SimpleRayContainer &rays, VssRayContainer &vssRays); 
     268        /** Wrapper for optized ray casting routine taking 4 eye rays and a bounding box for ray clipping. 
     269        */ 
     270        void Cast4Rays(float *dist, Vector3 *dirs, Vector3 *origs, VssRayContainer &vssRays, const AxisAlignedBox3 &box); 
     271 
     272        void CastRayBundle16(const SimpleRay &ray, VssRayContainer &vssRays); 
    266273 
    267274 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp

    r2710 r2729  
    8080  } 
    8181   
     82  rawCastTimer.Entry(); 
    8283  mlrtaTraverseGroupASEye4(&minBox.x, &maxBox.x, result4, dist4); 
     84  rawCastTimer.Exit(); 
    8385 
    8486  if (saveMutationRays) { 
     
    126128  float dist1, dist2; 
    127129  double normal[3]; 
     130 
     131  rawCastTimer.Entry(); 
    128132   
    129133  hittriangle = mlrtaIntersectAS( 
     
    132136                                 normal, 
    133137                                 dist); 
     138 
     139  rawCastTimer.Exit(); 
    134140  dist1 = dist; 
    135141   
     
    152158  { 
    153159    Vector3 dir = -simpleRay.mDirection; 
    154     hittriangle = mlrtaIntersectAS( 
     160 
     161        rawCastTimer.Entry(); 
     162 
     163        hittriangle = mlrtaIntersectAS( 
    155164                                   &simpleRay.mOrigin.x, 
    156165                                   &dir.x, 
    157166                                   normal, 
    158167                                   dist); 
     168         
     169        rawCastTimer.Exit(); 
     170 
    159171    dist2 = dist; 
    160172 
     
    265277    } 
    266278#endif 
     279 
    267280    mlrtaStoreRayAS16(&rays[k].mOrigin.x, 
    268281                      &rays[k].mDirection.x, 
     
    273286  Debug<<"TA\n"<<flush; 
    274287#endif 
    275    
     288  rawCastTimer.Entry(); 
     289 
    276290  mlrtaTraverseGroupAS16(&min.x, 
    277291                         &max.x, 
    278292                         forward_hit_triangles, 
    279293                         forward_dist); 
     294   
     295  rawCastTimer.Exit(); 
    280296   
    281297#if DEBUG_RAYCAST 
     
    294310    Debug<<"TB\n"<<flush; 
    295311#endif 
    296      
     312    rawCastTimer.Entry(); 
    297313    mlrtaTraverseGroupAS16(&min.x, 
    298314                           &max.x, 
    299315                           backward_hit_triangles, 
    300316                           backward_dist); 
     317 
     318        rawCastTimer.Exit(); 
    301319  } 
    302320         
     
    439457                        &rays[k].mDirection.x, 
    440458                        j); 
    441      
     459    rawCastTimer.Entry(); 
     460 
    442461    mlrtaTraverseGroupAS16(&min.x, 
    443462                           &max.x, 
    444463                           hit_triangles, 
    445464                           dist);        
     465        rawCastTimer.Exit(); 
    446466  } // for 
    447467 
     
    449469  for (; k < rays.size(); k++) { 
    450470        double normal[3]; 
     471        rawCastTimer.Entry(); 
    451472        hit_triangles[0] = mlrtaIntersectAS( 
    452473                                            &rays[k].mOrigin.x, 
     
    454475                                            normal, 
    455476                                            dist[0]); 
     477        rawCastTimer.Exit(); 
    456478  } 
    457479   
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r2726 r2729  
    11811181        { 
    11821182                const int n = 4; 
    1183                 cout << "hack: setting ray pool size to multiple " << n << " of samples per pass" << endl;        
    11841183                reserveRays = mSamplesPerPass * n; 
     1184                cout << "setting ray pool size to " << reserveRays << endl;        
     1185 
    11851186        } 
    11861187 
    11871188        cout << "======================" << endl; 
    11881189        cout << "reserving " << reserveRays << " rays " << endl; 
     1190 
    11891191        mRayCaster->ReserveVssRayPool(reserveRays); 
     1192         
    11901193        cout<<"done."<<endl<<flush; 
     1194         
    11911195        return true; 
    11921196} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h

    r2660 r2729  
    88#include "Vector3.h" 
    99#include "VssRay.h" 
    10  
    11 using namespace std; 
     10#include "Timer/PerfTimer.h" 
    1211 
    1312// 
     
    124123  SortRays2(SimpleRayContainer &rays); 
    125124   
    126   // pool of vss rays to be used in one pass of the sampling 
    127   struct VssRayPool  
    128   { 
    129     VssRayPool(): mRays(NULL), mIndex(0), mNumber(0)  
    130     {} 
    131      
    132     ~VssRayPool()  
    133     { 
    134       delete []mRays; 
    135     } 
    136      
    137     void Reserve(const int number)  
    138     { 
    139       DEL_PTR(mRays); 
    140       mRays = new VssRay[number]; 
    141       mNumber = number; 
    142     } 
    143      
    144     void Clear()  
    145     { 
    146       mIndex = 0; 
    147     } 
    148      
    149     VssRay *Alloc()  
    150     { 
    151       // reset pool 
    152       if (mIndex == mNumber) 
    153         mIndex = 0; 
    154       return mRays + mIndex ++; 
    155     } 
    156   protected: 
    157     VssRay *mRays; 
    158     int mIndex; 
    159     int mNumber; 
    160   }; 
    161  
    162  
    163   VssRayPool mVssRayPool; 
    164    
    165   void ReserveVssRayPool(const int n)  
    166   { 
    167     mVssRayPool.Reserve(n); 
    168   } 
    169    
    170   void InitPass()  
    171   { 
    172     mVssRayPool.Clear(); 
    173   } 
    174    
    175    
    176 protected: 
    177    
    178125  VssRay *RequestRay(const Vector3 &origin,  
    179126                     const Vector3 &termination,  
     
    182129                     const int pass,  
    183130                     const float pdf); 
     131   
     132  // pool of vss rays to be used in one pass of the sampling 
     133  struct VssRayPool  
     134  { 
     135    VssRayPool(): mRays(NULL), mIndex(0), mNumber(0)  
     136    {} 
     137     
     138    ~VssRayPool()  
     139    { 
     140      delete []mRays; 
     141    } 
     142     
     143    void Reserve(const int number)  
     144    { 
     145      DEL_PTR(mRays); 
     146      mRays = new VssRay[number]; 
     147      mNumber = number; 
     148    } 
     149     
     150    void Clear()  
     151    { 
     152      mIndex = 0; 
     153    } 
     154     
     155    VssRay *Alloc()  
     156    { 
     157#if 1 
     158                // reset pool 
     159                if (mIndex == mNumber)  
     160                { 
     161                        std::cerr << "warning: ray pool too small! " << std::endl; 
     162                        mIndex = 0; 
     163                } 
     164 
     165                // raypool larger index => enlarge ray pool 
     166#else 
     167                if (mNumber == mIndex) 
     168                { 
     169                        cerr << "warning: ray pool too small! " << "reserving " << mNumber * 2 << " rays" << std::endl; 
     170                        Reserve(mNumber * 2); 
     171                } 
     172#endif 
     173                return mRays + mIndex ++; 
     174    } 
     175  protected: 
     176          VssRay *mRays; 
     177          int mIndex; 
     178          int mNumber; 
     179  }; 
     180 
     181 
     182  VssRayPool mVssRayPool; 
     183   
     184  void ReserveVssRayPool(const int n)  
     185  { 
     186    mVssRayPool.Reserve(n); 
     187  } 
     188   
     189  void InitPass()  
     190  { 
     191    mVssRayPool.Clear(); 
     192  } 
     193   
     194  PerfTimer rawCastTimer; 
     195 
     196protected: 
     197   
    184198   
    185199  void _SortRays(SimpleRayContainer &rays, 
  • GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor05.vcproj

    r2725 r2729  
    104104                        InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
    105105                        CharacterSet="2" 
     106                        WholeProgramOptimization="1" 
    106107                        > 
    107108                        <Tool 
     
    123124                                Name="VCCLCompilerTool" 
    124125                                Optimization="2" 
    125                                 InlineFunctionExpansion="0" 
    126                                 EnableIntrinsicFunctions="false" 
     126                                InlineFunctionExpansion="2" 
     127                                EnableIntrinsicFunctions="true" 
    127128                                FavorSizeOrSpeed="1" 
    128                                 OmitFramePointers="false" 
    129                                 EnableFiberSafeOptimizations="false" 
     129                                OmitFramePointers="true" 
     130                                EnableFiberSafeOptimizations="true" 
    130131                                WholeProgramOptimization="true" 
    131132                                AdditionalIncludeDirectories="..\src;..\include;..\..\..\..\..\..\NonGTP\Boost;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;&quot;$(QTDIR)\include\QtOpenGl&quot;;&quot;$(QTDIR)\include\Qt&quot;;&quot;$(QTDIR)\include\QtCore&quot;;&quot;$(QTDIR)\include&quot;;QtInterface;..\src\sparsehash\src\;..\src\ootl\src\include\ootl;..\src\ootl\src\include\ootl\sandbox;$(NOINHERIT)" 
     
    135136                                ExceptionHandling="1" 
    136137                                RuntimeLibrary="2" 
     138                                BufferSecurityCheck="false" 
    137139                                EnableEnhancedInstructionSet="0" 
    138140                                RuntimeTypeInfo="false" 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r2726 r2729  
    32173217                                                           ) 
    32183218{ 
    3219  
    3220    
    3221   pvs.Reserve(viewCell->GetFilteredPvsSize()); 
     3219        pvs.Reserve(viewCell->GetFilteredPvsSize()); 
    32223220         
    32233221        PvsFilterStatistics stats; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/common.h

    r2726 r2729  
    531531#endif 
    532532 
    533 #define DYN_ERROR_STRING do {std::cout << "error: dynamic objects not supported" << endl;} while (0) 
     533#define DYN_ERROR_STRING do {std::cout << "error: dynamic objects not supported" << std::endl;} while (0) 
    534534 
    535535/** view cell id belonging to empty view space. 
Note: See TracChangeset for help on using the changeset viewer.