Changeset 492


Ignore:
Timestamp:
01/03/06 23:33:45 (18 years ago)
Author:
bittner
Message:

Large merge - viewcells seem not functional now

Location:
trunk/VUT/GtpVisibilityPreprocessor/src
Files:
4 added
38 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp

    r486 r492  
    301301      maxx = t1; 
    302302    } 
    303     if (maxx < 0.0) 
    304       return 0; 
     303        //    if (maxx < 0.0) 
     304        //      return 0; 
    305305  } 
    306306 
     
    327327      maxx = t1; 
    328328    } 
    329     if (maxx < 0.0) 
    330       return 0; 
     329        //    if (maxx < 0.0) 
     330        //      return 0; 
    331331  } 
    332332 
     
    355355      maxx = t1; 
    356356    } 
    357     if (maxx < 0.0) 
    358       return 0; 
     357        //    if (maxx < 0.0) 
     358        //      return 0; 
    359359  } 
    360360 
     
    17741774 
    17751775 
     1776  // Compute tmin and tmax for a ray, whenever required .. need not pierce box 
     1777int 
     1778AxisAlignedBox3::ComputeMinMaxT(const Vector3 &origin, 
     1779                                                                const Vector3 &direction, 
     1780                                                                float *tmin, 
     1781                                                                float *tmax) const 
     1782{ 
     1783 
     1784  register float minx, maxx; 
     1785 
     1786   
     1787  Vector3 invDirection; 
     1788  const float eps = 1e-6; 
     1789  const float invEps = 1e6; 
     1790   
     1791  // it does change the ray direction very slightly, 
     1792  // but the size direction vector is not practically changed 
     1793   
     1794  if (fabs(direction.x) < eps) { 
     1795    if (direction.x < 0.0) 
     1796      invDirection.x = -invEps; 
     1797    else 
     1798      invDirection.x = invEps; 
     1799  } 
     1800  else 
     1801    invDirection.x = 1.0 / direction.x; 
     1802   
     1803  if (fabs(direction.y) < eps) { 
     1804    if (direction.y < 0.0) 
     1805      invDirection.y = -invEps; 
     1806    else 
     1807      invDirection.y = invEps; 
     1808  } 
     1809  else 
     1810    invDirection.y = 1.0 / direction.y; 
     1811   
     1812  if (fabs(direction.z) < eps) { 
     1813    if (direction.z < 0.0) 
     1814      invDirection.z = -invEps; 
     1815    else 
     1816      invDirection.z = invEps; 
     1817  } 
     1818  else 
     1819    invDirection.z = 1.0 / direction.z; 
     1820 
     1821 
     1822   
     1823  if (fabs(direction.x) < 0.001) { 
     1824    if (mMin.x < origin.x && mMax.x > origin.x) { 
     1825      minx = -MAXFLOAT; 
     1826      maxx = MAXFLOAT; 
     1827    } 
     1828    else 
     1829      return 0; 
     1830  } 
     1831  else { 
     1832    float t1 = (mMin.x - origin.x) * invDirection.x; 
     1833    float t2 = (mMax.x - origin.x) * invDirection.x; 
     1834    if (t1 < t2) { 
     1835      minx = t1; 
     1836      maxx = t2; 
     1837    } 
     1838    else { 
     1839      minx = t2; 
     1840      maxx = t1; 
     1841    } 
     1842        //    if (maxx < 0.0) 
     1843        //      return 0; 
     1844  } 
     1845 
     1846  *tmin = minx; 
     1847  *tmax = maxx; 
     1848   
     1849  if (fabs(direction.y) < 0.001) { 
     1850    if (mMin.y < origin.y && mMax.y > origin.y) { 
     1851      minx = -MAXFLOAT; 
     1852      maxx = MAXFLOAT; 
     1853    } 
     1854    else 
     1855      return 0; 
     1856  } 
     1857  else { 
     1858    float t1 = (mMin.y - origin.y) * invDirection.y; 
     1859    float t2 = (mMax.y - origin.y) * invDirection.y; 
     1860    if (t1 < t2) { 
     1861      minx = t1; 
     1862      maxx = t2; 
     1863    } 
     1864    else { 
     1865      minx = t2; 
     1866      maxx = t1; 
     1867    } 
     1868        //    if (maxx < 0.0) 
     1869        //      return 0; 
     1870  } 
     1871 
     1872  if (minx > *tmin) 
     1873    *tmin = minx; 
     1874  if (maxx < *tmax) 
     1875    *tmax = maxx; 
     1876   
     1877  if (fabs(direction.z) < 0.001) { 
     1878    if (mMin.z < origin.z && mMax.z > origin.z) { 
     1879      minx = -MAXFLOAT; 
     1880      maxx = MAXFLOAT; 
     1881    } 
     1882    else 
     1883      return 0; 
     1884  } 
     1885  else { 
     1886    float t1 = (mMin.z - origin.z) * invDirection.z; 
     1887    float t2 = (mMax.z - origin.z) * invDirection.z; 
     1888    if (t1 < t2) { 
     1889      minx = t1; 
     1890      maxx = t2; 
     1891    } 
     1892    else { 
     1893      minx = t2; 
     1894      maxx = t1; 
     1895    } 
     1896        //    if (maxx < 0.0) 
     1897        //      return 0; 
     1898  } 
     1899 
     1900  if (minx > *tmin) 
     1901    *tmin = minx; 
     1902  if (maxx < *tmax) 
     1903    *tmax = maxx; 
     1904 
     1905  return 1; // yes, intersection was found 
     1906} 
     1907 
     1908 
    17761909bool AxisAlignedBox3::GetIntersectionFace(Rectangle3 &face,  
    17771910                                                                                  const AxisAlignedBox3 &neighbour) const 
  • trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h

    r487 r492  
    6868  } 
    6969 
     70 
    7071  void SetMin(const Vector3 &v) { 
    7172    mMin = v; 
     
    142143  bool IsPoint() const; 
    143144 
     145  void Scale(const float scale) { 
     146        Vector3 newSize = Size()*(scale*0.5f); 
     147        Vector3 center = Center(); 
     148        mMin = center - newSize; 
     149        mMax = center + newSize; 
     150  } 
     151   
    144152  void 
    145153  GetSqrDistances(const Vector3 &point, 
     
    181189                                                                                                        RandomValue(0, size.z));  
    182190  } 
    183    
     191 
     192 
     193  Vector3 GetPoint(const Vector3 &p) const { 
     194    return mMin + p*Size();  
     195  } 
     196 
    184197  // Returns the smallest axis-aligned box that includes all points 
    185198  // inside the two given boxes. 
     
    208221                ID_Right = 4, ID_Top = 5}; 
    209222   
     223  int 
     224  ComputeMinMaxT(const Vector3 &origin, 
     225                                 const Vector3 &direction, 
     226                                 float *tmin, 
     227                                 float *tmax) const; 
     228         
    210229  // Compute tmin and tmax for a ray, whenever required .. need not pierce box 
    211230  int ComputeMinMaxT(const Ray &ray, float *tmin, float *tmax) const; 
    212231 
    213232  // Compute tmin and tmax for a ray, whenever required .. need not pierce box 
    214   int ComputeMinMaxT(const Ray &ray, float *tmin, float *tmax, 
    215                      EFaces &entryFace, EFaces &exitFace) const; 
     233  int ComputeMinMaxT(const Ray &ray, 
     234                                         float *tmin, 
     235                                         float *tmax, 
     236                                         EFaces &entryFace, 
     237                                         EFaces &exitFace) const; 
    216238   
    217239  // If a ray pierces the box .. returns 1, otherwise 0. 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Camera.cpp

    r466 r492  
    1111#include "Mesh.h" 
    1212#include "Exporter.h" 
     13#include "SceneGraph.h" 
    1314 
    1415 
     
    3334bool 
    3435Camera::SnapImage(string filename, 
    35                   KdTree *tree 
    36                   ) 
     36                                  KdTree *tree, 
     37                                  SceneGraph *sceneGraph 
     38                                  ) 
    3739{ 
    3840  int x; 
     
    5961      SetupRay(ray, x, mHeight - (y + 1)); 
    6062      if (tree->CastRay(ray)) 
    61         if (ray.intersections.size()) { 
    62           sort(ray.intersections.begin(), ray.intersections.end()); 
    63           MeshInstance *mesh = (MeshInstance*)ray.intersections[0].mObject; 
    64           RgbColor color(1,1,1); 
    65           if (mesh->GetMesh()->mMaterial) 
    66             color = mesh->GetMesh()->mMaterial->mDiffuseColor; 
    67  
    68           pbuffer[0] = color.r; 
    69           pbuffer[1] = color.g; 
    70           pbuffer[2] = color.b; 
    71           pbuffer[3] = 1.0f; 
    72  
    73         } 
     63                if (ray.intersections.size()) { 
     64                  sort(ray.intersections.begin(), ray.intersections.end()); 
     65                  MeshInstance *mesh = (MeshInstance*)ray.intersections[0].mObject; 
     66                  RgbColor color(1,1,1); 
     67                  if (mesh->GetMesh()->mMaterial) 
     68                        color = mesh->GetMesh()->mMaterial->mDiffuseColor; 
     69                   
     70                  pbuffer[0] = color.r; 
     71                  pbuffer[1] = color.g; 
     72                  pbuffer[2] = color.b; 
     73                  pbuffer[3] = 1.0f; 
     74                   
     75                } 
    7476      pbuffer+=components; 
    7577       
    76       if (exportRays && (x==222) && (y==97)) { 
    77                                 Ray *nray = new Ray(ray); 
    78                                 rays.push_back(nray); 
    79                         } 
     78          //      if (exportRays && ( 1||(x==222) && (y==97))) { 
     79          //      if (exportRays && ((x%4==0) && (y%4==0))) { 
     80          if (exportRays && ray.intersections.empty()) { 
     81                Ray *nray = new Ray(ray); 
     82                rays.push_back(nray); 
     83          } 
    8084    } 
    8185    //    pbuffer-=2*components*mWidth; 
     
    8589  cout<<"#RAY_CAST_TIME\n"; 
    8690  cout<<TimeDiff(t1, t2)<<"\n"; 
    87  
     91   
    8892   
    8993  cout<<"Saving image"<<endl; 
    90  
     94   
    9195  ilRegisterType(IL_FLOAT); 
    9296  ilTexImage(mWidth, mHeight, 1, 4, IL_RGBA, IL_FLOAT, buffer); 
    9397  ilSaveImage((char *const)filename.c_str()); 
    9498  delete buffer; 
     99 
     100  cout<<"done."<<endl<<flush; 
    95101   
    96102  Exporter *exporter = NULL; 
    97   if (exportRays) { 
     103  if (1) { 
    98104    exporter = Exporter::GetExporter(filename + "-rays" + ".x3d"); 
    99     exporter->SetWireframe(); 
    100     exporter->ExportKdTree(*tree); 
    101                 //exporter->ExportBspTree(*bsptree); 
    102     exporter->ExportRays(rays, 10000); 
     105    exporter->SetFilled(); 
     106        if (sceneGraph) 
     107          exporter->ExportScene(sceneGraph->mRoot); 
     108         
     109    //exporter->ExportKdTree(*tree); 
     110        //exporter->ExportBspTree(*bsptree); 
     111    exporter->ExportRays(rays, 2000); 
    103112    exporter->SetFilled(); 
    104113    int k =0; 
    105114    for (int j=0; j < rays.size(); j++) 
    106115      if (rays[j]->kdLeaves.size()) { 
    107                                 Ray *ray = rays[j]; 
    108                                 int i; 
    109                                 if (1) 
    110                                         for (i= 0; i < ray->kdLeaves.size(); i++) 
    111                                                 exporter->ExportBox(tree->GetBox(ray->kdLeaves[i])); 
    112                                 if (0) 
    113                                         for (i= 0; i < ray->testedObjects.size(); i++) 
    114                                                 exporter->ExportIntersectable(ray->testedObjects[i]); 
    115                                  
     116                Ray *ray = rays[j]; 
     117                int i; 
     118                if (0) 
     119                  for (i= 0; i < ray->kdLeaves.size(); i++) 
     120                        exporter->ExportBox(tree->GetBox(ray->kdLeaves[i])); 
     121                if (0) 
     122                  for (i= 0; i < ray->testedObjects.size(); i++) 
     123                        exporter->ExportIntersectable(ray->testedObjects[i]); 
     124                 
    116125      } 
    117                  
     126         
    118127    delete exporter; 
    119128  } 
    120    
    121129   
    122130  return true; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Camera.h

    r469 r492  
    66 
    77class KdTree; 
     8class SceneGraph; 
    89 
    910class Camera 
     
    2223   
    2324  Camera() { 
    24     mWidth = 640; 
    25     mHeight = 480; 
     25    mWidth = 1400; 
     26    mHeight = 1000; 
    2627    mFovy = 60.0f*(float)M_PI/180.0f; 
    2728  } 
     
    6364   
    6465  bool 
    65   SnapImage(string filename, KdTree *tree); 
     66  SnapImage(string filename, 
     67                        KdTree *tree, 
     68                        SceneGraph *sceneGraph 
     69                        ); 
    6670 
    6771  void SetupRay(Ray &ray, const int x, const int y); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp

    r490 r492  
    4949bool 
    5050Environment::CheckForSwitch(const int argc, 
    51                              const char *argv[], 
    52                              const char swtch) const 
     51                                                        char **argv, 
     52                                                        const char swtch) const 
    5353{ 
    5454  for (int i = 1; i < argc; i++) 
     
    130130void 
    131131Environment::ReadCmdlineParams(const int argc, 
    132                                 const char *argv[], 
    133                                 const char *optParams) 
     132                                                           char **argv, 
     133                                                           const char *optParams) 
    134134{ 
    135135  int i; 
     
    619619void 
    620620Environment::ParseCmdline(const int argc, 
    621                            const char *argv[], 
    622                            const int index) 
     621                                                  char **argv, 
     622                                                  const int index) 
    623623{ 
    624624  int curIndex = -1; 
     
    10641064 
    10651065  RegisterOption("Scene.filename", 
    1066                 optString, 
    1067                  "-scene_filename=", 
    1068                 "atlanta2.x3d"); 
     1066                                optString, 
     1067                                 "scene_filename=", 
     1068                                "atlanta2.x3d"); 
    10691069 
    10701070  RegisterOption("Unigraphics.meshGrouping", 
    1071                 optInt, 
    1072                  "-unigraphics_mesh_grouping=", 
    1073                 "0"); 
     1071                                optInt, 
     1072                                 "unigraphics_mesh_grouping=", 
     1073                                "0"); 
    10741074   
    10751075 
    10761076  RegisterOption("KdTree.Termination.minCost", 
    1077                 optInt, 
    1078                  "-kd_term_min_cost=", 
    1079                 "10"); 
     1077                                optInt, 
     1078                                 "kd_term_min_cost=", 
     1079                                "10"); 
    10801080   
    10811081  RegisterOption("KdTree.Termination.maxDepth", 
    1082                 optInt, 
    1083                  "-kd_term_max_depth=", 
    1084                 "20"); 
     1082                                optInt, 
     1083                                 "kd_term_max_depth=", 
     1084                                "20"); 
    10851085 
    10861086  RegisterOption("KdTree.Termination.maxCostRatio", 
    1087                 optFloat, 
    1088                  "-kd_term_max_cost_ratio=", 
    1089                 "1.5"); 
     1087                                optFloat, 
     1088                                 "kd_term_max_cost_ratio=", 
     1089                                "1.5"); 
    10901090 
    10911091  RegisterOption("KdTree.Termination.ct_div_ci", 
    1092                 optFloat, 
    1093                  "-kd_term_ct_div_ci=", 
    1094                 "1.0"); 
     1092                                optFloat, 
     1093                                 "kd_term_ct_div_ci=", 
     1094                                "1.0"); 
    10951095 
    10961096  RegisterOption("KdTree.splitMethod", 
    1097                 optString, 
    1098                  "-kd_split_method=", 
    1099                 "spatialMedian"); 
     1097                                optString, 
     1098                                 "kd_split_method=", 
     1099                                "spatialMedian"); 
    11001100 
    11011101  RegisterOption("KdTree.splitBorder", 
    11021102                 optFloat, 
    1103                  "-kd_split_border=", 
     1103                 "kd_split_border=", 
    11041104                 "0.1"); 
    11051105 
    11061106  RegisterOption("KdTree.sahUseFaces", 
    11071107                 optBool, 
    1108                  "-kd_sah_use_faces=", 
     1108                 "kd_sah_use_faces=", 
    11091109                 "true"); 
    11101110 
     
    11121112  RegisterOption("MeshKdTree.Termination.minCost", 
    11131113                 optInt, 
    1114                  "-kd_term_min_cost=", 
     1114                 "kd_term_min_cost=", 
    11151115                 "10"); 
    11161116   
    11171117  RegisterOption("MeshKdTree.Termination.maxDepth", 
    11181118                 optInt, 
    1119                  "-kd_term_max_depth=", 
     1119                 "kd_term_max_depth=", 
    11201120                 "20"); 
    11211121 
    11221122  RegisterOption("MeshKdTree.Termination.maxCostRatio", 
    11231123                 optFloat, 
    1124                  "-kd_term_max_cost_ratio=", 
     1124                 "kd_term_max_cost_ratio=", 
    11251125                 "1.5"); 
    11261126 
    11271127  RegisterOption("MeshKdTree.Termination.ct_div_ci", 
    11281128                 optFloat, 
    1129                  "-kd_term_ct_div_ci=", 
     1129                 "kd_term_ct_div_ci=", 
    11301130                 "1.0"); 
    11311131 
    11321132  RegisterOption("MeshKdTree.splitMethod", 
    11331133                 optString, 
    1134                  "-kd_split_method=", 
     1134                 "kd_split_method=", 
    11351135                 "spatialMedian"); 
    11361136 
    11371137  RegisterOption("MeshKdTree.splitBorder", 
    11381138                 optFloat, 
    1139                  "-kd_split_border=", 
     1139                 "kd_split_border=", 
    11401140                 "0.1"); 
    11411141 
    11421142  RegisterOption("Sampling.totalSamples", 
    11431143                 optInt, 
    1144                  "-total_samples=", 
     1144                 "total_samples=", 
    11451145                 "1000000"); 
    11461146 
    11471147  RegisterOption("Sampling.samplesPerPass", 
    11481148                 optInt, 
    1149                  "-samples_per_pass=", 
     1149                 "samples_per_pass=", 
    11501150                 "10"); 
    11511151 
    11521152  RegisterOption("VssPreprocessor.initialSamples", 
    1153           optInt, 
    1154           "-initial_samples=", 
    1155           "100000"); 
    1156  
     1153                                optInt, 
     1154                                 "initial_samples=", 
     1155                                "100000"); 
     1156   
    11571157  RegisterOption("VssPreprocessor.vssSamples", 
    1158           optInt, 
    1159           "-vss_samples=", 
    1160           "1000000"); 
     1158                                optInt, 
     1159                                 "vss_samples=", 
     1160                                "1000000"); 
    11611161         
    11621162  RegisterOption("VssPreprocessor.vssSamplesPerPass", 
    1163           optInt, 
    1164           "-vss_samples_per_pass=", 
    1165           "1000"); 
    1166  
     1163                                optInt, 
     1164                                 "vss_samples_per_pass=", 
     1165                                "1000"); 
     1166   
    11671167  RegisterOption("VssPreprocessor.samplesPerPass", 
    1168           optInt, 
    1169           "-samples_per_pass=",                                                          
    1170           "100000"); 
     1168                                 optInt, 
     1169                                 "samples_per_pass=", 
     1170                                 "100000"); 
     1171 
    11711172 
    11721173 
    11731174  RegisterOption("VssPreprocessor.useImportanceSampling", 
    1174           optBool, 
    1175           "-vss_use_importance=", 
    1176           "true"); 
     1175                                optBool, 
     1176                                 "vss_use_importance=", 
     1177                                "true"); 
    11771178 
    11781179   RegisterOption("VssPreprocessor.loadInitialSamples", 
     
    11941195  RegisterOption("ViewCells.type", 
    11951196                 optString, 
    1196                  "-view_cells_type", 
     1197                 "view_cells_type", 
    11971198                 "bspTree"); 
    11981199 
    11991200  RegisterOption("ViewCells.PostProcess.samples", 
    1200           optInt, 
    1201           "-view_cells_postprocess_samples=", 
    1202           "200000"); 
    1203  
     1201                                optInt, 
     1202                                 "view_cells_postprocess_samples=", 
     1203                                "200000"); 
     1204   
    12041205  RegisterOption("ViewCells.Visualization.samples", 
    1205           optInt, 
    1206           "-view_cells_visualization_samples=", 
    1207           "20000"); 
    1208  
     1206                                optInt, 
     1207                                 "view_cells_visualization_samples=", 
     1208                                "20000"); 
     1209   
    12091210   RegisterOption("ViewCells.loadFromFile", 
    1210                 optBool, 
    1211                  "-view_cells_load_from_file", 
    1212                 "false"); 
    1213  
     1211                                  optBool, 
     1212                                  "view_cells_load_from_file", 
     1213                                  "false"); 
     1214    
    12141215  RegisterOption("ViewCells.maxViewCells", 
    12151216                 optInt, 
    1216                  "-view_cells_max_view_cells", 
     1217                 "view_cells_max_view_cells=", 
    12171218                 "0"); 
    12181219 
    12191220   
    12201221  RegisterOption("ViewCells.maxPvs", 
    1221                 optInt, 
    1222                  "-view_cells_max_pvs", 
    1223                 "300"); 
     1222                                optInt, 
     1223                                 "view_cells_max_pvs=", 
     1224                                "300"); 
    12241225 
    12251226  RegisterOption("ViewCells.PostProcess.minPvsDif", 
    1226                 optInt, 
    1227                  "-view_cells_post_process_min_pvs_dif", 
    1228                 "10"); 
     1227                                optInt, 
     1228                                 "view_cells_post_process_min_pvs_dif=", 
     1229                                "10"); 
    12291230 
    12301231  RegisterOption("ViewCells.PostProcess.maxPvs", 
    1231                 optInt, 
    1232                  "-view_cells_post_process_max_pvs", 
    1233                 "300"); 
     1232                                optInt, 
     1233                                 "view_cells_post_process_max_pvs=", 
     1234                                "300"); 
    12341235 
    12351236  RegisterOption("ViewCells.PostProcess.minPvs", 
    1236                 optString, 
    1237                  "-view_cells_post_process_min_pvs", 
    1238                 "10"); 
    1239  
     1237                                optString, 
     1238                                 "view_cells_post_process_min_pvs", 
     1239                                "10"); 
     1240   
    12401241  RegisterOption("ViewCells.filename", 
    12411242                 optString, 
    1242                  "-view_cells_filename=", 
     1243                 "view_cells_filename=", 
    12431244                 "atlanta_viewcells_large.x3d"); 
    12441245 
    12451246   RegisterOption("ViewCells.height", 
    12461247                 optFloat, 
    1247                  "-view_cells_height=", 
     1248                 "view_cells_height=", 
    12481249                 "5.0"); 
    12491250 
     
    12701271  RegisterOption("Simulation.objRenderCost", 
    12711272                 optFloat, 
    1272                  "-simulation_obj_render_cost", 
     1273                 "simulation_obj_render_cost", 
    12731274                 "1.0"); 
    12741275 
    12751276  RegisterOption("Simulation.vcOverhead", 
    12761277                 optFloat, 
    1277                  "-simulation_vc_overhead", 
     1278                 "simulation_vc_overhead", 
    12781279                 "0.05"); 
    12791280 
    12801281  RegisterOption("Simulation.moveSpeed", 
    12811282                 optFloat, 
    1282                  "-simulation_moveSpeed", 
     1283                 "simulation_moveSpeed", 
    12831284                 "1.0"); 
    12841285 
     
    12931294  RegisterOption("BspTree.Construction.input", 
    12941295          optString, 
    1295           "-bsp_construction_input=", 
     1296          "bsp_construction_input=", 
    12961297          "fromViewCells"); 
    12971298   
    12981299  RegisterOption("BspTree.Construction.samples", 
    12991300          optInt, 
    1300           "-bsp_construction_samples=", 
     1301          "bsp_construction_samples=", 
    13011302          "100000"); 
    13021303 
    13031304  RegisterOption("BspTree.Construction.epsilon", 
    13041305          optFloat, 
    1305           "-bsp_construction_side_tolerance=", 
     1306          "bsp_construction_side_tolerance=", 
    13061307          "0.002"); 
    13071308 
    13081309  RegisterOption("BspTree.Termination.minPolygons", 
    13091310                 optInt, 
    1310                  "-bsp_term_min_polygons=", 
     1311                 "bsp_term_min_polygons=", 
    13111312                 "5"); 
    13121313 
    13131314  RegisterOption("BspTree.Termination.minPvs", 
    13141315                 optInt, 
    1315                  "-bsp_term_min_pvs=", 
     1316                 "bsp_term_min_pvs=", 
    13161317                 "20"); 
    13171318 
    13181319  RegisterOption("BspTree.Termination.minArea", 
    13191320                 optFloat, 
    1320                  "-bsp_term_min_area=", 
     1321                 "bsp_term_min_area=", 
    13211322                 "0.001"); 
    13221323   
    13231324  RegisterOption("BspTree.Termination.maxRayContribution", 
    13241325                 optFloat, 
    1325                  "-bsp_term_ray_contribution=", 
     1326                 "bsp_term_ray_contribution=", 
    13261327                 "0.005"); 
    13271328 
    13281329  RegisterOption("BspTree.Termination.minAccRayLenght", 
    13291330                 optFloat, 
    1330                  "-bsp_term_min_acc_ray_length=", 
     1331                 "bsp_term_min_acc_ray_length=", 
    13311332                 "50"); 
    13321333 
    13331334   RegisterOption("BspTree.Termination.minRays", 
    13341335                 optInt, 
    1335                  "-bsp_term_min_rays=", 
     1336                 "bsp_term_min_rays=", 
    13361337                 "-1"); 
    13371338 
    13381339   RegisterOption("BspTree.Termination.ct_div_ci", 
    13391340                 optFloat, 
    1340                  "-bsp_term_ct_div_ci=", 
     1341                 "bsp_term_ct_div_ci=", 
    13411342                 "0.0"); 
    13421343   
    13431344  RegisterOption("BspTree.Termination.maxDepth", 
    13441345                 optInt, 
    1345                  "-bsp_term_max_depth=", 
     1346                 "bsp_term_max_depth=", 
    13461347                 "100"); 
    13471348 
    13481349  RegisterOption("BspTree.Termination.maxCostRatio", 
    13491350                 optFloat, 
    1350                  "-bsp_term_axis_aligned_max_cost_ratio=", 
     1351                 "bsp_term_axis_aligned_max_cost_ratio=", 
    13511352                 "1.5"); 
    13521353 
    13531354  RegisterOption("BspTree.Termination.AxisAligned.ct_div_ci", 
    13541355                 optFloat, 
    1355                  "-bsp_term_axis_aligned_ct_div_ci=", 
     1356                 "bsp_term_axis_aligned_ct_div_ci=", 
    13561357                 "0.5"); 
    13571358 
    13581359  RegisterOption("BspTree.AxisAligned.splitBorder", 
    13591360                 optFloat, 
    1360                  "-bsp__axis_aligned_split_border=", 
     1361                 "bsp__axis_aligned_split_border=", 
    13611362                 "0.1"); 
    13621363 
    13631364  RegisterOption("BspTree.Termination.AxisAligned.minPolys", 
    13641365                 optInt, 
    1365                  "-bsp_term_axis_aligned_max_polygons=", 
     1366                 "bsp_term_axis_aligned_max_polygons=", 
    13661367                 "50"); 
    13671368 
    13681369   RegisterOption("BspTree.Termination.AxisAligned.minObjects", 
    13691370                 optInt, 
    1370                  "-bsp_term_min_objects=", 
     1371                 "bsp_term_min_objects=", 
    13711372                 "3"); 
    13721373 
    13731374  RegisterOption("BspTree.Termination.AxisAligned.minRays", 
    13741375                 optInt, 
    1375                  "-bsp_term_axis_aligned_min_rays=", 
     1376                 "bsp_term_axis_aligned_min_rays=", 
    13761377                 "-1"); 
    13771378 
    13781379  RegisterOption("BspTree.splitPlaneStrategy", 
    13791380                 optString, 
    1380                  "-bsp_split_method=", 
     1381                 "bsp_split_method=", 
    13811382                 "leastSplits"); 
    13821383 
    13831384  RegisterOption("BspTree.maxPolyCandidates", 
    13841385          optInt, 
    1385           "-bsp_max_poly_candidates=", 
     1386          "bsp_max_poly_candidates=", 
    13861387          "20"); 
    13871388 
    13881389  RegisterOption("BspTree.maxRayCandidates", 
    13891390          optInt, 
    1390           "-bsp_max_plane_candidates=", 
     1391          "bsp_max_plane_candidates=", 
    13911392          "20"); 
    13921393 
    13931394  RegisterOption("BspTree.maxTests", 
    13941395          optInt, 
    1395           "-bsp_max_tests=", 
     1396          "bsp_max_tests=", 
    13961397          "5000"); 
    13971398 
    13981399  RegisterOption("BspTree.Visualization.exportSplits", 
    13991400          optBool, 
    1400           "-bsp_visualization.export_splits", 
     1401          "bsp_visualization.export_splits", 
    14011402          "false"); 
    14021403 
    1403  
    1404    RegisterOption("BspTree.Factor.verticalSplits", optFloat, "-bsp_factor_vertical=", "1.0"); 
    1405    RegisterOption("BspTree.Factor.largestPolyArea", optFloat, "-bsp_factor_largest_poly=", "1.0"); 
    1406    RegisterOption("BspTree.Factor.blockedRays", optFloat, "-bsp_factor_blocked=", "1.0"); 
    1407    RegisterOption("BspTree.Factor.leastSplits", optFloat, "-bsp_factor_least_splits=", "1.0"); 
    1408    RegisterOption("BspTree.Factor.balancedPolys", optFloat, "-bsp_factor_balanced_polys=", "1.0"); 
    1409    RegisterOption("BspTree.Factor.balancedViewCells", optFloat, "-bsp_factor_balanced_view_cells=", "1.0"); 
    1410    RegisterOption("BspTree.Factor.leastRaySplits", optFloat, "-bsp_factor_least_ray_splits=", "1.0"); 
    1411    RegisterOption("BspTree.Factor.balancedRays", optFloat, "-bsp_factor_balanced_rays=", "1.0"); 
    1412    RegisterOption("BspTree.Factor.pvs", optFloat, "-bsp_factor_pvs=", "1.0"); 
     1404  RegisterOption("BspTree.Factor.verticalSplits", optFloat, "bsp_factor_vertical=", "1.0"); 
     1405   RegisterOption("BspTree.Factor.largestPolyArea", optFloat, "bsp_factor_largest_poly=", "1.0"); 
     1406   RegisterOption("BspTree.Factor.blockedRays", optFloat, "bsp_factor_blocked=", "1.0"); 
     1407   RegisterOption("BspTree.Factor.leastSplits", optFloat, "bsp_factor_least_splits=", "1.0"); 
     1408   RegisterOption("BspTree.Factor.balancedPolys", optFloat, "bsp_factor_balanced_polys=", "1.0"); 
     1409   RegisterOption("BspTree.Factor.balancedViewCells", optFloat, "bsp_factor_balanced_view_cells=", "1.0"); 
     1410   RegisterOption("BspTree.Factor.leastRaySplits", optFloat, "bsp_factor_least_ray_splits=", "1.0"); 
     1411   RegisterOption("BspTree.Factor.balancedRays", optFloat, "bsp_factor_balanced_rays=", "1.0"); 
     1412   RegisterOption("BspTree.Factor.pvs", optFloat, "bsp_factor_pvs=", "1.0"); 
    14131413 
    14141414   /************************************************************************************/ 
     
    14181418   RegisterOption("Preprocessor.type", 
    14191419                                 optString, 
    1420                                  "-preprocessor=", 
     1420                                 "preprocessor=", 
    14211421                                 "sampling"); 
    14221422 
     
    14261426                                  "rays.out"); 
    14271427 
    1428    /**************************************************************************************/ 
    1429    /*                  View space partition KD tree related options                      */ 
    1430    /**************************************************************************************/ 
     1428  RegisterOption("Preprocessor.useGlRenderer", 
     1429                                 optBool, 
     1430                                 "useGlRenderer", 
     1431                                 "false"); 
     1432   
     1433  /**************************************************************************************/ 
     1434  /*                  View space partition KD tree related options                      */ 
     1435  /**************************************************************************************/ 
    14311436 
    14321437   RegisterOption("VspKdTree.Construction.samples", 
    1433            optInt, 
    1434            "-vsp_kd_construction_samples=", 
    1435            "100000"); 
     1438                                  optInt, 
     1439                                  "vsp_kd_construction_samples=", 
     1440                                  "100000"); 
    14361441 
    14371442   RegisterOption("VspKdTree.Termination.maxDepth",  
     
    15251530        RegisterOption("VspKdTree.PostProcess.maxCostRatio", 
    15261531                        optFloat, 
    1527                         "-vsp_kd_post_process_max_cost_ratio=", 
     1532                        "vsp_kd_post_process_max_cost_ratio=", 
    15281533                        "0.9"); 
    15291534 
     
    15681573        RegisterOption("VssTree.queryType", optString, "qtype=", "static"); 
    15691574 
     1575 
    15701576        RegisterOption("VssTree.queryPosWeight", optFloat, "qposweight=", "0.0"); 
    15711577        RegisterOption("VssTree.useRefDirSplits", optBool, "refdir", "false"); 
     
    15811587        RegisterOption("RssPreprocessor.initialSamples", 
    15821588                                                                        optInt, 
    1583                                                                         "-initial_samples=", 
     1589                                                                        "initial_samples=", 
    15841590                                                                        "100000"); 
    15851591 
    15861592        RegisterOption("RssPreprocessor.vssSamples", 
    1587                                                                         optInt, 
    1588                                                                         "-vss_samples=", 
    1589                                                                         "1000000"); 
    1590  
     1593                                   optInt, 
     1594                                   "rss_vss_samples=", 
     1595                                   "1000000"); 
     1596         
    15911597        RegisterOption("RssPreprocessor.vssSamplesPerPass", 
    1592                                                                         optInt, 
    1593                                                                         "-vss_samples_per_pass=", 
    1594                                                                         "1000"); 
    1595  
    1596                 RegisterOption("RssPreprocessor.samplesPerPass", 
    1597                                                                         optInt, 
    1598                                                                         "-samples_per_pass=", 
    1599                                                                         "100000"); 
    1600  
     1598                                   optInt, 
     1599                                   "rss_vss_samples_per_pass=", 
     1600                                   "1000"); 
     1601         
     1602        RegisterOption("RssPreprocessor.samplesPerPass", 
     1603                                   optInt, 
     1604                                   "rss_samples_per_pass=", 
     1605                                   "100000"); 
     1606         
    16011607        RegisterOption("RssPreprocessor.useImportanceSampling", 
    1602                                                                         optBool, 
    1603                                                                         "-vss_use_importance=", 
    1604                                                                         "true"); 
    1605  
     1608                                   optBool, 
     1609                                   "rss_use_importance", 
     1610                                   "true"); 
     1611         
     1612        RegisterOption("RssPreprocessor.objectBasedSampling", 
     1613                                   optBool, 
     1614                                   "rss_object_based_sampling", 
     1615                                   "true"); 
     1616         
     1617        RegisterOption("RssPreprocessor.directionalSampling", 
     1618                                   optBool, 
     1619                                   "rss_directional_sampling", 
     1620                                   "false"); 
     1621         
    16061622        RegisterOption("RssTree.maxDepth", optInt, "kd_depth=", "12"); 
    16071623        RegisterOption("RssTree.minPvs", optInt, "kd_minpvs=", "1"); 
     
    16091625        RegisterOption("RssTree.maxCostRatio", optFloat, "maxcost=", "0.95"); 
    16101626        RegisterOption("RssTree.maxRayContribution", optFloat, "maxraycontrib=", "0.5"); 
    1611  
     1627         
    16121628        RegisterOption("RssTree.epsilon", optFloat, "kd_eps=", "1e-6"); 
    16131629        RegisterOption("RssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0"); 
     
    16151631        RegisterOption("RssTree.splitType", optString, "split=", "queries"); 
    16161632        RegisterOption("RssTree.splitUseOnlyDrivingAxis", optBool, "splitdriving=", "false"); 
    1617  
     1633         
    16181634        RegisterOption("RssTree.numberOfEndPointDomains", optInt, "endpoints=", "10000"); 
    1619  
     1635         
    16201636        RegisterOption("RssTree.minSize", optFloat, "minsize=", "0.001"); 
    1621  
     1637         
    16221638        RegisterOption("RssTree.maxTotalMemory", optFloat, "mem=", "60.0"); 
    16231639        RegisterOption("RssTree.maxStaticMemory", optFloat, "statmem=", "8.0"); 
    1624  
     1640         
    16251641        RegisterOption("RssTree.queryType", optString, "qtype=", "static"); 
    1626  
     1642         
    16271643        RegisterOption("RssTree.queryPosWeight", optFloat, "qposweight=", "0.0"); 
    16281644        RegisterOption("RssTree.useRefDirSplits", optBool, "refdir", "false"); 
     
    16311647        RegisterOption("RssTree.accessTimeThreshold", optInt, "accesstime=", "1000"); 
    16321648        RegisterOption("RssTree.minCollapseDepth", optInt, "colldepth=", "4"); 
    1633  
     1649         
    16341650        RegisterOption("RssTree.interleaveDirSplits", optBool, "interleavedirsplits", "true"); 
    16351651        RegisterOption("RssTree.dirSplitDepth", optInt, "dirsplidepth=", "10"); 
    1636  
     1652        RegisterOption("RssTree.importanceBasedCost", optBool, "importance_based_cost", "true"); 
     1653        RegisterOption("RssTree.maxRays", optInt, "rss_max_rays=", "2000000"); 
     1654         
    16371655        RegisterOption("RssPreprocessor.Export.pvs", optBool, "rss_export_pvs", "false"); 
    16381656        RegisterOption("RssPreprocessor.Export.rssTree", optBool, "rss_export_rss_tree", "false"); 
     
    16411659        RegisterOption("RssPreprocessor.useViewcells", optBool, "rss_use_viewcells", "false"); 
    16421660        RegisterOption("RssPreprocessor.updateSubdivision", optBool, "rss_update_subdivision", "false"); 
     1661         
     1662         
     1663  /************************************************************************************/ 
     1664  /*               View space partition BSP tree related options                      */ 
     1665  /************************************************************************************/ 
     1666 
    16431667 
    16441668        RegisterOption("RssPreprocessor.loadInitialSamples", 
    1645           optBool, 
    1646           "-vss_load_loadInitialSamples=", 
    1647           "false"); 
     1669                                   optBool, 
     1670                                   "vss_load_loadInitialSamples=", 
     1671                                   "false"); 
    16481672 
    16491673        RegisterOption("RssPreprocessor.storeInitialSamples", 
    1650           optBool, 
    1651           "-vss_store_storeInitialSamples=", 
    1652           "false"); 
     1674                                   optBool, 
     1675                                   "vss_store_storeInitialSamples=", 
     1676                                   "false"); 
    16531677 
    16541678        /************************************************************************************/ 
    16551679        /*               View space partition BSP tree related options                      */ 
    16561680        /************************************************************************************/ 
    1657  
    16581681        RegisterOption("VspBspTree.Termination.minPolygons", 
    1659                 optInt, 
    1660                 "-vsp_bsp_term_min_polygons=", 
    1661                 "5"); 
     1682                                   optInt, 
     1683                                   "vsp_bsp_term_min_polygons=", 
     1684                                   "5"); 
    16621685 
    16631686        RegisterOption("VspBspTree.Termination.minPvs", 
    1664                 optInt, 
    1665                 "-vsp_bsp_term_min_pvs=", 
    1666                 "20"); 
    1667  
     1687                                   optInt, 
     1688                                   "vsp_bsp_term_min_pvs=", 
     1689                                   "20"); 
    16681690        RegisterOption("VspBspTree.Termination.minArea", 
    1669                 optFloat, 
    1670                 "-vsp_bsp_term_min_area=", 
    1671                 "0.001"); 
     1691                                   optFloat, 
     1692                                   "vsp_bsp_term_min_area=", 
     1693                                   "0.001"); 
    16721694 
    16731695        RegisterOption("VspBspTree.Termination.maxRayContribution", 
    1674                 optFloat, 
    1675                 "-vsp_bsp_term_ray_contribution=", 
    1676                 "0.005"); 
     1696                                   optFloat, 
     1697                                   "vsp_bsp_term_ray_contribution=", 
     1698                                   "0.005"); 
    16771699 
    16781700        RegisterOption("VspBspTree.Termination.minAccRayLenght", 
    1679                 optFloat, 
    1680                 "-vsp_bsp_term_min_acc_ray_length=", 
    1681                 "50"); 
     1701                                   optFloat, 
     1702                                   "vsp_bsp_term_min_acc_ray_length=", 
     1703                                   "50"); 
    16821704 
    16831705        RegisterOption("VspBspTree.Termination.minRays", 
    1684                 optInt, 
    1685                 "-vsp_bsp_term_min_rays=", 
    1686                 "-1"); 
     1706                                   optInt, 
     1707                                   "vsp_bsp_term_min_rays=", 
     1708                                   "-1"); 
    16871709 
    16881710        RegisterOption("VspBspTree.Termination.ct_div_ci", 
    1689                 optFloat, 
    1690                 "-vsp_bsp_term_ct_div_ci=", 
    1691                 "0.0"); 
     1711                                   optFloat, 
     1712                                   "vsp_bsp_term_ct_div_ci=", 
     1713                                   "0.0"); 
    16921714 
    16931715        RegisterOption("VspBspTree.Termination.maxDepth", 
    1694                 optInt, 
    1695                 "-vsp_bsp_term_max_depth=", 
    1696                 "100"); 
     1716                                   optInt, 
     1717                                   "vsp_bsp_term_max_depth=", 
     1718                                   "100"); 
    16971719 
    16981720        RegisterOption("VspBspTree.Termination.AxisAligned.maxCostRatio", 
     
    17121734 
    17131735        RegisterOption("VspBspTree.Termination.missTolerance", 
    1714                  optInt, 
    1715                  "-vsp_bsp_term_miss_tolerance=", 
    1716                  "4"); 
    1717  
     1736                                   optInt, 
     1737                                   "vsp_bsp_term_miss_tolerance=", 
     1738                                   "4"); 
    17181739        RegisterOption("VspBspTree.splitPlaneStrategy", 
    1719                         optString, 
    1720                         "-vsp_bsp_split_method=", 
    1721                         "leastSplits"); 
     1740                                   optString, 
     1741                                   "vsp_bsp_split_method=", 
     1742                                   "leastSplits"); 
    17221743 
    17231744        RegisterOption("VspBspTree.maxPolyCandidates", 
    1724                 optInt, 
    1725                 "-vsp_bsp_max_poly_candidates=", 
    1726                 "20"); 
    1727  
     1745                                   optInt, 
     1746                                   "vsp_bsp_max_poly_candidates=", 
     1747                                   "20"); 
    17281748        RegisterOption("VspBspTree.maxRayCandidates", 
    1729                 optInt, 
    1730                 "-vsp_bsp_max_plane_candidates=", 
    1731                 "20"); 
     1749                                   optInt, 
     1750                                   "vsp_bsp_max_plane_candidates=", 
     1751                                   "20"); 
    17321752 
    17331753        RegisterOption("VspBspTree.maxTests", 
    1734                 optInt, 
    1735                 "-vsp_bsp_max_tests=", 
    1736                 "5000"); 
     1754                                   optInt, 
     1755                                   "vsp_bsp_max_tests=", 
     1756                                   "5000"); 
    17371757 
    17381758        RegisterOption("VspBspTree.Construction.samples", 
    1739                 optInt, 
    1740                 "-bsp_construction_samples=", 
    1741                 "100000"); 
     1759                                   optInt, 
     1760                                   "bsp_construction_samples=", 
     1761                                   "100000"); 
    17421762 
    17431763        RegisterOption("VspBspTree.Construction.epsilon", 
    1744                 optFloat, 
    1745                 "-vsp_bsp_construction_side_tolerance=", 
    1746                 "0.002"); 
     1764                                   optFloat, 
     1765                                   "vsp_bsp_construction_side_tolerance=", 
     1766                                   "0.002"); 
    17471767 
    17481768        RegisterOption("VspBspTree.Visualization.exportSplits", 
    1749                 optBool, 
    1750                 "-vsp_bsp_visualization.export_splits", 
    1751                 "false"); 
     1769                                   optBool, 
     1770                                   "vsp_bsp_visualization.export_splits", 
     1771                                   "false"); 
    17521772         
    17531773        RegisterOption("VspBspTree.splitUseOnlyDrivingAxis",  
    1754                 optBool,  
    1755                 "vsp_bsp_splitdriving=",  
    1756                 "false"); 
    1757  
    1758  
     1774                                   optBool,  
     1775                                   "vsp_bsp_splitdriving=",  
     1776                                   "false"); 
     1777         
    17591778        RegisterOption("VspBspTree.Factor.leastRaySplits", optFloat, "-vsp_bsp_factor_least_ray_splits=", "1.0"); 
    17601779        RegisterOption("VspBspTree.Factor.balancedRays", optFloat, "-vsp_bsp_factor_balanced_rays=", "1.0"); 
     
    18011820 
    18021821void 
    1803 Environment::Parse(const int argc, const char *argv[], bool useExePath) 
     1822Environment::Parse(const int argc, char **argv, bool useExePath) 
    18041823{ 
    18051824   
  • trunk/VUT/GtpVisibilityPreprocessor/src/Environment.h

    r372 r492  
    206206   */ 
    207207  bool CheckForSwitch(const int argc, 
    208                       const char *argv[], 
    209                       const char swtch) const; 
     208                                          char **argv, 
     209                                          const char swtch) const; 
    210210  /** First pass of parsing command line. 
    211211    This function parses command line and gets from there all non-optional 
     
    220220   */ 
    221221  void ReadCmdlineParams(const int argc, 
    222                          const char *argv[], 
    223                         const char *optParams); 
     222                                                 char **argv, 
     223                                                const char *optParams); 
    224224  /** Reading of the environment file. 
    225225    This function reads the environment file. 
     
    236236                 be read in. 
    237237   */ 
    238   void ParseCmdline(const int argc, const char *argv[], const int index); 
     238  void ParseCmdline(const int argc, char **argv, const int index); 
    239239 
    240240  /** Clears the environment data structures. 
     
    335335  //@} 
    336336 
    337   void Parse(const int argc, const char *argv[], bool useExePath); 
     337  void Parse(const int argc, char **argv, bool useExePath); 
    338338 
    339339  void 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Halton.cpp

    r355 r492  
    55 
    66Halton2 halton2; 
     7float Halton2::_invBases[2]; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Halton.h

    r355 r492  
    22#define __HALTON_H 
    33 
     4#include <iostream> 
     5using namespace std; 
     6 
    47class Halton2 { 
    5          
    6         float _invBases[2]; 
    7         float _prev[2]; 
     8  static float _invBases[2]; 
     9  float _prev[2]; 
     10   
     11  float halton(float baseRec, float prev) const { 
     12        float r = 1 - prev - 1e-10; 
     13        if (baseRec < r) 
     14          return prev + baseRec; 
     15        float h = baseRec; 
     16        float hh; 
     17        do { 
     18          hh = h; 
     19          h *= baseRec; 
     20        } while (h >= r); 
     21        return prev + hh + h - 1; 
     22  } 
     23   
     24public: 
     25   
     26  void Reset() { 
     27        _prev[0] =_prev[1] = 0; 
     28  } 
     29   
     30  Halton2() { 
     31        _invBases[0] = 1./2; 
     32        _invBases[1] = 1./3; 
     33        Reset(); 
     34  } 
     35   
     36  void 
     37  GetNext(float &a, float &b) { 
     38        a = halton(_invBases[0], _prev[0]); 
     39        b = halton(_invBases[1], _prev[1]); 
     40        _prev[0] = a; 
     41        _prev[1] = b; 
     42  } 
     43}; 
    844 
    9         float halton(float baseRec, float prev) const { 
    10                 float r = 1 - prev - 1e-10; 
    11                 if (baseRec < r) return prev + baseRec; 
    12                 float h = baseRec; 
    13                 float hh; 
    14                 do { 
    15                         hh = h; 
    16                         h *= baseRec; 
    17                 } while (h >= r); 
    18                 return prev + hh + h - 1; 
     45 
     46/** 
     47 * Assert whether the argument is a prime number. 
     48 * @param number the number to be checked 
     49 */ 
     50inline bool IsPrime(const int number) { 
     51  bool isIt = true; 
     52  for(int i = 2; i < number; i++) { 
     53        if(number % i == 0) { 
     54          isIt = false; 
     55          break; 
    1956        } 
    20          
     57  } 
     58        if(number == 2) { 
     59          isIt = false; 
     60        } 
     61        return isIt; 
     62} 
     63 
     64/** 
     65 * Find the nth prime number. 
     66 * @param index the ordinal position in the sequence 
     67 */ 
     68inline int FindPrime(const int index) { 
     69  if(index < 1) { 
     70        cerr<<"FindPrime: The argument must be non-negative."<<endl; 
     71        return -1; 
     72  } 
     73  int prime = 1; 
     74  int found = 1; 
     75  while(found != index) { 
     76        prime += 2; 
     77          if(IsPrime(prime) == true) { 
     78                found++; 
     79          } 
     80  } 
     81  return prime; 
     82} 
     83 
     84struct HaltonSequence { 
    2185public: 
     86  int index; 
    2287 
    23         void Reset() { 
    24                 _prev[0] =_prev[1] = 0; 
     88  HaltonSequence():index(1) {} 
     89 
     90  void Reset() { 
     91        index = 1; 
     92  } 
     93 
     94  void GenerateNext() { 
     95        index++; 
     96  } 
     97   
     98  /** 
     99   * Returns the nth number in the sequence, taken from a specified dimension. 
     100   * @param index the ordinal position in the sequence 
     101   * @param dimension the dimension 
     102   */ 
     103 
     104  double GetNumber(const int dimension)  { 
     105        int base = FindPrime(dimension); 
     106        if(base == 1) { 
     107          base++;  //The first dimension uses base 2. 
     108        }  
     109        double remainder; 
     110        double output = 0.0; 
     111        double fraction = 1.0 / (double)base; 
     112        int N1 = 0; 
     113        int copyOfIndex = index; 
     114        if(base >= 2 & index >= 1) { 
     115          while(copyOfIndex > 0) { 
     116                N1 = (copyOfIndex / base); 
     117                remainder = copyOfIndex % base; 
     118                output += fraction * remainder; 
     119                copyOfIndex = (int)(copyOfIndex / base); 
     120                fraction /= (double)base; 
     121          }  
     122          return output; 
    25123        } 
    26  
    27         Halton2() { 
    28                 _invBases[0] = 1./2; 
    29                 _invBases[1] = 1./3; 
    30                 Reset(); 
     124        else { 
     125          cerr<<"Error generating Halton sequence."<<endl; 
     126          exit(1); 
    31127        } 
    32          
    33         void 
    34         GetNext(float &a, float &b) { 
    35                 a = halton(_invBases[0], _prev[0]); 
    36                 b = halton(_invBases[1], _prev[1]); 
    37                 _prev[0] = a; 
    38                 _prev[1] = b; 
    39         } 
     128  } 
    40129}; 
    41130 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Intersectable.h

    r387 r492  
    55#include "Pvs.h" 
    66 
     7class VssRayContainer; 
    78 
    89class Intersectable { 
     
    5455  virtual float IntersectionComplexity() = 0; 
    5556   
    56         virtual int NumberOfFaces() const = 0; 
     57  virtual int NumberOfFaces() const = 0; 
    5758 
    58         virtual int Type() const = 0; 
    59  
     59  virtual int Type() const = 0; 
     60   
    6061  virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0; 
    61  
    62         virtual int 
    63         GetRandomVisibleSurfacePoint(Vector3 &point, 
    64                                                                                                                         Vector3 &normal, 
    65                                                                                                                         const Vector3 &viewpoint, 
     62   
     63  virtual int 
     64  GetRandomVisibleSurfacePoint(Vector3 &point, 
     65                                                          Vector3 &normal, 
     66                                                          const Vector3 &viewpoint, 
    6667                                                                                                                         const int maxTries 
    67                                                                                                                          ) = 0; 
    68  
    69         virtual ostream &Describe(ostream &s) = 0; 
    70          
     68                                                           ) = 0; 
     69   
     70  virtual ostream &Describe(ostream &s) = 0; 
     71   
     72  virtual int GenerateSilhouetteRays(const int nrays, 
     73                                                                         const AxisAlignedBox3 &originBox, 
     74                                                                         const AxisAlignedBox3 &directionBox, 
     75                                                                         VssRayContainer &rays 
     76                                                                         ) {return 0;} 
     77   
    7178}; 
    7279 
  • trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp

    r475 r492  
    511511  float maxt = 1e6; 
    512512  float mint = 0; 
    513  
     513  
    514514  Intersectable::NewMail(); 
    515515 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Makefile

    r464 r492  
    11############################################################################# 
    22# Makefile for building: preprocessor 
    3 # Generated by qmake (2.00a) (Qt 4.1.0-rc1) on: st 14. XII 10:37:40 2005 
     3# Generated by qmake (2.00a) (Qt 4.1.0-rc1) on: út 3. I 23:13:25 2006 
    44# Project:  preprocessor.pro 
    55# Template: app 
     
    7171                D:\Qt\4.1.0-rc1\mkspecs\features\debug_and_release.prf \ 
    7272                D:\Qt\4.1.0-rc1\mkspecs\features\default_post.prf \ 
     73                D:\Qt\4.1.0-rc1\mkspecs\features\qt.prf \ 
     74                D:\Qt\4.1.0-rc1\mkspecs\features\win32\opengl.prf \ 
     75                D:\Qt\4.1.0-rc1\mkspecs\features\moc.prf \ 
    7376                D:\Qt\4.1.0-rc1\mkspecs\features\win32\thread.prf \ 
    7477                D:\Qt\4.1.0-rc1\mkspecs\features\warn_off.prf \ 
     
    7881                D:\Qt\4.1.0-rc1\mkspecs\features\win32\stl.prf \ 
    7982                D:\Qt\4.1.0-rc1\mkspecs\features\shared.prf \ 
    80                 D:\Qt\4.1.0-rc1\mkspecs\features\qt.prf \ 
    81                 D:\Qt\4.1.0-rc1\mkspecs\features\moc.prf \ 
    8283                D:\Qt\4.1.0-rc1\mkspecs\features\resources.prf \ 
    8384                D:\Qt\4.1.0-rc1\mkspecs\features\uic.prf 
     
    9192D:\Qt\4.1.0-rc1\mkspecs\features\debug_and_release.prf: 
    9293D:\Qt\4.1.0-rc1\mkspecs\features\default_post.prf: 
     94D:\Qt\4.1.0-rc1\mkspecs\features\qt.prf: 
     95D:\Qt\4.1.0-rc1\mkspecs\features\win32\opengl.prf: 
     96D:\Qt\4.1.0-rc1\mkspecs\features\moc.prf: 
    9397D:\Qt\4.1.0-rc1\mkspecs\features\win32\thread.prf: 
    9498D:\Qt\4.1.0-rc1\mkspecs\features\warn_off.prf: 
     
    98102D:\Qt\4.1.0-rc1\mkspecs\features\win32\stl.prf: 
    99103D:\Qt\4.1.0-rc1\mkspecs\features\shared.prf: 
    100 D:\Qt\4.1.0-rc1\mkspecs\features\qt.prf: 
    101 D:\Qt\4.1.0-rc1\mkspecs\features\moc.prf: 
    102104D:\Qt\4.1.0-rc1\mkspecs\features\resources.prf: 
    103105D:\Qt\4.1.0-rc1\mkspecs\features\uic.prf: 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.cpp

    r485 r492  
    103103         
    104104  for ( ; 
    105                                 faceIndex < mFaces.size(); 
    106                                 faceIndex++) { 
     105                faceIndex < mFaces.size(); 
     106                faceIndex++) { 
    107107    hits += CastRayToFace(faceIndex, ray, nearestT, nearestFace, instance); 
    108108    if (mIsConvex && nearestFace != -1) 
     
    122122int 
    123123Mesh::CastRayToSelectedFaces( 
    124                                                                                                                 Ray &ray, 
    125                                                                                                                 const vector<int> &faces, 
    126                                                                                                                 Intersectable *instance 
    127                                                                                                                 ) 
     124                                                        Ray &ray, 
     125                                                        const vector<int> &faces, 
     126                                                        Intersectable *instance 
     127                                                        ) 
    128128{ 
    129129  vector<int>::const_iterator fi; 
     
    160160inline int 
    161161int_lineseg(float px, 
    162                                                 float py, 
    163                                                 float u1, 
    164                                                 float v1, 
    165                                                 float u2, 
    166                                                 float v2) 
    167 { 
    168   float t; 
     162                        float py, 
     163                        float u1, 
     164                        float v1, 
     165                        float u2, 
     166                        float v2) 
     167{ 
    169168  float ydiff; 
    170169 
     
    183182  if (fabs(ydiff) < Limits::Small) {      // denominator near 0 
    184183    if (((fabs(v1) > Limits::Small) || 
    185                                 (u1 > 0) || (u2 > 0))) 
     184                (u1 > 0) || (u2 > 0))) 
    186185      return 0; 
    187186    return 1; 
    188187  } 
    189  
    190   t = -v1 / ydiff;                // Compute parameter 
    191  
    192   return (u1 + t * (u2 - u1)) > 0; 
     188   
     189  double t = -v1 / ydiff;                 // Compute parameter 
     190 
     191  double thresh; 
     192  if (ydiff < 0.0f) 
     193        thresh = -1e20; 
     194  else 
     195        thresh = 1e20; 
     196 
     197   
     198  return (u1 + t * (u2 - u1)) > thresh; //-Limits::Small; 
    193199} 
    194200 
     
    198204int 
    199205Mesh::RayFaceIntersection(const int faceIndex, 
    200                                                                                                         const Ray &ray, 
    201                                                                                                         float &t, 
    202                                                                                                         const float nearestT 
    203                                                                                                         ) 
     206                                                  const Ray &ray, 
     207                                                  float &t, 
     208                                                  const float nearestT 
     209                                                  ) 
    204210{ 
    205211  Face *face  = mFaces[faceIndex]; 
     
    244250      mVertices[face->mVertexIndices[i]].ExtractVerts(&u2, &v2, paxis); 
    245251      // line u1, v1, u2, v2 
    246       if ((v2 - v1)*(u1 - u) > (u2 - u1)*(v1 - v)) 
    247                                 return Ray::NO_INTERSECTION; 
     252      if ((v1 - v2)*(u - u1) + (u2 - u1)*(v - v1) > 0) 
     253                return Ray::NO_INTERSECTION; 
    248254      u1 = u2; 
    249255      v1 = v2; 
     
    416422int 
    417423TransformedMeshInstance::CastRay( 
    418                                                                                                                                 Ray &ray 
    419                                                                                                                                 ) 
     424                                                                Ray &ray 
     425                                                                ) 
    420426{ 
    421427  ray.ApplyTransform(Invert(mWorldTransform)); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.h

    r406 r492  
    145145  int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 
    146146 
     147  int 
     148  GetRandomVisibleSurfacePoint(Vector3 &point, 
     149                                                           Vector3 &normal, 
     150                                                           const Vector3 &viewpoint, 
     151                                                           const int maxTries 
     152                                                           ); 
     153   
     154  virtual ostream &Describe(ostream &s) { 
     155        return s<<"Mesh #vertices="<<(int)mVertices.size()<<" #faces="<<(int)mFaces.size(); 
     156  } 
     157   
     158 
     159}; 
     160 
     161 
     162class MeshInstance : public Intersectable { 
     163protected: 
     164  Mesh *mMesh; 
     165   
     166public: 
     167  MeshInstance(Mesh *mesh):Intersectable(), mMesh(mesh) 
     168  { 
     169  } 
     170 
     171  int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 
     172 
    147173        int 
    148174        GetRandomVisibleSurfacePoint(Vector3 &point, 
     
    151177                                                                                                                         const int maxTries 
    152178                                                                                                                         ); 
    153                  
    154         virtual ostream &Describe(ostream &s) { 
    155                 return s<<"Mesh #vertices="<<(int)mVertices.size()<<" #faces="<<(int)mFaces.size(); 
    156         } 
    157  
    158 }; 
    159  
    160 class MeshInstance : public Intersectable { 
    161 protected: 
    162   Mesh *mMesh; 
    163    
    164 public: 
    165   MeshInstance(Mesh *mesh):Intersectable(), mMesh(mesh) 
    166   { 
    167   } 
    168  
    169   int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 
    170  
    171         int 
    172         GetRandomVisibleSurfacePoint(Vector3 &point, 
    173                                                                                                                          Vector3 &normal, 
    174                                                                                                                          const Vector3 &viewpoint, 
    175                                                                                                                          const int maxTries 
    176                                                                                                                          ); 
    177179 
    178180 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp

    r491 r492  
    1212#include "RenderSimulator.h" 
    1313 
     14Preprocessor *preprocessor; 
     15 
    1416Preprocessor::Preprocessor(): 
    1517mKdTree(NULL), 
     
    1921mViewCellsManager(NULL) 
    2022{ 
     23  environment->GetBoolValue("Preprocessor.useGlRenderer", mUseGlRenderer); 
    2124} 
    2225 
     
    5558 
    5659  mSceneGraph = new SceneGraph; 
    57  
    5860   
    5961  Parser *parser; 
     
    9597 
    9698        if (result) { 
    97                 mSceneGraph->AssignObjectIds(); 
    98                 int intersectables, faces; 
    99                 mSceneGraph->GetStatistics(intersectables, faces); 
    100                 cout<<filename<<" parsed successfully."<<endl; 
    101                 cout<<"#NUM_OBJECTS (Total numner of objects)\n"<<intersectables<<endl; 
    102                 cout<<"#NUM_FACES (Total numner of faces)\n"<<faces<<endl; 
    103         } 
    104  
    105          
    106   return result; 
     99           
     100          mSceneGraph->AssignObjectIds(); 
     101          int intersectables, faces; 
     102          mSceneGraph->GetStatistics(intersectables, faces); 
     103          cout<<filename<<" parsed successfully."<<endl; 
     104          cout<<"#NUM_OBJECTS (Total numner of objects)\n"<<intersectables<<endl; 
     105          cout<<"#NUM_FACES (Total numner of faces)\n"<<faces<<endl; 
     106          mSceneGraph->CollectObjects(&mObjects); 
     107          mSceneGraph->mRoot->UpdateBox(); 
     108        } 
     109         
     110         
     111        return result; 
    107112} 
    108113 
     
    139144bool 
    140145Preprocessor::Export( const string filename, 
    141                                                                                         const bool scene, 
    142                                                                                         const bool kdtree, 
    143                                                                                         const bool bsptree 
    144                                                                                         ) 
     146                                          const bool scene, 
     147                                          const bool kdtree, 
     148                                          const bool bsptree 
     149                                          ) 
    145150{ 
    146151  Exporter *exporter = Exporter::GetExporter(filename); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h

    r490 r492  
    77#include "Mesh.h" 
    88#include "KdTree.h" 
     9 
     10#include <QObject> 
    911 
    1012class RenderSimulator; 
     
    3032      viewcell loading/generation and the visibility computation itself. 
    3133  */ 
    32 class Preprocessor { 
     34class Preprocessor : public QObject { 
     35  Q_OBJECT 
     36 
    3337public: 
    3438        /** Default constructor initialising e.g., KD tree and BSP tree. 
     
    9498  /// scene graph loaded from file 
    9599  SceneGraph *mSceneGraph; 
     100 
     101  /// raw array of objects 
     102  ObjectContainer mObjects; 
    96103   
    97104  /// kD-tree organizing the scene graph (occluders + occludees) + viewcells 
     
    115122  VspKdTree *mVspKdTree; 
    116123 
     124  bool mUseGlRenderer; 
     125   
     126protected: 
     127 
     128  ///////////////////////// 
     129 
     130  /// samples used for construction of the BSP view cells tree. 
     131  int mBspConstructionSamples; 
     132   /// samples used for construction of the VSP KD tree. 
     133  int mVspKdConstructionSamples; 
    117134  /** Simulates rendering of the scene. 
    118135  */ 
    119136  RenderSimulator *mRenderSimulator; 
     137 
     138  signals: 
     139  void EvalPvsStat(); 
     140 
    120141}; 
    121142 
    122143 
    123144 
    124  
     145extern Preprocessor *preprocessor; 
    125146 
    126147#endif 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.h

    r485 r492  
    6060  */ 
    6161  PvsData<T> *Find(T sample); 
     62 
     63  bool GetSampleContribution(T sample, float &contribution); 
    6264   
    6365  /** Adds sample to PVS.  
     
    7173  */ 
    7274  int AddSample(T sample); 
    73  
     75   
    7476  /** Adds one pvs to another one. 
    7577          @returns new pvs size 
     
    157159 
    158160template <typename T> 
    159 int Pvs<T>::AddSample(T sample) 
    160 { 
    161   float dummy; 
    162   return AddSample(sample, dummy) ? 1 : 0; 
    163 } 
    164  
    165 template <typename T> 
    166 bool Pvs<T>::AddSample(T sample, float &contribution) 
     161int 
     162Pvs<T>::AddSample(T sample) 
     163{ 
     164  PvsData<T> *data = Find(sample); 
     165   
     166  if (data)  { 
     167        return ++data->mVisibleSamples; 
     168  } 
     169  else { 
     170        mEntries[sample] = PvsData<T>(1); 
     171        return 1; 
     172  } 
     173} 
     174 
     175template <typename T> 
     176bool 
     177Pvs<T>::AddSample(T sample, float &contribution) 
    167178{ 
    168179  PvsData<T> *data = Find(sample); 
     
    181192 
    182193template <typename T> 
     194bool 
     195Pvs<T>::GetSampleContribution(T sample, float &contribution)  
     196{ 
     197  PvsData<T> *data = Find(sample); 
     198   
     199  if (data)  { 
     200        contribution = 1.0f/(data->mVisibleSamples + 1); 
     201        return false; 
     202  } 
     203  else { 
     204        contribution = 1.0f; 
     205        return true; 
     206  } 
     207} 
     208 
     209template <typename T> 
    183210bool Pvs<T>::RemoveSample(T sample, const int visibleSamples) 
    184211{ 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp

    r490 r492  
    1111#include "ViewCellsManager.h" 
    1212#include "RenderSimulator.h" 
     13#include "GlRenderer.h" 
    1314 
    1415static bool useViewSpaceBox = false; 
     
    3334  environment->GetIntValue("RssPreprocessor.Export.numRays", mExportNumRays); 
    3435  environment->GetBoolValue("RssPreprocessor.useViewcells", mUseViewcells); 
    35   environment->GetBoolValue("RssPreprocessor.useViewcells", mUseViewcells); 
     36  environment->GetBoolValue("RssPreprocessor.objectBasedSampling", mObjectBasedSampling); 
     37  environment->GetBoolValue("RssPreprocessor.directionalSampling", mDirectionalSampling); 
    3638 
    3739  environment->GetBoolValue("RssPreprocessor.loadInitialSamples", mLoadInitialSamples); 
     
    3941   
    4042  mStats.open("stats.log"); 
     43 
    4144} 
    4245 
    4346RssPreprocessor::~RssPreprocessor() 
    4447{ 
    45   CLEAR_CONTAINER(mVssRays); 
     48  // mVssRays get deleted in the tree 
     49  //  CLEAR_CONTAINER(mVssRays); 
    4650} 
    4751 
     
    7882  Vector3 pointA, pointB; 
    7983  float bsize = Magnitude(box.Size()); 
     84 
    8085   
    8186  if (mKdTree->CastRay(ray)) { 
     
    8691        // compute intersection with the scene bounding box 
    8792        float tmin, tmax; 
    88         box.ComputeMinMaxT(ray, &tmin, &tmax); 
    89         if (tmax > bsize) { 
    90           //cerr<<"Warning: tmax > box size tmax="<<tmax<<" tmin="<<tmin<<" size="<<bsize<<endl; 
    91           //cerr<<"ray"<<ray<<endl; 
    92         } 
    93         pointA = ray.Extrap(tmax); 
     93        if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax) 
     94          pointA = ray.Extrap(tmax); 
     95        else 
     96          return 0; 
    9497  } 
    9598 
     
    108111        objectB = NULL; 
    109112        float tmin, tmax; 
    110         box.ComputeMinMaxT(ray, &tmin, &tmax); 
    111         if (tmax > bsize) { 
    112           //cerr<<"Warning: tmax > box size tmax="<<tmax<<" tmin="<<tmin<<" size="<<bsize<<endl; 
    113           //cerr<<"ray"<<ray<<endl; 
    114         } 
    115         pointB = ray.Extrap(tmax); 
    116   } 
    117  
     113        if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax) 
     114          pointB = ray.Extrap(tmax); 
     115        else 
     116          return 0; 
     117  } 
     118 
     119  //  if (objectA == NULL && objectB != NULL) { 
     120  if (1) { 
     121        // cast again to ensure that there is no objectA 
     122        SetupRay(ray, pointB, direction); 
     123        if (mKdTree->CastRay(ray)) { 
     124          objectA = ray.intersections[0].mObject; 
     125          pointA = ray.Extrap(ray.intersections[0].mT); 
     126        } 
     127  } 
     128   
     129   
    118130  VssRay *vssRay  = NULL; 
    119131 
    120   bool validSample = true; 
    121   if (detectEmptyViewSpace) { 
     132  bool validSample = (objectA != objectB); 
     133  if (0 && detectEmptyViewSpace) {   // consider all samples valid 
    122134        // check if the viewpoint lies on the line segment AB 
    123135        if (Distance(pointA, pointB) < 
     
    176188  Vector3 point; 
    177189  if (!use2dSampling) { 
    178         Vector3 normal; 
    179         int i = (int)RandomValue(0, (Real)((int)mObjects.size()-1)); 
    180         Intersectable *object = mObjects[i]; 
    181         object->GetRandomSurfacePoint(point, normal); 
     190        if (mObjectBasedSampling) { 
     191          Vector3 normal; 
     192          int i = RandomValue(0, mObjects.size()-1); 
     193          Intersectable *object = mObjects[i]; 
     194          object->GetRandomSurfacePoint(point, normal); 
     195        } else { 
     196          // select 
     197          if (mDirectionalSampling) { 
     198                point = viewpoint + UniformRandomVector(); 
     199          } else { 
     200                // select the other point uniformly distruted in the whole viewspace 
     201                AxisAlignedBox3 box; 
     202                 
     203                if (viewSpaceBox) 
     204                  box =*viewSpaceBox; 
     205                else  
     206                  box = mKdTree->GetBox(); 
     207                 
     208                point = box.GetRandomPoint(); 
     209          } 
     210        } 
    182211  } else { 
    183212        AxisAlignedBox3 box; 
     
    187216        else  
    188217          box = mKdTree->GetBox(); 
    189                  
     218         
    190219        point = box.GetRandomPoint(); 
    191220        point.y = viewpoint.y; 
    192221  } 
    193222         
     223  return point - viewpoint; 
     224} 
     225 
     226Vector3 
     227RssPreprocessor::InitialGetDirection(const Vector3 &viewpoint, 
     228                                                                         AxisAlignedBox3 *viewSpaceBox 
     229                                                                         ) 
     230{ 
     231  Vector3 point; 
     232  if (!use2dSampling) { 
     233        if (1 || mObjectBasedSampling) { 
     234          Vector3 normal; 
     235          int i = RandomValue(0, mObjects.size()-1); 
     236          Intersectable *object = mObjects[i]; 
     237          object->GetRandomSurfacePoint(point, normal); 
     238        } else { 
     239          // select 
     240          if (1 || mDirectionalSampling) { 
     241                point = viewpoint + UniformRandomVector(); 
     242          } else { 
     243                // select the other point uniformly distruted in the whole viewspace 
     244                AxisAlignedBox3 box; 
     245                 
     246                if (viewSpaceBox) 
     247                  box =*viewSpaceBox; 
     248                else  
     249                  box = mKdTree->GetBox(); 
     250                 
     251                point = box.GetRandomPoint(); 
     252          } 
     253        } 
     254  } else { 
     255        AxisAlignedBox3 box; 
     256         
     257        if (viewSpaceBox) 
     258          box =*viewSpaceBox; 
     259        else  
     260          box = mKdTree->GetBox(); 
     261         
     262        point = box.GetRandomPoint(); 
     263        point.y = viewpoint.y; 
     264  } 
     265   
    194266  return point - viewpoint; 
    195267} 
     
    203275  int num; 
    204276 
    205  
    206    
    207   float avgPvsSize; 
    208   float avgRayContribution; 
    209   float avgPvsEntropy; 
    210   float avgRayLengthEntropy; 
    211   float avgImportance; 
    212   float avgRays; 
    213   rssTree->GetTreeStatistics( 
    214                                                          avgPvsSize, 
    215                                                          avgRays, 
    216                                                          avgRayContribution, 
    217                                                          avgPvsEntropy, 
    218                                                          avgRayLengthEntropy, 
    219                                                          avgImportance); 
    220    
     277  rssTree->UpdateTreeStatistics(); 
     278 
    221279  cout<< 
    222         "#RSS_AVG_PVS_SIZE\n"<<avgPvsSize<<endl<< 
    223         "#RSS_AVG_RAYS\n"<<avgRays<<endl<< 
    224         "#RSS_AVG_RAY_CONTRIB\n"<<avgRayContribution<<endl<< 
    225         "#RSS_AVG_PVS_ENTROPY\n"<<avgPvsEntropy<<endl<< 
    226         "#RSS_AVG_RAY_LENGTH_ENTROPY\n"<<avgRayLengthEntropy<<endl<< 
    227         "#RSS_AVG_IMPORTANCE\n"<<avgImportance<<endl; 
     280        "#RSS_AVG_PVS_SIZE\n"<<rssTree->stat.avgPvsSize<<endl<< 
     281        "#RSS_AVG_RAYS\n"<<rssTree->stat.avgRays<<endl<< 
     282        "#RSS_AVG_RAY_CONTRIB\n"<<rssTree->stat.avgRayContribution<<endl<< 
     283        "#RSS_AVG_PVS_ENTROPY\n"<<rssTree->stat.avgPvsEntropy<<endl<< 
     284        "#RSS_AVG_RAY_LENGTH_ENTROPY\n"<<rssTree->stat.avgRayLengthEntropy<<endl<< 
     285        "#RSS_AVG_IMPORTANCE\n"<<rssTree->stat.avgImportance<<endl; 
    228286   
    229287  if (0) { 
    230         float p = desiredSamples/(float)(avgRayContribution*rssTree->stat.Leaves()); 
     288        float p = desiredSamples/(float)(rssTree->stat.avgRayContribution*rssTree->stat.Leaves()); 
    231289        num = rssTree->GenerateRays(p, rays); 
    232290  } else { 
     
    249307  cout<<"Exporting vss rays..."<<endl<<flush; 
    250308         
    251   float prob = number/(float)vssRays.size(); 
    252  
    253  
    254309  Exporter *exporter = NULL; 
    255310  exporter = Exporter::GetExporter(filename); 
     
    266321  } 
    267322         
    268   VssRayContainer rays; for (int i=0; i < vssRays.size(); i++) 
    269         if (RandomValue(0,1) < prob) 
    270           rays.push_back(vssRays[i]); 
     323  VssRayContainer rays; 
     324   
     325  vssRays.SelectRays( number, rays); 
    271326 
    272327  exporter->ExportRays(rays, RgbColor(1, 0, 0)); 
     
    388443} 
    389444 
     445 
     446void 
     447RssPreprocessor::ComputeRenderError() 
     448{ 
     449  // compute rendering error 
     450  if (renderer) { 
     451        emit EvalPvsStat(); 
     452        QMutex mutex; 
     453        mutex.lock(); 
     454        renderer->mRenderingFinished.wait(&mutex); 
     455        mutex.unlock(); 
     456        mStats << 
     457          "#AvgPvsRenderError\n" <<renderer->mPvsStat.GetAvgError()<<endl<< 
     458          "#MaxPvsRenderError\n" <<renderer->mPvsStat.GetMaxError()<<endl<< 
     459          "#ErrorFreeFrames\n" <<renderer->mPvsStat.GetErrorFreeFrames()<<endl; 
     460  } 
     461} 
     462 
    390463bool 
    391464RssPreprocessor::ComputeVisibility() 
    392465{ 
     466   
     467  connect(this, SIGNAL(EvalPvsStat()), renderer, SLOT(EvalPvsStat()) ); 
     468   
    393469  cout<<"Rss Preprocessor started\n"<<flush; 
    394470  cout<<"Memory/ray "<<sizeof(VssRay)+sizeof(RssTreeNode::RayInfo)<<endl; 
    395   mSceneGraph->CollectObjects(&mObjects); 
     471 
     472  Randomize(0); 
     473   
    396474         
    397475  long startTime = GetTime(); 
     
    443521 
    444522  RssTree *rssTree = NULL; 
    445  
    446   if (mLoadInitialSamples) 
    447   { 
    448           cout << "Loading samples from file ... "; 
    449           LoadSamples(mVssRays, mObjects); 
    450           cout << "finished\n" << endl; 
    451   } 
    452   else 
    453   { 
     523  int rssPass = 0; 
     524  int rssSamples = 0; 
     525 
     526#if 0 
     527  if (mLoadInitialSamples) { 
     528        cout << "Loading samples from file ... "; 
     529        LoadSamples(mVssRays, mObjects); 
     530        cout << "finished\n" << endl; 
     531  } else { 
     532#endif 
    454533        while (totalSamples < mInitialSamples) { 
    455                 int passContributingSamples = 0; 
    456                 int passSampleContributions = 0; 
    457                 int passSamples = 0; 
    458                 int index = 0; 
    459                          
    460                 int sampleContributions; 
    461                          
    462                 int s = Min(mSamplesPerPass, mInitialSamples); 
    463                 for (int k=0; k < s; k++) { 
    464                                  
     534          int passContributingSamples = 0; 
     535          int passSampleContributions = 0; 
     536          int passSamples = 0; 
     537          int index = 0; 
     538           
     539          int sampleContributions; 
     540           
     541          //int s = Min(mSamplesPerPass, mInitialSamples); 
     542          int s = mInitialSamples; 
     543           
     544          for (int k=0; k < s; k++) { 
     545                 
     546                 
    465547                //Vector3 viewpoint = GetViewpoint(mViewSpaceBox); 
    466548                Vector3 viewpoint;  
    467                 mViewCellsManager->GetViewPoint(viewpoint); 
    468                 Vector3 direction = GetDirection(viewpoint, mViewSpaceBox); 
    469                                  
     549                //              mViewCellsManager->GetViewPoint(viewpoint); 
     550                viewpoint = GetViewpoint(mViewSpaceBox); 
     551                Vector3 direction = InitialGetDirection(viewpoint, mViewSpaceBox); 
     552                 
    470553                sampleContributions = CastRay(viewpoint, direction, mVssRays); 
    471                                  
    472                                  
     554                 
     555                 
    473556                //-- CORR matt: put block inside loop 
    474557                if (sampleContributions) { 
    475                         passContributingSamples ++; 
    476                         passSampleContributions += sampleContributions; 
     558                  passContributingSamples ++; 
     559                  passSampleContributions += sampleContributions; 
    477560                } 
    478561                passSamples++; 
    479562                totalSamples++; 
    480                 } 
    481              
    482                          
    483                 float avgRayContrib = (passContributingSamples > 0) ?  
     563          } 
     564           
     565           
     566          float avgRayContrib = (passContributingSamples > 0) ?  
    484567                passSampleContributions/(float)passContributingSamples : 0; 
    485                          
    486                 cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
    487                 cout << "#TotalSamples=" << totalSamples/1000  
    488                         << "k   #SampleContributions=" << passSampleContributions << " ("  
    489                         << 100*passContributingSamples/(float)passSamples<<"%)"  
    490                         << "avgcontrib=" << avgRayContrib << endl; 
    491                          
    492                 mStats << 
     568           
     569          cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
     570          cout << "#TotalSamples=" << totalSamples/1000  
     571                   << "k   #SampleContributions=" << passSampleContributions << " ("  
     572                   << 100*passContributingSamples/(float)passSamples<<"%)"  
     573                   << "avgcontrib=" << avgRayContrib << endl; 
     574           
     575          mPass++; 
     576        } 
     577           
     578        cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 
     579        cout << "#totalRayStackSize=" << (int)mVssRays.size() << endl <<flush; 
     580         
     581        rssSamples += mVssRays.size(); 
     582         
     583         
     584        if (mExportRays) { 
     585          char filename[64]; 
     586          sprintf(filename, "rss-rays-initial.x3d"); 
     587          ExportRays(filename, mVssRays, mExportNumRays); 
     588        } 
     589         
     590        if (mStoreInitialSamples) 
     591          { 
     592                cout << "Writing samples to file ... "; 
     593                WriteSamples(mVssRays); 
     594                cout << "finished\n" << endl; 
     595          } 
     596         
     597        if (mUseViewcells) { 
     598          // construct view cells 
     599          mViewCellsManager->Construct(mObjects, mVssRays); 
     600          // evaluate contributions of the intitial rays 
     601          mViewCellsManager->ComputeSampleContributions(mVssRays); 
     602           
     603           
     604          mStats << 
    493605                "#Pass\n" <<mPass<<endl<< 
    494                 "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<< 
    495                 "#TotalSamples\n" << totalSamples<< endl<< 
    496                 "#SampleContributions\n" << passSampleContributions << endl <<  
    497                 "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 
    498                 "#AvgRayContrib\n" << avgRayContrib << endl; 
    499                  
    500                 mPass++; 
    501  
    502         } 
    503    
    504         cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 
    505   } 
    506  
    507   cout << "#totalRayStackSize=" << (int)mVssRays.size() << endl <<flush; 
    508    
    509  
    510   if (mExportRays) { 
    511         char filename[64]; 
    512         sprintf(filename, "rss-rays-initial.x3d"); 
    513         ExportRays(filename, mVssRays, mExportNumRays); 
    514   } 
    515    
    516   if (mStoreInitialSamples) 
    517   { 
    518           cout << "Writing samples to file ... "; 
    519           WriteSamples(mVssRays); 
    520           cout << "finished\n" << endl; 
    521   } 
    522  
    523   if (mUseViewcells) { 
    524         // construct view cells 
    525         mViewCellsManager->Construct(mObjects, mVssRays); 
    526          
     606                "#RssPass\n" <<rssPass<<endl<< 
     607                "#Time\n" << TimeDiff(startTime, GetTime())*1e-3<<endl<< 
     608                "#TotalSamples\n" <<totalSamples<<endl<< 
     609                "#RssSamples\n" <<rssSamples<<endl; 
     610           
     611        ComputeRenderError(); 
     612 
     613        mVssRays.PrintStatistics(mStats); 
     614        mViewCellsManager->PrintPvsStatistics(mStats); 
     615 
    527616        VssRayContainer selectedRays; 
    528617        int desired = Max( 
    529618                                          mViewCellsManager->GetPostProcessSamples(), 
    530619                                          mViewCellsManager->GetVisualizationSamples()); 
    531         float p = desired/(float)mVssRays.size(); 
    532          
    533         for (int i=0; i < mVssRays.size(); i++) { 
    534           if (Random(1.0f) < p) 
    535                 selectedRays.push_back(mVssRays[i]); 
    536         } 
     620 
     621        mVssRays.SelectRays(desired, selectedRays); 
     622         
    537623        //-- post process view cells 
    538624        mViewCellsManager->PostProcess(mObjects, selectedRays); 
     
    547633 
    548634 
     635   
     636  rssPass++; 
     637   
    549638  rssTree = new RssTree; 
    550          
     639  rssTree->SetPass(mPass); 
     640   
    551641  if (mUseImportanceSampling) { 
    552642         
     
    555645        else 
    556646          rssTree->Construct(mVssRays, NULL); 
     647 
     648        rssTree->stat.Print(mStats); 
    557649        cout<<"RssTree root PVS size = "<<rssTree->GetRootPvsSize()<<endl; 
    558650         
     
    572664  // viewcells->UpdatePVS(newVssRays); 
    573665   
    574   int rssPass = 0; 
    575   int rssSamples = 0; 
     666 
    576667  while (1) { 
    577668        int num = mRssSamplesPerPass; 
    578669        SimpleRayContainer rays; 
    579670        VssRayContainer vssRays; 
    580                  
     671 
     672 
    581673        if (!mUseImportanceSampling) { 
    582674          for (int j=0; j < num; j++) { 
     
    597689 
    598690         
    599         totalSamples+=num; 
    600         rssSamples+=num; 
    601  
     691        totalSamples += rays.size(); 
     692        rssSamples += vssRays.size(); 
     693 
     694         
     695         
    602696        mStats << 
    603697          "#Pass\n" <<mPass<<endl<< 
     
    607701          "#RssSamples\n" <<rssSamples<<endl; 
    608702 
     703 
    609704        if (mUseViewcells) { 
    610705           
     
    616711        } 
    617712 
    618         // add rays to the tree after the viewcells have been cast to have their contributions 
    619         // already when adding into the tree 
    620         // do not add those rays which have too low or no contribution.... 
    621          
    622         if (mUseImportanceSampling) { 
    623           rssTree->AddRays(vssRays); 
    624            
    625           if (0) { 
    626                 cout<<"############# Rss PVS STAT ##################\n"; 
    627                 cout<<"#AVG_RSS_PVS\n"<<rssTree->GetAvgPvsSize()<<endl; 
    628                 cout<<"#RSS_ROOT_PVS\n"<<rssTree->GetRootPvsSize()<<endl; 
    629           } 
    630            
    631           if (mUpdateSubdivision) { 
    632                 int subdivided = rssTree->UpdateSubdivision(); 
    633                 cout<<"subdivided leafs = "<<subdivided<<endl; 
    634                 cout<<"#total leaves = "<<rssTree->stat.Leaves()<<endl; 
    635           } 
    636         } 
    637          
     713 
     714        ComputeRenderError(); 
     715         
     716        // epxort rays before adding them to the tree -> some of them can be deleted 
     717 
    638718        if (mExportRays) { 
    639719          char filename[64]; 
     
    644724           
    645725          ExportRays(filename, vssRays, mExportNumRays); 
    646         } 
     726 
     727          // now export all contributing rays 
     728          VssRayContainer contributingRays; 
     729          vssRays.GetContributingRays(contributingRays, mPass); 
     730          mStats<<"#NUM_CONTRIBUTING_RAYS\n"<<contributingRays.size()<<endl; 
     731          sprintf(filename, "rss-crays-%04d.x3d", rssPass); 
     732          ExportRays(filename, contributingRays, mExportNumRays); 
     733        } 
     734 
     735         
     736        // add rays to the tree after the viewcells have been cast to have their contributions 
     737        // already when adding into the tree 
     738        // do not add those rays which have too low or no contribution.... 
     739         
     740        if (mUseImportanceSampling) { 
     741          rssTree->AddRays(vssRays); 
     742           
     743          if (0) { 
     744                cout<<"############# Rss PVS STAT ##################\n"; 
     745                cout<<"#AVG_RSS_PVS\n"<<rssTree->GetAvgPvsSize()<<endl; 
     746                cout<<"#RSS_ROOT_PVS\n"<<rssTree->GetRootPvsSize()<<endl; 
     747          } 
     748           
     749           
     750          if (mUpdateSubdivision) { 
     751                int updatePasses = 1; 
     752                if (mPass % updatePasses == 0) { 
     753                  int subdivided = rssTree->UpdateSubdivision(); 
     754                  cout<<"subdivided leafs = "<<subdivided<<endl; 
     755                  cout<<"#total leaves = "<<rssTree->stat.Leaves()<<endl; 
     756                } 
     757          } 
     758        } 
     759         
    647760 
    648761         
     
    653766        } 
    654767 
     768         
     769        if (!mUseImportanceSampling)  
     770          CLEAR_CONTAINER(vssRays); 
     771 
    655772        if (totalSamples >= mRssSamples + mInitialSamples) 
    656773          break; 
     
    659776        rssPass++; 
    660777        mPass++; 
     778        rssTree->SetPass(mPass); 
    661779  } 
    662780   
  • trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.h

    r490 r492  
    44#include <fstream> 
    55using namespace std; 
     6 
    67 
    78#include "Preprocessor.h" 
     
    1415    sampling of view space */ 
    1516class RssPreprocessor : public Preprocessor { 
     17   
    1618public: 
    1719  int mPass; 
     
    2931  bool mUseViewcells; 
    3032  bool mUpdateSubdivision; 
     33 
     34  bool mObjectBasedSampling; 
     35  bool mDirectionalSampling; 
    3136   
    3237  AxisAlignedBox3 *mViewSpaceBox; 
     
    3439  ofstream mStats; 
    3540 
    36   ObjectContainer mObjects; 
    3741 
    3842  // rays cast during the processing 
     
    5660                           AxisAlignedBox3 *viewSpaceBox 
    5761                           ); 
    58          
     62 
     63  Vector3 
     64  InitialGetDirection(const Vector3 &viewpoint, 
     65                                          AxisAlignedBox3 *viewSpaceBox 
     66                                          ); 
     67 
    5968  void 
    6069  SetupRay(Ray &ray,  
     
    118127                        ); 
    119128 
     129 
     130  void 
     131  ComputeRenderError(); 
     132 
    120133}; 
    121134 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.cpp

    r485 r492  
    1  
    21// ================================================================ 
    32// $Id: lsds_kdtree.cpp,v 1.18 2005/04/16 09:34:21 bittner Exp $ 
     
    2524#include "Ray.h" 
    2625#include "Containers.h" 
     26#include "ViewCell.h" 
     27#include "Exporter.h" 
     28#include "Preprocessor.h" 
     29#include "SceneGraph.h" 
    2730 
    2831#define DEBUG_SPLIT_COST 0 
     
    6467} 
    6568 
     69inline void 
     70AddViewcells2Pvs(const ViewCellContainer &viewcells, 
     71                                 const int side, 
     72                                 int &viewcellsBack, 
     73                                 int &viewcellsFront) 
     74{ 
     75  ViewCellContainer::const_iterator it = viewcells.begin(); 
     76   
     77  for (; it != viewcells.end(); ++it) { 
     78        ViewCell *viewcell = *it; 
     79        if (side <= 0) { 
     80          if (!viewcell->Mailed() && !viewcell->Mailed(2)) { 
     81                viewcellsBack++; 
     82                if (viewcell->Mailed(1)) 
     83                  viewcell->Mail(2); 
     84                else 
     85                  viewcell->Mail(); 
     86          } 
     87        } 
     88         
     89        if (side >= 0) { 
     90          if (!viewcell->Mailed(1) && !viewcell->Mailed(2)) { 
     91                viewcellsFront++; 
     92                if (viewcell->Mailed()) 
     93                  viewcell->Mail(2); 
     94                else 
     95                  viewcell->Mail(1); 
     96          } 
     97        } 
     98  } 
     99} 
     100 
     101 
    66102// Constructor 
    67103RssTree::RssTree() 
     
    85121  environment->GetFloatValue("RssTree.maxStaticMemory", maxStaticMemory); 
    86122   
    87    
    88  
    89  
    90   float refDirAngle; 
    91   environment->GetFloatValue("RssTree.refDirAngle", refDirAngle); 
     123  environment->GetFloatValue("RssTree.maxStaticMemory", maxStaticMemory); 
     124 
     125 
    92126   
    93127  environment->GetIntValue("RssTree.accessTimeThreshold", accessTimeThreshold); 
     
    125159  environment->GetIntValue("RssTree.dirSplitDepth", mDirSplitDepth); 
    126160 
     161  environment->GetBoolValue("RssTree.importanceBasedCost", mImportanceBasedCost); 
     162   
     163  environment->GetIntValue("RssTree.maxRays", mMaxRays); 
     164 
    127165  root = NULL; 
    128166   
     
    143181RssStatistics::Print(ostream &app) const 
    144182{ 
    145   app << "===== RssTree statistics ===============\n"; 
     183  app << "###### RssTree statistics ######\n"; 
    146184 
    147185  app << "#N_RAYS ( Number of rays )\n" 
     
    204242      << Time() << " \n"; 
    205243 
    206   app << "===== END OF RssTree statistics ==========\n"; 
     244  app << "###### END OF RssTree statistics ######\n"; 
    207245 
    208246} 
     
    210248 
    211249void 
    212 RssTreeLeaf::UpdatePvsSize() 
    213 { 
    214   if (!mValidPvs) { 
     250RssTree::UpdatePvsSize(RssTreeLeaf *leaf) 
     251{ 
     252  if (!leaf->mValidPvs) { 
    215253        Intersectable::NewMail(); 
    216254        int pvsSize = 0; 
    217         for(RssTreeNode::RayInfoContainer::iterator ri = rays.begin(); 
    218                 ri != rays.end(); 
     255        for(RssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 
     256                ri != leaf->rays.end(); 
    219257                ri++) 
    220258          if ((*ri).mRay->IsActive()) { 
    221259                Intersectable *object; 
    222 #if BIDIRECTIONAL_RAY 
    223                 object = (*ri).mRay->mOriginObject; 
     260                object = (*ri).GetObject(); 
    224261                if (object && !object->Mailed()) { 
    225262                  pvsSize++; 
    226263                  object->Mail(); 
    227264                } 
    228 #endif 
    229                 object = (*ri).mRay->mTerminationObject; 
    230                 if (object && !object->Mailed()) { 
    231                   pvsSize++; 
    232                   object->Mail(); 
    233                 } 
    234           } 
    235         mPvsSize = pvsSize; 
    236         mValidPvs = true; 
    237  
    238         ComputeEntropyImportance(); 
     265          } 
     266        leaf->SetPvsSize(pvsSize); 
     267         
     268        ComputeImportance(leaf); 
    239269  } 
    240270} 
     
    248278  float tmin, tmax; 
    249279  static Ray ray; 
    250   ray.Init(rayInfo.mRay->GetOrigin(), rayInfo.mRay->GetDir(), Ray::LINE_SEGMENT); 
    251   box.ComputeMinMaxT(ray, &tmin, &tmax); 
    252   if (tmin >= tmax) 
     280  cerr<<"Clip not reimplented yet...Quiting\n"; 
     281  exit(1); 
     282  ray.Init(rayInfo.GetOrigin(), rayInfo.GetDir(), Ray::LINE_SEGMENT); 
     283 
     284  if (!box.ComputeMinMaxT(ray, &tmin, &tmax) || tmin>=tmax) 
    253285        return false; 
    254286   
     
    281313  if (root) 
    282314    delete root; 
    283          
     315 
     316   
    284317  root = new RssTreeLeaf(NULL, rays.size()); 
    285318  // first construct a leaf that will get subdivide 
     
    315348                                        ); 
    316349  } 
    317          
    318          
     350   
     351  // make the z axis (unused) a unit size 
     352  // important for volume computation 
     353  dirBBox.SetMin(2, 0.0f); 
     354  dirBBox.SetMax(2, 1.0f); 
     355   
    319356  if ( forcedBoundingBox )  
    320357        bbox = *forcedBoundingBox; 
     
    324361 
    325362  stat.rays = leaf->rays.size(); 
    326   leaf->UpdatePvsSize(); 
    327   leaf->ComputeEntropyImportance(); 
     363  UpdatePvsSize(leaf); 
    328364 
    329365  stat.initialPvsSize = leaf->GetPvsSize(); 
     
    338374   
    339375  stat.Stop(); 
    340  
    341376  stat.Print(cout); 
    342377  cout<<"#Total memory="<<GetMemUsage()<<endl; 
    343378 
     379  // this rotine also updates importances etc... 
    344380} 
    345381 
     
    387423          if (!node->IsLeaf()) { 
    388424                subdivided++; 
     425 
     426                 
    389427                RssTreeInterior *interior = (RssTreeInterior *) node; 
    390428                // push the children on the stack 
     
    482520                                         RssTreeLeaf *leaf, 
    483521                                         const AxisAlignedBox3 &box, 
    484                                          float &position, 
    485                                          int &raysBack, 
    486                                          int &raysFront, 
    487                                          int &pvsBack, 
    488                                          int &pvsFront 
     522                                         SplitInfo &info 
    489523                                         ) 
    490524{ 
    491525 
    492   int minDirDepth = 6; 
    493   int axis; 
    494   float costRatio; 
    495          
    496   costRatio = BestCostRatio(leaf, 
    497                                                         axis, 
    498                                                         position, 
    499                                                         raysBack, 
    500                                                         raysFront, 
    501                                                         pvsBack, 
    502                                                         pvsFront 
    503                                                         ); 
     526  BestCostRatio(leaf, 
     527                                info); 
     528   
    504529#if DEBUG_SPLIT_COST 
    505   cout<<axis<<" r="<<costRatio<<endl; 
     530  Debug<<"Split Info:"<<endl; 
     531  Debug<<"axis="<<info.axis<<" ratio="<<info.costRatio<<endl; 
     532  Debug<<"viewcells="<<info.viewCells<< 
     533        " viewcells back="<<info.viewCellsBack<< 
     534        " viewcells back="<<info.viewCellsFront<<endl; 
    506535#endif 
    507   if (costRatio > termMaxCostRatio) { 
     536   
     537  if (info.costRatio > termMaxCostRatio) { 
    508538        //              cout<<"Too big cost ratio "<<costRatio<<endl; 
    509539        stat.maxCostRatioNodes++; 
     
    516546        " rays="<<leaf->rays.size()<< 
    517547        " rc="<<leaf->GetAvgRayContribution()<< 
    518         " axis="<<axis<<endl; 
     548        " axis="<<info.axis<<endl; 
    519549#endif 
    520          
    521   return axis; 
    522 } 
    523  
    524  
    525 float 
     550   
     551  return info.axis; 
     552} 
     553 
     554 
     555void 
    526556RssTree::GetCostRatio( 
    527557                                          RssTreeLeaf *leaf, 
    528                                           const int axis, 
    529                                           const float position, 
    530                                           const int raysBack, 
    531                                           const int raysFront, 
    532                                           const int pvsBack, 
    533                                           const int pvsFront 
     558                                          SplitInfo &info 
    534559                                          ) 
    535560{ 
    536   bool costImportance = true; 
    537  
    538   float ratio; 
     561 
    539562  AxisAlignedBox3 box; 
    540563  float minBox, maxBox; 
    541564 
    542   if (axis < 3) { 
     565  if (info.axis < 3) { 
    543566        box = GetBBox(leaf); 
    544         minBox = box.Min(axis); 
    545         maxBox = box.Max(axis); 
     567        minBox = box.Min(info.axis); 
     568        maxBox = box.Max(info.axis); 
    546569  }     else { 
    547570        box = GetDirBBox(leaf); 
    548         minBox = box.Min(axis-3); 
    549         maxBox = box.Max(axis-3); 
     571        minBox = box.Min(info.axis-3); 
     572        maxBox = box.Max(info.axis-3); 
    550573  } 
    551574         
     
    554577  int pvsSize = leaf->GetPvsSize(); 
    555578 
    556   if (!costImportance) { 
    557         //              float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 
    558         float sum = pvsBack*(position - minBox) + pvsFront*(maxBox - position); 
    559         float newCost = ct_div_ci + sum/sizeBox; 
    560         float oldCost = pvsSize; 
    561         ratio = newCost/oldCost; 
     579  if (!mImportanceBasedCost) { 
     580        const int costMethod = 0; 
     581         
     582        switch (costMethod) { 
     583        case 0: { 
     584          //            float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 
     585          float sum = info.pvsBack*(info.position - minBox) + info.pvsFront*(maxBox - info.position); 
     586          float newCost = ct_div_ci + sum/sizeBox; 
     587          float oldCost = pvsSize; 
     588          info.costRatio = newCost/oldCost; 
     589          break; 
     590        } 
     591        case 1: { 
     592          float newContrib = 
     593                info.contributionBack/(info.position - minBox) +  
     594                + 
     595                info.contributionFront/(maxBox - info.position); 
     596          float oldContrib = info.contribution/sizeBox; 
     597          info.costRatio = oldContrib/newContrib; 
     598          break; 
     599        }  
     600        case 2: { 
     601          float sum = 
     602                info.viewCellsBack*(info.position - minBox) + 
     603                info.viewCellsFront*(maxBox - info.position); 
     604          float newCost = ct_div_ci + sum/sizeBox; 
     605          float oldCost = info.viewCells; 
     606          info.costRatio = newCost/oldCost; 
     607          break; 
     608        } 
     609        case 3: { 
     610          float newCost = info.raysBack*info.pvsBack  + info.raysFront*info.pvsFront; 
     611          float oldCost = leaf->rays.size()*pvsSize; 
     612          info.costRatio = newCost/oldCost; 
     613        } 
     614        } 
    562615  } else { 
     616        const int costMethod = 1; 
    563617        // importance based cost 
    564 #if 0 
    565         float newContrib = 
    566           ((position - minBox)*sqr(pvsBack/(raysBack + Limits::Small)) + 
    567            (maxBox - position)*sqr(pvsFront/(raysFront + Limits::Small)))/sizeBox; 
    568                  
    569         //                      float newContrib = 
    570         //                              sqr(pvsBack/(raysBack + Limits::Small)) + 
    571         //                              sqr(pvsFront/(raysFront + Limits::Small)); 
    572         float oldContrib = sqr(leaf->GetAvgRayContribution()); 
    573         ratio = oldContrib/newContrib; 
    574 #else 
    575 #if 1 
    576         float newCost = raysBack*pvsBack  + raysFront*pvsFront; 
    577         float oldCost = leaf->rays.size()*pvsSize; 
    578         ratio = newCost/oldCost; 
    579 #else 
    580 #if 0 
    581         float newCost = (pvsBack  + pvsFront)*0.5f; 
    582         float oldCost = pvsSize; 
    583         ratio = newCost/oldCost; 
    584 #else 
    585         float newCost = abs(raysBack  - raysFront); 
    586         float oldCost = leaf->rays.size(); 
    587         ratio = newCost/oldCost; 
    588 #endif 
    589 #endif 
    590 #endif 
    591   } 
    592          
    593   return ratio; 
     618        switch (costMethod) { 
     619        case 0: { 
     620          break; 
     621        } 
     622        case 1: { 
     623          float newContrib = 
     624                sqr(info.pvsBack/(info.raysBack + Limits::Small)) + 
     625                sqr(info.pvsFront/(info.raysFront + Limits::Small)); 
     626          float oldContrib = sqr(leaf->GetAvgRayContribution()); 
     627          info.costRatio = oldContrib/newContrib; 
     628          break; 
     629        } 
     630        case 2: { 
     631          float newCost = (info.pvsBack  + info.pvsFront)*0.5f; 
     632          float oldCost = pvsSize; 
     633          info.costRatio = newCost/oldCost; 
     634          break; 
     635        } 
     636        case 3: { 
     637          float newCost = abs(info.raysBack  - info.raysFront); 
     638          float oldCost = leaf->rays.size(); 
     639          info.costRatio = newCost/oldCost; 
     640          break; 
     641        } 
     642  } 
     643  } 
    594644} 
    595645                                                         
    596646 
    597 float 
     647void 
    598648RssTree::EvalCostRatio( 
    599649                                           RssTreeLeaf *leaf, 
    600                                            const int axis, 
    601                                            const float position, 
    602                                            int &raysBack, 
    603                                            int &raysFront, 
    604                                            int &pvsBack, 
    605                                            int &pvsFront 
     650                                           SplitInfo &info 
    606651                                           ) 
    607652{ 
    608   raysBack = 0; 
    609   raysFront = 0; 
    610   pvsFront = 0; 
    611   pvsBack = 0; 
    612  
    613          
     653  info.raysBack = 0; 
     654  info.raysFront = 0; 
     655  info.pvsFront = 0; 
     656  info.pvsBack = 0; 
     657  info.viewCells = 0; 
     658  info.viewCellsFront = 0; 
     659  info.viewCellsBack = 0; 
     660 
     661 
     662  float sumWeights = Limits::Small; 
     663  float sumWeightsBack = Limits::Small; 
     664  float sumWeightsFront = Limits::Small; 
     665   
     666  float sumContribution = 0.0f; 
     667  float sumContributionBack = 0.0f; 
     668  float sumContributionFront = 0.0f; 
     669 
     670  Intersectable::NewMail(); 
     671 
     672  // count the numebr of viewcells first 
     673  for(RssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 
     674          ri != leaf->rays.end(); 
     675          ri++) 
     676        if ((*ri).mRay->IsActive()) { 
     677          ViewCellContainer::const_iterator it = (*ri).mRay->mViewCells.begin(); 
     678          for (; it != (*ri).mRay->mViewCells.end(); ++it) { 
     679                if (!(*it)->Mailed()) { 
     680                  (*it)->Mail(); 
     681                  info.viewCells++; 
     682                } 
     683          } 
     684        } 
     685   
    614686  Intersectable::NewMail(3); 
    615          
    616   if (axis <= RssTreeNode::SPLIT_Z) { 
    617     // this is the main ray classification loop! 
    618     for(RssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 
    619                 ri != leaf->rays.end(); 
    620                 ri++) 
    621       if ((*ri).mRay->IsActive()) { 
    622                                  
    623                 // determine the side of this ray with respect to the plane 
    624                 int side = (*ri).ComputeRaySide(axis, position); 
    625                 //                              (*ri).mRay->mSide = side; 
    626                                  
    627                 if (side <= 0) 
    628                   raysBack++; 
    629                                  
    630                 if (side >= 0) 
    631                   raysFront++; 
    632                                  
    633                 AddObject2Pvs((*ri).mRay->mTerminationObject, side, pvsBack, pvsFront); 
    634       } 
    635                  
    636   } else { 
    637                  
    638         // directional split 
    639     for(RssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 
    640                 ri != leaf->rays.end(); 
    641                 ri++) 
    642       if ((*ri).mRay->IsActive()) { 
    643                                  
    644                 // determine the side of this ray with respect to the plane 
    645                 int side; 
    646                 if ((*ri).mRay->GetDirParametrization(axis - 3) <= position) 
    647                   side = -1; 
    648                 else 
    649                   side = 1; 
    650                  
    651                 if (side <= 0) 
    652                   raysBack++; 
    653                                  
    654                 if (side >= 0) 
    655                   raysFront++; 
    656  
    657                 //                              (*ri).mRay->mSide = side; 
    658                 AddObject2Pvs((*ri).mRay->mTerminationObject, side, pvsBack, pvsFront); 
    659                                  
    660       } 
    661   } 
    662  
    663   float ratio = GetCostRatio( 
    664                                                          leaf, 
    665                                                          axis, 
    666                                                          position, 
    667                                                          raysBack, 
    668                                                          raysFront, 
    669                                                          pvsBack, 
    670                                                          pvsFront); 
    671  
     687   
     688  // this is the main ray classification loop! 
     689  for(RssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 
     690          ri != leaf->rays.end(); 
     691          ri++) 
     692        if ((*ri).mRay->IsActive()) { 
     693          int side; 
     694           
     695           
     696          // determine the side of this ray with respect to the plane 
     697          side = (*ri).ComputeRaySide(info.axis, info.position); 
     698           
     699          float weight, contribution; 
     700           
     701          GetRayContribution(*ri, weight, contribution); 
     702          sumWeights += weight; 
     703          sumContribution += contribution; 
     704           
     705          if (side <= 0) { 
     706                info.raysBack++; 
     707                sumWeightsBack += weight; 
     708                sumContributionBack += contribution; 
     709          } 
     710           
     711          if (side >= 0) { 
     712                info.raysFront++; 
     713                sumWeightsFront += weight; 
     714                sumContributionFront += contribution; 
     715          } 
     716           
     717          AddObject2Pvs((*ri).GetObject(), side, info.pvsBack, info.pvsFront); 
     718          AddViewcells2Pvs((*ri).mRay->mViewCells, 
     719                                           side, 
     720                                           info.viewCellsBack, 
     721                                           info.viewCellsFront); 
     722        } 
     723 
     724  info.contribution = sumContribution/sumWeights; 
     725  info.contributionBack = sumContributionBack/sumWeightsBack; 
     726  info.contributionFront = sumContributionFront/sumWeightsFront; 
     727   
     728  GetCostRatio( 
     729                           leaf, 
     730                           info); 
     731   
    672732  //    cout<<axis<<" "<<pvsSize<<" "<<pvsBack<<" "<<pvsFront<<endl; 
    673733  //  float oldCost = leaf->rays.size(); 
    674  
     734   
    675735  //    cout<<"ratio="<<ratio<<endl; 
    676  
    677   return ratio; 
    678 } 
    679  
    680 float 
     736} 
     737 
     738void 
    681739RssTree::BestCostRatio( 
    682740                                           RssTreeLeaf *leaf, 
    683                                            int &axis, 
    684                                            float &position, 
    685                                            int &raysBack, 
    686                                            int &raysFront, 
    687                                            int &pvsBack, 
    688                                            int &pvsFront 
     741                                           SplitInfo &info 
    689742                                           ) 
    690743{ 
    691   int nRaysBack[6], nRaysFront[6]; 
    692   int nPvsBack[6], nPvsFront[6]; 
    693   float nPosition[6]; 
    694   float nCostRatio[6]; 
     744  SplitInfo nInfo[5]; 
    695745  int bestAxis = -1; 
    696          
     746   
    697747  AxisAlignedBox3 sBox = GetBBox(leaf); 
    698748  AxisAlignedBox3 dBox = GetDirBBox(leaf); 
     
    700750  int sAxis = sBox.Size().DrivingAxis(); 
    701751  int dAxis = dBox.Size().DrivingAxis() + 3; 
    702  
    703  
     752   
    704753  float dirSplitBoxSize = 0.01f; 
    705754  bool allowDirSplit = Magnitude(sBox.Size())*dirSplitBoxSize < Magnitude(bbox.Size()); 
    706755                 
    707756   
    708   for (axis = 0; axis < 5; axis++) 
     757  for (int axis = 0; axis < 5; axis++) 
    709758        if ( 
    710759                (axis < 3 && (leaf->depth < mDirSplitDepth ||  mInterleaveDirSplits)) || 
    711760                (axis >= 3 && (leaf->depth >= mDirSplitDepth)) 
    712761                ) { 
     762          nInfo[axis].axis = axis; 
    713763          if (!mSplitUseOnlyDrivingAxis || axis == sAxis || axis == dAxis) { 
    714764                 
    715765                if (splitType == ESplitRegular) { 
    716766                  if (axis < 3) 
    717                         nPosition[axis] = (sBox.Min()[axis] + sBox.Max()[axis])*0.5f; 
     767                        nInfo[axis].position = (sBox.Min()[axis] + sBox.Max()[axis])*0.5f; 
    718768                  else 
    719                         nPosition[axis] = (dBox.Min()[axis-3] + dBox.Max()[axis-3])*0.5f; 
    720                    
    721                   nCostRatio[axis] = EvalCostRatio(leaf, 
    722                                                                                    axis, 
    723                                                                                    nPosition[axis], 
    724                                                                                    nRaysBack[axis], 
    725                                                                                    nRaysFront[axis], 
    726                                                                                    nPvsBack[axis], 
    727                                                                                    nPvsFront[axis] 
    728                                                                                    ); 
     769                        nInfo[axis].position = (dBox.Min()[axis-3] + dBox.Max()[axis-3])*0.5f; 
     770                  EvalCostRatio(leaf, 
     771                                                nInfo[axis]); 
    729772                } else 
    730773                  if (splitType == ESplitHeuristic) { 
    731                         nCostRatio[axis] = EvalCostRatioHeuristic( 
    732                                                                                                           leaf, 
    733                                                                                                           axis, 
    734                                                                                                           nPosition[axis], 
    735                                                                                                           nRaysBack[axis], 
    736                                                                                                           nRaysFront[axis], 
    737                                                                                                           nPvsBack[axis], 
    738                                                                                                           nPvsFront[axis]); 
     774                        EvalCostRatioHeuristic( 
     775                                                                   leaf, 
     776                                                                   nInfo[axis] 
     777                                                                   ); 
    739778                  } else 
    740779                        if (splitType == ESplitHybrid) { 
    741780                          if (leaf->depth > 7) 
    742                                 nCostRatio[axis] = EvalCostRatioHeuristic( 
    743                                                                                                                   leaf, 
    744                                                                                                                   axis, 
    745                                                                                                                   nPosition[axis], 
    746                                                                                                                   nRaysBack[axis], 
    747                                                                                                                   nRaysFront[axis], 
    748                                                                                                                   nPvsBack[axis], 
    749                                                                                                                   nPvsFront[axis]); 
     781                                EvalCostRatioHeuristic( 
     782                                                                           leaf, 
     783                                                                           nInfo[axis] 
     784                                                                           ); 
    750785                          else { 
    751786                                if (axis < 3) 
    752                                   nPosition[axis] = (sBox.Min()[axis] + sBox.Max()[axis])*0.5f; 
     787                                  nInfo[axis].position = (sBox.Min()[axis] + sBox.Max()[axis])*0.5f; 
    753788                                else 
    754                                   nPosition[axis] = (dBox.Min()[axis-3] + dBox.Max()[axis-3])*0.5f; 
     789                                  nInfo[axis].position = (dBox.Min()[axis-3] + dBox.Max()[axis-3])*0.5f; 
    755790                                 
    756                                 nCostRatio[axis] = EvalCostRatio(leaf, 
    757                                                                                                  axis, 
    758                                                                                                  nPosition[axis], 
    759                                                                                                  nRaysBack[axis], 
    760                                                                                                  nRaysFront[axis], 
    761                                                                                                  nPvsBack[axis], 
    762                                                                                                  nPvsFront[axis] 
    763                                                                                                  ); 
     791                                EvalCostRatio(leaf, 
     792                                                          nInfo[axis] 
     793                                                          ); 
    764794                          } 
    765795                        } else { 
     
    768798                        } 
    769799                 
    770                  
    771800                if ( bestAxis == -1) 
    772801                  bestAxis = axis; 
    773802                else 
    774                   if ( nCostRatio[axis] < nCostRatio[bestAxis] ) 
     803                  if ( nInfo[axis].costRatio < nInfo[bestAxis].costRatio ) 
    775804                        bestAxis = axis; 
    776805          } 
    777806        } 
    778807   
    779   axis = bestAxis; 
    780   position = nPosition[bestAxis]; 
    781  
    782   raysBack = nRaysBack[bestAxis]; 
    783   raysFront = nRaysFront[bestAxis]; 
    784  
    785   pvsBack = nPvsBack[bestAxis]; 
    786   pvsFront = nPvsFront[bestAxis]; 
    787          
    788   return nCostRatio[bestAxis]; 
    789 } 
    790  
    791          
    792 float 
     808  info = nInfo[bestAxis]; 
     809} 
     810 
     811         
     812void 
    793813RssTree::EvalCostRatioHeuristic( 
    794814                                                                RssTreeLeaf *leaf, 
    795                                                                 const int axis, 
    796                                                                 float &bestPosition, 
    797                                                                 int &raysBack, 
    798                                                                 int &raysFront, 
    799                                                                 int &pvsBack, 
    800                                                                 int &pvsFront 
     815                                                                SplitInfo &info 
    801816                                                                ) 
    802817{ 
     
    804819  float minBox, maxBox; 
    805820         
    806   if (axis < 3) { 
     821  if (info.axis < 3) { 
    807822        box = GetBBox(leaf); 
    808         minBox = box.Min(axis); 
    809         maxBox = box.Max(axis); 
     823        minBox = box.Min(info.axis); 
     824        maxBox = box.Max(info.axis); 
    810825  } else { 
    811826        box = GetDirBBox(leaf); 
    812         minBox = box.Min(axis-3); 
    813         maxBox = box.Max(axis-3); 
    814   } 
    815          
    816   SortSplitCandidates(leaf, axis); 
     827        minBox = box.Min(info.axis-3); 
     828        maxBox = box.Max(info.axis-3); 
     829  } 
     830         
     831  SortSplitCandidates(leaf, info.axis); 
    817832   
    818833  // go through the lists, count the number of objects left and right 
    819834  // and evaluate the following cost funcion: 
    820835  // C = ct_div_ci  + (ql*rl + qr*rr)/queries 
    821          
    822   int rl=0, rr = leaf->rays.size(); 
    823   int pl=0, pr = leaf->GetPvsSize(); 
     836   
     837  SplitInfo currInfo; 
     838  currInfo.axis = info.axis; 
     839 
     840  currInfo.raysBack = 0; 
     841  currInfo.raysFront = leaf->rays.size(); 
     842   
     843  currInfo.pvsBack = 0; 
     844  currInfo.pvsFront = leaf->GetPvsSize(); 
     845 
     846  
    824847  float sizeBox = maxBox - minBox; 
    825          
     848   
    826849  float minBand = minBox + 0.1f*(maxBox - minBox); 
    827850  float maxBand = minBox + 0.9f*(maxBox - minBox); 
    828851         
    829   float minRatio = 1e20f; 
    830          
     852  // best cost ratio 
     853  info.costRatio = 1e20f; 
     854 
     855  currInfo.viewCells = 0; 
     856 
    831857  Intersectable::NewMail(); 
    832858  // set all object as belonging to the fron pvs 
     
    835861          ri++) 
    836862        if ((*ri).mRay->IsActive()) { 
    837           Intersectable *object = (*ri).mRay->mTerminationObject; 
     863          Intersectable *object = (*ri).GetObject(); 
    838864          if (object) 
    839865                if (!object->Mailed()) { 
     
    842868                } else 
    843869                  object->mCounter++; 
    844         } 
    845          
     870           
     871          // and do the same for all viewcells 
     872          ViewCellContainer::const_iterator it = (*ri).mRay->mViewCells.begin(); 
     873           
     874          for (; it != (*ri).mRay->mViewCells.end(); ++it) { 
     875                ViewCell *viewcell = *it; 
     876                if (!viewcell->Mailed()) { 
     877                  currInfo.viewCells++; 
     878                  viewcell->Mail(); 
     879                  viewcell->mCounter = 1; 
     880                } else 
     881                  viewcell->mCounter++; 
     882          } 
     883        } 
     884 
     885  currInfo.viewCellsBack = 0; 
     886  currInfo.viewCellsFront = currInfo.viewCells; 
     887  
    846888  Intersectable::NewMail(); 
    847889         
     
    849891          ci < splitCandidates->end(); 
    850892          ci++) { 
    851         VssRay *ray; 
    852893        switch ((*ci).type) { 
    853894        case SortableEntry::ERayMin: { 
    854           rr--; 
    855           rl++; 
    856           ray = (VssRay *) (*ci).data; 
    857           Intersectable *object = ray->mTerminationObject; 
     895          currInfo.raysFront--; 
     896          currInfo.raysBack++; 
     897          RssTreeNode::RayInfo *rayInfo = (RssTreeNode::RayInfo *) (*ci).data; 
     898          Intersectable *object = rayInfo->GetObject(); 
    858899          if (object) { 
    859900                if (!object->Mailed()) { 
    860901                  object->Mail(); 
    861                   pl++; 
     902                  currInfo.pvsBack++; 
    862903                } 
    863904                if (--object->mCounter == 0) 
    864                   pr--; 
     905                  currInfo.pvsFront--; 
     906          } 
     907          ViewCellContainer::const_iterator it = rayInfo->mRay->mViewCells.begin(); 
     908          for (; it != rayInfo->mRay->mViewCells.end(); ++it) { 
     909                ViewCell *viewcell = *it; 
     910                if (!viewcell->Mailed()) { 
     911                  viewcell->Mail(); 
     912                  currInfo.viewCellsBack++; 
     913                } 
     914                if (--viewcell->mCounter == 0) 
     915                  currInfo.viewCellsFront--; 
    865916          } 
    866917          break; 
     
    871922         
    872923        if (position > minBand && position < maxBand) { 
    873                          
    874           float ratio = GetCostRatio( 
    875                                                                  leaf, 
    876                                                                  axis, 
    877                                                                  position, 
    878                                                                  rl, 
    879                                                                  rr, 
    880                                                                  pl, 
    881                                                                  pr); 
    882                          
     924          currInfo.position = position; 
     925           
     926          GetCostRatio( 
     927                                   leaf, 
     928                                   currInfo); 
     929           
    883930                         
    884931          //      cout<<"pos="<<(*ci).value<<"\t q=("<<ql<<","<<qr<<")\t r=("<<rl<<","<<rr<<")"<<endl; 
    885932          //      cout<<"cost= "<<sum<<endl; 
    886                          
    887           if (ratio < minRatio) { 
    888                 minRatio = ratio; 
    889                 bestPosition = position; 
    890                                  
    891                 raysBack = rl; 
    892                 raysFront = rr; 
    893                                  
    894                 pvsBack = pl; 
    895                 pvsFront = pr; 
    896                                  
     933           
     934          if (currInfo.costRatio < info.costRatio) { 
     935                info = currInfo; 
    897936      } 
    898937    } 
    899938  } 
    900  
     939   
    901940   
    902941  //  cout<<"===================="<<endl; 
    903942  //  cout<<"costRatio="<<ratio<<" pos="<<position<<" t="<<(position - minBox)/(maxBox - minBox) 
    904943  //      <<"\t q=("<<queriesBack<<","<<queriesFront<<")\t r=("<<raysBack<<","<<raysFront<<")"<<endl; 
    905   return minRatio; 
    906944} 
    907945 
     
    933971          if (axis < 3) { 
    934972                splitCandidates->push_back(SortableEntry(SortableEntry::ERayMin, 
    935                                                                                                  (*ri).ExtrapOrigin(axis), 
    936                                                                                                  (void *)(*ri).mRay) 
     973                                                                                                 (*ri).GetOrigin(axis), 
     974                                                                                                 (void *)&(*ri)) 
    937975                                                                   ); 
    938976          } else { 
    939                 float pos = (*ri).mRay->GetDirParametrization(axis-3); 
     977                float pos = (*ri).GetDirParametrization(axis-3); 
    940978                splitCandidates->push_back(SortableEntry(SortableEntry::ERayMin, 
    941979                                                                                                 pos, 
    942                                                                                                  (void *)(*ri).mRay) 
     980                                                                                                 (void *)&(*ri)) 
    943981                                                                   ); 
    944982          } 
     
    10121050  } 
    10131051         
    1014   float position; 
    1015          
    1016   // first count ray sides 
    1017   int raysBack; 
    1018   int raysFront; 
    1019   int pvsBack; 
    1020   int pvsFront; 
     1052  SplitInfo info; 
    10211053         
    10221054  // select subdivision axis 
    1023   int axis = SelectPlane( leaf, box, position, raysBack, raysFront, pvsBack, pvsFront); 
    1024   Debug<<"axis="<<axis<<" depth="<<(int)leaf->depth<<" rb="<<raysBack<<" rf="<<raysFront<<" pvsb="<<pvsBack<<" pvsf="<<pvsFront<<endl; 
     1055  int axis = SelectPlane( leaf, 
     1056                                                  box, 
     1057                                                  info 
     1058                                                  ); 
     1059  //  Debug<<"axis="<<axis<<" depth="<<(int)leaf->depth<<" rb="<<raysBack<<" rf="<<raysFront<<" pvsb="<<pvsBack<<" pvsf="<<pvsFront<<endl; 
    10251060   
    10261061  if (axis == -1) { 
     
    10351070 
    10361071  node->axis = axis; 
    1037   node->position = position; 
     1072  node->position = info.position; 
    10381073  node->bbox = box; 
    10391074  node->dirBBox = GetDirBBox(leaf); 
     
    10411076  backBBox = box; 
    10421077  frontBBox = box; 
    1043  
    1044   RssTreeLeaf *back = new RssTreeLeaf(node, raysBack); 
    1045   RssTreeLeaf *front = new RssTreeLeaf(node, raysFront); 
    1046  
     1078   
     1079  RssTreeLeaf *back = new RssTreeLeaf(node, info.raysBack); 
     1080  RssTreeLeaf *front = new RssTreeLeaf(node, info.raysFront); 
     1081 
     1082  // update halton generator 
     1083  back->halton.index = leaf->halton.index; 
     1084  front->halton.index = leaf->halton.index; 
     1085   
    10471086  // replace a link from node's parent 
    10481087  if (  leaf->parent ) 
     
    10521091         
    10531092  if (axis <= RssTreeNode::SPLIT_Z) { 
    1054         backBBox.SetMax(axis, position); 
    1055     frontBBox.SetMin(axis, position); 
    1056                  
    1057         for(RssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 
    1058                 ri != leaf->rays.end(); 
    1059                 ri++) { 
    1060       if ((*ri).mRay->IsActive()) { 
    1061                                  
    1062                 // first unref ray from the former leaf 
    1063                 (*ri).mRay->Unref(); 
    1064  
    1065                 // Debug << "computed t: " << (*ri).mRay->mT << endl; 
    1066                 // determine the side of this ray with respect to the plane 
    1067                 int side = node->ComputeRaySide(*ri); 
    1068                  
    1069                 if (side == 0) { 
    1070                   if ((*ri).mRay->HasPosDir(axis)) { 
    1071                         back->AddRay(*ri); 
    1072                         front->AddRay(*ri); 
    1073                   } else { 
    1074                         back->AddRay(*ri); 
    1075                         front->AddRay(*ri); 
    1076                   } 
    1077                 } else 
    1078                   if (side == 1)  
    1079                         front->AddRay(*ri); 
    1080                   else 
    1081                         back->AddRay(*ri); 
    1082       } else 
    1083                 (*ri).mRay->Unref(); 
    1084     } 
    1085   } else { 
    1086     // rays front/back 
    1087      
    1088      
    1089     for(RssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 
    1090                 ri != leaf->rays.end(); 
    1091                 ri++) { 
    1092       if ((*ri).mRay->IsActive()) { 
    1093                 // first unref ray from the former leaf 
    1094                 (*ri).mRay->Unref(); 
    1095  
    1096                 int side; 
    1097                 if ((*ri).mRay->GetDirParametrization(axis - 3) <= position) 
    1098                   side = -1; 
    1099                 else 
    1100                   side = 1; 
    1101                                  
    1102                 if (side == 1) 
    1103                   front->AddRay(*ri); 
    1104                 else 
    1105                   back->AddRay(*ri); 
    1106                                  
    1107       } else 
    1108                 (*ri).mRay->Unref(); 
    1109     } 
    1110   } 
    1111  
     1093        backBBox.SetMax(axis, info.position); 
     1094    frontBBox.SetMin(axis, info.position); 
     1095  } 
     1096 
     1097  for(RssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 
     1098          ri != leaf->rays.end(); 
     1099          ri++) { 
     1100        if ((*ri).mRay->IsActive()) { 
     1101           
     1102          // first unref ray from the former leaf 
     1103          (*ri).mRay->Unref(); 
     1104           
     1105          // Debug << "computed t: " << (*ri).mRay->mT << endl; 
     1106          // determine the side of this ray with respect to the plane 
     1107          int side = node->ComputeRaySide(*ri); 
     1108           
     1109          if (side == 1)  
     1110                front->AddRay(*ri); 
     1111          else 
     1112                back->AddRay(*ri); 
     1113        } else 
     1114          (*ri).mRay->Unref(); 
     1115  } 
     1116 
     1117  // distribute the total number of rays according to the distribution 
     1118  // of rays which remained 
     1119   
     1120   
     1121  //  front->mTotalRays = front->rays.size()*leaf->mTotalRays/leaf->rays.size(); 
     1122  //  back->mTotalRays = back->rays.size()*leaf->mTotalRays/leaf->rays.size(); 
     1123   
    11121124#if 0 
    11131125  front->SetPvsSize(pvsFront); 
     
    11171129  back->ComputeEntropyImportance(); 
    11181130#else 
    1119   front->UpdatePvsSize(); 
    1120   back->UpdatePvsSize(); 
     1131  UpdatePvsSize(front); 
     1132  UpdatePvsSize(back); 
    11211133#endif 
    11221134 
     
    11241136  // update stats 
    11251137  stat.rayRefs -= (int)leaf->rays.size(); 
    1126   stat.rayRefs += raysBack + raysFront; 
     1138  stat.rayRefs += info.raysBack + info.raysFront; 
    11271139 
    11281140   
     
    12211233 
    12221234void 
    1223 RssTree::UpdateRays(VssRayContainer &remove, 
     1235RssTree::UpdateRays( 
     1236                                        VssRayContainer &remove, 
    12241237                                        VssRayContainer &add 
    12251238                                        ) 
     
    12571270          AddRay(info); 
    12581271  } 
    1259 } 
     1272 
     1273  stat.rayRefs += add.size() - remove.size(); 
     1274 
     1275  UpdateTreeStatistics(); 
     1276  // check whether the tree should be prunned 
     1277  if (stat.rayRefs > mMaxRays) { 
     1278        PruneRays(mMaxRays); 
     1279        //      UpdateTreeStatistics(); 
     1280  } 
     1281   
     1282} 
     1283 
     1284   
    12601285 
    12611286 
     
    13771402  RssTreeInterior *in =  (RssTreeInterior *) data.node; 
    13781403   
    1379   if (in->axis <= RssTreeNode::SPLIT_Z) { 
    1380  
    1381     // determine the side of this ray with respect to the plane 
    1382     int side = in->ComputeRaySide(data.rayData 
    1383                                                                   ); 
    1384      
    1385    
    1386     if (side == 0) { 
    1387       if (data.rayData.mRay->HasPosDir(in->axis)) { 
    1388                 tstack.push(RayTraversalData(in->back, 
    1389                                                                          data.rayData) 
    1390                                         ); 
    1391                                  
    1392                 tstack.push(RayTraversalData(in->front, 
    1393                                                                          data.rayData) 
    1394                                         ); 
    1395          
    1396       } else { 
    1397                 tstack.push(RayTraversalData(in->back, 
    1398                                                                          data.rayData 
    1399                                                                          ) 
    1400                                         ); 
    1401                                  
    1402                 tstack.push(RayTraversalData(in->front, 
    1403                                                                          data.rayData) 
    1404                                         ); 
    1405                                  
    1406                                  
    1407       } 
    1408     } else 
    1409       if (side == 1) 
    1410                 tstack.push(RayTraversalData(in->front, data.rayData)); 
    1411       else 
    1412                 tstack.push(RayTraversalData(in->back, data.rayData)); 
    1413   }  
    1414   else { 
    1415     // directional split 
    1416         if (data.rayData.mRay->GetDirParametrization(in->axis - 3) <= in->position) 
    1417           tstack.push(RayTraversalData(in->back, data.rayData)); 
    1418         else 
    1419           tstack.push(RayTraversalData(in->front, data.rayData)); 
    1420   } 
     1404  // determine the side of this ray with respect to the plane 
     1405  int side = in->ComputeRaySide(data.rayData 
     1406                                                                ); 
     1407   
     1408  if (side == 1) 
     1409        tstack.push(RayTraversalData(in->front, data.rayData)); 
     1410  else 
     1411        tstack.push(RayTraversalData(in->back, data.rayData)); 
     1412   
    14211413} 
    14221414 
     
    15591551                if ((*ri).mRay->IsActive()) { 
    15601552                  Intersectable *object; 
    1561 #if BIDIRECTIONAL_RAY 
    1562                   object = (*ri).mRay->mOriginObject; 
    1563                   if (object && !object->Mailed()) { 
    1564                         pvsSize++; 
    1565                         object->Mail(); 
    1566                   } 
    1567 #endif 
    1568                   object = (*ri).mRay->mTerminationObject; 
     1553                  object = (*ri).GetObject(); 
    15691554                  if (object && !object->Mailed()) { 
    15701555                        pvsSize++; 
     
    16121597                if ((*ri).mRay->IsActive()) { 
    16131598                  Intersectable *object; 
    1614                   object = (*ri).mRay->mTerminationObject; 
     1599                  object = (*ri).GetObject(); 
    16151600                  if (object && !object->Mailed()) { 
    16161601                        pvs.push_back(object); 
     
    16371622 
    16381623void 
    1639 RssTree::GetTreeStatistics( 
    1640                                                    float &avgPvsSize, 
    1641                                                    float &avgRays, 
    1642                                                    float &avgRayContribution, 
    1643                                                    float &avgPvsEntropy, 
    1644                                                    float &avgRayLengthEntropy, 
    1645                                                    float &avgImportance 
    1646                                                    ) 
     1624RssTree::UpdateTreeStatistics() 
    16471625{ 
    16481626  stack<RssTreeNode *> tstack; 
     
    16511629  float sumPvsSize = 0.0f; 
    16521630  float sumRayContribution = 0.0f; 
     1631  float sumWeightedRayContribution = 0.0f; 
    16531632  float sumImportance = 0.0f; 
    16541633  float sumPvsEntropy = 0.0f; 
     
    16651644          leaves++; 
    16661645          RssTreeLeaf *leaf = (RssTreeLeaf *)node; 
    1667           leaf->UpdatePvsSize(); 
     1646          UpdatePvsSize(leaf); 
    16681647           
    16691648          sumPvsSize += leaf->GetPvsSize(); 
    16701649          sumRayContribution += leaf->GetAvgRayContribution(); 
    1671           sumPvsEntropy += leaf->mPvsEntropy; 
    1672           sumRayLengthEntropy += leaf->mRayLengthEntropy; 
     1650           
     1651 
     1652          RssTreeNode::RayInfoContainer::const_iterator it = leaf->rays.begin(); 
     1653          for (;it != leaf->rays.end(); ++it) { 
     1654                float weight, contribution; 
     1655                GetRayContribution(*it, weight, contribution); 
     1656                sumWeightedRayContribution += weight*contribution; 
     1657          } 
     1658           
     1659          //      sumPvsEntropy += leaf->mPvsEntropy; 
     1660          //      sumRayLengthEntropy += leaf->mRayLengthEntropy; 
    16731661          sumRays += leaf->rays.size(); 
    16741662           
    16751663          float imp = leaf->GetImportance(); 
    16761664           
    1677           if (imp > 1.0f) 
    1678                 cout<<"warning imp > 1.0f:"<<imp<<endl; 
     1665          //      if (imp > 1.0f) 
     1666          //            cout<<"warning imp > 1.0f:"<<imp<<endl; 
    16791667           
    16801668          sumImportance += imp; 
     
    16891677  } 
    16901678   
    1691   avgPvsSize = sumPvsSize/(float)leaves; 
    1692   avgRays = sumRays/(float)leaves; 
    1693   avgRayContribution = sumRayContribution/(float)leaves; 
    1694   avgPvsEntropy = sumPvsEntropy/(float)leaves; 
    1695   avgRayLengthEntropy = sumRayLengthEntropy/(float)leaves; 
    1696   avgImportance = sumImportance/(float)leaves; 
    1697 } 
     1679  stat.avgPvsSize = sumPvsSize/(float)leaves; 
     1680  stat.avgRays = sumRays/(float)leaves; 
     1681  stat.avgRayContribution = sumRayContribution/(float)leaves; 
     1682  //  avgPvsEntropy = sumPvsEntropy/(float)leaves; 
     1683  //  avgRayLengthEntropy = sumRayLengthEntropy/(float)leaves; 
     1684  stat.avgImportance = sumImportance/(float)leaves; 
     1685  stat.avgWeightedRayContribution = sumWeightedRayContribution/(float)sumRays; 
     1686  stat.rayRefs = (int)sumRays; 
     1687} 
     1688 
    16981689 
    16991690 
    17001691int 
    1701 RssTree::GenerateRays(const float ratioPerLeaf, 
     1692RssTree::GenerateRays( 
     1693                                          const float ratioPerLeaf, 
    17021694                                          SimpleRayContainer &rays) 
    17031695{ 
     
    17771769        return; 
    17781770  } 
    1779    
     1771 
     1772#if 1 
    17801773  int tries = min(20, nrays); 
    17811774 
     
    17831776        r1 = Random(nrays); 
    17841777        r2 = Random(nrays); 
    1785         if (leaf->rays[r1].mRay->mTerminationObject != leaf->rays[r2].mRay->mTerminationObject) 
     1778        if (leaf->rays[r1].GetObject() != leaf->rays[r2].GetObject()) 
    17861779          break; 
    17871780  } 
     
    17891782  if (r1 == r2) 
    17901783        r2 = (r1+1)%leaf->rays.size(); 
    1791 } 
    1792  
     1784 
     1785#else 
     1786  // pick a random ray 
     1787  int base = Random(nrays); 
     1788  RssTreeNode::RayInfo *baseRay = &leaf->rays[base]; 
     1789  Intersectable *baseObject = baseRay->GetObject(); 
     1790   
     1791  // and a random 5D derivative which will be used to find the minimal projected distances 
     1792  Vector3 spatialDerivative; 
     1793  Vector3 directionalDerivative; 
     1794 
     1795  while (1) { 
     1796        spatialDerivative = Vector3(RandomValue(-1.0f, 1.0f), 
     1797                                                                RandomValue(-1.0f, 1.0f), 
     1798                                                                RandomValue(-1.0f, 1.0f)); 
     1799        float m = Magnitude(spatialDerivative); 
     1800        if (m != 0) { 
     1801          spatialDerivative /= m*Magnitude(GetBBox(leaf).Size()); 
     1802          break; 
     1803        } 
     1804  } 
     1805 
     1806  while (1) { 
     1807        directionalDerivative = Vector3(RandomValue(-1.0f, 1.0f), 
     1808                                                                        RandomValue(-1.0f, 1.0f), 
     1809                                                                        0.0f); 
     1810        float m = Magnitude(directionalDerivative); 
     1811        if (m != 0) { 
     1812          directionalDerivative /= m*Magnitude(GetDirBBox(leaf).Size()); 
     1813          break; 
     1814        } 
     1815  } 
     1816 
     1817  // now find the furthest sample from the same object and the closest from a different object 
     1818  int i = 0; 
     1819  float minDist = MAX_FLOAT; 
     1820  float maxDist = -MAX_FLOAT; 
     1821  r1 = base; 
     1822  r2 = base; 
     1823  for(RssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 
     1824          ri != leaf->rays.end(); 
     1825          ri++, i++) { 
     1826        float dist = RssTreeNode::RayInfo::SqrDistance5D(*baseRay, 
     1827                                                                                                         *ri, 
     1828                                                                                                         spatialDerivative, 
     1829                                                                                                         directionalDerivative 
     1830                                                                                                         ); 
     1831 
     1832        if ((*ri).GetObject() == baseObject) { 
     1833          if (dist > maxDist) { 
     1834                maxDist = dist; 
     1835                r1 = i; 
     1836          } 
     1837        } else { 
     1838          if (dist > 0.0f && dist < minDist) { 
     1839                minDist = dist; 
     1840                r2 = i; 
     1841          } 
     1842        } 
     1843  } 
     1844   
     1845#endif 
     1846} 
     1847 
     1848 
     1849struct RayNeighbor { 
     1850  int rayInfo; 
     1851  float distance; 
     1852  RayNeighbor():rayInfo(0), distance(MAX_FLOAT) {} 
     1853}; 
     1854 
     1855void 
     1856RssTree::FindSilhouetteRays(RssTreeLeaf *leaf, 
     1857                                                        vector<RssTreeLeaf::SilhouetteRays> &rays 
     1858                                                        ) 
     1859{ 
     1860  // for every leaf find its neares neighbor from a different object 
     1861  vector<RayNeighbor> neighbors(leaf->rays.size()); 
     1862  int i, j; 
     1863  for (i=0; i < leaf->rays.size(); i++) 
     1864        for (j=0; j < leaf->rays.size(); j++) 
     1865          if (i!=j) { 
     1866                float d = RssTreeLeaf::RayInfo::Distance(leaf->rays[i], leaf->rays[j]); 
     1867                if (d < neighbors[i].distance) { 
     1868                  neighbors[i].distance = d; 
     1869                  neighbors[i].rayInfo = j; 
     1870                } 
     1871          } 
     1872 
     1873  // now check which are the pairs of nearest neighbors 
     1874  for (i=0; i < leaf->rays.size(); i++) { 
     1875        int j = neighbors[i].rayInfo; 
     1876        if (neighbors[j].rayInfo == i) { 
     1877          // this is a silhouette edge pair 
     1878          if (i < j) { 
     1879                // generate an silhoutte ray pair 
     1880                rays.push_back(RssTreeLeaf::SilhouetteRays(&leaf->rays[i], 
     1881                                                                                                   &leaf->rays[j])); 
     1882          } 
     1883        } else { 
     1884          // this is not a silhouette ray - delete??? 
     1885        } 
     1886  } 
     1887   
     1888} 
     1889 
     1890 
     1891bool 
     1892GetRandomTripple(vector<RssTreeLeaf::RayInfo *> &rays, 
     1893                                 const int index, 
     1894                                 int &i1, 
     1895                                 int &i2, 
     1896                                 int &i3) 
     1897{ 
     1898  int found = 0; 
     1899  int indices[3]; 
     1900 
     1901  int size = rays.size(); 
     1902  // use russian roulete selection for the tripple 
     1903  // number of free positions for the bullet 
     1904  int positions = size - 1; 
     1905  int i; 
     1906  for (i=0; i < size; i++) { 
     1907        if (rays[i]->mRay->Mailed()) 
     1908          positions--; 
     1909  } 
     1910   
     1911  if (positions < 3) 
     1912        return false; 
     1913   
     1914  for (i=0; i < size; i++) { 
     1915        if (i != index && !rays[i]->mRay->Mailed()) { 
     1916          float p = (3 - found)/(float)positions; 
     1917          if (Random(1.0f) < p) { 
     1918                indices[found] = i; 
     1919                found++; 
     1920          } 
     1921        } 
     1922        positions--; 
     1923  } 
     1924} 
     1925 
     1926bool 
     1927RssTree::IsRayConvexCombination(const RssTreeNode::RayInfo &ray, 
     1928                                                                const RssTreeNode::RayInfo &r1, 
     1929                                                                const RssTreeNode::RayInfo &r2, 
     1930                                                                const RssTreeNode::RayInfo &r3) 
     1931{ 
     1932   
     1933 
     1934  return false; 
     1935} 
     1936 
     1937int 
     1938RssTree::RemoveInteriorRays( 
     1939                                                        RssTreeLeaf *leaf 
     1940                                                        ) 
     1941{ 
     1942#if 1 
     1943  // first collect all objects refered in this leaf 
     1944  map<Intersectable *, vector<RssTreeLeaf::RayInfo *> > rayMap; 
     1945   
     1946  RssTreeLeaf::RayInfoContainer::iterator it = leaf->rays.begin(); 
     1947  for (; it != leaf->rays.end(); ++it) { 
     1948        Intersectable *object = (*it).GetObject(); 
     1949         
     1950        rayMap[object].push_back(&(*it)); 
     1951//      vector<RayInfo *> *data = rayMap.Find(object); 
     1952//      if (data) { 
     1953//        data->push_back(&(*it)); 
     1954//      } else { 
     1955//        //      rayMap[object] = vector<RayInfo *>; 
     1956//        rayMap[object].push_back(&(*it)); 
     1957//      } 
     1958  } 
     1959 
     1960  // now go through all objects 
     1961  map<Intersectable *, vector<RssTreeLeaf::RayInfo *> >::iterator mi; 
     1962 
     1963  // infos of mailed rays are scheduled for removal 
     1964  VssRay::NewMail(); 
     1965  for (mi = rayMap.begin(); mi != rayMap.end(); ++ mi) { 
     1966        vector<RssTreeLeaf::RayInfo *> &rays = (*mi).second; 
     1967        vector<RssTreeLeaf::RayInfo *>::iterator ri = rays.begin(); 
     1968        int rayIndex = 0; 
     1969         
     1970        for (; ri != rays.end(); ++ri, ++rayIndex) { 
     1971          RssTreeNode::RayInfo *ray = *ri; 
     1972          int tries = rays.size(); 
     1973          for (int i = 0; i < tries; i++) { 
     1974                int r1, r2, r3; 
     1975                GetRandomTripple(rays, 
     1976                                                 rayIndex, 
     1977                                                 r1, 
     1978                                                 r2, 
     1979                                                 r3); 
     1980                if (IsRayConvexCombination(*ray, 
     1981                                                                   *rays[r1], 
     1982                                                                   *rays[r2], 
     1983                                                                   *rays[r3])) { 
     1984                  ray->mRay->Mail(); 
     1985                } 
     1986          } 
     1987        } 
     1988  } 
     1989   
     1990 
     1991#endif   
     1992        return 0; 
     1993} 
    17931994 
    17941995void 
     
    17981999{ 
    17992000 
     2001  if (numberOfRays == 0) 
     2002        return; 
     2003   
    18002004  int nrays = leaf->rays.size(); 
    1801   for (int i=0; i < numberOfRays; i++) { 
    1802         bool useExtendedConvexCombination = (nrays >= 2) && (i > numberOfRays/2); 
    1803  
    1804                  
     2005 
     2006 
     2007  AxisAlignedBox3 box = GetBBox(leaf); 
     2008  AxisAlignedBox3 dirBox = GetDirBBox(leaf); 
     2009 
     2010  AxisAlignedBox3 sBox(box); 
     2011  AxisAlignedBox3 sDirBox(dirBox); 
     2012  const float smoothRange = 0.5f; 
     2013  sBox.Scale(1.0f + smoothRange); 
     2014  sDirBox.Scale(1.0f + smoothRange); 
     2015  int smoothRays = (int)numberOfRays*0.0f; 
     2016   
     2017#if AVG_LEN 
     2018  float avgLength = 0.0f; 
     2019 
     2020  if (nrays) { 
     2021        const int numAvg = 5; 
     2022         
     2023        int step = (nrays-1)/10; 
     2024        if (step<1) 
     2025          step = 1; 
     2026         
     2027        int summed = 0; 
     2028        float sumLength = 0.0f; 
     2029        for (int i=0; i < nrays; i+=step) { 
     2030          sumLength += leaf->rays[i].mRay->GetSize(); 
     2031          summed++; 
     2032        } 
     2033   
     2034        avgLength = sumLength/summed; 
     2035  } 
     2036#endif 
     2037   
     2038  Exporter *exporter = NULL; 
     2039  VssRayContainer selectedRays; 
     2040  static int counter = 0; 
     2041  if (counter < 0) { 
     2042        char filename[128]; 
     2043        sprintf(filename, "selected-rays%04d.x3d", counter); 
     2044        exporter = Exporter::GetExporter(filename); 
     2045        //      exporter->SetWireframe(); 
     2046        //      exporter->ExportKdTree(*mKdTree); 
     2047        exporter->SetWireframe(); 
     2048        exporter->ExportScene(preprocessor->mSceneGraph->mRoot); 
     2049        exporter->SetWireframe(); 
     2050        exporter->ExportBox(box); 
     2051        exporter->SetFilled(); 
     2052        counter++; 
     2053  } 
     2054   
     2055  int numberOfTries = numberOfRays*4; 
     2056  int generated = 0; 
     2057 
     2058  Intersectable::NewMail(); 
     2059  vector<Intersectable *> pvs(0); 
     2060  pvs.reserve(leaf->GetPvsSize()); 
     2061  for(RssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 
     2062          ri != leaf->rays.end(); 
     2063          ri++) { 
     2064        Intersectable *object = (*ri).GetObject(); 
     2065        if (object && !object->Mailed()) { 
     2066          object->Mail(); 
     2067          pvs.push_back(object); 
     2068          if (exporter) 
     2069                exporter->ExportIntersectable(object); 
     2070        } 
     2071  } 
     2072   
     2073  for (int i=0; generated < numberOfRays && i < numberOfTries; i++) { 
     2074        bool useExtendedConvexCombination = ((nrays >= 2) && (Random(1.0f) < 0.7f)); 
     2075         
    18052076        Vector3 origin, direction; 
    18062077        // generate half of convex combination and half of random rays 
    18072078        if (useExtendedConvexCombination) { 
    1808           // pickup 3 random rays 
     2079          // pickup 2 random rays 
    18092080          int r1, r2; 
    18102081          PickEdgeRays(leaf, r1, r2); 
     2082 
    18112083           
    18122084          Vector3 o1 = leaf->rays[r1].GetOrigin(); 
    18132085          Vector3 o2 = leaf->rays[r2].GetOrigin(); 
    18142086           
    1815           const float overlap = 0.1f; 
     2087          const float overlap = 0.0f; 
    18162088          float w1, w2; 
    18172089          GenerateExtendedConvexCombinationWeights2(w1, w2, overlap); 
    18182090          origin = w1*o1 + w2*o2; 
     2091          GenerateExtendedConvexCombinationWeights2(w1, w2, overlap); 
    18192092          direction = 
    1820                 w1*leaf->rays[r1].mRay->GetDir() + 
    1821                 w2*leaf->rays[r2].mRay->GetDir(); 
    1822           // shift the origin a little bit 
    1823           origin += direction*0.1f; 
     2093                w1*leaf->rays[r1].GetDir() + 
     2094                w2*leaf->rays[r2].GetDir(); 
    18242095        } else { 
    1825           origin = GetBBox(leaf).GetRandomPoint(); 
    1826           Vector3 dirVector = GetDirBBox(leaf).GetRandomPoint(); 
     2096          Vector3 dirVector; 
     2097 
     2098          Vector3 pVector; 
     2099          Vector3 dVector; 
     2100 
     2101          bool useHalton = true; 
     2102           
     2103          if (useHalton) { 
     2104                // generate a random 5D vector 
     2105                pVector = Vector3(leaf->halton.GetNumber(1), 
     2106                                                  leaf->halton.GetNumber(2), 
     2107                                                  leaf->halton.GetNumber(3)); 
     2108                 
     2109                dVector = Vector3(leaf->halton.GetNumber(4), 
     2110                                                  leaf->halton.GetNumber(5), 
     2111                                                  0.0f); 
     2112                leaf->halton.GenerateNext(); 
     2113          } else { 
     2114                pVector = Vector3(RandomValue(0.0f, 1.0f), 
     2115                                                  RandomValue(0.0f, 1.0f), 
     2116                                                  RandomValue(0.0f, 1.0f)); 
     2117                 
     2118                dVector = Vector3(RandomValue(0.0f, 1.0f), 
     2119                                                  RandomValue(0.0f, 1.0f), 
     2120                                                  0.0f); 
     2121          } 
     2122           
     2123          if (i < smoothRays) { 
     2124                origin = sBox.GetPoint(pVector); 
     2125                dirVector = sDirBox.GetPoint(dVector); 
     2126          } else { 
     2127                origin = box.GetPoint(pVector); 
     2128                dirVector = dirBox.GetPoint(dVector); 
     2129          } 
    18272130          direction = Vector3(sin(dirVector.x), sin(dirVector.y), cos(dirVector.x)); 
    18282131        } 
    1829         //cout<<"dir vector.x="<<dirVector.x<<"direction'.x="<<atan2(direction.x, direction.y)<<endl; 
    1830         rays.push_back(SimpleRay(origin, direction)); 
    1831   } 
     2132 
     2133        // shift the origin a little bit 
     2134        direction.Normalize(); 
     2135         
     2136        //      float dist = Min(avgLength*0.5f, Magnitude(GetBBox(leaf).Size())); 
     2137        float dist = 0.0f; 
     2138        float minT, maxT; 
     2139        // compute interection of the ray with the box 
     2140 
     2141        if (box.ComputeMinMaxT(origin, direction, &minT, &maxT) && minT < maxT) 
     2142          dist = maxT; 
     2143   
     2144         
     2145        origin += direction*dist; 
     2146         
     2147        bool intersects = false; 
     2148         
     2149 
     2150        if (i > numberOfRays/2) { 
     2151          if (exporter) { 
     2152                VssRay *ray = new VssRay(origin, origin + 100*direction, NULL, NULL); 
     2153                selectedRays.push_back(ray); 
     2154          } 
     2155 
     2156          // check whether the ray does not intersect already visible objects 
     2157          Ray traversalRay; 
     2158          traversalRay.Init(origin, direction, Ray::LOCAL_RAY); 
     2159          for(vector<Intersectable *>::const_iterator oi = pvs.begin(); 
     2160                  oi != pvs.end(); 
     2161                  oi++) { 
     2162                Intersectable *object = *oi; 
     2163                 
     2164                if ( object->CastRay(traversalRay) ) { 
     2165                  intersects = true; 
     2166                  break; 
     2167                } 
     2168          } 
     2169        } 
     2170         
     2171         
     2172        if (!intersects) { 
     2173          //cout<<"dir vector.x="<<dirVector.x<<"direction'.x="<<atan2(direction.x, direction.y)<<endl; 
     2174          rays.push_back(SimpleRay(origin, direction)); 
     2175          generated++; 
     2176        } 
     2177  } 
     2178 
     2179  //  cout<<"desired="<<numberOfRays<<" tries="<<i<<endl; 
     2180   
     2181  if (exporter) { 
     2182        exporter->ExportRays(selectedRays, RgbColor(1, 0, 0)); 
     2183        delete exporter; 
     2184        CLEAR_CONTAINER(selectedRays); 
     2185  } 
     2186} 
     2187 
     2188int 
     2189RssTree::PruneRays(RssTreeLeaf *leaf, 
     2190                                   const float contributionThreshold) 
     2191{ 
     2192  int i; 
     2193  int j; 
     2194   
     2195  for (j=0, i=0; i < leaf->rays.size(); i++) { 
     2196         
     2197        if (leaf->rays[i].mRay->mWeightedPvsContribution > contributionThreshold) { 
     2198          // copy a valid sample 
     2199          if (i!=j)  
     2200                leaf->rays[j] = leaf->rays[i]; 
     2201          j++; 
     2202        } else { 
     2203          // delete the ray 
     2204          leaf->rays[i].mRay->Unref(); 
     2205          if (leaf->rays[i].mRay->RefCount() != 0) { 
     2206                cerr<<"Error: refcount!=0, but"<<leaf->rays[j].mRay->RefCount()<<endl; 
     2207                exit(1); 
     2208          } 
     2209          delete leaf->rays[i].mRay; 
     2210        } 
     2211  } 
     2212 
     2213 
     2214  leaf->rays.resize(j); 
     2215  int removed = (i-j); 
     2216  stat.rayRefs -= removed; 
     2217  return removed; 
     2218} 
     2219 
     2220int 
     2221RssTree::PruneRaysRandom(RssTreeLeaf *leaf, 
     2222                                                 const float ratio) 
     2223{ 
     2224  int i; 
     2225  int j; 
     2226   
     2227  for (j=0, i=0; i < leaf->rays.size(); i++) { 
     2228         
     2229        if (Random(1.0f) < ratio) { 
     2230          // copy a valid sample 
     2231          if (i!=j)  
     2232                leaf->rays[j] = leaf->rays[i]; 
     2233          j++; 
     2234        } else { 
     2235          // delete the ray 
     2236          leaf->rays[i].mRay->Unref(); 
     2237          if (leaf->rays[i].mRay->RefCount() != 0) { 
     2238                cerr<<"Error: refcount!=0, but"<<leaf->rays[j].mRay->RefCount()<<endl; 
     2239                exit(1); 
     2240          } 
     2241          delete leaf->rays[i].mRay; 
     2242        } 
     2243  } 
     2244 
     2245 
     2246  leaf->rays.resize(j); 
     2247  int removed = (i-j); 
     2248  stat.rayRefs -= removed; 
     2249  return removed; 
     2250} 
     2251 
     2252int 
     2253RssTree::PruneRaysContribution(RssTreeLeaf *leaf, 
     2254                                                           const float ratio) 
     2255{ 
     2256  int i; 
     2257   
     2258  if (leaf->rays.size() == 0) 
     2259        return 0; 
     2260   
     2261  sort(leaf->rays.begin(), 
     2262           leaf->rays.end(), 
     2263           RssTreeLeaf::RayInfo::GreaterWeightedPvsContribution); 
     2264 
     2265  int desired = ratio*leaf->rays.size(); 
     2266  int removed = leaf->rays.size() - desired; 
     2267   
     2268  for (i=desired; i < leaf->rays.size(); i++) { 
     2269        // delete the ray 
     2270        leaf->rays[i].mRay->Unref(); 
     2271        if (leaf->rays[i].mRay->RefCount() != 0) { 
     2272          cerr<<"Error: refcount!=0, but"<<leaf->rays[i].mRay->RefCount()<<endl; 
     2273          exit(1); 
     2274        } 
     2275        delete leaf->rays[i].mRay; 
     2276  } 
     2277   
     2278  leaf->rays.resize(desired); 
     2279  stat.rayRefs -= removed; 
     2280  return removed; 
     2281} 
     2282 
     2283 
     2284int 
     2285RssTree::PruneRays( 
     2286                                   const int desired 
     2287                                   ) 
     2288{ 
     2289  bool globalPrunning = false; 
     2290 
     2291  stack<RssTreeNode *> tstack; 
     2292  int prunned = 0; 
     2293 
     2294  Debug<<"Prunning rays...\nOriginal size "<<stat.rayRefs<<endl; 
     2295 
     2296  if (globalPrunning) { 
     2297        VssRayContainer allRays; 
     2298        allRays.reserve(stat.rayRefs); 
     2299        CollectRays(allRays); 
     2300        sort(allRays.begin(), 
     2301                 allRays.end(), 
     2302                 GreaterWeightedPvsContribution); 
     2303         
     2304        if ( desired >= allRays.size() ) 
     2305          return 0; 
     2306         
     2307        float contributionThreshold = allRays[desired]->mWeightedPvsContribution; 
     2308         
     2309        tstack.push(root); 
     2310         
     2311        while (!tstack.empty()) { 
     2312          RssTreeNode *node = tstack.top(); 
     2313          tstack.pop(); 
     2314           
     2315          if (node->IsLeaf()) { 
     2316                RssTreeLeaf *leaf = (RssTreeLeaf *)node; 
     2317                prunned += PruneRays(leaf, contributionThreshold); 
     2318          } else { 
     2319                RssTreeInterior *in = (RssTreeInterior *)node; 
     2320                // both nodes for directional splits 
     2321                tstack.push(in->front); 
     2322                tstack.push(in->back); 
     2323          } 
     2324        } 
     2325  } else { 
     2326        // prune random rays from each leaf so that the ratio's remain the same 
     2327        tstack.push(root); 
     2328        float ratio = desired/(float)stat.rayRefs; 
     2329         
     2330        while (!tstack.empty()) { 
     2331          RssTreeNode *node = tstack.top(); 
     2332          tstack.pop(); 
     2333           
     2334          if (node->IsLeaf()) { 
     2335                RssTreeLeaf *leaf = (RssTreeLeaf *)node; 
     2336                //              prunned += PruneRaysRandom(leaf, ratio); 
     2337                prunned += PruneRaysContribution(leaf, ratio); 
     2338          } else { 
     2339                RssTreeInterior *in = (RssTreeInterior *)node; 
     2340                // both nodes for directional splits 
     2341                tstack.push(in->front); 
     2342                tstack.push(in->back); 
     2343          } 
     2344        } 
     2345 
     2346         
     2347 
     2348 
     2349  } 
     2350   
     2351   
     2352   
     2353  Debug<<"Remained "<<stat.rayRefs<<" rays"<<endl; 
     2354   
     2355  return prunned; 
    18322356} 
    18332357 
     
    18372361                                          SimpleRayContainer &rays) 
    18382362{ 
     2363 
    18392364 
    18402365  vector<RssTreeLeaf *> leaves; 
     
    18592384                                 
    18602385  float avgContrib = sumContrib/numberOfLeaves; 
    1861   float ratioPerLeaf = numberOfRays/(avgContrib*numberOfLeaves); 
     2386   
     2387  // always generate at leat n ray per leaf 
     2388  int fixedPerLeaf = 1; 
     2389  int fixed = 1*leaves.size(); 
     2390  int iGenerated = numberOfRays; 
     2391  float ratioPerLeaf = iGenerated /(avgContrib*numberOfLeaves); 
     2392 
    18622393  k = 0; 
    18632394  for (i=0; i < leaves.size() && k < numberOfLeaves; i++) 
     
    18662397          RssTreeLeaf *leaf = leaves[i]; 
    18672398          float c = leaf->GetImportance(); 
    1868           int num = (c*ratioPerLeaf + 0.5); 
     2399 
     2400          int num = fixedPerLeaf + (int)(c*ratioPerLeaf + 0.5f); 
    18692401          GenerateLeafRays(leaf, num, rays); 
    18702402        } 
     
    18892421          RssTreeLeaf *leaf = (RssTreeLeaf *)node; 
    18902422          // update pvs size 
    1891           leaf->UpdatePvsSize(); 
     2423          UpdatePvsSize(leaf); 
    18922424          sumPvs += leaf->GetPvsSize(); 
    18932425          leaves++; 
     
    19042436} 
    19052437 
    1906          
     2438float weightAbsContributions = 0.0f; 
     2439// if small very high importance of the last sample 
     2440// if 1.0f then weighs = 1 1/2 1/3 1/4 
     2441float passSampleWeightDecay = 0.5f; 
     2442 
     2443void 
     2444RssTree::GetRayContribution(const RssTreeNode::RayInfo &info, 
     2445                                                        float &weight, 
     2446                                                        float &contribution) 
     2447{ 
     2448  VssRay *ray = info.mRay; 
     2449  weight = 1.0f/(mCurrentPass - ray->mPass + passSampleWeightDecay); 
     2450  contribution = 
     2451        weightAbsContributions*ray->mPvsContribution + 
     2452        (1.0f - weightAbsContributions)*ray->mRelativePvsContribution; 
     2453  // store the computed value 
     2454  info.mRay->mWeightedPvsContribution = weight*contribution; 
     2455} 
     2456 
     2457float 
     2458RssTree::GetSampleWeight(const int pass) 
     2459{ 
     2460  int passDiff = mCurrentPass - pass; 
     2461  float weight; 
     2462  if (1)  
     2463        weight = 1.0f/(passDiff + passSampleWeightDecay); 
     2464  else  
     2465        switch (passDiff) { 
     2466        case 0: 
     2467          weight = 1.0f; 
     2468          break; 
     2469        default: 
     2470          weight = 0.01f; 
     2471          break; 
     2472          //    case 1: 
     2473//        weight = 0.5f; 
     2474//        break; 
     2475//      case 2: 
     2476//        weight = 0.25f; 
     2477//        break; 
     2478//      case 3: 
     2479//        weight = 0.12f; 
     2480//        break; 
     2481//      case 4: 
     2482//        weight = 0.06f; 
     2483//        break; 
     2484//      default: 
     2485//        weight = 0.03f; 
     2486//        break; 
     2487        } 
     2488  return weight; 
     2489} 
     2490 
     2491void 
     2492RssTree::ComputeImportance(RssTreeLeaf *leaf)  
     2493{ 
     2494  if (0)  
     2495        leaf->mImportance = leaf->GetAvgRayContribution(); 
     2496  else { 
     2497        RssTreeNode::RayInfoContainer::const_iterator it = leaf->rays.begin(), 
     2498          it_end = leaf->rays.end(); 
     2499         
     2500        float sumContributions = 0.0f; 
     2501        float sumRelContributions = 0.0f; 
     2502        float sumWeights = 0.0f; 
     2503        for (; it != it_end; ++it) { 
     2504          VssRay *ray = (*it).mRay; 
     2505          float weight = GetSampleWeight(ray->mPass); 
     2506           
     2507          sumContributions += weight*ray->mPvsContribution; 
     2508          sumRelContributions += weight*ray->mRelativePvsContribution; 
     2509           
     2510          //      sumWeights += weight; 
     2511          sumWeights += 1.0f; 
     2512        } 
     2513        // $$  
     2514        // sumWeights = leaf->mTotalRays; 
     2515           
     2516        if (sumWeights != 0.0f)  
     2517          leaf->mImportance = 
     2518                (weightAbsContributions*sumContributions + 
     2519                 (1.0f - weightAbsContributions)*sumRelContributions)/sumWeights; 
     2520        else 
     2521          leaf->mImportance = 0.0f; 
     2522         
     2523  } 
     2524   
     2525  // return GetAvgRayContribution()*mImportance; 
     2526  //return GetAvgRayContribution(); 
     2527} 
     2528 
     2529 
    19072530float 
    19082531RssTreeLeaf::GetImportance()  const 
    19092532{ 
    1910  
    1911   if (1) { 
    1912         return GetAvgRayContribution(); 
    1913         //      return GetPvsSize(); 
    1914   } else { 
    1915         // return GetAvgRayContribution()*mEntropyImportance; 
    1916         //return GetAvgRayContribution(); 
    1917         return mEntropyImportance; 
    1918   } 
     2533  return mImportance; 
    19192534} 
    19202535 
    19212536 
    19222537float 
    1923 RssTreeLeaf::ComputePvsEntropy() 
     2538RssTreeLeaf::ComputePvsEntropy() const 
    19242539{ 
    19252540  int samples = 0; 
    19262541  Intersectable::NewMail(); 
    19272542  // set all object as belonging to the fron pvs 
    1928   for(RssTreeNode::RayInfoContainer::iterator ri = rays.begin(); 
     2543  for(RssTreeNode::RayInfoContainer::const_iterator ri = rays.begin(); 
    19292544          ri != rays.end(); 
    19302545          ri++) 
    19312546        if ((*ri).mRay->IsActive()) { 
    1932           Intersectable *object = (*ri).mRay->mTerminationObject; 
     2547          Intersectable *object = (*ri).GetObject(); 
    19332548          if (object) { 
    19342549                if (!object->Mailed()) { 
     
    19492564                ri++)  
    19502565          if ((*ri).mRay->IsActive()) { 
    1951                 Intersectable *object = (*ri).mRay->mTerminationObject; 
     2566                Intersectable *object = (*ri).GetObject(); 
    19522567                if (object) { 
    19532568                  if (!object->Mailed()) { 
     
    19672582 
    19682583float 
    1969 RssTreeLeaf::ComputeRayLengthEntropy() 
     2584RssTreeLeaf::ComputeRayLengthEntropy() const 
    19702585{ 
    19712586  // get sum of all ray lengths 
     
    20172632 
    20182633 
    2019 void 
    2020 RssTreeLeaf::ComputeEntropyImportance() 
    2021 { 
    2022   mPvsEntropy = ComputePvsEntropy(); 
    2023   mRayLengthEntropy = ComputeRayLengthEntropy(); 
     2634float 
     2635RssTreeLeaf::ComputeEntropyImportance() const 
     2636{ 
    20242637   
    20252638  //  mEntropy = 1.0f - ComputeRayLengthEntropy(); 
    2026   mEntropyImportance = 1.0f - ComputePvsEntropy(); 
    2027    
    2028   //  cout<<"ei="<<mEntropyImportance<<" "; 
     2639  return 1.0f - ComputePvsEntropy(); 
     2640} 
     2641 
     2642float 
     2643RssTreeLeaf::ComputeRayContributionImportance() const 
     2644{ 
     2645  //  mPvsEntropy = ComputePvsEntropy(); 
     2646  //  mRayLengthEntropy = ComputeRayLengthEntropy(); 
     2647   
     2648  //  mEntropy = 1.0f - ComputeRayLengthEntropy(); 
     2649  return 1.0f - ComputePvsEntropy(); 
    20292650} 
    20302651 
     
    20592680  VssRayContainer allRays; 
    20602681  CollectRays(allRays); 
     2682 
    20612683   
    20622684  int desired = min(number, (int)allRays.size()); 
     
    21052727  return (int)rays.size(); 
    21062728} 
     2729 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.h

    r469 r492  
    2121#include "VssRay.h" 
    2222#include "AxisAlignedBox3.h" 
     23#include "Halton.h" 
    2324 
    2425 
     
    6970  // number of dynamically removed ray refs 
    7071  int removedRayRefs; 
    71    
     72 
     73 
     74 
     75  // dynamically updated values 
     76  float avgPvsSize; 
     77  float avgRays; 
     78  float avgRayContribution; 
     79  float avgPvsEntropy; 
     80  float avgRayLengthEntropy; 
     81  float avgImportance; 
     82 
     83  float avgWeightedRayContribution; 
     84 
    7285  // Constructor 
    7386  RssStatistics() { 
     
    144157          return a.mRay < b.mRay; 
    145158        } 
     159 
     160#define USE_ORIGIN 0 
    146161         
    147162        Vector3 GetOrigin() const { 
     163#if USE_ORIGIN 
    148164          return mRay->GetOrigin(); 
    149         } 
    150  
    151         float ExtrapOrigin(const int axis) const { 
     165#else 
     166          return mRay->GetTermination(); 
     167#endif 
     168        } 
     169 
     170        Vector3 GetTermination() const { 
     171#if USE_ORIGIN 
     172          return mRay->GetTermination(); 
     173#else 
     174          return mRay->GetOrigin(); 
     175#endif 
     176        } 
     177 
     178        float GetOrigin(const int axis) const { 
     179#if USE_ORIGIN 
    152180          return mRay->GetOrigin(axis); 
    153         } 
    154          
    155         float ExtrapTermination(const int axis) const { 
     181#else 
    156182          return mRay->GetTermination(axis); 
    157         } 
    158  
    159         Vector3 Extrap(const float t) const { 
    160           return mRay->Extrap(t); 
    161         } 
     183#endif 
     184        } 
     185 
     186        Vector3 GetDir() const { 
     187#if USE_ORIGIN 
     188          return mRay->GetDir(); 
     189#else 
     190          return -mRay->GetDir(); 
     191#endif 
     192        } 
     193 
     194        float GetDirParametrization(const int axis) const { 
     195#if USE_ORIGIN 
     196          return mRay->GetDirParametrization(axis); 
     197#else 
     198          return mRay->GetOpositeDirParametrization(axis); 
     199#endif 
     200        } 
     201 
     202         
     203//      Vector3 GetTermination() const { 
     204//        return mRay->GetOrigin(); 
     205//      } 
     206         
     207//      float GetTermination(const int axis) const { 
     208//        return mRay->GetTermination(axis); 
     209//      } 
     210 
     211        Intersectable *GetObject() const { 
     212#if USE_ORIGIN 
     213          return mRay->mTerminationObject; 
     214#else 
     215          return mRay->mOriginObject; 
     216#endif 
     217        } 
     218         
     219        Intersectable *GetSourceObject() const { 
     220#if USE_ORIGIN 
     221          return mRay->mOriginObject; 
     222#else 
     223          return mRay->mTerminationObject; 
     224#endif 
     225        } 
     226 
     227        //      Vector3 Extrap(const float t) const { 
     228        //        return mRay->Extrap(t); 
     229        //      } 
    162230         
    163231        int 
     
    167235           
    168236          // only compare the side of the origin 
    169           float rpos = mRay->GetOrigin(axis); 
     237          float rpos = (axis < 3) ? GetOrigin(axis) : GetDirParametrization(axis - 3); 
    170238          return (rpos <= position) ? -1 : 1; 
    171239        } 
    172          
     240 
     241        static bool GreaterWeightedPvsContribution(const RayInfo &a, 
     242                                                                                           const RayInfo &b) { 
     243          return a.mRay->mWeightedPvsContribution > b.mRay->mWeightedPvsContribution; 
     244        } 
     245 
     246        static float Distance(const RayInfo &a, 
     247                                                 const RayInfo &b) 
     248        { 
     249          if (a.mRay->mTerminationObject == b.mRay->mTerminationObject) 
     250                return MAX_FLOAT; 
     251           
     252          return Min(a.mRay->SqrDistance(b.GetTermination()), 
     253                                 b.mRay->SqrDistance(a.GetTermination())); 
     254        } 
     255 
     256         
     257        static float SqrDistance5D(const RayInfo &a, 
     258                                                           const RayInfo &b, 
     259                                                           const Vector3 &spatialDerivative, 
     260                                                           const Vector3 &directionalDerivative 
     261                                                           ) 
     262        { 
     263          Vector3 spatialDiff = b.GetOrigin() - a.GetOrigin(); 
     264          Vector3 directionalDiff = b.GetDir() - a.GetDir(); 
     265           
     266          return DotProd(spatialDiff, spatialDerivative) + 
     267                DotProd(directionalDiff, directionalDerivative); 
     268        } 
     269 
     270         
     271  }; 
     272 
     273  struct SilhouetteRays { 
     274        RayInfo *a; 
     275        RayInfo *b; 
     276        SilhouetteRays() {} 
     277        SilhouetteRays(RayInfo *_a, RayInfo *_b):a(_a), b(_b) { 
     278        } 
    173279  }; 
    174280   
     
    307413   
    308414  RayInfoContainer rays; 
    309   int mPassingRays; 
     415  int mTotalRays; 
    310416         
    311417  bool mValidPvs; 
    312   float mEntropyImportance; 
    313   float mPvsEntropy; 
    314   float mRayLengthEntropy; 
    315    
    316          
     418  float mImportance; 
     419   
     420  HaltonSequence halton; 
     421   
    317422  RssTreeLeaf(RssTreeInterior *p, 
    318423                          const int nRays 
    319                           ):RssTreeNode(p), rays(), mPvsSize(0), mPassingRays(0), mValidPvs(false) { 
     424                          ):RssTreeNode(p), rays(), mPvsSize(0), mTotalRays(0), mValidPvs(false) { 
    320425    rays.reserve(nRays); 
    321426  } 
     
    328433    s<< 
    329434          "L: rays="<<(int)rays.size()<< 
    330           " pvs="<<mPvsSize<<" pEntropy="<<mPvsEntropy<<" lEntropy="<<mRayLengthEntropy<<endl; 
     435          " pvs="<<mPvsSize<<" importance="<<mImportance<<endl; 
    331436  }; 
    332437   
     
    334439        mValidPvs = false; 
    335440    rays.push_back(data); 
    336     data.mRay->Ref(); 
    337         if (data.GetRayClass() == RayInfo::PASSING_RAY) 
    338           mPassingRays++; 
     441        mTotalRays++; 
     442        data.mRay->Ref(); 
    339443  } 
    340444         
     
    348452  } 
    349453 
    350   void 
    351   UpdatePvsSize(); 
    352454 
    353455  float 
    354   ComputePvsEntropy(); 
     456  ComputePvsEntropy() const; 
    355457   
    356458  float 
    357   ComputeRayLengthEntropy(); 
     459  ComputeRayLengthEntropy() const; 
    358460   
    359461  float 
    360   ComputeRayTerminationEntropy(); 
    361    
    362   void 
    363   ComputeEntropyImportance(); 
     462  ComputeRayTerminationEntropy() const; 
     463   
     464 
     465  float 
     466  ComputeEntropyImportance() const; 
     467   
     468  float 
     469  ComputeRayContributionImportance() const; 
    364470 
    365471  void Mail() { mailbox = mailID; } 
     
    401507        return a->GetAvgRayContribution() > b->GetAvgRayContribution(); 
    402508  } 
     509 
    403510   
    404511}; 
     
    560667  // depth at which directional splits are performed if mInterleaveDirSplits is false 
    561668  int mDirSplitDepth; 
     669 
     670  // maximal number of rays maintained in the rss tree 
     671  int mMaxRays; 
    562672   
    563673  // maximal size of the box on which the refdir splitting can be performed 
     
    582692  int minCollapseDepth; 
    583693 
     694  bool mImportanceBasedCost; 
     695 
     696  // sampling pass 
     697  int mCurrentPass; 
    584698   
    585699  // reusable array of split candidates 
     
    627741  Subdivide(const TraversalData &tdata); 
    628742         
    629   int 
    630   SelectPlane(RssTreeLeaf *leaf, 
    631                           const AxisAlignedBox3 &box, 
    632                           float &position, 
    633                           int &raysBack, 
    634                           int &raysFront, 
    635                           int &pvsBack, 
    636                           int &pvsFront 
    637                           ); 
    638743 
    639744  void 
     
    658763  } 
    659764   
    660  
    661   float 
     765  struct SplitInfo { 
     766         
     767        int axis; 
     768        float position; 
     769        float costRatio; 
     770         
     771        int rays; 
     772        int raysBack; 
     773        int raysFront; 
     774 
     775        int pvs; 
     776        int pvsBack; 
     777        int pvsFront; 
     778 
     779        float contribution; 
     780        float contributionBack; 
     781        float contributionFront; 
     782 
     783        int viewCells; 
     784        int viewCellsBack; 
     785        int viewCellsFront; 
     786 
     787        float volume; 
     788        float volumeBack; 
     789        float volumeFront; 
     790         
     791  }; 
     792   
     793  void 
    662794  BestCostRatio( 
    663795                                RssTreeLeaf *node, 
    664                                 int &axis, 
    665                                 float &position, 
    666                                 int &raysBack, 
    667                                 int &raysFront, 
    668                                 int &pvsBack, 
    669                                 int &pvsFront 
     796                                SplitInfo &info 
     797//                              int &axis, 
     798//                              float &position, 
     799//                              int &raysBack, 
     800//                              int &raysFront, 
     801//                              int &pvsBack, 
     802//                              int &pvsFront 
    670803                                ); 
    671804         
    672   float 
     805   
     806  void 
    673807  EvalCostRatio( 
    674808                                RssTreeLeaf *node, 
    675                                 const int axis, 
    676                                 const float position, 
    677                                 int &raysBack, 
    678                                 int &raysFront, 
    679                                 int &pvsBack, 
    680                                 int &pvsFront 
     809                                SplitInfo &info 
     810//                              const int axis, 
     811//                              const float position, 
     812//                              int &raysBack, 
     813//                              int &raysFront, 
     814//                              int &pvsBack, 
     815//                              int &pvsFront 
    681816                                ); 
    682817 
    683   float 
     818  void 
    684819  EvalCostRatioHeuristic( 
    685820                                                 RssTreeLeaf *node, 
    686                                                  const int axis, 
    687                                                  float &position, 
    688                                                  int &raysBack, 
    689                                                  int &raysFront, 
    690                                                  int &pvsBack, 
    691                                                  int &pvsFront 
     821                                                 SplitInfo &info 
     822//                                               const int axis, 
     823//                                               float &position, 
     824//                                               int &raysBack, 
     825//                                               int &raysFront, 
     826//                                               int &pvsBack, 
     827//                                               int &pvsFront 
    692828                                                 ); 
    693829 
    694   float 
     830  int 
     831  SelectPlane(RssTreeLeaf *leaf, 
     832                          const AxisAlignedBox3 &box, 
     833                          SplitInfo &info 
     834                          ); 
     835   
     836  void 
    695837  GetCostRatio( 
    696838                           RssTreeLeaf *leaf, 
    697                            const int axis, 
    698                            const float position, 
    699                            const int raysBack, 
    700                            const int raysFront, 
    701                            const int pvsBack, 
    702                            const int pvsFront 
     839                           SplitInfo &info 
     840                           //                      const int axis, 
     841                           //                      const float position, 
     842                           //                      const int raysBack, 
     843                           //                      const int raysFront, 
     844                           //                      const int pvsBack, 
     845                           //                      const int pvsFront 
    703846                           ); 
    704  
     847   
    705848  AxisAlignedBox3 GetBBox(const RssTreeNode *node) const { 
    706849    if (node->parent == NULL) 
     
    803946         
    804947  void 
    805   GetTreeStatistics( 
    806                                         float &avgPvsSize, 
    807                                         float &avgRays, 
    808                                         float &avgRayContribution, 
    809                                         float &avgPvsEntropy, 
    810                                         float &avgRayLengthEntropy, 
    811                                         float &avgImportance 
    812                                         ); 
     948  UpdateTreeStatistics(); 
    813949 
    814950 
     
    8651001                          ); 
    8661002 
     1003  void 
     1004  UpdatePvsSize(RssTreeLeaf *leaf); 
     1005 
     1006  void 
     1007  ComputeImportance(RssTreeLeaf *leaf); 
     1008   
     1009  void 
     1010  SetPass(const int p) { 
     1011        mCurrentPass = p; 
     1012  } 
     1013   
     1014  void GetRayContribution(const RssTreeNode::RayInfo &info, 
     1015                                                  float &weight, 
     1016                                                  float &contribution); 
     1017 
     1018  float 
     1019  GetSampleWeight(const int pass); 
     1020 
     1021  int 
     1022  RemoveInteriorRays( 
     1023                                         RssTreeLeaf *leaf 
     1024                                         ); 
     1025 
     1026  bool 
     1027  IsRayConvexCombination(const RssTreeNode::RayInfo &ray, 
     1028                                                 const RssTreeNode::RayInfo &r1, 
     1029                                                 const RssTreeNode::RayInfo &r2, 
     1030                                                 const RssTreeNode::RayInfo &r3); 
     1031 
     1032  int 
     1033  PruneRays(RssTreeLeaf *leaf, 
     1034                        const float contributionThreshold); 
     1035  int 
     1036  PruneRaysRandom(RssTreeLeaf *leaf, 
     1037                                  const float ratio); 
     1038 
     1039  int 
     1040  PruneRaysContribution(RssTreeLeaf *leaf, 
     1041                                                const float ratio); 
     1042 
     1043  int 
     1044  PruneRays( 
     1045                        const int desired 
     1046                        ); 
     1047   
     1048 
     1049  void 
     1050  FindSilhouetteRays(RssTreeLeaf *leaf, 
     1051                                         vector<RssTreeLeaf::SilhouetteRays> &rays 
     1052                                         ); 
     1053   
    8671054}; 
    8681055 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r487 r492  
    242242SamplingPreprocessor::ComputeVisibility() 
    243243{ 
    244   // pickup an object 
    245   ObjectContainer objects; 
    246244   
    247245  /// rays per pass 
    248246  RayContainer passRays; 
    249247 
    250   mSceneGraph->CollectObjects(&objects); 
    251248 
    252249  mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox()); 
     
    270267                int reverseSamples = 0; 
    271268                 
    272                 for (i = 0; i < objects.size(); i++) { 
     269                for (i = 0; i < mObjects.size(); i++) { 
    273270                                                 
    274271                        KdNode *nodeToSample = NULL; 
    275                         Intersectable *object = objects[i]; 
     272                        Intersectable *object = mObjects[i]; 
    276273                 
    277274                        int pvsSize = 0; 
     
    339336                // cast rays for view cells construction 
    340337                ProcessViewCells(passRays, 
    341                                                  objects, 
     338                                                 mObjects, 
    342339                                                 passSampleContributions, 
    343340                                                 passContributingSamples); 
     
    361358                                 << "k   #SampleContributions=" << passSampleContributions << " ("  
    362359                                 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 
    363                                  << (float)pvsSize /(float)objects.size() << endl  
     360                                 << (float)pvsSize /(float)mObjects.size() << endl  
    364361                                 << "avg ray contrib=" << avgRayContrib << endl 
    365362                                 << "reverse samples [%]" << reverseSamples/(float)passSamples*100.0f << endl; 
     
    371368                        "#SampleContributions\n" << passSampleContributions << endl <<  
    372369                        "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 
    373                         "#AvgPVS\n"<< pvsSize/(float)objects.size() << endl << 
     370                        "#AvgPVS\n"<< pvsSize/(float)mObjects.size() << endl << 
    374371                        "#AvgRayContrib\n" << avgRayContrib << endl; 
    375372        } 
     
    387384        // construct view cells if not already constructed 
    388385        if (!mViewCellsManager->ViewCellsConstructed()) 
    389                 mViewCellsManager->Construct(objects, mVssSampleRays); 
     386          mViewCellsManager->Construct(mObjects, mVssSampleRays); 
    390387 
    391388        // $$JB temporary removed 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SceneGraph.cpp

    r490 r492  
    55#include "X3dExporter.h" 
    66#include "Intersectable.h" 
    7  
    87 
    98 
     
    104103         
    105104} 
     105 
     106 
     107void 
     108SceneGraphNode::UpdateBox() 
     109{ 
     110  AxisAlignedBox3 box; 
     111   
     112  box.Initialize(); 
     113   
     114  ObjectContainer::const_iterator mi = mGeometry.begin(); 
     115  for (; mi != mGeometry.end(); mi++) 
     116        box.Include((*mi)->GetBox()); 
     117   
     118  SceneGraphNodeContainer::iterator ni = mChildren.begin(); 
     119  for (; ni != mChildren.end(); ni++) { 
     120        (*ni)->UpdateBox(); 
     121        box.Include((*ni)->mBox); 
     122  } 
     123   
     124  mBox = box; 
     125} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SceneGraph.h

    r387 r492  
    1616  SceneGraphNodeContainer mChildren; 
    1717  AxisAlignedBox3 mBox; 
     18  void UpdateBox(); 
    1819}; 
    1920 
     
    2728   
    2829  int 
    29         CollectObjects(ObjectContainer *instances); 
    30          
     30  CollectObjects(ObjectContainer *instances); 
     31   
    3132  int 
    32         AssignObjectIds(); 
     33  AssignObjectIds(); 
     34   
     35  void 
     36  GetStatistics(int &intersectables, int &faces) const; 
    3337 
    34         void 
    35         GetStatistics(int &intersectables, int &faces) const; 
    36  
     38  AxisAlignedBox3 GetBox() const { return mRoot->mBox; } 
     39   
    3740protected: 
    3841}; 
     
    4043 
    4144 
    42  
    4345#endif 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Vector3.cpp

    r448 r492  
    191191 
    192192Vector3 
    193 UniformRandomVector(const Vector3 &normal) 
    194 { 
    195         //  float r1 = RandomValue(0.0f, 1.0f); 
    196         //  float r2 = RandomValue(0.0f, 1.0f); 
    197         float r1, r2; 
     193UniformRandomVector() 
     194{ 
     195  //  float r1 = RandomValue(0.0f, 1.0f); 
     196  //  float r2 = RandomValue(0.0f, 1.0f); 
     197  float r1, r2; 
    198198         
    199         halton2.GetNext(r1, r2); 
     199  halton2.GetNext(r1, r2); 
    200200         
    201201         
    202         float cosTheta = 1.0f - r1; 
     202  float cosTheta = 1.0f - 2*r1; 
    203203  float sinTheta = sqrt(1 - sqr(cosTheta)); 
    204204  float fi = 2.0f*M_PI*r2; 
    205205   
    206206  Vector3 dir(sinTheta*sin(fi), 
    207                                                         cosTheta, 
    208                                                         sinTheta*cos(fi)); 
    209          
     207                          cosTheta, 
     208                          sinTheta*cos(fi)); 
     209   
     210  return dir; 
     211} 
     212 
     213Vector3 
     214UniformRandomVector(const Vector3 &normal) 
     215{ 
     216  //  float r1 = RandomValue(0.0f, 1.0f); 
     217  //  float r2 = RandomValue(0.0f, 1.0f); 
     218  float r1, r2; 
     219   
     220  halton2.GetNext(r1, r2); 
     221   
     222   
     223  float cosTheta = 1.0f - r1; 
     224  float sinTheta = sqrt(1 - sqr(cosTheta)); 
     225  float fi = 2.0f*M_PI*r2; 
     226   
     227  Vector3 dir(sinTheta*sin(fi), 
     228                          cosTheta, 
     229                          sinTheta*cos(fi)); 
     230   
    210231   
    211232  //  return Normalize(dir); 
    212          
     233   
    213234  Matrix4x4 m = RotationVectorsMatrix( 
    214                                                                                                                                                         normal, 
    215                                                                                                                                                         Vector3(0,1,0)); 
     235                                                                          normal, 
     236                                                                          Vector3(0,1,0)); 
    216237  Matrix4x4 mi = Invert(m); 
    217238  m = m*RotationVectorsMatrix( 
    218                                                                                                                         Vector3(0,1,0), 
    219                                                                                                                         Normalize(dir))*mi; 
     239                                                          Vector3(0,1,0), 
     240                                                          Normalize(dir))*mi; 
    220241   
    221242  return TransformNormal(m, normal); 
    222243   
    223         //    return TransformNormal( 
    224         //                       RotationVectorsMatrix( 
    225         //                                             Vector3(0,1,0), 
    226         //                                             Normalize(dir) 
    227         //                                             ), 
    228         //                       normal 
    229         //                       ); 
    230 } 
     244  //    return TransformNormal( 
     245  //                     RotationVectorsMatrix( 
     246  //                                           Vector3(0,1,0), 
     247  //                                           Normalize(dir) 
     248  //                                           ), 
     249  //                     normal 
     250  //                     ); 
     251} 
     252 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Vector3.h

    r448 r492  
    228228 
    229229  friend Vector3 UniformRandomVector(const Vector3 &normal); 
     230  friend Vector3 UniformRandomVector(); 
     231   
     232 
    230233}; 
    231234 
     
    445448} 
    446449 
     450 
    447451// Overload << operator for C++-style output 
    448452inline ostream& 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r491 r492  
    26722672} 
    26732673 
     2674 
     2675ViewCell * 
     2676BspTree::GetViewCell(const Vector3 &point) 
     2677{ 
     2678  stack<BspNode *> nodeStack; 
     2679  nodeStack.push(mRoot); 
     2680   
     2681  ViewCell *viewcell = NULL; 
     2682   
     2683  while (!nodeStack.empty())  { 
     2684        BspNode *node = nodeStack.top(); 
     2685        nodeStack.pop(); 
     2686         
     2687        if (node->IsLeaf()) { 
     2688          viewcell = dynamic_cast<BspLeaf *>(node)->mViewCell; 
     2689          break; 
     2690        } else { 
     2691           
     2692          BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     2693                 
     2694          // random decision 
     2695          if (interior->GetPlane().Side(point) < 0) 
     2696                nodeStack.push(interior->GetBack()); 
     2697          else 
     2698                nodeStack.push(interior->GetFront()); 
     2699        } 
     2700  } 
     2701   
     2702  return viewcell; 
     2703} 
     2704 
    26742705void BspNodeGeometry::ComputeBoundingBox(AxisAlignedBox3 &box) 
    26752706{ 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r491 r492  
    468468                                  ); 
    469469 
     470  ViewCell * 
     471  GetViewCell(const Vector3 &point); 
     472   
    470473        /// bsp tree construction types 
    471474        enum {FROM_INPUT_VIEW_CELLS, FROM_SCENE_GEOMETRY, FROM_SAMPLES}; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp

    r491 r492  
    330330void ViewCellsManager::ComputeSampleContributions(VssRay &ray) 
    331331{ 
    332         ViewCellContainer viewcells; 
    333                  
    334         ray.mPvsContribution = 0; 
    335         ray.mRelativePvsContribution = 0.0f; 
    336  
    337         // matt TODO: remove this!! 
    338         Ray hray(ray); 
    339         float tmin = 0, tmax = 1.0; 
    340          
    341         //hray.Init(ray.GetOrigin(), ray.GetDir(), Ray::LINE_SEGMENT); 
    342         if (!GetSceneBbox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 
    343                 return; 
    344  
    345         Vector3 origin = hray.Extrap(tmin); 
    346         Vector3 termination = hray.Extrap(tmax); 
    347          
    348         CastLineSegment(origin, 
    349                                         termination, 
    350                                         viewcells); 
     332 
     333 
     334 
     335  ViewCellContainer viewcells; 
     336                 
     337  ray.mPvsContribution = 0; 
     338  ray.mRelativePvsContribution = 0.0f; 
     339 
     340  // matt TODO: remove this!! 
     341  Ray hray(ray); 
     342  float tmin = 0, tmax = 1.0; 
    351343   
    352         ViewCellContainer::const_iterator it = viewcells.begin(); 
    353          
    354         for (; it != viewcells.end(); ++it)  
    355         {        
    356                 ViewCell *viewcell = *it; 
    357          
    358                 // if ray not outside of view space 
    359                 float contribution; 
    360                 bool added =  
    361                         viewcell->GetPvs().AddSample(ray.mTerminationObject, 
    362                                                                                  contribution); 
    363                  
    364                 if (added) 
    365                         ++ ray.mPvsContribution; 
    366                  
    367                 ray.mRelativePvsContribution += contribution; 
    368         } 
     344  //hray.Init(ray.GetOrigin(), ray.GetDir(), Ray::LINE_SEGMENT); 
     345  if (!GetSceneBbox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 
     346        return; 
     347   
     348  Vector3 origin = hray.Extrap(tmin); 
     349  Vector3 termination = hray.Extrap(tmax); 
     350   
     351  CastLineSegment(origin, 
     352                                  termination, 
     353                                  viewcells); 
     354   
     355  // copy viewcells memory efficiently 
     356  const bool storeViewcells = false; 
     357  if (storeViewcells) { 
     358        ray.mViewCells.reserve(viewcells.size()); 
     359        ray.mViewCells = viewcells; 
     360  } 
     361   
     362  ViewCellContainer::const_iterator it = viewcells.begin(); 
     363 
     364  bool addInPlace = false; 
     365 
     366  if (addInPlace) { 
     367        for (; it != viewcells.end(); ++it) {    
     368          ViewCell *viewcell = *it; 
     369           
     370          // if ray not outside of view space 
     371          float contribution; 
     372          bool added =  
     373                viewcell->GetPvs().AddSample(ray.mTerminationObject, 
     374                                                                         contribution 
     375                                                                         ); 
     376          if (added) 
     377                ray.mPvsContribution++; 
     378           
     379          ray.mRelativePvsContribution += contribution; 
     380        } 
     381  } else { 
     382    for (; it != viewcells.end(); ++it) {        
     383          ViewCell *viewcell = *it; 
     384          // if ray not outside of view space 
     385          float contribution; 
     386          if (viewcell->GetPvs().GetSampleContribution(ray.mTerminationObject, 
     387                                                                                                   contribution 
     388                                                                                                   )) 
     389                ray.mPvsContribution++; 
     390           
     391          ray.mRelativePvsContribution += contribution; 
     392        } 
     393 
     394        for (it = viewcells.begin(); it != viewcells.end(); ++it) {      
     395          ViewCell *viewcell = *it; 
     396          // if ray not outside of view space 
     397          viewcell->GetPvs().AddSample(ray.mTerminationObject); 
     398        } 
     399  } 
    369400} 
    370401 
     
    520551#endif 
    521552} 
    522  
     553   
    523554 
    524555float BspViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost) const 
     
    17051736                                                                          const VssRayContainer &rays) 
    17061737{ 
    1707         // if view cells were already constructed 
    1708         if (ViewCellsConstructed()) 
    1709                 return 0; 
    1710  
    1711         int sampleContributions = 0; 
     1738  // if view cells were already constructed 
     1739  if (ViewCellsConstructed()) 
     1740        return 0; 
     1741   
     1742  Debug << "Constructing bsp view cells" << endl; 
     1743   
     1744  int sampleContributions = 0; 
     1745   
     1746  VssRayContainer sampleRays; 
     1747   
     1748  int limit = min (mConstructionSamples, (int)rays.size()); 
     1749 
    17121750         
    17131751        VssRayContainer constructionRays; 
     
    22682306                } 
    22692307        } 
    2270  
    22712308        return maxDist; 
    22722309} 
     2310 
     2311 
     2312 
     2313 
     2314ViewCell * 
     2315VspBspViewCellsManager::GetViewCell(const Vector3 &point) 
     2316{ 
     2317  if (!mVspBspTree) 
     2318        return NULL; 
     2319  return mVspBspTree->GetViewCell(point); 
     2320} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h

    r490 r492  
    171171        virtual void GetPvsStatistics(PvsStatistics &stat); 
    172172 
    173         virtual void PrintPvsStatistics(ostream &s); 
     173  /** Get a viewcell containing the specified point */ 
     174  virtual ViewCell *GetViewCell(const Vector3 &point) = 0; 
     175   
     176  virtual void 
     177  PrintPvsStatistics(ostream &s); 
    174178 
    175179        /** Returns probability that view point lies in one view cell. 
     
    339343        AxisAlignedBox3 GetSceneBbox() const; 
    340344 
     345  /** Get a viewcell containing the specified point */ 
     346  ViewCell *GetViewCell(const Vector3 &point) { return NULL; } 
     347 
    341348protected: 
    342349 
     
    404411        /** Prints out statistics of this approach. 
    405412        */ 
    406         //void PrintStatistics(ostream &s) const; 
    407  
    408         float GetProbability(ViewCell *viewCell); 
    409         float GetRendercost(ViewCell *viewCell, float objRendercost) const; 
    410          
    411         AxisAlignedBox3 GetSceneBbox() const; 
     413  //  virtual void PrintStatistics(ostream &s) const; 
     414  ViewCell *GetViewCell(const Vector3 &point) { return NULL; } 
     415 
     416  float GetProbability(ViewCell *viewCell); 
     417  float GetRendercost(ViewCell *viewCell, float objRendercost) const; 
     418   
     419  AxisAlignedBox3 GetSceneBbox() const; 
    412420 
    413421protected: 
     
    460468                                                ViewCellContainer &viewcells); 
    461469 
     470  ViewCell *GetViewCell(const Vector3 &point) { return NULL; } 
     471 
    462472        float GetProbability(ViewCell *viewCell); 
    463473        float GetRendercost(ViewCell *viewCell, float objRendercost) const; 
    464474 
    465475        AxisAlignedBox3 GetSceneBbox() const; 
    466  
    467476protected: 
    468477 
     
    508517        bool ViewCellsConstructed() const; 
    509518 
    510         //void PrintStatistics(ostream &s) const; 
    511519         
    512520        int CastLineSegment(const Vector3 &origin, 
     
    519527        AxisAlignedBox3 GetSceneBbox() const; 
    520528 
     529  ViewCell *GetViewCell(const Vector3 &point); 
     530 
    521531        bool GetViewPoint(Vector3 &viewPoint) const; 
    522532 
    523533        bool ViewPointValid(const Vector3 &viewPoint) const; 
    524  
    525534protected: 
    526535        /** DEPRECATED 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp

    r491 r492  
    15251525void VspBspTree::CollectViewCells(ViewCellContainer &viewCells) const 
    15261526{ 
    1527         stack<BspNode *> nodeStack; 
    1528         nodeStack.push(mRoot); 
    1529  
    1530         ViewCell::NewMail(); 
    1531  
    1532         while (!nodeStack.empty()) 
    1533         { 
    1534                 BspNode *node = nodeStack.top(); 
    1535                 nodeStack.pop(); 
    1536  
    1537                 if (node->IsLeaf()) 
    1538                 { 
    1539                         ViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 
    1540                         if (node->TreeValid() && !viewCell->Mailed()) 
     1527  stack<BspNode *> nodeStack; 
     1528 
     1529  if (!mRoot) 
     1530        return; 
     1531 
     1532  nodeStack.push(mRoot); 
     1533   
     1534  ViewCell::NewMail(); 
     1535   
     1536  while (!nodeStack.empty())  
     1537        { 
     1538          BspNode *node = nodeStack.top(); 
     1539          nodeStack.pop(); 
     1540           
     1541          if (node->IsLeaf())  
     1542                { 
     1543                  ViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 
     1544                   
     1545                  if (!viewCell->Mailed())  
    15411546                        { 
    1542                                 viewCell->Mail(); 
    1543                                 viewCells.push_back(viewCell); 
     1547                          viewCell->Mail(); 
     1548                          viewCells.push_back(viewCell); 
    15441549                        } 
    15451550                } 
    15461551                else 
    15471552                { 
    1548                         BspInterior *interior = dynamic_cast<BspInterior *>(node); 
    1549  
    1550                         nodeStack.push(interior->GetFront()); 
    1551                         nodeStack.push(interior->GetBack()); 
     1553                  BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     1554                   
     1555                  nodeStack.push(interior->GetFront()); 
     1556                  nodeStack.push(interior->GetBack()); 
    15521557                } 
    15531558        } 
     
    25042509 
    25052510 
     2511ViewCell * 
     2512VspBspTree::GetViewCell(const Vector3 &point) 
     2513{ 
     2514  if (mRoot == NULL) 
     2515        return NULL; 
     2516   
     2517  stack<BspNode *> nodeStack; 
     2518  nodeStack.push(mRoot); 
     2519   
     2520  ViewCell *viewcell = NULL; 
     2521   
     2522  while (!nodeStack.empty())  { 
     2523        BspNode *node = nodeStack.top(); 
     2524        nodeStack.pop(); 
     2525         
     2526        if (node->IsLeaf()) { 
     2527          viewcell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 
     2528          break; 
     2529        } else { 
     2530           
     2531          BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     2532                 
     2533          // random decision 
     2534          if (interior->GetPlane().Side(point) < 0) 
     2535                nodeStack.push(interior->GetBack()); 
     2536          else 
     2537                nodeStack.push(interior->GetFront()); 
     2538        } 
     2539  } 
     2540   
     2541  return viewcell; 
     2542} 
     2543 
     2544 
    25062545int VspBspTree::RefineViewCells(const VssRayContainer &rays) 
    25072546{ 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h

    r491 r492  
    264264        BspNode *CollapseTree(BspNode *node); 
    265265 
     266  ViewCell * 
     267  GetViewCell(const Vector3 &point); 
     268 
    266269        /** Constructs bsp rays for post processing and visualization. 
    267270        */ 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp

    r491 r492  
    351351{ 
    352352 
    353   mSceneGraph->CollectObjects(&mObjects); 
    354353 
    355354  long startTime = GetTime(); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.cpp

    r487 r492  
    139139  point = GetOrigin() + t*dir; 
    140140   
    141   return SqrDistance(point, center) < sqrRadius; 
     141  return ::SqrDistance(point, center) < sqrRadius; 
    142142} 
    143143 
     
    153153{ 
    154154  Vector3 dir = GetNormalizedDir(); 
     155  return GetDirParam(axis, dir); 
     156} 
     157 
     158float 
     159VssRay::GetOpositeDirParametrization(const int axis) const 
     160{ 
     161  Vector3 dir = -GetNormalizedDir(); 
    155162  return GetDirParam(axis, dir); 
    156163} 
     
    217224   
    218225} 
     226 
     227 
     228int 
     229VssRayContainer::SelectRays(const int number, 
     230                                                        VssRayContainer &selected) const 
     231{ 
     232  float p = number/(float)size(); 
     233  VssRayContainer::const_iterator it = begin(); 
     234   
     235  for (; it != end(); it++) 
     236        if (Random(1.0f) < p) 
     237          selected.push_back(*it); 
     238   
     239  return selected.size(); 
     240} 
     241 
     242 
     243int 
     244VssRayContainer::GetContributingRays(VssRayContainer &selected, 
     245                                                                         const int minPass 
     246                                                                         ) const 
     247{ 
     248  VssRayContainer::const_iterator it = begin(); 
     249   
     250  for (; it != end(); it++) { 
     251        VssRay *ray = *it; 
     252        if (ray->mPass >= minPass && ray->mPvsContribution > 0) 
     253          selected.push_back(ray); 
     254  } 
     255  return selected.size(); 
     256} 
     257 
     258 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h

    r467 r492  
    66#include "Vector3.h" 
    77#include "Ray.h" 
     8#include "Containers.h" 
    89 
    910class AxisAlignedBox3; 
     
    4546  Intersectable *mTerminationObject; 
    4647 
     48  ViewCellContainer mViewCells; 
     49   
    4750  //////////////////////// 
    4851  // members related to importance sampling 
     
    5558  // sum of relative ray contributions per object 
    5659  float mRelativePvsContribution; 
     60 
     61 
     62  // weighted contribution to the pvs (based on the pass the ray was casted at) 
     63  // computed by the prperocessor 
     64  float mWeightedPvsContribution; 
    5765   
    5866  ////////////////////////////// 
     
    7179        mRefCount(0), 
    7280    mFlags(0), 
    73         mPass(pass) 
     81        mPass(pass), 
     82        mViewCells(0), 
     83        mWeightedPvsContribution(0) 
    7484        //      mT(1.0f) 
    7585  { 
     
    8292        mMailbox(-1), 
    8393        mOriginObject(ray.sourceObject.mObject), 
    84         mPass(0) 
     94        mPass(0), 
     95        mViewCells(0) 
    8596        //      mT(1.0f) 
    86         { 
    87                 if (ray.sourceObject.mObject) 
    88                         mOrigin = ray.Extrap(ray.sourceObject.mT); 
    89                 else 
    90                         mOrigin = ray.GetLoc();  
    91  
    92                 //Debug << "origin: " << mOrigin << endl; 
    93                 if (!ray.intersections.empty()) 
    94                 { 
    95                         mTermination = ray.Extrap(ray.intersections[0].mT); 
    96                         mTerminationObject = ray.intersections[0].mObject; 
    97                 } 
    98                 else 
    99                 { 
    100                         mTermination = ray.Extrap(1e6);//TODO: should be Limits::Infinity 
    101                         mTerminationObject = NULL; 
    102                 } 
    103  
    104                 Precompute(); 
    105   } 
    106  
     97  { 
     98        if (ray.sourceObject.mObject) 
     99          mOrigin = ray.Extrap(ray.sourceObject.mT); 
     100        else 
     101          mOrigin = ray.GetLoc();  
     102         
     103        //Debug << "origin: " << mOrigin << endl; 
     104        if (!ray.intersections.empty()) 
     105          { 
     106                mTermination = ray.Extrap(ray.intersections[0].mT); 
     107                mTerminationObject = ray.intersections[0].mObject; 
     108          } 
     109        else 
     110          { 
     111                mTermination = ray.Extrap(1e6);//TODO: should be Limits::Infinity 
     112                mTerminationObject = NULL; 
     113          } 
     114         
     115        Precompute(); 
     116  } 
     117   
    107118  void Precompute() { 
    108119    mFlags = 0; 
     
    158169         
    159170  float GetDirParametrization(const int axis) const; 
     171  float GetOpositeDirParametrization(const int axis) const; 
    160172 
    161173  static float VssRay::GetDirParam(const int axis, const Vector3 dir); 
     
    230242  } 
    231243 
     244  friend bool GreaterWeightedPvsContribution(const VssRay * a, 
     245                                                                                         const VssRay *b) { 
     246        return a->mWeightedPvsContribution > b->mWeightedPvsContribution; 
     247  } 
     248 
     249  float SqrDistance(const Vector3 &point) const { 
     250        Vector3 diff = point - mOrigin; 
     251        float t = DotProd(diff, GetDir()); 
     252         
     253    if ( t <= 0.0f ) { 
     254          t = 0.0f; 
     255    } else { 
     256          if (t >= 1.0f) { 
     257                t = 1.0f; 
     258          } else { 
     259        t /= SqrMagnitude(GetDir()); 
     260          } 
     261          diff -= t*GetDir(); 
     262        } 
     263    return SqrMagnitude(diff); 
     264  } 
     265 
    232266}; 
    233267 
     
    272306{ 
    273307  void PrintStatistics(ostream &s); 
     308  int SelectRays(const int number, VssRayContainer &selected) const; 
     309  int 
     310  GetContributingRays(VssRayContainer &selected, 
     311                                          const int minPass 
     312                                          ) const; 
     313   
    274314}; 
    275315 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r486 r492  
    115115    else 
    116116      if ((*ri)->intersections.size()==0) 
    117         b = (*ri)->GetLoc() + length*(*ri)->GetDir(); 
     117                b = (*ri)->GetLoc() + length*(*ri)->GetDir(); 
    118118      else 
    119         b = (*ri)->Extrap((*ri)->intersections[0].mT); 
     119                b = (*ri)->Extrap((*ri)->intersections[0].mT); 
    120120     
    121121    stream<<a.x<<" "<<a.y<<" "<<a.z<<" ,"; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/default.env

    r467 r492  
    1515# filename ../data/atlanta/atlanta2.x3d 
    1616# filename ../data/soda/soda.dat 
    17  filename ../data/soda/soda5.dat 
     17filename ../data/soda/soda5.dat 
    1818} 
    1919 
     
    2222#       type vss 
    2323        type rss 
     24        useGlRenderer true 
    2425} 
    2526 
     
    6667        initialSamples 500000 
    6768        vssSamples 10000000 
    68         vssSamplesPerPass 100000 
     69        vssSamplesPerPass 500000 
    6970        useImportanceSampling true 
     71 
     72        directionalSampling true 
     73        objectBasedSampling false 
    7074 
    7175        Export { 
     
    7781 
    7882        useViewcells true 
    79         updateSubdivision false 
     83        updateSubdivision true 
    8084} 
    8185 
     
    8892        minRays         30 
    8993        minSize         0.001 
    90         maxCostRatio    0.9 
    91         maxRayContribution 0.1 
    92          
     94        maxCostRatio 1.0 
     95        maxRayContribution 0.5 
     96        maxRays         1000000 
    9397        maxTotalMemory  200 
    9498        maxStaticMemory 100 
     
    97101#       splitType heuristic 
    98102        splitType hybrid 
    99         splitUseOnlyDrivingAxis false 
     103        splitUseOnlyDrivingAxis true 
     104        importanceBasedCost false 
    100105 
    101106        interleaveDirSplits     true 
     
    157162        #type kdTree 
    158163        #type vspKdTree 
    159         #type bspTree 
     164        # type bspTree 
    160165        type vspBspTree 
    161166         
     
    184189} 
    185190 
    186 BspTree { 
    187         Construction { 
    188                 samples 50000 
    189                 epsilon 0.005 
    190         } 
    191  
    192         # random polygon       = 1 
    193         # axis aligned         = 2 
    194         # least splits         = 4 
    195         # balanced polygons    = 8 
    196         # balanced view cells  = 16 
    197         # largest polygon area = 32 
    198         # vertical axis        = 64 
    199         # blocked rays         = 128 
    200         # least ray splits     = 256 
    201         # balanced rays        = 512 
    202         # pvs                  = 1024 
    203  
    204         # least splits + balanced polygons 
    205         #splitPlaneStrategy 12 
    206          
    207         #axis aligned + vertical axis 
    208         #splitPlaneStrategy 66 
    209          
    210         # axis aligned + balanced view cells 
    211         # splitPlaneStrategy 18 
    212          
    213         # largest polygon area 
    214         #splitPlaneStrategy 32 
    215          
    216         # axus aligned + balanced polygons 
    217         #splitPlaneStrategy 72 
    218          
    219         # axis aligned + blocked rays 
    220         #splitPlaneStrategy 130 
    221          
    222         #splitPlaneStrategy 384 
    223         #splitPlaneStrategy 130 
    224          
    225         splitPlaneStrategy 1024 
    226          
    227         maxPolyCandidates 50 
    228         maxRayCandidates 50 
    229          
    230         maxTests 10000 
    231          
    232         # factors for evaluating split plane costs 
    233         Factor { 
    234                 verticalSplits 1.0 
    235                 largestPolyArea 1.0 
    236                 blockedRays 1.0 
    237                 leastRaySplits 1.0 
    238                 balancedRays 1.0 
    239                 pvs 1.0 
    240                 leastSplits 1.0 
    241                 balancedPolys 1.0 
    242                 balancedViewCells 1.0 
    243         } 
    244          
    245         Termination { 
    246                 # parameters used for autopartition 
    247                 minRays 200 
    248                 minPolygons -1 
    249                 maxDepth 40 
    250                 minPvs 100 
    251                 minArea 0.01 
    252                 maxRayContribution 0.005 
    253                 #maxAccRayLength 100 
    254                  
    255                 # used for pvs criterium 
    256                 ct_div_ci 0.0 
    257                  
    258                 # axis aligned splits 
    259                 AxisAligned { 
    260                         minPolys 5000 
    261                         minRays 500 
    262                         minObjects 10 
    263                         maxCostRatio 0.9 
    264                         ct_div_ci 0.5 
    265                 } 
    266         } 
    267          
    268         AxisAligned { 
    269                 splitBorder 0.01 
    270         } 
    271          
    272                  
    273         Visualization { 
    274         # x3d visualization of the split planes 
    275         exportSplits true 
    276         } 
    277 } 
    278191 
    279192Simulation { 
     
    355268                        minRays 500 
    356269                        minObjects 10 
    357                         maxCostRatio 0.9 
    358                         ct_div_ci 0.5 
     270#                       maxCostRatio 0.9 
     271#                       ct_div_ci 0.5 
    359272                } 
    360273        } 
    361274         
    362         AxisAligned { 
    363                 splitBorder 0.01 
    364         } 
     275#       AxisAligned { 
     276#               splitBorder 0.01 
     277#       } 
    365278         
    366279         
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r487 r492  
    1313#include "ViewCell.h" 
    1414#include "SceneGraph.h" 
     15#include "PreprocessorThread.h" 
     16 
     17#include <QApplication> 
     18#include <QtOpenGL> 
     19#include "GlRenderer.h" 
    1520 
    1621#define USE_EXE_PATH false 
    1722 
    1823 
     24 
     25 
     26 
    1927int 
    20 main(int argc, const char **argv) 
     28main(int argc, char **argv) 
    2129{ 
    2230  Debug.open("debug.log"); 
     
    2432  environment->Parse(argc, argv, USE_EXE_PATH); 
    2533  MeshKdTree::ParseEnvironment(); 
    26     
     34   
    2735  char buff[128]; 
    2836  environment->GetStringValue("Preprocessor.type", buff); 
     
    4856                } 
    4957   
     58  preprocessor = p; 
    5059   
    51         environment->GetStringValue("Scene.filename", buff); 
    52         string filename(buff); 
    53          
    54         p->LoadScene(filename); 
    55          
    56         p->BuildKdTree(); 
    57         p->KdTreeStatistics(cout); 
    58          
    59         // parse view cells related options 
    60         p->PrepareViewCells(); 
     60  environment->GetStringValue("Scene.filename", buff); 
     61  string filename(buff); 
     62  p->LoadScene(filename); 
     63   
     64  p->BuildKdTree(); 
     65  p->KdTreeStatistics(cout); 
     66   
     67  // parse view cells related options 
     68  p->PrepareViewCells(); 
     69   
     70 
     71  // create a preprocessor thread 
     72  PreprocessorThread *pt = new PreprocessorThread(p); 
    6173 
    6274  //  p->mSceneGraph->Export("soda.x3d"); 
     
    6577    p->Export(filename + "-kdtree.x3d", false, true, false);     
    6678  } 
     79 
     80  if (p->mUseGlRenderer) { 
     81        QApplication a(argc, argv); 
     82         
     83        if (!QGLFormat::hasOpenGL() || !QGLPbuffer::hasPbuffers()) { 
     84          QMessageBox::information(0, "OpenGL pbuffers",  
     85                                                           "This system does not support OpenGL/pbuffers.", 
     86                                                           QMessageBox::Ok); 
     87          return -1; 
     88        } 
     89         
     90        renderer = new GlRenderer(p->mSceneGraph, p->mViewCellsManager); 
     91        //  renderer->resize(640, 480); 
     92        renderer->resize(1024, 768); 
     93        renderer->show(); 
     94         
     95         
     96        pt->start(QThread::LowPriority); 
     97         
     98        return a.exec(); 
     99  } else { 
     100        // just call the mail method -> will be executed in the main thread 
     101        pt->Main(); 
     102  } 
    67103   
    68     
    69   if (1) { 
    70     p->ComputeVisibility(); 
    71     p->ExportPreprocessedData("scene.vis"); 
    72   } 
    73  
    74         Camera camera; 
    75   if (0) { 
    76     //camera.LookAtBox(p->mKdTree->GetBox()); 
    77                 camera.LookInBox(p->mKdTree->GetBox()); 
    78                 camera.SetPosition(camera.mPosition + Vector3(0,300,0)); 
    79     camera.SnapImage("camera.jpg", p->mKdTree); 
    80         } 
    81         if (0) { 
    82     camera.LookInBox(p->mKdTree->GetBox()); 
    83     camera.SetPosition(camera.mPosition - Vector3(0,100,0)); 
    84     camera.SnapImage("camera2.jpg", p->mKdTree); 
    85   } 
    86  
    87         if (0) { 
    88     camera.SetPosition( p->mKdTree->GetBox().Center() - Vector3(0,-100,0) ); 
    89                 camera.SetDirection(Vector3(1, 0, 0)); 
    90                 camera.SnapImage("camera3.jpg", p->mKdTree); 
    91   } 
    92  
    93104  // clean up 
    94   DEL_PTR(p); 
    95   DEL_PTR(environment); 
     105  //  DEL_PTR(p); 
     106  //  DEL_PTR(environment); 
    96107 
    97108  return 0; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro

    r463 r492  
    1616 
    1717# debuc config 
    18 CONFIG          += console warn_off thread release 
     18CONFIG          += console warn_off thread release qt 
    1919 
    2020# RELEASE CONFIG 
     
    2323# DEPENDPATH    = ../../include 
    2424 
     25QT += opengl 
     26 
    2527win32:LIBS += xerces-c_2.lib devil.lib ilu.lib ilut.lib 
    2628unix:LIBS += -lxerces-c -lIL -lILU -lILUT 
    2729 
    2830# Input 
    29 HEADERS += Halton.h VssRay.h VssPreprocessor.h RssTree.h 
     31HEADERS += Halton.h VssRay.h VssPreprocessor.h RssTree.h GlRenderer.h \ 
     32PreprocessorThread.h Preprocessor.h 
    3033 
    3134 
     
    3942ViewCell.cpp ViewCellBsp.cpp Halton.cpp VssRay.cpp VssTree.cpp VssPreprocessor.cpp \ 
    4043RenderSimulator.cpp VspKdTree.cpp RayInfo.cpp RssTree.cpp RssPreprocessor.cpp \ 
    41 ViewCellsManager.cpp VspBspTree.cpp 
     44ViewCellsManager.cpp VspBspTree.cpp GlRenderer.cpp \ 
     45PreprocessorThread.cpp Renderer.cpp 
    4246 
Note: See TracChangeset for help on using the changeset viewer.