Ignore:
Timestamp:
01/05/07 16:29:54 (17 years ago)
Author:
bittner
Message:

tmp commit

File:
1 edited

Legend:

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

    r1932 r1942  
    33#include "Ray.h" 
    44#include "Preprocessor.h" 
     5#include "ViewCellsManager.h" 
    56 
    67 
     
    1011#define DEBUG_RAYCAST 0 
    1112 
    12 #define EXACT_BOX_CLIPPING 1 
     13#define EXACT_BOX_CLIPPING 0 
    1314 
    1415RayCaster::RayCaster(const Preprocessor &preprocessor): 
     
    3839} 
    3940 
     41bool 
     42RayCaster::ClipToViewSpaceBox(const Vector3 &origin, 
     43                                                          const Vector3 &termination, 
     44                                                          Vector3 &clippedOrigin, 
     45                                                          Vector3 &clippedTermination) 
     46{ 
     47  Ray ray(origin, termination - origin, Ray::LINE_SEGMENT);      
     48  ray.Precompute(); 
     49   
     50  float tmin, tmax; 
     51  if ((!mPreprocessor.mViewCellsManager-> 
     52           GetViewSpaceBox().ComputeMinMaxT(ray, &tmin, &tmax)) || 
     53          tmin>=tmax 
     54          ) 
     55        return false; 
     56 
     57  if (tmin >= 1.0f || tmax <=0.0f) 
     58        return false; 
     59   
     60  if (tmin > 0.0f) 
     61        clippedOrigin = ray.Extrap(tmin); 
     62  else 
     63        clippedOrigin = origin; 
     64   
     65  if (tmax < 1.0f) 
     66        clippedTermination = ray.Extrap(tmax); 
     67  else 
     68        clippedTermination = termination; 
     69   
     70  return true; 
     71} 
    4072 
    4173/** Checks if ray is valid, (e.g., not in empty view space or outside the view space) 
     
    140172        // degenerate rays checked by geometrical constraint... 
    141173        //      !pruneInvalidRays || (hitA.mObject != hitB.mObject); 
     174 
    142175         
    143176#if DEBUG_RAYCAST 
    144177        Debug<<"PR2"<<flush; 
    145178#endif 
    146  
    147         if (!pruneInvalidRays || hitA.mObject)  
    148         { 
    149                 VssRay *vssRay = new VssRay(hitB.mPoint, 
     179        const bool validSample = true; 
     180        if (validSample) { 
     181          Vector3 clipA, clipB; 
     182          if (!ClipToViewSpaceBox(hitA.mPoint, 
     183                                                          hitB.mPoint, 
     184                                                          clipA, 
     185                                                          clipB)) 
     186                return 0; 
     187          if (!pruneInvalidRays || hitA.mObject) { 
     188                VssRay *vssRay = new VssRay( 
     189                                                                        clipB, 
    150190                                                                        hitA.mPoint, 
    151191                                                                        hitB.mObject, 
     
    167207#endif 
    168208 
    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) 
     209          if (castDoubleRay && (!pruneInvalidRays || hitB.mObject)) 
     210                { 
     211                  VssRay *vssRay = new VssRay( 
     212                                                                          clipA, 
     213                                                                          hitB.mPoint, 
     214                                                                          hitA.mObject, 
     215                                                                          hitB.mObject, 
     216                                                                          mPreprocessor.mPass, 
     217                                                                          simpleRay.mPdf 
     218                                                                          ); 
     219                  if (validB) 
    179220                        vssRay->mFlags |= VssRay::Valid; 
    180221 
     
    183224                ++ hits; 
    184225                //cout << "vssray 2: " << *vssRay << endl; 
    185         } 
    186          
    187 #if DEBUG_RAYCAST 
    188         Debug<<"PR4"<<flush; 
    189 #endif 
    190  
     226                } 
     227#if DEBUG_RAYCAST 
     228          Debug<<"PR4"<<flush; 
     229#endif 
     230        } 
     231         
    191232        return hits; 
    192233} 
Note: See TracChangeset for help on using the changeset viewer.