Ignore:
Timestamp:
12/08/06 17:10:14 (18 years ago)
Author:
bittner
Message:

merge, global lines, rss sampling updates

File:
1 edited

Legend:

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

    r1824 r1867  
    3939/** Checks if ray is valid, (e.g., not in empty view space or outside the view space) 
    4040*/ 
    41 bool RayCaster::ValidateRay(const Vector3 &origin, 
    42                                                         const Vector3 &direction, 
    43                                                         const AxisAlignedBox3 &box, 
    44                                                         Intersection &hit) 
     41bool 
     42RayCaster::ValidateRay(const Vector3 &origin, 
     43                                           const Vector3 &direction, 
     44                                           const AxisAlignedBox3 &box, 
     45                                           Intersection &hit) 
    4546{ 
    46         if (!hit.mObject)  { 
    47           // compute intersection with the scene bounding box 
     47  if (!hit.mObject)  { 
     48        // compute intersection with the scene bounding box 
    4849#if EXACT_BOX_CLIPPING 
    49           static Ray ray; 
    50           mPreprocessor.SetupRay(ray, origin, direction); 
    51            
    52           float tmin, tmax; 
    53           if (box.ComputeMinMaxT(ray, &tmin, &tmax) && (tmin < tmax)) { 
    54                 hit.mPoint = ray.Extrap(tmax); 
    55           } 
    56           else { 
    57                 //              cout<<" invalid hp "<<tmin<<" "<<tmax<<endl; 
    58                 //              cout<<" box "<<box<<endl; 
    59                 //              cout<<" origin "<<origin<<endl; 
    60                 //              cout<<" direction "<<direction<<endl; 
    61                 //              cout<< "inv dir"<<ray.GetInvDir()<<endl; 
    62                 return false; 
    63           } 
     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); 
     56        } 
     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; 
     64        } 
    6465#else 
    65           hit.mPoint = origin + direction*Magnitude(box.Diagonal()); 
     66        hit.mPoint = origin + direction*Magnitude(box.Diagonal()); 
    6667#endif 
    67         } 
    68         else if (mPreprocessor.mDetectEmptyViewSpace) { 
    69           if (DotProd(hit.mNormal, direction) >= 0) {    
     68  } 
     69  else 
     70        if (mPreprocessor.mDetectEmptyViewSpace) { 
     71          if (DotProd(hit.mNormal, direction) >= -Limits::Small) {       
    7072                hit.mObject = NULL; 
    7173                return false; 
    7274          } 
    7375        } 
    74          
    75         return true; 
     76   
     77  return true; 
    7678} 
    7779 
    7880 
    79 int RayCaster::ProcessRay(const SimpleRay &simpleRay, 
    80                                                   Intersection &hitA, 
    81                                                   Intersection &hitB, 
    82                                                   VssRayContainer &vssRays, 
    83                                                   const AxisAlignedBox3 &box, 
    84                                                   const bool castDoubleRay, 
    85                                                   const bool pruneInvalidRays) 
     81int 
     82RayCaster::ProcessRay(const SimpleRay &simpleRay, 
     83                                          Intersection &hitA, 
     84                                          Intersection &hitB, 
     85                                          VssRayContainer &vssRays, 
     86                                          const AxisAlignedBox3 &box, 
     87                                          const bool castDoubleRay, 
     88                                          const bool pruneInvalidRays) 
    8689{ 
    8790        int hits = 0; 
     
    9093        Debug<<"PRA"<<flush; 
    9194#endif 
     95 
     96        // regardless of the pruneInvalidRays setting reject rays whic degenerate to a point 
     97        if (EpsilonEqualV3(hitA.mPoint, hitB.mPoint, Limits::Small)) 
     98          return 0; 
    9299         
    93         if (pruneInvalidRays) 
    94         { 
     100        if (pruneInvalidRays) { 
    95101          if (!hitA.mObject && !hitB.mObject) { 
    96102                return 0; 
     
    100106        const bool validA =  
    101107          ValidateRay(simpleRay.mOrigin, simpleRay.mDirection, box, hitA); 
    102  
     108         
     109        const bool validB = castDoubleRay &&  
     110          ValidateRay(simpleRay.mOrigin, -simpleRay.mDirection, box, hitB); 
     111         
    103112#if DEBUG_RAYCAST 
    104113        Debug<<"PR1"<<flush; 
    105114#endif 
    106115         
    107         if (!validA && pruneInvalidRays) 
    108           { 
     116        // reset both contributions 
     117        if (!validA || !validB) { 
     118          if (pruneInvalidRays) 
    109119                return 0; 
    110           } 
     120          // reset both contributions of this ray 
     121          hitA.mObject = NULL; 
     122          hitB.mObject = NULL; 
     123        } 
     124           
    111125         
    112         const bool validB = castDoubleRay &&  
    113           ValidateRay(simpleRay.mOrigin, -simpleRay.mDirection, box, hitB); 
    114          
    115         if (!validB && pruneInvalidRays) 
    116           { 
    117                 return 0; 
    118         } 
    119  
    120         const bool validSample = !pruneInvalidRays || (hitA.mObject != hitB.mObject); 
    121  
     126        const bool validSample = true; 
     127        // 8.11. 2007 JB 
     128        // degenerate rays checked by geometrical constraint... 
     129        //      !pruneInvalidRays || (hitA.mObject != hitB.mObject); 
    122130         
    123131#if DEBUG_RAYCAST 
     
    126134 
    127135        if (validSample) { 
    128           if (!pruneInvalidRays || hitA.mObject)  
    129                 { 
    130                   VssRay *vssRay = new VssRay( 
    131                                                                           hitB.mPoint, 
    132                                                                           hitA.mPoint, 
    133                                                                           hitB.mObject, 
    134                                                                           hitA.mObject, 
    135                                                                           mPreprocessor.mPass, 
    136                                                                           simpleRay.mPdf 
    137                                                                           ); 
    138                   if (validA) 
    139                         vssRay->mFlags |= VssRay::Valid; 
    140                   vssRays.push_back(vssRay); 
    141                   ++ hits; 
    142                   //cout << "vssray 1: " << *vssRay << " " << vssRay->mTermination - vssRay->mOrigin << endl; 
    143                 } 
    144  
     136          if (!pruneInvalidRays || hitA.mObject) { 
     137                VssRay *vssRay = new VssRay( 
     138                                                                        hitB.mPoint, 
     139                                                                        hitA.mPoint, 
     140                                                                        hitB.mObject, 
     141                                                                        hitA.mObject, 
     142                                                                        mPreprocessor.mPass, 
     143                                                                        simpleRay.mPdf 
     144                                                                        ); 
     145                 
     146                if (validA) 
     147                  vssRay->mFlags |= VssRay::Valid; 
     148                vssRay->mGeneratingRayId = simpleRay.mId; 
     149                vssRays.push_back(vssRay); 
     150                ++ hits; 
     151                //cout << "vssray 1: " << *vssRay << " " << vssRay->mTermination - vssRay->mOrigin << endl; 
     152          } 
     153           
    145154#if DEBUG_RAYCAST 
    146         Debug<<"PR3"<<flush; 
     155          Debug<<"PR3"<<flush; 
    147156#endif 
    148157 
     
    150159                { 
    151160                  VssRay *vssRay = new VssRay( 
    152                                                                                                                                         hitA.mPoint, 
    153                                                                                                                                         hitB.mPoint, 
    154                                                                                                                                         hitA.mObject, 
    155                                                                                                                                         hitB.mObject, 
    156                                                                                                                                         mPreprocessor.mPass, 
    157                                                                                                                                         simpleRay.mPdf 
    158                                                                                                                                         ); 
     161                                                                          hitA.mPoint, 
     162                                                                          hitB.mPoint, 
     163                                                                          hitA.mObject, 
     164                                                                          hitB.mObject, 
     165                                                                          mPreprocessor.mPass, 
     166                                                                          simpleRay.mPdf 
     167                                                                          ); 
    159168                  if (validB) 
    160                                 vssRay->mFlags |= VssRay::Valid; 
     169                        vssRay->mFlags |= VssRay::Valid; 
    161170                   
     171                  vssRay->mGeneratingRayId = simpleRay.mId; 
    162172                  vssRays.push_back(vssRay); 
    163173                  ++ hits; 
     
    165175                } 
    166176        } 
    167  
     177         
    168178#if DEBUG_RAYCAST 
    169179        Debug<<"PR4"<<flush; 
Note: See TracChangeset for help on using the changeset viewer.