Ignore:
Timestamp:
01/03/07 01:36:35 (17 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r1900 r1932  
    2424 
    2525VssRay *RayCaster::CastRay(const SimpleRay &simpleRay, 
    26                                                    const AxisAlignedBox3 &box, 
    27                                                    const bool castDoubleRay) 
     26                                                   const AxisAlignedBox3 &box) 
     27                                                   //const bool castDoubleRay)  
    2828{ 
    29   VssRayContainer rays; 
    30   CastRay(simpleRay, rays, box, castDoubleRay); 
    31    
    32   if (!rays.empty()) 
    33         return rays.back(); 
    34   else 
    35         return NULL; 
     29        // note: make no sense otherwise 
     30        const bool castDoubleRay = false; 
     31        VssRayContainer rays; 
     32        CastRay(simpleRay, rays, box, castDoubleRay); 
     33     
     34        if (!rays.empty()) 
     35                return rays.back(); 
     36        else 
     37                return NULL; 
    3638} 
    3739 
     
    4547                                           Intersection &hit) 
    4648{ 
    47   if (!hit.mObject)  { 
    48         // compute intersection with the scene bounding box 
     49        if (!hit.mObject)   
     50        { 
     51                // compute intersection with the scene bounding box 
    4952#if EXACT_BOX_CLIPPING 
    50         static Ray ray; 
    51         mPreprocessor.SetupRay(ray, origin, direction); 
    52          
    53         float tmin, tmax; 
    54         if (box.ComputeMinMaxT(ray, &tmin, &tmax) && (tmin < tmax)) { 
    55           hit.mPoint = ray.Extrap(tmax); 
     53                static Ray ray; 
     54                mPreprocessor.SetupRay(ray, origin, direction); 
     55 
     56                float tmin, tmax; 
     57                if (box.ComputeMinMaxT(ray, &tmin, &tmax) && (tmin < tmax))  
     58                { 
     59                        hit.mPoint = ray.Extrap(tmax); 
     60                } 
     61                else  
     62                { 
     63                        // cout<<" invalid hp "<<tmin<<" "<<tmax<<endl; 
     64                        // cout<<" box "<<box<<endl; 
     65                        // cout<<" origin "<<origin<<endl; 
     66                        // cout<<" direction "<<direction<<endl; 
     67                        // cout<< "inv dir"<<ray.GetInvDir()<<endl; 
     68                        return false; 
     69                } 
     70#else 
     71                hit.mPoint = origin + direction * Magnitude(box.Diagonal()); 
     72#endif 
    5673        } 
    57         else { 
    58           //            cout<<" invalid hp "<<tmin<<" "<<tmax<<endl; 
    59           //            cout<<" box "<<box<<endl; 
    60           //            cout<<" origin "<<origin<<endl; 
    61           //            cout<<" direction "<<direction<<endl; 
    62           //            cout<< "inv dir"<<ray.GetInvDir()<<endl; 
    63           return false; 
     74        else 
     75        { 
     76                if (mPreprocessor.mDetectEmptyViewSpace)  
     77                { 
     78                        if (DotProd(hit.mNormal, direction) >= -Limits::Small)  
     79                        {        
     80                                hit.mObject = NULL; 
     81                                return false; 
     82                        } 
     83                } 
    6484        } 
    65 #else 
    66         hit.mPoint = origin + direction*Magnitude(box.Diagonal()); 
    67 #endif 
    68   } 
    69   else 
    70         if (mPreprocessor.mDetectEmptyViewSpace) { 
    71           if (DotProd(hit.mNormal, direction) >= -Limits::Small) {       
    72                 hit.mObject = NULL; 
    73                 return false; 
    74           } 
    75         } 
    76    
    77   return true; 
     85 
     86        return true; 
    7887} 
    7988 
     
    98107        //        return 0; 
    99108         
    100         if (pruneInvalidRays) { 
    101           if (!hitA.mObject && !hitB.mObject) { 
    102                 return 0; 
    103           } 
     109        if (pruneInvalidRays)  
     110        { 
     111                if (!hitA.mObject && !hitB.mObject)  
     112                { 
     113                        return 0; 
     114                } 
    104115        } 
    105116         
     
    107118          ValidateRay(simpleRay.mOrigin, simpleRay.mDirection, box, hitA); 
    108119         
    109         const bool validB = castDoubleRay &&  
    110           ValidateRay(simpleRay.mOrigin, -simpleRay.mDirection, box, hitB); 
     120        // note: should we check for backward valitidy also for single rays? 
     121        const bool validB = //castDoubleRay &&  
     122                ValidateRay(simpleRay.mOrigin, -simpleRay.mDirection, box, hitB); 
    111123         
    112124#if DEBUG_RAYCAST 
     
    115127         
    116128        // reset both contributions 
    117         if (!validA || !validB) { 
    118           if (pruneInvalidRays) 
    119                 return 0; 
    120           // reset both contributions of this ray 
    121           hitA.mObject = NULL; 
    122           hitB.mObject = NULL; 
     129        if (!validA || !validB) 
     130        { 
     131                if (pruneInvalidRays) 
     132                        return 0; 
     133                 
     134                // reset both contributions of this ray 
     135                hitA.mObject = NULL; 
     136                hitB.mObject = NULL; 
    123137        } 
    124138           
    125          
    126         const bool validSample = true; 
    127139        // 8.11. 2007 JB 
    128140        // degenerate rays checked by geometrical constraint... 
     
    133145#endif 
    134146 
    135         if (validSample) { 
    136           if (!pruneInvalidRays || hitA.mObject) { 
    137                 VssRay *vssRay = new VssRay( 
    138                                                                         hitB.mPoint, 
     147        if (!pruneInvalidRays || hitA.mObject)  
     148        { 
     149                VssRay *vssRay = new VssRay(hitB.mPoint, 
    139150                                                                        hitA.mPoint, 
    140151                                                                        hitB.mObject, 
    141152                                                                        hitA.mObject, 
    142153                                                                        mPreprocessor.mPass, 
    143                                                                         simpleRay.mPdf 
    144                                                                         ); 
    145                  
     154                                                                        simpleRay.mPdf); 
     155 
    146156                if (validA) 
    147                   vssRay->mFlags |= VssRay::Valid; 
     157                        vssRay->mFlags |= VssRay::Valid; 
     158 
    148159                vssRay->mDistribution = simpleRay.mDistribution; 
    149160                vssRays.push_back(vssRay); 
    150161                ++ hits; 
    151162                //cout << "vssray 1: " << *vssRay << " " << vssRay->mTermination - vssRay->mOrigin << endl; 
    152           } 
    153            
     163        } 
     164 
    154165#if DEBUG_RAYCAST 
    155           Debug<<"PR3"<<flush; 
     166        Debug<<"PR3"<<flush; 
    156167#endif 
    157168 
    158           if (castDoubleRay && (!pruneInvalidRays || hitB.mObject)) 
    159                 { 
    160                   VssRay *vssRay = new VssRay( 
    161                                                                           hitA.mPoint, 
    162                                                                           hitB.mPoint, 
    163                                                                           hitA.mObject, 
    164                                                                           hitB.mObject, 
    165                                                                           mPreprocessor.mPass, 
    166                                                                           simpleRay.mPdf 
    167                                                                           ); 
    168                   if (validB) 
     169        if (castDoubleRay && (!pruneInvalidRays || hitB.mObject)) 
     170        { 
     171                VssRay *vssRay = new VssRay(hitA.mPoint, 
     172                                                                        hitB.mPoint, 
     173                                                                        hitA.mObject, 
     174                                                                        hitB.mObject, 
     175                                                                        mPreprocessor.mPass, 
     176                                                                        simpleRay.mPdf); 
     177 
     178                if (validB) 
    169179                        vssRay->mFlags |= VssRay::Valid; 
    170                    
    171                   vssRay->mDistribution = simpleRay.mDistribution; 
    172                   vssRays.push_back(vssRay); 
    173                   ++ hits; 
    174                   //cout << "vssray 2: " << *vssRay << endl; 
    175                 } 
     180 
     181                vssRay->mDistribution = simpleRay.mDistribution; 
     182                vssRays.push_back(vssRay); 
     183                ++ hits; 
     184                //cout << "vssray 2: " << *vssRay << endl; 
    176185        } 
    177186         
Note: See TracChangeset for help on using the changeset viewer.