Changeset 1867 for GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
- Timestamp:
- 12/08/06 17:10:14 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
r1824 r1867 39 39 /** Checks if ray is valid, (e.g., not in empty view space or outside the view space) 40 40 */ 41 bool RayCaster::ValidateRay(const Vector3 &origin, 42 const Vector3 &direction, 43 const AxisAlignedBox3 &box, 44 Intersection &hit) 41 bool 42 RayCaster::ValidateRay(const Vector3 &origin, 43 const Vector3 &direction, 44 const AxisAlignedBox3 &box, 45 Intersection &hit) 45 46 { 46 47 47 if (!hit.mObject) { 48 // compute intersection with the scene bounding box 48 49 #if EXACT_BOX_CLIPPING 49 50 51 52 53 54 55 56 57 58 59 60 61 62 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 } 64 65 #else 65 66 hit.mPoint = origin + direction*Magnitude(box.Diagonal()); 66 67 #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) { 70 72 hit.mObject = NULL; 71 73 return false; 72 74 } 73 75 } 74 75 76 77 return true; 76 78 } 77 79 78 80 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) 81 int 82 RayCaster::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) 86 89 { 87 90 int hits = 0; … … 90 93 Debug<<"PRA"<<flush; 91 94 #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; 92 99 93 if (pruneInvalidRays) 94 { 100 if (pruneInvalidRays) { 95 101 if (!hitA.mObject && !hitB.mObject) { 96 102 return 0; … … 100 106 const bool validA = 101 107 ValidateRay(simpleRay.mOrigin, simpleRay.mDirection, box, hitA); 102 108 109 const bool validB = castDoubleRay && 110 ValidateRay(simpleRay.mOrigin, -simpleRay.mDirection, box, hitB); 111 103 112 #if DEBUG_RAYCAST 104 113 Debug<<"PR1"<<flush; 105 114 #endif 106 115 107 if (!validA && pruneInvalidRays) 108 { 116 // reset both contributions 117 if (!validA || !validB) { 118 if (pruneInvalidRays) 109 119 return 0; 110 } 120 // reset both contributions of this ray 121 hitA.mObject = NULL; 122 hitB.mObject = NULL; 123 } 124 111 125 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); 122 130 123 131 #if DEBUG_RAYCAST … … 126 134 127 135 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 145 154 #if DEBUG_RAYCAST 146 Debug<<"PR3"<<flush;155 Debug<<"PR3"<<flush; 147 156 #endif 148 157 … … 150 159 { 151 160 VssRay *vssRay = new VssRay( 152 153 154 155 156 157 158 161 hitA.mPoint, 162 hitB.mPoint, 163 hitA.mObject, 164 hitB.mObject, 165 mPreprocessor.mPass, 166 simpleRay.mPdf 167 ); 159 168 if (validB) 160 169 vssRay->mFlags |= VssRay::Valid; 161 170 171 vssRay->mGeneratingRayId = simpleRay.mId; 162 172 vssRays.push_back(vssRay); 163 173 ++ hits; … … 165 175 } 166 176 } 167 177 168 178 #if DEBUG_RAYCAST 169 179 Debug<<"PR4"<<flush;
Note: See TracChangeset
for help on using the changeset viewer.