Ignore:
Timestamp:
01/23/08 00:21:50 (16 years ago)
Author:
bittner
Message:

commit after merge with vlastimil

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

Legend:

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

    r2603 r2629  
    77#include <cassert> 
    88 
     9#include "common.h" 
    910#include "Camera.h" 
    1011#include "Ray.h" 
     
    1617#include "Preprocessor.h" 
    1718#include "RayCaster.h" 
    18  
    19 #ifdef USE_HAVRAN_RAYCASTER  
     19#include "tgaimg.h" 
     20 
     21#ifdef USE_HAVRAN_RAYCASTER 
    2022//#include "timer.h" 
    21 #include "ktbconf.h" 
    2223#include "raypack.h" 
    2324#endif 
     
    5455 
    5556  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); 
    6358   
    6459  vector<Ray *> rays; 
     
    6964 
    7065  for (y = 0; y < mHeight; y++) { 
    71     cout<<"+"; 
     66    cout<<"+" << flush; 
    7267    for (x = 0; x < mWidth; x++) { 
    7368      SetupRay(ray, mWidth - (x + 1), mHeight - (y + 1)); 
     
    9186                  if (mesh->GetMesh()->mMaterial) 
    9287                        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); 
    9990                } 
    10091          } 
    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()) { 
    10792          if (debug) { 
    108                 Ray *nray = new Ray(ray); 
    109                 rays.push_back(nray); 
     93            Ray *nray = new Ray(ray); 
     94            rays.push_back(nray); 
    11095          } 
    11196    } 
    112     //    pbuffer-=2*components*mWidth; 
    11397  } 
    11498   
     
    119103   
    120104  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());   
    126106 
    127107  cout<<"done."<<endl<<flush; 
     
    183163  Vector3 xv = mRight*((x - mWidth/2)/(float)mWidth); 
    184164  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; 
    187166  dir.Normalize(); 
    188167   
     
    202181 
    203182  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); 
    212185   
    213186  vector<Ray *> rays; 
     
    218191  VssRayContainer vssRays; 
    219192 
     193  bool doubleRays = true; 
     194  bool exploitDoubleRays = true; 
     195  if (!doubleRays) 
     196    exploitDoubleRays = false; 
     197   
    220198  //CTimer timer; 
    221199  //timer.Start(); 
    222200   
    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; 
    225206    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; 
    229212      //          (y == mHeight/2) && (x== mWidth/3); 
    230213      //          MeshDebug = debug; 
    231        
    232214 
    233215      int res = raycaster->CastRay(ray, 
    234216                                   vssRays, 
    235217                                   bbox, 
    236                                    false, // castDoubleRay, 
     218                                   doubleRays, // castDoubleRay, 
    237219                                   false); // pruneInvalidRays 
     220 
     221      // cout << "End ------------------------ " 
     222      // << SimpleRay::IntersectionRes[0].intersectable 
     223      // << " t = " << SimpleRay::IntersectionRes[0].tdist 
     224      // << endl; 
    238225       
    239226      if (res) { 
    240         Vector3 normal = raycaster->intersect.mNormal; 
     227        Vector3 normal = SimpleRay::IntersectionRes[0].intersectable->GetNormal(0); 
    241228        float v = 
    242229          ray.mDirection.x * normal.x + 
    243230          ray.mDirection.y * normal.y + 
    244231          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); 
    250236      } 
    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; 
    258237       
    259238      if (debug) { 
     
    263242      } 
    264243    } 
    265     //    pbuffer-=2*components*mWidth; 
    266244  } // for y 
    267245 
     
    273251   
    274252  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; 
    280260 
    281261  cout<<"done."<<endl<<flush; 
     
    284264} 
    285265 
     266 
     267bool 
     268Camera::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   
    286385bool 
    287386Camera::SnapImagePacket(string filename, 
     
    291390                        ) 
    292391{ 
    293 #if defined(USE_HAVRAN_RAYCASTER) && defined(_USE_HAVRAN_SSE) 
     392#ifdef USE_HAVRAN_RAYCASTER  
     393#ifdef _USE_HAVRAN_SSE 
    294394   
    295395  int x; 
    296396  int y; 
    297397 
    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 
    306400  //  - components*mWidth; 
     401  CTGAImage tgaimg; tgaimg.Init(mWidth, mHeight); 
     402  tgaimg.FillInImage(0.0, 0.0f, 200.f); // blue color image 
    307403   
    308404  vector<Ray *> rays; 
     
    315411  //CTimer timer; 
    316412  //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;; 
    319423  for (y = 0; y < mHeight-1; y+=2) { 
    320     float *pppbuffer = pbuffer; 
    321     cout<<"+"; 
     424  //for (y = ystart-2; y > 0; y-=2) { 
    322425    for (x = 0; x < mWidth-1; x+=2) { 
    323426      int i = 0; 
    324427      for (int yi = 0; yi < 2; yi++) { 
    325428        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); 
    327430          rp.SetLoc(i, ray.mOrigin); 
    328431          rp.SetDir(i, ray.mDirection); 
     432          if (exploitDoubleRays) 
     433            rp.SetDir(i, -ray.mDirection); 
    329434          i++; 
    330435        } // for xi 
    331436      } // 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); 
    334444 
    335445      i = 0; 
    336       float *ppbuffer = pbuffer; 
    337446      for (int yi = 0; yi < 2; yi++) { 
    338447        for (int xi = 0; xi < 2; xi++) { 
    339448          Intersectable* res = rp.GetObject(i); 
    340449          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); 
    351481          } 
    352482          i++; 
    353           ppbuffer += components; 
    354483        } // xi 
    355         ppbuffer += components * (mWidth-2); 
    356484      } // yi 
    357  
    358       pbuffer = ppbuffer + 2 * components; 
    359485    } // for x 
    360     pbuffer = pppbuffer + mWidth * 2 * components; 
    361     pppbuffer = pbuffer; // for the next time; 
    362486  } // for y 
    363487 
     
    369493   
    370494  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  
    377499  cout<<"done."<<endl<<flush; 
    378500     
     
    380502} 
    381503   
    382  
    383 } 
     504inline static bool ilt(Intersectable *obj1, Intersectable *obj2) 
     505{ 
     506  return obj1->mId < obj2->mId; 
     507} 
     508 
     509 
     510bool 
     511Camera::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  
    44#include "Vector3.h" 
    55#include "AxisAlignedBox3.h" 
     6#include "ktbconf.h" 
    67 
    78namespace GtpVisibilityPreprocessor { 
     
    3132  } 
    3233 
    33   Camera(int width, int height) { 
     34  Camera(int width, int height, float fieldOfView = 90.f) { 
    3435    mWidth = width; 
    3536    mHeight = height; 
    36     mFovy = 90.0f*(float)M_PI/180.0f; 
     37    mFovy = fieldOfView*(float)M_PI/180.0f; 
    3738  } 
    38  
    3939   
    4040  void Precompute() { 
     
    8787 
    8888  bool 
     89  SnapImage2(std::string filename, 
     90             RayCaster *raycaster, 
     91             AxisAlignedBox3 &bbox, 
     92             SceneGraph *sceneGraph 
     93             ); 
     94   
     95  bool 
    8996  SnapImagePacket(std::string filename, 
    9097                  RayCaster *raycaster, 
     
    9299                  SceneGraph *sceneGraph 
    93100                  ); 
    94    
     101 
     102  bool 
     103  SnapImagePacket2(std::string filename, 
     104                  RayCaster *raycaster, 
     105                  AxisAlignedBox3 &bbox, 
     106                  SceneGraph *sceneGraph 
     107                  ); 
     108 
    95109  void SetupRay(Ray &ray, const int x, const int y); 
    96110 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp

    r2621 r2629  
    2626#define DEBUG_RAYCAST 0 
    2727 
    28 // This macro should be undefined when testing ray tracing 
    29 // by casting rays from file or using camera 
    30 #define _PROCESS_RAY 
    31  
    3228namespace GtpVisibilityPreprocessor { 
    3329 
    34  
    35  
    36 #ifdef USE_HAVRAN_RAYCASTER  
    3730#ifdef _USE_HAVRAN_SSE 
    38    
    3931// static rays 
    40 RayPacket2x2 
     32GALIGN16 RayPacket2x2 
    4133HavranRayCaster::raypack; 
    4234#endif // _USE_HAVRAN_SSE 
    43 #endif // USE_HAVRAN_RAYCASTER 
     35 
    4436   
    4537HavranRayCaster::HavranRayCaster(const Preprocessor &preprocessor): 
     
    7062 
    7163  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); 
    8477  } 
    8578#endif 
     
    513506#endif // USE_HAVRAN_RAYCASTER  
    514507} 
     508 
     509 
     510 
     511   
    515512#endif // _USE_HAVRAN_SSE 
    516513 
    517514 
    518     /* 
    519   virtual void HavranRayCaster::AddDynamicObjecs(const ObjectContainer &objects, const Matrix4x4 &m); 
    520   virtual void UpdateDynamicObjects(const Matrix4x4 &m); 
    521   virtual void DeleteDynamicObjects); 
    522 */ 
    523515} // the namespace 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.h

    r2623 r2629  
    2222struct SimpleRay; 
    2323class 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 
    2528 
    2629/** This class provides an interface for ray casting. 
     
    3740   
    3841  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   
    4443  virtual int CastRay( 
    4544                      const SimpleRay &simpleRay, 
     
    9897protected: 
    9998  CKTB *mKtbtree; 
    100   static RayPacket2x2 raypack; 
     99#ifdef _USE_HAVRAN_SSE 
     100  static GALIGN16 RayPacket2x2 raypack; 
     101#endif 
    101102}; 
    102103 
    103104 
     105// -------------------------------------------------------------------- 
     106// The implementation of ray caster with dynamic objects 
     107 
     108class HavranDynRayCaster: public HavranRayCaster 
     109{ 
     110public: 
     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   
     172protected: 
     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   
    104208} // namespace 
    105209 
    106 #endif 
     210#endif // _HavranRayCaster_H__ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Makefile

    r2622 r2629  
    11############################################################################# 
    22# Makefile for building: preprocessor 
    3 # Generated by qmake (2.00a) (Qt 4.1.2) on: po 21. I 21:36:51 2008 
     3# Generated by qmake (2.00a) (Qt 4.1.2) on: út 22. I 23:58:58 2008 
    44# Project:  preprocessor.pro 
    55# Template: app 
     
    6363        $(MAKE) -f $(MAKEFILE).Debug uninstall 
    6464 
    65 Makefile: preprocessor.pro  C:/Qt/4.1.2/mkspecs/win32-msvc.net\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \ 
     65Makefile: preprocessor.pro  C:/Qt/4.1.2/mkspecs/win32-msvc2005\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \ 
    6666                C:\Qt\4.1.2\mkspecs\features\qt_config.prf \ 
    6767                C:\Qt\4.1.2\mkspecs\features\exclusive_builds.prf \ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/MeshKdTree.cpp

    r2614 r2629  
    418418  mRoot = Subdivide(TraversalData(leaf, NULL, GetBox(), 0)); 
    419419   
    420   cout <<  "created " <<  
     420  cout <<  "created " << endl; 
    421421  // remove the allocated array 
    422422  delete mSubdivisionCandidates; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/OcclusionQuery.cpp

    r2612 r2629  
    1212#endif 
    1313 
     14#ifdef _WIN32 
     15// This Macro does not compile under LINUX 
    1416#define _ARBGL 
     17#endif 
    1518 
    1619using namespace std; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r2623 r2629  
    10451045        GetIntValue("Preprocessor.rayCastMethod", rayCastMethod); 
    10461046 
    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; 
    10561069  } 
    10571070   
     
    11211134        if (rayCastMethod == 2)  
    11221135        { 
    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         
    11271146        ///////////////// 
    11281147        //-- reserve constant block of rays 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp

    r2592 r2629  
    55#include "ViewCellsManager.h" 
    66 
     7#include <cassert> 
    78 
    89namespace GtpVisibilityPreprocessor { 
     
    178179  //const int batchsize = 16384; 
    179180  const int batchsize = 8192; 
    180   // const int batchsize = 1024; 
    181181  //const int batchsize = 128; 
    182182 
     
    238238} 
    239239   
     240 
     241void 
     242RayCaster::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} 
    240284                                         
     285void 
     286RayCaster::_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   
    241364VssRay *RayCaster::RequestRay(const Vector3 &origin,  
    242365                                                          const Vector3 &termination,  
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h

    r2621 r2629  
    2525struct SimpleRay; 
    2626class RayPacket2x2; 
    27 class Matrix4x4; 
    2827 
    2928/** This class provides an interface for ray casting. 
     
    3736    INTERNAL_RAYCASTER = 0, 
    3837    INTEL_RAYCASTER = 1, 
    39     HAVRAN_RAYCASTER = 2 
     38    HAVRAN_RAYCASTER = 2, 
     39    HAVRAN_DYN_RAYCASTER = 3 
    4040  }; 
    4141 
     
    7272                        const bool pruneInvalidRays = true); 
    7373 
     74  virtual void 
     75  CastSimpleForwardRays(SimpleRayContainer &rays, 
     76                        const AxisAlignedBox3 &sbox 
     77                        ) { return;} 
     78   
    7479  // Using packet of 4 rays supposing that these are coherent 
    7580  virtual void CastRaysPacket4(Vector3 origin4[], 
     
    8287  // ray shooting is computed ! 
    8388  virtual void CastRaysPacket4(const Vector3 &minBox, 
    84                                                            const Vector3 &maxBox, 
    85                                                            const Vector3 origin4[], 
    86                                                            const Vector3 direction4[], 
    87                                                            int result4[], 
    88                                                            float dist4[]) {  } 
     89                               const Vector3 &maxBox, 
     90                               const Vector3 origin4[], 
     91                               const Vector3 direction4[], 
     92                               int result4[], 
     93                               float dist4[]) {  } 
    8994   
    9095  // Just for testing concept 
     
    9398                                 const bool pruneInvalidRays = true) 
    9499  { } 
     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 
    95110   
    96111  /*virtual void CastRaysEye4(SimpleRayContainer &rays, 
     
    101116  */ 
    102117 
     118  // This sorts only rays by origin 
    103119  virtual void 
    104120  SortRays(SimpleRayContainer &rays); 
    105121 
    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   
    111126  // pool of vss rays to be used in one pass of the sampling 
    112127  struct VssRayPool  
     
    173188                 const int depth, 
    174189                 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]); 
    175196   
    176197  struct Intersection 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SG08/run_test_arena

    r2622 r2629  
    44 
    55# 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" 
     6COMMAND="../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" 
    77 
    88#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" 
    1010 
    1111 
    1212SCENE=../data/Arena/arena-high-lods.obj 
    13 VIEWCELLS=../data/Arena/viewcells-5000.xml.gz 
     13#VIEWCELLS=../data/Arena/viewcells-5000.xml.gz 
     14VIEWCELLS=../data/Arena/arena-high-lods-5000-viewcells.xml.gz 
    1415 
    15 PREFIX=../work/plots/osp-arena-SG08x-TIME 
     16PREFIX=../work/plots/osp-arena-SG08k 
    1617 
    1718# $COMMAND -preprocessor=combined -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 
     
    2425 
    2526 
    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.hlog 
     27# $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 
    3132 
    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.hlog 
     33# $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 
    3637 
    3738# -total_samples=500000000000 -total_time=12208 \ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SG08/run_test_powerplant

    r2608 r2629  
    22 
    33#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+" 
     4COMMAND="../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" 
    55 
    66 
     
    88VIEWCELLS=../data/PowerPlant/powerplant-seq-viewcells.xml.gz 
    99 
    10 PREFIX=../work/plots/osp-powerplant-SG08 
     10PREFIX=../work/plots/osp-powerplant-SG08c 
    1111 
    1212 
    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 
    1914 
    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 
    2128 
    2229$COMMAND -preprocessor=sampling -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \ 
     
    3138 -preprocessor_histogram_file=$PREFIX-r-reference-global.hlog 
    3239 
     40 
     41 
    3342#mutation+object_direction+ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/default.env

    r2616 r2629  
    44############################################################################# 
    55 
    6  
    76Scene { 
     7 
     8#filename ./data/arena-high-lods.obj 
     9filename ./data/vienna/vienna_cropped.obj 
     10#filename ./data/PowerPlantM.obj 
    811 
    912#filename ../data/Arena/arena-low-lods.obj 
     
    2023#filename ../data/vienna/vienna.obj 
    2124 
    22 filename ../data/vienna/vienna_cropped.obj 
    2325 
    2426# filename ../data/vienna/viewcells-25-sel.x3d 
     
    4143        totalSamples 250000000 
    4244#       totalSamples 2000000 
    43         samplesPerPass 500000 
     45        samplesPerPass 100000 
    4446        samplesPerEvaluation 5000000 
    4547 
     
    5456        useGlDebugger false 
    5557# 0 = INTERNAL  1 = MLRT 2 = HAVRAN 
    56         rayCastMethod 1 
     58#       rayCastMethod 2 
    5759         
    5860#       type sampling 
     
    107109#       distributions rss+spatial+object_direction 
    108110#       distributions rss+object_direction+spatial+object+direction 
     111#       distributions mutation+spatial+object_direction+filter_based 
    109112        distributions mutation+spatial+object_direction 
    110113#       distributions rss+object_direction 
     
    159162 
    160163Limits { 
    161  
    162164       threshold        1e-6 
    163        small            1e-6 
     165       small            1e-5 
    164166       infinity         1e9 
    165167} 
     
    183185        splitMethod SAH 
    184186        splitBorder 0.01 
    185         pvsArea 1e-5 
    186 } 
    187  
     187        pvsArea 1e-3 
     188} 
    188189 
    189190 
     
    196197        } 
    197198 
    198         splitMethod spatialMedian 
    199 #       splitMethod SAH 
     199#       splitMethod spatialMedian 
     200        splitMethod SAH 
    200201        splitBorder 0.01 
    201202} 
     
    204205        importRandomViewCells false 
    205206 
    206         useKdPvs true 
     207        # useKdPvs true 
     208        ### VH - problem in ViewCellsManager.cpp - line 690 
     209        useKdPvs false 
    207210        useKdPvsAfterFiltering true 
    208211        # samples used for view cell construction 
     
    317320#       filename ../data/vienna/vsposp-seq-viewCells.xml.gz 
    318321 
    319         filename ../data/vienna/vienna_cropped-gradient-viewcells.xml.gz 
     322        filename ./data/vienna/vienna_cropped-gradient-viewcells.xml.gz 
    320323 
    321324#       filename ../data/vienna/vienna_cropped-2-sequential-30000-viewcells.xml.gz 
     
    506509        } 
    507510         
    508  
    509  
     511         
    510512        Visualization { 
    511513                # x3d visualization of the split planes 
     
    514516} 
    515517 
    516 # settings for havran ray caster 
    517 TestDoubleRays  true 
     518# Settings for havran ray caster 
     519 
    518520 
    519521BSP { 
    520   termCrit        auto 
    521   # auto2 allows to set the number of primitives per leaf        
     522  #termCrit       auto 
    522523  #termCrit       auto2 
    523   #adhoc allows to set maxdepth + number of primitives per leaf  
    524   #termCrit       adhoc 
     524  termCrit        adhoc 
    525525  # For Arena 
    526526  #maxDepthAllowed 15 
     
    529529  #maxDepthAllowed 22 
    530530  #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 
     536Rays { 
     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 
     552TestDoubleRays  true 
     553 
     554Preprocessor { 
     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  
    1313#ifndef __CONFIGH_H__ 
    1414#define __CONFIGH_H__ 
    15  
    16  
    17 #if defined(_MSC_VER) 
    18 // use perftimer only on msvc 
    19 // define __SSE__ macro as it is not defined under MSVC 
    20 #define __SSE__ 
    21 // If we support the use of SSE instructions for ray shooting 
    22 //#define _USE_HAVRAN_SSE 
    23 #endif 
    2415 
    2516#ifndef USE_GOLEM_NAMESPACE 
  • GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbai.cpp

    r2592 r2629  
    218218 
    219219  // 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; 
    222222  stackID = new GALIGN16 SInputData[stackDepth]; 
    223223  assert(stackID); 
     
    11491149      int estHeight = (int)(log((float)initcnt)/log((float)2.0) + 0.9); 
    11501150      // cout << "EstHeight=" << estHeight << endl; 
    1151       maxDepthAllowed = (int)((float)estHeight * 1.2 + 2.0); 
     1151      maxDepthAllowed = (int)((float)estHeight * 1.2f + 2.0f); 
    11521152 
    11531153      // maximum number of trials to further subdivide 
     
    12051205    } 
    12061206  } 
     1207  else { 
     1208    if (maxDepthAllowed >= MAX_HEIGHT) 
     1209      maxDepthAllowed = MAX_HEIGHT - 1; 
     1210  } 
    12071211 
    12081212  if (verbose) 
     
    12211225  if (objlist.size() == 0) 
    12221226    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   
    12231256  // cerr<<"hh44"<<endl; 
    12241257  // initialize the whole box of the kd-tree and sort 
  • GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbai.h

    r2582 r2629  
    2020#include "ktb8b.h" 
    2121#include "Containers.h" 
     22#include "IntersectableWrapper.h" 
    2223 
    2324namespace GtpVisibilityPreprocessor { 
     
    4243#endif 
    4344 
     45class AxisAlignedBox3Intersectable: 
     46    public IntersectableWrapper<AxisAlignedBox3> 
     47{ 
     48public: 
     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// ---------------------------------------------------------------   
    4463// The base class for KD-tree with irregular change of axes, where 
    4564// the splitting plane can be positioned. 
     
    216235  void Check1List(SInputData *data, int axis, int countExpected); 
    217236     
    218   //---------------------------------------------------------------------- 
     237  //---------------------------------------------------------------- 
    219238  // Termination criteria and fixing the splitting plane orientation 
    220239 
     
    230249    CKTBAxes::Axes reqAxis; 
    231250 
    232     // -------------- AUTOMATIC TERMINATION CRITERIA --------------------- 
     251    // -------------- AUTOMATIC TERMINATION CRITERIA ---------------- 
    233252    // the ratio of improvement for the cost by subdivision and not-subdividing 
    234253    // for the previous subdivision 
     
    578597  int startEmptyCutDepth; 
    579598 
     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   
    580603  // ---------- Special improvements on the kd-tree construction -------- 
    581604  // flag if to split bounding boxes during splitting 
     
    588611  int     minObjectsToCreateMinBox, minDepthDistanceBetweenMinBoxes; 
    589612  float   minSA2ratioMinBoxes; 
    590   // Biasing the empty cuts (no objects are split). The cost is multiplied 
    591   // by the coefficient which is assumed to be 0.8-0.9 
    592   float  biasFreeCuts; 
    593613  // Make min box here 
    594614  bool   makeMinBoxHere; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktball.cpp

    r2608 r2629  
    1111 
    1212// GOLEM library 
    13 #include "ktbconf.h" 
    1413#include "ktb.h" 
    1514#include "ktbai.h" 
     15#include "ktbs.h" 
    1616#include "ktball.h" 
    1717#include "ktbtrav.h" 
     
    6161{ 
    6262  CKTBAllocManPredecessor *bc = 0; 
    63   bool useArray = true; 
     63  bool useArray = false; 
    6464   
    6565  // this should be already initialised, but we want to be sure 
    6666  if (useArray) { 
     67    cout << "Using kbt-tree based on arrays" << endl; 
    6768    // the implementation based on arrays 
    6869    bc = new CKTBABuildUp(); // file ktbai.cpp 
    6970  } 
    7071  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 
    7375  } 
    7476     
     
    425427void 
    426428CKTB::FindNearestI(RayPacket2x2 &raypack, 
    427                                    const Vector3 &boxmin, 
    428                                    const Vector3 &boxmax) 
     429                   const Vector3 &boxmin, 
     430                   const Vector3 &boxmax) 
    429431{ 
    430432  if (!makeMinBoxes) 
     
    766768} 
    767769 
    768    
     770 
     771static int 
     772cntInterior = 0; 
     773 
     774static int 
     775cntInteriorA[4] = {0, 0, 0, 0}; 
     776 
     777static int 
     778cntLeaves = 0; 
     779 
     780static int 
     781cntEmptyLeaves = 0; 
     782 
     783static int 
     784objReferences = 0; 
     785 
    769786SKTBNodeT* 
    770787CKTB::ImportBinLeaf(IN_STREAM &stream,  
     
    775792  int objId = leafId; 
    776793  int size; 
     794 
     795  cntLeaves++; 
    777796   
    778797  stream.read(reinterpret_cast<char *>(&size), sizeof(int)); 
     
    782801    SKTBNodeT* leaf = buildClass->AllocLeaf(0); 
    783802    *nodeToLink = buildClass->nodeToLink; 
     803    cntEmptyLeaves++; 
    784804    return leaf; 
    785805  } 
     
    790810 
    791811  ObjectContainer *newobjlist = new ObjectContainer; 
     812 
     813  objReferences += size; 
    792814   
    793815  // read object ids 
     
    826848} 
    827849 
    828  
    829850SKTBNodeT * 
    830851CKTB::ImportBinInterior(IN_STREAM  &stream, SKTBNodeT **nodeToLink) 
     
    839860    buildClass->AllocInteriorNode(axis, pos, 0, 0); 
    840861  *nodeToLink = buildClass->nodeToLink; 
    841          
     862 
     863  cntInterior++; 
     864  assert( (axis >= 0) && (axis < 3)); 
     865  cntInteriorA[axis]++; 
     866   
    842867  return interiorNode; 
    843868} 
     
    928953 
    929954  if (!stream.is_open()) { 
    930     cerr << "Kd-tree description file (.kdh) cannot be opened for reading\n"; 
     955    cerr << "Kd-tree description file (.kbt) cannot be opened for reading\n"; 
    931956    return true; // error 
    932957  } 
     
    963988  bc->InitAux(0, CKTBNodeAbstract::MAX_HEIGHT - 1, maxItemsAtOnce);   
    964989 
     990  for(int i = 0; i < 4; i++) 
     991    cntInteriorA[i] = 0; 
     992   
    965993  // Compute the box from all objects 
    966994  bbox.Initialize(); 
     
    10401068  builtUp = true;   
    10411069 
     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   
    10421078  return false; // OK 
    10431079} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktball.h

    r2608 r2629  
    1616// GOLEM headers 
    1717#include "configh.h" 
    18 #include "ktbconf.h" 
    1918//#include "ktbi.h" 
    2019#include "ktbai.h" 
     
    155154   
    156155  // allocate new build class and return it 
    157   static CKTBAllocManPredecessor* AllocBuildClass(); 
     156  CKTBAllocManPredecessor* AllocBuildClass(); 
    158157   
    159158  CKTBNodeIteratorPredecessor* GetTraversalClass() { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbconf.h

    r2608 r2629  
    2323#endif 
    2424 
     25// If we support the use of SSE instructions for ray shooting 
     26#define _USE_HAVRAN_SSE 
    2527 
    2628namespace GtpVisibilityPreprocessor { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbf2trv.cpp

    r2608 r2629  
    5757      results[i].intersectable; 
    5858    SimpleRay::IntersectionRes[i + copyOffset].tdist = 
     59    SimpleRay::IntersectionRes[i + copyOffset].maxt = 
    5960      results[i].tdist; 
    6061  } // for i 
     
    204205    FindNearestI(ray); 
    205206    rp.SetObject(i, SimpleRay::IntersectionRes[0].intersectable); 
    206     rp.SetT(i, SimpleRay::IntersectionRes[0].tdist); 
     207    rp.SetT(i, SimpleRay::IntersectionRes[0].maxt); 
    207208    // SimpleRay::IntersectionRes[0].intersectable->GetNormal(0); 
    208209  } // for 
     
    403404    FindNearestI(ray); 
    404405    rp.SetObject(i, SimpleRay::IntersectionRes[0].intersectable); 
    405     rp.SetT(i, SimpleRay::IntersectionRes[0].tdist); 
     406    rp.SetT(i, SimpleRay::IntersectionRes[0].maxt); 
    406407    // SimpleRay::IntersectionRes[0].intersectable->GetNormal(0); 
    407408  } // for 
     
    414415void 
    415416CKTBTraversal::FindNearestI(RayPacket2x2 &rp, 
    416                                                         const Vector3 &boxmin, 
    417                                                         const Vector3 &boxmax) 
     417                            const Vector3 &boxmin, 
     418                            const Vector3 &boxmax) 
    418419{ 
    419420  static AxisAlignedBox3 localbox; 
     
    606607    FindNearestI(ray, localbox); 
    607608    rp.SetObject(i, SimpleRay::IntersectionRes[0].intersectable); 
    608     rp.SetT(i, SimpleRay::IntersectionRes[0].tdist); 
     609    rp.SetT(i, SimpleRay::IntersectionRes[0].maxt); 
    609610    // SimpleRay::IntersectionRes[0].intersectable->GetNormal(0); 
    610611  } // for 
  • GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbftrav.cpp

    r2602 r2629  
    166166            cout << "Full leaf HIT " << endl;  
    167167#endif   
    168                
     168            SimpleRay::IntersectionRes[0].tdist = 
     169              SimpleRay::IntersectionRes[0].maxt; 
    169170#ifdef __TRAVERSAL_STATISTICS 
    170171            _allNodesTraversed += allNodesTraversed; 
     
    372373            cout << "Full leaf HIT " << endl;  
    373374#endif   
     375            SimpleRay::IntersectionRes[0].tdist = 
     376              SimpleRay::IntersectionRes[0].maxt; 
    374377               
    375378#ifdef __TRAVERSAL_STATISTICS 
     
    381384            // We have to add the distance from the original ray origin 
    382385            SimpleRay::IntersectionRes[0].tdist += tminOffset; 
     386            SimpleRay::IntersectionRes[0].maxt = SimpleRay::IntersectionRes[0].tdist; 
    383387             
    384388            // signed distance should be already set in TestFullLeaf 
     
    592596              tmax + Limits::Small; 
    593597            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; 
    594601 
    595602              // we remove the ray from the calculation 
     
    599606#ifdef _DEBUGKTB 
    600607              cout << "Full leaf HIT " << endl;  
    601 #endif   
     608#endif 
    602609               
    603610#ifdef __TRAVERSAL_STATISTICS 
  • GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbtrav.h

    r2602 r2629  
    150150  // of a packet to individual rays and traced individually. 
    151151  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) { } 
    153154#endif 
    154155   
     
    328329  // of a packet to individual rays and traced individually. 
    329330  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); 
    331333#endif // __SSE__ 
    332334#endif // _USE_HAVRAN_SSE   
     
    421423  // of a packet to individual rays and traced individually. 
    422424  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); 
    424427#endif // __SSE__ 
    425428#endif // _USE_HAVRAN_SSE   
  • GTP/trunk/Lib/Vis/Preprocessing/src/havran/raypack.h

    r2592 r2629  
    1010// 
    1111// 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 2005 
     12// Jakko Biker layout as proposed in the article on Intel Web Site in year 2005 
    1313// http://www.intel.com/cd/ids/developer/asmo-na/eng/245711.htm?page=1 
    1414 
     
    2121 
    2222#include "Vector3.h" 
     23#include "Matrix4x4.h" 
    2324#include "ktbconf.h" 
    2425   
     
    8889    // and also for shadow rays finish at the same object 
    8990    const Intersectable *_stopObject = NULL 
    90   ) 
    91   { 
     91  ) { 
    9292    // location 
    9393    ox[0] = orf[0].x; ox[1] = orf[1].x; ox[2] = orf[2].x; ox[3] = orf[3].x; 
     
    182182  int GetType() const { return ttype; } 
    183183 
     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   
    184199  // Reading and Setting origin of the ray and direction 
    185200  // Ray origin 
  • GTP/trunk/Lib/Vis/Preprocessing/src/havran/sbbox.h

    r2582 r2629  
    146146 
    147147  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   
    149152  // Test if the box is really sensefull 
    150153  bool IsCorrect(); 
     
    278281DescribeXYZ(const SBBox &b, std::ostream &app, int indent); 
    279282 
     283inline SBBox 
     284Intersect(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 
    280298#if 1 
    281299// The implementation I, the first version implemented by Vlastimil 
     
    425443#endif 
    426444 
     445 
    427446} 
    428447 
  • GTP/trunk/Lib/Vis/Preprocessing/src/havran/testrt.cpp

    r2602 r2629  
    2626#include "GlobalLinesRenderer.h" 
    2727#include "RayCaster.h" 
     28#include "Triangle3.h" 
     29#include "IntersectableWrapper.h" 
    2830#include "timer.h" 
    2931#include "raypack.h" 
     
    6466extern void Cleanup(); 
    6567 
    66 static string ReplaceSuffix(const string &filename, const string &a, const string &b) 
     68void 
     69_SortRays2(SimpleRayContainer &rays, 
     70           const int l, 
     71           const int r, 
     72           const int depth, 
     73           float box[12]) 
    6774{ 
    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--; 
    74121        } 
    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  }      
    77144} 
    78145 
    79  
    80 static int SplitFilenames(const string &str, vector<string> &filenames) 
     146void 
     147SortRays2(SimpleRayContainer &rays, const AxisAlignedBox3 &box) 
    81148{ 
    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}                                        
    96173 
    97174 
     
    254331  AxisAlignedBox3 bboxOrig = preprocessor->mSceneGraph->GetBox(); 
    255332  AxisAlignedBox3 bbox = bboxOrig; 
    256   int sizeDiag = Magnitude(bbox.Diagonal()); 
     333  float sizeDiag = Magnitude(bbox.Diagonal()); 
    257334  bbox.Enlarge(sizeDiag * 1.5f); 
    258335 
    259336  Vector3 origin, dir; 
    260337 
    261 //#define WIEN1 
    262 #define WIEN2 
     338#define WIEN1 
     339//#define WIEN2 
    263340//#define ARENA1 
    264341     
     
    267344  origin = Vector3(1099.9f, 183.0f, -387.0f); 
    268345  dir = Vector3(-0.6f, 0.0001f, -0.8f); 
     346  //dir = -dir; 
    269347#define DIREXISTS 
    270348#endif   
     
    292370  cout << "Computing image\n" << endl; 
    293371 
     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 
    294395#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   
    301409#if 1 
    302   // using ray packets 
    303   cam.SnapImagePacket("test-packet.tga", 
    304                       preprocessor->mRayCaster, 
    305                       bboxOrig, 
    306                       preprocessor->mSceneGraph); 
     410    // ray by ray 
     411    cam.SnapImage("test-rays.tga", 
     412                  preprocessor->mRayCaster, 
     413                  bboxOrig, 
     414                  preprocessor->mSceneGraph); 
    307415#endif 
    308416#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 
    315488   
    316489  cout << "Done\n" << endl; 
     
    327500}; 
    328501 
     502 
    329503// This is for testing RT implementation 
    330504void 
     
    427601  int cntMaxRays = 100000; 
    428602  Environment::GetSingleton()->GetIntValue("Rays.cnt", cntMaxRays); 
    429   vector<SimpleRay> rays; 
     603  SimpleRayContainer rays; 
    430604  SimpleRay rayTest; 
    431605  vector<RESult> results; 
     
    475649  if (castDoubleRays) 
    476650    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 
    478676  cout << "Starting to shoot " << cntRays * mult << " rays" << endl; 
     677  timer.Start(); 
    479678   
    480679  RayCaster *raycaster = preprocessor->mRayCaster; 
    481680  VssRayContainer vssRays; 
    482   AxisAlignedBox3 bboxOrig = preprocessor->mSceneGraph->GetBox(); 
    483681 
    484682//#define DEBUGRESULTS 
     
    494692#endif 
    495693 
    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    
    507694  SimpleRayContainer raysToTest; 
    508695  for (int i = 0; i < cntRays - 16; i++) { 
     696 
    509697#if 0 
    510698    int res = raycaster->CastRay(rays[i], 
     
    573761 
    574762  timer.Stop(); 
    575   long t2 = GetTime(); 
    576   cout<<"\n#RAY_CAST_TIME = "; 
     763  t2 = GetTime(); 
     764  cout<<"\n#SORTING + RAY_CAST_TIME = "; 
    577765  cout << TimeDiff(t1, t2)<<" [mikrosec]" 
    578766       << " userTime = " << timer.UserTime() << " realTime = " 
     
    695883  int cntMaxRays = 100000; 
    696884  Environment::GetSingleton()->GetIntValue("Rays.cnt", cntMaxRays); 
    697   vector<SimpleRay> rays; 
     885  SimpleRayContainer rays; 
    698886  SimpleRay rayTest; 
    699887  vector<RESult> results; 
     
    9571145  int cntMaxRays = 100000; 
    9581146  Environment::GetSingleton()->GetIntValue("Rays.cnt", cntMaxRays); 
    959   vector<SimpleRay> rays; 
     1147  SimpleRayContainer rays; 
    9601148  SimpleRay rayTest; 
    9611149  vector<RESult> results; 
     
    10381226  timer.Start(); 
    10391227  Vector3 boxMin, boxMax; 
     1228 
     1229  bool printOut = false; 
    10401230   
    10411231  SimpleRayContainer raysToTest; 
     
    10561246                               origin4, direction4, 
    10571247                               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    } 
    10601252 
    10611253    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      } 
    10721292    } // for j     
    10731293  } // for i 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r2625 r2629  
    2626#include "GlobalLinesRenderer.h" 
    2727#include "RayCaster.h" 
    28 //#include "vlastimil/testrt.h" 
    29  
    3028#include "ViewCellsManager.h" 
     29 
     30#include "testrt.h" 
     31 
    3132 
    3233#ifdef USE_QT   
     
    134135#if 0 
    135136  // Test code by VH 
    136   //TestRTcamera(argc, argv); 
     137  TestRTcamera(argc, argv); 
    137138  //TestRTfromFile(argc, argv); 
    138   TestRTfromFilePackets(argc, argv); 
     139  //TestRTfromFilePackets(argc, argv); 
     140  //TestRT_4_fromFile(argc, argv); 
    139141  return 0; 
    140142#endif 
  • GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro

    r2627 r2629  
    3434  $$NONGTP/Zlib/include $$NONGTP/Boost $$NONGTP/Devil/include sparsehash/src 
    3535 
    36 win32:LIBPATH += GL $$XERCES/lib $$NONGTP/Devil/lib \ 
     36win32:LIBPATH += GL $$NONGTP/Xerces/xerces/lib $$NONGTP/Devil/lib \ 
    3737  $$NONGTP/glut $$NONGTP/Boost/lib $$NONGTP/Zlib/lib  
    3838 
     
    6161CONFIG(release) { 
    6262win32:LIBS += xerces-c_2.lib  
    63 #win32:LIBS += xerces-c_static_2.lib  
    6463} 
    6564 
    6665CONFIG(debug) { 
    6766win32:LIBS += xerces-c_2D.lib  
    68 #win32:LIBS += xerces-c_static_2D.lib  
    6967} 
    7068 
     
    127125Intersectable.cpp TraversalTree.cpp ObjectPvs.cpp ObjectsParser.cpp \ 
    128126FilterBasedDistribution.cpp DifferenceSampling.cpp HavranRayCaster.cpp \ 
    129 OcclusionQuery.cpp RandomViewCellsHandler.cpp 
     127HavranDynRayCaster.cpp OcclusionQuery.cpp  
    130128 
    131129 
     
    135133SOURCES += havran/allocgo2.cpp havran/ktbai.cpp havran/ktbtrav.cpp \ 
    136134havran/ktb.cpp havran/ktball.cpp havran/sbbox.cpp \ 
    137 havran/ktb8b.cpp havran/ktbftrav.cpp havran/ktbf2trv.cpp havran/timer.cpp 
     135havran/ktb8b.cpp havran/ktbftrav.cpp havran/timer.cpp  
    138136 
    139137 
Note: See TracChangeset for help on using the changeset viewer.