Changeset 2629
- Timestamp:
- 01/23/08 00:21:50 (17 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Camera.cpp
r2603 r2629 7 7 #include <cassert> 8 8 9 #include "common.h" 9 10 #include "Camera.h" 10 11 #include "Ray.h" … … 16 17 #include "Preprocessor.h" 17 18 #include "RayCaster.h" 18 19 #ifdef USE_HAVRAN_RAYCASTER 19 #include "tgaimg.h" 20 21 #ifdef USE_HAVRAN_RAYCASTER 20 22 //#include "timer.h" 21 #include "ktbconf.h"22 23 #include "raypack.h" 23 24 #endif … … 54 55 55 56 bool exportRays = false; 56 57 58 InitDevIl(); 59 int components = 4; 60 float *buffer = new float[components*mWidth*mHeight]; 61 float *pbuffer = buffer; 62 // - components*mWidth; 57 CTGAImage tgaimg; tgaimg.Init(mWidth, mHeight); 63 58 64 59 vector<Ray *> rays; … … 69 64 70 65 for (y = 0; y < mHeight; y++) { 71 cout<<"+" ;66 cout<<"+" << flush; 72 67 for (x = 0; x < mWidth; x++) { 73 68 SetupRay(ray, mWidth - (x + 1), mHeight - (y + 1)); … … 91 86 if (mesh->GetMesh()->mMaterial) 92 87 color = mesh->GetMesh()->mMaterial->mDiffuseColor; 93 94 pbuffer[0] = color.r; 95 pbuffer[1] = color.g; 96 pbuffer[2] = color.b; 97 pbuffer[3] = 1.0f; 98 88 89 tgaimg.SetPixel(x, y, color.r * 255.f, color.g * 255.f, color.b * 255.f); 99 90 } 100 91 } 101 pbuffer+=components;102 103 // if (exportRays && ( 1||(x==222) && (y==97))) {104 // if (exportRays && ((x%4==0) && (y%4==0))) {105 106 // if (exportRays && ray.intersections.empty()) {107 92 if (debug) { 108 109 93 Ray *nray = new Ray(ray); 94 rays.push_back(nray); 110 95 } 111 96 } 112 // pbuffer-=2*components*mWidth;113 97 } 114 98 … … 119 103 120 104 cout<<"Saving image"<<endl; 121 122 ilRegisterType(IL_FLOAT); 123 ilTexImage(mWidth, mHeight, 1, 4, IL_RGBA, IL_FLOAT, buffer); 124 ilSaveImage((char *const)filename.c_str()); 125 delete buffer; 105 tgaimg.SaveToFile(filename.c_str()); 126 106 127 107 cout<<"done."<<endl<<flush; … … 183 163 Vector3 xv = mRight*((x - mWidth/2)/(float)mWidth); 184 164 Vector3 yv = mUp*((y - mHeight/2)/(float)mHeight); 185 Vector3 target = xv + yv + mDirection; 186 Vector3 dir = target - mPosition; 165 Vector3 dir = mDirection - xv + yv; 187 166 dir.Normalize(); 188 167 … … 202 181 203 182 bool exportRays = false; 204 205 206 InitDevIl(); 207 int components = 4; 208 float *buffer = new float[components*mWidth*mHeight]; 209 assert(buffer); 210 float *pbuffer = buffer; 211 // - components*mWidth; 183 CTGAImage tgaimg; tgaimg.Init(mWidth, mHeight); 184 tgaimg.FillInImage(0.0, 0.0f, 200.f); 212 185 213 186 vector<Ray *> rays; … … 218 191 VssRayContainer vssRays; 219 192 193 bool doubleRays = true; 194 bool exploitDoubleRays = true; 195 if (!doubleRays) 196 exploitDoubleRays = false; 197 220 198 //CTimer timer; 221 199 //timer.Start(); 222 200 223 for (y = 0; y < mHeight; y++) { 224 cout<<"+"; 201 //int ystart = 92; 202 int xstart = 0; 203 int ymax = mHeight; 204 for (y = 0; y < ymax; y++) { 205 cout<<"+" << flush; 225 206 for (x = 0; x < mWidth; x++) { 226 SetupRay(ray, mWidth - (x + 1), mHeight - (y + 1)); 227 228 bool debug = true; 207 SetupRay(ray, x, y); 208 if (exploitDoubleRays) 209 ray.mDirection = - ray.mDirection; 210 211 bool debug = false; 229 212 // (y == mHeight/2) && (x== mWidth/3); 230 213 // MeshDebug = debug; 231 232 214 233 215 int res = raycaster->CastRay(ray, 234 216 vssRays, 235 217 bbox, 236 false, // castDoubleRay,218 doubleRays, // castDoubleRay, 237 219 false); // pruneInvalidRays 220 221 // cout << "End ------------------------ " 222 // << SimpleRay::IntersectionRes[0].intersectable 223 // << " t = " << SimpleRay::IntersectionRes[0].tdist 224 // << endl; 238 225 239 226 if (res) { 240 Vector3 normal = raycaster->intersect.mNormal;227 Vector3 normal = SimpleRay::IntersectionRes[0].intersectable->GetNormal(0); 241 228 float v = 242 229 ray.mDirection.x * normal.x + 243 230 ray.mDirection.y * normal.y + 244 231 ray.mDirection.z * normal.z; 245 v *= 1.0f; 246 pbuffer[0] = v; 247 pbuffer[1] = v; 248 pbuffer[2] = v; 249 pbuffer[3] = 1.0f; 232 v = fabs(v); 233 v *= 200.0f; 234 if (v < 50.f) v = 50.f; 235 tgaimg.SetPixel(x, y, v, v, v); 250 236 } 251 else {252 pbuffer[0] = 0.0;253 pbuffer[1] = 0.0;254 pbuffer[2] = 0.0;255 pbuffer[3] = 1.0f;256 }257 pbuffer+=components;258 237 259 238 if (debug) { … … 263 242 } 264 243 } 265 // pbuffer-=2*components*mWidth;266 244 } // for y 267 245 … … 273 251 274 252 cout<<"Saving image"<<endl; 275 276 ilRegisterType(IL_FLOAT); 277 ilTexImage(mWidth, mHeight, 1, 4, IL_RGBA, IL_FLOAT, buffer); 278 ilSaveImage((char *const)filename.c_str()); 279 delete buffer; 253 254 tgaimg.SaveToFile(filename.c_str()); 255 256 //ilRegisterType(IL_FLOAT); 257 //ilTexImage(mWidth, mHeight, 1, 4, IL_RGBA, IL_FLOAT, buffer); 258 //ilSaveImage((char *const)filename.c_str()); 259 //delete buffer; 280 260 281 261 cout<<"done."<<endl<<flush; … … 284 264 } 285 265 266 267 bool 268 Camera::SnapImage2(string filename, 269 RayCaster *raycaster, 270 AxisAlignedBox3 &bbox, 271 SceneGraph *sceneGraph) 272 { 273 int x; 274 int y; 275 276 bool exportRays = false; 277 CTGAImage tgaimg; tgaimg.Init(mWidth, mHeight); 278 tgaimg.FillInImage(0.0, 0.0f, 200.f); 279 280 vector<Ray *> raysDebug; 281 282 long t1 = GetTime(); 283 284 SimpleRay ray; 285 SimpleRayContainer rays; 286 VssRayContainer vssRays; 287 288 bool doubleRays = false; 289 bool exploitDoubleRays = false; 290 int batchSize = 16; 291 if (!doubleRays) 292 exploitDoubleRays = false; 293 int shiftIndex = 0; 294 if (exploitDoubleRays) 295 shiftIndex = batchSize; 296 297 //CTimer timer; 298 //timer.Start(); 299 300 //int ystart = 92; 301 int xstart = 0; 302 int ymax = mHeight; 303 for (y = 0; y < ymax; y++) { 304 if (y == 250) { 305 cout << "Debug y = " << y << endl; 306 } 307 308 cout<<"+" << flush; 309 for (x = 0; x < mWidth; x += batchSize ) { 310 rays.erase(rays.begin(), rays.end()); 311 int xi; 312 for (xi = 0; (xi < batchSize) && (x+xi < mWidth); xi++ ) { 313 SetupRay(ray, x + xi, y); 314 if (exploitDoubleRays) 315 ray.mDirection = -ray.mDirection; 316 rays.push_back(ray); 317 } // for 318 319 bool debug = false; 320 // (y == mHeight/2) && (x== mWidth/3); 321 // MeshDebug = debug; 322 323 #if 1 324 assert(batchSize == 16); 325 raycaster->CastRays16(rays, 326 vssRays, 327 bbox, 328 doubleRays, // castDoubleRay, 329 false); // pruneInvalidRays 330 #else 331 raycaster->CastSimpleForwardRays(rays, bbox); 332 #endif 333 334 // cout << "End ------------------------ " 335 // << SimpleRay::IntersectionRes[0].intersectable 336 // << " t = " << SimpleRay::IntersectionRes[0].tdist 337 // << endl; 338 339 for (xi = 0; (xi < batchSize) && (x+xi < mWidth); xi++ ) { 340 Intersectable* res = 341 SimpleRay::IntersectionRes[xi + shiftIndex].intersectable; 342 343 if (res) { 344 Vector3 normal = res->GetNormal(0); 345 float v = 346 rays[xi].mDirection.x * normal.x + 347 rays[xi].mDirection.y * normal.y + 348 rays[xi].mDirection.z * normal.z; 349 v = fabs(v); 350 v *= 200.0f; 351 if (v < 50.f) v = 50.f; 352 tgaimg.SetPixel(x + xi, y, v, v, v); 353 } 354 } 355 356 if (debug) { 357 Ray *nray = new Ray(ray.mOrigin, ray.mDirection, 358 Ray::LOCAL_RAY); 359 raysDebug.push_back(nray); 360 } 361 } // for x 362 } // for y 363 364 //timer.Stop(); 365 366 long t2 = GetTime(); 367 cout<<"\n#RAY_CAST_TIME = "; 368 cout << TimeDiff(t1, t2)<<" [mikrosec]\n"; 369 370 cout<<"Saving image"<<endl; 371 372 tgaimg.SaveToFile(filename.c_str()); 373 374 //ilRegisterType(IL_FLOAT); 375 //ilTexImage(mWidth, mHeight, 1, 4, IL_RGBA, IL_FLOAT, buffer); 376 //ilSaveImage((char *const)filename.c_str()); 377 //delete buffer; 378 379 cout<<"done."<<endl<<flush; 380 381 return true; 382 } 383 384 286 385 bool 287 386 Camera::SnapImagePacket(string filename, … … 291 390 ) 292 391 { 293 #if defined(USE_HAVRAN_RAYCASTER) && defined(_USE_HAVRAN_SSE) 392 #ifdef USE_HAVRAN_RAYCASTER 393 #ifdef _USE_HAVRAN_SSE 294 394 295 395 int x; 296 396 int y; 297 397 298 bool exportRays = false; 299 300 301 InitDevIl(); 302 int components = 4; 303 float *buffer = new float[components*mWidth*mHeight]; 304 assert(buffer); 305 float *pbuffer = buffer; 398 bool exportRays = false; 399 306 400 // - components*mWidth; 401 CTGAImage tgaimg; tgaimg.Init(mWidth, mHeight); 402 tgaimg.FillInImage(0.0, 0.0f, 200.f); // blue color image 307 403 308 404 vector<Ray *> rays; … … 315 411 //CTimer timer; 316 412 //timer.Start(); 317 318 RayPacket2x2 rp; 413 414 bool doubleRays = false; 415 bool exploitDoubleRays = false; 416 if (!doubleRays) 417 exploitDoubleRays = false; 418 419 GALIGN16 RayPacket2x2 rp; 420 //int ystart = 92; 421 //int xstart = 738; 422 int pixels = 0;; 319 423 for (y = 0; y < mHeight-1; y+=2) { 320 float *pppbuffer = pbuffer; 321 cout<<"+"; 424 //for (y = ystart-2; y > 0; y-=2) { 322 425 for (x = 0; x < mWidth-1; x+=2) { 323 426 int i = 0; 324 427 for (int yi = 0; yi < 2; yi++) { 325 428 for (int xi = 0; xi < 2; xi++) { 326 SetupRay(ray, mWidth - (x+xi + 1), mHeight - (y+yi + 1));429 SetupRay(ray, x+xi, y+yi); 327 430 rp.SetLoc(i, ray.mOrigin); 328 431 rp.SetDir(i, ray.mDirection); 432 if (exploitDoubleRays) 433 rp.SetDir(i, -ray.mDirection); 329 434 i++; 330 435 } // for xi 331 436 } // for yi 332 333 raycaster->CastRaysPacket2x2(rp, false, false); 437 pixels += 4; 438 if (pixels > mWidth) { 439 cout << "+" << flush; 440 pixels = 0; 441 } 442 443 raycaster->CastRaysPacket2x2(rp, doubleRays, false); 334 444 335 445 i = 0; 336 float *ppbuffer = pbuffer;337 446 for (int yi = 0; yi < 2; yi++) { 338 447 for (int xi = 0; xi < 2; xi++) { 339 448 Intersectable* res = rp.GetObject(i); 340 449 if (res) { 341 pbuffer[0] = 1.0f; 342 pbuffer[1] = 1.0f; 343 pbuffer[2] = 1.0f; 344 pbuffer[3] = 1.0f; 345 } 346 else { 347 pbuffer[0] = 0.0; 348 pbuffer[1] = 0.0; 349 pbuffer[2] = 0.0; 350 pbuffer[3] = 1.0f; 450 #if 0 451 // This is debugging code to find a bug 452 for (int j = 0; j < 4; j++) { 453 cout << " j = " << j << " obj = " 454 << rp.GetObject(j) 455 << " t = " << rp.GetT(j); 456 ray.Set(rp.GetLoc(j), rp.GetDir(j), 0, 1.0f, 0); 457 int res = raycaster->CastRay(ray, 458 vssRays, 459 bbox, 460 doubleRays, // castDoubleRay, 461 false); // pruneInvalidRays 462 cout << " correct result obj = " 463 << SimpleRay::IntersectionRes[0].intersectable 464 << " t = " 465 << SimpleRay::IntersectionRes[0].tdist 466 << endl; 467 } // for 468 469 raycaster->CastRaysPacket2x2(rp, false, false); 470 #endif 471 472 Vector3 normal = res->GetNormal(0); 473 float v = 474 ray.mDirection.x * normal.x + 475 ray.mDirection.y * normal.y + 476 ray.mDirection.z * normal.z; 477 v = fabs(v); 478 v *= 200.0f; 479 if (v < 50.f) v = 50.f; 480 tgaimg.SetPixel(x+xi, y+yi, v, v, v); 351 481 } 352 482 i++; 353 ppbuffer += components;354 483 } // xi 355 ppbuffer += components * (mWidth-2);356 484 } // yi 357 358 pbuffer = ppbuffer + 2 * components;359 485 } // for x 360 pbuffer = pppbuffer + mWidth * 2 * components;361 pppbuffer = pbuffer; // for the next time;362 486 } // for y 363 487 … … 369 493 370 494 cout<<"Saving image"<<endl; 371 372 ilRegisterType(IL_FLOAT); 373 ilTexImage(mWidth, mHeight, 1, 4, IL_RGBA, IL_FLOAT, buffer); 374 ilSaveImage((char *const)filename.c_str()); 375 delete buffer; 376 #endif 495 tgaimg.SaveToFile(filename.c_str()); 496 497 #endif // _USE_HAVRAN_SSE 498 #endif // USE_HAVRAN_RAYCASTER 377 499 cout<<"done."<<endl<<flush; 378 500 … … 380 502 } 381 503 382 383 } 504 inline static bool ilt(Intersectable *obj1, Intersectable *obj2) 505 { 506 return obj1->mId < obj2->mId; 507 } 508 509 510 bool 511 Camera::SnapImagePacket2(string filename, 512 RayCaster *raycaster, 513 AxisAlignedBox3 &bbox, 514 SceneGraph *sceneGraph 515 ) 516 { 517 #ifdef USE_HAVRAN_RAYCASTER 518 #ifdef _USE_HAVRAN_SSE 519 520 int x; 521 int y; 522 523 bool exportRays = false; 524 525 // - components*mWidth; 526 CTGAImage tgaimg; tgaimg.Init(mWidth, mHeight); 527 tgaimg.FillInImage(0.0, 0.0f, 200.f); // blue color image 528 529 vector<Ray *> rays; 530 531 long t1 = GetTime(); 532 533 SimpleRay ray; 534 VssRayContainer vssRays; 535 536 //CTimer timer; 537 //timer.Start(); 538 539 bool doubleRays = false; 540 bool exploitDoubleRays = false; 541 if (!doubleRays) 542 exploitDoubleRays = false; 543 544 Vector3 origin4[4]; 545 Vector3 direction4[4]; 546 int result4[4]; 547 float dist4[4]; 548 549 GALIGN16 RayPacket2x2 rp; 550 //int ystart = 92; 551 //int xstart = 738; 552 int pixels = 0;; 553 for (y = 0; y < mHeight-1; y+=2) { 554 //for (y = ystart-2; y > 0; y-=2) { 555 for (x = 0; x < mWidth-1; x+=2) { 556 int i = 0; 557 for (int yi = 0; yi < 2; yi++) { 558 for (int xi = 0; xi < 2; xi++) { 559 SetupRay(ray, x+xi, y+yi); 560 origin4[i] = ray.mOrigin; 561 direction4[i] = ray.mDirection; 562 if (exploitDoubleRays) 563 direction4[i] = -ray.mDirection; 564 i++; 565 } // for xi 566 } // for yi 567 pixels += 4; 568 if (pixels > mWidth) { 569 cout << "+" << flush; 570 pixels = 0; 571 } 572 573 raycaster->CastRaysPacket4(bbox.Min(), bbox.Max(), 574 origin4, 575 direction4, 576 result4, 577 dist4); 578 579 i = 0; 580 for (int yi = 0; yi < 2; yi++) { 581 for (int xi = 0; xi < 2; xi++) { 582 int objId = result4[i]; 583 if (objId != -1) { 584 MeshInstance dummyInst(NULL); 585 dummyInst.SetId(objId); 586 ObjectContainer &objects = preprocessor->mObjects; 587 ObjectContainer::const_iterator oit = 588 lower_bound(objects.begin(), objects.end(), 589 (Intersectable *)&dummyInst, ilt); 590 591 if ((oit != objects.end()) && ((*oit)->GetId() == objId)) { 592 Intersectable *res = *oit; 593 594 Vector3 normal = res->GetNormal(0); 595 float v = 596 ray.mDirection.x * normal.x + 597 ray.mDirection.y * normal.y + 598 ray.mDirection.z * normal.z; 599 v = fabs(v); 600 v *= 200.0f; 601 if (v < 50.f) v = 50.f; 602 tgaimg.SetPixel(x+xi, y+yi, v, v, v); 603 } 604 else { 605 cout <<"*" << endl; 606 } 607 608 } // object intersected 609 i++; 610 } // xi 611 } // yi 612 } // for x 613 } // for y 614 615 //timer.Stop(); 616 617 long t2 = GetTime(); 618 cout<<"\n#RAY_CAST_TIME = "; 619 cout << TimeDiff(t1, t2)<<" [mikrosec]\n"; 620 621 cout<<"Saving image"<<endl; 622 tgaimg.SaveToFile(filename.c_str()); 623 624 #endif // _USE_HAVRAN_SSE 625 #endif // USE_HAVRAN_RAYCASTER 626 cout<<"done."<<endl<<flush; 627 628 return true; 629 } 630 631 } 632 -
GTP/trunk/Lib/Vis/Preprocessing/src/Camera.h
r2575 r2629 4 4 #include "Vector3.h" 5 5 #include "AxisAlignedBox3.h" 6 #include "ktbconf.h" 6 7 7 8 namespace GtpVisibilityPreprocessor { … … 31 32 } 32 33 33 Camera(int width, int height ) {34 Camera(int width, int height, float fieldOfView = 90.f) { 34 35 mWidth = width; 35 36 mHeight = height; 36 mFovy = 90.0f*(float)M_PI/180.0f;37 mFovy = fieldOfView*(float)M_PI/180.0f; 37 38 } 38 39 39 40 40 void Precompute() { … … 87 87 88 88 bool 89 SnapImage2(std::string filename, 90 RayCaster *raycaster, 91 AxisAlignedBox3 &bbox, 92 SceneGraph *sceneGraph 93 ); 94 95 bool 89 96 SnapImagePacket(std::string filename, 90 97 RayCaster *raycaster, … … 92 99 SceneGraph *sceneGraph 93 100 ); 94 101 102 bool 103 SnapImagePacket2(std::string filename, 104 RayCaster *raycaster, 105 AxisAlignedBox3 &bbox, 106 SceneGraph *sceneGraph 107 ); 108 95 109 void SetupRay(Ray &ray, const int x, const int y); 96 110 -
GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp
r2621 r2629 26 26 #define DEBUG_RAYCAST 0 27 27 28 // This macro should be undefined when testing ray tracing29 // by casting rays from file or using camera30 #define _PROCESS_RAY31 32 28 namespace GtpVisibilityPreprocessor { 33 29 34 35 36 #ifdef USE_HAVRAN_RAYCASTER37 30 #ifdef _USE_HAVRAN_SSE 38 39 31 // static rays 40 RayPacket2x232 GALIGN16 RayPacket2x2 41 33 HavranRayCaster::raypack; 42 34 #endif // _USE_HAVRAN_SSE 43 #endif // USE_HAVRAN_RAYCASTER 35 44 36 45 37 HavranRayCaster::HavranRayCaster(const Preprocessor &preprocessor): … … 70 62 71 63 if (!ImportBinTree(kdfile, objlist)) { 72 cout << "\nKd-tree for Havran ray caster imported."<<endl<<flush; 73 } else { 74 CTimer timer; 75 cout << "\nBuilding up kd-tree for Havran ray caster ..."<<endl<<flush; 76 77 timer.Start(); 78 mKtbtree->BuildUp(objlist); 79 timer.Stop(); 80 cout << "\nBuilding up kd-tree is finished, user time = " 81 << timer.UserTime() << " real time = " << timer.RealTime() << 82 endl <<flush; 83 ExportBinTree(kdfile); 64 cout << "\nKd-tree for Havran ray caster imported."<<endl<<flush; 65 } 66 else { 67 CTimer timer; 68 cout << "\nBuilding up kd-tree for Havran ray caster ..."<<endl<<flush; 69 70 timer.Start(); 71 mKtbtree->BuildUp(objlist); 72 timer.Stop(); 73 cout << "\nBuilding up kd-tree is finished, user time = " 74 << timer.UserTime() << " real time = " << timer.RealTime() 75 << endl; 76 ExportBinTree(kdfile); 84 77 } 85 78 #endif … … 513 506 #endif // USE_HAVRAN_RAYCASTER 514 507 } 508 509 510 511 515 512 #endif // _USE_HAVRAN_SSE 516 513 517 514 518 /*519 virtual void HavranRayCaster::AddDynamicObjecs(const ObjectContainer &objects, const Matrix4x4 &m);520 virtual void UpdateDynamicObjects(const Matrix4x4 &m);521 virtual void DeleteDynamicObjects);522 */523 515 } // the namespace -
GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.h
r2623 r2629 22 22 struct SimpleRay; 23 23 class CKTB; 24 24 25 // This macro should be undefined when testing ray tracing 26 // by casting rays from file or using camera 27 #define _PROCESS_RAY 25 28 26 29 /** This class provides an interface for ray casting. … … 37 40 38 41 int Type() const { return HAVRAN_RAYCASTER; } 39 40 virtual void AddDynamicObjecs(const ObjectContainer &objects, const Matrix4x4 &m){}; 41 virtual void UpdateDynamicObjects(const Matrix4x4 &m){}; 42 virtual void DeleteDynamicObjects(){}; 43 42 44 43 virtual int CastRay( 45 44 const SimpleRay &simpleRay, … … 98 97 protected: 99 98 CKTB *mKtbtree; 100 static RayPacket2x2 raypack; 99 #ifdef _USE_HAVRAN_SSE 100 static GALIGN16 RayPacket2x2 raypack; 101 #endif 101 102 }; 102 103 103 104 105 // -------------------------------------------------------------------- 106 // The implementation of ray caster with dynamic objects 107 108 class HavranDynRayCaster: public HavranRayCaster 109 { 110 public: 111 /** Default constructor initialising e.g., KD tree 112 */ 113 HavranDynRayCaster(const Preprocessor &preprocessor); 114 virtual ~HavranDynRayCaster(); 115 116 int Type() const { return HAVRAN_DYN_RAYCASTER; } 117 118 virtual int CastRay(const SimpleRay &simpleRay, 119 VssRayContainer &vssRays, 120 const AxisAlignedBox3 &box, 121 const bool castDoubleRay, 122 const bool pruneInvalidRays = true 123 ); 124 125 virtual void CastRays16(SimpleRayContainer &rays, 126 VssRayContainer &vssRays, 127 const AxisAlignedBox3 &sbox, 128 const bool castDoubleRay, 129 const bool pruneInvalidRays = true 130 ); 131 132 virtual void CastRays16(SimpleRayContainer &rays, 133 int offset, 134 VssRayContainer &vssRays, 135 const AxisAlignedBox3 &sbox, 136 const bool castDoubleRay, 137 const bool pruneInvalidRays = true 138 ); 139 virtual void 140 CastSimpleForwardRays(SimpleRayContainer &rays, 141 const AxisAlignedBox3 &sbox); 142 143 virtual void CastRays(SimpleRayContainer &rays, 144 VssRayContainer &vssRays, 145 const AxisAlignedBox3 &sbox, 146 const bool castDoubleRay, 147 const bool pruneInvalidRays = true); 148 149 // Using packet of 4 rays supposing that these are coherent 150 // We give a box to which each ray is clipped to before the 151 // ray shooting is computed ! 152 virtual void CastRaysPacket4(const Vector3 &minBox, 153 const Vector3 &maxBox, 154 const Vector3 origin4[], 155 const Vector3 direction4[], 156 int result4[], 157 float dist4[]); 158 159 #ifdef _USE_HAVRAN_SSE 160 // Just for testing concept 161 virtual void CastRaysPacket2x2(RayPacket2x2 &raysPack, 162 bool castDoubleRay, 163 const bool pruneInvalidRays = true); 164 #endif 165 166 virtual void AddDynamicObjecs(const ObjectContainer &objects, const Matrix4x4 &m); 167 168 virtual void UpdateDynamicObjects(const Matrix4x4 &m); 169 170 virtual void DeleteDynamicObjects(); 171 172 protected: 173 174 // The kd-tree for dynamic objects 175 CKTB *mDynKtbtree; 176 177 #ifdef _USE_HAVRAN_SSE 178 // This has to be aligned by 16 Bytes boundary - if HavranDynRayCaster 179 // is aligned, then also this data entity below !!! 180 static GALIGN16 RayPacket2x2 raypack_t; 181 #endif 182 183 ObjectContainer *dynobjects; 184 bool dynamicFlag; 185 186 Matrix4x4 matTr, matTr_inv; 187 188 int result4_t[4]; 189 float dist4_t[4]; 190 SimpleRay sray_t; 191 192 Vector3 orig[16]; 193 Vector3 dirs[16]; 194 float tdist[32]; 195 Intersectable* objI[32]; 196 Vector3 normal[32]; 197 198 // This transforms the ray 199 void ApplyTransform(SimpleRay &sray) { 200 sray.mOrigin = matTr_inv * sray.mOrigin; 201 sray.mDirection = RotateOnly(matTr_inv, sray.mDirection); 202 // note that normalization to the unit size of the direction 203 // is NOT computed -- this is what we want. 204 } 205 }; 206 207 104 208 } // namespace 105 209 106 #endif 210 #endif // _HavranRayCaster_H__ -
GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
r2622 r2629 1 1 ############################################################################# 2 2 # Makefile for building: preprocessor 3 # Generated by qmake (2.00a) (Qt 4.1.2) on: po 21. I 21:36:5120083 # Generated by qmake (2.00a) (Qt 4.1.2) on: út 22. I 23:58:58 2008 4 4 # Project: preprocessor.pro 5 5 # Template: app … … 63 63 $(MAKE) -f $(MAKEFILE).Debug uninstall 64 64 65 Makefile: preprocessor.pro C:/Qt/4.1.2/mkspecs/win32-msvc .net\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \65 Makefile: preprocessor.pro C:/Qt/4.1.2/mkspecs/win32-msvc2005\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \ 66 66 C:\Qt\4.1.2\mkspecs\features\qt_config.prf \ 67 67 C:\Qt\4.1.2\mkspecs\features\exclusive_builds.prf \ -
GTP/trunk/Lib/Vis/Preprocessing/src/MeshKdTree.cpp
r2614 r2629 418 418 mRoot = Subdivide(TraversalData(leaf, NULL, GetBox(), 0)); 419 419 420 cout << "created " << 420 cout << "created " << endl; 421 421 // remove the allocated array 422 422 delete mSubdivisionCandidates; -
GTP/trunk/Lib/Vis/Preprocessing/src/OcclusionQuery.cpp
r2612 r2629 12 12 #endif 13 13 14 #ifdef _WIN32 15 // This Macro does not compile under LINUX 14 16 #define _ARBGL 17 #endif 15 18 16 19 using namespace std; -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r2623 r2629 1045 1045 GetIntValue("Preprocessor.rayCastMethod", rayCastMethod); 1046 1046 1047 if (rayCastMethod == 2) { 1048 //HavranRayCaster *hr = 1049 // dynamic_cast<HavranRayCaster*>(mRayCaster); 1050 HavranRayCaster *hr = 1051 reinterpret_cast<HavranRayCaster*>(mRayCaster); 1052 hr->Build(this->mObjects); 1053 // $$ do not exit here, so that the "internal" kD-tree used 1054 // other puroposes can be loaded 1055 // return true; 1047 if ((rayCastMethod == 2) || (rayCastMethod == 3)) { 1048 HavranRayCaster *hr = 0; 1049 if (rayCastMethod == 3) 1050 hr = reinterpret_cast<HavranDynRayCaster*>(mRayCaster); 1051 else 1052 hr = reinterpret_cast<HavranRayCaster*>(mRayCaster); 1053 1054 string ktbFilename = internKdTree; 1055 int l = ktbFilename.length(); 1056 ktbFilename[l-1] = 't'; 1057 ktbFilename[l-2] = 'b'; 1058 ktbFilename[l-3] = 'k'; 1059 1060 cout << "Trying to load tree from file " << ktbFilename << endl; 1061 if (hr->ImportBinTree(ktbFilename, this->mObjects)) { 1062 cout << "Loading failed - building kd-tree" << endl; 1063 hr->Build(this->mObjects); 1064 cout << "Exporting kd-tree to file " << ktbFilename << endl; 1065 hr->ExportBinTree(ktbFilename); 1066 } 1067 else 1068 cout << " done." << endl; 1056 1069 } 1057 1070 … … 1121 1134 if (rayCastMethod == 2) 1122 1135 { 1123 cout << "ray cast method: havran" << endl <<flush; 1124 mRayCaster = new HavranRayCaster(*this); 1125 } 1126 1136 cout << "ray cast method: havran" << endl <<flush; 1137 mRayCaster = new GALIGN16 HavranRayCaster(*this); 1138 } 1139 if (rayCastMethod == 3) 1140 { 1141 cout << "ray cast method: havran - dyn" << endl <<flush; 1142 mRayCaster = new GALIGN16 HavranDynRayCaster(*this); 1143 } 1144 1145 1127 1146 ///////////////// 1128 1147 //-- reserve constant block of rays -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
r2592 r2629 5 5 #include "ViewCellsManager.h" 6 6 7 #include <cassert> 7 8 8 9 namespace GtpVisibilityPreprocessor { … … 178 179 //const int batchsize = 16384; 179 180 const int batchsize = 8192; 180 // const int batchsize = 1024;181 181 //const int batchsize = 128; 182 182 … … 238 238 } 239 239 240 241 void 242 RayCaster::SortRays2(SimpleRayContainer &rays) 243 { 244 AxisAlignedBox3 box = 245 mPreprocessor.mViewCellsManager->GetViewSpaceBox(); 246 247 const float sizeBox = Magnitude(box.Diagonal()); 248 // This is some size of the 249 const float sizeDir = 0.2f * sizeBox; 250 251 float b[12]={ 252 box.Min().x, 253 box.Min().y, 254 box.Min().z, 255 -sizeDir, 256 -sizeDir, 257 -sizeDir, 258 box.Max().x, 259 box.Max().y, 260 box.Max().z, 261 sizeDir, 262 sizeDir, 263 sizeDir 264 }; 265 266 #if 0 267 static vector<SimpleRay *> pointerArray; 268 269 if (pointerArray.size()!=rays.size()) { 270 // realloc the pointerarray 271 pointerArray.resize(rays.size()); 272 } 273 274 // init pointer array 275 SimpleRay *p = &pointerArray[0]; 276 for (i=0; i < rays.size(); i++, p++) 277 pointerArray[i] = p; 278 #endif 279 280 _SortRays2(rays, 0, (int)rays.size()-1, 0, b); 281 282 return; 283 } 240 284 285 void 286 RayCaster::_SortRays2(SimpleRayContainer &rays, 287 const int l, 288 const int r, 289 const int depth, 290 float box[12]) 291 { 292 // pick-up a pivot 293 int axis; 294 295 float maxDiff = -1.0f; 296 // get the largest axis 297 int offset = 0; 298 int i; 299 300 //const int batchsize = 16384; 301 //const int batchsize = 8192; 302 const int batchsize = 128; 303 304 //if (r - l < 16*batchsize) 305 // offset = 3; 306 307 // if (depth%2==0) 308 // offset = 3; 309 310 for (i=offset; i < offset + 6; i++) { 311 float diff = box[i + 6] - box[i]; 312 assert(diff >= 0.f); 313 if (diff > maxDiff) { 314 // Find the maximum 315 maxDiff = diff; 316 axis = i; 317 } 318 } 319 320 // cout<<depth<<" "<<axis<<" "<<l<<" "<<r<<endl; 321 322 i=l; 323 int j=r; 324 325 float x = (box[axis] + box[axis+6])*0.5f; 326 // float x = rays[(l+r)/2].GetParam(axis); 327 do { 328 while(i<j && rays[i].GetParam(axis) < x) 329 i++; 330 while(i<j && x < rays[j].GetParam(axis)) 331 j--; 332 333 if (i <= j) { 334 swap(rays[i], rays[j]); 335 i++; 336 j--; 337 } 338 } while (i<=j); 339 340 341 if (l + batchsize < j ) { 342 // set new max 343 float save = box[axis+6]; 344 box[axis+6] = x; 345 _SortRays2(rays, l, j, depth+1, box); 346 box[axis+6] = save; 347 } else { 348 // for (int k=0; k < 6; k++) 349 // cout<<k<<" "<<box[k]<<" - "<<box[k+6]<<endl; 350 } 351 352 if (i + batchsize < r) { 353 // set new min 354 box[axis] = x; 355 _SortRays2(rays, i, r, depth+1, box); 356 } else { 357 // for (int k=0; k < 6; k++) 358 // cout<<k<<" "<<box[k]<<" - "<<box[k+6]<<endl; 359 } 360 361 } 362 363 241 364 VssRay *RayCaster::RequestRay(const Vector3 &origin, 242 365 const Vector3 &termination, -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h
r2621 r2629 25 25 struct SimpleRay; 26 26 class RayPacket2x2; 27 class Matrix4x4;28 27 29 28 /** This class provides an interface for ray casting. … … 37 36 INTERNAL_RAYCASTER = 0, 38 37 INTEL_RAYCASTER = 1, 39 HAVRAN_RAYCASTER = 2 38 HAVRAN_RAYCASTER = 2, 39 HAVRAN_DYN_RAYCASTER = 3 40 40 }; 41 41 … … 72 72 const bool pruneInvalidRays = true); 73 73 74 virtual void 75 CastSimpleForwardRays(SimpleRayContainer &rays, 76 const AxisAlignedBox3 &sbox 77 ) { return;} 78 74 79 // Using packet of 4 rays supposing that these are coherent 75 80 virtual void CastRaysPacket4(Vector3 origin4[], … … 82 87 // ray shooting is computed ! 83 88 virtual void CastRaysPacket4(const Vector3 &minBox, 84 85 86 87 88 89 const Vector3 &maxBox, 90 const Vector3 origin4[], 91 const Vector3 direction4[], 92 int result4[], 93 float dist4[]) { } 89 94 90 95 // Just for testing concept … … 93 98 const bool pruneInvalidRays = true) 94 99 { } 100 101 virtual void AddDynamicObjecs(const ObjectContainer &objects, const Matrix4x4 &m) 102 { } 103 104 virtual void UpdateDynamicObjects(const Matrix4x4 &m) 105 { } 106 107 virtual void DeleteDynamicObjects() 108 { } 109 95 110 96 111 /*virtual void CastRaysEye4(SimpleRayContainer &rays, … … 101 116 */ 102 117 118 // This sorts only rays by origin 103 119 virtual void 104 120 SortRays(SimpleRayContainer &rays); 105 121 106 107 virtual void AddDynamicObjecs(const ObjectContainer &objects, const Matrix4x4 &m) = 0; 108 virtual void UpdateDynamicObjects(const Matrix4x4 &m) = 0; 109 virtual void DeleteDynamicObjects() = 0; 110 122 // This sorts the ray by origin and direction 123 virtual void 124 SortRays2(SimpleRayContainer &rays); 125 111 126 // pool of vss rays to be used in one pass of the sampling 112 127 struct VssRayPool … … 173 188 const int depth, 174 189 float box[12]); 190 191 void _SortRays2(SimpleRayContainer &rays, 192 const int l, 193 const int r, 194 const int depth, 195 float box[12]); 175 196 176 197 struct Intersection -
GTP/trunk/Lib/Vis/Preprocessing/src/SG08/run_test_arena
r2622 r2629 4 4 5 5 # NORMAL TEST 6 #COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter- -preprocessor_detect_empty_viewspace+ -total_samples=1000000000 -samples_per_pass=1000000 -total_samples=1000000000 -view_cells_use_kd_pvs+ -af_use_kd_pvs+ -kd_pvs_area=1e-5"6 COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter- -preprocessor_detect_empty_viewspace+ -total_samples=1000000000 -samples_per_pass=1000000 -total_samples=1000000000 -view_cells_use_kd_pvs+ -af_use_kd_pvs+ -kd_pvs_area=1e-5" 7 7 8 8 #TIME TERMINATION 9 COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter- -preprocessor_detect_empty_viewspace- -total_samples=1000000000 -samples_per_pass=1000000 -total_samples=4000000000 -total_time=7200 -view_cells_use_kd_pvs+ -af_use_kd_pvs+ -kd_pvs_area=1e-5"9 #COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter- -preprocessor_detect_empty_viewspace- -total_samples=1000000000 -samples_per_pass=1000000 -total_samples=4000000000 -total_time=7200 -view_cells_use_kd_pvs+ -af_use_kd_pvs+ -kd_pvs_area=1e-5" 10 10 11 11 12 12 SCENE=../data/Arena/arena-high-lods.obj 13 VIEWCELLS=../data/Arena/viewcells-5000.xml.gz 13 #VIEWCELLS=../data/Arena/viewcells-5000.xml.gz 14 VIEWCELLS=../data/Arena/arena-high-lods-5000-viewcells.xml.gz 14 15 15 PREFIX=../work/plots/osp-arena-SG08 x-TIME16 PREFIX=../work/plots/osp-arena-SG08k 16 17 17 18 # $COMMAND -preprocessor=combined -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ … … 24 25 25 26 26 $COMMAND -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \27 -rss_distributions=direction -view_cells_filter_max_size=1 \28 -preprocessor_visibility_file=$PREFIX-r-reference-global.xml \29 -preprocessor_stats=$PREFIX-r-reference-global.log \30 -preprocessor_histogram_file=$PREFIX-r-reference-global.hlog27 # $COMMAND -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 28 # -rss_distributions=direction -view_cells_filter_max_size=1 \ 29 # -preprocessor_visibility_file=$PREFIX-r-reference-global.xml \ 30 # -preprocessor_stats=$PREFIX-r-reference-global.log \ 31 # -preprocessor_histogram_file=$PREFIX-r-reference-global.hlog 31 32 32 $COMMAND -preprocessor=sampling -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \33 -preprocessor_visibility_file=$PREFIX-r-reference.xml \34 -view_cells_filter_max_size=1 -preprocessor_stats=$PREFIX-r-reference.log \35 -preprocessor_histogram_file=$PREFIX-r-reference.hlog33 # $COMMAND -preprocessor=sampling -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 34 # -preprocessor_visibility_file=$PREFIX-r-reference.xml \ 35 # -view_cells_filter_max_size=1 -preprocessor_stats=$PREFIX-r-reference.log \ 36 # -preprocessor_histogram_file=$PREFIX-r-reference.hlog 36 37 37 38 # -total_samples=500000000000 -total_time=12208 \ -
GTP/trunk/Lib/Vis/Preprocessing/src/SG08/run_test_powerplant
r2608 r2629 2 2 3 3 #COMMAND="./release/preprocessor.exe -preprocessor_quit_on_finish+" 4 COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter- -preprocessor_detect_empty_viewspace+ - total_samples=500000000 -view_cells_use_kd_pvs+ -af_use_kd_pvs+"4 COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter- -preprocessor_detect_empty_viewspace+ -samples_per_evaluation=5000000 -samples_per_pass=1000000 -total_samples=250000000 -view_cells_use_kd_pvs+ -af_use_kd_pvs+ -preprocessor_ray_cast_method=2 -kd_pvs_area=1e-5" 5 5 6 6 … … 8 8 VIEWCELLS=../data/PowerPlant/powerplant-seq-viewcells.xml.gz 9 9 10 PREFIX=../work/plots/osp-powerplant-SG08 10 PREFIX=../work/plots/osp-powerplant-SG08c 11 11 12 12 13 # $COMMAND -preprocessor=combined -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 14 # -rss_distributions=mutation+object_direction+spatial -view_cells_filter_max_size=1 \ 15 # -view_cells_use_kd_pvs+ -af_use_kd_pvs+ \ 16 # -preprocessor_visibility_file=$PREFIX-i-mixed-b1-n4a.xml \ 17 # -preprocessor_stats=$PREFIX-i-mixed-b1-n4a.log \ 18 # -preprocessor_histogram_file=$PREFIX-i-mixed-b1-n4a.hlog 13 # n - no origin mutation, q=2, reverse samples 19 14 20 # n - no origin mutation, q=2, reverse samples 15 $COMMAND -preprocessor=combined -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 16 -rss_distributions=mutation+object_direction+spatial -view_cells_filter_max_size=1 \ 17 -mutation_silhouette_prob=0.5 \ 18 -mutation_reverse_samples_distance=1.0 \ 19 -mutation_radius_origin=0.5 \ 20 -mutation_radius_termination=0.2 \ 21 -mutation_use_unsucc_count_importance- \ 22 -mutation_use_pass_importance+ \ 23 -mutation_buffer_size=2000000 \ 24 -preprocessor_visibility_file=$PREFIX-i-mixed-b1-n4a.xml \ 25 -preprocessor_stats=$PREFIX-i-mixed-b1-n4a.log \ 26 -preprocessor_histogram_file=$PREFIX-i-mixed-b1-n4a.hlog 27 21 28 22 29 $COMMAND -preprocessor=sampling -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ … … 31 38 -preprocessor_histogram_file=$PREFIX-r-reference-global.hlog 32 39 40 41 33 42 #mutation+object_direction+ -
GTP/trunk/Lib/Vis/Preprocessing/src/default.env
r2616 r2629 4 4 ############################################################################# 5 5 6 7 6 Scene { 7 8 #filename ./data/arena-high-lods.obj 9 filename ./data/vienna/vienna_cropped.obj 10 #filename ./data/PowerPlantM.obj 8 11 9 12 #filename ../data/Arena/arena-low-lods.obj … … 20 23 #filename ../data/vienna/vienna.obj 21 24 22 filename ../data/vienna/vienna_cropped.obj23 25 24 26 # filename ../data/vienna/viewcells-25-sel.x3d … … 41 43 totalSamples 250000000 42 44 # totalSamples 2000000 43 samplesPerPass 50000045 samplesPerPass 100000 44 46 samplesPerEvaluation 5000000 45 47 … … 54 56 useGlDebugger false 55 57 # 0 = INTERNAL 1 = MLRT 2 = HAVRAN 56 rayCastMethod 1 58 # rayCastMethod 2 57 59 58 60 # type sampling … … 107 109 # distributions rss+spatial+object_direction 108 110 # distributions rss+object_direction+spatial+object+direction 111 # distributions mutation+spatial+object_direction+filter_based 109 112 distributions mutation+spatial+object_direction 110 113 # distributions rss+object_direction … … 159 162 160 163 Limits { 161 162 164 threshold 1e-6 163 small 1e- 6165 small 1e-5 164 166 infinity 1e9 165 167 } … … 183 185 splitMethod SAH 184 186 splitBorder 0.01 185 pvsArea 1e-5 186 } 187 187 pvsArea 1e-3 188 } 188 189 189 190 … … 196 197 } 197 198 198 splitMethod spatialMedian199 #splitMethod SAH199 # splitMethod spatialMedian 200 splitMethod SAH 200 201 splitBorder 0.01 201 202 } … … 204 205 importRandomViewCells false 205 206 206 useKdPvs true 207 # useKdPvs true 208 ### VH - problem in ViewCellsManager.cpp - line 690 209 useKdPvs false 207 210 useKdPvsAfterFiltering true 208 211 # samples used for view cell construction … … 317 320 # filename ../data/vienna/vsposp-seq-viewCells.xml.gz 318 321 319 filename . ./data/vienna/vienna_cropped-gradient-viewcells.xml.gz322 filename ./data/vienna/vienna_cropped-gradient-viewcells.xml.gz 320 323 321 324 # filename ../data/vienna/vienna_cropped-2-sequential-30000-viewcells.xml.gz … … 506 509 } 507 510 508 509 511 510 512 Visualization { 511 513 # x3d visualization of the split planes … … 514 516 } 515 517 516 # settings for havran ray caster517 TestDoubleRays true 518 # Settings for havran ray caster 519 518 520 519 521 BSP { 520 termCrit auto 521 # auto2 allows to set the number of primitives per leaf 522 #termCrit auto 522 523 #termCrit auto2 523 #adhoc allows to set maxdepth + number of primitives per leaf 524 #termCrit adhoc 524 termCrit adhoc 525 525 # For Arena 526 526 #maxDepthAllowed 15 … … 529 529 #maxDepthAllowed 22 530 530 #maxListLength 6 531 # For PowerPlant 532 maxDepthAllowed 18 533 maxListLength 8 534 # For Power plant 535 #maxDepthAllowed 8 536 #maxListLength 10 537 } 538 531 # For Powerplant 532 maxDepthAllowed 27 533 maxListLength 4 534 } 535 536 Rays { 537 cnt 1000000 538 #cnt 1999000 539 #cnt 499000 540 541 #file data/fileRays_arena.txt 542 #file data/rays-arena-4M-6M.txt 543 544 #file data/fileRays_vienna.txt 545 #file data/fileRays_vienna2.txt 546 file data/rays-vienna_cropped-4M-6M.txt 547 #file data/fileRays_vienna_4.txt 548 #file data/fileRays_vienna_test.txt 549 } 550 551 #TestDoubleRays false 552 TestDoubleRays true 553 554 Preprocessor { 555 # internal 556 #rayCastMethod 0 557 # Intel 558 #rayCastMethod 1 559 # Havran - 2 - static scene 560 rayCastMethod 2 561 # Havran - 3 - dynamic scene 562 rayCastMethod 3 563 564 loadMeshes false 565 } 566 -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/configh.h
r2610 r2629 13 13 #ifndef __CONFIGH_H__ 14 14 #define __CONFIGH_H__ 15 16 17 #if defined(_MSC_VER)18 // use perftimer only on msvc19 // define __SSE__ macro as it is not defined under MSVC20 #define __SSE__21 // If we support the use of SSE instructions for ray shooting22 //#define _USE_HAVRAN_SSE23 #endif24 15 25 16 #ifndef USE_GOLEM_NAMESPACE -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbai.cpp
r2592 r2629 218 218 219 219 // Maximum depth of the tree is set and stack is allocated 220 maxTreeDepth = 50;221 stackDepth = 2*maxTreeDepth;220 maxTreeDepth = MAX_HEIGHT; 221 stackDepth = maxTreeDepth + 2; 222 222 stackID = new GALIGN16 SInputData[stackDepth]; 223 223 assert(stackID); … … 1149 1149 int estHeight = (int)(log((float)initcnt)/log((float)2.0) + 0.9); 1150 1150 // cout << "EstHeight=" << estHeight << endl; 1151 maxDepthAllowed = (int)((float)estHeight * 1.2 + 2.0);1151 maxDepthAllowed = (int)((float)estHeight * 1.2f + 2.0f); 1152 1152 1153 1153 // maximum number of trials to further subdivide … … 1205 1205 } 1206 1206 } 1207 else { 1208 if (maxDepthAllowed >= MAX_HEIGHT) 1209 maxDepthAllowed = MAX_HEIGHT - 1; 1210 } 1207 1211 1208 1212 if (verbose) … … 1221 1225 if (objlist.size() == 0) 1222 1226 return 0; // nothing 1227 1228 // --------------------------------------------------- 1229 // Rewriting the triangles to the just wrappers to save 1230 // the memory during building!!!! 1231 bool useWrappers = false; 1232 if (useWrappers) { 1233 cout << "WARNING: using only wrappers, not objects to save the memory!" 1234 << endl; 1235 cout << "Size of(AxisAlignedBox3Intersectable) = " << sizeof(AxisAlignedBox3Intersectable) << endl; 1236 cout << "Size of(TriangleIntersectable) = " << sizeof(TriangleIntersectable) << endl; 1237 for (ObjectContainer::iterator it = objlist.begin(); 1238 it != objlist.end(); it++) { 1239 // take the triangle 1240 Intersectable *i = *it; 1241 // store the properties to new variables 1242 AxisAlignedBox3 b = i->GetBox(); 1243 int mId = i->mId; 1244 // delete the triangle 1245 delete i; 1246 // create the wrapper with the same box as triangle 1247 AxisAlignedBox3Intersectable *a = new AxisAlignedBox3Intersectable(b); 1248 a->mId = mId; 1249 // and put it back to the list of objects 1250 *it = a; 1251 } // for 1252 cout << "Rewriting to wrappers is finished!" << endl; 1253 } // if 1254 // --------------------------------------------------- 1255 1223 1256 // cerr<<"hh44"<<endl; 1224 1257 // initialize the whole box of the kd-tree and sort -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbai.h
r2582 r2629 20 20 #include "ktb8b.h" 21 21 #include "Containers.h" 22 #include "IntersectableWrapper.h" 22 23 23 24 namespace GtpVisibilityPreprocessor { … … 42 43 #endif 43 44 45 class AxisAlignedBox3Intersectable: 46 public IntersectableWrapper<AxisAlignedBox3> 47 { 48 public: 49 AxisAlignedBox3Intersectable(const AxisAlignedBox3 &item): 50 IntersectableWrapper<AxisAlignedBox3>(item) { } 51 52 AxisAlignedBox3 GetBox() const { return mItem;} 53 54 int Type() const 55 { 56 // This is not ture, but for our purposes it is OK 57 return Intersectable::TRIANGLE_INTERSECTABLE; 58 } 59 60 }; 61 62 // --------------------------------------------------------------- 44 63 // The base class for KD-tree with irregular change of axes, where 45 64 // the splitting plane can be positioned. … … 216 235 void Check1List(SInputData *data, int axis, int countExpected); 217 236 218 //---------------------------------------------------------------- ------237 //---------------------------------------------------------------- 219 238 // Termination criteria and fixing the splitting plane orientation 220 239 … … 230 249 CKTBAxes::Axes reqAxis; 231 250 232 // -------------- AUTOMATIC TERMINATION CRITERIA ---------------- -----251 // -------------- AUTOMATIC TERMINATION CRITERIA ---------------- 233 252 // the ratio of improvement for the cost by subdivision and not-subdividing 234 253 // for the previous subdivision … … 578 597 int startEmptyCutDepth; 579 598 599 // Biasing the empty cuts (no objects are split). The cost is multiplied 600 // by the coefficient which is assumed to be 0.8-0.9 601 float biasFreeCuts; 602 580 603 // ---------- Special improvements on the kd-tree construction -------- 581 604 // flag if to split bounding boxes during splitting … … 588 611 int minObjectsToCreateMinBox, minDepthDistanceBetweenMinBoxes; 589 612 float minSA2ratioMinBoxes; 590 // Biasing the empty cuts (no objects are split). The cost is multiplied591 // by the coefficient which is assumed to be 0.8-0.9592 float biasFreeCuts;593 613 // Make min box here 594 614 bool makeMinBoxHere; -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktball.cpp
r2608 r2629 11 11 12 12 // GOLEM library 13 #include "ktbconf.h"14 13 #include "ktb.h" 15 14 #include "ktbai.h" 15 #include "ktbs.h" 16 16 #include "ktball.h" 17 17 #include "ktbtrav.h" … … 61 61 { 62 62 CKTBAllocManPredecessor *bc = 0; 63 bool useArray = true;63 bool useArray = false; 64 64 65 65 // this should be already initialised, but we want to be sure 66 66 if (useArray) { 67 cout << "Using kbt-tree based on arrays" << endl; 67 68 // the implementation based on arrays 68 69 bc = new CKTBABuildUp(); // file ktbai.cpp 69 70 } 70 71 else { 71 // the implementation based on lists 72 // bc = new CKTBBuildUp(); // file ktbi.cpp 72 cout << "Using kbt-tree based on sampling" << endl; 73 // the implementation based on sampling 74 bc = new CKTBSBuildUp(); // file ktbs.cpp 73 75 } 74 76 … … 425 427 void 426 428 CKTB::FindNearestI(RayPacket2x2 &raypack, 427 428 429 const Vector3 &boxmin, 430 const Vector3 &boxmax) 429 431 { 430 432 if (!makeMinBoxes) … … 766 768 } 767 769 768 770 771 static int 772 cntInterior = 0; 773 774 static int 775 cntInteriorA[4] = {0, 0, 0, 0}; 776 777 static int 778 cntLeaves = 0; 779 780 static int 781 cntEmptyLeaves = 0; 782 783 static int 784 objReferences = 0; 785 769 786 SKTBNodeT* 770 787 CKTB::ImportBinLeaf(IN_STREAM &stream, … … 775 792 int objId = leafId; 776 793 int size; 794 795 cntLeaves++; 777 796 778 797 stream.read(reinterpret_cast<char *>(&size), sizeof(int)); … … 782 801 SKTBNodeT* leaf = buildClass->AllocLeaf(0); 783 802 *nodeToLink = buildClass->nodeToLink; 803 cntEmptyLeaves++; 784 804 return leaf; 785 805 } … … 790 810 791 811 ObjectContainer *newobjlist = new ObjectContainer; 812 813 objReferences += size; 792 814 793 815 // read object ids … … 826 848 } 827 849 828 829 850 SKTBNodeT * 830 851 CKTB::ImportBinInterior(IN_STREAM &stream, SKTBNodeT **nodeToLink) … … 839 860 buildClass->AllocInteriorNode(axis, pos, 0, 0); 840 861 *nodeToLink = buildClass->nodeToLink; 841 862 863 cntInterior++; 864 assert( (axis >= 0) && (axis < 3)); 865 cntInteriorA[axis]++; 866 842 867 return interiorNode; 843 868 } … … 928 953 929 954 if (!stream.is_open()) { 930 cerr << "Kd-tree description file (.k dh) cannot be opened for reading\n";955 cerr << "Kd-tree description file (.kbt) cannot be opened for reading\n"; 931 956 return true; // error 932 957 } … … 963 988 bc->InitAux(0, CKTBNodeAbstract::MAX_HEIGHT - 1, maxItemsAtOnce); 964 989 990 for(int i = 0; i < 4; i++) 991 cntInteriorA[i] = 0; 992 965 993 // Compute the box from all objects 966 994 bbox.Initialize(); … … 1040 1068 builtUp = true; 1041 1069 1070 cout << "Importing ktb-tree cntInterior = " 1071 << cntInterior << " cntLeaves = " << cntLeaves 1072 << " cntEmptyLeaves = " << cntEmptyLeaves << endl; 1073 1074 cout << "X-splits = " << cntInteriorA[0] << " Y-splits = " << cntInteriorA[1] 1075 << " Z-splits = " << cntInteriorA[2] << "\nref_to_objs/full_leaf = " 1076 << (float)objReferences/(cntLeaves - cntEmptyLeaves) << endl; 1077 1042 1078 return false; // OK 1043 1079 } -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktball.h
r2608 r2629 16 16 // GOLEM headers 17 17 #include "configh.h" 18 #include "ktbconf.h"19 18 //#include "ktbi.h" 20 19 #include "ktbai.h" … … 155 154 156 155 // allocate new build class and return it 157 staticCKTBAllocManPredecessor* AllocBuildClass();156 CKTBAllocManPredecessor* AllocBuildClass(); 158 157 159 158 CKTBNodeIteratorPredecessor* GetTraversalClass() { -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbconf.h
r2608 r2629 23 23 #endif 24 24 25 // If we support the use of SSE instructions for ray shooting 26 #define _USE_HAVRAN_SSE 25 27 26 28 namespace GtpVisibilityPreprocessor { -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbf2trv.cpp
r2608 r2629 57 57 results[i].intersectable; 58 58 SimpleRay::IntersectionRes[i + copyOffset].tdist = 59 SimpleRay::IntersectionRes[i + copyOffset].maxt = 59 60 results[i].tdist; 60 61 } // for i … … 204 205 FindNearestI(ray); 205 206 rp.SetObject(i, SimpleRay::IntersectionRes[0].intersectable); 206 rp.SetT(i, SimpleRay::IntersectionRes[0]. tdist);207 rp.SetT(i, SimpleRay::IntersectionRes[0].maxt); 207 208 // SimpleRay::IntersectionRes[0].intersectable->GetNormal(0); 208 209 } // for … … 403 404 FindNearestI(ray); 404 405 rp.SetObject(i, SimpleRay::IntersectionRes[0].intersectable); 405 rp.SetT(i, SimpleRay::IntersectionRes[0]. tdist);406 rp.SetT(i, SimpleRay::IntersectionRes[0].maxt); 406 407 // SimpleRay::IntersectionRes[0].intersectable->GetNormal(0); 407 408 } // for … … 414 415 void 415 416 CKTBTraversal::FindNearestI(RayPacket2x2 &rp, 416 417 417 const Vector3 &boxmin, 418 const Vector3 &boxmax) 418 419 { 419 420 static AxisAlignedBox3 localbox; … … 606 607 FindNearestI(ray, localbox); 607 608 rp.SetObject(i, SimpleRay::IntersectionRes[0].intersectable); 608 rp.SetT(i, SimpleRay::IntersectionRes[0]. tdist);609 rp.SetT(i, SimpleRay::IntersectionRes[0].maxt); 609 610 // SimpleRay::IntersectionRes[0].intersectable->GetNormal(0); 610 611 } // for -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbftrav.cpp
r2602 r2629 166 166 cout << "Full leaf HIT " << endl; 167 167 #endif 168 168 SimpleRay::IntersectionRes[0].tdist = 169 SimpleRay::IntersectionRes[0].maxt; 169 170 #ifdef __TRAVERSAL_STATISTICS 170 171 _allNodesTraversed += allNodesTraversed; … … 372 373 cout << "Full leaf HIT " << endl; 373 374 #endif 375 SimpleRay::IntersectionRes[0].tdist = 376 SimpleRay::IntersectionRes[0].maxt; 374 377 375 378 #ifdef __TRAVERSAL_STATISTICS … … 381 384 // We have to add the distance from the original ray origin 382 385 SimpleRay::IntersectionRes[0].tdist += tminOffset; 386 SimpleRay::IntersectionRes[0].maxt = SimpleRay::IntersectionRes[0].tdist; 383 387 384 388 // signed distance should be already set in TestFullLeaf … … 592 596 tmax + Limits::Small; 593 597 if (TestFullLeaf(rays[indexR+offset], currNode, indexR)) { 598 // copy the result to tdist 599 SimpleRay::IntersectionRes[indexR + rayOffset].tdist = 600 SimpleRay::IntersectionRes[indexR + rayOffset].maxt; 594 601 595 602 // we remove the ray from the calculation … … 599 606 #ifdef _DEBUGKTB 600 607 cout << "Full leaf HIT " << endl; 601 #endif 608 #endif 602 609 603 610 #ifdef __TRAVERSAL_STATISTICS -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbtrav.h
r2602 r2629 150 150 // of a packet to individual rays and traced individually. 151 151 virtual void FindNearestI(RayPacket2x2 &raypack) { } 152 virtual void FindNearestI(RayPacket2x2 &raypack, const Vector3 &boxMin, const Vector3 &boxMax) { } 152 virtual void FindNearestI(RayPacket2x2 &raypack, const Vector3 &boxMin, 153 const Vector3 &boxMax) { } 153 154 #endif 154 155 … … 328 329 // of a packet to individual rays and traced individually. 329 330 virtual void FindNearestI(RayPacket2x2 &raypack); 330 virtual void FindNearestI(RayPacket2x2 &raypack, const Vector3 &boxMin, const Vector3 &boxMax); 331 virtual void FindNearestI(RayPacket2x2 &raypack, const Vector3 &boxMin, 332 const Vector3 &boxMax); 331 333 #endif // __SSE__ 332 334 #endif // _USE_HAVRAN_SSE … … 421 423 // of a packet to individual rays and traced individually. 422 424 virtual void FindNearestI(RayPacket2x2 &raypack); 423 virtual void FindNearestI(RayPacket2x2 &raypack, const Vector3 &boxMin, const Vector3 &boxMax); 425 virtual void FindNearestI(RayPacket2x2 &raypack, const Vector3 &boxMin, 426 const Vector3 &boxMax); 424 427 #endif // __SSE__ 425 428 #endif // _USE_HAVRAN_SSE -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/raypack.h
r2592 r2629 10 10 // 11 11 // Initial coding by Vlastimil Havran, 2006. The data design is in fact 12 // Jakko Biker layout as propose in the article on Intel Web Site in year 200512 // Jakko Biker layout as proposed in the article on Intel Web Site in year 2005 13 13 // http://www.intel.com/cd/ids/developer/asmo-na/eng/245711.htm?page=1 14 14 … … 21 21 22 22 #include "Vector3.h" 23 #include "Matrix4x4.h" 23 24 #include "ktbconf.h" 24 25 … … 88 89 // and also for shadow rays finish at the same object 89 90 const Intersectable *_stopObject = NULL 90 ) 91 { 91 ) { 92 92 // location 93 93 ox[0] = orf[0].x; ox[1] = orf[1].x; ox[2] = orf[2].x; ox[3] = orf[3].x; … … 182 182 int GetType() const { return ttype; } 183 183 184 void ApplyTransform(const Matrix4x4 &tform) { 185 for (int i = 0; i < 4; i++) { 186 Vector3 o_orig(ox[i], oy[i], oz[i]); 187 Vector3 t_orig = tform * o_orig; 188 ox[i] = t_orig.x; oy[i] = t_orig.y; oz[i] = t_orig.z; 189 Vector3 o_dir(dx[i], dy[i], dz[i]); 190 Vector3 t_dir = RotateOnly(tform, o_dir); 191 dx[i] = t_dir.x; dy[i] = t_dir.y; dz[i] = t_dir.z; 192 193 // ?? note that normalization to the unit size of the direction 194 // ?? is NOT computed -- this is what we want. 195 } 196 Precompute(); 197 } 198 184 199 // Reading and Setting origin of the ray and direction 185 200 // Ray origin -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/sbbox.h
r2582 r2629 146 146 147 147 inline bool Equal(const SBBox &b, float eps = 0.f) const; 148 148 149 // Returns the intersection of two axis-aligned boxes. 150 friend inline SBBox Intersect(const SBBox &x, const SBBox &y); 151 149 152 // Test if the box is really sensefull 150 153 bool IsCorrect(); … … 278 281 DescribeXYZ(const SBBox &b, std::ostream &app, int indent); 279 282 283 inline SBBox 284 Intersect(const SBBox &x, const SBBox &y) 285 { 286 SBBox ret = x; 287 if (OverlapS(ret, y)) { 288 Maximize(ret.pp[0], y.pp[0]); 289 Minimize(ret.pp[1], y.pp[1]); 290 return ret; 291 } 292 293 // Null intersection. 294 return SBBox(Vector3(0), Vector3(0)); 295 } 296 297 280 298 #if 1 281 299 // The implementation I, the first version implemented by Vlastimil … … 425 443 #endif 426 444 445 427 446 } 428 447 -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/testrt.cpp
r2602 r2629 26 26 #include "GlobalLinesRenderer.h" 27 27 #include "RayCaster.h" 28 #include "Triangle3.h" 29 #include "IntersectableWrapper.h" 28 30 #include "timer.h" 29 31 #include "raypack.h" … … 64 66 extern void Cleanup(); 65 67 66 static string ReplaceSuffix(const string &filename, const string &a, const string &b) 68 void 69 _SortRays2(SimpleRayContainer &rays, 70 const int l, 71 const int r, 72 const int depth, 73 float box[12]) 67 74 { 68 string result = filename; 69 70 int pos = (int)filename.rfind(a, (int)filename.size() - 1); 71 if (pos == filename.size() - a.size()) 72 { 73 result.replace(pos, a.size(), b); 75 // pick-up a pivot 76 int axis; 77 78 float maxDiff = -1.0f; 79 // get the largest axis 80 int offset = 0; 81 int i; 82 83 //const int batchsize = 16384; 84 //const int batchsize = 8192; 85 //const int batchsize = 128; 86 const int batchsize = 4; 87 88 //if (r - l < 16*batchsize) 89 // offset = 3; 90 91 // if (depth%2==0) 92 // offset = 3; 93 94 for (i=offset; i < offset + 6; i++) { 95 float diff = box[i + 6] - box[i]; 96 assert(diff >= 0.f); 97 if (diff > maxDiff) { 98 // Find the maximum 99 maxDiff = diff; 100 axis = i; 101 } 102 } 103 104 // cout<<depth<<" "<<axis<<" "<<l<<" "<<r<<endl; 105 106 i=l; 107 int j=r; 108 109 float x = (box[axis] + box[axis+6])*0.5f; 110 // float x = rays[(l+r)/2].GetParam(axis); 111 do { 112 while(i<j && rays[i].GetParam(axis) < x) 113 i++; 114 while(i<j && x < rays[j].GetParam(axis)) 115 j--; 116 117 if (i <= j) { 118 swap(rays[i], rays[j]); 119 i++; 120 j--; 74 121 } 75 76 return result; 122 } while (i<=j); 123 124 125 if (l + batchsize < j ) { 126 // set new max 127 float save = box[axis+6]; 128 box[axis+6] = x; 129 _SortRays2(rays, l, j, depth+1, box); 130 box[axis+6] = save; 131 } else { 132 // for (int k=0; k < 6; k++) 133 // cout<<k<<" "<<box[k]<<" - "<<box[k+6]<<endl; 134 } 135 136 if (i + batchsize < r) { 137 // set new min 138 box[axis] = x; 139 _SortRays2(rays, i, r, depth+1, box); 140 } else { 141 // for (int k=0; k < 6; k++) 142 // cout<<k<<" "<<box[k]<<" - "<<box[k+6]<<endl; 143 } 77 144 } 78 145 79 80 static int SplitFilenames(const string &str, vector<string> &filenames)146 void 147 SortRays2(SimpleRayContainer &rays, const AxisAlignedBox3 &box) 81 148 { 82 int pos = 0; 83 84 while(1) { 85 int npos = (int)str.find(';', pos); 86 87 if (npos < 0 || npos - pos < 1) 88 break; 89 filenames.push_back(string(str, pos, npos - pos)); 90 pos = npos + 1; 91 } 92 93 filenames.push_back(string(str, pos, str.size() - pos)); 94 return (int)filenames.size(); 95 } 149 const float sizeBox = Magnitude(box.Diagonal()); 150 // This is some size of the 151 const float sizeDir = 0.1f * sizeBox; 152 153 float b[12]={ 154 box.Min().x, 155 box.Min().y, 156 box.Min().z, 157 -sizeDir, 158 -sizeDir, 159 -sizeDir, 160 box.Max().x, 161 box.Max().y, 162 box.Max().z, 163 sizeDir, 164 sizeDir, 165 sizeDir 166 }; 167 168 169 _SortRays2(rays, 0, (int)rays.size()-1, 0, b); 170 171 return; 172 } 96 173 97 174 … … 254 331 AxisAlignedBox3 bboxOrig = preprocessor->mSceneGraph->GetBox(); 255 332 AxisAlignedBox3 bbox = bboxOrig; 256 int sizeDiag = Magnitude(bbox.Diagonal());333 float sizeDiag = Magnitude(bbox.Diagonal()); 257 334 bbox.Enlarge(sizeDiag * 1.5f); 258 335 259 336 Vector3 origin, dir; 260 337 261 //#define WIEN1262 #define WIEN2338 #define WIEN1 339 //#define WIEN2 263 340 //#define ARENA1 264 341 … … 267 344 origin = Vector3(1099.9f, 183.0f, -387.0f); 268 345 dir = Vector3(-0.6f, 0.0001f, -0.8f); 346 //dir = -dir; 269 347 #define DIREXISTS 270 348 #endif … … 292 370 cout << "Computing image\n" << endl; 293 371 372 int id = preprocessor->mObjects.size() + 1; 373 374 //We add here a few objects 375 ObjectContainer dynObjects; 376 Vector3 baseVec = origin + dir * 2.0f; 377 Triangle3 tr1(baseVec, baseVec + Vector3(1, 0, 0), 378 baseVec + Vector3(0, 1, 0)); 379 TriangleIntersectable ti1(tr1); 380 dynObjects.push_back(&ti1); 381 ti1.mId = id+1; 382 383 tr1.Init(baseVec, baseVec + Vector3(1, 0, 0), 384 baseVec + Vector3(0, 0, 1)); 385 TriangleIntersectable ti2(tr1); 386 dynObjects.push_back(&ti2); 387 ti2.mId = id+2; 388 389 tr1.Init(baseVec, baseVec + Vector3(0, 1, 0), 390 baseVec + Vector3(0, 0, 1)); 391 TriangleIntersectable ti3(tr1); 392 dynObjects.push_back(&ti3); 393 ti3.mId = id+3; 394 294 395 #if 1 295 // ray by ray 296 cam.SnapImage("test-rays.tga", 297 preprocessor->mRayCaster, 298 bboxOrig, 299 preprocessor->mSceneGraph); 300 #endif 396 // This is required for cam.SnapImagePacket2 397 // otherwise dynamic object cannot be identified! 398 preprocessor->mObjects.push_back(&ti1); 399 preprocessor->mObjects.push_back(&ti2); 400 preprocessor->mObjects.push_back(&ti3); 401 #endif 402 403 if (0) { 404 Matrix4x4 mat; 405 mat = IdentityMatrix(); 406 mat = mat * TranslationMatrix(Vector3(-1, 0, 0)); 407 preprocessor->mRayCaster->AddDynamicObjecs(dynObjects, mat); 408 301 409 #if 1 302 // using ray packets303 cam.SnapImagePacket("test-packet.tga",304 305 306 410 // ray by ray 411 cam.SnapImage("test-rays.tga", 412 preprocessor->mRayCaster, 413 bboxOrig, 414 preprocessor->mSceneGraph); 307 415 #endif 308 416 #if 1 309 // using ray packets 310 cam.SnapImage2("test-oneDir.tga", 311 preprocessor->mRayCaster, 312 bboxOrig, 313 preprocessor->mSceneGraph); 314 #endif 417 // using ray packets 418 cam.SnapImage2("test-oneDir.tga", 419 preprocessor->mRayCaster, 420 bboxOrig, 421 preprocessor->mSceneGraph); 422 #endif 423 424 #if 1 425 #ifdef _USE_HAVRAN_SSE 426 // using ray packets 427 cam.SnapImagePacket("test-packet.tga", 428 preprocessor->mRayCaster, 429 bboxOrig, 430 preprocessor->mSceneGraph); 431 #endif 432 #endif 433 #if 1 434 // using ray packets 435 cam.SnapImagePacket2("test-packet4.tga", 436 preprocessor->mRayCaster, 437 bboxOrig, 438 preprocessor->mSceneGraph); 439 #endif 440 } 441 else { 442 cout << "Computing animation" << endl; 443 for (int i = 0; i < 20; i++) { 444 preprocessor->mRayCaster->DeleteDynamicObjects(); 445 Matrix4x4 mat; 446 mat = IdentityMatrix(); 447 mat = mat * TranslationMatrix(Vector3(-0.1*(float)i, 0, 0)); 448 preprocessor->mRayCaster->AddDynamicObjecs(dynObjects, mat); 449 char name[200]; 450 #if 1 451 // ray by ray 452 sprintf(name, "test-rays-%03d.tga", i); 453 cam.SnapImage(name, 454 preprocessor->mRayCaster, 455 bboxOrig, 456 preprocessor->mSceneGraph); 457 #endif 458 #if 1 459 // using ray packets 460 sprintf(name, "test-oneDir-%03d.tga", i); 461 cam.SnapImage2(name, 462 preprocessor->mRayCaster, 463 bboxOrig, 464 preprocessor->mSceneGraph); 465 #endif 466 467 #if 1 468 #ifdef _USE_HAVRAN_SSE 469 // using ray packets 470 sprintf(name, "test-packet-%03d.tga", i); 471 cam.SnapImagePacket(name, 472 preprocessor->mRayCaster, 473 bboxOrig, 474 preprocessor->mSceneGraph); 475 #endif 476 #endif 477 #if 1 478 // using ray packets 479 sprintf(name, "test-packet4-%03d.tga", i); 480 cam.SnapImagePacket2(name, 481 preprocessor->mRayCaster, 482 bboxOrig, 483 preprocessor->mSceneGraph); 484 #endif 485 } // for 486 } // animation 487 315 488 316 489 cout << "Done\n" << endl; … … 327 500 }; 328 501 502 329 503 // This is for testing RT implementation 330 504 void … … 427 601 int cntMaxRays = 100000; 428 602 Environment::GetSingleton()->GetIntValue("Rays.cnt", cntMaxRays); 429 vector<SimpleRay>rays;603 SimpleRayContainer rays; 430 604 SimpleRay rayTest; 431 605 vector<RESult> results; … … 475 649 if (castDoubleRays) 476 650 mult = 2.0; 477 651 652 cout << "Press a key to start ray shooting" << endl; 653 getchar(); 654 cout << "Ray shooting " << cntRays << " rays started - " 655 << (castDoubleRays ? " double " : " single ") 656 << " dir " << endl; 657 658 AxisAlignedBox3 bboxOrig = preprocessor->mSceneGraph->GetBox(); 659 660 cout << "Sorting rays " << endl; 661 662 CTimer timer; 663 timer.Reset(); 664 timer.Start(); 665 long t1 = GetTime(); 666 667 //SortRays2(rays, bboxOrig); 668 669 timer.Stop(); 670 long t2 = GetTime(); 671 cout<<"\n#SORTING_TIME = "; 672 cout << TimeDiff(t1, t2)<<" [mikrosec]" 673 << " userTime = " << timer.UserTime() << " realTime = " 674 << timer.RealTime() << endl; 675 478 676 cout << "Starting to shoot " << cntRays * mult << " rays" << endl; 677 timer.Start(); 479 678 480 679 RayCaster *raycaster = preprocessor->mRayCaster; 481 680 VssRayContainer vssRays; 482 AxisAlignedBox3 bboxOrig = preprocessor->mSceneGraph->GetBox();483 681 484 682 //#define DEBUGRESULTS … … 494 692 #endif 495 693 496 cout << "Press a key to start ray shooting" << endl;497 getchar();498 cout << "Ray shooting " << cntRays << " rays started - "499 << (castDoubleRays ? " double " : " single ")500 << " dir " << endl;501 502 long t1 = GetTime();503 CTimer timer;504 timer.Reset();505 timer.Start();506 507 694 SimpleRayContainer raysToTest; 508 695 for (int i = 0; i < cntRays - 16; i++) { 696 509 697 #if 0 510 698 int res = raycaster->CastRay(rays[i], … … 573 761 574 762 timer.Stop(); 575 longt2 = GetTime();576 cout<<"\n# RAY_CAST_TIME = ";763 t2 = GetTime(); 764 cout<<"\n#SORTING + RAY_CAST_TIME = "; 577 765 cout << TimeDiff(t1, t2)<<" [mikrosec]" 578 766 << " userTime = " << timer.UserTime() << " realTime = " … … 695 883 int cntMaxRays = 100000; 696 884 Environment::GetSingleton()->GetIntValue("Rays.cnt", cntMaxRays); 697 vector<SimpleRay>rays;885 SimpleRayContainer rays; 698 886 SimpleRay rayTest; 699 887 vector<RESult> results; … … 957 1145 int cntMaxRays = 100000; 958 1146 Environment::GetSingleton()->GetIntValue("Rays.cnt", cntMaxRays); 959 vector<SimpleRay>rays;1147 SimpleRayContainer rays; 960 1148 SimpleRay rayTest; 961 1149 vector<RESult> results; … … 1038 1226 timer.Start(); 1039 1227 Vector3 boxMin, boxMax; 1228 1229 bool printOut = false; 1040 1230 1041 1231 SimpleRayContainer raysToTest; … … 1056 1246 origin4, direction4, 1057 1247 result4, dist4); 1058 printf("I %4.7f %4.7f %4.7f %4.7f %4.7f %4.7f\n", 1059 boxMin.x, boxMin.y, boxMin.z, boxMax.x, boxMax.y, boxMax.z); 1248 if (printOut) { 1249 printf("I %4.7f %4.7f %4.7f %4.7f %4.7f %4.7f\n", 1250 boxMin.x, boxMin.y, boxMin.z, boxMax.x, boxMax.y, boxMax.z); 1251 } 1060 1252 1061 1253 for (int j = 0; j < 4; j++) { 1062 printf("%d %4.7f %4.7f %4.7f %4.7f %4.7f %4.7f %d %4.7f\n", 1063 i+j, 1064 origin4[j].x, 1065 origin4[j].y, 1066 origin4[j].z, 1067 direction4[j].x, 1068 direction4[j].y, 1069 direction4[j].z, 1070 (result4[j] != -1) ? 1 : 0, 1071 (result4[j] != -1) ? dist4[j] : 0); 1254 #if 0 1255 if (result4[j] == 0) { 1256 int res = raycaster->CastRay(rays[i+j], 1257 vssRays, 1258 bboxOrig, 1259 false, 1260 true); 1261 if (res) { 1262 float tdist = SimpleRay::IntersectionRes[0].tdist; 1263 Vector3 point = rays[i+j].Extrap(tdist); 1264 AxisAlignedBox3 testbox(boxMin, boxMax); 1265 1266 if (testbox.IsInside(point)) { 1267 cout << "Error in the algorithm - computed not in the box, but" 1268 << " it is later found in the box" << endl; 1269 cout << " j = " << j << endl; 1270 cout << " box = " << testbox << endl; 1271 cout << " point = " << point << endl; 1272 raycaster->CastRaysPacket4(boxMin, boxMax, 1273 origin4, direction4, 1274 result4, dist4); 1275 } 1276 } 1277 } 1278 #endif 1279 1280 if (printOut) { 1281 printf("%d %4.7f %4.7f %4.7f %4.7f %4.7f %4.7f %d %4.7f\n", 1282 i+j, 1283 origin4[j].x, 1284 origin4[j].y, 1285 origin4[j].z, 1286 direction4[j].x, 1287 direction4[j].y, 1288 direction4[j].z, 1289 (result4[j] != -1) ? 1 : 0, 1290 (result4[j] != -1) ? dist4[j] : 0); 1291 } 1072 1292 } // for j 1073 1293 } // for i -
GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
r2625 r2629 26 26 #include "GlobalLinesRenderer.h" 27 27 #include "RayCaster.h" 28 //#include "vlastimil/testrt.h"29 30 28 #include "ViewCellsManager.h" 29 30 #include "testrt.h" 31 31 32 32 33 #ifdef USE_QT … … 134 135 #if 0 135 136 // Test code by VH 136 //TestRTcamera(argc, argv);137 TestRTcamera(argc, argv); 137 138 //TestRTfromFile(argc, argv); 138 TestRTfromFilePackets(argc, argv); 139 //TestRTfromFilePackets(argc, argv); 140 //TestRT_4_fromFile(argc, argv); 139 141 return 0; 140 142 #endif -
GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro
r2627 r2629 34 34 $$NONGTP/Zlib/include $$NONGTP/Boost $$NONGTP/Devil/include sparsehash/src 35 35 36 win32:LIBPATH += GL $$ XERCES/lib $$NONGTP/Devil/lib \36 win32:LIBPATH += GL $$NONGTP/Xerces/xerces/lib $$NONGTP/Devil/lib \ 37 37 $$NONGTP/glut $$NONGTP/Boost/lib $$NONGTP/Zlib/lib 38 38 … … 61 61 CONFIG(release) { 62 62 win32:LIBS += xerces-c_2.lib 63 #win32:LIBS += xerces-c_static_2.lib64 63 } 65 64 66 65 CONFIG(debug) { 67 66 win32:LIBS += xerces-c_2D.lib 68 #win32:LIBS += xerces-c_static_2D.lib69 67 } 70 68 … … 127 125 Intersectable.cpp TraversalTree.cpp ObjectPvs.cpp ObjectsParser.cpp \ 128 126 FilterBasedDistribution.cpp DifferenceSampling.cpp HavranRayCaster.cpp \ 129 OcclusionQuery.cpp RandomViewCellsHandler.cpp 127 HavranDynRayCaster.cpp OcclusionQuery.cpp 130 128 131 129 … … 135 133 SOURCES += havran/allocgo2.cpp havran/ktbai.cpp havran/ktbtrav.cpp \ 136 134 havran/ktb.cpp havran/ktball.cpp havran/sbbox.cpp \ 137 havran/ktb8b.cpp havran/ktbftrav.cpp havran/ ktbf2trv.cpp havran/timer.cpp135 havran/ktb8b.cpp havran/ktbftrav.cpp havran/timer.cpp 138 136 139 137
Note: See TracChangeset
for help on using the changeset viewer.