Changeset 1528


Ignore:
Timestamp:
09/28/06 18:51:43 (18 years ago)
Author:
mattausch
Message:

worked on gvs

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

Legend:

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

    r1524 r1528  
    2323static vector<VizStruct> vizContainer; 
    2424 
    25 GvsPreprocessor::GvsPreprocessor(): Preprocessor(), mSamplingType(0) 
     25GvsPreprocessor::GvsPreprocessor(): Preprocessor(), mSamplingType(0), mCastPassSamples(0), mCastTotalSamples(0) 
    2626{ 
    2727        Environment::GetSingleton()->GetIntValue("GvsPreprocessor.totalSamples", mTotalSamples); 
     
    5757                VssRay *newRay = ReverseSampling(currentRay, hitTriangle, oldRay); 
    5858                if (!HandleRay(newRay)) 
     59                { 
    5960                        delete newRay; 
     61                } 
    6062 
    6163                return true; 
     
    6870bool GvsPreprocessor::HandleRay(VssRay *vssRay) 
    6971{ 
    70         const int oldContri = vssRay->mPvsContribution; 
    7172        mViewCellsManager->ComputeSampleContribution(*vssRay, true, false); 
    72  
    73          // some pvs contribution for this ray? 
    74         if ((vssRay->mPvsContribution - oldContri) > 0) 
    75         { 
    76                 //cout << "h"; 
     73                 
     74        // some pvs contribution for this ray? 
     75        if (vssRay->mPvsContribution > 0) 
     76        { 
     77                cout << " h " << mCastPassSamples << " " << mSamplesPerPass << " " << mTotalSamples << " q: " << mRayQueue.size() << endl; 
     78                 
     79                cout << "error!!! " << vssRay->mPvsContribution << " " << vssRay->mTerminationObject << endl; 
     80 
    7781                mRayQueue.push(vssRay); 
    7882                mVssRays.push_back(new VssRay(*vssRay)); 
     83                ++ mCastPassSamples; 
    7984                return true; 
    8085        } 
     
    99104        const Vector3 c = hitTriangle.mVertices[index] - hitTriangle.mVertices[indexL]; 
    100105         
    101         const float len = Magnitude(a); 
     106        const float len = 1;//Magnitude(a); 
    102107 
    103108        const Vector3 dir1 = Normalize(CrossProd(a, b)); //N((pi-xp)×(pi+1- pi)); 
     
    172177                SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin); 
    173178         
    174                 VssRay *newRay = mRayCaster->CastSingleRay(sray.mOrigin, sray.mDirection, 1, mViewSpaceBox); 
     179                VssRay *newRay = mRayCaster->CastSingleRay(sray, mViewSpaceBox); 
    175180 
    176181                if (!newRay) return 0; 
     
    217222        { 
    218223                const Vector3 rayDir = (*vit) - currentRay.GetOrigin(); 
    219                 simpleRays.push_back(SimpleRay(currentRay.GetOrigin(), rayDir)); 
     224                SimpleRay sr(currentRay.GetOrigin(), rayDir); 
     225                simpleRays.AddRay(sr); 
     226 
     227                //cout << "here244 " << (*vit) << " " << currentRay.GetOrigin() << endl; 
     228                //cout << " sr" << sr.mOrigin << sr.mDirection << endl; 
    220229        } 
    221230 
     
    228237        // cast rays to triangle vertices and determine visibility 
    229238        VssRayContainer vssRays; 
    230         CastRays(simpleRays, vssRays, false); 
    231 cout << "here211 " << simpleRays.size() << " " << vssRays.size() << endl; 
     239        CastRays(simpleRays, vssRays, false, false); 
     240        //CastRays(simpleRays, vssRays, true, true); 
     241        //cout << "here211 " << simpleRays.size() << " " << vssRays.size() << endl; 
    232242        // add to ray queue 
    233243        EnqueueRays(vssRays); 
     244         
    234245        const int n = (int)enlargedTriangle.size(); 
    235246         
    236 #if 1 
     247#if 0 
    237248    // recursivly subdivide each edge 
    238249        for (int i = 0; i < n; ++ i) 
     
    303314        SimpleRayContainer simpleRays; 
    304315        GenerateRays(numSamples, sampleType, simpleRays); 
    305          
     316 
     317        //cout << "here909 " << simpleRays.size() << endl; 
     318        //for (int i = 0; i < simpleRays.size(); ++ i) 
     319        //      cout << "here544 " << simpleRays[i].mOrigin << endl; 
    306320        // generate vss rays 
    307321        VssRayContainer samples; 
     
    310324        // add to ray queue 
    311325        EnqueueRays(samples); 
    312  
     326//for (int i = 0; i < samples.size(); ++ i) 
     327//              cout << "here1544 " << samples[i]->mOrigin << endl; 
    313328        Debug << "generated " <<  numSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    314329 
     
    331346int GvsPreprocessor::Pass() 
    332347{ 
    333         int castSamples = 0; 
    334348        const int mSampleType = 0; 
    335         while (castSamples < mSamplesPerPass)  
    336         { 
     349        // reset samples 
     350        mCastPassSamples = 0; 
     351         
     352        while (mCastPassSamples < mSamplesPerPass)  
     353        {        
    337354                // Ray queue empty =>  
    338355                // cast a number of uniform samples to fill ray Queue 
    339356                CastInitialSamples(mInitialSamples, mSampleType); 
    340  
    341                 const int gvsSamples = ProcessQueue(); 
    342 #if 0 
    343                 castSamples += gvsSamples; 
    344 #else 
    345                 castSamples += mInitialSamples; 
    346 #endif 
    347                 cout << "\nround finished, cast " << castSamples << " of " << mSamplesPerPass << endl; 
    348         } 
    349  
    350         return castSamples; 
     357                ProcessQueue(); 
     358 
     359                cout << "\nround finished, cast " << mCastPassSamples << " of " << mSamplesPerPass << endl; 
     360        } 
     361 
     362        mCastTotalSamples += mCastPassSamples; 
     363 
     364        return mCastPassSamples; 
    351365} 
    352366 
     
    361375                VssRay *ray = mRayQueue.top(); 
    362376                mRayQueue.pop(); 
    363                  
     377         
    364378                castSamples += AdaptiveBorderSampling(*ray); 
    365  
    366379                delete ray; 
    367380        } 
    368  
     381         
    369382        return castSamples; 
    370383} 
     
    385398        } 
    386399 
    387         int castSamples = 0; 
    388  
    389         while (castSamples < mTotalSamples)  
    390         { 
    391                 const int passSamples = Pass(); 
    392                 castSamples += passSamples; 
    393                  
     400        while (mCastTotalSamples < mTotalSamples)  
     401        { 
     402                Pass(); 
     403                                 
    394404                //////// 
    395405                //-- stats 
    396406                cout << "+"; 
    397                 cout << "\nsamples cast " << passSamples << " (=" << castSamples << " of " << mTotalSamples << ")" << endl; 
     407                cout << "\nsamples cast " << mCastPassSamples << " (=" << mCastTotalSamples << " of " << mTotalSamples << ")" << endl; 
    398408                //mVssRays.PrintStatistics(mStats); 
    399409                mStats << "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl 
    400                            << "#TotalSamples\n" << castSamples << endl; 
     410                           << "#TotalSamples\n" << mCastTotalSamples << endl; 
    401411 
    402412                mViewCellsManager->PrintPvsStatistics(mStats); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h

    r1522 r1528  
    129129        float mThreshold; 
    130130        VssRayContainer mVssRays; 
     131        int mCastPassSamples; 
     132        int mCastTotalSamples; 
    131133}; 
    132134 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp

    r1521 r1528  
    3232 
    3333int IntelRayCaster::CastRay( 
    34                                                         const Vector3 &viewPoint, 
    35                                                         const Vector3 &direction, 
    36                                                         const float probability, 
     34                                                        const SimpleRay &simpleRay, 
    3735                                                        VssRayContainer &vssRays, 
    3836                                                        const AxisAlignedBox3 &box, 
    39                                                         const bool castDoubleRay 
     37                                                        const bool castDoubleRay, 
     38                                                        const bool pruneInvalidRays 
    4039                                                        ) 
    4140{ 
     
    4443        int hits = 0; 
    4544        int hittriangle; 
    46         Vector3 pointA, pointB; 
    47         Vector3 normalA, normalB; 
    48         Intersectable *objectA = NULL, *objectB = NULL; 
     45        Intersection hitA, hitB; 
     46 
    4947        float dist; 
    5048        double normal[3]; 
    5149 
    5250        hittriangle = mlrtaIntersectAS( 
    53                 &viewPoint.x, 
    54                 &direction.x, 
     51                &simpleRay.mOrigin.x, 
     52                &simpleRay.mDirection.x, 
    5553                normal, 
    5654                dist); 
     
    6058                        cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl; 
    6159                else { 
    62                         objectA = mPreprocessor.mFaceParents[hittriangle].mObject; 
    63                         normalA = Vector3(normal[0], normal[1], normal[2]); 
     60                        hitA.mObject = mPreprocessor.mFaceParents[hittriangle].mObject; 
     61                        hitA.mNormal = Vector3(normal[0], normal[1], normal[2]); 
    6462                        // Get the normal of that face 
    6563                        //              Mesh *mesh = ((MeshInstance *)objectA)->GetMesh(); 
    6664                        //              normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 
    6765                        //-rays[index+i].mDirection; // $$ temporary 
    68                         pointA = viewPoint + direction*dist; 
     66                        hitA.mPoint = simpleRay.Extrap(dist); 
    6967                } 
    7068        } 
     
    7270        if (castDoubleRay) 
    7371        { 
    74                 Vector3 dir = -direction; 
     72                Vector3 dir = -simpleRay.mDirection; 
    7573                hittriangle = mlrtaIntersectAS( 
    76                         &viewPoint.x, 
     74                        &simpleRay.mOrigin.x, 
    7775                        &dir.x, 
    7876                        normal, 
     
    8482                        else  
    8583                        { 
    86                                 objectB = mPreprocessor.mFaceParents[hittriangle].mObject; 
    87                                 normalB = Vector3(normal[0], normal[1], normal[2]); 
     84                                hitB.mObject = mPreprocessor.mFaceParents[hittriangle].mObject; 
     85                                hitB.mNormal = Vector3(normal[0], normal[1], normal[2]); 
    8886                                // Get the normal of that face 
    8987                                //              Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 
    9088                                //              normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 
    9189                                //-rays[index+i].mDirection; // $$ temporary 
    92                                 pointB = viewPoint + dir * dist; 
     90                                hitB.mPoint = simpleRay.Extrap(dist); 
    9391                        } 
    9492                } 
     
    9694 
    9795        return ProcessRay( 
    98                 viewPoint, 
    99                 direction, 
    100                 objectA, pointA, normalA, 
    101                 objectB, pointB, normalB, 
    102                 probability, 
     96                simpleRay, 
     97                hitA, 
     98                hitB, 
    10399                vssRays, 
    104                 box 
     100                box, 
     101                castDoubleRay, 
     102                pruneInvalidRays 
    105103                ); 
    106104} 
     
    112110                                                                VssRayContainer &vssRays, 
    113111                                                                const AxisAlignedBox3 &sbox, 
    114                                                                 const bool castDoubleRay) 
     112                                                                const bool castDoubleRay, 
     113                                                                const bool pruneInvalidRays) 
    115114{ 
    116115        int i; 
     
    160159        for (i=0; i < num; i++)  
    161160        { 
    162                 Intersectable *objectA = NULL, *objectB = NULL; 
    163                 Vector3 pointA, pointB; 
    164                 Vector3 normalA, normalB; 
    165  
     161                Intersection hitA, hitB; 
     162                 
    166163                if (forward_hit_triangles[i] != -1 ) { 
    167164                        if (forward_hit_triangles[i] >= mPreprocessor.mFaceParents.size()) 
    168165                                cerr<<"Warning: triangle index out of range! "<<forward_hit_triangles[i]<<endl; 
    169166                        else {  
    170                                 objectA = mPreprocessor.mFaceParents[forward_hit_triangles[i]].mObject; 
     167                                hitA.mObject = mPreprocessor.mFaceParents[forward_hit_triangles[i]].mObject; 
    171168                                // Get the normal of that face 
    172                                 normalA = objectA->GetNormal(mPreprocessor.mFaceParents[forward_hit_triangles[i]].mFaceIndex); 
     169                                hitA.mNormal = hitA.mObject->GetNormal(mPreprocessor.mFaceParents[forward_hit_triangles[i]].mFaceIndex); 
    173170                                //-rays[index+i].mDirection; // $$ temporary 
    174                                 pointA = rays[index+i].Extrap(forward_dist[i]); 
     171                                hitA.mPoint = rays[index+i].Extrap(forward_dist[i]); 
    175172                        } 
    176173                } 
     
    180177                                cerr<<"Warning: triangle  index out of range! "<<backward_hit_triangles[i]<<endl; 
    181178                        else {  
    182                                 objectB = mPreprocessor.mFaceParents[backward_hit_triangles[i]].mObject; 
    183                                 normalB = objectB->GetNormal(mPreprocessor.mFaceParents[forward_hit_triangles[i]].mFaceIndex); 
     179                                hitB.mObject = mPreprocessor.mFaceParents[backward_hit_triangles[i]].mObject; 
     180                                hitB.mNormal = hitB.mObject->GetNormal(mPreprocessor.mFaceParents[forward_hit_triangles[i]].mFaceIndex); 
    184181 
    185182                                // normalB = rays[index+i].mDirection; // $$ temporary 
    186                                 pointB = rays[index+i].Extrap(-backward_dist[i]); 
     183                                hitB.mPoint = rays[index+i].Extrap(-backward_dist[i]); 
    187184                        } 
    188185                } 
    189186 
    190187                ProcessRay( 
    191                         rays[index+i].mOrigin, 
    192                         rays[index+i].mDirection, 
    193                         objectA, pointA, normalA, 
    194                         objectB, pointB, normalB, 
    195                         rays[index+i].mPdf, 
     188                        rays[index + i], 
     189                        hitA, 
     190                        hitB, 
    196191                        vssRays, 
    197                         sbox 
     192                        sbox, 
     193                        castDoubleRay, 
     194                        pruneInvalidRays 
    198195                        ); 
    199196        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.h

    r1520 r1528  
    1818struct VssRayContainer; 
    1919class Preprocessor; 
    20  
     20struct SimpleRay; 
    2121 
    2222/** This class provides an interface for ray casting. 
     
    3636 
    3737        virtual int CastRay( 
    38                 const Vector3 &viewPoint, 
    39                 const Vector3 &direction, 
    40                 const float probability, 
     38                const SimpleRay &simpleRay, 
    4139        VssRayContainer &vssRays, 
    4240                const AxisAlignedBox3 &box, 
    43                 const bool castDoubleRay 
     41                const bool castDoubleRay, 
     42                const bool pruneInvalidRays = true 
    4443                ); 
    4544 
     
    4948                 VssRayContainer &vssRays, 
    5049                 const AxisAlignedBox3 &sbox, 
    51                  const bool castDoubleRay 
     50                 const bool castDoubleRay, 
     51                 const bool pruneInvalidRays = true 
    5252                 ); 
    5353          
  • GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp

    r1521 r1528  
    2121 
    2222 
    23 int InternalRayCaster::CastRay(const Vector3 &viewPoint, 
    24                                                            const Vector3 &direction, 
    25                                                            const float probability, 
     23int InternalRayCaster::CastRay(const SimpleRay &simpleRay, 
    2624                                                           VssRayContainer &vssRays, 
    2725                                                           const AxisAlignedBox3 &box, 
    28                                                            const bool castDoubleRay 
     26                                                           const bool castDoubleRay, 
     27                                                           const bool pruneInvalidRays 
    2928                                                           ) 
    3029{ 
     
    3231        int hits = 0; 
    3332        static Ray ray; 
    34         Intersectable *objectA = NULL, *objectB = NULL; 
    35         Vector3 pointA, pointB; 
    36         Vector3 normalA, normalB; 
    37  
    38 #if 0 
    39         AxisAlignedBox3 sbox = box; 
    40         sbox.Enlarge(Vector3(-Limits::Small)); 
    41         if (!sbox.IsInside(viewPoint)) 
    42                 return 0; 
    43 #endif 
    44  
    45         mPreprocessor.SetupRay(ray, viewPoint, direction); 
     33        Intersection hitA(simpleRay.mOrigin), hitB(simpleRay.mOrigin); 
     34         
     35        mPreprocessor.SetupRay(ray, simpleRay.mOrigin, simpleRay.mDirection); 
    4636        ray.mFlags &= ~Ray::CULL_BACKFACES; 
    4737 
    4838        if (mKdTree->CastRay(ray))  
    4939        { 
    50                 objectA = ray.intersections[0].mObject; 
    51                 pointA = ray.Extrap(ray.intersections[0].mT); 
    52                 normalA = ray.intersections[0].mNormal; 
     40                hitA.mObject = ray.intersections[0].mObject; 
     41                hitA.mPoint = ray.Extrap(ray.intersections[0].mT); 
     42                hitA.mNormal = ray.intersections[0].mNormal;  
     43        //      cout << "here91 " << hitA.mPoint << " !obj: " << hitA.mObject << endl; 
    5344        } 
    5445         
    55         mPreprocessor.SetupRay(ray, viewPoint, -direction); 
     46        mPreprocessor.SetupRay(ray, simpleRay.mOrigin, -simpleRay.mDirection); 
    5647        ray.mFlags &= ~Ray::CULL_BACKFACES; 
    5748 
    5849        if (castDoubleRay && mKdTree->CastRay(ray))  
    5950        { 
    60                 objectB = ray.intersections[0].mObject; 
    61                 pointB = ray.Extrap(ray.intersections[0].mT); 
    62                 normalB = ray.intersections[0].mNormal; 
     51                hitB.mObject = ray.intersections[0].mObject; 
     52                hitB.mPoint = ray.Extrap(ray.intersections[0].mT); 
     53                hitB.mNormal = ray.intersections[0].mNormal; 
    6354        } 
    64          
     55                 
    6556        return ProcessRay( 
    66                 viewPoint, 
    67                 direction, 
    68                 objectA, pointA, normalA, 
    69                 objectB, pointB, normalB, 
    70                 probability, 
    71                 vssRays, 
    72                 box 
     57                simpleRay, 
     58                hitA, 
     59                hitB, 
     60        vssRays, 
     61                box, 
     62                castDoubleRay, 
     63                pruneInvalidRays 
    7364                ); 
    7465} 
     
    7970                                                                   VssRayContainer &vssRays, 
    8071                                                                   const AxisAlignedBox3 &sbox, 
    81                                                                    const bool castDoubleRays) 
     72                                                                   const bool castDoubleRays, 
     73                                                                   const bool pruneInvalidRays) 
    8274{ 
    8375        const int num = 16; 
     
    9082        for (int i=index; i < index + num; i++)  
    9183        { 
    92                 CastRay(rays[i].mOrigin, 
    93                         rays[i].mDirection, 
    94                         rays[i].mPdf, 
    95                         vssRays, 
    96                         sbox, 
    97                         castDoubleRays); 
     84                CastRay(rays[i], vssRays, sbox, castDoubleRays, pruneInvalidRays); 
    9885        } 
    9986 
  • GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.h

    r1520 r1528  
    2020struct VssRayContainer; 
    2121class Preprocessor; 
    22  
     22struct SimpleRay; 
    2323 
    2424 
     
    3636 
    3737        virtual int CastRay( 
    38                 const Vector3 &viewPoint, 
    39                 const Vector3 &direction, 
    40                 const float probability, 
     38        const SimpleRay &simpleRay, 
    4139        VssRayContainer &vssRays, 
    4240                const AxisAlignedBox3 &box, 
    43                 const bool castDoubleRay 
     41                const bool castDoubleRay, 
     42                const bool pruneInvalidRays = true 
    4443                ); 
    4544 
     
    4948                 VssRayContainer &vssRays, 
    5049                 const AxisAlignedBox3 &sbox, 
    51                  const bool castDoubleRay 
     50                 const bool castDoubleRay, 
     51                 const bool pruneInvalidRays = true 
    5252                 ); 
    5353 
  • GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp

    r1444 r1528  
    13861386                        if (!vdata) 
    13871387                        { 
    1388                                 Debug << "error!!" << endl; 
     1388                                Debug << "error! should not come here" << endl; 
    13891389                                continue; 
    13901390                        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1524 r1528  
    846846                                           SimpleRayContainer &rays, 
    847847                                           VssRayContainer &vssRays, 
    848                                            const bool castDoubleRays 
     848                                           const bool castDoubleRays, 
     849                                           const bool pruneInvalidRays 
    849850                                           ) 
    850851{ 
     
    860861                                vssRays, 
    861862                                mViewCellsManager->GetViewSpaceBox(), 
    862                                 castDoubleRays); 
     863                                castDoubleRays, 
     864                                pruneInvalidRays); 
    863865                        i += 16; 
    864866                } 
     
    866868                { 
    867869                        mRayCaster->CastRay( 
    868                                 rays[i].mOrigin, 
    869                                 rays[i].mDirection, 
    870                                 rays[i].mPdf, 
     870                                rays[i], 
    871871                                vssRays, 
    872872                                mViewCellsManager->GetViewSpaceBox(), 
    873                                 castDoubleRays); 
     873                                castDoubleRays, 
     874                                pruneInvalidRays); 
    874875                        i ++; 
    875876                } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r1521 r1528  
    138138  virtual void CastRays(SimpleRayContainer &rays, 
    139139                                                VssRayContainer &vssRays, 
    140                                                 const bool castDoubleRays); 
     140                                                const bool castDoubleRays, 
     141                                                const bool pruneInvalidRays = true); 
    141142 
    142143  /** Returns a view cells manager of the given name. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h

    r1189 r1528  
    392392bool 
    393393Pvs<T, S>::GetSampleContribution(T sample, 
    394                                                           const float pdf, 
    395                                                           float &contribution)  
     394                                                                const float pdf, 
     395                                                                float &contribution)  
    396396{ 
    397397  S *data = Find(sample); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Ray.h

    r1473 r1528  
    3535  enum {FRONT, BACK, BACK_FRONT, FRONT_BACK, COINCIDENT}; 
    3636         
    37   struct Intersection { 
    38     // the point of intersection 
    39     float mT; 
    40  
    41         // the normal of the intersection 
    42         Vector3 mNormal; 
    43          
    44     // can be either mesh or a viewcell 
    45     Intersectable *mObject; 
    46                  
    47     // the face of the intersectable 
    48     int mFace; 
    49          
    50     Intersection(const float t, 
    51                                  const Vector3 &normal, 
    52                                  Intersectable *object, 
    53                                  const int face):mT(t), 
    54                                                                  mNormal(normal), 
    55                                                                  mObject(object), mFace(face) {} 
    56                  
    57                                  Intersection(): mT(0), mNormal(0,0,0), mObject(NULL), mFace(0) {} 
    58                  
    59     bool operator<( 
    60                                    const Intersection &b) const { 
    61  
    62       return  
    63                                 mT 
    64                                 < 
    65                                 b.mT; 
    66     } 
    67      
     37  struct Intersection  
     38  { 
     39          /// the point of intersection 
     40          float mT; 
     41 
     42          /// the normal of the intersection 
     43          Vector3 mNormal; 
     44 
     45          /// can be either mesh or a viewcell 
     46          Intersectable *mObject; 
     47 
     48          /// the face of the intersectable 
     49          int mFace; 
     50 
     51          Intersection(const float t, 
     52                                   const Vector3 &normal, 
     53                                   Intersectable *object, 
     54                                   const int face):  
     55          mT(t), mNormal(normal), mObject(object), mFace(face)  
     56          {} 
     57 
     58          Intersection(): mT(0), mNormal(0,0,0), mObject(NULL), mFace(0)  
     59          {} 
     60 
     61          bool operator<(const Intersection &b) const  
     62          { 
     63                  return mT < b.mT; 
     64          } 
    6865  }; 
    6966 
     
    318315        mOrigin(o), mDirection(d), mPdf(p) {} 
    319316 
    320   Vector3 Extrap(const float t) { 
     317  Vector3 Extrap(const float t) const { 
    321318        return mOrigin + mDirection * t; 
    322319  } 
     
    326323{ 
    327324public: 
    328    
    329    
     325     
    330326  SimpleRayContainer():vector<SimpleRay>() {} 
    331327   
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp

    r1522 r1528  
    2222 
    2323 
    24 VssRay *RayCaster::CastSingleRay(const Vector3 &viewPoint, 
    25                                                                  const Vector3 &direction, 
    26                                                                  const float probability, 
     24VssRay *RayCaster::CastSingleRay(const SimpleRay &simpleRay, 
    2725                                                                 const AxisAlignedBox3 &box) 
    2826{ 
    2927        VssRayContainer rays; 
    30         CastRay(viewPoint, direction, probability, rays, box, false); 
     28        CastRay(simpleRay, rays, box, false); 
    3129 
    3230        if (!rays.empty()) 
     
    3735 
    3836 
    39 int RayCaster::ProcessRay(const Vector3 &viewPoint, 
    40                                                   const Vector3 &direction, 
    41                                                   Intersectable *objectA, 
    42                                                   Vector3 &pointA, 
    43                                                   const Vector3 &normalA, 
    44                                                   Intersectable *objectB, 
    45                                                   Vector3 &pointB, 
    46                                                   const Vector3 &normalB, 
    47                                                   const float probability, 
     37/** Checks if ray is valid, (e.g., not in empty view space or outside the view space) 
     38*/ 
     39bool RayCaster::ValidateRay(const Vector3 &origin, 
     40                                                        const Vector3 &direction, 
     41                                                        const AxisAlignedBox3 &box, 
     42                                                        Intersection &hit) 
     43{ 
     44        if (!hit.mObject)  
     45        { 
     46                // compute intersection with the scene bounding box 
     47                static Ray ray; 
     48                mPreprocessor.SetupRay(ray, origin, direction); 
     49 
     50                float tmin, tmax; 
     51                if (box.ComputeMinMaxT(ray, &tmin, &tmax) && (tmin < tmax)) 
     52                { 
     53                        hit.mPoint = ray.Extrap(tmax); 
     54                } 
     55                else 
     56                { 
     57                        return false; 
     58                }                
     59        }  
     60        else if (mPreprocessor.mDetectEmptyViewSpace) 
     61        { 
     62                if (DotProd(hit.mNormal, direction) >= 0)  
     63                {        
     64                        hit.mObject = NULL; 
     65                        return false; 
     66                } 
     67        } 
     68 
     69        return true; 
     70} 
     71 
     72 
     73int RayCaster::ProcessRay(const SimpleRay &simpleRay, 
     74                                                  Intersection &hitA, 
     75                                                  Intersection &hitB, 
    4876                                                  VssRayContainer &vssRays, 
    49                                                   const AxisAlignedBox3 &box 
    50                                                   ) 
     77                                                  const AxisAlignedBox3 &box, 
     78                                                  const bool castDoubleRay, 
     79                                                  const bool pruneInvalidRays) 
    5180{ 
    5281        int hits = 0; 
     82 
    5383#if DEBUG_RAYCAST 
    5484        Debug<<"PR "; 
    5585#endif 
    56         if (objectA == NULL && objectB == NULL) 
     86         
     87        if (pruneInvalidRays) 
     88        { 
     89                if (!hitA.mObject && !hitB.mObject) 
     90                { 
     91                        return 0; 
     92                } 
     93         
     94                // inside test for bounding box 
     95                // enlarge box slightly so the view point fits for sure 
     96                AxisAlignedBox3 sbox = box; 
     97                sbox.Enlarge(Vector3(-Limits::Small)); 
     98 
     99                if (!sbox.IsInside(simpleRay.mOrigin)) 
     100                { 
     101                        return 0; 
     102                } 
     103        } 
     104//      cout << "here81 " << hitA.mObject << endl; 
     105        const bool validA =  
     106                ValidateRay(simpleRay.mOrigin, simpleRay.mDirection, box, hitA); 
     107        if (!validA && pruneInvalidRays) 
     108        { 
    57109                return 0; 
    58  
    59         AxisAlignedBox3 sbox = box; 
    60         sbox.Enlarge(Vector3(-Limits::Small)); 
    61  
    62         if (!sbox.IsInside(viewPoint)) 
    63                 return 0; 
    64  
    65         if (objectA == NULL) { 
    66                 // compute intersection with the scene bounding box 
    67                 static Ray ray; 
    68                 mPreprocessor.SetupRay(ray, viewPoint, direction); 
    69  
    70                 float tmin, tmax; 
    71                 if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax) 
    72                         pointA = ray.Extrap(tmax); 
    73                 else 
    74                         return 0; 
    75         } else { 
    76                 if (mPreprocessor.mDetectEmptyViewSpace) 
    77                         if (DotProd(normalA, direction) >= 0) { 
    78                                 // discard the sample 
    79                                 return 0; 
    80                         } 
    81110        } 
    82111 
    83         if (objectB == NULL) { 
    84                 // compute intersection with the scene bounding box 
    85                 static Ray ray; 
    86                 mPreprocessor.SetupRay(ray, viewPoint, -direction); 
     112        const bool validB = castDoubleRay &&  
     113                ValidateRay(simpleRay.mOrigin, -simpleRay.mDirection, box, hitB); 
    87114 
    88                 float tmin, tmax; 
    89                 if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax) 
    90                         pointB = ray.Extrap(tmax); 
    91                 else 
    92                         return 0; 
    93         } else { 
    94                 if (mPreprocessor.mDetectEmptyViewSpace) 
    95                         if (DotProd(normalB, direction) <= 0) { 
    96                                 // discard the sample 
    97                                 return 0; 
    98                         } 
     115        if (!validB && pruneInvalidRays) 
     116        { 
     117                return 0; 
    99118        } 
    100119 
    101         VssRay *vssRay  = NULL; 
    102         bool validSample = (objectA != objectB); 
    103         if (validSample) { 
    104                 if (objectA) { 
    105                         vssRay = new VssRay( 
    106                                 pointB, 
    107                                 pointA, 
    108                                 objectB, 
    109                                 objectA, 
     120        const bool validSample = !pruneInvalidRays || (hitA.mObject != hitB.mObject); 
     121         
     122        if (validSample)  
     123        { 
     124                if (!pruneInvalidRays || hitA.mObject)  
     125                { 
     126                        VssRay *vssRay = new VssRay( 
     127                                hitB.mPoint, 
     128                                hitA.mPoint, 
     129                                hitB.mObject, 
     130                                hitA.mObject, 
    110131                                mPreprocessor.mPass, 
    111                                 probability 
     132                                simpleRay.mPdf 
    112133                                ); 
    113134                         
    114135                        vssRays.push_back(vssRay); 
    115                         hits ++; 
     136                        ++ hits; 
     137                        //cout << "here70 vssray 1: " << *vssRay << " " << vssRay->mTermination - vssRay->mOrigin << endl; 
    116138                } 
    117139 
    118                 if (objectB) { 
    119                         vssRay = new VssRay( 
    120                                 pointA, 
    121                                 pointB, 
    122                                 objectA, 
    123                                 objectB, 
     140                if (castDoubleRay && (!pruneInvalidRays || hitB.mObject)) 
     141                { 
     142                        VssRay *vssRay = new VssRay( 
     143                                hitA.mPoint, 
     144                                hitB.mPoint, 
     145                                hitA.mObject, 
     146                                hitB.mObject, 
    124147                                mPreprocessor.mPass, 
    125                                 probability 
     148                                simpleRay.mPdf 
    126149                                ); 
    127150                         
    128151                        vssRays.push_back(vssRay); 
    129                         hits ++; 
     152                        ++ hits; 
     153                        //cout << "here71 vssray 2: " << *vssRay << endl; 
    130154                } 
    131155        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h

    r1521 r1528  
    44#include "Containers.h" 
    55#include <string> 
     6#include "Vector3.h" 
     7 
    68using namespace std; 
    79 
     
    1416class SimpleRayContainer; 
    1517class AxisAlignedBox3; 
    16 class Vector3; 
     18//class Vector3; 
    1719struct VssRayContainer; 
    1820class Preprocessor; 
     21struct SimpleRay; 
     22 
    1923 
    2024/** This class provides an interface for ray casting. 
     
    2226class RayCaster 
    2327{ 
     28 
    2429public: 
    2530         
     
    3843        */ 
    3944        VssRay *CastSingleRay( 
    40                 const Vector3 &viewPoint, 
    41                 const Vector3 &direction, 
    42                 const float probability, 
    43         const AxisAlignedBox3 &box 
     45                const SimpleRay &simpleRay, 
     46            const AxisAlignedBox3 &box 
    4447                ); 
    4548 
    4649        virtual int CastRay( 
    47                 const Vector3 &viewPoint, 
    48                 const Vector3 &direction, 
    49                 const float probability, 
     50                const SimpleRay &simpleRay, 
    5051        VssRayContainer &vssRays, 
    5152                const AxisAlignedBox3 &box, 
    52                 const bool castDoubleRay 
     53                const bool castDoubleRay, 
     54                const bool pruneInvalidRays = true 
    5355                ) = 0; 
    5456 
     
    5860                 VssRayContainer &vssRays, 
    5961                 const AxisAlignedBox3 &sbox, 
    60                  const bool castDoubleRay 
     62                 const bool castDoubleRay, 
     63                 const bool pruneInvalidRays = true 
    6164                 ) = 0; 
    6265         
    6366 
    6467protected: 
     68        struct Intersection 
     69        { 
     70                Intersection(): mObject(NULL), mFaceId(0) 
     71                {} 
     72 
     73                Intersection(const Vector3 &p, const Vector3 &n, Intersectable *o, const int f): 
     74                mPoint(p), mNormal(n), mObject(o), mFaceId(f) 
     75                {} 
     76 
     77                Intersection(const Vector3 &p): mPoint(p), mObject(NULL), mFaceId(0) 
     78                {} 
     79                Vector3 mPoint; 
     80                Vector3 mNormal; 
     81                Intersectable *mObject; 
     82                int mFaceId; 
     83        }; 
    6584 
    6685        int ProcessRay( 
    67                          const Vector3 &viewPoint, 
    68                          const Vector3 &direction, 
    69                          Intersectable *objectA, 
    70                          Vector3 &pointA, 
    71                          const Vector3 &normalA, 
    72                          Intersectable *objectB, 
    73                          Vector3 &pointB, 
    74                          const Vector3 &normalB, 
    75                          const float probability, 
     86                         const SimpleRay &ray, 
     87                         Intersection &hitA, 
     88                         Intersection &hitB, 
    7689                         VssRayContainer &vssRays, 
    77                          const AxisAlignedBox3 &box 
     90                         const AxisAlignedBox3 &box, 
     91                         const bool castDoubleRay, 
     92                         const bool pruneInvalidRays = true 
    7893                         ); 
    7994 
     95        /** Checks if ray is valid. 
     96                I.e., the ray is in valid view space. 
     97                @note: clamps the ray to valid view space. 
     98        */ 
     99        bool ValidateRay(const Vector3 &origin, 
     100                                         const Vector3 &direction, 
     101                                 const AxisAlignedBox3 &box, 
     102                                         Intersection &hit); 
    80103         
    81104        const Preprocessor &mPreprocessor; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1522 r1528  
    13181318         
    13191319        float sum = 0.0f; 
    1320  
    13211320        VssRayContainer::const_iterator it, it_end = rays.end(); 
    13221321         
     
    18311830                ViewCell *viewcell = *it; 
    18321831                 
    1833                 if (viewcell->GetValid()) // tests if view cellis in valid view space 
     1832                if (viewcell->GetValid()) // tests if view cell is in valid view space 
    18341833                { 
    18351834                        float contribution; 
     
    18381837                        { 
    18391838                                if (viewcell->GetPvs().GetSampleContribution( 
    1840                                                 ray.mTerminationObject, 
    1841                                                 ray.mPdf, 
    1842                                                 contribution)) 
     1839                                                        ray.mTerminationObject, 
     1840                                                        ray.mPdf, 
     1841                                                        contribution)) 
    18431842                                { 
    18441843                                        ++ ray.mPvsContribution; 
     
    18651864        } 
    18661865 
    1867         // if addrays is true, sampled entities are stored in the pvs 
     1866        // if true, the sampled entities are stored in the pvs 
    18681867        if (addRays) 
    18691868        { 
     
    18761875                                // if view point is valid, add new object to the pvs 
    18771876                                if (ray.mTerminationObject) 
    1878                                 { 
     1877                                {cout <<"here22" << endl; 
    18791878                                        viewcell->GetPvs().AddSample(ray.mTerminationObject, ray.mPdf); 
    18801879                                }                                
     
    54835482                        { 
    54845483                                // todo: maybe not correct for kd node pvs 
    5485                                 if (viewcell->GetPvs().GetSampleContribution(ray.mTerminationObject, 
    5486                                                                                                                          ray.mPdf, contribution)) 
     5484                                Intersectable *obj = mHierarchyManager->GetIntersectable(ray, true); 
     5485                                if (viewcell->GetPvs().GetSampleContribution(obj, 
     5486                                                                                                                         ray.mPdf,  
     5487                                                                                                                         contribution)) 
    54875488                                { 
    54885489                                        ++ ray.mPvsContribution; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp

    r1420 r1528  
    9797 
    9898        if (rays.empty()) 
     99        { 
    99100                return false; 
    100  
    101   stream << "Shape {" << endl; 
    102   stream << "appearance Appearance {" << endl; 
    103   stream << "material Material {" << endl; 
    104   stream << "diffuseColor " << color.r << " " << color.g << " " << color.b << endl; 
    105   stream << "}" << endl; // end material 
    106   stream << "}" << endl; // end appearance 
    107   
    108   stream << "geometry IndexedLineSet { coordIndex [" << endl; 
    109  
    110   int index = 0; 
    111   VssRayContainer::const_iterator ri = rays.begin(); 
    112  
    113   for (; ri != rays.end(); ++ ri)  
    114   { 
    115           stream << index << " " << index + 1 << " -1\n"; 
    116           index += 2 ; 
    117   } 
    118    
    119   stream << "]" << endl; 
    120    
    121   stream << "coord Coordinate { point [" << endl; 
    122    
    123   for (ri = rays.begin(); ri != rays.end(); ++ ri)  
    124   { 
    125           const Vector3 a = (*ri)->GetOrigin(); 
    126           const Vector3 b = (*ri)->mTerminationObject ? (*ri)->GetTermination() : a + 1000 * Normalize((*ri)->GetDir()); 
    127  
     101        } 
     102 
     103        stream << "Shape {" << endl; 
     104        stream << "appearance Appearance {" << endl; 
     105        stream << "material Material {" << endl; 
     106        stream << "diffuseColor " << color.r << " " << color.g << " " << color.b << endl; 
     107        stream << "}" << endl; // end material 
     108        stream << "}" << endl; // end appearance 
     109 
     110        stream << "geometry IndexedLineSet { coordIndex [" << endl; 
     111 
     112        int index = 0; 
     113        VssRayContainer::const_iterator ri = rays.begin(); 
     114 
     115        for (; ri != rays.end(); ++ ri)  
     116        { 
     117                stream << index << " " << index + 1 << " -1\n"; 
     118                index += 2 ; 
     119        } 
     120 
     121        stream << "]" << endl; 
     122 
     123        stream << "coord Coordinate { point [" << endl; 
     124 
     125        for (ri = rays.begin(); ri != rays.end(); ++ ri)  
     126        { 
     127                const Vector3 a = (*ri)->GetOrigin(); 
     128                const Vector3 b = (*ri)->mTerminationObject ? (*ri)->GetTermination() : a + 1000 * Normalize((*ri)->GetDir()); 
     129 
     130        //      cout << "here45 origin " << a << " termination: " << b << endl; 
    128131#if _DEBUG 
    129           bool isnan = false; 
    130           if (!a.CheckValidity()) 
    131           { 
    132                   cout << "error a"<<endl; 
    133                   isnan = true; 
    134           } 
    135  
    136            if (!b.CheckValidity()) 
    137           { 
    138                   cout << "error b"<<endl; 
    139                   isnan = true; 
    140           } 
    141           if (isnan) 
    142                   continue; 
     132                bool isnan = false; 
     133                if (!a.CheckValidity()) 
     134                { 
     135                        cout << "error a"<<endl; 
     136                        isnan = true; 
     137                } 
     138 
     139                if (!b.CheckValidity()) 
     140                { 
     141                        cout << "error b"<<endl; 
     142                        isnan = true; 
     143                } 
     144                if (isnan) 
     145                        continue; 
    143146#endif 
    144           stream << a.x << " " << a.y << " " << a.z << " ,"; 
    145           stream << b.x << " " << b.y << " " << b.z << " ,\n"; 
    146   } 
    147  
    148   stream << "]" << endl; 
    149   stream << "}" << endl; 
    150   stream << "}" << endl; 
    151   stream << "}" << endl; 
    152   //stream << "}" << endl; 
    153          
    154   return true; 
     147                stream << a.x << " " << a.y << " " << a.z << " ,"; 
     148                stream << b.x << " " << b.y << " " << b.z << " ,\n"; 
     149        } 
     150 
     151        stream << "]" << endl; 
     152        stream << "}" << endl; 
     153        stream << "}" << endl; 
     154        stream << "}" << endl; 
     155        //stream << "}" << endl; 
     156 
     157        return true; 
    155158} 
    156159 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp

    r1521 r1528  
    485485                 
    486486                        mViewCellsManager->GetViewPoint(viewpoint); 
    487                         Vector3 direction = GetDirection(viewpoint, &mViewSpaceBox); 
    488  
    489                         sampleContributions = mRayCaster->CastRay(viewpoint, direction, 1, mVssRays, mViewSpaceBox, true); 
     487                        const Vector3 direction = GetDirection(viewpoint, &mViewSpaceBox); 
     488 
     489                        const SimpleRay sray(viewpoint, direction); 
     490                        sampleContributions = mRayCaster->CastRay(sray, mVssRays, mViewSpaceBox, true); 
    490491 
    491492                        if (sampleContributions) { 
     
    615616        } 
    616617 
    617         for (int i=0; i < rays.size(); i++) 
    618         { 
    619                 mRayCaster->CastRay(rays[i].mOrigin, rays[i].mDirection, 1, vssRays, mViewSpaceBox, true); 
    620         } 
    621  
     618        CastRays(rays, vssRays, true); 
    622619        vssTree->AddRays(vssRays); 
    623620 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.cpp

    r1259 r1528  
    77int 
    88VssRay::mailID = 0; 
     9 
     10 
     11VssRay::VssRay( 
     12                 const Vector3 &origin, 
     13                 const Vector3 &termination, 
     14                 Intersectable *originObject, 
     15                 Intersectable *terminationObject, 
     16                 const int pass, 
     17                 const float pdf 
     18                 ): 
     19        mMailbox(-1), 
     20    mOrigin(origin), 
     21    mTermination(termination), 
     22        mOriginObject(originObject), 
     23        mTerminationObject(terminationObject), 
     24        mRefCount(0), 
     25    mFlags(0), 
     26        mPass(pass), 
     27        mViewCells(0), 
     28        mWeightedPvsContribution(0), 
     29        mPdf(pdf), 
     30        mTerminationNode(NULL), 
     31        mOriginNode(NULL), 
     32        mPvsContribution(0) 
     33{ 
     34        Precompute(); 
     35} 
     36 
     37 
     38VssRay::VssRay(const Ray &ray): 
     39        mRefCount(0), 
     40        mFlags(0), 
     41        mMailbox(-1), 
     42        mOriginObject(ray.sourceObject.mObject), 
     43        mPass(0), 
     44        mViewCells(0), 
     45        mPdf(1.0f), 
     46        mTerminationNode(NULL), 
     47        mOriginNode(NULL), 
     48        mPvsContribution(0) 
     49{ 
     50        if (ray.sourceObject.mObject) 
     51                mOrigin = ray.Extrap(ray.sourceObject.mT); 
     52        else 
     53                mOrigin = ray.GetLoc();  
     54 
     55        //Debug << "origin: " << mOrigin << endl; 
     56        if (!ray.intersections.empty()) 
     57        { 
     58                mTermination = ray.Extrap(ray.intersections[0].mT); 
     59                mTerminationObject = ray.intersections[0].mObject; 
     60        } 
     61        else 
     62        { 
     63                mTermination = ray.Extrap(1e6);//TODO: should be Limits::Infinity 
     64                mTerminationObject = NULL; 
     65        } 
     66 
     67        Precompute(); 
     68} 
     69 
     70 
     71void VssRay::Precompute()  
     72{ 
     73        mFlags = 0; 
     74        Vector3 dir = GetDir(); 
     75 
     76#define BIDIRECTIONAL_RAY 0 
     77#if BIDIRECTIONAL_RAY 
     78        if (dir.y < 0) { 
     79                // swap objects and poits        
     80                swap(mOriginObject, mTerminationObject); 
     81                swap(mOrigin, mTermination); 
     82                dir = -dir; 
     83        } 
     84#endif 
     85        if (dir.x > 0.0f) mFlags |= FPosDirX; 
     86        if (dir.y > 0.0f) mFlags |= FPosDirY; 
     87        if (dir.z > 0.0f) mFlags |= FPosDirZ; 
     88 
     89        mInvSize = 1.0f/Magnitude(GetDir()); 
     90} 
    991 
    1092 
     
    265347 
    266348 
    267 void VssRay::GetSampleData(const bool isTermination,  
    268                                                    Vector3 &pt,  
    269                                                    Intersectable **obj, 
    270                                                    KdNode **node) const 
    271 { 
    272         if (isTermination) 
    273         { 
    274                 pt = mTermination; 
    275                 *obj = mTerminationObject; 
    276                 *node = mTerminationNode; 
    277         } 
    278         else 
    279         { 
    280                 pt = mOrigin; 
    281                 *obj = mOriginObject; 
    282                 *node = mOriginNode; 
    283         } 
    284 } 
    285  
    286  
    287 } 
     349 
     350} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h

    r1259 r1528  
    1414class KdNode; 
    1515 
     16 
    1617class VssRay { 
    1718public: 
    18   // various flags 
     19 
     20 // various flags 
    1921  enum { 
    2022    FPosDirX = 1,  // the direction of ray in X-axis is positive 
     
    8789                 const int pass = 0, 
    8890                 const float pdf = 1.0f 
    89                  ): 
    90         mMailbox(-1), 
    91     mOrigin(origin), 
    92     mTermination(termination), 
    93         mOriginObject(originObject), 
    94         mTerminationObject(terminationObject), 
    95         mRefCount(0), 
    96     mFlags(0), 
    97         mPass(pass), 
    98         mViewCells(0), 
    99         mWeightedPvsContribution(0), 
    100         mPdf(pdf), 
    101         mTerminationNode(NULL), 
    102         mOriginNode(NULL) 
    103         { 
    104                 Precompute(); 
    105         } 
    106          
    107   VssRay(const Ray &ray): 
    108         mRefCount(0), 
    109         mFlags(0), 
    110         mMailbox(-1), 
    111         mOriginObject(ray.sourceObject.mObject), 
    112         mPass(0), 
    113         mViewCells(0), 
    114         mPdf(1.0f), 
    115         mTerminationNode(NULL), 
    116         mOriginNode(NULL) 
    117   { 
    118         if (ray.sourceObject.mObject) 
    119           mOrigin = ray.Extrap(ray.sourceObject.mT); 
    120         else 
    121           mOrigin = ray.GetLoc();  
    122          
    123         //Debug << "origin: " << mOrigin << endl; 
    124         if (!ray.intersections.empty()) 
    125           { 
    126                 mTermination = ray.Extrap(ray.intersections[0].mT); 
    127                 mTerminationObject = ray.intersections[0].mObject; 
    128           } 
    129         else 
    130           { 
    131                 mTermination = ray.Extrap(1e6);//TODO: should be Limits::Infinity 
    132                 mTerminationObject = NULL; 
    133           } 
    134          
    135         Precompute(); 
    136   } 
    137    
    138   void Precompute() { 
    139     mFlags = 0; 
    140         Vector3 dir = GetDir(); 
    141  
    142 #define BIDIRECTIONAL_RAY 0 
    143 #if BIDIRECTIONAL_RAY 
    144         if (dir.y < 0) { 
    145           // swap objects and poits      
    146           swap(mOriginObject, mTerminationObject); 
    147           swap(mOrigin, mTermination); 
    148           dir = -dir; 
    149         } 
    150 #endif 
    151         if (dir.x > 0.0f) mFlags |= FPosDirX; 
    152     if (dir.y > 0.0f) mFlags |= FPosDirY; 
    153     if (dir.z > 0.0f) mFlags |= FPosDirZ; 
    154  
    155     mInvSize = 1.0f/Magnitude(GetDir()); 
    156   } 
     91                 ); 
     92         
     93  VssRay(const Ray &ray); 
     94         
     95   
     96  void Precompute(); 
    15797 
    15898  void Mail() { mMailbox = mailID; } 
     
    283223  } 
    284224 
     225  /** Returns the data sampled on either the ray origin or termination. 
     226  */ 
    285227  void GetSampleData( 
    286228          const bool isTerminaton,  
     
    292234     
    293235}; 
     236 
     237inline void VssRay::GetSampleData(const bool isTermination,  
     238                                                                  Vector3 &pt,  
     239                                                                  Intersectable **obj, 
     240                                                                  KdNode **node) const 
     241{ 
     242        if (isTermination) 
     243        { 
     244                pt = mTermination; 
     245                *obj = mTerminationObject; 
     246                *node = mTerminationNode; 
     247        } 
     248        else 
     249        { 
     250                pt = mOrigin; 
     251                *obj = mOriginObject; 
     252                *node = mOriginNode; 
     253        } 
     254} 
    294255 
    295256void 
     
    318279// For sorting rays 
    319280// -------------------------------------------------------------- 
    320 struct  SortableEntry 
     281struct SortableEntry 
    321282{ 
    322283  enum EType { 
Note: See TracChangeset for help on using the changeset viewer.