Changeset 2001 for GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.cpp
- Timestamp:
- 01/20/07 14:03:37 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.cpp
r1997 r2001 9 9 #include "RndGauss.h" 10 10 #include "Mutation.h" 11 #include "Exporter.h" 11 12 12 13 #ifdef GTP_INTERNAL … … 20 21 21 22 #define USE_SIL_TERMINATION_MUTATION 1 23 #define MUTATE_ORIGIN 1 22 24 23 25 #define EVALUATE_MUTATION_STATS 1 26 27 #define Q_SEARCH_STEPS 2 24 28 25 29 void … … 51 55 int dummyNcMutations = 0; 52 56 int dummyCMutations = 0; 57 58 int reverseCandidates = 0; 53 59 54 60 for (int i=0; i < vssRays.size(); i++) { … … 86 92 *mRays[mBufferStart].mRay = *vssRays[i]; 87 93 mRays[mBufferStart].mMutations = 0; 94 mRays[mBufferStart].ResetReverseMutation(); 88 95 // mRays[mBufferStart] = RayEntry(newRay); 89 96 mBufferStart++; 90 97 if (mBufferStart >= mMaxRays) 91 98 mBufferStart = 0; 99 100 92 101 } 93 102 } else { 94 #if EVALUATE_MUTATION_STATS95 103 if (vssRays[i]->mDistribution == MUTATION_BASED_DISTRIBUTION && 96 104 vssRays[i]->mGeneratorId != -1 97 105 ) { 106 // check whether not to store a new backward mutation candidate 107 VssRay *oldRay = mRays[vssRays[i]->mGeneratorId].mRay; 108 VssRay *newRay = vssRays[i]; 109 110 #define DIST_THRESHOLD 3.0f 111 112 Intersectable *oldObject = 113 mPreprocessor.mViewCellsManager->GetIntersectable( 114 *oldRay, 115 true); 116 117 118 if (!mRays[newRay->mGeneratorId].HasReverseMutation()) { 119 if (DotProd(oldRay->GetDir(), newRay->GetDir()) > 0.0f) { 120 float oldDist = Magnitude(oldRay->mTermination - newRay->mOrigin); 121 float newDist = Magnitude(newRay->mTermination - newRay->mOrigin); 122 123 if (newDist < oldDist - oldObject->GetBox().Radius()*DIST_THRESHOLD) { 124 Vector3 origin, termination; 125 if (ComputeReverseMutation(*oldRay, *newRay, origin, termination)) { 126 mRays[newRay->mGeneratorId].SetReverseMutation(origin, termination); 127 } 128 129 reverseCandidates++; 130 //mReverseCandidates 131 } 132 } 133 } 134 #if EVALUATE_MUTATION_STATS 98 135 mutationRays++; 99 136 100 137 Intersectable *newObject = 101 138 mPreprocessor.mViewCellsManager->GetIntersectable( … … 103 140 true); 104 141 105 Intersectable *oldObject =106 mPreprocessor.mViewCellsManager->GetIntersectable(107 *mRays[vssRays[i]->mGeneratorId].mRay,108 true);109 142 110 143 if (oldObject == newObject) 111 144 dummyNcMutations++; 145 #endif 112 146 } 113 #endif114 147 } 115 148 } 116 149 117 150 if (mutationRays) { 118 151 cout<<"Mutated rays:"<<mutationRays<<endl; … … 121 154 cout<<"Dummy NC mutations ratio:"<<100.0f*dummyNcMutations/(float)mutationRays<<"%"<<endl; 122 155 cout<<"Dummy C mutations ratio:"<<100.0f*dummyCMutations/(float)mutationRays<<"%"<<endl; 156 cout<<"Reverse candidates:"<<reverseCandidates<<endl; 123 157 } 124 158 … … 259 293 } 260 294 295 bool 296 MutationBasedDistribution::ComputeReverseMutation( 297 const VssRay &oldRay, 298 const VssRay &newRay, 299 Vector3 &origin, 300 Vector3 &termination 301 ) 302 { 303 // first reconstruct the termination point 304 Vector3 oldDir = Normalize(oldRay.GetDir()); 305 Plane3 oldPlane(oldDir, oldRay.mTermination); 306 307 termination = oldPlane.FindIntersection(newRay.mOrigin, 308 newRay.mTermination); 309 310 // now find the new origin of the ray by casting ray backward from the termination and termining 311 // silhouette point with respect to the occluding object (object containing the newRay termination) 312 313 Plane3 newPlane(oldDir, newRay.mTermination); 314 315 Vector3 oldPivot = newPlane.FindIntersection(oldRay.mOrigin, 316 oldRay.mTermination); 317 318 Vector3 newPivot = newRay.mTermination; 319 Vector3 line = 2.0f*(oldPivot - newPivot); 320 321 Intersectable *occluder = mPreprocessor.mViewCellsManager->GetIntersectable( 322 newRay, 323 true); 324 325 AxisAlignedBox3 box = occluder->GetBox(); 326 box.Scale(2.0f); 327 328 const int packetSize = 4; 329 static int hit_triangles[packetSize]; 330 static float dist[packetSize]; 331 static Vector3 dirs[packetSize]; 332 static Vector3 shifts[packetSize]; 333 // now find the silhouette along the line 334 int i; 335 float left = 0.0f; 336 float right = 1.0f; 337 // cast rays to find silhouette ray 338 for (int j=0; j < Q_SEARCH_STEPS; j++) { 339 for (i=0; i < packetSize; i++) { 340 float r = left + (i+1)*(right-left)/(packetSize+1); 341 shifts[i] = r*line; 342 dirs[i] = Normalize(newPivot + shifts[i] - termination ); 343 mlrtaStoreRayASEye4(&termination.x, 344 &dirs[i].x, 345 i); 346 } 347 348 mlrtaTraverseGroupASEye4(&box.Min().x, 349 &box.Max().x, 350 hit_triangles, 351 dist); 352 353 for (i=0; i < packetSize; i++) { 354 if (hit_triangles[i] == -1) { 355 // break on first passing ray 356 break; 357 } 358 } 359 float rr = left + (i+1)*(right-left)/(packetSize+1); 360 float rl = left + i*(right-left)/(packetSize+1); 361 left = rl; 362 right = rr; 363 } 364 365 float t = right; 366 if (right==1.0f) 367 return false; 368 369 if (i == packetSize) 370 origin = newPivot + right*line; 371 else 372 origin = newPivot + shifts[i]; 373 374 if (0) { 375 376 static VssRayContainer rRays; 377 static int counter = 0; 378 char filename[256]; 379 380 if (counter < 50) { 381 sprintf(filename, "reverse_rays_%03d.x3d", counter++); 382 383 VssRay tRay(origin, termination, NULL, NULL); 384 rRays.push_back((VssRay *)&oldRay); 385 rRays.push_back((VssRay *)&newRay); 386 rRays.push_back(&tRay); 387 388 Exporter *exporter = NULL; 389 exporter = Exporter::GetExporter(filename); 390 391 exporter->SetFilled(); 392 393 Intersectable *occludee = mPreprocessor.mViewCellsManager->GetIntersectable( 394 oldRay, 395 true); 396 397 exporter->SetForcedMaterial(RgbColor(0,0,1)); 398 exporter->ExportIntersectable(occluder); 399 exporter->SetForcedMaterial(RgbColor(0,1,0)); 400 exporter->ExportIntersectable(occludee); 401 exporter->ResetForcedMaterial(); 402 403 exporter->SetWireframe(); 404 405 406 exporter->ExportRays(rRays, RgbColor(1, 0, 0)); 407 delete exporter; 408 rRays.clear(); 409 } 410 } 411 412 413 414 return true; 415 416 // now the origin and termination is swapped compred to the generator ray 417 // swap(origin, termination);??? 418 // -> perhaps not neccessary as the reverse mutation wil only be used once! 419 } 261 420 262 421 Vector3 … … 270 429 ) 271 430 { 272 const int packetSize = 16; 273 431 const int packetSize = 4; 274 432 static int hit_triangles[packetSize]; 275 433 static float dist[packetSize]; 276 434 static Vector3 dirs[packetSize]; 435 static Vector3 shifts[packetSize]; 277 436 // mutate the 278 437 float alpha = RandomValue(0.0f, 2.0f*M_PI); 438 //float alpha = vr2.x*2.0f*M_PI; 279 439 280 440 // direction along which we will mutate the ray … … 283 443 // cout<<line<<endl; 284 444 // create 16 rays along the selected dir 285 445 int i; 446 float left = 0.0f; 447 float right = radius; 286 448 // cast rays to find silhouette ray 287 for (int i=0; i < packetSize; i++) { 288 dirs[i] = Normalize(ray.mTermination + ((radius/(packetSize - i))*line) - origin ); 289 mlrtaStoreRayAS16(&origin.x, 290 &dirs[i].x, 291 i); 292 } 293 294 mlrtaTraverseGroupAS16(&box.Min().x, 295 &box.Max().x, 296 hit_triangles, 297 dist); 298 299 for (int i=0; i < packetSize; i++) { 300 if (hit_triangles[i] == -1 || !box.IsInside(origin + dist[i]*dirs[i])) { 301 // break on first passing ray 302 break; 449 for (int j=0; j < Q_SEARCH_STEPS; j++) { 450 for (i=0; i < packetSize; i++) { 451 float r = left + (i+1)*(right-left)/(packetSize+1); 452 shifts[i] = r*line; 453 dirs[i] = Normalize(ray.mTermination + shifts[i] - origin ); 454 mlrtaStoreRayASEye4(&origin.x, 455 &dirs[i].x, 456 i); 303 457 } 458 459 mlrtaTraverseGroupASEye4(&box.Min().x, 460 &box.Max().x, 461 hit_triangles, 462 dist); 463 464 for (i=0; i < packetSize; i++) { 465 if (hit_triangles[i] == -1) { 466 // if (hit_triangles[i] == -1 || !box.IsInside(origin + dist[i]*dirs[i])) { 467 // break on first passing ray 468 break; 469 } 470 } 471 float rr = left + (i+1)*(right-left)/(packetSize+1); 472 float rl = left + i*(right-left)/(packetSize+1); 473 left = rl; 474 right = rr; 304 475 } 305 476 … … 307 478 // cerr<<"Warning: hit the same box here should never happen!"<<endl; 308 479 // shift the ray even a bit more 309 // cout<<"W"<<i<<endl; 310 return ray.mTermination + (RandomValue(1.0f, 2.0f)*radius)*line; 311 } 312 480 //cout<<"W"<<i<<endl; 481 // return (RandomValue(1.0f, 1.5f)*radius)*line; 482 return right*line; 483 } 484 313 485 // cout<<i<<endl; 314 return dirs[i];486 return shifts[i]; 315 487 } 316 488 … … 386 558 mLastIndex = index; 387 559 560 if (mRays[index].HasReverseMutation()) { 561 //cout<<"R "<<mRays[index].mutatedOrigin<<" "<<mRays[index].mutatedTermination<<endl; 562 sray = SimpleRay(mRays[index].mutatedOrigin, 563 Normalize(mRays[index].mutatedTermination - mRays[index].mutatedOrigin), 564 MUTATION_BASED_DISTRIBUTION, 1.0f); 565 sray.mGeneratorId = index; 566 mRays[index].ResetReverseMutation(); 567 mRays[index].mMutations++; 568 return true; 569 } 570 388 571 #if USE_SILHOUETTE_MUTATIONS 389 572 return GenerateSilhouetteMutation(index, sray); … … 391 574 return GenerateMutation(index, sray); 392 575 #endif 393 394 576 } 395 577 … … 410 592 411 593 mRays[index].mHalton.GetNext(4, rr); 594 // rr[0] = RandomValue(0.0f,0.99999f); 595 // rr[1] = RandomValue(0.0f,0.99999f); 596 // rr[2] = RandomValue(0.0f,0.99999f); 597 // rr[3] = RandomValue(0.0f,0.99999f); 412 598 413 599 // mutate the origin … … 430 616 // optimal for Vienna 0.5f 431 617 432 float radiusExtension = 0. 05f;618 float radiusExtension = 0.5f; 433 619 // + mRays[index].mMutations/50.0f; 434 620 435 621 float mutationRadius = objectRadius*radiusExtension; 436 622 437 623 // tmp for pompeii 438 mutationRadius = 0.22f; 439 624 // mutationRadius = 0.22f; 625 626 #if MUTATE_ORIGIN 440 627 origin += ComputeOriginMutation(*ray, U, V, 441 628 Vector2(rr[0], rr[1]), 442 629 mutationRadius); 630 #endif 443 631 444 632 #if USE_SIL_TERMINATION_MUTATION … … 448 636 U, V, 449 637 Vector2(rr[2], rr[3]), 450 3.0f*objectRadius);638 2.0f*objectRadius); 451 639 #else 452 640 termination += ComputeTerminationMutation(*ray, U, V,
Note: See TracChangeset
for help on using the changeset viewer.