Ignore:
Timestamp:
01/16/08 21:30:29 (16 years ago)
Author:
bittner
Message:

Havran ray Caster update

Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp

    r2599 r2602  
    9292// We give a box to which each ray is clipped to before the 
    9393// ray shooting is computed ! 
    94 void HavranRayCaster::CastRaysPacket4(const Vector3 &boxmax, 
    95                                                                           const Vector3 &boxmin, 
    96                                                                           const Vector3 origin4[], 
    97                                                                           const Vector3 direction4[], 
    98                                                                           int     result4[], 
    99                                                                           float   dist4[]) 
    100 { 
    101 #if defined(_USE_HAVRAN_SSE) 
    102 #ifdef USE_HAVRAN_RAYCASTER  
     94void HavranRayCaster::CastRaysPacket4(const Vector3 &minBox, 
     95                                      const Vector3 &maxBox, 
     96                                      const Vector3 origin4[], 
     97                                      const Vector3 direction4[], 
     98                                      int     result4[], 
     99                                      float   dist4[]) 
     100{ 
     101#ifdef USE_HAVRAN_RAYCASTER  
     102#ifdef _USE_HAVRAN_SSE  
    103103  for (int i = 0; i < 4; i++) { 
    104104    result4[i] = -1; 
    105         //      raypack.SetObject(i, NULL); 
    106105    raypack.SetLoc(i, origin4[i]); 
    107106    raypack.SetDir(i, direction4[i]); 
     
    111110  // a particular ASDS, otherwise it is emulated by decomposition 
    112111  // of a packet to individual rays and traced individually. 
    113   mKtbtree->FindNearestI(raypack, (Vector3&)boxmin, (Vector3&)boxmax); 
    114   //  mKtbtree->FindNearestI(raypack, bmin, bmax); 
     112  mKtbtree->FindNearestI(raypack, minBox, maxBox); 
    115113 
    116114  for (int i = 0; i < 4; i++) { 
     
    120118    if ( (intersectable = raypack.GetObject(i)) ) { 
    121119      // $$JB this is very hacky - > should be replaced with fetching the index of the triangle 
     120      // $$VH - this is object ID - is this the triangle index ??? 
    122121      result4[i] = intersectable->mId; 
    123122      dist4[i] = raypack.GetT(i); 
     
    126125   
    127126  return; 
    128 #endif // USE_HAVRAN_RAYCASTER  
    129127#else // _USE_HAVRAN_SSE 
    130128  // Compute the result ray by ray 
     
    133131    sray.mOrigin = origin4[i]; 
    134132    sray.mDirection = direction4[i]; 
    135     mKtbtree->FindNearestI(sray, (Vector3&)boxmin, (Vector3&)boxmax); 
     133    mKtbtree->FindNearestI(sray, minBox, maxBox); 
    136134    if (SimpleRay::IntersectionRes[0].intersectable) { 
    137135      // This is object ID - is this the triangle index ??? 
     
    145143   
    146144#endif // _USE_HAVRAN_SSE   
     145#endif // USE_HAVRAN_RAYCASTER  
    147146} 
    148147 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.h

    r2599 r2602  
    7676  // ray shooting is computed ! 
    7777  virtual void CastRaysPacket4(const Vector3 &minBox, 
    78                                                            const Vector3 &maxBox, 
    79                                                            const Vector3 origin4[], 
    80                                                            const Vector3 direction4[], 
    81                                                            int     result4[], 
    82                                                            float   dist4[]); 
     78                               const Vector3 &maxBox, 
     79                               const Vector3 origin4[], 
     80                               const Vector3 direction4[], 
     81                               int     result4[], 
     82                               float   dist4[]); 
    8383 
    8484#ifdef _USE_HAVRAN_SSE   
  • GTP/trunk/Lib/Vis/Preprocessing/src/Makefile

    r2599 r2602  
    11############################################################################# 
    22# Makefile for building: preprocessor 
    3 # Generated by qmake (2.00a) (Qt 4.1.2) on: út 15. I 21:38:15 2008 
     3# Generated by qmake (2.00a) (Qt 4.1.2) on: st 16. I 21:20:04 2008 
    44# Project:  preprocessor.pro 
    55# Template: app 
  • GTP/trunk/Lib/Vis/Preprocessing/src/default.env

    r2599 r2602  
    5353        useGlDebugger false 
    5454# 0 = INTERNAL  1 = MLRT 2 = HAVRAN 
    55         rayCastMethod 1 
     55        rayCastMethod 2 
    5656         
    5757#       type sampling 
  • GTP/trunk/Lib/Vis/Preprocessing/src/havran/configh.h

    r2592 r2602  
    5959 
    6060#ifdef _MSC_VER 
    61 #define __SSE__ 
    6261// disable some Microsoft Visual Compiler warnings if necessary 
    6362#pragma warning( disable:4305 ) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktball.cpp

    r2592 r2602  
    402402 
    403403int 
    404 CKTB::FindNearestI(const SimpleRay &ray, Vector3 &boxmin, Vector3 &boxmax) 
     404CKTB::FindNearestI(const SimpleRay &ray, const Vector3 &boxmin, const Vector3 &boxmax) 
    405405{ 
    406406  const AxisAlignedBox3 localbox(boxmin, boxmax); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktball.h

    r2592 r2602  
    174174   
    175175  int FindNearestI(const SimpleRay &ray); 
    176   int FindNearestI(const SimpleRay &ray, Vector3 &boxmin, Vector3 &boxmax); 
     176  int FindNearestI(const SimpleRay &ray, const Vector3 &boxMin, const Vector3 &boxMax); 
    177177  void SetOffset(int offset) { traversalClass->SetOffset(offset); } 
    178178  int FindNearestI_16oneDir(SimpleRayContainer &rays, int offset, int copyOffset) { 
     
    192192  // of a packet to individual rays and traced individually. 
    193193  void FindNearestI(RayPacket2x2 &raypack); 
    194   void FindNearestI(RayPacket2x2 &raypack, Vector3 &boxmin, Vector3 &boxmax); 
     194  void FindNearestI(RayPacket2x2 &raypack, const Vector3 &boxMin, const Vector3 &boxMax); 
    195195#endif 
    196196#else 
    197197  void FindNearestI(RayPacket2x2 &raypack) { } 
    198   void FindNearestI(RayPacket2x2 &raypack, Vector3 &boxmin, Vector3 &boxmax) { } 
     198  void FindNearestI(RayPacket2x2 &raypack, const Vector3 &boxMin, const Vector3 &boxMax) { } 
    199199#endif // __SSE__ 
    200200 
  • GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbconf.h

    r2592 r2602  
    2424 
    2525// If we support the use of SSE instructions for ray shooting 
    26 #define _USE_HAVRAN_SSE 
     26//#define _USE_HAVRAN_SSE 
    2727 
    2828namespace GtpVisibilityPreprocessor { 
     
    3535#define GPREFETCH(A, B)   
    3636#endif 
    37    
     37 
    3838#if defined(__INTEL_COMPILER)||defined(_MSC_VER) 
    3939// Intel compiler or Microsoft Compiler 
  • GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbftrav.cpp

    r2592 r2602  
    222222// to be contained in the scene box!!! 
    223223int 
    224 CKTBTraversal::FindNearestI(const SimpleRay &ray, const AxisAlignedBox3 &localbox) 
     224CKTBTraversal::FindNearestI(const SimpleRay &oray, const AxisAlignedBox3 &localbox) 
    225225{ 
    226226#if 0 
     
    238238  float tmin, tmax; 
    239239  SimpleRay::IntersectionRes[0].intersectable = 0; 
     240  SimpleRay ray(oray.mOrigin, oray.mDirection, 0, 0.f, 0); 
    240241   
    241242  // test if the whole CKTB tree is missed by the input ray 
     
    246247    return 0; // no object can be intersected 
    247248  } 
     249  float tminOffset = 0.f; 
    248250 
    249251//#define _DEBUGKTB 
     
    267269  if (tmin < 0.f) 
    268270    tmin = 0.f; 
     271  else { 
     272    // Here the origin of the ray is always zero - it starts 
     273    // at the box face!! 
     274    tminOffset = tmin; 
     275    tmin = 0.f; 
     276    tmax -= tminOffset; 
     277    ray.mOrigin += ray.mDirection * tminOffset; 
     278  } 
    269279 
    270280  int index = 1; 
     
    368378            _emptyLeavesTraversed += emptyLeavesTraversed; 
    369379#endif // __TRAVERSAL_STATISTICS 
     380 
     381            // We have to add the distance from the original ray origin 
     382            SimpleRay::IntersectionRes[0].tdist += tminOffset; 
    370383             
    371384            // signed distance should be already set in TestFullLeaf 
  • GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbtrav.h

    r2592 r2602  
    150150  // of a packet to individual rays and traced individually. 
    151151  virtual void FindNearestI(RayPacket2x2 &raypack) { } 
    152   virtual void FindNearestI(RayPacket2x2 &raypack, Vector3 &boxmin, Vector3 &boxmax) { } 
     152  virtual void FindNearestI(RayPacket2x2 &raypack, const Vector3 &boxMin, const Vector3 &boxMax) { } 
    153153#endif 
    154154   
     
    328328  // of a packet to individual rays and traced individually. 
    329329  virtual void FindNearestI(RayPacket2x2 &raypack); 
    330   virtual void FindNearestI(RayPacket2x2 &raypack, Vector3 &boxmin, Vector3 &boxmax); 
     330  virtual void FindNearestI(RayPacket2x2 &raypack, const Vector3 &boxMin, const Vector3 &boxMax); 
    331331#endif // __SSE__ 
    332332#endif // _USE_HAVRAN_SSE   
     
    421421  // of a packet to individual rays and traced individually. 
    422422  virtual void FindNearestI(RayPacket2x2 &raypack); 
    423   virtual void FindNearestI(RayPacket2x2 &raypack, Vector3 &boxmin, Vector3 &boxmax); 
     423  virtual void FindNearestI(RayPacket2x2 &raypack, const Vector3 &boxMin, const Vector3 &boxMax); 
    424424#endif // __SSE__ 
    425425#endif // _USE_HAVRAN_SSE   
  • GTP/trunk/Lib/Vis/Preprocessing/src/havran/testrt.cpp

    r2595 r2602  
    3737#else 
    3838        #if USE_THREADS 
    39                 #include "BoostPreprocessorThread.h" 
     39#include "BoostPreprocessorThread.h" 
    4040        #endif 
    4141#endif 
     
    489489  int cntIntelOurDistMismatch = 0; 
    490490  bool printOut = false; 
    491   double sumDistIntel = 0.; 
    492   doublecca sumDistOurAlg = 0.; 
     491  double sumDistIntel = 0.f; 
     492  double sumDistOurAlg = 0.f; 
    493493  double sumDistAbsDiff = 0.f; 
    494494#endif 
     
    536536      float T = rays[i].IntersectionRes[0].tdist; 
    537537      if ( (res != results[i].hitA) || 
    538            ((res)&&(results[i].hitA)&& (fabs(T - results[i].hitAT)) > 2.0f) 
     538           ((res)&&(results[i].hitA)&& (fabs(T - results[i].hitAT)) > 0.1f) 
    539539           ) 
    540540        { 
     
    547547          } 
    548548          else { 
    549             if ((res = 0) && (results[i].hitA)) { 
     549            if ((res == 0) && (results[i].hitA)) { 
    550550              cntIntelYesWeNo++; 
    551551              if (printOut) 
     
    578578       << " userTime = " << timer.UserTime() << " realTime = " 
    579579       << timer.RealTime() << endl; 
    580     ; 
    581580  cout << "Rays shot per milisecond [userTimer] = " 
    582581       << ((double)cntRays * mult/(double)timer.UserTime()) / 1000.f << endl; 
     
    750749  AxisAlignedBox3 bboxOrig = preprocessor->mSceneGraph->GetBox(); 
    751750 
     751#undef DEBUGRESULTS 
    752752//#define DEBUGRESULTS 
    753753 
     
    758758  bool printOut = false; 
    759759  double sumDistIntel = 0.; 
    760   doublecca sumDistOurAlg = 0.; 
     760  double sumDistOurAlg = 0.; 
    761761  double sumDistAbsDiff = 0.f; 
    762762#endif 
     
    856856  return; 
    857857} 
     858 
     859// This is for testing RT implementation 
     860void 
     861TestRT_4_fromFile(int argc, char **argv) 
     862{ 
     863  int returnCode = 0; 
     864 
     865  InitTiming(); 
     866  Debug.open("debug.log"); 
     867 
     868  Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH); 
     869  MeshKdTree::ParseEnvironment(); 
     870 
     871  char buff[128]; 
     872  Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff); 
     873  string preprocessorType(buff); 
     874 
     875  if (!(preprocessor = PreprocessorFactory::CreatePreprocessor(preprocessorType))) 
     876  { 
     877    Environment::DelSingleton(); 
     878    cerr << "Unknown preprocessor type" << endl; 
     879    exit(1); 
     880  } 
     881 
     882 
     883  Environment::GetSingleton()->GetStringValue("Scene.filename", buff); 
     884  string filename(buff); 
     885 
     886  const string externKdTree = ReplaceSuffix(filename, ".obj", ".kdf"); 
     887  const string internKdTree = GetInternFilename(filename, preprocessor->mLoadMeshes ? 
     888                                                ".kdm" : ".kdt"); 
     889 
     890  if (preprocessor->InitRayCast(externKdTree, internKdTree)) 
     891  { 
     892    cout << "ray casting initialized!" << endl; 
     893  } 
     894  else 
     895  { 
     896    cout << "ray casting initialization failed!" << endl; 
     897    Cleanup(); 
     898    exit(1); 
     899  } 
     900   
     901  //Debug << "using pvs type " << PVS_TYPE << endl; 
     902 
     903  ///////////// 
     904  //-- load scene  
     905   
     906  if (!preprocessor->LoadScene(filename)) 
     907  { 
     908    cout << "loading file " << filename << " failed" << endl; 
     909    Cleanup(); 
     910    exit(1); 
     911  } 
     912         
     913  //////////// 
     914  //-- initialize external ray caster 
     915   
     916  if (preprocessor->LoadInternKdTree(internKdTree)) 
     917  { 
     918    cout << "intern kd tree loaded!" << endl; 
     919  } 
     920  else 
     921  { 
     922    cout << "loading intern kd tree failed!" << endl; 
     923    Cleanup(); 
     924    exit(1); 
     925  } 
     926   
     927  // export objects as obj 
     928  if (preprocessor->mExportObj) 
     929  { 
     930    if (strstr(filename.c_str(), ".obj")) 
     931    { 
     932      cerr << "already in obj format" << endl; 
     933      if (0)    preprocessor->ExportObj("test.obj", preprocessor->mObjects); 
     934    } 
     935    else 
     936    { 
     937      const string objname = GetInternFilename(filename, ".obj"); 
     938         
     939      cout << "exporting scene to " << objname << endl; 
     940      bool success = preprocessor->ExportObj(objname, preprocessor->mObjects);   
     941         
     942      if (success) 
     943        cout << "finished exporting obj" << endl; 
     944      else 
     945        cerr << "error exporting " << objname << endl; 
     946    } 
     947  } 
     948 
     949  Environment::GetSingleton()->GetStringValue("Rays.file", buff); 
     950  FILE *fp = fopen(buff, "rb"); 
     951  if (!fp) { 
     952    cerr << "ERROR: file " << buff << " cannot be opened for reading" << endl; 
     953    cerr << "EXITING" << endl; 
     954    exit(3); 
     955  } 
     956  cout << "File " << buff << " was opened successfully" << endl; 
     957  int cntMaxRays = 100000; 
     958  Environment::GetSingleton()->GetIntValue("Rays.cnt", cntMaxRays); 
     959  vector<SimpleRay> rays; 
     960  SimpleRay rayTest; 
     961  vector<RESult> results; 
     962  vector<AxisAlignedBox3> boxes; 
     963 
     964  int cntRays = 0; 
     965  for (int i = 0; cntRays < cntMaxRays;) { 
     966    int ch = fgetc(fp); 
     967    switch (ch) { 
     968    case 'I': { // two-sided rays of 16 
     969      Vector3 minv, maxv; 
     970      if (fscanf(fp, "%f %f %f %f %f %f\n", 
     971                 &minv.x, &minv.y, &minv.z, 
     972                 &maxv.x, &maxv.y, &maxv.z) != 6) { 
     973        cerr << "Problem parsing the ray file" << endl; 
     974        cerr << "EXITING for ray order" << i << endl; 
     975        goto FINISH; 
     976      } 
     977      boxes.push_back(AxisAlignedBox3(minv, maxv));       
     978 
     979      for (int j = 0; j < 4; j++) { 
     980        int order; 
     981        float ox, oy, oz, dx, dy, dz; 
     982        int hitA; float hitAT; 
     983        int hitB; float hitBT;   
     984        if (fscanf(fp, "%d %f %f %f %f %f %f %d %f\n", 
     985                   &order, &ox, &oy, &oz, &dx, &dy, &dz, 
     986                   &hitA, &hitAT) != 9) { 
     987          cerr << "Problem parsing the ray file" << endl; 
     988          cerr << "EXITING for ray order" << order << endl; 
     989          goto FINISH; 
     990        } 
     991        Vector3 mPosition(ox, oy, oz); 
     992        Vector3 mDirection(dx, dy, dz); 
     993        rayTest.Set(mPosition, mDirection, 0, 1.0, true); 
     994        rays.push_back(rayTest); 
     995        results.push_back(RESult(hitA, hitAT, 0, -1.f)); 
     996        cntRays++; 
     997        i++; 
     998      } 
     999      break; 
     1000    } 
     1001    default: { 
     1002      cerr << "Not yet implemented or end of file" << endl; 
     1003      goto FINISH; 
     1004    } 
     1005    } // switch 
     1006  } // for i 
     1007 
     1008FINISH: 
     1009   
     1010  fclose(fp); 
     1011  cout << "Starting to shoot " << cntRays << " rays" << endl; 
     1012   
     1013  RayCaster *raycaster = preprocessor->mRayCaster; 
     1014  VssRayContainer vssRays; 
     1015  AxisAlignedBox3 bboxOrig = preprocessor->mSceneGraph->GetBox(); 
     1016 
     1017//#define DEBUGRESULTS 
     1018 
     1019#ifdef DEBUGRESULTS 
     1020  int cntIntelYesWeNo = 0; 
     1021  int cntIntelNoWeYes = 0; 
     1022  int cntIntelOurDistMismatch = 0; 
     1023  bool printOut = false; 
     1024  double sumDistIntel = 0.f; 
     1025  double sumDistOurAlg = 0.f; 
     1026  double sumDistAbsDiff = 0.f; 
     1027#endif 
     1028 
     1029  //cout << "Press a key to start ray shooting" << endl; 
     1030  //getchar(); 
     1031  cout << "Ray shooting " << cntRays << " rays started - " 
     1032       << (castDoubleRays ? " double " : " single ") 
     1033       << " dir " << endl; 
     1034 
     1035  long t1 = GetTime(); 
     1036  CTimer timer; 
     1037  timer.Reset(); 
     1038  timer.Start(); 
     1039  Vector3 boxMin, boxMax; 
     1040   
     1041  SimpleRayContainer raysToTest; 
     1042  int boxI = 0; 
     1043  for (int i = 0; i < cntRays - 4; i+= 4, boxI++) { 
     1044    Vector3 origin4[4]; 
     1045    Vector3 direction4[4]; 
     1046    int     result4[4]; 
     1047    float   dist4[4]; 
     1048    boxMin = boxes[boxI].Min(); 
     1049    boxMax = boxes[boxI].Max(); 
     1050    for (int j = 0; j < 4; j++) { 
     1051      int o = i+j; 
     1052      origin4[j] = rays[o].mOrigin; 
     1053      direction4[j] = rays[o].mDirection; 
     1054    } 
     1055    raycaster->CastRaysPacket4(boxMin, boxMax, 
     1056                               origin4, direction4, 
     1057                               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); 
     1060 
     1061    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);       
     1072    } // for j     
     1073  } // for i 
     1074 
     1075  timer.Stop(); 
     1076  long t2 = GetTime(); 
     1077  cout<<"\n#RAY_CAST_TIME = "; 
     1078  cout << TimeDiff(t1, t2)<<" [mikrosec]" 
     1079       << " userTime = " << timer.UserTime() << " realTime = " 
     1080       << timer.RealTime() << endl; 
     1081  cout << "Rays shot per milisecond [userTimer] = " 
     1082       << ((double)cntRays/(double)timer.UserTime()) / 1000.f << endl; 
     1083 
     1084#ifdef DEBUGRESULTS   
     1085  cout << "cntIntelYesWeNo = " << cntIntelYesWeNo << endl; 
     1086  cout << "cntIntelNoWeYes = " << cntIntelNoWeYes << endl; 
     1087  cout << "cntIntelOurDistMismatch = " << cntIntelOurDistMismatch++ << endl; 
     1088  cout << " sumDistIntel = " << sumDistIntel/(double)cntIntelOurDistMismatch << endl; 
     1089  cout << " sumDistOur = " << sumDistOurAlg/(double)cntIntelOurDistMismatch << endl; 
     1090  cout << " sumAbsDiffDist = " << sumDistAbsDiff/(double)cntIntelOurDistMismatch 
     1091       << endl; 
     1092#endif   
     1093  cout << "Done\n" << endl; 
     1094  return; 
     1095} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/havran/testrt.h

    r2595 r2602  
    1313TestRTfromFilePackets(int argc, char **argv); 
    1414 
     15void 
     16TestRT_4_fromFile(int argc, char **argv); 
     17 
    1518#endif // _TESTRT_H_ 
    1619 
  • GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro

    r2592 r2602  
    121121Intersectable.cpp TraversalTree.cpp ObjectPvs.cpp ObjectsParser.cpp \ 
    122122FilterBasedDistribution.cpp DifferenceSampling.cpp HavranRayCaster.cpp \ 
    123 OcclusionQuery.cpp  
     123OcclusionQuery.cpp RandomViewCellsHandler.cpp 
    124124 
    125125 
Note: See TracChangeset for help on using the changeset viewer.