Changeset 1990


Ignore:
Timestamp:
01/18/07 11:44:46 (17 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
21 edited

Legend:

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

    r1976 r1990  
    13201320                                        "gvs_stats=", 
    13211321                                        "gvsStats.log"); 
    1322  
    13231322         
    13241323  /**********************************************************************/ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp

    r1983 r1990  
    1515#include "KdTree.h" 
    1616 
    17 //#include <Cg/cg.h> 
    18 //#include <Cg/cgGL.h> 
    19  
     17#ifdef USE_CG 
     18 
     19#include <Cg/cg.h> 
     20#include <Cg/cgGL.h> 
     21 
     22#endif 
    2023 
    2124namespace GtpVisibilityPreprocessor { 
     
    814817GlRendererBuffer::~GlRendererBuffer() 
    815818{ 
    816 #if USE_CG 
    817   if (sCgFragmentProgram) 
     819#if 0 
     820#ifdef USE_CG 
     821        if (sCgFragmentProgram) 
    818822                cgDestroyProgram(sCgFragmentProgram); 
    819823        if (sCgContext) 
    820824                cgDestroyContext(sCgContext); 
     825#endif 
    821826#endif 
    822827} 
     
    10401045        glEnable(GL_TEXTURE_2D); 
    10411046         
    1042 #if USE_CG 
     1047#if 0 
     1048#ifdef USE_CG 
    10431049        // bind pixel shader implementing the front depth buffer functionality 
    10441050        cgGLBindProgram(sCgFragmentProgram); 
    10451051        cgGLEnableProfile(sCgFragmentProfile); 
    10461052#endif 
    1047  
     1053#endif 
    10481054        // 5. render all objects inside the beam  
    10491055        //    we can use id based false color to read them back for gaining the pvs 
     
    11731179#endif 
    11741180 
     1181        //////// 
    11751182        //-- cleanup 
    11761183 
     
    11811188        glDisable(GL_STENCIL_TEST); 
    11821189 
    1183 #if USE_CG 
     1190#if 0 
     1191#ifdef USE_CG 
    11841192        cgGLDisableProfile(sCgFragmentProfile); 
    11851193#endif 
     1194#endif 
     1195 
    11861196        glDisable(GL_TEXTURE_2D); 
    11871197 
     
    12271237void GlRendererBuffer::InitGL() 
    12281238{ 
    1229   MakeCurrent();  
    1230   GlRenderer::InitGL(); 
    1231  
    1232 #if 1 
     1239        MakeCurrent();  
     1240        GlRenderer::InitGL(); 
     1241 
    12331242        // initialise dual depth buffer textures 
    12341243        glGenTextures(1, &frontDepthMap); 
     
    12531262        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); 
    12541263 
    1255          
    1256 #if USE_CG 
     1264#if 0 
     1265#ifdef USE_CG 
     1266 
    12571267        // cg initialization 
    12581268        cgSetErrorCallback(handleCgError); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.cpp

    r1980 r1990  
    99#include "SamplingStrategy.h" 
    1010 
    11  
    1211// the devil library 
    1312#include <IL/il.h> 
     
    1514#include <IL/ilut.h> 
    1615 
     16#ifdef USE_CG 
     17 
    1718#include <Cg/cg.h> 
    1819#include <Cg/cgGL.h> 
    1920 
    20 //#include <QtOpenGL> 
    2121 
    2222namespace GtpVisibilityPreprocessor { 
     
    659659         
    660660        const float leftDist = -0.5f * mWidth + mWidth * ((float)x + 0.5f) / mTexWidth; 
    661         //const float leftDist = 0.5f * mWidth - mWidth * ((float)x + 0.5f) / mTexWidth; 
    662          
    663         const float upDist = -0.5f * mWidth + mWidth * ((float)y + 0.5f) / mTexHeight; 
    664         //const float upDist = 0.5f * mWidth - mWidth * ((float)y + 0.5f) / mTexHeight; 
     661        const float upDist   = -0.5f * mWidth + mWidth * ((float)y + 0.5f) / mTexHeight; 
    665662 
    666663        hitPoint = mViewPoint +  
     
    693690 
    694691 
    695 void GlobalLinesRenderer::ComputeBoundingQuad(float &xMin,  
    696                                                                                           float &yMin,  
    697                                                                                           float &xMax, 
    698                                                                                           float &yMax) 
     692void GlobalLinesRenderer::ComputeBoundingQuad(int &xMin,  
     693                                                                                          int &yMin,  
     694                                                                                          int &xMax, 
     695                                                                                          int &yMax) 
    699696{ 
    700697        const AxisAlignedBox3 bbox = mPreprocessor->mKdTree->GetBox(); 
     
    704701        m.Invert(); 
    705702 
    706         Vector3 eye(m.x[0][0], m.x[0][1], m.x[0][2]); 
    707         Vector3 up(m.x[1][0], m.x[1][1], m.x[1][2]); 
    708         Vector3 left(m.x[2][0], m.x[2][1], m.x[2][2]); 
     703        Vector3 eye(m.x[0][0], m.x[1][0], m.x[2][0]); 
     704        Vector3 up(m.x[0][0], m.x[1][1], m.x[2][1]); 
     705        Vector3 left(m.x[0][2], m.x[1][2], m.x[2][2]); 
    709706 
    710707        Vector3 boxMin(1e20f); 
    711708        Vector3 boxMax(-1e20f); 
    712709         
    713 /*      for (int i = 0; i < 6; ++ i) 
    714         { 
    715                 Vector3 pt; 
     710        for (int i = 0; i < 8; ++ i) 
     711        { 
     712        Vector3 vtx; 
     713 
     714                bbox.GetVertex(i, vtx); 
     715 
     716                Vector3 pt = vtx.x * eye + vtx.y * up + vtx.z * left; 
     717 
    716718                // TODO 
    717                 if (boxMin.x < pt[i].x) 
    718                         boxMin.x = pt[i].x; 
     719                if (boxMin.x > pt.x) 
     720                        boxMin.x = pt.x; 
    719721                 
    720                 if (boxMin.y < pt[i].y) 
    721                         boxMin.y = pt[i].y; 
    722  
    723                 if (boxMin.z < pt[i].z) 
    724                         boxMin.z = pt[i].z; 
    725         } 
    726 */ 
    727         xMin = boxMin.x; 
    728         yMin = boxMin.y; 
    729  
    730         xMax = boxMax.x; 
    731         yMax = boxMax.y; 
     722                if (boxMin.y > pt.y) 
     723                        boxMin.y = pt.y; 
     724 
     725                if (boxMin.z > pt.z) 
     726                        boxMin.z = pt.z; 
     727 
     728                if (boxMax.x < pt.x) 
     729                        boxMax.x = pt.x; 
     730                 
     731                if (boxMax.y < pt.y) 
     732                        boxMax.y = pt.y; 
     733 
     734                if (boxMax.z < pt.z) 
     735                        boxMax.z = pt.z; 
     736        } 
     737 
     738        cout << "xmin: " << boxMin.x << " ymin " << boxMin.y << " xmax: " << boxMax.x << " ymax: " << boxMax.y << endl; 
     739 
     740        xMin = (int)(-0.5f * mWidth + mWidth * (boxMin.x + 0.5f) / mTexWidth); 
     741        yMin = (int)(-0.5f * mWidth + mWidth * (boxMin.y + 0.5f) / mTexHeight); 
     742        xMax = (int)(-0.5f * mWidth + mWidth * (boxMax.x + 0.5f) / mTexWidth); 
     743        yMax = (int)(-0.5f * mWidth + mWidth * (boxMax.y + 0.5f) / mTexHeight); 
    732744} 
    733745 
     
    757769                } 
    758770        } 
     771 
     772        int xMin, yMin, xMax, yMax; 
     773        ComputeBoundingQuad(xMin, yMin, xMax, yMax); 
     774         
     775        cout << "xmin2: " << xMin << " ymin " << yMin << " xmax: " << xMax << " ymax: " << yMax << endl; 
    759776 
    760777        ///////////////// 
     
    10811098} 
    10821099 
    1083  
    1084 } 
     1100} 
     1101 
     1102#endif 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.h

    r1980 r1990  
    5050 
    5151 
    52         void ComputeBoundingQuad(float &xMin,  
    53                                                          float &yMin,  
    54                                                          float &xMax, 
    55                                                          float &yMax); 
     52        void ComputeBoundingQuad(int &xMin,  
     53                                                         int &yMin,  
     54                                                         int &xMax, 
     55                                                         int &yMax); 
    5656 
    5757        void InitGl(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp

    r1982 r1990  
    1010#include "Exporter.h" 
    1111#include "SamplingStrategy.h" 
     12#include "BvHierarchy.h" 
    1213 
    1314 
     
    2425}; 
    2526 
     27static const float MIN_DIST = 0.01f; 
     28 
    2629static vector<VizStruct> vizContainer; 
    2730 
    2831GvsPreprocessor::GvsPreprocessor():  
    2932Preprocessor(),  
    30 mSamplingType(SamplingStrategy::DIRECTION_BOX_BASED_DISTRIBUTION), 
     33mSamplingType(SamplingStrategy::VIEWCELL_BASED_DISTRIBUTION), 
     34//mSamplingType(SamplingStrategy::DIRECTION_BASED_DISTRIBUTION), 
    3135mNumViewCells(0), 
    3236mCurrentViewCell(NULL) 
     
    3741        Environment::GetSingleton()->GetFloatValue("GvsPreprocessor.epsilon", mEps); 
    3842        Environment::GetSingleton()->GetFloatValue("GvsPreprocessor.threshold", mThreshold);     
    39         Environment::GetSingleton()->GetBoolValue("GvsPreprocessor.UsePerViewCellSampling", mPerViewCell); 
     43        Environment::GetSingleton()->GetBoolValue("GvsPreprocessor.perViewCell", mPerViewCell); 
    4044 
    4145        char gvsStatsLog[100]; 
     
    5155        Debug << "stats: " << gvsStatsLog << endl; 
    5256 
    53         if (0) 
     57        if (1) 
     58                mOnlyRandomSampling = false;             
     59        else 
    5460                mOnlyRandomSampling = true; 
    55         else 
    56                 mOnlyRandomSampling = false; 
    5761 
    5862        mGvsStats.Reset(); 
     63} 
     64 
     65 
     66GvsPreprocessor::~GvsPreprocessor() 
     67{ 
     68        // clean ray queue 
     69        while (!mRayQueue.empty()) 
     70        { 
     71                // handle next ray 
     72                VssRay *ray = mRayQueue.top(); 
     73                mRayQueue.pop(); 
     74 
     75                delete ray; 
     76        } 
    5977} 
    6078 
     
    6583                return false; // no more view cells 
    6684 
    67         mCurrentViewCell = mViewCellsManager->GetViewCell(mNumViewCells); 
    68         mViewCellsManager->CreateMesh(mCurrentViewCell); 
     85    if (1) 
     86                mCurrentViewCell = mViewCellsManager->GetViewCell(mNumViewCells); 
     87        else 
     88        { 
     89                // HACK 
     90                int idx = (int)RandomValue(0.0f, (float)mViewCellsManager->GetNumViewCells() - 0.5f); 
     91                mCurrentViewCell = mViewCellsManager->GetViewCell(idx); 
     92        } 
     93 
     94        if (!mCurrentViewCell->GetMesh()) 
     95                mViewCellsManager->CreateMesh(mCurrentViewCell); 
    6996 
    7097        ++ mNumViewCells; 
     
    106133                        delete newRay; 
    107134                } 
    108                 else if (GVS_DEBUG && (mVssRays.size() < 9)) 
     135                else if (0 && GVS_DEBUG && (mVssRays.size() < 9)) 
    109136                { 
    110137                        mVssRays.push_back(new VssRay(oldRay)); 
     
    122149bool GvsPreprocessor::HandleRay(VssRay *vssRay) 
    123150{ 
    124         // compute the contribution to the view cells 
    125         const bool storeRaysForViz = GVS_DEBUG; 
     151        // store the rays + the intersected view cells 
     152        const bool storeRaysForViz = false; //GVS_DEBUG; 
    126153 
    127154        if (!mPerViewCell) 
     
    129156                mViewCellsManager->ComputeSampleContribution(*vssRay,  
    130157                                                                                                         true,  
    131                                                                                                          storeRaysForViz); 
     158                                                                                                         storeRaysForViz, 
     159                                                                                                         true); 
    132160        } 
    133161        else 
     
    135163                mViewCellsManager->ComputeSampleContribution(*vssRay,  
    136164                                                                                                         true,  
    137                                                                                                          mCurrentViewCell); 
     165                                                                                                         mCurrentViewCell, 
     166                                                                                                         true); 
    138167        } 
    139168 
     
    141170        if (!vssRay->mPvsContribution) 
    142171                return false; 
     172 
     173        if (GVS_DEBUG) 
     174                mVssRays.push_back(new VssRay(*vssRay)); 
    143175 
    144176        // add new ray to ray queue 
     
    158190        } 
    159191 
    160         ++ mGvsStats.mPassContribution; 
     192        ++ mGvsStats.mTotalContribution; 
    161193 
    162194        return true; 
     
    237269                                                                   const VssRay &oldRay) 
    238270{ 
     271        // cast reverse rays if necessary 
    239272        CheckDiscontinuity(ray1, hitTriangle, oldRay); 
    240273        CheckDiscontinuity(ray2, hitTriangle, oldRay); 
    241274 
    242         if (EqualVisibility(ray1, ray2) || (Magnitude(p1 - p2) <= mEps)) 
     275        if (EqualVisibility(ray1, ray2) || (Magnitude(p1 - p2) <= MIN_DIST)) 
    243276        { 
    244277                return 0; 
    245278        } 
    246         else 
    247         { 
    248                 // the new subdivision point 
    249                 const Vector3 p = (p1 + p2) * 0.5f; 
    250          
    251                 //cout << "tobj " << ray1.mTerminationObject << " " << ray2.mTerminationObject << " " << p1 << " " << p2 << endl; 
    252                 //cout << "term " << ray1.mTermination << " " << ray2.mTermination << endl; 
    253  
    254                 // cast ray into the new point 
    255                 SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin, SamplingStrategy::GVS, 1.0f); 
    256          
    257                 VssRay *newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox()); 
    258  
    259                 if (!newRay) return 0; 
    260  
    261                 newRay->mFlags |= VssRay::BorderSample; 
    262  
    263                 // add new ray to queue 
    264                 const bool enqueued = HandleRay(newRay); 
    265                  
    266                 // subdivide further 
    267                 const int samples1 = SubdivideEdge(hitTriangle, p1, p, ray1, *newRay, oldRay); 
    268                 const int samples2 = SubdivideEdge(hitTriangle, p, p2, *newRay, ray2, oldRay); 
    269                          
    270                 // this ray will not be further processed 
    271                 if (!enqueued) 
    272                         delete newRay; 
    273                  
    274                 return samples1 + samples2 + 1; 
    275         } 
     279         
     280        // the new subdivision point 
     281        const Vector3 p = (p1 + p2) * 0.5f; 
     282 
     283        // cast ray into the new point 
     284        SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin, SamplingStrategy::GVS, 1.0f); 
     285 
     286        VssRay *newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox(), mPerViewCell); 
     287 
     288        if (!newRay) return 0; 
     289 
     290        newRay->mFlags |= VssRay::BorderSample; 
     291 
     292        // add new ray to queue 
     293        const bool enqueued = HandleRay(newRay); 
     294 
     295        // subdivide further 
     296        const int samples1 = SubdivideEdge(hitTriangle, p1, p, ray1, *newRay, oldRay); 
     297        const int samples2 = SubdivideEdge(hitTriangle, p, p2, *newRay, ray2, oldRay); 
     298 
     299        // this ray will not be further processed 
     300        if (!enqueued) 
     301                delete newRay; 
     302 
     303        return samples1 + samples2 + 1; 
    276304} 
    277305 
     
    301329        simpleRays.reserve(9); 
    302330 
    303         //cout << "currentRay: " << currentRay.mOrigin << " dir: " << currentRay.GetDir() << endl; 
    304  
    305331        VertexContainer::const_iterator vit, vit_end = enlargedTriangle.end(); 
    306332 
     
    308334        { 
    309335                const Vector3 rayDir = (*vit) - currentRay.GetOrigin(); 
     336 
    310337                SimpleRay sr(currentRay.GetOrigin(), rayDir, SamplingStrategy::GVS, 1.0f); 
    311                 simpleRays.AddRay(sr); 
    312  
    313                 //cout << "new: " << sr.mOrigin << " dist: " << sr.mDirection << endl; 
     338                simpleRays.AddRay(sr);   
    314339        } 
    315340 
     
    328353        // don't cast double rays as we need only the forward rays 
    329354        const bool castDoubleRays = false; 
    330         // cannot prune invalid rays because we have to  
    331         // compare adjacent  rays. 
     355        // cannot prune invalid rays because we have to compare adjacent  rays. 
    332356        const bool pruneInvalidRays = false; 
    333357 
    334         CastRays(simpleRays, vssRays, castDoubleRays, pruneInvalidRays); 
     358        // keep origin for per view cell sampling 
     359        CastRays(simpleRays, vssRays, castDoubleRays, pruneInvalidRays, mPerViewCell); 
    335360 
    336361        // set flags 
     
    344369        EnqueueRays(vssRays); 
    345370         
    346         const int n = (int)enlargedTriangle.size(); 
    347         int castRays = (int)vssRays.size(); 
    348  
     371        const int n = (int)vssRays.size(); 
     372        int castRays = n; 
     373         
    349374    // recursivly subdivide each edge 
    350375        for (int i = 0; i < n; ++ i) 
     
    395420 
    396421        const float eps = mEps; 
     422 
    397423        // the point is chosen to be on the side closer to the original ray 
    398424        if (Distance(pt1, pt3) < Distance(pt2, pt3)) 
     
    432458        const Vector3 predicted = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay); 
    433459 
     460        Vector3 newDir, newOrigin; 
     461 
    434462        //-- Construct the mutated ray with xnew, 
    435463        //-- dir = predicted(x)- pnew as direction vector 
    436         const Vector3 newDir = predicted - newPoint; 
     464        newDir = predicted - newPoint; 
    437465 
    438466        // take xnew, p = intersect(viewcell, line(pnew, predicted(x)) as origin ? 
    439467        // difficult to say!! 
    440468        const float offset = 0.5f; 
    441         const Vector3 newOrigin = newPoint - newDir * offset; 
    442  
    443         static Ray ray(newOrigin, newDir, Ray::LOCAL_RAY); 
    444         ray.Precompute(); 
    445  
    446         // check if ray intersects view cell 
    447         if (mPerViewCell && !mCurrentViewCell->CastRay(ray)) 
    448                 return NULL; 
     469        newOrigin = newPoint - newDir * offset; 
     470         
     471        ////////////// 
     472        //-- for per view cell sampling, we must check for intersection 
     473        //-- with the current view cell 
     474 
     475    if (mPerViewCell) 
     476        { 
     477                // send ray to view cell 
     478                static Ray ray; 
     479                ray.Clear(); 
     480                ray.Init(newOrigin, -newDir, Ray::LOCAL_RAY); 
     481                //ray.Init(newOrigin, -newDir, Ray::LINE_SEGMENT); 
     482                 
     483                //cout << "z"; 
     484                // check if ray intersects view cell 
     485                if (!mCurrentViewCell->CastRay(ray)) 
     486                        return NULL; 
     487 
     488                Ray::Intersection &hit = ray.intersections[0]; 
     489         
     490                //cout << "q"; 
     491                // the ray starts from the view cell 
     492                newOrigin = ray.Extrap(hit.mT); 
     493        } 
    449494 
    450495        const SimpleRay simpleRay(newOrigin, newDir, SamplingStrategy::GVS, 1.0f); 
    451496 
    452497        VssRay *reverseRay =  
    453                 mRayCaster->CastRay(simpleRay, mViewCellsManager->GetViewSpaceBox()); 
     498                mRayCaster->CastRay(simpleRay, mViewCellsManager->GetViewSpaceBox(), mPerViewCell); 
    454499 
    455500    ++ mGvsStats.mReverseSamples; 
     
    466511        // generate simple rays 
    467512        SimpleRayContainer simpleRays; 
    468         GenerateRays(numSamples, sampleType, simpleRays); 
    469  
     513         
     514        ViewCellBasedDistribution vcStrat(*this, mCurrentViewCell); 
     515 
     516    GenerateRays(numSamples, vcStrat, simpleRays); 
     517 
     518        //cout << "sr: " << simpleRays.size() << endl; 
    470519        // generate vss rays 
    471520        VssRayContainer samples; 
    472         CastRays(simpleRays, samples, true); 
     521         
     522        const bool castDoubleRays = false; 
     523        const bool pruneInvalidRays = true; 
     524        const bool keepOrigin = mPerViewCell; 
     525 
     526        CastRays(simpleRays, samples, castDoubleRays, pruneInvalidRays, keepOrigin); 
     527         
    473528        // add to ray queue 
    474529        EnqueueRays(samples); 
    475530 
    476531        //Debug << "generated " <<  numSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    477         return (int)samples.size(); 
     532        return (int)simpleRays.size(); 
    478533} 
    479534 
     
    490545 
    491546 
    492 int GvsPreprocessor::Pass() 
    493 { 
    494         // reset samples 
    495         int castSamples = 0; 
    496         mGvsStats.mPassContribution = 0; 
    497  
    498         while (castSamples < mSamplesPerPass)  
    499         {        
    500                 // Ray queue empty =>  
    501                 // cast a number of uniform samples to fill ray queue 
    502                 castSamples += CastInitialSamples(mInitialSamples, mSamplingType); 
    503  
    504                 if (!mOnlyRandomSampling) 
    505                         castSamples += ProcessQueue(); 
    506         } 
    507  
    508         mGvsStats.mTotalContribution += mGvsStats.mPassContribution; 
    509         return castSamples; 
    510 } 
    511  
    512  
    513547int GvsPreprocessor::ProcessQueue() 
    514548{ 
     
    516550        ++ mGvsStats.mGvsPass; 
    517551 
    518         while (!mRayQueue.empty())  
     552        while (!mRayQueue.empty()  
     553                )//&& (mGvsStats.mTotalSamples + castSamples < mTotalSamples) ) 
    519554        { 
    520555                // handle next ray 
    521556                VssRay *ray = mRayQueue.top(); 
    522557                mRayQueue.pop(); 
    523  
    524                 castSamples += AdaptiveBorderSampling(*ray); 
     558                if (!ray) cout << "Error!!!!!" << endl; 
     559                const int newSamples = AdaptiveBorderSampling(*ray); 
     560 
     561                castSamples += newSamples; 
     562 
     563                //cout << newSamples << " ";     
    525564                delete ray; 
    526565        } 
    527          
     566 
    528567        return castSamples; 
    529568} 
    530569 
    531570 
    532 void GvsPreprocessor::VisualizeViewCells() 
    533 { 
    534         char str[64]; sprintf(str, "tmp/pass%06d_%04d-", mNumViewCells, mPass); 
    535                          
    536         // visualization 
    537         if (mGvsStats.mPassContribution > 0) 
    538         { 
    539                 const bool exportRays = true; 
    540                 const bool exportPvs = true; 
    541  
    542                 mViewCellsManager->ExportSingleViewCells(mObjects,  
    543                                                                                                  10,  
    544                                                                                                  false,  
    545                                                                                                  exportPvs,  
    546                                                                                                  exportRays,  
    547                                                                                                  1000,  
    548                                                                                                  str); 
    549         } 
    550  
    551         // remove pass samples 
    552         ViewCellContainer::const_iterator vit, vit_end = mViewCellsManager->GetViewCells().end(); 
    553  
    554         for (vit = mViewCellsManager->GetViewCells().begin(); vit != vit_end; ++ vit) 
    555         { 
    556                 (*vit)->DelRayRefs(); 
    557         } 
    558 } 
    559  
    560  
    561 void GvsPreprocessor::PerViewCellComputation() 
    562 { 
    563         const int maxViewCells = 5; 
    564  
    565         while (NextViewCell() && mNumViewCells < maxViewCells) 
    566         { 
    567                 cout << "processing view cell " << mNumViewCells << endl; 
    568  
    569                 while (mGvsStats.mTotalSamples < mTotalSamples)  
    570                 { 
    571                         ++ mPass; 
    572  
    573                         mGvsStats.mTotalSamples += Pass(); 
    574                                  
    575                         //////// 
    576                         //-- stats 
    577  
    578                         cout << "\nPass " << mPass << " #samples: " << mGvsStats.mTotalSamples  
    579                                  << " of " << mTotalSamples << endl; 
    580  
    581                         mGvsStats.mPass = mPass; 
    582                         mGvsStats.Stop(); 
    583                         mGvsStats.Print(mGvsStatsStream); 
    584                         //mViewCellsManager->PrintPvsStatistics(mGvsStats); 
    585  
    586                         if (GVS_DEBUG) 
    587                                 VisualizeViewCells(); 
    588                 } 
    589  
    590                 // ComputeRenderError(); 
    591         } 
    592 } 
    593  
    594  
    595 void GvsPreprocessor::GlobalComputation() 
    596 { 
    597         while (mGvsStats.mTotalSamples < mTotalSamples)  
    598         { 
    599                 ++ mPass; 
    600  
    601                 mGvsStats.mTotalSamples += Pass(); 
    602                                  
    603                 //////// 
    604                 //-- stats 
    605  
    606                 cout << "\nPass " << mPass << " #samples: " << mGvsStats.mTotalSamples  
    607                          << " of " << mTotalSamples << endl; 
    608  
    609                 mGvsStats.mPass = mPass; 
    610                 mGvsStats.Stop(); 
    611                 mGvsStats.Print(mGvsStatsStream); 
    612                 //mViewCellsManager->PrintPvsStatistics(mGvsStats); 
    613  
    614                 if (GVS_DEBUG) 
    615                         VisualizeViewCells(); 
    616         } 
    617 } 
    618  
    619  
    620 bool GvsPreprocessor::ComputeVisibility() 
    621 { 
    622         cout << "Gvs Preprocessor started\n" << flush; 
    623         const long startTime = GetTime(); 
    624  
    625         Randomize(0); 
    626          
    627         mGvsStats.Reset(); 
    628         mGvsStats.Start(); 
    629  
    630         if (!mLoadViewCells) 
    631         {        
    632                 /// construct the view cells from the scratch 
    633                 ConstructViewCells(); 
    634                 // reset pvs already gathered during view cells construction 
    635                 mViewCellsManager->ResetPvs(); 
    636                 cout << "finished view cell construction" << endl; 
    637         } 
    638         else if (0) 
    639         {        
    640                 //-- test successful view cells loading by exporting them again 
    641                 VssRayContainer dummies; 
    642                 mViewCellsManager->Visualize(mObjects, dummies); 
    643                 mViewCellsManager->ExportViewCells("test.xml.gz", mViewCellsManager->GetExportPvs(), mObjects); 
    644         } 
    645  
    646         mGvsStats.Stop(); 
    647         mGvsStats.Print(mGvsStatsStream); 
    648  
    649         if (mPerViewCell) 
    650         { 
    651                 PerViewCellComputation(); 
    652         } 
    653         else 
    654         { 
    655                 GlobalComputation(); 
    656         } 
    657  
    658         cout << "cast " << 2 * mGvsStats.mTotalSamples / (1e3f * TimeDiff(startTime, GetTime())) << "M rays/s" << endl; 
    659  
    660         if (GVS_DEBUG) 
    661         { 
    662                 Visualize(); 
    663                 CLEAR_CONTAINER(mVssRays); 
    664         } 
    665  
    666         return true; 
    667 } 
    668  
    669  
    670 void GvsPreprocessor::Visualize() 
    671 { 
    672         Exporter *exporter = Exporter::GetExporter("gvs.wrl"); 
    673  
    674         if (!exporter) 
    675                 return; 
    676          
    677         vector<VizStruct>::const_iterator vit, vit_end = vizContainer.end(); 
    678         for (vit = vizContainer.begin(); vit != vit_end; ++ vit) 
    679         { 
    680                 exporter->SetWireframe(); 
    681                 exporter->ExportPolygon((*vit).enlargedTriangle); 
    682                 //Material m; 
    683                 exporter->SetFilled(); 
    684                 Polygon3 poly = Polygon3((*vit).originalTriangle); 
    685                 exporter->ExportPolygon(&poly); 
    686         } 
    687  
    688         VssRayContainer::const_iterator rit, rit_end = mVssRays.end(); 
    689         for (rit = mVssRays.begin(); rit != rit_end; ++ rit) 
    690         { 
    691                 Intersectable *obj = (*rit)->mTerminationObject; 
    692                 exporter->ExportIntersectable(obj); 
    693         } 
    694  
     571void ExportVssRays(Exporter *exporter, const VssRayContainer &vssRays) 
     572{ 
    695573        VssRayContainer vcRays, vcRays2, vcRays3; 
    696574 
     575        VssRayContainer::const_iterator rit, rit_end = vssRays.end(); 
     576 
    697577        // prepare some rays for output 
    698         for (rit = mVssRays.begin(); rit != rit_end; ++ rit) 
    699         { 
    700                 const float p = RandomValue(0.0f, (float)mVssRays.size()); 
     578        for (rit = vssRays.begin(); rit != rit_end; ++ rit) 
     579        { 
     580                //const float p = RandomValue(0.0f, (float)vssRays.size()); 
     581 
    701582                if (1)//(p < raysOut) 
    702583                { 
     
    716597        } 
    717598 
    718         exporter->ExportRays(vcRays, RgbColor(1, 0, 0)); 
     599        //exporter->ExportRays(vcRays, RgbColor(1, 0, 0)); 
    719600        exporter->ExportRays(vcRays2, RgbColor(0, 1, 0)); 
    720         exporter->ExportRays(vcRays3, RgbColor(1, 1, 1)); 
    721  
    722         //exporter->ExportRays(mVssRays); 
     601        //exporter->ExportRays(vcRays3, RgbColor(1, 1, 1)); 
     602} 
     603 
     604 
     605void GvsPreprocessor::VisualizeViewCell(ViewCell *vc) 
     606{ 
     607    Intersectable::NewMail(); 
     608 
     609        Material m; 
     610         
     611        char str[64]; sprintf(str, "pass%06d.wrl", mNumViewCells); 
     612 
     613        Exporter *exporter = Exporter::GetExporter(str); 
     614        if (!exporter) 
     615                return; 
     616 
     617        ObjectPvsIterator pit = vc->GetPvs().GetIterator(); 
     618 
     619        // output PVS of view cell 
     620        while (pit.HasMoreEntries()) 
     621        {                
     622                ObjectPvsEntry entry = pit.Next(); 
     623 
     624                Intersectable *intersect = entry.mObject; 
     625                 
     626                if (intersect->Mailed()) 
     627                        continue; 
     628                 
     629                intersect->Mail(); 
     630                //m.mDiffuseColor = RgbColor(1, 0, 0); 
     631                m = RandomMaterial(); 
     632                exporter->SetForcedMaterial(m); 
     633 
     634                exporter->ExportIntersectable(intersect); 
     635        } 
     636 
     637        cout << "vssrays: " << (int)mVssRays.size() << endl; 
     638        ExportVssRays(exporter, mVssRays); 
     639 
     640        ///////////////// 
     641        //-- export view cell geometry 
     642 
     643        exporter->SetWireframe(); 
     644 
     645        m.mDiffuseColor = RgbColor(0, 1, 0); 
     646        exporter->SetForcedMaterial(m); 
     647 
     648        mViewCellsManager->ExportViewCellGeometry(exporter, vc, NULL, NULL); 
     649        //exporter->SetFilled(); 
     650 
     651        DEL_PTR(exporter); 
     652} 
     653 
     654 
     655void GvsPreprocessor::VisualizeViewCells() 
     656{ 
     657        char str[64]; sprintf(str, "tmp/pass%06d_%04d-", mNumViewCells, mPass); 
     658                         
     659        // visualization 
     660        if (mGvsStats.mPassContribution > 0) 
     661        { 
     662                const bool exportRays = true; 
     663                const bool exportPvs = true; 
     664 
     665                mViewCellsManager->ExportSingleViewCells(mObjects,  
     666                                                                                                 10,  
     667                                                                                                 false,  
     668                                                                                                 exportPvs,  
     669                                                                                                 exportRays,  
     670                                                                                                 1000,  
     671                                                                                                 str); 
     672        } 
     673 
     674        // remove pass samples 
     675        ViewCellContainer::const_iterator vit, vit_end = mViewCellsManager->GetViewCells().end(); 
     676 
     677        for (vit = mViewCellsManager->GetViewCells().begin(); vit != vit_end; ++ vit) 
     678        { 
     679                (*vit)->DelRayRefs(); 
     680        } 
     681} 
     682 
     683 
     684void GvsPreprocessor::ProcessViewCell() 
     685{ 
     686        mGvsStats.mPerViewCellSamples = 0; 
     687        int oldContribution = 0; 
     688        int passSamples = 0; 
     689 
     690        while (mGvsStats.mPerViewCellSamples < mTotalSamples)  
     691        { 
     692                // Ray queue empty =>  
     693                // cast a number of uniform samples to fill ray queue 
     694                int newSamples = CastInitialSamples(mInitialSamples, mSamplingType); 
     695 
     696                if (!mOnlyRandomSampling) 
     697                        newSamples += ProcessQueue(); 
     698 
     699                passSamples += newSamples; 
     700                mGvsStats.mPerViewCellSamples += newSamples; 
     701         
     702                if (0 && 
     703                        passSamples % (mSamplesPerPass + 1) == mSamplesPerPass) 
     704                { 
     705                        ++ mPass; 
     706 
     707                        mGvsStats.mPassContribution = mGvsStats.mTotalContribution - oldContribution; 
     708 
     709                        //////// 
     710                        //-- stats 
     711 
     712                        mGvsStats.mPass = mPass; 
     713                        mGvsStats.Stop(); 
     714                        mGvsStats.Print(mGvsStatsStream); 
     715 
     716                        //cout << "\nPass " << mPass << " #samples: " << mGvsStats.mTotalSamples << " of " << mTotalSamples << endl; 
     717 
     718                        // reset 
     719                        oldContribution = mGvsStats.mTotalContribution; 
     720                        mGvsStats.mPassContribution = 0; 
     721                        passSamples = 0; 
     722                } 
     723        } 
     724} 
     725 
     726 
     727void GvsPreprocessor::PerViewCellComputation() 
     728{ 
     729        const int maxViewCells = 25; 
     730         
     731        while (mNumViewCells < maxViewCells && NextViewCell()) 
     732        { 
     733                cout << "processing view cell " << mNumViewCells << endl; 
     734 
     735                // compute the pvs of the current view cell 
     736                ProcessViewCell(); 
     737 
     738                // exchange triangle pvs with objects 
     739                UpdatePvs(mCurrentViewCell); 
     740 
     741                if (GVS_DEBUG) 
     742                { 
     743                        VisualizeViewCell(mCurrentViewCell); 
     744                        CLEAR_CONTAINER(mVssRays); 
     745                } 
     746 
     747                //////// 
     748                //-- stats 
     749                 
     750                mGvsStats.mViewCells = mNumViewCells;//mPass; 
     751                mGvsStats.mTotalPvs += mCurrentViewCell->GetPvs().GetSize(); 
     752                mGvsStats.mTotalSamples += mGvsStats.mPerViewCellSamples; 
     753 
     754                mGvsStats.Stop(); 
     755                mGvsStats.Print(mGvsStatsStream); 
     756        } 
     757} 
     758 
     759 
     760void GvsPreprocessor::UpdatePvs(ViewCell *currentViewCell) 
     761{ 
     762        ObjectPvs newPvs; 
     763        BvhLeaf::NewMail(); 
     764 
     765        ObjectPvsIterator pit = currentViewCell->GetPvs().GetIterator(); 
     766 
     767        // output PVS of view cell 
     768        while (pit.HasMoreEntries()) 
     769        {                
     770                ObjectPvsEntry entry = pit.Next(); 
     771 
     772                Intersectable *intersect = entry.mObject; 
     773         
     774                BvhLeaf *bv = intersect->mBvhLeaf; 
     775 
     776                if (!bv || bv->Mailed()) 
     777                        continue; 
     778                 
     779                bv->Mail(); 
     780 
     781                //m.mDiffuseColor = RgbColor(1, 0, 0); 
     782                newPvs.AddSampleDirty(bv, 1.0f); 
     783        } 
     784 
     785        newPvs.SimpleSort(); 
     786 
     787        currentViewCell->SetPvs(newPvs); 
     788} 
     789 
     790 
     791void GvsPreprocessor::GlobalComputation() 
     792{ 
     793        int passSamples = 0; 
     794        int oldContribution = 0; 
     795 
     796        while (mGvsStats.mTotalSamples < mTotalSamples)  
     797        { 
     798                // Ray queue empty =>  
     799                // cast a number of uniform samples to fill ray queue 
     800                int newSamples = CastInitialSamples(mInitialSamples, mSamplingType); 
     801 
     802                if (!mOnlyRandomSampling) 
     803                        newSamples += ProcessQueue(); 
     804 
     805                passSamples += newSamples; 
     806                mGvsStats.mTotalSamples += newSamples; 
     807 
     808                if (passSamples % (mSamplesPerPass + 1) == mSamplesPerPass) 
     809                { 
     810                        ++ mPass; 
     811 
     812                        mGvsStats.mPassContribution = mGvsStats.mTotalContribution - oldContribution; 
     813 
     814                        //////// 
     815                        //-- stats 
     816 
     817                        //cout << "\nPass " << mPass << " #samples: " << mGvsStats.mTotalSamples << " of " << mTotalSamples << endl; 
     818                        mGvsStats.mPass = mPass; 
     819                        mGvsStats.Stop(); 
     820                        mGvsStats.Print(mGvsStatsStream); 
     821 
     822                        // reset 
     823                        oldContribution = mGvsStats.mTotalContribution; 
     824                        mGvsStats.mPassContribution = 0; 
     825                        passSamples = 0; 
     826 
     827                        if (GVS_DEBUG) 
     828                                VisualizeViewCells(); 
     829                } 
     830        } 
     831} 
     832 
     833 
     834bool GvsPreprocessor::ComputeVisibility() 
     835{ 
     836        cout << "Gvs Preprocessor started\n" << flush; 
     837        const long startTime = GetTime(); 
     838 
     839        //Randomize(0); 
     840         
     841        mGvsStats.Reset(); 
     842        mGvsStats.Start(); 
     843 
     844        if (!mLoadViewCells) 
     845        {        
     846                /// construct the view cells from the scratch 
     847                ConstructViewCells(); 
     848                // reset pvs already gathered during view cells construction 
     849                mViewCellsManager->ResetPvs(); 
     850                cout << "finished view cell construction" << endl; 
     851        } 
     852        else if (0) 
     853        {        
     854                //-- test successful view cells loading by exporting them again 
     855                VssRayContainer dummies; 
     856                mViewCellsManager->Visualize(mObjects, dummies); 
     857                mViewCellsManager->ExportViewCells("test.xml.gz", mViewCellsManager->GetExportPvs(), mObjects); 
     858        } 
     859 
     860        mGvsStats.Stop(); 
     861        mGvsStats.Print(mGvsStatsStream); 
     862 
     863        if (mPerViewCell) 
     864        { 
     865                PerViewCellComputation(); 
     866        } 
     867        else 
     868        { 
     869                GlobalComputation(); 
     870        } 
     871 
     872        cout << "cast " << 2 * mGvsStats.mTotalSamples / (1e3f * TimeDiff(startTime, GetTime())) << "M rays/s" << endl; 
     873 
     874        if (GVS_DEBUG) 
     875        { 
     876                Visualize(); 
     877                CLEAR_CONTAINER(mVssRays); 
     878        } 
     879 
     880        return true; 
     881} 
     882 
     883 
     884void GvsPreprocessor::Visualize() 
     885{ 
     886        Exporter *exporter = Exporter::GetExporter("gvs.wrl"); 
     887 
     888        if (!exporter) 
     889                return; 
     890         
     891        vector<VizStruct>::const_iterator vit, vit_end = vizContainer.end(); 
     892        for (vit = vizContainer.begin(); vit != vit_end; ++ vit) 
     893        { 
     894                exporter->SetWireframe(); 
     895                exporter->ExportPolygon((*vit).enlargedTriangle); 
     896                //Material m; 
     897                exporter->SetFilled(); 
     898                Polygon3 poly = Polygon3((*vit).originalTriangle); 
     899                exporter->ExportPolygon(&poly); 
     900        } 
     901 
     902        VssRayContainer::const_iterator rit, rit_end = mVssRays.end(); 
     903        for (rit = mVssRays.begin(); rit != rit_end; ++ rit) 
     904        { 
     905                Intersectable *obj = (*rit)->mTerminationObject; 
     906                exporter->ExportIntersectable(obj); 
     907        } 
     908 
     909        ExportVssRays(exporter, mVssRays); 
     910         
    723911        delete exporter; 
    724912} 
     
    735923        app << "#BorderSamples\n" << mBorderSamples << endl;             
    736924        app << "#GvsRuns\n" << mGvsPass << endl; 
    737 } 
    738  
    739  
    740 } 
     925        app << "#ViewCells\n" << mViewCells << endl; 
     926        app << "#TotalPvs\n" << mTotalPvs << endl; 
     927        app << "#PerViewCellSamples\n" << mPerViewCellSamples << endl << endl; 
     928} 
     929 
     930 
     931} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h

    r1982 r1990  
    3434                mBorderSamples = 0; 
    3535                mGvsPass = 0; 
     36 
     37                mTotalPvs = 0; 
     38                mViewCells = 0; 
     39                mPerViewCellSamples = 0; 
    3640        } 
    3741 
     
    4650        int mBorderSamples; 
    4751        int mGvsPass; 
     52         
     53        int mTotalPvs; 
     54        int mViewCells; 
     55        int mPerViewCellSamples; 
    4856                 
    4957        void Print(ostream &app) const; 
     
    6573 
    6674        GvsPreprocessor(); 
    67         ~GvsPreprocessor() {} 
     75        ~GvsPreprocessor(); 
    6876 
    6977        virtual bool ComputeVisibility(); 
     
    94102        */ 
    95103        int ProcessQueue(); 
    96  
    97         /** One pass of the sampling preprocessor.  
    98                 Continues as long as at least passSample rays have been cast. 
    99                 @returns the number of samples cast. 
    100         */ 
    101         int Pass(); 
    102104 
    103105        /** Generates the rays starting the adaptive visibility sampling process. 
     
    180182        void VisualizeViewCells(); 
    181183 
     184        void VisualizeViewCell(ViewCell *vc); 
     185 
     186        /** Exchanges view cell triangle pvs with bvh leaf pvs. 
     187        */ 
     188        void UpdatePvs(ViewCell *currentViewCell); 
     189 
     190        void ProcessViewCell(); 
    182191 
    183192        ////////////////////// 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp

    r1984 r1990  
    3838                                                        const AxisAlignedBox3 &box, 
    3939                                                        const bool castDoubleRay, 
    40                                                         const bool pruneInvalidRays 
     40                                                        const bool pruneInvalidRays, 
     41                                                        const bool keepOrigin 
    4142                                                        ) 
    4243{ 
     
    102103                                          box, 
    103104                                          castDoubleRay, 
    104                                           pruneInvalidRays 
     105                                          pruneInvalidRays, 
     106                                          keepOrigin 
    105107                                          ); 
    106108} 
     
    112114                                                                const AxisAlignedBox3 &sbox, 
    113115                                                                const bool castDoubleRay, 
    114                                                                 const bool pruneInvalidRays) 
     116                                                                const bool pruneInvalidRays, 
     117                                                                const bool keepOrigin) 
    115118{ 
    116119        int i; 
     
    227230                                   sbox, 
    228231                                   castDoubleRay, 
    229                                    pruneInvalidRays 
     232                                   pruneInvalidRays, 
     233                                   keepOrigin 
    230234                                   ); 
    231235        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.h

    r1972 r1990  
    4242                                                const AxisAlignedBox3 &box, 
    4343                                                const bool castDoubleRay, 
    44                                                 const bool pruneInvalidRays = true); 
     44                                                const bool pruneInvalidRays = true, 
     45                                                const bool keepOrigin = false); 
    4546 
    4647        virtual void CastRays16( 
     
    4950                                                        const AxisAlignedBox3 &sbox, 
    5051                                                        const bool castDoubleRay, 
    51                                                         const bool pruneInvalidRays = true); 
     52                                                        const bool pruneInvalidRays = true, 
     53                                                        const bool keepOrigin = false); 
    5254 
    5355protected: 
  • GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp

    r1984 r1990  
    2525                                                           const AxisAlignedBox3 &box, 
    2626                                                           const bool castDoubleRay, 
    27                                                            const bool pruneInvalidRays 
     27                                                           const bool pruneInvalidRays, 
     28                                                           const bool keepOrigin 
    2829                                                           ) 
    2930{ 
     
    7475                                        box, 
    7576                                        castDoubleRay, 
    76                                         pruneInvalidRays 
     77                                        pruneInvalidRays, 
     78                                        keepOrigin 
    7779                                        ); 
    7880} 
     
    196198                                                                   const AxisAlignedBox3 &sbox, 
    197199                                                                   const bool castDoubleRays, 
    198                                                                    const bool pruneInvalidRays) 
     200                                                                   const bool pruneInvalidRays, 
     201                                                                   const bool keepOrigin) 
    199202{ 
    200203#if DEBUG_RAYCAST 
     
    207210        for (sit = rays.begin(); sit != sit_end; ++ sit)  
    208211        { 
    209                 CastRay(*sit, vssRays, sbox, castDoubleRays, pruneInvalidRays); 
     212                CastRay(*sit, vssRays, sbox, castDoubleRays, pruneInvalidRays, keepOrigin); 
    210213        } 
    211214 
  • GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.h

    r1972 r1990  
    4040                                                const AxisAlignedBox3 &box, 
    4141                                                const bool castDoubleRay, 
    42                                                 const bool pruneInvalidRays = true 
     42                                                const bool pruneInvalidRays = true, 
     43                                                const bool keepOrigin = false 
    4344                                                ); 
    4445 
     
    4748                                                         const AxisAlignedBox3 &sbox, 
    4849                                                         const bool castDoubleRay, 
    49                                                          const bool pruneInvalidRays = true 
     50                                                         const bool pruneInvalidRays = true, 
     51                                                         const bool keepOrigin = false 
    5052                                                         ); 
    5153 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h

    r1877 r1990  
    129129                                           const int maxTries) = 0; 
    130130 
     131 // virtual int GetRandomPoint(Vector3 &point, 
     132//                                                       Vector3 &normal) = 0; 
     133 
    131134  virtual ostream &Describe(ostream &s) = 0; 
    132135 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp

    r1981 r1990  
    212212  int nearestFace = -1; 
    213213   
    214   if (ray.GetType() == Ray::LOCAL_RAY && ray.intersections.size()) 
     214  if (ray.GetType() == Ray::LOCAL_RAY && !ray.intersections.empty()) 
    215215    nearestT = ray.intersections[0].mT; 
    216216 
     
    230230   
    231231  if ( hits && ray.GetType() == Ray::LOCAL_RAY ) { 
    232     if (ray.intersections.size()) 
     232    if (!ray.intersections.empty()) 
    233233      ray.intersections[0] = Ray::Intersection(nearestT, 
    234                                                                                                                                                                                         nearestNormal, 
    235                                                                                                                                                                                         instance, 
    236                                                                                                                                                                                         nearestFace); 
     234                                                                                          nearestNormal, 
     235                                                                                          instance, 
     236                                                                                          nearestFace); 
    237237    else 
    238238      ray.intersections.push_back(Ray::Intersection(nearestT, 
    239                                                                                                                                                                                                                 nearestNormal, 
    240                                                                                                                                                                                                                 instance, 
    241                                                                                                                                                                                                                 nearestFace)); 
     239                                                                                                        nearestNormal, 
     240                                                                                                        instance, 
     241                                                                                                        nearestFace)); 
    242242  } 
    243243   
     
    758758{ 
    759759  int res = mMesh->CastRay(ray, this); 
     760 
    760761  return res; 
    761762} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Plane3.cpp

    r1883 r1990  
    106106                                                                 bool *coplanar) const  
    107107{ 
    108     const Vector3 v = b - a; // line from A to B 
    109     float dv = DotProd(v, mNormal); 
     108        //cout << "a: " << a << " b: " << b << endl; 
     109        const Vector3 v = b - a; // line from A to B 
     110        float dv = DotProd(v, mNormal); 
    110111     
    111112    if (signum(dv) == 0) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1984 r1990  
    211211        DEL_PTR(renderer); 
    212212        DEL_PTR(mRayCaster); 
    213  
     213#ifdef USE_CG 
    214214        DEL_PTR(mGlobalLinesRenderer); 
     215#endif 
    215216} 
    216217 
     
    10121013  return strategy.GenerateSamples(number, rays); 
    10131014} 
     1015 
    10141016 
    10151017int 
     
    11451147                                           VssRayContainer &vssRays, 
    11461148                                           const bool castDoubleRays, 
    1147                                            const bool pruneInvalidRays 
     1149                                           const bool pruneInvalidRays, 
     1150                                           const bool keepOrigin 
    11481151                                           ) 
    11491152{ 
     
    11781181        { 
    11791182                SimpleRay ray = *rit; 
     1183#ifdef USE_CG 
    11801184                // HACK: global lines must be treated special 
    11811185                if (ray.mDistribution == SamplingStrategy::HW_GLOBAL_LINES_DISTRIBUTION) 
     
    11841188                        continue; 
    11851189                } 
    1186  
     1190#endif 
    11871191                rayBucket.push_back(ray); 
    11881192 
     
    11951199                                                                   mViewCellsManager->GetViewSpaceBox(), 
    11961200                                                                   castDoubleRays, 
    1197                                                                    pruneInvalidRays); 
     1201                                                                   pruneInvalidRays, 
     1202                                                                   keepOrigin); 
    11981203 
    11991204                        rayBucket.clear(); 
     
    12101215        { 
    12111216                SimpleRay ray = *sit; 
     1217 
     1218#ifdef USE_CG 
    12121219                // HACK: global lines must be treated special 
    12131220                if (ray.mDistribution == SamplingStrategy::HW_GLOBAL_LINES_DISTRIBUTION) 
    12141221                { 
    12151222                        mGlobalLinesRenderer->CastGlobalLines(ray, vssRays); 
    1216                 } 
    1217                 else 
    1218                 { 
    1219                         mRayCaster->CastRay( 
    1220                                                                 ray, 
    1221                                                                 vssRays, 
    1222                                                                 mViewCellsManager->GetViewSpaceBox(), 
    1223                                                                 castDoubleRays, 
    1224                                                                 pruneInvalidRays); 
    1225                 } 
     1223                        continue; 
     1224                } 
     1225#endif 
     1226                mRayCaster->CastRay( 
     1227                                                        ray, 
     1228                                                        vssRays, 
     1229                                                        mViewCellsManager->GetViewSpaceBox(), 
     1230                                                        castDoubleRays, 
     1231                                                        pruneInvalidRays, 
     1232                                                        keepOrigin); 
     1233                 
    12261234        } 
    12271235 
     
    14031411        Debug << endl; 
    14041412 
     1413#ifdef USE_CG 
    14051414        globalLinesRenderer = mGlobalLinesRenderer =  
    14061415                new GlobalLinesRenderer(this, 
     
    14101419                                                                maxDepth, 
    14111420                                                                sampleReverse); 
    1412                                                                  
     1421 
    14131422        mGlobalLinesRenderer->InitGl(); 
    1414 } 
    1415  
    1416 } 
     1423 
     1424#endif 
     1425} 
     1426 
     1427} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r1968 r1990  
    145145                                                  VssRayContainer &vssRays, 
    146146                                                  const bool castDoubleRays, 
    147                                                   const bool pruneInvalidRays = true); 
     147                                                  const bool pruneInvalidRays = true, 
     148                                                  const bool keepOrigin = false); 
    148149 
    149150        /** Compute pixel error of the current PVS solution by sampling given number of viewpoints */ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp

    r1989 r1990  
    2525 
    2626VssRay *RayCaster::CastRay(const SimpleRay &simpleRay, 
    27                                                    const AxisAlignedBox3 &box) 
    28                                                    //const bool castDoubleRay)  
     27                                                   const AxisAlignedBox3 &box, 
     28                                                   const bool keepOrigin)  
    2929{ 
    3030        // note: make no sense otherwise 
    3131        const bool castDoubleRay = false; 
     32         
    3233        VssRayContainer rays; 
    33         CastRay(simpleRay, rays, box, castDoubleRay); 
     34        CastRay(simpleRay, rays, box, castDoubleRay, true, keepOrigin); 
    3435     
    3536        if (!rays.empty()) 
     
    3839                return NULL; 
    3940} 
     41 
    4042 
    4143bool 
     
    143145  _SortRays(rays, 
    144146                        0, 
    145                         rays.size()-1, 
     147                        (int)rays.size()-1, 
    146148                        0, 
    147149                        b 
     
    162164  // get the largest axis 
    163165  int offset = 0; 
     166  int i; 
    164167 
    165168  if (depth%5==0) 
    166169        offset = 3; 
    167170   
    168   for (int i=offset; i < offset+3; i++) { 
     171  for (i=offset; i < offset+3; i++) { 
    169172        float diff = box[i+6] - box[i]; 
    170173        if (diff > maxDiff) { 
     
    176179  //  cout<<depth<<" "<<axis<<endl; 
    177180   
    178   int i=l,j=r; 
     181  i=l; 
     182  int j=r; 
     183 
    179184  float x = (box[axis] + box[axis+6])*0.5f; 
    180185  //  float x = rays[(l+r)/2].GetParam(axis); 
     
    216221                                          const AxisAlignedBox3 &box, 
    217222                                          const bool castDoubleRay, 
    218                                           const bool pruneInvalidRays) 
     223                                          const bool pruneInvalidRays, 
     224                                          const bool keepOrigin) 
    219225{ 
    220226  int hits = 0; 
     
    235241        // regardless of the pruneInvalidRays setting reject rays whic degenerate to a point 
    236242        if (EpsilonEqualV3(hitA.mPoint, hitB.mPoint, Limits::Small)) { 
    237           return 0; 
     243                return 0; 
    238244        } 
    239245         
     
    277283          if (!pruneInvalidRays || hitA.mObject) { 
    278284                VssRay *vssRay = new VssRay( 
    279                                                                         clipB, 
     285                                                                        keepOrigin ? simpleRay.mOrigin : clipB, 
    280286                                                                        hitA.mPoint, 
    281287                                                                        hitB.mObject, 
     
    303309                { 
    304310                  VssRay *vssRay = new VssRay( 
    305                                                                           clipA, 
     311                                                                          keepOrigin ? simpleRay.mOrigin : clipA, 
    306312                                                                          hitB.mPoint, 
    307313                                                                          hitA.mObject, 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h

    r1984 r1990  
    4444        */ 
    4545        VssRay *CastRay(const SimpleRay &simpleRay, 
    46                                         const AxisAlignedBox3 &box); 
     46                                        const AxisAlignedBox3 &box, 
     47                                        const bool keepOrigin); 
    4748 
    4849        virtual int CastRay(const SimpleRay &simpleRay, 
     
    5051                                                const AxisAlignedBox3 &box, 
    5152                                                const bool castDoubleRay, 
    52                                                 const bool pruneInvalidRays = true 
     53                                                const bool pruneInvalidRays = true, 
     54                                                const bool keepOrigin = false 
    5355                                                ) = 0; 
    5456 
    55          virtual void CastRays16( 
     57        virtual void CastRays16( 
    5658                                                         SimpleRayContainer &rays, 
    5759                                                         VssRayContainer &vssRays, 
    5860                                                         const AxisAlignedBox3 &sbox, 
    5961                                                         const bool castDoubleRay, 
    60                                                          const bool pruneInvalidRays = true 
     62                                                         const bool pruneInvalidRays = true, 
     63                                                         const bool keepOrigin = false 
    6164                                                         ) = 0; 
    6265 
     
    98101                                   const AxisAlignedBox3 &box, 
    99102                                   const bool castDoubleRay, 
    100                                    const bool pruneInvalidRays = true); 
     103                                   const bool pruneInvalidRays = true, 
     104                                   const bool keepOrigin = false); 
    101105 
    102106        /** Checks if ray is valid. 
     
    109113                                         Intersection &hit); 
    110114 
    111   bool 
    112   ClipToViewSpaceBox(const Vector3 &origin, 
    113                                         const Vector3 &termination, 
    114                                         Vector3 &clippedOrigin, 
    115                                         Vector3 &clippedTermination); 
     115        bool 
     116                ClipToViewSpaceBox(const Vector3 &origin, 
     117                                                  const Vector3 &termination, 
     118                                                  Vector3 &clippedOrigin, 
     119                                                  Vector3 &clippedTermination); 
    116120         
    117121        const Preprocessor &mPreprocessor; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h

    r1989 r1990  
    1515struct SimpleRay; 
    1616class SimpleRayContainer; 
     17class ViewCell; 
    1718 
    1819struct VssRayContainer; 
     
    4546                GVS, 
    4647                MUTATION_BASED_DISTRIBUTION, 
    47                 HW_GLOBAL_LINES_DISTRIBUTION 
     48                HW_GLOBAL_LINES_DISTRIBUTION, 
     49                VIEWCELL_BASED_DISTRIBUTION 
    4850        }; 
    4951 
     
    257259}; 
    258260 
    259 /** This strategy generates samples inside of the objects, e.g., 
    260         for sampling the inside of a colon. 
    261 */ 
    262 /*class ObjectsInteriorDistribution: public SamplingStrategy 
    263 { 
    264  public: 
    265          ObjectsInteriorDistribution(Preprocessor &preprocessor): 
    266          SamplingStrategy(preprocessor) {} 
    267           
    268          virtual bool GenerateSample(SimpleRay &ray); 
    269 }; 
    270 */ 
     261class ViewCellBasedDistribution: public SamplingStrategy 
     262{ 
     263public: 
     264        ViewCellBasedDistribution(Preprocessor &preprocessor, ViewCell *viewCell) 
     265        : SamplingStrategy(preprocessor), mViewCell(viewCell) 
     266        { 
     267                mType = VIEWCELL_BASED_DISTRIBUTION; 
     268        } 
     269 
     270private: 
     271 
     272        virtual bool GenerateSample(SimpleRay &ray); 
     273 
     274        ViewCell *mViewCell; 
     275        static HaltonSequence sHalton; 
     276}; 
     277 
    271278 
    272279class MixtureDistribution: public SamplingStrategy  
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1989 r1990  
    16791679ViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays, 
    16801680                                                                                         const bool addRays, 
    1681                                                                                          const bool storeViewCells) 
     1681                                                                                         const bool storeViewCells, 
     1682                                                                                         const bool useHitObjects) 
    16821683{ 
    16831684  float sum = 0.0f; 
     
    16931694                  sum += (*it)->Length(); 
    16941695          } else { 
    1695                 sum += ComputeSampleContribution(*(*it), addRays, storeViewCells); 
     1696                sum += ComputeSampleContribution(*(*it), addRays, storeViewCells, useHitObjects); 
    16961697          } 
    16971698        } 
     
    22422243          { 
    22432244                // todo: maybe not correct for kd node pvs 
    2244                 if (addRays) { 
    2245                   float pdf = viewCell->GetPvs().AddSampleDirtyCheck(obj, ray.mPdf); 
    2246                   if (pdf == ray.mPdf) { 
    2247                         absContribution = 1.0f; 
    2248                         if (viewCell->GetPvs().RequiresResort())  
    2249                           viewCell->GetPvs().SimpleSort(); 
    2250                   } 
    2251                           } else { 
    2252                                 if (viewCell->GetPvs().GetSampleContribution( 
    2253                                                                                                                          obj, 
    2254                                                                                                                          ray.mPdf, 
    2255                                                                                                                          relContribution)) 
    2256                                   absContribution = 1.0f; 
    2257                           } 
     2245                if (addRays)  
     2246                { 
     2247                        float pdf = viewCell->GetPvs().AddSampleDirtyCheck(obj, ray.mPdf); 
     2248                         
     2249                        if (pdf == ray.mPdf)  
     2250                        { 
     2251                                absContribution = 1.0f; 
     2252                                if (viewCell->GetPvs().RequiresResort())  
     2253                                        viewCell->GetPvs().SimpleSort(); 
     2254                        } 
     2255                }  
     2256                else  
     2257                { 
     2258                        if (viewCell->GetPvs().GetSampleContribution( 
     2259                                                                                                                 obj, 
     2260                                                                                                                 ray.mPdf, 
     2261                                                                                                                 relContribution)) 
     2262                        { 
     2263                                absContribution = 1.0f; 
     2264                        } 
     2265                } 
     2266 
    22582267                // $$ clear the relative contribution as it is currently not correct anyway 
    22592268                relContribution = 0.0f; 
    22602269                 
    2261                 if (absContribution == 1.0f) { 
     2270                if (absContribution == 1.0f)  
     2271                { 
    22622272                  ++ ray.mPvsContribution; 
    22632273                  relContribution = 1.0f; 
     
    22972307float ViewCellsManager::ComputeSampleContribution(VssRay &ray, 
    22982308                                                                                                  const bool addRays, 
    2299                                                                                                   ViewCell *currentViewCell) 
     2309                                                                                                  ViewCell *currentViewCell, 
     2310                                                                                                  const bool useHitObjects) 
    23002311{ 
    23012312        ray.mPvsContribution = 0; 
     
    23062317 
    23072318        // optain pvs entry (can be different from hit object) 
    2308         Intersectable *terminationObj = GetIntersectable(ray, true); 
     2319        Intersectable *terminationObj; 
     2320 
     2321        if (!useHitObjects) 
     2322                terminationObj = GetIntersectable(ray, true); 
     2323        else 
     2324                terminationObj = ray.mTerminationObject; 
    23092325 
    23102326        ComputeViewCellContribution(currentViewCell,  
     
    23312347ViewCellsManager::ComputeSampleContribution(VssRay &ray, 
    23322348                                                                                        const bool addRays, 
    2333                                                                                         const bool storeViewCells) 
     2349                                                                                        const bool storeViewCells, 
     2350                                                                                        const bool useHitObjects) 
    23342351{ 
    23352352        ray.mPvsContribution = 0; 
     
    23612378        CastLineSegment(origin, termination, viewCells); 
    23622379 
    2363         mSamplesStat.mViewCells+=viewCells.size(); 
     2380        mSamplesStat.mViewCells += (int)viewCells.size(); 
    23642381 
    23652382        if (storeViewCells) 
     
    23752392        } 
    23762393 
    2377         // optain pvs entry (can be different from hit object) 
    2378         Intersectable *terminationObj = GetIntersectable(ray, true); 
     2394        Intersectable *terminationObj; 
     2395 
     2396        // obtain pvs entry (can be different from hit object) 
     2397        if (!useHitObjects) 
     2398                terminationObj = GetIntersectable(ray, true); 
     2399        else 
     2400                terminationObj = ray.mTerminationObject; 
    23792401 
    23802402        ViewCellContainer::const_iterator it = viewCells.begin(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1983 r1990  
    152152        float ComputeSampleContributions(const VssRayContainer &rays, 
    153153                                                                         const bool addContributions, 
    154                                                                          const bool storeViewCells); 
     154                                                                         const bool storeViewCells, 
     155                                                                         const bool useHitObject = false); 
    155156 
    156157        /** Computes sample contribution of a simgle ray to the view cells PVS. 
     
    162163        virtual float ComputeSampleContribution(VssRay &ray,  
    163164                                                                                        const bool addContributions, 
    164                                                                                         const bool storeViewCells); 
     165                                                                                        const bool storeViewCells, 
     166                                                                                        const bool useHitObject = false); 
    165167 
    166168        /** Compute sample contribution only for current view cell. 
     
    168170        virtual float ComputeSampleContribution(VssRay &ray,  
    169171                                                                                        const bool addContributions, 
    170                                                                                         ViewCell *currentViewCell); 
     172                                                                                        ViewCell *currentViewCell, 
     173                                                                                        const bool useHitObject = false); 
    171174 
    172175        /** Prints out statistics of the view cells. 
     
    10361039 
    10371040        bool ViewCellsConstructed() const; 
    1038  
    10391041         
    10401042        int CastLineSegment(const Vector3 &origin, 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r1977 r1990  
    468468        //mMemoryConst = (float)(sizeof(VspLeaf) + sizeof(VspViewCell)); 
    469469        //mMemoryConst = 50;//(float)(sizeof(VspViewCell)); 
    470  
    471470        //mMemoryConst = (float)(sizeof(VspLeaf) + sizeof(ObjectPvs)); 
     471 
    472472        mMemoryConst = 16;//(float)sizeof(ObjectPvs); 
    473         cout << "vsp memcost: " << mMemoryConst << endl; 
     473         
    474474 
    475475        ////////////// 
    476476        //-- debug output 
    477477 
    478         Debug << "******* VSP options ******** " << endl; 
     478        Debug << "******* VSP options ********" << endl; 
    479479 
    480480    Debug << "max depth: " << mTermMaxDepth << endl; 
     
    501501 
    502502        Debug << "vsp mem const: " << mMemoryConst << endl; 
    503  
    504         cout << "use cost heuristics: " << mUseCostHeuristics << endl; 
    505503 
    506504        Debug << endl; 
Note: See TracChangeset for help on using the changeset viewer.