- Timestamp:
- 11/28/06 19:46:36 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp
r1584 r1824 22 22 23 23 int InternalRayCaster::CastRay(const SimpleRay &simpleRay, 24 VssRayContainer &vssRays, 25 const AxisAlignedBox3 &box, 26 const bool castDoubleRay, 27 const bool pruneInvalidRays 28 ) 29 { 30 //cout << "internal ray" << endl; 24 VssRayContainer &vssRays, 25 const AxisAlignedBox3 &box, 26 const bool castDoubleRay, 27 const bool pruneInvalidRays 28 ) 29 { 30 if (simpleRay.mType == Ray::GLOBAL_RAY) 31 return CastGlobalRay(simpleRay, vssRays, box, pruneInvalidRays); 32 33 //cout << "internal ray" << endl; 31 34 static Ray ray; 32 35 int hits = 0; … … 53 56 } 54 57 55 mPreprocessor.SetupRay(ray, simpleRay.mOrigin, -simpleRay.mDirection);56 ray.mFlags &= ~Ray::CULL_BACKFACES;57 58 58 59 if (castDoubleRay && mKdTree->CastRay(ray)) 59 { 60 hitB.mObject = ray.intersections[0].mObject; 61 hitB.mPoint = ray.Extrap(ray.intersections[0].mT); 62 hitB.mNormal = ray.intersections[0].mNormal; 60 { 61 mPreprocessor.SetupRay(ray, simpleRay.mOrigin, -simpleRay.mDirection); 62 ray.mFlags &= ~Ray::CULL_BACKFACES; 63 hitB.mObject = ray.intersections[0].mObject; 64 hitB.mPoint = ray.Extrap(ray.intersections[0].mT); 65 hitB.mNormal = ray.intersections[0].mNormal; 66 } 67 68 return ProcessRay( 69 simpleRay, 70 hitA, 71 hitB, 72 vssRays, 73 box, 74 castDoubleRay, 75 pruneInvalidRays 76 ); 77 } 78 79 80 int 81 InternalRayCaster::CastGlobalRay(const SimpleRay &simpleRay, 82 VssRayContainer &vssRays, 83 const AxisAlignedBox3 &box, 84 const bool pruneInvalidRays 85 ) 86 { 87 static Ray ray; 88 int hits = 0; 89 mPreprocessor.SetupRay(ray, simpleRay.mOrigin, simpleRay.mDirection); 90 91 float tmin, tmax; 92 if (!(box.ComputeMinMaxT(ray, &tmin, &tmax) && (tmin < tmax))) 93 return 0; 94 95 // shift the ray origin to tmin 96 // Vector3 origin = ray.Extrap(tmin); 97 // mPreprocessor.SetupRay(ray, origin, simpleRay.mDirection); 98 ray.SetType(Ray::GLOBAL_RAY); 99 ray.mFlags &= ~Ray::CULL_BACKFACES; 100 101 102 VssRay *vssRay; 103 104 if (mKdTree->CastRay(ray)) { 105 // sort intersections 106 ray.SortIntersections(); 107 //cout<<"I="<<ray.intersections.size()<<endl; 108 109 110 Ray::Intersection &hit = ray.intersections[0]; 111 112 if (DotProd(hit.mNormal, ray.GetDir()) < 0) { 113 // insert intial segment 114 vssRay = new VssRay( 115 ray.Extrap(tmin), 116 ray.Extrap(hit.mT), 117 NULL, 118 hit.mObject, 119 mPreprocessor.mPass, 120 simpleRay.mPdf 121 ); 122 vssRay->mFlags |= VssRay::Valid; 123 vssRays.push_back(vssRay); 124 ++hits; 125 } 126 127 hit = ray.intersections[ray.intersections.size()-1]; 128 if (DotProd(hit.mNormal, ray.GetDir()) > 0) { 129 130 // insert termination segment 131 vssRay = new VssRay( 132 ray.Extrap(tmax), 133 ray.Extrap(hit.mT), 134 NULL, 135 hit.mObject, 136 mPreprocessor.mPass, 137 simpleRay.mPdf 138 ); 139 vssRay->mFlags |= VssRay::Valid; 140 vssRays.push_back(vssRay); 141 ++hits; 142 } 143 144 // insert the rest of segments 145 for (int i=0; i < ray.intersections.size() - 1; i++) { 146 Ray::Intersection &hitA = ray.intersections[i]; 147 Ray::Intersection &hitB = ray.intersections[i + 1]; 148 if (DotProd(hitA.mNormal, ray.GetDir()) > 0 && 149 DotProd(hitB.mNormal, ray.GetDir()) < 0 150 ) { 151 152 vssRay = new VssRay( 153 ray.Extrap(hitA.mT), 154 ray.Extrap(hitB.mT), 155 hitA.mObject, 156 hitB.mObject, 157 mPreprocessor.mPass, 158 simpleRay.mPdf 159 ); 160 vssRay->mFlags |= VssRay::Valid; 161 vssRays.push_back(vssRay); 162 ++hits; 163 164 vssRay = new VssRay( 165 ray.Extrap(hitB.mT), 166 ray.Extrap(hitA.mT), 167 hitB.mObject, 168 hitA.mObject, 169 mPreprocessor.mPass, 170 simpleRay.mPdf 171 ); 172 173 vssRay->mFlags |= VssRay::Valid; 174 vssRays.push_back(vssRay); 175 ++hits; 176 } 177 } 63 178 } 64 65 return ProcessRay( 66 simpleRay, 67 hitA, 68 hitB, 69 vssRays, 70 box, 71 castDoubleRay, 72 pruneInvalidRays 73 ); 74 } 75 179 180 return hits; 181 } 76 182 77 183 void InternalRayCaster::CastRays16(const int index, 78 79 80 81 82 184 SimpleRayContainer &rays, 185 VssRayContainer &vssRays, 186 const AxisAlignedBox3 &sbox, 187 const bool castDoubleRays, 188 const bool pruneInvalidRays) 83 189 { 84 190 const int num = 16;
Note: See TracChangeset
for help on using the changeset viewer.