Changeset 1199


Ignore:
Timestamp:
08/11/06 15:23:47 (18 years ago)
Author:
bittner
Message:

code merge

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

Legend:

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

    r1184 r1199  
    2323void BoostPreprocessorThread::Main() 
    2424{ 
    25         Camera camera; 
     25  Camera camera; 
    2626 
    27         if (0) 
     27  if (0) 
    2828        { 
    2929                // camera.LookAtBox(mPreprocessor->mKdTree->GetBox()); 
     
    3636                camera.SnapImage("camera.jpg", mPreprocessor->mKdTree, mPreprocessor->mSceneGraph); 
    3737        }  
     38   
     39  if (0) { 
     40        camera.LookInBox(mPreprocessor->mKdTree->GetBox()); 
     41        camera.SetPosition(camera.mPosition + Vector3(-250,0,-550)); 
     42        camera.SnapImage("camera2.jpg", mPreprocessor->mKdTree, mPreprocessor->mSceneGraph); 
     43  } 
    3844 
    39         if (0) { 
    40                 camera.LookInBox(mPreprocessor->mKdTree->GetBox()); 
    41                 camera.SetPosition(camera.mPosition + Vector3(-250,0,-550)); 
    42                 camera.SnapImage("camera2.jpg", mPreprocessor->mKdTree, mPreprocessor->mSceneGraph); 
    43         } 
    44  
    45         if (0) { 
    46                 camera.SetPosition( mPreprocessor->mKdTree->GetBox().Center() - Vector3(0,-100,0) ); 
    47                 camera.SetDirection(Vector3(1, 0, 0)); 
    48                 camera.SnapImage("camera3.jpg", mPreprocessor->mKdTree, mPreprocessor->mSceneGraph); 
    49         } 
    50  
    51         if (mPreprocessor->mComputeVisibility) { 
    52                 mPreprocessor->ComputeVisibility(); 
    53                 //      mPreprocessor->ExportPreprocessedData("scene.vis"); 
    54                 mPreprocessor->PostProcessVisibility(); 
    55         } 
    56  
    57         cerr << "Preprocessor main finished...\n"; 
     45  if (0) { 
     46        camera.SetPosition( mPreprocessor->mKdTree->GetBox().Center() - Vector3(0,-100,0) ); 
     47        camera.SetDirection(Vector3(1, 0, 0)); 
     48        camera.SnapImage("camera3.jpg", mPreprocessor->mKdTree, mPreprocessor->mSceneGraph); 
     49  } 
     50   
     51  if (mPreprocessor->mComputeVisibility) { 
     52        mPreprocessor->ComputeVisibility(); 
     53        //      mPreprocessor->ExportPreprocessedData("scene.vis"); 
     54        mPreprocessor->PostProcessVisibility(); 
     55  } 
     56   
     57  cerr << "Preprocessor main finished...\n"; 
    5858   
    5959} 
     
    6262BoostPreprocessorThread::~BoostPreprocessorThread() 
    6363{ 
    64         cerr << "Boost Preprocessor thread destructor ... \n"; 
    65         DEL_PTR(mThread); 
     64  cerr << "Boost Preprocessor thread destructor ... \n"; 
     65  DEL_PTR(mThread); 
    6666} 
    6767 
     
    6969void BoostPreprocessorThread::InitThread() 
    7070{ 
    71         mThread = new boost::thread(*this); 
     71  mThread = new boost::thread(*this); 
    7272} 
    7373 
     
    7575void BoostPreprocessorThread::RunThread() 
    7676{ 
    77         mThread->join(); 
     77  mThread->join(); 
    7878} 
    79   
     79 
    8080} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp

    r1174 r1199  
    18161816                                        "false"); 
    18171817 
     1818        RegisterOption("RssTree.hybridDepth", optInt, "hybrid_depth=", "10"); 
    18181819        RegisterOption("RssTree.maxDepth", optInt, "kd_depth=", "12"); 
    18191820        RegisterOption("RssTree.minPvs", optInt, "kd_minpvs=", "1"); 
     
    18251826        RegisterOption("RssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0"); 
    18261827        RegisterOption("RssTree.randomize", optBool, "randomize=", "false"); 
    1827         RegisterOption("RssTree.splitType", optString, "split=", "queries"); 
     1828        RegisterOption("RssTree.splitType", optString, "rss_split=", "queries"); 
    18281829        RegisterOption("RssTree.splitUseOnlyDrivingAxis", optBool, "splitdriving=", "false"); 
    18291830 
     
    23542355  if (!GetParam(' ', 0, filename)) { 
    23552356    // user didn't specified environment file explicitly, so 
    2356     strcpy(filename, "default.Environment::GetSingleton()"); 
     2357    strcpy(filename, "default.env"); 
    23572358  } 
    23582359   
  • GTP/trunk/Lib/Vis/Preprocessing/src/Makefile

    r1112 r1199  
    11############################################################################# 
    22# Makefile for building: preprocessor 
    3 # Generated by qmake (2.00a) (Qt 4.1.2) on: po 10. VII 19:18:45 2006 
     3# Generated by qmake (2.00a) (Qt 4.1.2) on: pá 11. VIII 14:29:54 2006 
    44# Project:  preprocessor.pro 
    55# Template: app 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp

    r1076 r1199  
    164164                                        Ray &ray, 
    165165                                        float &nearestT, 
     166                                        Vector3 &nearestNormal, 
    166167                                        int &nearestFace, 
    167168                                        Intersectable *instance 
     
    170171  float t; 
    171172  int hit = 0; 
    172   if (RayFaceIntersection(faceIndex, ray, t, nearestT) == Ray::INTERSECTION) { 
     173  Vector3 normal; 
     174  if (RayFaceIntersection(faceIndex, ray, t, normal, nearestT) == Ray::INTERSECTION) { 
    173175    switch (ray.GetType()) { 
    174176    case Ray::GLOBAL_RAY: 
    175       ray.intersections.push_back(Ray::Intersection(t, instance, faceIndex)); 
     177      ray.intersections.push_back(Ray::Intersection(t, normal, instance, faceIndex)); 
    176178      hit++; 
    177179      break; 
    178180    case Ray::LOCAL_RAY: 
    179181      nearestT = t; 
     182          nearestNormal = normal; 
    180183      nearestFace = faceIndex; 
    181184      hit++; 
     
    183186    case Ray::LINE_SEGMENT: 
    184187      if (t <= 1.0f) { 
    185                 ray.intersections.push_back(Ray::Intersection(t, instance, faceIndex)); 
     188                ray.intersections.push_back(Ray::Intersection(t, normal, instance, faceIndex)); 
    186189                hit++; 
    187190      } 
     
    205208  int hits = 0; 
    206209  float nearestT = MAX_FLOAT; 
     210  Vector3 nearestNormal; 
    207211  int nearestFace = -1; 
    208212   
     
    214218                faceIndex < mFaces.size(); 
    215219                faceIndex++) { 
    216     hits += CastRayToFace(faceIndex, ray, nearestT, nearestFace, instance); 
     220    hits += CastRayToFace(faceIndex, ray, nearestT, nearestNormal, nearestFace, instance); 
    217221    if (mIsConvex && nearestFace != -1) 
    218222      break; 
     
    221225  if ( hits && ray.GetType() == Ray::LOCAL_RAY ) { 
    222226    if (ray.intersections.size()) 
    223       ray.intersections[0] = Ray::Intersection(nearestT, instance, nearestFace); 
     227      ray.intersections[0] = Ray::Intersection(nearestT, nearestNormal, instance, nearestFace); 
    224228    else 
    225       ray.intersections.push_back(Ray::Intersection(nearestT, instance, nearestFace)); 
     229      ray.intersections.push_back(Ray::Intersection(nearestT, nearestNormal, instance, nearestFace)); 
    226230  } 
    227231   
     
    240244  int hits = 0; 
    241245  float nearestT = MAX_FLOAT; 
     246  Vector3 nearestNormal; 
    242247  int nearestFace = -1; 
    243  
     248   
    244249  if (ray.GetType() == Ray::LOCAL_RAY && ray.intersections.size()) 
    245250    nearestT = ray.intersections[0].mT; 
     
    248253                fi != faces.end(); 
    249254                fi++) { 
    250     hits += CastRayToFace(*fi, ray, nearestT, nearestFace, instance); 
     255    hits += CastRayToFace(*fi, ray, nearestT, nearestNormal, nearestFace, instance); 
    251256    if (mIsConvex && nearestFace != -1) 
    252257      break; 
     
    255260  if ( hits && ray.GetType() == Ray::LOCAL_RAY ) { 
    256261    if (ray.intersections.size()) 
    257       ray.intersections[0] = Ray::Intersection(nearestT, instance, nearestFace); 
     262      ray.intersections[0] = Ray::Intersection(nearestT, nearestNormal,instance, nearestFace); 
    258263    else 
    259       ray.intersections.push_back(Ray::Intersection(nearestT, instance, nearestFace)); 
     264      ray.intersections.push_back(Ray::Intersection(nearestT, nearestNormal,instance, nearestFace)); 
    260265  } 
    261266   
     
    316321                                                  const Ray &ray, 
    317322                                                  float &t, 
     323                                                  Vector3 &normal, 
    318324                                                  const float nearestT 
    319325                                                  ) 
     
    342348  } 
    343349   
     350  normal = plane.mNormal; 
     351 
    344352  t = (-plane.mD - DotProd(plane.mNormal, ray.GetLoc())) / dot; 
    345353 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h

    r1020 r1199  
    176176                                Ray &ray, 
    177177                                float &nearestT, 
     178                                Vector3 &nearestNormal, 
    178179                                int &nearestFace, 
    179180                                Intersectable *instance 
     
    183184  int 
    184185  RayFaceIntersection(const int faceIndex, 
    185                                         const Ray &ray, 
    186                                         float &t, 
    187                                         const float nearestT 
    188                                         ); 
     186                                          const Ray &ray, 
     187                                          float &t, 
     188                                          Vector3 &normal, 
     189                                          const float nearestT 
     190                                          ); 
    189191   
    190192  Plane3 GetFacePlane(const int faceIndex); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1197 r1199  
    299299         
    300300        if (!mViewCellsManager) 
    301                 return false; 
    302  
     301          return false; 
     302         
    303303        mViewCellsManager->ApplyFilter(mKdTree, 
    304304                                                                   mApplyVisibilityFilter ? mVisibilityFilterWidth : -1.0f, 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Ray.cpp

    r863 r1199  
    227227{ 
    228228  loc = vssRay.mOrigin; 
    229   sourceObject = Intersection(0, vssRay.mOriginObject, 0); 
     229  sourceObject = Intersection(0, vssRay.GetDir(), vssRay.mOriginObject, 0); 
    230230  mType = LOCAL_RAY; 
    231231   
     
    239239  intersections.clear(); 
    240240  if (vssRay.mTerminationObject) 
    241         intersections.push_back(Intersection(len, vssRay.mTerminationObject, 0)); 
     241        intersections.push_back(Intersection(len, -vssRay.GetDir(), vssRay.mTerminationObject, 0)); 
    242242   
    243243  Precompute(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Ray.h

    r1112 r1199  
    3939    float mT; 
    4040 
     41        // the normal of the intersection 
     42        Vector3 mNormal; 
     43         
    4144    // can be either mesh or a viewcell 
    4245    Intersectable *mObject; 
     
    4447    // the face of the intersectable 
    4548    int mFace; 
    46  
     49         
    4750    Intersection(const float t, 
     51                                 const Vector3 &normal, 
    4852                                 Intersectable *object, 
    49                                  const int face):mT(t), mObject(object), mFace(face) {} 
     53                                 const int face):mT(t), 
     54                                                                 mNormal(normal), 
     55                                                                 mObject(object), mFace(face) {} 
    5056                 
    51                                  Intersection(): mT(0), mObject(NULL), mFace(0) {} 
     57                                 Intersection(): mT(0), mNormal(0,0,0), mObject(NULL), mFace(0) {} 
    5258                 
    5359    bool operator<( 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp

    r1151 r1199  
    2323static bool fromBoxVisibility = false; 
    2424 
    25 #define ADD_RAYS_IN_PLACE 0 
     25#define ADD_RAYS_IN_PLACE 1 
    2626   
    2727RssPreprocessor::RssPreprocessor(): 
     
    122122  int hits = 0; 
    123123  static Ray ray; 
     124  Intersectable *objectA, *objectB; 
     125  Vector3 pointA, pointB; 
     126 
    124127  //  AxisAlignedBox3 box = Union(mKdTree->GetBox(), mViewCellsManager->GetViewSpaceBox()); 
    125  
     128   
    126129  AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); 
    127130 
     
    132135         
    133136  SetupRay(ray, viewPoint, direction); 
    134  
    135   if (!mDetectEmptyViewSpace) 
    136         ray.mFlags &= ~Ray::CULL_BACKFACES; 
    137   else 
    138         ray.mFlags |= Ray::CULL_BACKFACES; 
    139  
     137  ray.mFlags &= ~Ray::CULL_BACKFACES; 
    140138 
    141139  // cast ray to KD tree to find intersection with other objects 
    142   Intersectable *objectA, *objectB; 
    143   Vector3 pointA, pointB; 
    144140  float bsize = Magnitude(box.Size()); 
    145  
     141   
    146142   
    147143  if (mKdTree->CastRay(ray)) { 
    148144        objectA = ray.intersections[0].mObject; 
    149145        pointA = ray.Extrap(ray.intersections[0].mT); 
     146        if (mDetectEmptyViewSpace) 
     147          if (DotProd(ray.intersections[0].mNormal, direction) >= 0) { 
     148                // discard the sample 
     149                return 0; 
     150          } 
     151         
    150152  } else { 
    151153        objectA = NULL; 
     
    158160  } 
    159161 
    160  
    161   if (mDetectEmptyViewSpace) { 
    162         SetupRay(ray, pointA, -direction); 
    163   } else 
    164         SetupRay(ray, viewPoint, -direction); 
    165          
    166   if (!mDetectEmptyViewSpace) 
    167         ray.mFlags &= ~Ray::CULL_BACKFACES; 
    168   else 
    169         ray.mFlags |= Ray::CULL_BACKFACES; 
    170  
     162   
     163  SetupRay(ray, viewPoint, -direction); 
     164  ray.mFlags &= ~Ray::CULL_BACKFACES; 
     165   
    171166  if (mKdTree->CastRay(ray)) { 
    172167        objectB = ray.intersections[0].mObject; 
    173168        pointB = ray.Extrap(ray.intersections[0].mT); 
     169        if (mDetectEmptyViewSpace) 
     170          if (DotProd(ray.intersections[0].mNormal, direction) <= 0) { 
     171                // discard the sample 
     172                return 0; 
     173          } 
    174174  } else { 
    175175        objectB = NULL; 
     
    180180          return 0; 
    181181  } 
    182  
    183   //  if (objectA == NULL && objectB != NULL) { 
    184   if (mDetectEmptyViewSpace) { 
    185         // cast again to ensure that there is no objectA 
    186         SetupRay(ray, pointB, direction); 
    187         ray.mFlags |= Ray::CULL_BACKFACES; 
    188         if (mKdTree->CastRay(ray)) { 
    189           objectA = ray.intersections[0].mObject; 
    190           pointA = ray.Extrap(ray.intersections[0].mT); 
    191         } 
    192   } 
    193182   
    194183   
    195184  VssRay *vssRay  = NULL; 
    196  
    197185  bool validSample = (objectA != objectB); 
    198186  if (validSample) { 
     
    207195          vssRays.push_back(vssRay); 
    208196          hits ++; 
    209  
    210197        } 
    211198         
     
    587574        cout<<"Generating initial rays..."<<endl<<flush; 
    588575 
    589         GenerateRays(mInitialSamples/3, SPATIAL_BOX_BASED_DISTRIBUTION, rays); 
    590         GenerateRays(mInitialSamples/3, OBJECT_BASED_DISTRIBUTION, rays); 
    591         GenerateRays(mInitialSamples/3, DIRECTION_BASED_DISTRIBUTION, rays); 
    592         //      GenerateRays(mInitialSamples/4, OBJECT_DIRECTION_BASED_DISTRIBUTION, rays); 
    593  
     576        if (mUseImportanceSampling) { 
     577          GenerateRays(mInitialSamples/3, SPATIAL_BOX_BASED_DISTRIBUTION, rays); 
     578          GenerateRays(mInitialSamples/3, OBJECT_BASED_DISTRIBUTION, rays); 
     579          GenerateRays(mInitialSamples/3, DIRECTION_BASED_DISTRIBUTION, rays); 
     580          //    GenerateRays(mInitialSamples/4, OBJECT_DIRECTION_BASED_DISTRIBUTION, rays); 
     581        } else { 
     582          int rayType = SPATIAL_BOX_BASED_DISTRIBUTION; 
     583          if (mObjectBasedSampling) 
     584                rayType = OBJECT_BASED_DISTRIBUTION; 
     585          else 
     586                if (mDirectionalSampling) 
     587                  rayType = DIRECTION_BASED_DISTRIBUTION; 
     588          cout<<"Generating rays..."<<endl; 
     589          GenerateRays(mRssSamplesPerPass, rayType, rays); 
     590        } 
     591         
     592         
    594593        cout<<"Casting initial rays..."<<endl<<flush; 
    595594        CastRays(rays, mVssRays); 
     
    904903         
    905904         
    906         if (!mUseImportanceSampling)  
     905        if (!mUseImportanceSampling) 
    907906          CLEAR_CONTAINER(vssRays); 
    908907        // otherwise the rays get deleted by the rss tree update according to RssTree.maxRays .... 
     
    919918  if (mUseViewcells) { 
    920919 
    921           if(0) 
     920        if(0) 
    922921          { 
    923                   VssRayContainer selectedRays; 
    924                   int desired = mViewCellsManager->GetVisualizationSamples(); 
    925  
    926                   mVssRays.SelectRays(desired, selectedRays); 
    927  
    928                   mViewCellsManager->Visualize(mObjects, selectedRays); 
    929           } 
    930            
    931           // view cells after sampling 
    932           mViewCellsManager->PrintStatistics(Debug); 
    933        
    934           //-- render simulation after merge 
    935           cout << "\nevaluating bsp view cells render time after sampling ... "; 
    936            
    937           mRenderSimulator->RenderScene(); 
    938           SimulationStatistics ss; 
    939           mRenderSimulator->GetStatistics(ss); 
    940            
    941           cout << " finished" << endl; 
    942           cout << ss << endl; 
    943           Debug << ss << endl; 
     922                VssRayContainer selectedRays; 
     923                int desired = mViewCellsManager->GetVisualizationSamples(); 
     924                 
     925                mVssRays.SelectRays(desired, selectedRays); 
     926                 
     927                mViewCellsManager->Visualize(mObjects, selectedRays); 
     928          } 
     929         
     930        // view cells after sampling 
     931        mViewCellsManager->PrintStatistics(Debug); 
     932         
     933        //-- render simulation after merge 
     934        cout << "\nevaluating bsp view cells render time after sampling ... "; 
     935         
     936        mRenderSimulator->RenderScene(); 
     937        SimulationStatistics ss; 
     938        mRenderSimulator->GetStatistics(ss); 
     939         
     940        cout << " finished" << endl; 
     941        cout << ss << endl; 
     942        Debug << ss << endl; 
    944943         
    945944  } 
     
    959958 
    960959 
    961   // mViewCellsManager->ExportViewCells("visibility.xml", 
     960  //mViewCellsManager->ExportViewCells("visibility.xml", 
    962961  //                                                                     true); 
    963962   
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp

    r1189 r1199  
    3636#define DEBUG_SPLITS 0 
    3737 
     38#define EVAL_VIEWCELLS 0 
     39   
    3840// Static variables 
    3941int 
     
    156158                exit(1); 
    157159          } 
    158          
     160 
     161  Environment::GetSingleton()->GetIntValue("RssTree.hybridDepth", mHybridDepth); 
     162 
    159163  Environment::GetSingleton()->GetBoolValue("RssTree.randomize", randomize); 
    160164  Environment::GetSingleton()->GetBoolValue("RssTree.splitUseOnlyDrivingAxis", mSplitUseOnlyDrivingAxis); 
     
    568572  Debug<<"Split Info:"<<endl; 
    569573  Debug<<"axis="<<info.axis<<" ratio="<<info.costRatio<<endl; 
    570   Debug<<"viewcells="<<info.viewCells<< 
    571         " viewcells back="<<info.viewCellsBack<< 
    572         " viewcells back="<<info.viewCellsFront<<endl; 
     574  Debug<<"rays="<<info.rays<< 
     575        " rays back="<<info.raysBack<< 
     576        " rays front="<<info.raysFront<<endl; 
     577  Debug<<"c="<<info.contribution<< 
     578        " c back="<<info.contributionBack<< 
     579        " c front="<<info.contributionFront<<endl; 
     580 
     581  //  Debug<<"viewcells="<<info.viewCells<< 
     582  //    " viewcells back="<<info.viewCellsBack<< 
     583  //    " viewcells back="<<info.viewCellsFront<<endl; 
    573584#endif 
    574585   
     
    579590  } 
    580591         
    581 #if 0    
     592#if 0 
    582593  cout<< 
    583594        "pvs="<<leaf->mPvsSize<< 
     
    620631        switch (costMethod) { 
    621632        case 0: { 
    622           //            float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 
    623633          float sum = info.pvsBack*(info.position - minBox) + info.pvsFront*(maxBox - info.position); 
    624634          float newCost = ct_div_ci + sum/sizeBox; 
     
    627637          break; 
    628638        } 
     639        case 6: { 
     640          float sum = info.raysBack*(info.position - minBox) + info.raysFront*(maxBox - info.position); 
     641          float newCost = ct_div_ci + sum/sizeBox; 
     642          float oldCost = info.rays; 
     643          info.costRatio = newCost/oldCost; 
     644          break; 
     645        } 
     646        case 7: { 
     647          float benefit = 
     648                (sqr(info.contributionBack) + sqr(info.contributionFront))/ 
     649                (2.0f*sqr(info.contribution)); 
     650          info.costRatio = 1.0f/(benefit + Limits::Small); 
     651          break; 
     652        } 
     653 
     654           
    629655        case 1: { 
    630656          float newContrib = 
     
    690716                                           ) 
    691717{ 
     718  info.rays = 0; 
    692719  info.raysBack = 0; 
    693720  info.raysFront = 0; 
     
    699726 
    700727 
     728 
    701729  float sumWeights = Limits::Small; 
    702730  float sumWeightsBack = Limits::Small; 
     
    709737  Intersectable::NewMail(); 
    710738 
     739#if EVAL_VIEWCELLS 
    711740  // count the numebr of viewcells first 
    712741  for(RssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 
     
    714743          ri++) 
    715744        if ((*ri).mRay->IsActive()) { 
     745 
    716746          ViewCellContainer::const_iterator it = (*ri).mRay->mViewCells.begin(); 
    717747          for (; it != (*ri).mRay->mViewCells.end(); ++it) { 
     
    722752          } 
    723753        } 
     754#endif 
    724755   
    725756  Intersectable::NewMail(3); 
     
    741772          sumWeights += weight; 
    742773          sumContribution += contribution; 
    743            
     774          info.rays++; 
    744775          if (side <= 0) { 
    745776                info.raysBack++; 
     
    755786           
    756787          AddObject2Pvs((*ri).GetObject(), side, info.pvsBack, info.pvsFront); 
     788 
     789#if EVAL_VIEWCELLS 
    757790          AddViewcells2Pvs((*ri).mRay->mViewCells, 
    758791                                           side, 
    759792                                           info.viewCellsBack, 
    760793                                           info.viewCellsFront); 
     794#endif 
    761795        } 
    762796 
     
    775809  else 
    776810        info.contributionFront = 0.0f; 
    777    
     811 
     812  //  info.costRatio = 0.1 + Random(0.5f); 
     813  //  return; 
     814 
    778815  GetCostRatio( 
    779816                           leaf, 
     
    804841  bool allowDirSplit = Magnitude(sBox.Size())*dirSplitBoxSize < Magnitude(bbox.Size()); 
    805842                 
     843  bool useCyclingAxis = true; 
     844 
     845  if (splitType == ESplitHeuristic || 
     846          (splitType == ESplitHybrid && leaf->depth > mHybridDepth)) 
     847        useCyclingAxis = false; 
     848   
     849  int cyclingAxis = 0; 
     850   
     851  if (leaf->parent)  
     852        cyclingAxis = (leaf->parent->axis + 1)%5; 
     853   
     854  if (0 && useCyclingAxis) { 
     855        int axis = cyclingAxis; 
     856        info.position = (sBox.Min()[axis] + sBox.Max()[axis])*0.5f; 
     857        info.axis = axis; 
     858        info.costRatio = 0.5f; // not true but good for speeding up the subdivision at the top levels! 
     859        info.raysBack = info.raysFront = leaf->rays.size()/2; 
     860        return; 
     861  } 
     862 
    806863   
    807864  for (int axis = 0; axis < 5; axis++) 
     
    811868                ) { 
    812869          nInfo[axis].axis = axis; 
    813           if (!mSplitUseOnlyDrivingAxis || axis == sAxis || axis == dAxis) { 
     870          if ((!useCyclingAxis && (!mSplitUseOnlyDrivingAxis || axis == sAxis || axis == dAxis)) 
     871                  || (useCyclingAxis && (axis == cyclingAxis)) 
     872                  ) { 
    814873                 
    815874                if (splitType == ESplitRegular) { 
     
    828887                  } else 
    829888                        if (splitType == ESplitHybrid) { 
    830                           if (leaf->depth > 7) 
     889                          if (leaf->depth > mHybridDepth) 
    831890                                EvalCostRatioHeuristic( 
    832891                                                                           leaf, 
     
    894953  currInfo.pvsFront = leaf->GetPvsSize(); 
    895954 
    896   
     955 
     956  float sumWeights = Limits::Small; 
     957  float sumWeightsBack = Limits::Small; 
     958  float sumWeightsFront = Limits::Small; 
     959   
     960  float sumContribution = 0.0f; 
     961  float sumContributionBack = 0.0f; 
     962  float sumContributionFront = 0.0f; 
     963 
     964   
    897965  float sizeBox = maxBox - minBox; 
    898966   
     
    904972 
    905973  currInfo.viewCells = 0; 
     974  currInfo.rays = 0; 
    906975 
    907976  Intersectable::NewMail(); 
     
    911980          ri++) 
    912981        if ((*ri).mRay->IsActive()) { 
     982 
     983          float weight, contribution; 
     984          GetRayContribution(*ri, weight, contribution); 
     985 
     986          sumWeights += weight; 
     987          sumContribution += contribution; 
     988          currInfo.rays++; 
     989 
    913990          Intersectable *object = (*ri).GetObject(); 
    914991          if (object) 
     
    919996                  object->mCounter++; 
    920997           
     998#if EVAL_VIEWCELLS        
    921999          // and do the same for all viewcells 
    9221000          ViewCellContainer::const_iterator it = (*ri).mRay->mViewCells.begin(); 
     
    9311009                  viewcell->mCounter++; 
    9321010          } 
    933         } 
    934  
     1011#endif 
     1012        } 
     1013 
     1014  if (sumWeights!=0.0f) 
     1015        currInfo.contribution = sumContribution/sumWeights; 
     1016  else 
     1017        currInfo.contribution = 0.0f; 
     1018 
     1019  sumWeightsFront = sumWeights; 
     1020  sumContributionFront = sumContribution; 
     1021 
     1022  sumWeightsBack = 0; 
     1023  sumContributionBack = 0; 
     1024   
    9351025  currInfo.viewCellsBack = 0; 
    9361026  currInfo.viewCellsFront = currInfo.viewCells; 
    937   
     1027   
    9381028  Intersectable::NewMail(); 
    939          
     1029   
    9401030  for(vector<SortableEntry>::const_iterator ci = splitCandidates->begin(); 
    9411031          ci < splitCandidates->end(); 
     
    9451035          currInfo.raysFront--; 
    9461036          currInfo.raysBack++; 
     1037 
    9471038          RssTreeNode::RayInfo *rayInfo = (RssTreeNode::RayInfo *) (*ci).data; 
     1039           
     1040          float weight, contribution; 
     1041          GetRayContribution(*rayInfo, weight, contribution); 
     1042 
     1043          sumWeightsBack += weight; 
     1044          sumContributionBack += contribution; 
     1045 
     1046          sumWeightsFront -= weight; 
     1047          sumContributionFront -= contribution; 
     1048 
    9481049          Intersectable *object = rayInfo->GetObject(); 
    9491050          if (object) { 
     
    9551056                  currInfo.pvsFront--; 
    9561057          } 
     1058 
     1059#if EVAL_VIEWCELLS        
    9571060          ViewCellContainer::const_iterator it = rayInfo->mRay->mViewCells.begin(); 
    9581061          for (; it != rayInfo->mRay->mViewCells.end(); ++it) { 
     
    9651068                  currInfo.viewCellsFront--; 
    9661069          } 
     1070#endif 
     1071           
    9671072          break; 
    9681073        } 
     
    9731078        if (position > minBand && position < maxBand) { 
    9741079          currInfo.position = position; 
     1080 
     1081           
     1082          if (sumWeightsBack!=0.0f) 
     1083                info.contributionBack = sumContributionBack/sumWeightsBack; 
     1084          else 
     1085                info.contributionBack = 0.0f; 
     1086           
     1087          if (sumWeightsFront!=0.0f) 
     1088                info.contributionFront = sumContributionFront/sumWeightsFront; 
     1089          else 
     1090                info.contributionFront = 0.0f; 
    9751091           
    9761092          GetCostRatio( 
     
    11921308  // update stats 
    11931309  stat.rayRefs -= (int)leaf->rays.size(); 
    1194   stat.rayRefs += info.raysBack + info.raysFront; 
     1310  stat.rayRefs += back->rays.size() + front->rays.size(); 
    11951311 
    11961312   
     
    20932209  } 
    20942210   
    2095   //  int numberOfTries = numberOfRays*4; 
    2096   int numberOfTries = numberOfRays; 
    2097   int generated = 0; 
    2098  
    2099   Intersectable::NewMail(); 
    2100   vector<Intersectable *> pvs(0); 
    2101   pvs.reserve(leaf->GetPvsSize()); 
    2102   for(RssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 
    2103           ri != leaf->rays.end(); 
    2104           ri++) { 
    2105         Intersectable *object = (*ri).GetObject(); 
    2106         if (object) { 
    2107           if (!object->Mailed()) { 
    2108                 object->Mail(); 
    2109                 object->mCounter = 1; 
    2110                 pvs.push_back(object); 
    2111                 if (exporter) 
    2112                   exporter->ExportIntersectable(object); 
    2113           } else { 
    2114                 object->mCounter++; 
    2115           } 
    2116         } 
    2117   } 
    2118   // sort objects based on their mCounter 
    2119   sort(pvs.begin(), pvs.end(), Intersectable::GreaterCounter); 
    2120    
     2211 
    21212212  float extendedConvexCombinationProb = 0.0f; //0.7f 
    21222213  //  float silhouetteCheckPercentage = 1.0f; //0.5f 
    21232214  float silhouetteCheckPercentage = 0.0f; //0.9f; // 0.5f; 
    21242215  float silhouetteObjectCheckPercentage = 0.8f; 
     2216 
     2217  //  int numberOfTries = numberOfRays*4; 
     2218  int numberOfTries = numberOfRays; 
     2219  int generated = 0; 
     2220 
     2221  vector<Intersectable *> pvs(0); 
     2222  if (silhouetteCheckPercentage != 0.0f) { 
     2223        Intersectable::NewMail(); 
     2224        pvs.reserve(leaf->GetPvsSize()); 
     2225        for(RssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 
     2226                ri != leaf->rays.end(); 
     2227                ri++) { 
     2228          Intersectable *object = (*ri).GetObject(); 
     2229          if (object) { 
     2230                if (!object->Mailed()) { 
     2231                  object->Mail(); 
     2232                  object->mCounter = 1; 
     2233                  pvs.push_back(object); 
     2234                  if (exporter) 
     2235                        exporter->ExportIntersectable(object); 
     2236                } else { 
     2237                  object->mCounter++; 
     2238                } 
     2239          } 
     2240        } 
     2241        // sort objects based on their mCounter 
     2242        sort(pvs.begin(), pvs.end(), Intersectable::GreaterCounter); 
     2243  } 
     2244   
    21252245  for (int i=0; generated < numberOfRays && i < numberOfTries; i++) { 
    21262246        bool useExtendedConvexCombination = ((nrays >= 2) && (Random(1.0f) < 
     
    23452465int 
    23462466RssTree::PruneRays( 
    2347                                    const int desired 
     2467                                   const int maxRays 
    23482468                                   ) 
    23492469{ 
    2350   bool globalPrunning = true; 
     2470  bool globalPrunning = false; 
    23512471 
    23522472  stack<RssTreeNode *> tstack; 
    23532473  int prunned = 0; 
    23542474 
    2355   Debug<<"Prunning rays...\nOriginal size "<<stat.rayRefs<<endl; 
     2475  // prune more rays to amortize  the procedure 
     2476  int desired = maxRays*0.8f; 
     2477 
     2478  Debug<<"Prunning rays...\nOriginal size "<<stat.rayRefs<<endl<<flush; 
    23562479 
    23572480  if (globalPrunning) { 
     
    23632486                 GreaterWeightedPvsContribution); 
    23642487         
    2365         if ( desired >= allRays.size() ) 
     2488        if ( maxRays >= allRays.size() ) 
    23662489          return 0; 
    2367          
     2490 
    23682491        float contributionThreshold = allRays[desired]->mWeightedPvsContribution; 
    23692492         
     
    23872510        // prune random rays from each leaf so that the ratio's remain the same 
    23882511        PushRoots(tstack); 
     2512 
     2513        if ( maxRays >= stat.rayRefs ) 
     2514          return 0; 
     2515         
    23892516        float ratio = desired/(float)stat.rayRefs; 
    23902517         
     
    24122539   
    24132540   
    2414   Debug<<"Remained "<<stat.rayRefs<<" rays"<<endl; 
     2541  Debug<<"Remained "<<stat.rayRefs<<" rays"<<endl<<flush; 
    24152542   
    24162543  return prunned; 
     
    25722699           
    25732700          sumContributions += weight*ray->mPvsContribution; 
    2574           sumRelContributions += weight*ray->mRelativePvsContribution; 
     2701          //$$ 20.7. changed to sqr to pronouce higher contribution so that they do not get smoothed!! 
     2702          //sumRelContributions += weight*ray->mRelativePvsContribution; 
     2703 
     2704          sumRelContributions += sqr(weight*ray->mRelativePvsContribution); 
    25752705           
    25762706          //sumWeights += weight; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.h

    r1112 r1199  
    682682  int mDirSplitDepth; 
    683683 
     684  // depth till which the regular splits are applied for hybrid split type 
     685  int mHybridDepth; 
     686   
    684687  // maximal number of rays maintained in the rss tree 
    685688  int mMaxRays; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp

    r1189 r1199  
    1717{ 
    1818  // this should increase coherence of the samples 
    19   Environment::GetSingleton()->GetIntValue("Sampling.samplesPerPass", mSamplesPerPass); 
    20   Environment::GetSingleton()->GetIntValue("Sampling.totalSamples", mTotalSamples); 
    21   
     19  Environment::GetSingleton()->GetIntValue("SamplingPreprocessor.samplesPerPass", mSamplesPerPass); 
     20  Environment::GetSingleton()->GetIntValue("SamplingPreprocessor.totalSamples", mTotalSamples); 
     21   
    2222  mStats.open("stats.log"); 
    2323} 
     
    2525SamplingPreprocessor::~SamplingPreprocessor() 
    2626{ 
    27         CLEAR_CONTAINER(mSampleRays); 
    28         CLEAR_CONTAINER(mVssSampleRays); 
    29 } 
    30  
    31 void 
    32 SamplingPreprocessor::SetupRay(Ray &ray,  
    33                                                            const Vector3 &point,  
    34                                                            const Vector3 &direction, 
    35                                                            const int type, 
    36                                                            const Ray::Intersection &origin) 
    37 { 
    38   ray.Clear(); 
    39    
    40         ray.mFlags |= Ray::STORE_KDLEAVES | Ray::STORE_BSP_INTERSECTIONS; 
    41         //  cout<<point<<" "<<direction<<endl; 
    42  
    43         ray.Init(point, direction, type); 
    44         ray.sourceObject = origin; 
     27  CLEAR_CONTAINER(mSampleRays); 
     28  CLEAR_CONTAINER(mVssSampleRays); 
     29} 
     30 
     31Intersectable * 
     32SamplingPreprocessor::CastRay( 
     33                                                          const Vector3 &origin, 
     34                                                          const Vector3 &direction 
     35                                                          ) 
     36{ 
     37 
     38  static Ray ray; 
     39  AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); 
     40   
     41  AxisAlignedBox3 sbox = box; 
     42  sbox.Enlarge(Vector3(-Limits::Small)); 
     43  if (!sbox.IsInside(origin)) 
     44        return 0; 
     45         
     46  ray.intersections.clear(); 
     47  // do not store anything else then intersections at the ray 
     48  ray.Init(origin, direction, Ray::LOCAL_RAY); 
     49 
     50  ray.mFlags &= ~Ray::CULL_BACKFACES; 
     51 
     52 
     53 
     54  // cast ray to KD tree to find intersection with other objects 
     55  Intersectable *objectA = NULL; 
     56  Vector3 pointA; 
     57  float bsize = Magnitude(box.Size()); 
     58   
     59  if (mKdTree->CastRay(ray)) { 
     60        if (!mDetectEmptyViewSpace || DotProd(ray.intersections[0].mNormal, direction) < 0) { 
     61          objectA = ray.intersections[0].mObject; 
     62          pointA = ray.Extrap(ray.intersections[0].mT); 
     63        } 
     64  } 
     65  return objectA; 
    4566} 
    4667 
     
    5879} 
    5980 
    60   
    61 void 
    62 SamplingPreprocessor::CastRays(const RayContainer &rays) 
    63 {        
    64   // cast ray to KD tree to find intersection with other objects 
    65   RayContainer::const_iterator it, it_end = rays.end(); 
    66  
    67   VssRayContainer vssRays; 
    68   for (it = rays.begin(); it != it_end; ++it) { 
    69         mKdTree->CastRay(*(*it)); 
    70         vssRays.push_back(new VssRay(*(*it))); 
    71   } 
    72    
    73   mViewCellsManager->ComputeSampleContributions(vssRays, true, false); 
    74   CLEAR_CONTAINER(vssRays); 
    75 } 
    76  
    77 int 
    78 SamplingPreprocessor::CastRay(Ray &ray) 
    79 { 
    80         // cast ray to KD tree to find intersection with other objects 
    81         mKdTree->CastRay(ray); 
    82         VssRay vssRay(ray); 
    83  
    84         mViewCellsManager->ComputeSampleContribution(vssRay, true, false); 
    85          
    86         return vssRay.mPvsContribution; 
    87 } 
    88  
    89  
    90  
    91 int 
    92 SamplingPreprocessor::CastEdgeSamples( 
    93                                                                           Intersectable *object, 
    94                                                                           const Vector3 &point, 
    95                                                                           MeshInstance *mi, 
    96                                                                           const int samples 
    97                                                                           ) 
    98 { 
    99         Ray ray; 
    100         int maxTries = samples*10; 
    101         int i; 
    102         int rays = 0; 
    103         int edgeSamplesContributions = 0; 
    104         for (i=0; i < maxTries && rays < samples; i++) { 
    105                 // pickup a random face of each mesh  
    106                 Mesh *mesh = mi->GetMesh(); 
    107                 int face = (int)RandomValue(0, (Real)((int)mesh->mFaces.size() - 1)); 
    108                  
    109                 Polygon3 poly(mesh->mFaces[face], mesh); 
    110                 poly.Scale(1.001f); 
    111                 // now extend a random edge of the face 
    112                 int edge = (int)RandomValue(0, (Real)((int)poly.mVertices.size() - 1)); 
    113                 float t = RandomValue(0.0f, 1.0f); 
    114                 Vector3 target = t*poly.mVertices[edge] + (1.0f-t)*poly.mVertices[(edge + 1)% 
    115                         poly.mVertices.size()]; 
    116                 SetupRay(ray, point, target - point, Ray::LOCAL_RAY, Ray::Intersection(0, object, 0)); 
    117                 if (!mesh->CastRay(ray, mi)) { 
    118                         // the rays which intersect the mesh have been discarded since they are not tangent 
    119                         // to the mesh 
    120                         rays++; 
    121                         edgeSamplesContributions += CastRay(ray); 
    122                 } 
    123         } 
    124         return edgeSamplesContributions; 
    125 } 
    126  
    127 KdNode * 
    128 SamplingPreprocessor::GetNodeToSample(Intersectable *object) 
    129 { 
    130         int pvsSize = object->mKdPvs.GetSize(); 
    131         KdNode *nodeToSample = NULL; 
    132          
    133         bool samplePvsBoundary = false; 
    134         if (pvsSize && samplePvsBoundary) { 
    135                 // this samples the nodes from the boundary of the current PVS 
    136                 // mail all nodes from the pvs 
    137                 Intersectable::NewMail(); 
    138                 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 
    139                  
    140                 for (; i != object->mKdPvs.mEntries.end(); i++) { 
    141                         KdNode *node = (*i).first; 
    142                         node->Mail(); 
    143                 } 
    144                  
    145                 int maxTries = 2*pvsSize; 
    146                 Debug << "Finding random neighbour" << endl;     
    147                 for (int tries = 0; tries < 10; tries++) { 
    148                         int index = (int)RandomValue(0, (Real)(pvsSize - 1)); 
    149                         PvsData data; 
    150                         KdNode *node; 
    151                         object->mKdPvs.GetData(index, node, data); 
    152                         nodeToSample = mKdTree->FindRandomNeighbor(node, true); 
    153                         if (nodeToSample) 
    154                                 break; 
    155                 } 
    156         } else { 
    157                 // just pickup a random node 
    158                 //              nodeToSample = mKdTree->GetRandomLeaf(Plane3(normal, point)); 
    159                 nodeToSample = mKdTree->GetRandomLeaf(); 
    160         } 
    161         return nodeToSample; 
    162 } 
    16381 
    16482void 
     
    16684{ 
    16785        // mail all nodes from the pvs 
    168         Intersectable::NewMail(); 
    169         KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 
    170         for (; i != object->mKdPvs.mEntries.end(); i++) { 
    171                 KdNode *node = (*i).first; 
    172                 node->Mail(); 
    173         } 
    174         Debug << "Get all neighbours from PVS" << endl; 
    175         vector<KdNode *> invisibleNeighbors; 
    176         // get all neighbors of all PVS nodes 
    177         i = object->mKdPvs.mEntries.begin(); 
    178         for (; i != object->mKdPvs.mEntries.end(); i++) { 
    179                 KdNode *node = (*i).first; 
    180                 mKdTree->FindNeighbors(node, invisibleNeighbors, true); 
    181                 AxisAlignedBox3 box = object->GetBox(); 
    182                 for (int j=0; j < invisibleNeighbors.size(); j++) { 
    183                         int visibility = ComputeBoxVisibility(mSceneGraph, 
    184                                                               mKdTree, 
    185                                                               box, 
    186                                                               mKdTree->GetBox(invisibleNeighbors[j]), 
    187                                                               1e-6f); 
    188                         //            exit(0); 
    189                 } 
    190                 // now rank all the neighbors according to probability that a new 
    191                 // sample creates some contribution 
    192         } 
     86  Intersectable::NewMail(); 
     87  KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 
     88  for (; i != object->mKdPvs.mEntries.end(); i++) { 
     89        KdNode *node = (*i).first; 
     90        node->Mail(); 
     91  } 
     92  Debug << "Get all neighbours from PVS" << endl; 
     93  vector<KdNode *> invisibleNeighbors; 
     94  // get all neighbors of all PVS nodes 
     95  i = object->mKdPvs.mEntries.begin(); 
     96  for (; i != object->mKdPvs.mEntries.end(); i++) { 
     97        KdNode *node = (*i).first; 
     98        mKdTree->FindNeighbors(node, invisibleNeighbors, true); 
     99        AxisAlignedBox3 box = object->GetBox(); 
     100        for (int j=0; j < invisibleNeighbors.size(); j++) { 
     101          int visibility = ComputeBoxVisibility(mSceneGraph, 
     102                                                                                        mKdTree, 
     103                                                                                        box, 
     104                                                                                        mKdTree->GetBox(invisibleNeighbors[j]), 
     105                                                                                        1e-6f); 
     106          //          exit(0); 
     107        } 
     108        // now rank all the neighbors according to probability that a new 
     109        // sample creates some contribution 
     110  } 
    193111} 
    194112 
     
    197115{ 
    198116   
    199   /// rays per pass 
    200   RayContainer passRays; 
    201  
    202  
    203   mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox()); 
    204    
    205   Vector3 point, normal, direction; 
    206   //Ray ray; 
    207  
     117  Debug << "type: sampling" << endl; 
     118   
     119  cout<<"Sampling Preprocessor started\n"<<flush; 
     120  //  cout<<"Memory/ray "<<sizeof(VssRay)+sizeof(RssTreeNode::RayInfo)<<endl; 
     121 
     122  Randomize(0); 
     123   
    208124  long startTime = GetTime(); 
    209125   
    210   int i; 
    211126  int totalSamples = 0; 
    212127 
    213   int pvsSize = 0; 
    214  
    215   while (totalSamples < mTotalSamples) { 
    216                 int passContributingSamples = 0; 
    217                 int passSampleContributions = 0; 
    218                 int passSamples = 0; 
    219                 int index = 0; 
    220                  
    221                 int reverseSamples = 0; 
    222                  
    223                 for (i = 0; i < mObjects.size(); i++) { 
    224                                                  
    225                         KdNode *nodeToSample = NULL; 
    226                         Intersectable *object = mObjects[i]; 
    227                  
    228                         int pvsSize = 0; 
    229                          
    230                         if (0 && pvsSize && mPass == 1000 ) { 
    231                                 VerifyVisibility(object); 
     128  // if not already loaded, construct view cells from file 
     129  if (!mLoadViewCells) 
     130  { 
     131        mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox()); 
     132 
     133        // construct view cells using it's own set of samples 
     134        mViewCellsManager->Construct(this); 
     135         
     136        //-- several visualizations and statistics 
     137        Debug << "view cells construction finished: " << endl; 
     138        mViewCellsManager->PrintStatistics(Debug); 
     139  } 
     140   
     141 
     142   
     143  int samples = 0; 
     144  int i=0; 
     145  while (samples < mTotalSamples) { 
     146        for (i=0; i < mSamplesPerPass; i++, samples++) { 
     147           
     148          if (i%10000 == 0) 
     149                cout<<"+"; 
     150           
     151          Vector3 origin, direction; 
     152          mViewCellsManager->GetViewPoint(origin); 
     153          direction = UniformRandomVector(); 
     154 
     155           
     156          ViewCell *viewcell = mViewCellsManager->GetViewCell(origin); 
     157           
     158          if (viewcell && viewcell->GetValid()) { 
     159                // cast rays in both directions to make the number of samples comparable 
     160                // with the global sampling method which also casts a "double" ray per sample 
     161                for (int j=0; j < 2; j++) { 
     162                  Intersectable *object = CastRay(origin, direction); 
     163                  if (object) { 
     164                        // if ray not outside of view space 
     165                        float contribution; 
     166                        int pvsContribution = 0; 
     167                        float relativePvsContribution = 0; 
     168                        if (object) { 
     169                          float pdf = 1.0f; 
     170                          if (viewcell->GetPvs().GetSampleContribution(object, 
     171                                                                                                                   pdf, 
     172                                                                                                                   contribution)) 
     173                                ++pvsContribution; 
     174                          relativePvsContribution += contribution; 
     175                          viewcell->GetPvs().AddSample(object, pdf); 
    232176                        } 
    233                          
    234                         int faceIndex = object->GetRandomSurfacePoint(point, normal); 
    235                          
    236                         bool viewcellSample = true; 
    237                         //int sampleContributions; 
    238                         bool debug = false; //(object->GetId() >= 2199); 
    239                         if (viewcellSample) { 
    240                                 //mKdTree->GetRandomLeaf(Plane3(normal, point)); 
    241  
    242                                 nodeToSample = GetNodeToSample(object); 
    243  
    244                                 for (int k=0; k < mSamplesPerPass; k++) { 
    245                                         bool reverseSample = false; 
    246                                  
    247                                         if (nodeToSample) { 
    248                                                 AxisAlignedBox3 box = mKdTree->GetBox(nodeToSample); 
    249                                                 Vector3 pointToSample = box.GetRandomPoint(); 
    250                                                 //                                              pointToSample.y = 0.9*box.Min().y + 0.1*box.Max().y; 
    251                                                 if (object->GetRandomVisibleSurfacePoint( point, normal, pointToSample, 3 )) { 
    252                                                         direction = pointToSample - point; 
    253                                                 } else { 
    254                                                         reverseSamples++; 
    255                                                         reverseSample = true; 
    256                                                         direction = point - pointToSample; 
    257                                                         point = pointToSample; 
    258                                                         //Debug << "point: " << pointToSample << endl; 
    259                                                 } 
    260                                         } 
    261                                         else { 
    262                                                 direction = UniformRandomVector(normal); 
    263                                         } 
    264                                          
    265                                         Ray *ray = new Ray(); 
    266  
    267                                         // construct a ray 
    268                                         SetupRay(*ray, point, direction, Ray::LOCAL_RAY,  
    269                                                          Ray::Intersection(0, reverseSample ? NULL : object, faceIndex)); 
    270  
    271                                         passRays.push_back(ray); 
    272                                          
    273                                         //-- CORR matt: put block inside loop 
    274                                         /*if (sampleContributions) { 
    275                                                 passContributingSamples ++; 
    276                                                 passSampleContributions += sampleContributions; 
    277                                         }*/ 
    278                                 } 
    279                         } else { 
    280                                 // edge samples 
    281                                 // get random visible mesh 
    282                                 //                              object->GetRandomVisibleMesh(Plane3(normal, point)); 
    283                         } 
    284          
    285                         // CORR matt: must add all samples 
    286                         passSamples += mSamplesPerPass; 
     177                  } 
     178                  direction = -direction; 
    287179                } 
    288          
    289                 //------------------- 
    290                 // cast rays for view cells construction 
    291                 ProcessViewCells(passRays, 
    292                                                  mObjects, 
    293                                                  passSampleContributions, 
    294                                                  passContributingSamples); 
    295  
    296                 CLEAR_CONTAINER(passRays); 
    297                  
    298                 totalSamples += passSamples;  
    299                  
    300                 //    if (pass>10) 
    301                 //      HoleSamplingPass(); 
    302      
    303                 mPass ++; 
    304          
    305                 pvsSize += passSampleContributions; 
    306                  
    307                 float avgRayContrib = (passContributingSamples > 0) ?  
    308                         passSampleContributions / (float)passContributingSamples : 0; 
    309  
    310                 cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
    311                 cout << "#TotalSamples=" << totalSamples/1000  
    312                                  << "k   #SampleContributions=" << passSampleContributions << " ("  
    313                                  << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 
    314                                  << (float)pvsSize /(float)mObjects.size() << endl  
    315                                  << "avg ray contrib=" << avgRayContrib << endl 
    316                                  << "reverse samples [%]" << reverseSamples/(float)passSamples*100.0f << endl; 
    317  
    318                 mStats << 
    319                         "#Pass\n" <<mPass<<endl<< 
    320                         "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<< 
    321                         "#TotalSamples\n" << totalSamples<< endl<< 
    322                         "#SampleContributions\n" << passSampleContributions << endl <<  
    323                         "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 
    324                         "#AvgPVS\n"<< pvsSize/(float)mObjects.size() << endl << 
    325                         "#AvgRayContrib\n" << avgRayContrib << endl; 
    326         } 
    327          
    328         //cout << "#totalKdPvsSize=" << mKdTree->CollectLeafPvs() << endl; 
    329          
     180          } 
     181           
     182          if (samples > mTotalSamples) 
     183                break; 
     184        } 
     185         
     186        //      mVssRays.PrintStatistics(mStats); 
     187        mStats << 
     188          "#Time\n" << TimeDiff(startTime, GetTime())*1e-3<<endl<< 
     189          "#TotalSamples\n" <<samples<<endl; 
     190 
     191        mViewCellsManager->PrintPvsStatistics(mStats); 
     192        // ComputeRenderError(); 
     193  } 
     194   
    330195  //  HoleSamplingPass(); 
    331196        if (0) { 
    332                 Exporter *exporter = Exporter::GetExporter("ray-density.x3d");  
    333                 exporter->SetExportRayDensity(true); 
    334                 exporter->ExportKdTree(*mKdTree); 
    335                 delete exporter; 
    336         } 
    337          
    338         // construct view cells if not already constructed 
    339         if (!mViewCellsManager->ViewCellsConstructed()) 
    340           mViewCellsManager->ConstructSubdivision(mObjects, mVssSampleRays); 
    341  
     197          Exporter *exporter = Exporter::GetExporter("ray-density.x3d");  
     198          exporter->SetExportRayDensity(true); 
     199          exporter->ExportKdTree(*mKdTree); 
     200          delete exporter; 
     201        } 
     202         
     203         
    342204        // $$JB temporary removed 
    343205        //      mViewCellsManager->PostProcess(objects, mSampleRays); 
     
    346208        Debug << "view cells after post processing: " << endl; 
    347209        mViewCellsManager->PrintStatistics(Debug); 
    348  
     210         
    349211        //-- render simulation after merge 
    350212        cout << "\nevaluating bsp view cells render time after merge ... "; 
    351213         
    352          mRenderSimulator->RenderScene(); 
    353          SimulationStatistics ss; 
    354          mRenderSimulator->GetStatistics(ss); 
    355           
    356          cout << " finished" << endl; 
    357          cout << ss << endl; 
    358          Debug << ss << endl; 
     214        mRenderSimulator->RenderScene(); 
     215        SimulationStatistics ss; 
     216        mRenderSimulator->GetStatistics(ss); 
     217         
     218        cout << " finished" << endl; 
     219        cout << ss << endl; 
     220        Debug << ss << endl; 
    359221         
    360222        // $$JB temporary removed 
    361223        //mViewCellsManager->Visualize(objects, mSampleRays);    
    362     
     224         
    363225        return true; 
    364226} 
    365227 
    366 void SamplingPreprocessor::ProcessViewCells(const RayContainer &newRays, 
    367                                                                                         const ObjectContainer &objects, 
    368                                                                                         int &sampleContributions, 
    369                                                                                         int &contributingSamples) 
    370 { 
    371   // cast rays to view cells 
    372   CastRays(newRays); 
    373  
    374   // save rays for view cells construction 
    375   if (!mViewCellsManager->ViewCellsConstructed()) 
    376         { 
    377           if ((int)mVssSampleRays.size() < mViewCellsManager->GetConstructionSamples()) 
    378                 { 
    379                   RayContainer::const_iterator it, it_end = newRays.end(); 
    380                    
    381                   for (it = newRays.begin(); it != it_end; ++ it) 
    382                         mVssSampleRays.push_back(new VssRay(*(*it))); 
    383                 } 
    384           else 
    385                 { 
    386                   // construct view cells 
    387                   mViewCellsManager->ConstructSubdivision(objects, mVssSampleRays); 
    388                    
    389                   // throw away samples  
    390                   //CLEAR_CONTAINER(mVssSampleRays); 
    391                 } 
    392         } 
    393   // Need rays (with ordered intersections) for post processing => collect new rays 
    394   if (((int)mSampleRays.size() < mViewCellsManager->GetPostProcessSamples()) || 
    395           ((int)mSampleRays.size() < mViewCellsManager->GetVisualizationSamples())) 
    396         { 
    397           RayContainer::const_iterator it, it_end = newRays.end(); 
    398            
    399           for (it = newRays.begin(); it != it_end; ++ it) 
    400                 mSampleRays.push_back(new Ray(*(*it))); 
    401         } 
    402 } 
    403  
    404 } 
     228 
     229} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.h

    r860 r1199  
    3838  HoleSamplingPass(); 
    3939   
    40   /** Casts a bundle of sample rays into the scene. 
    41                 @param sampleContributions the number of sample contributions 
    42                 @param contributingSamples the number of samples contributing 
    43         */ 
    44         void 
    45         CastRays(const RayContainer &rays); 
    46          
    47         /** Casts a single ray into the scene. 
    48                 @returns sample contributions 
    49         */ 
    50         int CastRay(Ray &ray); 
    51          
    52         /** Verify if the exact visibility for this object was established. 
    53         */ 
    54         void 
    55         VerifyVisibility(Intersectable *object); 
    56  
    57         /** Sample the shiluette of objects in order to find visibility changes 
    58                 along the visibility skeleton. 
    59         */ 
    60         int  
    61         CastEdgeSamples( 
    62                                         Intersectable *object, 
    63                                         const Vector3 &point, 
    64                                         MeshInstance *mi, 
    65                                         const int samples 
    66                                         ); 
    67  
    68         /** Processes the view cells during a pass. 
    69                 @param newRays the newly cast rays 
    70                 @param sampleContributions returns the accumulated contribution of the samples 
    71                 @param contributingSamples returns the samples contributing to pvs 
    72         */ 
    73          
    74         void ProcessViewCells(const RayContainer &newRays, 
    75                                                   const ObjectContainer &objects, 
    76                                                   int &sampleContributions, 
    77                                                   int &contributingSamples); 
    78  
    79         /** 
    80                 Returns random node as target for the current sample ray. 
    81         */ 
    82         KdNode *GetNodeToSample(Intersectable *object); 
    83  
     40   
     41  Intersectable * 
     42  CastRay( 
     43                  const Vector3 &origin, 
     44                  const Vector3 &direction 
     45                  ); 
     46   
     47  /** Verify if the exact visibility for this object was established. 
     48   */ 
     49  void 
     50  VerifyVisibility(Intersectable *object); 
     51   
    8452 
    8553protected: 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1189 r1199  
    18331833        while (root->GetParent()) 
    18341834        { 
     1835// <<<<<<< .mine 
     1836//      case PVS_IN_LEAVES: //-- store pvs only in leaves 
     1837//              {                        
     1838//                      // pvs is always stored directly in leaves 
     1839//                      if (vc->IsLeaf()) 
     1840//                      { 
     1841//                              if (!countKdPvs) 
     1842//                                      pvsSize = vc->GetPvs().GetSize(); 
     1843//                              else 
     1844//                                      pvsSize = CountKdPvs(dynamic_cast<ViewCellLeaf *>(vc)); 
     1845//                              break; 
     1846//                      } 
    18351847                root = root->GetParent(); 
    18361848         
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1189 r1199  
    16921692void ViewCellsManager::GetPvsStatistics(PvsStatistics &stat) 
    16931693{ 
    1694         // update pvs of view cells tree if necessary 
    1695         UpdatePvs(); 
    1696  
    1697         ViewCellContainer::const_iterator it = mViewCells.begin(); 
    1698  
    1699         stat.viewcells = 0; 
    1700         stat.minPvs = 100000000; 
    1701         stat.maxPvs = 0; 
    1702         stat.avgPvs = 0.0f; 
    1703  
    1704         for (; it != mViewCells.end(); ++ it)  
    1705         { 
    1706                 ViewCell *viewcell = *it; 
    1707  
    1708                 const int pvsSize = mViewCellsTree->GetPvsSize(viewcell); 
    1709  
    1710                 if (pvsSize < stat.minPvs) 
    1711                         stat.minPvs = pvsSize; 
    1712                 if (pvsSize > stat.maxPvs) 
    1713                         stat.maxPvs = pvsSize; 
    1714  
    1715                 stat.avgPvs += pvsSize; 
    1716  
    1717                 ++ stat.viewcells; 
    1718         } 
    1719  
    1720         if (stat.viewcells) 
    1721                 stat.avgPvs/=stat.viewcells; 
     1694  // update pvs of view cells tree if necessary 
     1695  UpdatePvs(); 
     1696   
     1697  ViewCellContainer::const_iterator it = mViewCells.begin(); 
     1698   
     1699  stat.viewcells = 0; 
     1700  stat.minPvs = 100000000; 
     1701  stat.maxPvs = 0; 
     1702  stat.avgPvs = 0.0f; 
     1703   
     1704  for (; it != mViewCells.end(); ++ it)  
     1705        { 
     1706          ViewCell *viewcell = *it; 
     1707 
     1708          //      bool mCountKdPvs = false; 
     1709          const int pvsSize = mViewCellsTree->GetPvsSize(viewcell); 
     1710 
     1711 
     1712          if (pvsSize < stat.minPvs) 
     1713                stat.minPvs = pvsSize; 
     1714          if (pvsSize > stat.maxPvs) 
     1715                stat.maxPvs = pvsSize; 
     1716           
     1717          stat.avgPvs += pvsSize; 
     1718           
     1719          ++ stat.viewcells; 
     1720        } 
     1721   
     1722  if (stat.viewcells) 
     1723        stat.avgPvs/=stat.viewcells; 
    17221724} 
    17231725 
  • GTP/trunk/Lib/Vis/Preprocessing/src/default.env

    r1112 r1199  
    1111#filename ../data/vienna/vienna-buildings.x3d 
    1212#filename ../data/vienna/city1500_flat_1.x3d 
    13 #filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-plane.x3d;../data/vienna/vienna-roads.x3d 
     13filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d 
     14#;../data/vienna/vienna-plane.x3d;../data/vienna/vienna-roads.x3d 
    1415# filename ../data/vienna/viewcells-25-sel.x3d 
    1516#filename ../data/atlanta/atlanta2.x3d 
    16 # filename ../data/soda/soda.dat 
     17#filename ../data/soda/soda.dat 
     18#filename ../data/test1/test2.x3d 
    1719#filename ../data/soda/soda5.dat 
    1820#filename ../data/PowerPlant/ppsection1/part_a/g0.ply 
     
    2224#filename ../data/PowerPlant/selection3.plb 
    2325#filename ../data/PowerPlant/section10.plb;../data/PowerPlant/section14.plb 
    24 filename ../data/PowerPlant/selection.plb 
     26#filename ../data/PowerPlant/selection.plb 
    2527#filename ../data/PowerPlant/comps/ppsection1/comps.plb 
    2628} 
     
    2931        # stored sample rays 
    3032        samplesFilename rays.out 
    31         useGlRenderer true 
     33        useGlRenderer false 
    3234        useGlDebugger false 
    3335#       type sampling 
     
    5557        samplesPerPass  100000 
    5658        initialSamples 100000 
    57         vssSamples 1000000 
     59        vssSamples 500000 
    5860        vssSamplesPerPass 100000 
    5961        useImportanceSampling true 
     
    7173        maxDepth        40 
    7274        minPvs          30 
    73         minRays         100 
     75        minRays         20 
    7476        minSize         0.001 
    7577        maxCostRatio    2.0 
     
    7981        maxStaticMemory 100 
    8082 
    81 #       splitType regular 
    82         splitType heuristic 
     83        splitType regular 
     84#       splitType heuristic 
    8385#       splitType hybrid 
    84         splitUseOnlyDrivingAxis true 
     86        splitUseOnlyDrivingAxis false 
    8587 
    8688        interleaveDirSplits     true 
     
    9496} 
    9597 
     98SamplingPreprocessor { 
     99        totalSamples 30000000 
     100        samplesPerPass 1000000 
     101} 
     102 
    96103RssPreprocessor { 
    97104        samplesPerPass 1000 
    98         initialSamples 1000000 
    99         vssSamples 500000000 
     105        initialSamples 2000000 
     106        vssSamples 30000000 
    100107        vssSamplesPerPass 1000000 
    101108        useImportanceSampling true 
     
    128135#       splitType heuristic 
    129136 
    130         minRays         200 
     137        minRays         100 
    131138        minSize         0.001 
    132         maxCostRatio 0.98 
    133         maxRayContribution 0.5 
     139        maxCostRatio 1.0 
     140        maxRayContribution 1.0 
    134141        maxRays         4000000 
    135142        maxTotalMemory  200 
    136143        maxStaticMemory 100 
    137144 
    138 #       splitType regular 
    139         splitType heuristic 
     145        splitType regular 
     146#       splitType heuristic 
    140147#       splitType hybrid 
     148        hybridDepth             10 
    141149        splitUseOnlyDrivingAxis false 
     150#false 
    142151        importanceBasedCost false 
    143152 
     
    190199 
    191200 
    192 SamplingPreprocessor { 
    193         totalSamples 10000000 
    194         samplesPerPass  3 
    195 } 
    196201 
    197202 
     
    281286#       filename ../data/soda/soda5-viewcells.xml 
    282287#       filename ../scripts/viewcells_atlanta.xml 
    283 #       filename ../data/soda/soda5-viewcells2.xml 
     288#       filename ../data/soda/soda-viewcells-5000.xml 
     289#       filename ../data/test1/test-viewcells.xml 
    284290 
    285291#       filename ../data/soda/soda5-viewcell-single.xm 
     
    288294 
    289295#       filename ../data/atlanta/viewcells_atlanta3.xml 
     296 
    290297#       filename ../data/vienna/viewcells_vienna.xml 
    291298#       filename ../data/vienna/viewcells_vienna2.xml 
    292299#       filename ../data/vienna/vienna_simple-21-04-avs2-viewCells.xml 
    293         filename ../data/PowerPlant/power_plant_viewcells1.xml 
     300        filename ../data/vienna/vienna-viewcells-5000.xml 
     301 
     302 
     303#       filename ../data/PowerPlant/power_plant_viewcells1.xml 
    294304} 
    295305 
     
    303313 
    304314 
    305 VspKdTree { 
    306         epsilon         1e-6 
    307  
    308         Construction { 
    309                 samples 500000 
    310         } 
    311          
    312         Termination { 
    313                 maxDepth                40 
    314                 minPvs                  0 
    315                 minRays                 1 
    316                 minSize                 0.001 
    317                 maxCostRatio            5.9 
    318                 maxViewCells            169 
    319                 missTolerance           4 
    320                 maxRayContribution      2.5 
    321         } 
    322          
    323         maxTotalMemory  100 
    324         maxStaticMemory 40 
    325  
    326         splitType       regular 
    327         #splitType      heuristics 
    328         splitUseOnlyDrivingAxis true 
    329         ct_div_ci       0.0 
    330          
    331         # maximal cost for merging a view cell 
    332         PostProcess { 
    333                 maxCostRatio 0.005 
    334                 minViewCells 10000 
    335                 maxPvsSize   5000 
    336         } 
    337          
    338          
    339         Visualization { 
    340         } 
    341 } 
    342315 
    343316VspBspTree { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r1197 r1199  
     1#ifdef UNICODE 
     2#undef UNICODE 
     3#endif 
     4 
    15#include <windows.h> 
    26#include <stdio.h> 
     
    3438int LoadMyDll() 
    3539{ 
    36         importFunction LoadRenderWidget; 
    37          
    38     // Load DLL file 
    39         HINSTANCE hinstLib = LoadLibrary("QtGlRenderer.dll"); 
    40          
    41         if (hinstLib == NULL)  
    42         { 
    43                 cout << "ERROR: unable to load DLL\n"; 
    44                 return 1; 
    45         } 
    46  
    47         // Get function pointer 
    48         LoadRenderWidget = (importFunction)GetProcAddress(hinstLib, "LoadRenderWidget"); 
    49          
    50         if (LoadRenderWidget == NULL)  
    51         { 
    52                 cout << "ERROR: unable to find DLL function\n"; 
    53                 return 1; 
    54         } 
    55  
    56         // load the render window 
    57     rendererWidget = LoadRenderWidget(preprocessor); 
    58  
    59         // Unload DLL file 
    60     //FreeLibrary(hinstLib); 
    61  
    62         return 0; 
     40  importFunction LoadRenderWidget; 
     41 
     42  // Load DLL file 
     43  HINSTANCE hinstLib = LoadLibrary("QtGlRenderer.dll"); 
     44   
     45  if (hinstLib == NULL)  
     46        { 
     47          cout << "ERROR: unable to load DLL\n"; 
     48          return 1; 
     49        } 
     50   
     51  // Get function pointer 
     52  LoadRenderWidget = (importFunction)GetProcAddress(hinstLib, "LoadRenderWidget"); 
     53   
     54  if (LoadRenderWidget == NULL)  
     55        { 
     56          cout << "ERROR: unable to find DLL function\n"; 
     57          return 1; 
     58        } 
     59   
     60  // load the render window 
     61  rendererWidget = LoadRenderWidget(preprocessor); 
     62   
     63  // Unload DLL file 
     64  //FreeLibrary(hinstLib); 
     65   
     66  return 0; 
    6367} 
    6468 
     
    103107 
    104108        Debug.open("debug.log"); 
    105  
     109   
    106110        Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH); 
    107111        MeshKdTree::ParseEnvironment(); 
     
    112116 
    113117        if (preprocessorType == "vss") 
    114         { 
     118          { 
    115119                preprocessor = new VssPreprocessor(); 
    116         } 
     120          } 
    117121        else 
    118122        { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro

    r1112 r1199  
    1313 
    1414 
    15 win32:LIBPATH += GL $$NONGTP/Xerces/xerces/lib $$NONGTP/Devil/lib \ 
    16   "d:/Programs/NVIDIA Corporation/Cg/lib" $$NONGTP/glut 
     15win32:LIBPATH += GL $$NONGTP/Xerces/xerces/lib $$NONGTP/Devil/lib $$NONGTP/Xe/xerces/lib \ 
     16  "d:/Programs/NVIDIA Corporation/Cg/lib" $$NONGTP/glut $$NONGTP/Boost/lib 
    1717   
    1818unix:LIBPATH += ../support/src/xerces-c-src_2_7_0/lib ../support/devil/lib /usr/lib/qt3/lib64 
     
    3030QT += opengl 
    3131 
    32 win32:LIBS += xerces-c_2.lib devil.lib ilu.lib ilut.lib cg.lib cgGL.lib glew32.lib  
     32win32:LIBS += xerces-c_2.lib devil.lib ilu.lib ilut.lib cg.lib cgGL.lib glew32.lib boost_thread-vc71-mt-1_33_1.lib 
    3333 
    3434unix:LIBS += -lxerces-c -lIL -lILU -lILUT 
     
    5353GzBinFileInputStream.cpp  GzFileInputSource.cpp \ 
    5454OcclusionQuery.cpp VspOspTree.cpp LogManager.cpp \ 
    55 SamplingStrategy.cpp 
     55SamplingStrategy.cpp KdIntersectable.cpp BoostPreprocessorThread.cpp 
    5656 
    5757#VspKdTree.cpp ResourceManager.cpp  
Note: See TracChangeset for help on using the changeset viewer.