Changeset 492 for trunk/VUT/GtpVisibilityPreprocessor
- Timestamp:
- 01/03/06 23:33:45 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 4 added
- 38 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp
r486 r492 301 301 maxx = t1; 302 302 } 303 if (maxx < 0.0)304 return 0;303 // if (maxx < 0.0) 304 // return 0; 305 305 } 306 306 … … 327 327 maxx = t1; 328 328 } 329 if (maxx < 0.0)330 return 0;329 // if (maxx < 0.0) 330 // return 0; 331 331 } 332 332 … … 355 355 maxx = t1; 356 356 } 357 if (maxx < 0.0)358 return 0;357 // if (maxx < 0.0) 358 // return 0; 359 359 } 360 360 … … 1774 1774 1775 1775 1776 // Compute tmin and tmax for a ray, whenever required .. need not pierce box 1777 int 1778 AxisAlignedBox3::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 1776 1909 bool AxisAlignedBox3::GetIntersectionFace(Rectangle3 &face, 1777 1910 const AxisAlignedBox3 &neighbour) const -
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h
r487 r492 68 68 } 69 69 70 70 71 void SetMin(const Vector3 &v) { 71 72 mMin = v; … … 142 143 bool IsPoint() const; 143 144 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 144 152 void 145 153 GetSqrDistances(const Vector3 &point, … … 181 189 RandomValue(0, size.z)); 182 190 } 183 191 192 193 Vector3 GetPoint(const Vector3 &p) const { 194 return mMin + p*Size(); 195 } 196 184 197 // Returns the smallest axis-aligned box that includes all points 185 198 // inside the two given boxes. … … 208 221 ID_Right = 4, ID_Top = 5}; 209 222 223 int 224 ComputeMinMaxT(const Vector3 &origin, 225 const Vector3 &direction, 226 float *tmin, 227 float *tmax) const; 228 210 229 // Compute tmin and tmax for a ray, whenever required .. need not pierce box 211 230 int ComputeMinMaxT(const Ray &ray, float *tmin, float *tmax) const; 212 231 213 232 // 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; 216 238 217 239 // If a ray pierces the box .. returns 1, otherwise 0. -
trunk/VUT/GtpVisibilityPreprocessor/src/Camera.cpp
r466 r492 11 11 #include "Mesh.h" 12 12 #include "Exporter.h" 13 #include "SceneGraph.h" 13 14 14 15 … … 33 34 bool 34 35 Camera::SnapImage(string filename, 35 KdTree *tree 36 ) 36 KdTree *tree, 37 SceneGraph *sceneGraph 38 ) 37 39 { 38 40 int x; … … 59 61 SetupRay(ray, x, mHeight - (y + 1)); 60 62 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 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 } 74 76 pbuffer+=components; 75 77 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 } 80 84 } 81 85 // pbuffer-=2*components*mWidth; … … 85 89 cout<<"#RAY_CAST_TIME\n"; 86 90 cout<<TimeDiff(t1, t2)<<"\n"; 87 91 88 92 89 93 cout<<"Saving image"<<endl; 90 94 91 95 ilRegisterType(IL_FLOAT); 92 96 ilTexImage(mWidth, mHeight, 1, 4, IL_RGBA, IL_FLOAT, buffer); 93 97 ilSaveImage((char *const)filename.c_str()); 94 98 delete buffer; 99 100 cout<<"done."<<endl<<flush; 95 101 96 102 Exporter *exporter = NULL; 97 if ( exportRays) {103 if (1) { 98 104 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); 103 112 exporter->SetFilled(); 104 113 int k =0; 105 114 for (int j=0; j < rays.size(); j++) 106 115 if (rays[j]->kdLeaves.size()) { 107 108 109 if (1)110 111 112 113 114 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 116 125 } 117 126 118 127 delete exporter; 119 128 } 120 121 129 122 130 return true; -
trunk/VUT/GtpVisibilityPreprocessor/src/Camera.h
r469 r492 6 6 7 7 class KdTree; 8 class SceneGraph; 8 9 9 10 class Camera … … 22 23 23 24 Camera() { 24 mWidth = 640;25 mHeight = 480;25 mWidth = 1400; 26 mHeight = 1000; 26 27 mFovy = 60.0f*(float)M_PI/180.0f; 27 28 } … … 63 64 64 65 bool 65 SnapImage(string filename, KdTree *tree); 66 SnapImage(string filename, 67 KdTree *tree, 68 SceneGraph *sceneGraph 69 ); 66 70 67 71 void SetupRay(Ray &ray, const int x, const int y); -
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r490 r492 49 49 bool 50 50 Environment::CheckForSwitch(const int argc, 51 const char *argv[],52 51 char **argv, 52 const char swtch) const 53 53 { 54 54 for (int i = 1; i < argc; i++) … … 130 130 void 131 131 Environment::ReadCmdlineParams(const int argc, 132 const char *argv[],133 const char *optParams)132 char **argv, 133 const char *optParams) 134 134 { 135 135 int i; … … 619 619 void 620 620 Environment::ParseCmdline(const int argc, 621 const char *argv[],622 621 char **argv, 622 const int index) 623 623 { 624 624 int curIndex = -1; … … 1064 1064 1065 1065 RegisterOption("Scene.filename", 1066 optString,1067 "-scene_filename=",1068 "atlanta2.x3d");1066 optString, 1067 "scene_filename=", 1068 "atlanta2.x3d"); 1069 1069 1070 1070 RegisterOption("Unigraphics.meshGrouping", 1071 optInt,1072 "-unigraphics_mesh_grouping=",1073 "0");1071 optInt, 1072 "unigraphics_mesh_grouping=", 1073 "0"); 1074 1074 1075 1075 1076 1076 RegisterOption("KdTree.Termination.minCost", 1077 optInt,1078 "-kd_term_min_cost=",1079 "10");1077 optInt, 1078 "kd_term_min_cost=", 1079 "10"); 1080 1080 1081 1081 RegisterOption("KdTree.Termination.maxDepth", 1082 optInt,1083 "-kd_term_max_depth=",1084 "20");1082 optInt, 1083 "kd_term_max_depth=", 1084 "20"); 1085 1085 1086 1086 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"); 1090 1090 1091 1091 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"); 1095 1095 1096 1096 RegisterOption("KdTree.splitMethod", 1097 optString,1098 "-kd_split_method=",1099 "spatialMedian");1097 optString, 1098 "kd_split_method=", 1099 "spatialMedian"); 1100 1100 1101 1101 RegisterOption("KdTree.splitBorder", 1102 1102 optFloat, 1103 " -kd_split_border=",1103 "kd_split_border=", 1104 1104 "0.1"); 1105 1105 1106 1106 RegisterOption("KdTree.sahUseFaces", 1107 1107 optBool, 1108 " -kd_sah_use_faces=",1108 "kd_sah_use_faces=", 1109 1109 "true"); 1110 1110 … … 1112 1112 RegisterOption("MeshKdTree.Termination.minCost", 1113 1113 optInt, 1114 " -kd_term_min_cost=",1114 "kd_term_min_cost=", 1115 1115 "10"); 1116 1116 1117 1117 RegisterOption("MeshKdTree.Termination.maxDepth", 1118 1118 optInt, 1119 " -kd_term_max_depth=",1119 "kd_term_max_depth=", 1120 1120 "20"); 1121 1121 1122 1122 RegisterOption("MeshKdTree.Termination.maxCostRatio", 1123 1123 optFloat, 1124 " -kd_term_max_cost_ratio=",1124 "kd_term_max_cost_ratio=", 1125 1125 "1.5"); 1126 1126 1127 1127 RegisterOption("MeshKdTree.Termination.ct_div_ci", 1128 1128 optFloat, 1129 " -kd_term_ct_div_ci=",1129 "kd_term_ct_div_ci=", 1130 1130 "1.0"); 1131 1131 1132 1132 RegisterOption("MeshKdTree.splitMethod", 1133 1133 optString, 1134 " -kd_split_method=",1134 "kd_split_method=", 1135 1135 "spatialMedian"); 1136 1136 1137 1137 RegisterOption("MeshKdTree.splitBorder", 1138 1138 optFloat, 1139 " -kd_split_border=",1139 "kd_split_border=", 1140 1140 "0.1"); 1141 1141 1142 1142 RegisterOption("Sampling.totalSamples", 1143 1143 optInt, 1144 " -total_samples=",1144 "total_samples=", 1145 1145 "1000000"); 1146 1146 1147 1147 RegisterOption("Sampling.samplesPerPass", 1148 1148 optInt, 1149 " -samples_per_pass=",1149 "samples_per_pass=", 1150 1150 "10"); 1151 1151 1152 1152 RegisterOption("VssPreprocessor.initialSamples", 1153 1154 "-initial_samples=",1155 1156 1153 optInt, 1154 "initial_samples=", 1155 "100000"); 1156 1157 1157 RegisterOption("VssPreprocessor.vssSamples", 1158 1159 "-vss_samples=",1160 1158 optInt, 1159 "vss_samples=", 1160 "1000000"); 1161 1161 1162 1162 RegisterOption("VssPreprocessor.vssSamplesPerPass", 1163 1164 "-vss_samples_per_pass=",1165 1166 1163 optInt, 1164 "vss_samples_per_pass=", 1165 "1000"); 1166 1167 1167 RegisterOption("VssPreprocessor.samplesPerPass", 1168 optInt, 1169 "-samples_per_pass=", 1170 "100000"); 1168 optInt, 1169 "samples_per_pass=", 1170 "100000"); 1171 1171 1172 1172 1173 1173 1174 RegisterOption("VssPreprocessor.useImportanceSampling", 1174 1175 "-vss_use_importance=",1176 1175 optBool, 1176 "vss_use_importance=", 1177 "true"); 1177 1178 1178 1179 RegisterOption("VssPreprocessor.loadInitialSamples", … … 1194 1195 RegisterOption("ViewCells.type", 1195 1196 optString, 1196 " -view_cells_type",1197 "view_cells_type", 1197 1198 "bspTree"); 1198 1199 1199 1200 RegisterOption("ViewCells.PostProcess.samples", 1200 1201 "-view_cells_postprocess_samples=",1202 1203 1201 optInt, 1202 "view_cells_postprocess_samples=", 1203 "200000"); 1204 1204 1205 RegisterOption("ViewCells.Visualization.samples", 1205 1206 "-view_cells_visualization_samples=",1207 1208 1206 optInt, 1207 "view_cells_visualization_samples=", 1208 "20000"); 1209 1209 1210 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 1214 1215 RegisterOption("ViewCells.maxViewCells", 1215 1216 optInt, 1216 " -view_cells_max_view_cells",1217 "view_cells_max_view_cells=", 1217 1218 "0"); 1218 1219 1219 1220 1220 1221 RegisterOption("ViewCells.maxPvs", 1221 optInt,1222 "-view_cells_max_pvs",1223 "300");1222 optInt, 1223 "view_cells_max_pvs=", 1224 "300"); 1224 1225 1225 1226 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"); 1229 1230 1230 1231 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"); 1234 1235 1235 1236 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 1240 1241 RegisterOption("ViewCells.filename", 1241 1242 optString, 1242 " -view_cells_filename=",1243 "view_cells_filename=", 1243 1244 "atlanta_viewcells_large.x3d"); 1244 1245 1245 1246 RegisterOption("ViewCells.height", 1246 1247 optFloat, 1247 " -view_cells_height=",1248 "view_cells_height=", 1248 1249 "5.0"); 1249 1250 … … 1270 1271 RegisterOption("Simulation.objRenderCost", 1271 1272 optFloat, 1272 " -simulation_obj_render_cost",1273 "simulation_obj_render_cost", 1273 1274 "1.0"); 1274 1275 1275 1276 RegisterOption("Simulation.vcOverhead", 1276 1277 optFloat, 1277 " -simulation_vc_overhead",1278 "simulation_vc_overhead", 1278 1279 "0.05"); 1279 1280 1280 1281 RegisterOption("Simulation.moveSpeed", 1281 1282 optFloat, 1282 " -simulation_moveSpeed",1283 "simulation_moveSpeed", 1283 1284 "1.0"); 1284 1285 … … 1293 1294 RegisterOption("BspTree.Construction.input", 1294 1295 optString, 1295 " -bsp_construction_input=",1296 "bsp_construction_input=", 1296 1297 "fromViewCells"); 1297 1298 1298 1299 RegisterOption("BspTree.Construction.samples", 1299 1300 optInt, 1300 " -bsp_construction_samples=",1301 "bsp_construction_samples=", 1301 1302 "100000"); 1302 1303 1303 1304 RegisterOption("BspTree.Construction.epsilon", 1304 1305 optFloat, 1305 " -bsp_construction_side_tolerance=",1306 "bsp_construction_side_tolerance=", 1306 1307 "0.002"); 1307 1308 1308 1309 RegisterOption("BspTree.Termination.minPolygons", 1309 1310 optInt, 1310 " -bsp_term_min_polygons=",1311 "bsp_term_min_polygons=", 1311 1312 "5"); 1312 1313 1313 1314 RegisterOption("BspTree.Termination.minPvs", 1314 1315 optInt, 1315 " -bsp_term_min_pvs=",1316 "bsp_term_min_pvs=", 1316 1317 "20"); 1317 1318 1318 1319 RegisterOption("BspTree.Termination.minArea", 1319 1320 optFloat, 1320 " -bsp_term_min_area=",1321 "bsp_term_min_area=", 1321 1322 "0.001"); 1322 1323 1323 1324 RegisterOption("BspTree.Termination.maxRayContribution", 1324 1325 optFloat, 1325 " -bsp_term_ray_contribution=",1326 "bsp_term_ray_contribution=", 1326 1327 "0.005"); 1327 1328 1328 1329 RegisterOption("BspTree.Termination.minAccRayLenght", 1329 1330 optFloat, 1330 " -bsp_term_min_acc_ray_length=",1331 "bsp_term_min_acc_ray_length=", 1331 1332 "50"); 1332 1333 1333 1334 RegisterOption("BspTree.Termination.minRays", 1334 1335 optInt, 1335 " -bsp_term_min_rays=",1336 "bsp_term_min_rays=", 1336 1337 "-1"); 1337 1338 1338 1339 RegisterOption("BspTree.Termination.ct_div_ci", 1339 1340 optFloat, 1340 " -bsp_term_ct_div_ci=",1341 "bsp_term_ct_div_ci=", 1341 1342 "0.0"); 1342 1343 1343 1344 RegisterOption("BspTree.Termination.maxDepth", 1344 1345 optInt, 1345 " -bsp_term_max_depth=",1346 "bsp_term_max_depth=", 1346 1347 "100"); 1347 1348 1348 1349 RegisterOption("BspTree.Termination.maxCostRatio", 1349 1350 optFloat, 1350 " -bsp_term_axis_aligned_max_cost_ratio=",1351 "bsp_term_axis_aligned_max_cost_ratio=", 1351 1352 "1.5"); 1352 1353 1353 1354 RegisterOption("BspTree.Termination.AxisAligned.ct_div_ci", 1354 1355 optFloat, 1355 " -bsp_term_axis_aligned_ct_div_ci=",1356 "bsp_term_axis_aligned_ct_div_ci=", 1356 1357 "0.5"); 1357 1358 1358 1359 RegisterOption("BspTree.AxisAligned.splitBorder", 1359 1360 optFloat, 1360 " -bsp__axis_aligned_split_border=",1361 "bsp__axis_aligned_split_border=", 1361 1362 "0.1"); 1362 1363 1363 1364 RegisterOption("BspTree.Termination.AxisAligned.minPolys", 1364 1365 optInt, 1365 " -bsp_term_axis_aligned_max_polygons=",1366 "bsp_term_axis_aligned_max_polygons=", 1366 1367 "50"); 1367 1368 1368 1369 RegisterOption("BspTree.Termination.AxisAligned.minObjects", 1369 1370 optInt, 1370 " -bsp_term_min_objects=",1371 "bsp_term_min_objects=", 1371 1372 "3"); 1372 1373 1373 1374 RegisterOption("BspTree.Termination.AxisAligned.minRays", 1374 1375 optInt, 1375 " -bsp_term_axis_aligned_min_rays=",1376 "bsp_term_axis_aligned_min_rays=", 1376 1377 "-1"); 1377 1378 1378 1379 RegisterOption("BspTree.splitPlaneStrategy", 1379 1380 optString, 1380 " -bsp_split_method=",1381 "bsp_split_method=", 1381 1382 "leastSplits"); 1382 1383 1383 1384 RegisterOption("BspTree.maxPolyCandidates", 1384 1385 optInt, 1385 " -bsp_max_poly_candidates=",1386 "bsp_max_poly_candidates=", 1386 1387 "20"); 1387 1388 1388 1389 RegisterOption("BspTree.maxRayCandidates", 1389 1390 optInt, 1390 " -bsp_max_plane_candidates=",1391 "bsp_max_plane_candidates=", 1391 1392 "20"); 1392 1393 1393 1394 RegisterOption("BspTree.maxTests", 1394 1395 optInt, 1395 " -bsp_max_tests=",1396 "bsp_max_tests=", 1396 1397 "5000"); 1397 1398 1398 1399 RegisterOption("BspTree.Visualization.exportSplits", 1399 1400 optBool, 1400 " -bsp_visualization.export_splits",1401 "bsp_visualization.export_splits", 1401 1402 "false"); 1402 1403 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"); 1413 1413 1414 1414 /************************************************************************************/ … … 1418 1418 RegisterOption("Preprocessor.type", 1419 1419 optString, 1420 " -preprocessor=",1420 "preprocessor=", 1421 1421 "sampling"); 1422 1422 … … 1426 1426 "rays.out"); 1427 1427 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 /**************************************************************************************/ 1431 1436 1432 1437 RegisterOption("VspKdTree.Construction.samples", 1433 1434 "-vsp_kd_construction_samples=",1435 1438 optInt, 1439 "vsp_kd_construction_samples=", 1440 "100000"); 1436 1441 1437 1442 RegisterOption("VspKdTree.Termination.maxDepth", … … 1525 1530 RegisterOption("VspKdTree.PostProcess.maxCostRatio", 1526 1531 optFloat, 1527 " -vsp_kd_post_process_max_cost_ratio=",1532 "vsp_kd_post_process_max_cost_ratio=", 1528 1533 "0.9"); 1529 1534 … … 1568 1573 RegisterOption("VssTree.queryType", optString, "qtype=", "static"); 1569 1574 1575 1570 1576 RegisterOption("VssTree.queryPosWeight", optFloat, "qposweight=", "0.0"); 1571 1577 RegisterOption("VssTree.useRefDirSplits", optBool, "refdir", "false"); … … 1581 1587 RegisterOption("RssPreprocessor.initialSamples", 1582 1588 optInt, 1583 " -initial_samples=",1589 "initial_samples=", 1584 1590 "100000"); 1585 1591 1586 1592 RegisterOption("RssPreprocessor.vssSamples", 1587 1588 "-vss_samples=",1589 1590 1593 optInt, 1594 "rss_vss_samples=", 1595 "1000000"); 1596 1591 1597 RegisterOption("RssPreprocessor.vssSamplesPerPass", 1592 1593 "-vss_samples_per_pass=",1594 1595 1596 1597 1598 "-samples_per_pass=",1599 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 1601 1607 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 1606 1622 RegisterOption("RssTree.maxDepth", optInt, "kd_depth=", "12"); 1607 1623 RegisterOption("RssTree.minPvs", optInt, "kd_minpvs=", "1"); … … 1609 1625 RegisterOption("RssTree.maxCostRatio", optFloat, "maxcost=", "0.95"); 1610 1626 RegisterOption("RssTree.maxRayContribution", optFloat, "maxraycontrib=", "0.5"); 1611 1627 1612 1628 RegisterOption("RssTree.epsilon", optFloat, "kd_eps=", "1e-6"); 1613 1629 RegisterOption("RssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0"); … … 1615 1631 RegisterOption("RssTree.splitType", optString, "split=", "queries"); 1616 1632 RegisterOption("RssTree.splitUseOnlyDrivingAxis", optBool, "splitdriving=", "false"); 1617 1633 1618 1634 RegisterOption("RssTree.numberOfEndPointDomains", optInt, "endpoints=", "10000"); 1619 1635 1620 1636 RegisterOption("RssTree.minSize", optFloat, "minsize=", "0.001"); 1621 1637 1622 1638 RegisterOption("RssTree.maxTotalMemory", optFloat, "mem=", "60.0"); 1623 1639 RegisterOption("RssTree.maxStaticMemory", optFloat, "statmem=", "8.0"); 1624 1640 1625 1641 RegisterOption("RssTree.queryType", optString, "qtype=", "static"); 1626 1642 1627 1643 RegisterOption("RssTree.queryPosWeight", optFloat, "qposweight=", "0.0"); 1628 1644 RegisterOption("RssTree.useRefDirSplits", optBool, "refdir", "false"); … … 1631 1647 RegisterOption("RssTree.accessTimeThreshold", optInt, "accesstime=", "1000"); 1632 1648 RegisterOption("RssTree.minCollapseDepth", optInt, "colldepth=", "4"); 1633 1649 1634 1650 RegisterOption("RssTree.interleaveDirSplits", optBool, "interleavedirsplits", "true"); 1635 1651 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 1637 1655 RegisterOption("RssPreprocessor.Export.pvs", optBool, "rss_export_pvs", "false"); 1638 1656 RegisterOption("RssPreprocessor.Export.rssTree", optBool, "rss_export_rss_tree", "false"); … … 1641 1659 RegisterOption("RssPreprocessor.useViewcells", optBool, "rss_use_viewcells", "false"); 1642 1660 RegisterOption("RssPreprocessor.updateSubdivision", optBool, "rss_update_subdivision", "false"); 1661 1662 1663 /************************************************************************************/ 1664 /* View space partition BSP tree related options */ 1665 /************************************************************************************/ 1666 1643 1667 1644 1668 RegisterOption("RssPreprocessor.loadInitialSamples", 1645 optBool,1646 "-vss_load_loadInitialSamples=",1647 "false");1669 optBool, 1670 "vss_load_loadInitialSamples=", 1671 "false"); 1648 1672 1649 1673 RegisterOption("RssPreprocessor.storeInitialSamples", 1650 optBool,1651 "-vss_store_storeInitialSamples=",1652 "false");1674 optBool, 1675 "vss_store_storeInitialSamples=", 1676 "false"); 1653 1677 1654 1678 /************************************************************************************/ 1655 1679 /* View space partition BSP tree related options */ 1656 1680 /************************************************************************************/ 1657 1658 1681 RegisterOption("VspBspTree.Termination.minPolygons", 1659 optInt,1660 "-vsp_bsp_term_min_polygons=",1661 "5");1682 optInt, 1683 "vsp_bsp_term_min_polygons=", 1684 "5"); 1662 1685 1663 1686 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"); 1668 1690 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"); 1672 1694 1673 1695 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"); 1677 1699 1678 1700 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"); 1682 1704 1683 1705 RegisterOption("VspBspTree.Termination.minRays", 1684 optInt,1685 "-vsp_bsp_term_min_rays=",1686 "-1");1706 optInt, 1707 "vsp_bsp_term_min_rays=", 1708 "-1"); 1687 1709 1688 1710 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"); 1692 1714 1693 1715 RegisterOption("VspBspTree.Termination.maxDepth", 1694 optInt,1695 "-vsp_bsp_term_max_depth=",1696 "100");1716 optInt, 1717 "vsp_bsp_term_max_depth=", 1718 "100"); 1697 1719 1698 1720 RegisterOption("VspBspTree.Termination.AxisAligned.maxCostRatio", … … 1712 1734 1713 1735 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"); 1718 1739 RegisterOption("VspBspTree.splitPlaneStrategy", 1719 optString,1720 "-vsp_bsp_split_method=",1721 "leastSplits");1740 optString, 1741 "vsp_bsp_split_method=", 1742 "leastSplits"); 1722 1743 1723 1744 RegisterOption("VspBspTree.maxPolyCandidates", 1724 optInt, 1725 "-vsp_bsp_max_poly_candidates=", 1726 "20"); 1727 1745 optInt, 1746 "vsp_bsp_max_poly_candidates=", 1747 "20"); 1728 1748 RegisterOption("VspBspTree.maxRayCandidates", 1729 optInt,1730 "-vsp_bsp_max_plane_candidates=",1731 "20");1749 optInt, 1750 "vsp_bsp_max_plane_candidates=", 1751 "20"); 1732 1752 1733 1753 RegisterOption("VspBspTree.maxTests", 1734 optInt,1735 "-vsp_bsp_max_tests=",1736 "5000");1754 optInt, 1755 "vsp_bsp_max_tests=", 1756 "5000"); 1737 1757 1738 1758 RegisterOption("VspBspTree.Construction.samples", 1739 optInt,1740 "-bsp_construction_samples=",1741 "100000");1759 optInt, 1760 "bsp_construction_samples=", 1761 "100000"); 1742 1762 1743 1763 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"); 1747 1767 1748 1768 RegisterOption("VspBspTree.Visualization.exportSplits", 1749 optBool,1750 "-vsp_bsp_visualization.export_splits",1751 "false");1769 optBool, 1770 "vsp_bsp_visualization.export_splits", 1771 "false"); 1752 1772 1753 1773 RegisterOption("VspBspTree.splitUseOnlyDrivingAxis", 1754 optBool, 1755 "vsp_bsp_splitdriving=", 1756 "false"); 1757 1758 1774 optBool, 1775 "vsp_bsp_splitdriving=", 1776 "false"); 1777 1759 1778 RegisterOption("VspBspTree.Factor.leastRaySplits", optFloat, "-vsp_bsp_factor_least_ray_splits=", "1.0"); 1760 1779 RegisterOption("VspBspTree.Factor.balancedRays", optFloat, "-vsp_bsp_factor_balanced_rays=", "1.0"); … … 1801 1820 1802 1821 void 1803 Environment::Parse(const int argc, c onst char *argv[], bool useExePath)1822 Environment::Parse(const int argc, char **argv, bool useExePath) 1804 1823 { 1805 1824 -
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.h
r372 r492 206 206 */ 207 207 bool CheckForSwitch(const int argc, 208 const char *argv[],209 208 char **argv, 209 const char swtch) const; 210 210 /** First pass of parsing command line. 211 211 This function parses command line and gets from there all non-optional … … 220 220 */ 221 221 void ReadCmdlineParams(const int argc, 222 const char *argv[],223 const char *optParams);222 char **argv, 223 const char *optParams); 224 224 /** Reading of the environment file. 225 225 This function reads the environment file. … … 236 236 be read in. 237 237 */ 238 void ParseCmdline(const int argc, c onst char *argv[], const int index);238 void ParseCmdline(const int argc, char **argv, const int index); 239 239 240 240 /** Clears the environment data structures. … … 335 335 //@} 336 336 337 void Parse(const int argc, c onst char *argv[], bool useExePath);337 void Parse(const int argc, char **argv, bool useExePath); 338 338 339 339 void -
trunk/VUT/GtpVisibilityPreprocessor/src/Halton.cpp
r355 r492 5 5 6 6 Halton2 halton2; 7 float Halton2::_invBases[2]; -
trunk/VUT/GtpVisibilityPreprocessor/src/Halton.h
r355 r492 2 2 #define __HALTON_H 3 3 4 #include <iostream> 5 using namespace std; 6 4 7 class 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 24 public: 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 }; 8 44 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 */ 50 inline 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; 19 56 } 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 */ 68 inline 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 84 struct HaltonSequence { 21 85 public: 86 int index; 22 87 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; 25 123 } 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); 31 127 } 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 } 40 129 }; 41 130 -
trunk/VUT/GtpVisibilityPreprocessor/src/Intersectable.h
r387 r492 5 5 #include "Pvs.h" 6 6 7 class VssRayContainer; 7 8 8 9 class Intersectable { … … 54 55 virtual float IntersectionComplexity() = 0; 55 56 56 57 virtual int NumberOfFaces() const = 0; 57 58 58 59 59 virtual int Type() const = 0; 60 60 61 virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0; 61 62 63 64 65 62 63 virtual int 64 GetRandomVisibleSurfacePoint(Vector3 &point, 65 Vector3 &normal, 66 const Vector3 &viewpoint, 66 67 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 71 78 }; 72 79 -
trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp
r475 r492 511 511 float maxt = 1e6; 512 512 float mint = 0; 513 513 514 514 Intersectable::NewMail(); 515 515 -
trunk/VUT/GtpVisibilityPreprocessor/src/Makefile
r464 r492 1 1 ############################################################################# 2 2 # Makefile for building: preprocessor 3 # Generated by qmake (2.00a) (Qt 4.1.0-rc1) on: st 14. XII 10:37:40 20053 # Generated by qmake (2.00a) (Qt 4.1.0-rc1) on: út 3. I 23:13:25 2006 4 4 # Project: preprocessor.pro 5 5 # Template: app … … 71 71 D:\Qt\4.1.0-rc1\mkspecs\features\debug_and_release.prf \ 72 72 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 \ 73 76 D:\Qt\4.1.0-rc1\mkspecs\features\win32\thread.prf \ 74 77 D:\Qt\4.1.0-rc1\mkspecs\features\warn_off.prf \ … … 78 81 D:\Qt\4.1.0-rc1\mkspecs\features\win32\stl.prf \ 79 82 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 \82 83 D:\Qt\4.1.0-rc1\mkspecs\features\resources.prf \ 83 84 D:\Qt\4.1.0-rc1\mkspecs\features\uic.prf … … 91 92 D:\Qt\4.1.0-rc1\mkspecs\features\debug_and_release.prf: 92 93 D:\Qt\4.1.0-rc1\mkspecs\features\default_post.prf: 94 D:\Qt\4.1.0-rc1\mkspecs\features\qt.prf: 95 D:\Qt\4.1.0-rc1\mkspecs\features\win32\opengl.prf: 96 D:\Qt\4.1.0-rc1\mkspecs\features\moc.prf: 93 97 D:\Qt\4.1.0-rc1\mkspecs\features\win32\thread.prf: 94 98 D:\Qt\4.1.0-rc1\mkspecs\features\warn_off.prf: … … 98 102 D:\Qt\4.1.0-rc1\mkspecs\features\win32\stl.prf: 99 103 D:\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:102 104 D:\Qt\4.1.0-rc1\mkspecs\features\resources.prf: 103 105 D:\Qt\4.1.0-rc1\mkspecs\features\uic.prf: -
trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.cpp
r485 r492 103 103 104 104 for ( ; 105 106 105 faceIndex < mFaces.size(); 106 faceIndex++) { 107 107 hits += CastRayToFace(faceIndex, ray, nearestT, nearestFace, instance); 108 108 if (mIsConvex && nearestFace != -1) … … 122 122 int 123 123 Mesh::CastRayToSelectedFaces( 124 125 126 127 124 Ray &ray, 125 const vector<int> &faces, 126 Intersectable *instance 127 ) 128 128 { 129 129 vector<int>::const_iterator fi; … … 160 160 inline int 161 161 int_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 { 169 168 float ydiff; 170 169 … … 183 182 if (fabs(ydiff) < Limits::Small) { // denominator near 0 184 183 if (((fabs(v1) > Limits::Small) || 185 184 (u1 > 0) || (u2 > 0))) 186 185 return 0; 187 186 return 1; 188 187 } 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; 193 199 } 194 200 … … 198 204 int 199 205 Mesh::RayFaceIntersection(const int faceIndex, 200 201 202 203 206 const Ray &ray, 207 float &t, 208 const float nearestT 209 ) 204 210 { 205 211 Face *face = mFaces[faceIndex]; … … 244 250 mVertices[face->mVertexIndices[i]].ExtractVerts(&u2, &v2, paxis); 245 251 // line u1, v1, u2, v2 246 if ((v 2 - v1)*(u1 - u) > (u2 - u1)*(v1 - v))247 252 if ((v1 - v2)*(u - u1) + (u2 - u1)*(v - v1) > 0) 253 return Ray::NO_INTERSECTION; 248 254 u1 = u2; 249 255 v1 = v2; … … 416 422 int 417 423 TransformedMeshInstance::CastRay( 418 419 424 Ray &ray 425 ) 420 426 { 421 427 ray.ApplyTransform(Invert(mWorldTransform)); -
trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.h
r406 r492 145 145 int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 146 146 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 162 class MeshInstance : public Intersectable { 163 protected: 164 Mesh *mMesh; 165 166 public: 167 MeshInstance(Mesh *mesh):Intersectable(), mMesh(mesh) 168 { 169 } 170 171 int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 172 147 173 int 148 174 GetRandomVisibleSurfacePoint(Vector3 &point, … … 151 177 const int maxTries 152 178 ); 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 int172 GetRandomVisibleSurfacePoint(Vector3 &point,173 Vector3 &normal,174 const Vector3 &viewpoint,175 const int maxTries176 );177 179 178 180 -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r491 r492 12 12 #include "RenderSimulator.h" 13 13 14 Preprocessor *preprocessor; 15 14 16 Preprocessor::Preprocessor(): 15 17 mKdTree(NULL), … … 19 21 mViewCellsManager(NULL) 20 22 { 23 environment->GetBoolValue("Preprocessor.useGlRenderer", mUseGlRenderer); 21 24 } 22 25 … … 55 58 56 59 mSceneGraph = new SceneGraph; 57 58 60 59 61 Parser *parser; … … 95 97 96 98 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; 107 112 } 108 113 … … 139 144 bool 140 145 Preprocessor::Export( const string filename, 141 142 143 144 146 const bool scene, 147 const bool kdtree, 148 const bool bsptree 149 ) 145 150 { 146 151 Exporter *exporter = Exporter::GetExporter(filename); -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h
r490 r492 7 7 #include "Mesh.h" 8 8 #include "KdTree.h" 9 10 #include <QObject> 9 11 10 12 class RenderSimulator; … … 30 32 viewcell loading/generation and the visibility computation itself. 31 33 */ 32 class Preprocessor { 34 class Preprocessor : public QObject { 35 Q_OBJECT 36 33 37 public: 34 38 /** Default constructor initialising e.g., KD tree and BSP tree. … … 94 98 /// scene graph loaded from file 95 99 SceneGraph *mSceneGraph; 100 101 /// raw array of objects 102 ObjectContainer mObjects; 96 103 97 104 /// kD-tree organizing the scene graph (occluders + occludees) + viewcells … … 115 122 VspKdTree *mVspKdTree; 116 123 124 bool mUseGlRenderer; 125 126 protected: 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; 117 134 /** Simulates rendering of the scene. 118 135 */ 119 136 RenderSimulator *mRenderSimulator; 137 138 signals: 139 void EvalPvsStat(); 140 120 141 }; 121 142 122 143 123 144 124 145 extern Preprocessor *preprocessor; 125 146 126 147 #endif -
trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.h
r485 r492 60 60 */ 61 61 PvsData<T> *Find(T sample); 62 63 bool GetSampleContribution(T sample, float &contribution); 62 64 63 65 /** Adds sample to PVS. … … 71 73 */ 72 74 int AddSample(T sample); 73 75 74 76 /** Adds one pvs to another one. 75 77 @returns new pvs size … … 157 159 158 160 template <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) 161 int 162 Pvs<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 175 template <typename T> 176 bool 177 Pvs<T>::AddSample(T sample, float &contribution) 167 178 { 168 179 PvsData<T> *data = Find(sample); … … 181 192 182 193 template <typename T> 194 bool 195 Pvs<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 209 template <typename T> 183 210 bool Pvs<T>::RemoveSample(T sample, const int visibleSamples) 184 211 { -
trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp
r490 r492 11 11 #include "ViewCellsManager.h" 12 12 #include "RenderSimulator.h" 13 #include "GlRenderer.h" 13 14 14 15 static bool useViewSpaceBox = false; … … 33 34 environment->GetIntValue("RssPreprocessor.Export.numRays", mExportNumRays); 34 35 environment->GetBoolValue("RssPreprocessor.useViewcells", mUseViewcells); 35 environment->GetBoolValue("RssPreprocessor.useViewcells", mUseViewcells); 36 environment->GetBoolValue("RssPreprocessor.objectBasedSampling", mObjectBasedSampling); 37 environment->GetBoolValue("RssPreprocessor.directionalSampling", mDirectionalSampling); 36 38 37 39 environment->GetBoolValue("RssPreprocessor.loadInitialSamples", mLoadInitialSamples); … … 39 41 40 42 mStats.open("stats.log"); 43 41 44 } 42 45 43 46 RssPreprocessor::~RssPreprocessor() 44 47 { 45 CLEAR_CONTAINER(mVssRays); 48 // mVssRays get deleted in the tree 49 // CLEAR_CONTAINER(mVssRays); 46 50 } 47 51 … … 78 82 Vector3 pointA, pointB; 79 83 float bsize = Magnitude(box.Size()); 84 80 85 81 86 if (mKdTree->CastRay(ray)) { … … 86 91 // compute intersection with the scene bounding box 87 92 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; 94 97 } 95 98 … … 108 111 objectB = NULL; 109 112 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 118 130 VssRay *vssRay = NULL; 119 131 120 bool validSample = true;121 if ( detectEmptyViewSpace) {132 bool validSample = (objectA != objectB); 133 if (0 && detectEmptyViewSpace) { // consider all samples valid 122 134 // check if the viewpoint lies on the line segment AB 123 135 if (Distance(pointA, pointB) < … … 176 188 Vector3 point; 177 189 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 } 182 211 } else { 183 212 AxisAlignedBox3 box; … … 187 216 else 188 217 box = mKdTree->GetBox(); 189 218 190 219 point = box.GetRandomPoint(); 191 220 point.y = viewpoint.y; 192 221 } 193 222 223 return point - viewpoint; 224 } 225 226 Vector3 227 RssPreprocessor::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 194 266 return point - viewpoint; 195 267 } … … 203 275 int num; 204 276 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 221 279 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; 228 286 229 287 if (0) { 230 float p = desiredSamples/(float)( avgRayContribution*rssTree->stat.Leaves());288 float p = desiredSamples/(float)(rssTree->stat.avgRayContribution*rssTree->stat.Leaves()); 231 289 num = rssTree->GenerateRays(p, rays); 232 290 } else { … … 249 307 cout<<"Exporting vss rays..."<<endl<<flush; 250 308 251 float prob = number/(float)vssRays.size();252 253 254 309 Exporter *exporter = NULL; 255 310 exporter = Exporter::GetExporter(filename); … … 266 321 } 267 322 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); 271 326 272 327 exporter->ExportRays(rays, RgbColor(1, 0, 0)); … … 388 443 } 389 444 445 446 void 447 RssPreprocessor::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 390 463 bool 391 464 RssPreprocessor::ComputeVisibility() 392 465 { 466 467 connect(this, SIGNAL(EvalPvsStat()), renderer, SLOT(EvalPvsStat()) ); 468 393 469 cout<<"Rss Preprocessor started\n"<<flush; 394 470 cout<<"Memory/ray "<<sizeof(VssRay)+sizeof(RssTreeNode::RayInfo)<<endl; 395 mSceneGraph->CollectObjects(&mObjects); 471 472 Randomize(0); 473 396 474 397 475 long startTime = GetTime(); … … 443 521 444 522 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 454 533 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 465 547 //Vector3 viewpoint = GetViewpoint(mViewSpaceBox); 466 548 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 470 553 sampleContributions = CastRay(viewpoint, direction, mVssRays); 471 472 554 555 473 556 //-- CORR matt: put block inside loop 474 557 if (sampleContributions) { 475 476 558 passContributingSamples ++; 559 passSampleContributions += sampleContributions; 477 560 } 478 561 passSamples++; 479 562 totalSamples++; 480 481 482 483 563 } 564 565 566 float avgRayContrib = (passContributingSamples > 0) ? 484 567 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 << 493 605 "#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 527 616 VssRayContainer selectedRays; 528 617 int desired = Max( 529 618 mViewCellsManager->GetPostProcessSamples(), 530 619 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 537 623 //-- post process view cells 538 624 mViewCellsManager->PostProcess(mObjects, selectedRays); … … 547 633 548 634 635 636 rssPass++; 637 549 638 rssTree = new RssTree; 550 639 rssTree->SetPass(mPass); 640 551 641 if (mUseImportanceSampling) { 552 642 … … 555 645 else 556 646 rssTree->Construct(mVssRays, NULL); 647 648 rssTree->stat.Print(mStats); 557 649 cout<<"RssTree root PVS size = "<<rssTree->GetRootPvsSize()<<endl; 558 650 … … 572 664 // viewcells->UpdatePVS(newVssRays); 573 665 574 int rssPass = 0; 575 int rssSamples = 0; 666 576 667 while (1) { 577 668 int num = mRssSamplesPerPass; 578 669 SimpleRayContainer rays; 579 670 VssRayContainer vssRays; 580 671 672 581 673 if (!mUseImportanceSampling) { 582 674 for (int j=0; j < num; j++) { … … 597 689 598 690 599 totalSamples+=num; 600 rssSamples+=num; 601 691 totalSamples += rays.size(); 692 rssSamples += vssRays.size(); 693 694 695 602 696 mStats << 603 697 "#Pass\n" <<mPass<<endl<< … … 607 701 "#RssSamples\n" <<rssSamples<<endl; 608 702 703 609 704 if (mUseViewcells) { 610 705 … … 616 711 } 617 712 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 638 718 if (mExportRays) { 639 719 char filename[64]; … … 644 724 645 725 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 647 760 648 761 … … 653 766 } 654 767 768 769 if (!mUseImportanceSampling) 770 CLEAR_CONTAINER(vssRays); 771 655 772 if (totalSamples >= mRssSamples + mInitialSamples) 656 773 break; … … 659 776 rssPass++; 660 777 mPass++; 778 rssTree->SetPass(mPass); 661 779 } 662 780 -
trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.h
r490 r492 4 4 #include <fstream> 5 5 using namespace std; 6 6 7 7 8 #include "Preprocessor.h" … … 14 15 sampling of view space */ 15 16 class RssPreprocessor : public Preprocessor { 17 16 18 public: 17 19 int mPass; … … 29 31 bool mUseViewcells; 30 32 bool mUpdateSubdivision; 33 34 bool mObjectBasedSampling; 35 bool mDirectionalSampling; 31 36 32 37 AxisAlignedBox3 *mViewSpaceBox; … … 34 39 ofstream mStats; 35 40 36 ObjectContainer mObjects;37 41 38 42 // rays cast during the processing … … 56 60 AxisAlignedBox3 *viewSpaceBox 57 61 ); 58 62 63 Vector3 64 InitialGetDirection(const Vector3 &viewpoint, 65 AxisAlignedBox3 *viewSpaceBox 66 ); 67 59 68 void 60 69 SetupRay(Ray &ray, … … 118 127 ); 119 128 129 130 void 131 ComputeRenderError(); 132 120 133 }; 121 134 -
trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.cpp
r485 r492 1 2 1 // ================================================================ 3 2 // $Id: lsds_kdtree.cpp,v 1.18 2005/04/16 09:34:21 bittner Exp $ … … 25 24 #include "Ray.h" 26 25 #include "Containers.h" 26 #include "ViewCell.h" 27 #include "Exporter.h" 28 #include "Preprocessor.h" 29 #include "SceneGraph.h" 27 30 28 31 #define DEBUG_SPLIT_COST 0 … … 64 67 } 65 68 69 inline void 70 AddViewcells2Pvs(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 66 102 // Constructor 67 103 RssTree::RssTree() … … 85 121 environment->GetFloatValue("RssTree.maxStaticMemory", maxStaticMemory); 86 122 87 88 89 90 float refDirAngle; 91 environment->GetFloatValue("RssTree.refDirAngle", refDirAngle); 123 environment->GetFloatValue("RssTree.maxStaticMemory", maxStaticMemory); 124 125 92 126 93 127 environment->GetIntValue("RssTree.accessTimeThreshold", accessTimeThreshold); … … 125 159 environment->GetIntValue("RssTree.dirSplitDepth", mDirSplitDepth); 126 160 161 environment->GetBoolValue("RssTree.importanceBasedCost", mImportanceBasedCost); 162 163 environment->GetIntValue("RssTree.maxRays", mMaxRays); 164 127 165 root = NULL; 128 166 … … 143 181 RssStatistics::Print(ostream &app) const 144 182 { 145 app << " ===== RssTree statistics ===============\n";183 app << "###### RssTree statistics ######\n"; 146 184 147 185 app << "#N_RAYS ( Number of rays )\n" … … 204 242 << Time() << " \n"; 205 243 206 app << " ===== END OF RssTree statistics ==========\n";244 app << "###### END OF RssTree statistics ######\n"; 207 245 208 246 } … … 210 248 211 249 void 212 RssTree Leaf::UpdatePvsSize()213 { 214 if (! mValidPvs) {250 RssTree::UpdatePvsSize(RssTreeLeaf *leaf) 251 { 252 if (!leaf->mValidPvs) { 215 253 Intersectable::NewMail(); 216 254 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(); 219 257 ri++) 220 258 if ((*ri).mRay->IsActive()) { 221 259 Intersectable *object; 222 #if BIDIRECTIONAL_RAY 223 object = (*ri).mRay->mOriginObject; 260 object = (*ri).GetObject(); 224 261 if (object && !object->Mailed()) { 225 262 pvsSize++; 226 263 object->Mail(); 227 264 } 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); 239 269 } 240 270 } … … 248 278 float tmin, tmax; 249 279 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) 253 285 return false; 254 286 … … 281 313 if (root) 282 314 delete root; 283 315 316 284 317 root = new RssTreeLeaf(NULL, rays.size()); 285 318 // first construct a leaf that will get subdivide … … 315 348 ); 316 349 } 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 319 356 if ( forcedBoundingBox ) 320 357 bbox = *forcedBoundingBox; … … 324 361 325 362 stat.rays = leaf->rays.size(); 326 leaf->UpdatePvsSize(); 327 leaf->ComputeEntropyImportance(); 363 UpdatePvsSize(leaf); 328 364 329 365 stat.initialPvsSize = leaf->GetPvsSize(); … … 338 374 339 375 stat.Stop(); 340 341 376 stat.Print(cout); 342 377 cout<<"#Total memory="<<GetMemUsage()<<endl; 343 378 379 // this rotine also updates importances etc... 344 380 } 345 381 … … 387 423 if (!node->IsLeaf()) { 388 424 subdivided++; 425 426 389 427 RssTreeInterior *interior = (RssTreeInterior *) node; 390 428 // push the children on the stack … … 482 520 RssTreeLeaf *leaf, 483 521 const AxisAlignedBox3 &box, 484 float &position, 485 int &raysBack, 486 int &raysFront, 487 int &pvsBack, 488 int &pvsFront 522 SplitInfo &info 489 523 ) 490 524 { 491 525 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 504 529 #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; 506 535 #endif 507 if (costRatio > termMaxCostRatio) { 536 537 if (info.costRatio > termMaxCostRatio) { 508 538 // cout<<"Too big cost ratio "<<costRatio<<endl; 509 539 stat.maxCostRatioNodes++; … … 516 546 " rays="<<leaf->rays.size()<< 517 547 " rc="<<leaf->GetAvgRayContribution()<< 518 " axis="<< axis<<endl;548 " axis="<<info.axis<<endl; 519 549 #endif 520 521 return axis;522 } 523 524 525 float 550 551 return info.axis; 552 } 553 554 555 void 526 556 RssTree::GetCostRatio( 527 557 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 534 559 ) 535 560 { 536 bool costImportance = true; 537 538 float ratio; 561 539 562 AxisAlignedBox3 box; 540 563 float minBox, maxBox; 541 564 542 if ( axis < 3) {565 if (info.axis < 3) { 543 566 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); 546 569 } else { 547 570 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); 550 573 } 551 574 … … 554 577 int pvsSize = leaf->GetPvsSize(); 555 578 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 } 562 615 } else { 616 const int costMethod = 1; 563 617 // 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 } 594 644 } 595 645 596 646 597 float 647 void 598 648 RssTree::EvalCostRatio( 599 649 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 606 651 ) 607 652 { 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 614 686 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 672 732 // cout<<axis<<" "<<pvsSize<<" "<<pvsBack<<" "<<pvsFront<<endl; 673 733 // float oldCost = leaf->rays.size(); 674 734 675 735 // cout<<"ratio="<<ratio<<endl; 676 677 return ratio; 678 } 679 680 float 736 } 737 738 void 681 739 RssTree::BestCostRatio( 682 740 RssTreeLeaf *leaf, 683 int &axis, 684 float &position, 685 int &raysBack, 686 int &raysFront, 687 int &pvsBack, 688 int &pvsFront 741 SplitInfo &info 689 742 ) 690 743 { 691 int nRaysBack[6], nRaysFront[6]; 692 int nPvsBack[6], nPvsFront[6]; 693 float nPosition[6]; 694 float nCostRatio[6]; 744 SplitInfo nInfo[5]; 695 745 int bestAxis = -1; 696 746 697 747 AxisAlignedBox3 sBox = GetBBox(leaf); 698 748 AxisAlignedBox3 dBox = GetDirBBox(leaf); … … 700 750 int sAxis = sBox.Size().DrivingAxis(); 701 751 int dAxis = dBox.Size().DrivingAxis() + 3; 702 703 752 704 753 float dirSplitBoxSize = 0.01f; 705 754 bool allowDirSplit = Magnitude(sBox.Size())*dirSplitBoxSize < Magnitude(bbox.Size()); 706 755 707 756 708 for ( axis = 0; axis < 5; axis++)757 for (int axis = 0; axis < 5; axis++) 709 758 if ( 710 759 (axis < 3 && (leaf->depth < mDirSplitDepth || mInterleaveDirSplits)) || 711 760 (axis >= 3 && (leaf->depth >= mDirSplitDepth)) 712 761 ) { 762 nInfo[axis].axis = axis; 713 763 if (!mSplitUseOnlyDrivingAxis || axis == sAxis || axis == dAxis) { 714 764 715 765 if (splitType == ESplitRegular) { 716 766 if (axis < 3) 717 n Position[axis]= (sBox.Min()[axis] + sBox.Max()[axis])*0.5f;767 nInfo[axis].position = (sBox.Min()[axis] + sBox.Max()[axis])*0.5f; 718 768 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]); 729 772 } else 730 773 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 ); 739 778 } else 740 779 if (splitType == ESplitHybrid) { 741 780 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 ); 750 785 else { 751 786 if (axis < 3) 752 n Position[axis]= (sBox.Min()[axis] + sBox.Max()[axis])*0.5f;787 nInfo[axis].position = (sBox.Min()[axis] + sBox.Max()[axis])*0.5f; 753 788 else 754 n Position[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; 755 790 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 ); 764 794 } 765 795 } else { … … 768 798 } 769 799 770 771 800 if ( bestAxis == -1) 772 801 bestAxis = axis; 773 802 else 774 if ( n CostRatio[axis] < nCostRatio[bestAxis])803 if ( nInfo[axis].costRatio < nInfo[bestAxis].costRatio ) 775 804 bestAxis = axis; 776 805 } 777 806 } 778 807 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 812 void 793 813 RssTree::EvalCostRatioHeuristic( 794 814 RssTreeLeaf *leaf, 795 const int axis, 796 float &bestPosition, 797 int &raysBack, 798 int &raysFront, 799 int &pvsBack, 800 int &pvsFront 815 SplitInfo &info 801 816 ) 802 817 { … … 804 819 float minBox, maxBox; 805 820 806 if ( axis < 3) {821 if (info.axis < 3) { 807 822 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); 810 825 } else { 811 826 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); 817 832 818 833 // go through the lists, count the number of objects left and right 819 834 // and evaluate the following cost funcion: 820 835 // 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 824 847 float sizeBox = maxBox - minBox; 825 848 826 849 float minBand = minBox + 0.1f*(maxBox - minBox); 827 850 float maxBand = minBox + 0.9f*(maxBox - minBox); 828 851 829 float minRatio = 1e20f; 830 852 // best cost ratio 853 info.costRatio = 1e20f; 854 855 currInfo.viewCells = 0; 856 831 857 Intersectable::NewMail(); 832 858 // set all object as belonging to the fron pvs … … 835 861 ri++) 836 862 if ((*ri).mRay->IsActive()) { 837 Intersectable *object = (*ri). mRay->mTerminationObject;863 Intersectable *object = (*ri).GetObject(); 838 864 if (object) 839 865 if (!object->Mailed()) { … … 842 868 } else 843 869 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 846 888 Intersectable::NewMail(); 847 889 … … 849 891 ci < splitCandidates->end(); 850 892 ci++) { 851 VssRay *ray;852 893 switch ((*ci).type) { 853 894 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(); 858 899 if (object) { 859 900 if (!object->Mailed()) { 860 901 object->Mail(); 861 pl++;902 currInfo.pvsBack++; 862 903 } 863 904 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--; 865 916 } 866 917 break; … … 871 922 872 923 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 883 930 884 931 // cout<<"pos="<<(*ci).value<<"\t q=("<<ql<<","<<qr<<")\t r=("<<rl<<","<<rr<<")"<<endl; 885 932 // 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; 897 936 } 898 937 } 899 938 } 900 939 901 940 902 941 // cout<<"===================="<<endl; 903 942 // cout<<"costRatio="<<ratio<<" pos="<<position<<" t="<<(position - minBox)/(maxBox - minBox) 904 943 // <<"\t q=("<<queriesBack<<","<<queriesFront<<")\t r=("<<raysBack<<","<<raysFront<<")"<<endl; 905 return minRatio;906 944 } 907 945 … … 933 971 if (axis < 3) { 934 972 splitCandidates->push_back(SortableEntry(SortableEntry::ERayMin, 935 (*ri). ExtrapOrigin(axis),936 (void *) (*ri).mRay)973 (*ri).GetOrigin(axis), 974 (void *)&(*ri)) 937 975 ); 938 976 } else { 939 float pos = (*ri). mRay->GetDirParametrization(axis-3);977 float pos = (*ri).GetDirParametrization(axis-3); 940 978 splitCandidates->push_back(SortableEntry(SortableEntry::ERayMin, 941 979 pos, 942 (void *) (*ri).mRay)980 (void *)&(*ri)) 943 981 ); 944 982 } … … 1012 1050 } 1013 1051 1014 float position; 1015 1016 // first count ray sides 1017 int raysBack; 1018 int raysFront; 1019 int pvsBack; 1020 int pvsFront; 1052 SplitInfo info; 1021 1053 1022 1054 // 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; 1025 1060 1026 1061 if (axis == -1) { … … 1035 1070 1036 1071 node->axis = axis; 1037 node->position = position;1072 node->position = info.position; 1038 1073 node->bbox = box; 1039 1074 node->dirBBox = GetDirBBox(leaf); … … 1041 1076 backBBox = box; 1042 1077 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 1047 1086 // replace a link from node's parent 1048 1087 if ( leaf->parent ) … … 1052 1091 1053 1092 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 1112 1124 #if 0 1113 1125 front->SetPvsSize(pvsFront); … … 1117 1129 back->ComputeEntropyImportance(); 1118 1130 #else 1119 front->UpdatePvsSize();1120 back->UpdatePvsSize();1131 UpdatePvsSize(front); 1132 UpdatePvsSize(back); 1121 1133 #endif 1122 1134 … … 1124 1136 // update stats 1125 1137 stat.rayRefs -= (int)leaf->rays.size(); 1126 stat.rayRefs += raysBack +raysFront;1138 stat.rayRefs += info.raysBack + info.raysFront; 1127 1139 1128 1140 … … 1221 1233 1222 1234 void 1223 RssTree::UpdateRays(VssRayContainer &remove, 1235 RssTree::UpdateRays( 1236 VssRayContainer &remove, 1224 1237 VssRayContainer &add 1225 1238 ) … … 1257 1270 AddRay(info); 1258 1271 } 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 1260 1285 1261 1286 … … 1377 1402 RssTreeInterior *in = (RssTreeInterior *) data.node; 1378 1403 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 1421 1413 } 1422 1414 … … 1559 1551 if ((*ri).mRay->IsActive()) { 1560 1552 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(); 1569 1554 if (object && !object->Mailed()) { 1570 1555 pvsSize++; … … 1612 1597 if ((*ri).mRay->IsActive()) { 1613 1598 Intersectable *object; 1614 object = (*ri). mRay->mTerminationObject;1599 object = (*ri).GetObject(); 1615 1600 if (object && !object->Mailed()) { 1616 1601 pvs.push_back(object); … … 1637 1622 1638 1623 void 1639 RssTree::GetTreeStatistics( 1640 float &avgPvsSize, 1641 float &avgRays, 1642 float &avgRayContribution, 1643 float &avgPvsEntropy, 1644 float &avgRayLengthEntropy, 1645 float &avgImportance 1646 ) 1624 RssTree::UpdateTreeStatistics() 1647 1625 { 1648 1626 stack<RssTreeNode *> tstack; … … 1651 1629 float sumPvsSize = 0.0f; 1652 1630 float sumRayContribution = 0.0f; 1631 float sumWeightedRayContribution = 0.0f; 1653 1632 float sumImportance = 0.0f; 1654 1633 float sumPvsEntropy = 0.0f; … … 1665 1644 leaves++; 1666 1645 RssTreeLeaf *leaf = (RssTreeLeaf *)node; 1667 leaf->UpdatePvsSize();1646 UpdatePvsSize(leaf); 1668 1647 1669 1648 sumPvsSize += leaf->GetPvsSize(); 1670 1649 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; 1673 1661 sumRays += leaf->rays.size(); 1674 1662 1675 1663 float imp = leaf->GetImportance(); 1676 1664 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; 1679 1667 1680 1668 sumImportance += imp; … … 1689 1677 } 1690 1678 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 1698 1689 1699 1690 1700 1691 int 1701 RssTree::GenerateRays(const float ratioPerLeaf, 1692 RssTree::GenerateRays( 1693 const float ratioPerLeaf, 1702 1694 SimpleRayContainer &rays) 1703 1695 { … … 1777 1769 return; 1778 1770 } 1779 1771 1772 #if 1 1780 1773 int tries = min(20, nrays); 1781 1774 … … 1783 1776 r1 = Random(nrays); 1784 1777 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()) 1786 1779 break; 1787 1780 } … … 1789 1782 if (r1 == r2) 1790 1783 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 1849 struct RayNeighbor { 1850 int rayInfo; 1851 float distance; 1852 RayNeighbor():rayInfo(0), distance(MAX_FLOAT) {} 1853 }; 1854 1855 void 1856 RssTree::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 1891 bool 1892 GetRandomTripple(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 1926 bool 1927 RssTree::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 1937 int 1938 RssTree::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 } 1793 1994 1794 1995 void … … 1798 1999 { 1799 2000 2001 if (numberOfRays == 0) 2002 return; 2003 1800 2004 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 1805 2076 Vector3 origin, direction; 1806 2077 // generate half of convex combination and half of random rays 1807 2078 if (useExtendedConvexCombination) { 1808 // pickup 3random rays2079 // pickup 2 random rays 1809 2080 int r1, r2; 1810 2081 PickEdgeRays(leaf, r1, r2); 2082 1811 2083 1812 2084 Vector3 o1 = leaf->rays[r1].GetOrigin(); 1813 2085 Vector3 o2 = leaf->rays[r2].GetOrigin(); 1814 2086 1815 const float overlap = 0. 1f;2087 const float overlap = 0.0f; 1816 2088 float w1, w2; 1817 2089 GenerateExtendedConvexCombinationWeights2(w1, w2, overlap); 1818 2090 origin = w1*o1 + w2*o2; 2091 GenerateExtendedConvexCombinationWeights2(w1, w2, overlap); 1819 2092 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(); 1824 2095 } 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 } 1827 2130 direction = Vector3(sin(dirVector.x), sin(dirVector.y), cos(dirVector.x)); 1828 2131 } 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 2188 int 2189 RssTree::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 2220 int 2221 RssTree::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 2252 int 2253 RssTree::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 2284 int 2285 RssTree::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; 1832 2356 } 1833 2357 … … 1837 2361 SimpleRayContainer &rays) 1838 2362 { 2363 1839 2364 1840 2365 vector<RssTreeLeaf *> leaves; … … 1859 2384 1860 2385 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 1862 2393 k = 0; 1863 2394 for (i=0; i < leaves.size() && k < numberOfLeaves; i++) … … 1866 2397 RssTreeLeaf *leaf = leaves[i]; 1867 2398 float c = leaf->GetImportance(); 1868 int num = (c*ratioPerLeaf + 0.5); 2399 2400 int num = fixedPerLeaf + (int)(c*ratioPerLeaf + 0.5f); 1869 2401 GenerateLeafRays(leaf, num, rays); 1870 2402 } … … 1889 2421 RssTreeLeaf *leaf = (RssTreeLeaf *)node; 1890 2422 // update pvs size 1891 leaf->UpdatePvsSize();2423 UpdatePvsSize(leaf); 1892 2424 sumPvs += leaf->GetPvsSize(); 1893 2425 leaves++; … … 1904 2436 } 1905 2437 1906 2438 float 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 2441 float passSampleWeightDecay = 0.5f; 2442 2443 void 2444 RssTree::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 2457 float 2458 RssTree::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 2491 void 2492 RssTree::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 1907 2530 float 1908 2531 RssTreeLeaf::GetImportance() const 1909 2532 { 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; 1919 2534 } 1920 2535 1921 2536 1922 2537 float 1923 RssTreeLeaf::ComputePvsEntropy() 2538 RssTreeLeaf::ComputePvsEntropy() const 1924 2539 { 1925 2540 int samples = 0; 1926 2541 Intersectable::NewMail(); 1927 2542 // 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(); 1929 2544 ri != rays.end(); 1930 2545 ri++) 1931 2546 if ((*ri).mRay->IsActive()) { 1932 Intersectable *object = (*ri). mRay->mTerminationObject;2547 Intersectable *object = (*ri).GetObject(); 1933 2548 if (object) { 1934 2549 if (!object->Mailed()) { … … 1949 2564 ri++) 1950 2565 if ((*ri).mRay->IsActive()) { 1951 Intersectable *object = (*ri). mRay->mTerminationObject;2566 Intersectable *object = (*ri).GetObject(); 1952 2567 if (object) { 1953 2568 if (!object->Mailed()) { … … 1967 2582 1968 2583 float 1969 RssTreeLeaf::ComputeRayLengthEntropy() 2584 RssTreeLeaf::ComputeRayLengthEntropy() const 1970 2585 { 1971 2586 // get sum of all ray lengths … … 2017 2632 2018 2633 2019 void 2020 RssTreeLeaf::ComputeEntropyImportance() 2021 { 2022 mPvsEntropy = ComputePvsEntropy(); 2023 mRayLengthEntropy = ComputeRayLengthEntropy(); 2634 float 2635 RssTreeLeaf::ComputeEntropyImportance() const 2636 { 2024 2637 2025 2638 // mEntropy = 1.0f - ComputeRayLengthEntropy(); 2026 mEntropyImportance = 1.0f - ComputePvsEntropy(); 2027 2028 // cout<<"ei="<<mEntropyImportance<<" "; 2639 return 1.0f - ComputePvsEntropy(); 2640 } 2641 2642 float 2643 RssTreeLeaf::ComputeRayContributionImportance() const 2644 { 2645 // mPvsEntropy = ComputePvsEntropy(); 2646 // mRayLengthEntropy = ComputeRayLengthEntropy(); 2647 2648 // mEntropy = 1.0f - ComputeRayLengthEntropy(); 2649 return 1.0f - ComputePvsEntropy(); 2029 2650 } 2030 2651 … … 2059 2680 VssRayContainer allRays; 2060 2681 CollectRays(allRays); 2682 2061 2683 2062 2684 int desired = min(number, (int)allRays.size()); … … 2105 2727 return (int)rays.size(); 2106 2728 } 2729 -
trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.h
r469 r492 21 21 #include "VssRay.h" 22 22 #include "AxisAlignedBox3.h" 23 #include "Halton.h" 23 24 24 25 … … 69 70 // number of dynamically removed ray refs 70 71 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 72 85 // Constructor 73 86 RssStatistics() { … … 144 157 return a.mRay < b.mRay; 145 158 } 159 160 #define USE_ORIGIN 0 146 161 147 162 Vector3 GetOrigin() const { 163 #if USE_ORIGIN 148 164 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 152 180 return mRay->GetOrigin(axis); 153 } 154 155 float ExtrapTermination(const int axis) const { 181 #else 156 182 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 // } 162 230 163 231 int … … 167 235 168 236 // only compare the side of the origin 169 float rpos = mRay->GetOrigin(axis);237 float rpos = (axis < 3) ? GetOrigin(axis) : GetDirParametrization(axis - 3); 170 238 return (rpos <= position) ? -1 : 1; 171 239 } 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 } 173 279 }; 174 280 … … 307 413 308 414 RayInfoContainer rays; 309 int m PassingRays;415 int mTotalRays; 310 416 311 417 bool mValidPvs; 312 float mEntropyImportance; 313 float mPvsEntropy; 314 float mRayLengthEntropy; 315 316 418 float mImportance; 419 420 HaltonSequence halton; 421 317 422 RssTreeLeaf(RssTreeInterior *p, 318 423 const int nRays 319 ):RssTreeNode(p), rays(), mPvsSize(0), m PassingRays(0), mValidPvs(false) {424 ):RssTreeNode(p), rays(), mPvsSize(0), mTotalRays(0), mValidPvs(false) { 320 425 rays.reserve(nRays); 321 426 } … … 328 433 s<< 329 434 "L: rays="<<(int)rays.size()<< 330 " pvs="<<mPvsSize<<" pEntropy="<<mPvsEntropy<<" lEntropy="<<mRayLengthEntropy<<endl;435 " pvs="<<mPvsSize<<" importance="<<mImportance<<endl; 331 436 }; 332 437 … … 334 439 mValidPvs = false; 335 440 rays.push_back(data); 336 data.mRay->Ref(); 337 if (data.GetRayClass() == RayInfo::PASSING_RAY) 338 mPassingRays++; 441 mTotalRays++; 442 data.mRay->Ref(); 339 443 } 340 444 … … 348 452 } 349 453 350 void351 UpdatePvsSize();352 454 353 455 float 354 ComputePvsEntropy() ;456 ComputePvsEntropy() const; 355 457 356 458 float 357 ComputeRayLengthEntropy() ;459 ComputeRayLengthEntropy() const; 358 460 359 461 float 360 ComputeRayTerminationEntropy(); 361 362 void 363 ComputeEntropyImportance(); 462 ComputeRayTerminationEntropy() const; 463 464 465 float 466 ComputeEntropyImportance() const; 467 468 float 469 ComputeRayContributionImportance() const; 364 470 365 471 void Mail() { mailbox = mailID; } … … 401 507 return a->GetAvgRayContribution() > b->GetAvgRayContribution(); 402 508 } 509 403 510 404 511 }; … … 560 667 // depth at which directional splits are performed if mInterleaveDirSplits is false 561 668 int mDirSplitDepth; 669 670 // maximal number of rays maintained in the rss tree 671 int mMaxRays; 562 672 563 673 // maximal size of the box on which the refdir splitting can be performed … … 582 692 int minCollapseDepth; 583 693 694 bool mImportanceBasedCost; 695 696 // sampling pass 697 int mCurrentPass; 584 698 585 699 // reusable array of split candidates … … 627 741 Subdivide(const TraversalData &tdata); 628 742 629 int630 SelectPlane(RssTreeLeaf *leaf,631 const AxisAlignedBox3 &box,632 float &position,633 int &raysBack,634 int &raysFront,635 int &pvsBack,636 int &pvsFront637 );638 743 639 744 void … … 658 763 } 659 764 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 662 794 BestCostRatio( 663 795 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 670 803 ); 671 804 672 float 805 806 void 673 807 EvalCostRatio( 674 808 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 681 816 ); 682 817 683 float818 void 684 819 EvalCostRatioHeuristic( 685 820 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 692 828 ); 693 829 694 float 830 int 831 SelectPlane(RssTreeLeaf *leaf, 832 const AxisAlignedBox3 &box, 833 SplitInfo &info 834 ); 835 836 void 695 837 GetCostRatio( 696 838 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 703 846 ); 704 847 705 848 AxisAlignedBox3 GetBBox(const RssTreeNode *node) const { 706 849 if (node->parent == NULL) … … 803 946 804 947 void 805 GetTreeStatistics( 806 float &avgPvsSize, 807 float &avgRays, 808 float &avgRayContribution, 809 float &avgPvsEntropy, 810 float &avgRayLengthEntropy, 811 float &avgImportance 812 ); 948 UpdateTreeStatistics(); 813 949 814 950 … … 865 1001 ); 866 1002 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 867 1054 }; 868 1055 -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r487 r492 242 242 SamplingPreprocessor::ComputeVisibility() 243 243 { 244 // pickup an object245 ObjectContainer objects;246 244 247 245 /// rays per pass 248 246 RayContainer passRays; 249 247 250 mSceneGraph->CollectObjects(&objects);251 248 252 249 mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox()); … … 270 267 int reverseSamples = 0; 271 268 272 for (i = 0; i < objects.size(); i++) {269 for (i = 0; i < mObjects.size(); i++) { 273 270 274 271 KdNode *nodeToSample = NULL; 275 Intersectable *object = objects[i];272 Intersectable *object = mObjects[i]; 276 273 277 274 int pvsSize = 0; … … 339 336 // cast rays for view cells construction 340 337 ProcessViewCells(passRays, 341 objects,338 mObjects, 342 339 passSampleContributions, 343 340 passContributingSamples); … … 361 358 << "k #SampleContributions=" << passSampleContributions << " (" 362 359 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 363 << (float)pvsSize /(float) objects.size() << endl360 << (float)pvsSize /(float)mObjects.size() << endl 364 361 << "avg ray contrib=" << avgRayContrib << endl 365 362 << "reverse samples [%]" << reverseSamples/(float)passSamples*100.0f << endl; … … 371 368 "#SampleContributions\n" << passSampleContributions << endl << 372 369 "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 373 "#AvgPVS\n"<< pvsSize/(float) objects.size() << endl <<370 "#AvgPVS\n"<< pvsSize/(float)mObjects.size() << endl << 374 371 "#AvgRayContrib\n" << avgRayContrib << endl; 375 372 } … … 387 384 // construct view cells if not already constructed 388 385 if (!mViewCellsManager->ViewCellsConstructed()) 389 mViewCellsManager->Construct(objects, mVssSampleRays);386 mViewCellsManager->Construct(mObjects, mVssSampleRays); 390 387 391 388 // $$JB temporary removed -
trunk/VUT/GtpVisibilityPreprocessor/src/SceneGraph.cpp
r490 r492 5 5 #include "X3dExporter.h" 6 6 #include "Intersectable.h" 7 8 7 9 8 … … 104 103 105 104 } 105 106 107 void 108 SceneGraphNode::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 16 16 SceneGraphNodeContainer mChildren; 17 17 AxisAlignedBox3 mBox; 18 void UpdateBox(); 18 19 }; 19 20 … … 27 28 28 29 int 29 30 30 CollectObjects(ObjectContainer *instances); 31 31 32 int 32 AssignObjectIds(); 33 AssignObjectIds(); 34 35 void 36 GetStatistics(int &intersectables, int &faces) const; 33 37 34 void 35 GetStatistics(int &intersectables, int &faces) const; 36 38 AxisAlignedBox3 GetBox() const { return mRoot->mBox; } 39 37 40 protected: 38 41 }; … … 40 43 41 44 42 43 45 #endif -
trunk/VUT/GtpVisibilityPreprocessor/src/Vector3.cpp
r448 r492 191 191 192 192 Vector3 193 UniformRandomVector( const Vector3 &normal)194 { 195 196 197 193 UniformRandomVector() 194 { 195 // float r1 = RandomValue(0.0f, 1.0f); 196 // float r2 = RandomValue(0.0f, 1.0f); 197 float r1, r2; 198 198 199 199 halton2.GetNext(r1, r2); 200 200 201 201 202 float cosTheta = 1.0f -r1;202 float cosTheta = 1.0f - 2*r1; 203 203 float sinTheta = sqrt(1 - sqr(cosTheta)); 204 204 float fi = 2.0f*M_PI*r2; 205 205 206 206 Vector3 dir(sinTheta*sin(fi), 207 cosTheta, 208 sinTheta*cos(fi)); 209 207 cosTheta, 208 sinTheta*cos(fi)); 209 210 return dir; 211 } 212 213 Vector3 214 UniformRandomVector(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 210 231 211 232 // return Normalize(dir); 212 233 213 234 Matrix4x4 m = RotationVectorsMatrix( 214 215 235 normal, 236 Vector3(0,1,0)); 216 237 Matrix4x4 mi = Invert(m); 217 238 m = m*RotationVectorsMatrix( 218 219 239 Vector3(0,1,0), 240 Normalize(dir))*mi; 220 241 221 242 return TransformNormal(m, normal); 222 243 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 228 228 229 229 friend Vector3 UniformRandomVector(const Vector3 &normal); 230 friend Vector3 UniformRandomVector(); 231 232 230 233 }; 231 234 … … 445 448 } 446 449 450 447 451 // Overload << operator for C++-style output 448 452 inline ostream& -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r491 r492 2672 2672 } 2673 2673 2674 2675 ViewCell * 2676 BspTree::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 2674 2705 void BspNodeGeometry::ComputeBoundingBox(AxisAlignedBox3 &box) 2675 2706 { -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r491 r492 468 468 ); 469 469 470 ViewCell * 471 GetViewCell(const Vector3 &point); 472 470 473 /// bsp tree construction types 471 474 enum {FROM_INPUT_VIEW_CELLS, FROM_SCENE_GEOMETRY, FROM_SAMPLES}; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r491 r492 330 330 void ViewCellsManager::ComputeSampleContributions(VssRay &ray) 331 331 { 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; 351 343 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 } 369 400 } 370 401 … … 520 551 #endif 521 552 } 522 553 523 554 524 555 float BspViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost) const … … 1705 1736 const VssRayContainer &rays) 1706 1737 { 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 1712 1750 1713 1751 VssRayContainer constructionRays; … … 2268 2306 } 2269 2307 } 2270 2271 2308 return maxDist; 2272 2309 } 2310 2311 2312 2313 2314 ViewCell * 2315 VspBspViewCellsManager::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 171 171 virtual void GetPvsStatistics(PvsStatistics &stat); 172 172 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); 174 178 175 179 /** Returns probability that view point lies in one view cell. … … 339 343 AxisAlignedBox3 GetSceneBbox() const; 340 344 345 /** Get a viewcell containing the specified point */ 346 ViewCell *GetViewCell(const Vector3 &point) { return NULL; } 347 341 348 protected: 342 349 … … 404 411 /** Prints out statistics of this approach. 405 412 */ 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; 412 420 413 421 protected: … … 460 468 ViewCellContainer &viewcells); 461 469 470 ViewCell *GetViewCell(const Vector3 &point) { return NULL; } 471 462 472 float GetProbability(ViewCell *viewCell); 463 473 float GetRendercost(ViewCell *viewCell, float objRendercost) const; 464 474 465 475 AxisAlignedBox3 GetSceneBbox() const; 466 467 476 protected: 468 477 … … 508 517 bool ViewCellsConstructed() const; 509 518 510 //void PrintStatistics(ostream &s) const;511 519 512 520 int CastLineSegment(const Vector3 &origin, … … 519 527 AxisAlignedBox3 GetSceneBbox() const; 520 528 529 ViewCell *GetViewCell(const Vector3 &point); 530 521 531 bool GetViewPoint(Vector3 &viewPoint) const; 522 532 523 533 bool ViewPointValid(const Vector3 &viewPoint) const; 524 525 534 protected: 526 535 /** DEPRECATED -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r491 r492 1525 1525 void VspBspTree::CollectViewCells(ViewCellContainer &viewCells) const 1526 1526 { 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()) 1541 1546 { 1542 1543 1547 viewCell->Mail(); 1548 viewCells.push_back(viewCell); 1544 1549 } 1545 1550 } 1546 1551 else 1547 1552 { 1548 1549 1550 1551 1553 BspInterior *interior = dynamic_cast<BspInterior *>(node); 1554 1555 nodeStack.push(interior->GetFront()); 1556 nodeStack.push(interior->GetBack()); 1552 1557 } 1553 1558 } … … 2504 2509 2505 2510 2511 ViewCell * 2512 VspBspTree::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 2506 2545 int VspBspTree::RefineViewCells(const VssRayContainer &rays) 2507 2546 { -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
r491 r492 264 264 BspNode *CollapseTree(BspNode *node); 265 265 266 ViewCell * 267 GetViewCell(const Vector3 &point); 268 266 269 /** Constructs bsp rays for post processing and visualization. 267 270 */ -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
r491 r492 351 351 { 352 352 353 mSceneGraph->CollectObjects(&mObjects);354 353 355 354 long startTime = GetTime(); -
trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.cpp
r487 r492 139 139 point = GetOrigin() + t*dir; 140 140 141 return SqrDistance(point, center) < sqrRadius;141 return ::SqrDistance(point, center) < sqrRadius; 142 142 } 143 143 … … 153 153 { 154 154 Vector3 dir = GetNormalizedDir(); 155 return GetDirParam(axis, dir); 156 } 157 158 float 159 VssRay::GetOpositeDirParametrization(const int axis) const 160 { 161 Vector3 dir = -GetNormalizedDir(); 155 162 return GetDirParam(axis, dir); 156 163 } … … 217 224 218 225 } 226 227 228 int 229 VssRayContainer::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 243 int 244 VssRayContainer::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 6 6 #include "Vector3.h" 7 7 #include "Ray.h" 8 #include "Containers.h" 8 9 9 10 class AxisAlignedBox3; … … 45 46 Intersectable *mTerminationObject; 46 47 48 ViewCellContainer mViewCells; 49 47 50 //////////////////////// 48 51 // members related to importance sampling … … 55 58 // sum of relative ray contributions per object 56 59 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; 57 65 58 66 ////////////////////////////// … … 71 79 mRefCount(0), 72 80 mFlags(0), 73 mPass(pass) 81 mPass(pass), 82 mViewCells(0), 83 mWeightedPvsContribution(0) 74 84 // mT(1.0f) 75 85 { … … 82 92 mMailbox(-1), 83 93 mOriginObject(ray.sourceObject.mObject), 84 mPass(0) 94 mPass(0), 95 mViewCells(0) 85 96 // mT(1.0f) 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 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 107 118 void Precompute() { 108 119 mFlags = 0; … … 158 169 159 170 float GetDirParametrization(const int axis) const; 171 float GetOpositeDirParametrization(const int axis) const; 160 172 161 173 static float VssRay::GetDirParam(const int axis, const Vector3 dir); … … 230 242 } 231 243 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 232 266 }; 233 267 … … 272 306 { 273 307 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 274 314 }; 275 315 -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r486 r492 115 115 else 116 116 if ((*ri)->intersections.size()==0) 117 b = (*ri)->GetLoc() + length*(*ri)->GetDir();117 b = (*ri)->GetLoc() + length*(*ri)->GetDir(); 118 118 else 119 b = (*ri)->Extrap((*ri)->intersections[0].mT);119 b = (*ri)->Extrap((*ri)->intersections[0].mT); 120 120 121 121 stream<<a.x<<" "<<a.y<<" "<<a.z<<" ,"; -
trunk/VUT/GtpVisibilityPreprocessor/src/default.env
r467 r492 15 15 # filename ../data/atlanta/atlanta2.x3d 16 16 # filename ../data/soda/soda.dat 17 17 filename ../data/soda/soda5.dat 18 18 } 19 19 … … 22 22 # type vss 23 23 type rss 24 useGlRenderer true 24 25 } 25 26 … … 66 67 initialSamples 500000 67 68 vssSamples 10000000 68 vssSamplesPerPass 10000069 vssSamplesPerPass 500000 69 70 useImportanceSampling true 71 72 directionalSampling true 73 objectBasedSampling false 70 74 71 75 Export { … … 77 81 78 82 useViewcells true 79 updateSubdivision false83 updateSubdivision true 80 84 } 81 85 … … 88 92 minRays 30 89 93 minSize 0.001 90 maxCostRatio 0.991 maxRayContribution 0. 192 94 maxCostRatio 1.0 95 maxRayContribution 0.5 96 maxRays 1000000 93 97 maxTotalMemory 200 94 98 maxStaticMemory 100 … … 97 101 # splitType heuristic 98 102 splitType hybrid 99 splitUseOnlyDrivingAxis false 103 splitUseOnlyDrivingAxis true 104 importanceBasedCost false 100 105 101 106 interleaveDirSplits true … … 157 162 #type kdTree 158 163 #type vspKdTree 159 # type bspTree164 # type bspTree 160 165 type vspBspTree 161 166 … … 184 189 } 185 190 186 BspTree {187 Construction {188 samples 50000189 epsilon 0.005190 }191 192 # random polygon = 1193 # axis aligned = 2194 # least splits = 4195 # balanced polygons = 8196 # balanced view cells = 16197 # largest polygon area = 32198 # vertical axis = 64199 # blocked rays = 128200 # least ray splits = 256201 # balanced rays = 512202 # pvs = 1024203 204 # least splits + balanced polygons205 #splitPlaneStrategy 12206 207 #axis aligned + vertical axis208 #splitPlaneStrategy 66209 210 # axis aligned + balanced view cells211 # splitPlaneStrategy 18212 213 # largest polygon area214 #splitPlaneStrategy 32215 216 # axus aligned + balanced polygons217 #splitPlaneStrategy 72218 219 # axis aligned + blocked rays220 #splitPlaneStrategy 130221 222 #splitPlaneStrategy 384223 #splitPlaneStrategy 130224 225 splitPlaneStrategy 1024226 227 maxPolyCandidates 50228 maxRayCandidates 50229 230 maxTests 10000231 232 # factors for evaluating split plane costs233 Factor {234 verticalSplits 1.0235 largestPolyArea 1.0236 blockedRays 1.0237 leastRaySplits 1.0238 balancedRays 1.0239 pvs 1.0240 leastSplits 1.0241 balancedPolys 1.0242 balancedViewCells 1.0243 }244 245 Termination {246 # parameters used for autopartition247 minRays 200248 minPolygons -1249 maxDepth 40250 minPvs 100251 minArea 0.01252 maxRayContribution 0.005253 #maxAccRayLength 100254 255 # used for pvs criterium256 ct_div_ci 0.0257 258 # axis aligned splits259 AxisAligned {260 minPolys 5000261 minRays 500262 minObjects 10263 maxCostRatio 0.9264 ct_div_ci 0.5265 }266 }267 268 AxisAligned {269 splitBorder 0.01270 }271 272 273 Visualization {274 # x3d visualization of the split planes275 exportSplits true276 }277 }278 191 279 192 Simulation { … … 355 268 minRays 500 356 269 minObjects 10 357 maxCostRatio 0.9358 ct_div_ci 0.5270 # maxCostRatio 0.9 271 # ct_div_ci 0.5 359 272 } 360 273 } 361 274 362 AxisAligned {363 splitBorder 0.01364 }275 # AxisAligned { 276 # splitBorder 0.01 277 # } 365 278 366 279 -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r487 r492 13 13 #include "ViewCell.h" 14 14 #include "SceneGraph.h" 15 #include "PreprocessorThread.h" 16 17 #include <QApplication> 18 #include <QtOpenGL> 19 #include "GlRenderer.h" 15 20 16 21 #define USE_EXE_PATH false 17 22 18 23 24 25 26 19 27 int 20 main(int argc, c onst char **argv)28 main(int argc, char **argv) 21 29 { 22 30 Debug.open("debug.log"); … … 24 32 environment->Parse(argc, argv, USE_EXE_PATH); 25 33 MeshKdTree::ParseEnvironment(); 26 34 27 35 char buff[128]; 28 36 environment->GetStringValue("Preprocessor.type", buff); … … 48 56 } 49 57 58 preprocessor = p; 50 59 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); 61 73 62 74 // p->mSceneGraph->Export("soda.x3d"); … … 65 77 p->Export(filename + "-kdtree.x3d", false, true, false); 66 78 } 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 } 67 103 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 93 104 // clean up 94 DEL_PTR(p);95 DEL_PTR(environment);105 // DEL_PTR(p); 106 // DEL_PTR(environment); 96 107 97 108 return 0; -
trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro
r463 r492 16 16 17 17 # debuc config 18 CONFIG += console warn_off thread release 18 CONFIG += console warn_off thread release qt 19 19 20 20 # RELEASE CONFIG … … 23 23 # DEPENDPATH = ../../include 24 24 25 QT += opengl 26 25 27 win32:LIBS += xerces-c_2.lib devil.lib ilu.lib ilut.lib 26 28 unix:LIBS += -lxerces-c -lIL -lILU -lILUT 27 29 28 30 # Input 29 HEADERS += Halton.h VssRay.h VssPreprocessor.h RssTree.h 31 HEADERS += Halton.h VssRay.h VssPreprocessor.h RssTree.h GlRenderer.h \ 32 PreprocessorThread.h Preprocessor.h 30 33 31 34 … … 39 42 ViewCell.cpp ViewCellBsp.cpp Halton.cpp VssRay.cpp VssTree.cpp VssPreprocessor.cpp \ 40 43 RenderSimulator.cpp VspKdTree.cpp RayInfo.cpp RssTree.cpp RssPreprocessor.cpp \ 41 ViewCellsManager.cpp VspBspTree.cpp 44 ViewCellsManager.cpp VspBspTree.cpp GlRenderer.cpp \ 45 PreprocessorThread.cpp Renderer.cpp 42 46
Note: See TracChangeset
for help on using the changeset viewer.