Changeset 1932 for GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
- Timestamp:
- 01/03/07 01:36:35 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
r1928 r1932 46 46 Debug << "eps: " << mEps << endl; 47 47 48 m Stats.open("gvspreprocessor.log");48 mGvsStats.open("gvspreprocessor.log"); 49 49 } 50 50 … … 54 54 const VssRay &oldRay) 55 55 { 56 const float dist = Magnitude(oldRay.GetDir());57 const float newDist = Magnitude(currentRay.GetDir());58 59 #if 0 60 if ((dist - newDist) > mThresHold)61 #else 62 // rather take relative distance63 if (( dist / newDist) > mThreshold)64 #endif 65 {56 // the predicted hitpoint: we expect to hit the same mesh again 57 const Vector3 predictedHit = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay); 58 59 const float predictedLen = Magnitude(predictedHit - currentRay.mOrigin); 60 const float len = Magnitude(currentRay.mTermination - currentRay.mOrigin); 61 62 // distance large => this is likely to be a discontinuity 63 if ((predictedLen - len) > mThreshold) 64 { 65 cout << "d"; 66 66 VssRay *newRay = ReverseSampling(currentRay, hitTriangle, oldRay); 67 67 68 // set flag for visualization 68 69 newRay->mFlags |= VssRay::ReverseSample; 69 70 70 // ray is not pushed into the queue=> can delete ray71 // if ray is not further processed => can delete ray 71 72 if (!HandleRay(newRay)) 72 73 delete newRay; … … 81 82 bool GvsPreprocessor::HandleRay(VssRay *vssRay) 82 83 { 84 // compute the contribution to the view cells 83 85 const bool storeRaysForViz = true; 84 mViewCellsManager->ComputeSampleContribution(*vssRay, true, storeRaysForViz); 85 86 mViewCellsManager->ComputeSampleContribution(*vssRay, 87 true, 88 storeRaysForViz); 89 86 90 // some pvs contribution for this ray? 87 91 if (vssRay->mPvsContribution > 0) … … 92 96 if (storeRaysForViz) 93 97 { 98 VssRay *nray = new VssRay(*vssRay); 99 nray->mFlags = vssRay->mFlags; 100 101 // store ray in contributing view cell 94 102 ViewCellContainer::const_iterator vit, vit_end = vssRay->mViewCells.end(); 95 103 for (vit = vssRay->mViewCells.begin(); vit != vit_end; ++ vit) 96 { 97 VssRay *nray = new VssRay(*vssRay); 104 { 98 105 (*vit)->GetOrCreateRays()->push_back(nray); 99 106 } 100 107 } 108 101 109 //mVssRays.push_back(new VssRay(*vssRay)); 102 110 ++ mSampleContriPerPass; … … 111 119 /** Creates 3 new vertices for triangle vertex with specified index. 112 120 */ 113 static void CreateNewVertices(VertexContainer &vertices, 114 const Triangle3 &hitTriangle, 115 const VssRay &ray, 116 const int index, 117 const float eps) 121 void GvsPreprocessor::CreateDisplacedVertices(VertexContainer &vertices, 122 const Triangle3 &hitTriangle, 123 const VssRay &ray, 124 const int index) const 118 125 { 119 126 const int indexU = (index + 1) % 3; … … 125 132 126 133 const float len = Magnitude(a); 127 134 128 135 const Vector3 dir1 = Normalize(CrossProd(a, b)); //N((pi-xp)×(pi+1- pi)); 129 136 const Vector3 dir2 = Normalize(CrossProd(a, c)); // N((pi-xp)×(pi- pi-1)) … … 133 140 // compute the new three hit points 134 141 // pi, i + 1: pi+ e·|pi-xp|·di, j 135 const Vector3 pt1 = hitTriangle.mVertices[index] + eps * len * dir1;142 const Vector3 pt1 = hitTriangle.mVertices[index] + mEps * len * dir1; 136 143 // pi, i - 1: pi+ e·|pi-xp|·di, j 137 const Vector3 pt2 = hitTriangle.mVertices[index] + eps * len * dir2;144 const Vector3 pt2 = hitTriangle.mVertices[index] + mEps * len * dir2; 138 145 // pi, i: pi+ e·|pi-xp|·di, j 139 const Vector3 pt3 = hitTriangle.mVertices[index] + eps * len * dir3;146 const Vector3 pt3 = hitTriangle.mVertices[index] + mEps * len * dir3; 140 147 141 148 vertices.push_back(pt2); … … 147 154 void GvsPreprocessor::EnlargeTriangle(VertexContainer &vertices, 148 155 const Triangle3 &hitTriangle, 149 const VssRay &ray) 150 { 151 CreateNewVertices(vertices, hitTriangle, ray, 0, mEps); 152 CreateNewVertices(vertices, hitTriangle, ray, 1, mEps); 153 CreateNewVertices(vertices, hitTriangle, ray, 2, mEps); 154 } 155 156 157 static Vector3 CalcPredictedHitPoint(const VssRay &newRay, 158 const Triangle3 &hitTriangle, 159 const VssRay &oldRay) 160 { 156 const VssRay &ray) const 157 { 158 CreateDisplacedVertices(vertices, hitTriangle, ray, 0); 159 CreateDisplacedVertices(vertices, hitTriangle, ray, 1); 160 CreateDisplacedVertices(vertices, hitTriangle, ray, 2); 161 } 162 163 164 Vector3 GvsPreprocessor::CalcPredictedHitPoint(const VssRay &newRay, 165 const Triangle3 &hitTriangle, 166 const VssRay &oldRay) const 167 { 168 // find the intersection of the plane induced by the 169 // hit triangle with the new ray 161 170 Plane3 plane(hitTriangle.GetNormal(), hitTriangle.mVertices[0]); 162 171 … … 177 186 const Vector3 &p1, 178 187 const Vector3 &p2, 179 const VssRay & x,180 const VssRay & y,188 const VssRay &ray1, 189 const VssRay &ray2, 181 190 const VssRay &oldRay) 182 191 { 183 // the predicted hitpoint expects to hit the same mesh again 184 const Vector3 predictedHitX = CalcPredictedHitPoint(x, hitTriangle, oldRay); 185 const Vector3 predictedHitY = CalcPredictedHitPoint(y, hitTriangle, oldRay); 186 187 CheckDiscontinuity(x, hitTriangle, oldRay); 188 CheckDiscontinuity(y, hitTriangle, oldRay); 189 190 if (EqualVisibility(x, y)) 192 CheckDiscontinuity(ray1, hitTriangle, oldRay); 193 CheckDiscontinuity(ray2, hitTriangle, oldRay); 194 195 if (EqualVisibility(ray1, ray2) || (Magnitude(p1 - p2) <= mEps)) 191 196 { 192 197 return 0; … … 194 199 else 195 200 { 196 cout << "s";201 // the new subdivision point 197 202 const Vector3 p = (p1 + p2) * 0.5f; 203 204 //cout << "tobj " << ray1.mTerminationObject << " " << ray2.mTerminationObject << " " << p1 << " " << p2 << endl; 205 //cout << "term " << ray1.mTermination << " " << ray2.mTermination << endl; 206 207 // cast ray into the new point 198 208 SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin, SamplingStrategy::GVS, 1.0f); 199 209 200 // cast ray into the new subdivision point 201 VssRay *newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox(), false); 202 210 VssRay *newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox()); 211 203 212 if (!newRay) return 0; 204 213 … … 209 218 210 219 // subdivide further 211 const int s1 = SubdivideEdge(hitTriangle, p1, p, x, *newRay, oldRay); 212 const int s2 = SubdivideEdge(hitTriangle, p, p2, *newRay, y, oldRay); 213 220 const int samples1 = SubdivideEdge(hitTriangle, p1, p, ray1, *newRay, oldRay); 221 const int samples2 = SubdivideEdge(hitTriangle, p, p2, *newRay, ray2, oldRay); 222 223 // this ray will not be further processed 214 224 if (!enqueued) 215 225 delete newRay; 216 226 217 return s 1 +s2 + 1;227 return samples1 + samples2 + 1; 218 228 } 219 229 } … … 222 232 int GvsPreprocessor::AdaptiveBorderSampling(const VssRay ¤tRay) 223 233 { 224 cout << "a";225 234 Intersectable *tObj = currentRay.mTerminationObject; 226 235 Triangle3 hitTriangle; … … 245 254 simpleRays.reserve(9); 246 255 256 //cout << "currentRay: " << currentRay.mOrigin << " dir: " << currentRay.GetDir() << endl; 257 247 258 VertexContainer::const_iterator vit, vit_end = enlargedTriangle.end(); 248 259 … … 252 263 SimpleRay sr(currentRay.GetOrigin(), rayDir, SamplingStrategy::GVS, 1.0f); 253 264 simpleRays.AddRay(sr); 254 } 255 256 // visualize enlarged triangles 265 266 //cout << "new: " << sr.mOrigin << " dist: " << sr.mDirection << endl; 267 } 268 257 269 if (0) 258 270 { 271 // visualize enlarged triangles 259 272 VizStruct dummy; 260 273 dummy.enlargedTriangle = new Polygon3(enlargedTriangle); 261 274 dummy.originalTriangle = hitTriangle; 262 //dummy.ray = new VssRay(currentRay);263 275 vizContainer.push_back(dummy); 264 276 } … … 266 278 // cast rays to triangle vertices and determine visibility 267 279 VssRayContainer vssRays; 268 CastRays(simpleRays, vssRays, false, false); 280 281 // don't cast double rays as we need only the forward rays 282 const bool castDoubleRays = false; 283 // cannot prune invalid rays because we have to 284 // compare adjacent rays. 285 const bool pruneInvalidRays = false; 286 287 CastRays(simpleRays, vssRays, castDoubleRays, pruneInvalidRays); 269 288 270 289 // set flags … … 275 294 } 276 295 277 // add to ray queue296 // handle rays 278 297 EnqueueRays(vssRays); 279 298 … … 282 301 283 302 // recursivly subdivide each edge 284 for (int i = 0; 1 && (i < n); ++ i) 285 { 286 castRays += SubdivideEdge( 287 hitTriangle, 288 enlargedTriangle[i], 289 enlargedTriangle[(i + 1) % n], 290 *vssRays[i], 291 *vssRays[(i + 1) % n], 292 currentRay); 303 for (int i = 0; i < n; ++ i) 304 { 305 castRays += SubdivideEdge(hitTriangle, 306 enlargedTriangle[i], 307 enlargedTriangle[(i + 1) % n], 308 *vssRays[i], 309 *vssRays[(i + 1) % n], 310 currentRay); 293 311 } 294 312 295 313 mBorderSamples += castRays; 314 296 315 return castRays; 297 316 } 298 317 299 318 300 static Vector3GetPassingPoint(const VssRay ¤tRay,301 302 const VssRay &oldRay)303 { 304 // intersect triangle plane with plane spanned by current samples319 Vector3 GvsPreprocessor::GetPassingPoint(const VssRay ¤tRay, 320 const Triangle3 &hitTriangle, 321 const VssRay &oldRay) const 322 { 323 //-- intersect triangle plane with plane spanned by current samples 305 324 Plane3 plane(currentRay.GetOrigin(), currentRay.GetTermination(), oldRay.GetTermination()); 306 325 Plane3 triPlane(hitTriangle.GetNormal(), hitTriangle.mVertices[0]); … … 310 329 // Evaluate new hitpoint just outside the triangle 311 330 const float factor = 0.95f; 312 float t = triPlane.FindT(intersectLine);331 const float t = triPlane.FindT(intersectLine); 313 332 const Vector3 newPoint = intersectLine.mOrigin + t * factor * intersectLine.mDirection; 314 333 … … 329 348 const Vector3 predicted = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay); 330 349 331 //-- Construct the mutated ray with xnew, dir = predicted(x)- pnew332 //-- as direction vector350 //-- Construct the mutated ray with xnew, 351 //-- dir = predicted(x)- pnew as direction vector 333 352 const Vector3 newDir = predicted - newPoint ; 353 334 354 // take xnew,p = intersect(viewcell, line(pnew, predicted(x)) as origin ? 335 355 // difficult to say!! … … 438 458 else if (0) 439 459 { 440 //-- load view cells from file441 460 //-- test successful view cells loading by exporting them again 442 461 VssRayContainer dummies; … … 451 470 //////// 452 471 //-- stats 472 453 473 cout << "\nPass " << mPass << " #samples: " << castSamples << " of " << mTotalSamples << endl; 454 455 //mVssRays.PrintStatistics(mStats); 456 mStats 474 //mVssRays.PrintStatistics(mGvsStats); 475 mGvsStats 457 476 << "#Pass\n" << mPass << endl 458 477 << "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl … … 464 483 << "#GvsRuns\n" << mGvsPass << endl; 465 484 466 mViewCellsManager->PrintPvsStatistics(m Stats);485 mViewCellsManager->PrintPvsStatistics(mGvsStats); 467 486 468 487 char str[64]; sprintf(str, "tmp/pass%04d-", mPass); … … 489 508 } 490 509 491 cout << 2 * castSamples / (1e3f * TimeDiff(startTime, GetTime())) << "M rays/s" << endl;510 cout << "cast " << 2 * castSamples / (1e3f * TimeDiff(startTime, GetTime())) << "M rays/s" << endl; 492 511 Visualize(); 493 512
Note: See TracChangeset
for help on using the changeset viewer.