Changeset 508


Ignore:
Timestamp:
01/08/06 05:56:40 (18 years ago)
Author:
mattausch
Message:

implemented view cells exporting / loading
improved vsp bsp tree (only axis aligbed until a level), reuse results from Plane
testing, collectmergeneighbors
implemented view cell meshes

Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
3 added
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj

    r498 r508  
    156156                                                Name="VCCustomBuildTool" 
    157157                                                Description="Performing moc on $(InputName).h" 
    158                                                 CommandLine="%qtdir%\bin\moc.exe $(InputDir)$(InputName).h -o $(InputDir)moc_$(InputName).cpp" 
     158                                                CommandLine="%qtdir%\bin\moc.exe $(InputDir)$(InputName).h -o $(InputDir)moc_$(InputName).cpp 
     159" 
    159160                                                Outputs="$(InputDir)moc_$(InputName).cpp"/> 
    160161                                </FileConfiguration> 
     
    225226                        <File 
    226227                                RelativePath="..\src\Parser.h"> 
     228                        </File> 
     229                        <File 
     230                                RelativePath="..\src\Plane3.cpp"> 
    227231                        </File> 
    228232                        <File 
     
    251255                                                Name="VCCustomBuildTool" 
    252256                                                Description="Performing moc on $(InputName).h" 
    253                                                 CommandLine="%qtdir%\bin\moc.exe $(InputDir)$(InputName).h -o $(InputDir)moc_$(InputName).cpp" 
     257                                                CommandLine="%qtdir%\bin\moc.exe $(InputDir)$(InputName).h -o $(InputDir)moc_$(InputName).cpp 
     258" 
    254259                                                Outputs="$(InputDir)moc_$(InputName).cpp"/> 
    255260                                </FileConfiguration> 
     
    265270                                                Name="VCCustomBuildTool" 
    266271                                                Description="Performing moc on $(InputName).h" 
    267                                                 CommandLine="%qtdir%\bin\moc.exe $(InputDir)$(InputName).h -o $(InputDir)moc_$(InputName).cpp" 
     272                                                CommandLine="%qtdir%\bin\moc.exe $(InputDir)$(InputName).h -o $(InputDir)moc_$(InputName).cpp 
     273" 
    268274                                                Outputs="$(InputDir)moc_$(InputName).cpp"/> 
    269275                                </FileConfiguration> 
     
    367373                        <File 
    368374                                RelativePath="..\src\ViewCellsManager.h"> 
     375                        </File> 
     376                        <File 
     377                                RelativePath="..\src\ViewCellsParser.cpp"> 
     378                        </File> 
     379                        <File 
     380                                RelativePath="..\src\ViewCellsParser.h"> 
     381                        </File> 
     382                        <File 
     383                                RelativePath="..\src\ViewCellsParserXerces.h"> 
    369384                        </File> 
    370385                        <File 
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env

    r503 r508  
    1515        filename ../data/atlanta/atlanta2.x3d 
    1616#       filename ../data/soda/soda.dat 
    17 #       filename ../data/soda/soda5.dat 
     17        filename ../data/soda/soda5.dat 
    1818} 
    1919 
     
    2121        # stored sample rays 
    2222        samplesFilename rays.out 
    23         useGlRenderer true 
     23        useGlRenderer false 
    2424#       type sampling 
    2525        type vss 
     
    2828 
    2929VssPreprocessor { 
    30         samplesPerPass  100000 
    31         initialSamples 500000 
    32         vssSamples 2000000 
     30        samplesPerPass  500000 
     31        initialSamples 200000 
     32        vssSamples 200000 
    3333        vssSamplesPerPass 100000 
    3434        useImportanceSampling true 
    3535        loadInitialSamples  false 
    3636        storeInitialSamples false 
     37        useViewSpaceBox true 
     38} 
     39 
     40 
     41SamplingPreprocessor { 
     42        totalSamples 500000 
     43        samplesPerPass  3 
    3744} 
    3845 
     
    160167 
    161168 
    162 Sampling { 
    163         totalSamples 300000 
    164         samplesPerPass  3 
    165 } 
    166169 
    167170ViewCells { 
    168171        loadFromFile false 
     172        exportToFile true 
    169173        #type kdTree 
    170174        #type vspKdTree 
     
    176180        height 5.0 
    177181        maxViewCells 500 
    178         maxPvs 200 
    179          
    180          
     182        maxPvs 500 
     183                 
    181184        PostProcess { 
    182185                # how much samples are used for post processing 
     
    192195                colorCode Random 
    193196                exportRays false 
    194                 exportGeometry false 
     197                exportGeometry true 
    195198        } 
    196199         
     
    199202#       filename ../data/vienna/viewcells-25.x3d 
    200203#       filename ../data/vienna/viewcells-large-sel.x3d 
     204        filename ../scripts/viewcells.xml 
    201205} 
    202206 
     
    220224                maxDepth                40 
    221225                minPvs                  50 
    222                 minRays                 300 
     226                minRays                 700 
    223227                minSize                 0.001 
    224228                maxCostRatio            0.9 
    225229                missTolerance           4 
    226                 maxRayContribution      0.5 
     230                maxRayContribution      0.05 
    227231        } 
    228232         
     
    260264        # balanced rays        = 512 
    261265        # pvs                  = 1024 
    262  
    263         splitPlaneStrategy 1024 
     266         
     267        splitPlaneStrategy 1026 
    264268         
    265269        # maximal candidates for split planes 
     
    268272         
    269273        # maximal tested rays for split cost heuristics 
    270         maxTests 2000 
     274        maxTests 10000 
    271275         
    272276        # factors for evaluating split plane costs 
     
    279283        Termination { 
    280284                # parameters used for autopartition 
    281                 minRays                 200 
     285                minRays                 500 
    282286                minPolygons             -1 
    283287                maxDepth                30 
    284288                minPvs                  20 
    285                 #minArea                0.0001 
    286                 minArea                 0.000 
    287                 maxRayContribution      0.05 
    288                 maxCostRatio            0.9 
     289                minArea                 0.0001 
     290                #minArea                0.000 
     291                maxRayContribution      0.5 
     292                maxCostRatio            0.95 
    289293                missTolerance           5 
    290294                #maxAccRayLength        100 
    291295                 
    292                 maxViewCells            20000 
     296                maxViewCells            200000 
    293297                 
    294298                # used for pvs criterium 
    295299                ct_div_ci 0.0 
     300                 
     301                AxisAligned { 
     302                        minRays                 2000 
     303                        maxRayContribution      0.5 
     304                } 
    296305        } 
    297306         
     
    305314        PostProcess { 
    306315                maxCostRatio 0.1 
    307                 minViewCells 500 
     316                minViewCells 200 
    308317                maxPvsSize   1000 
    309318                useRaysForMerge true 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp

    r503 r508  
    11401140                 "0.1"); 
    11411141 
    1142   RegisterOption("Sampling.totalSamples", 
     1142  RegisterOption("SamplingPreprocessor.totalSamples", 
    11431143                 optInt, 
    11441144                 "total_samples=", 
    11451145                 "1000000"); 
    11461146 
    1147   RegisterOption("Sampling.samplesPerPass", 
     1147  RegisterOption("SamplingPreprocessor.samplesPerPass", 
    11481148                 optInt, 
    11491149                 "samples_per_pass=", 
     
    11911191          optBool, 
    11921192          "-vss_use_viewspace_box=", 
    1193           "true"); 
     1193          "false"); 
    11941194    
    11951195 
     
    11991199 
    12001200 
    1201   RegisterOption("ViewCells.type", 
    1202                  optString, 
    1203                  "view_cells_type", 
    1204                  "bspTree"); 
    1205  
    1206   RegisterOption("ViewCells.PostProcess.samples", 
    1207                                  optInt, 
    1208                                  "view_cells_postprocess_samples=", 
    1209                                  "200000"); 
    1210    
    1211   RegisterOption("ViewCells.Visualization.samples", 
    1212                                  optInt, 
    1213                                  "view_cells_visualization_samples=", 
    1214                                  "20000"); 
    1215    
    1216    RegisterOption("ViewCells.loadFromFile", 
    1217                                   optBool, 
    1218                                   "view_cells_load_from_file", 
    1219                                   "false"); 
    1220     
    1221   RegisterOption("ViewCells.maxViewCells", 
    1222                  optInt, 
    1223                  "view_cells_max_view_cells=", 
    1224                  "0"); 
    1225  
    1226    
    1227   RegisterOption("ViewCells.maxPvs", 
    1228                                  optInt, 
    1229                                  "view_cells_max_pvs=", 
    1230                                  "300"); 
    1231   
    1232   RegisterOption("ViewCells.filename", 
    1233                  optString, 
    1234                  "view_cells_filename=", 
    1235                  "atlanta_viewcells_large.x3d"); 
    1236  
    1237    RegisterOption("ViewCells.height", 
    1238                  optFloat, 
    1239                  "view_cells_height=", 
    1240                  "5.0"); 
    1241  
    1242    RegisterOption("ViewCells.Visualization.colorCode", 
     1201        RegisterOption("ViewCells.type", 
     1202                        optString, 
     1203                        "view_cells_type", 
     1204                        "bspTree"); 
     1205 
     1206        RegisterOption("ViewCells.PostProcess.samples", 
     1207                                        optInt, 
     1208                                        "view_cells_postprocess_samples=", 
     1209                                        "200000"); 
     1210 
     1211        RegisterOption("ViewCells.Visualization.samples", 
     1212                                        optInt, 
     1213                                        "view_cells_visualization_samples=", 
     1214                                        "20000"); 
     1215 
     1216        RegisterOption("ViewCells.loadFromFile", 
     1217                                        optBool, 
     1218                                        "view_cells_load_from_file", 
     1219                                        "false"); 
     1220 
     1221        RegisterOption("ViewCells.exportToFile", 
     1222                                        optBool, 
     1223                                        "view_cells_export_to_file", 
     1224                                        "false"); 
     1225 
     1226        RegisterOption("ViewCells.maxViewCells", 
     1227                        optInt, 
     1228                        "view_cells_max_view_cells=", 
     1229                        "0"); 
     1230 
     1231        RegisterOption("ViewCells.maxPvs", 
     1232                                        optInt, 
     1233                                        "view_cells_max_pvs=", 
     1234                                        "300"); 
     1235 
     1236        RegisterOption("ViewCells.filename", 
     1237                        optString, 
     1238                        "view_cells_filename=", 
     1239                        "atlanta_viewcells_large.x3d"); 
     1240 
     1241        RegisterOption("ViewCells.height", 
     1242                        optFloat, 
     1243                        "view_cells_height=", 
     1244                        "5.0"); 
     1245 
     1246        RegisterOption("ViewCells.Visualization.colorCode", 
    12431247                optString, 
    12441248                "-view_cells_visualization.color_code", 
    12451249                "PVS"); 
    12461250 
    1247    RegisterOption("ViewCells.Visualization.exportRays", 
    1248           optBool, 
    1249           "-bsp_visualization.export_rays", 
    1250           "false"); 
    1251     
    1252    RegisterOption("ViewCells.Visualization.exportGeometry", 
    1253           optBool, 
    1254           "-bsp_visualization.export_geometry", 
    1255           "false"); 
    1256  
    1257   /************************************************************************************/ 
    1258   /*                         Render simulation related options                        */ 
    1259   /************************************************************************************/ 
    1260  
    1261  
    1262   RegisterOption("Simulation.objRenderCost", 
    1263                  optFloat, 
    1264                  "simulation_obj_render_cost", 
    1265                  "1.0"); 
    1266  
    1267   RegisterOption("Simulation.vcOverhead", 
    1268                  optFloat, 
    1269                  "simulation_vc_overhead", 
    1270                  "0.05"); 
    1271  
    1272   RegisterOption("Simulation.moveSpeed", 
    1273                  optFloat, 
    1274                  "simulation_moveSpeed", 
    1275                  "1.0"); 
    1276  
    1277  
    1278  
    1279  
    1280   /************************************************************************************/ 
    1281   /*                         Bsp tree related options                                 */ 
    1282   /************************************************************************************/ 
    1283  
    1284  
    1285   RegisterOption("BspTree.Construction.input", 
    1286           optString, 
    1287           "bsp_construction_input=", 
    1288           "fromViewCells"); 
    1289    
    1290   RegisterOption("BspTree.Construction.samples", 
    1291           optInt, 
    1292           "bsp_construction_samples=", 
    1293           "100000"); 
    1294  
    1295   RegisterOption("BspTree.Construction.epsilon", 
    1296           optFloat, 
    1297           "bsp_construction_side_tolerance=", 
    1298           "0.002"); 
    1299  
    1300   RegisterOption("BspTree.Termination.minPolygons", 
    1301                  optInt, 
    1302                  "bsp_term_min_polygons=", 
    1303                  "5"); 
    1304  
    1305   RegisterOption("BspTree.Termination.minPvs", 
    1306                  optInt, 
    1307                  "bsp_term_min_pvs=", 
    1308                  "20"); 
    1309  
    1310   RegisterOption("BspTree.Termination.minArea", 
    1311                  optFloat, 
    1312                  "bsp_term_min_area=", 
    1313                  "0.001"); 
    1314    
    1315   RegisterOption("BspTree.Termination.maxRayContribution", 
    1316                  optFloat, 
    1317                  "bsp_term_ray_contribution=", 
    1318                  "0.005"); 
    1319  
    1320   RegisterOption("BspTree.Termination.minAccRayLenght", 
    1321                  optFloat, 
    1322                  "bsp_term_min_acc_ray_length=", 
    1323                  "50"); 
    1324  
    1325    RegisterOption("BspTree.Termination.minRays", 
    1326                  optInt, 
    1327                  "bsp_term_min_rays=", 
    1328                  "-1"); 
    1329  
    1330    RegisterOption("BspTree.Termination.ct_div_ci", 
    1331                  optFloat, 
    1332                  "bsp_term_ct_div_ci=", 
    1333                  "0.0"); 
    1334    
    1335   RegisterOption("BspTree.Termination.maxDepth", 
    1336                  optInt, 
    1337                  "bsp_term_max_depth=", 
    1338                  "100"); 
    1339  
    1340   RegisterOption("BspTree.Termination.maxCostRatio", 
    1341                  optFloat, 
    1342                  "bsp_term_axis_aligned_max_cost_ratio=", 
    1343                  "1.5"); 
    1344  
    1345   RegisterOption("BspTree.Termination.AxisAligned.ct_div_ci", 
    1346                  optFloat, 
    1347                  "bsp_term_axis_aligned_ct_div_ci=", 
    1348                  "0.5"); 
    1349  
    1350   RegisterOption("BspTree.AxisAligned.splitBorder", 
    1351                  optFloat, 
    1352                  "bsp__axis_aligned_split_border=", 
    1353                  "0.1"); 
    1354  
    1355   RegisterOption("BspTree.Termination.AxisAligned.minPolys", 
    1356                  optInt, 
    1357                  "bsp_term_axis_aligned_max_polygons=", 
    1358                  "50"); 
    1359  
    1360    RegisterOption("BspTree.Termination.AxisAligned.minObjects", 
    1361                  optInt, 
    1362                  "bsp_term_min_objects=", 
    1363                  "3"); 
    1364  
    1365   RegisterOption("BspTree.Termination.AxisAligned.minRays", 
    1366                  optInt, 
    1367                  "bsp_term_axis_aligned_min_rays=", 
    1368                  "-1"); 
    1369  
    1370   RegisterOption("BspTree.splitPlaneStrategy", 
    1371                  optString, 
    1372                  "bsp_split_method=", 
    1373                  "leastSplits"); 
    1374  
    1375   RegisterOption("BspTree.maxPolyCandidates", 
    1376           optInt, 
    1377           "bsp_max_poly_candidates=", 
    1378           "20"); 
    1379  
    1380   RegisterOption("BspTree.maxRayCandidates", 
    1381           optInt, 
    1382           "bsp_max_plane_candidates=", 
    1383           "20"); 
    1384  
    1385   RegisterOption("BspTree.maxTests", 
    1386           optInt, 
    1387           "bsp_max_tests=", 
    1388           "5000"); 
    1389  
    1390   RegisterOption("BspTree.Visualization.exportSplits", 
    1391           optBool, 
    1392           "bsp_visualization.export_splits", 
    1393           "false"); 
    1394  
    1395   RegisterOption("BspTree.Factor.verticalSplits", optFloat, "bsp_factor_vertical=", "1.0"); 
    1396    RegisterOption("BspTree.Factor.largestPolyArea", optFloat, "bsp_factor_largest_poly=", "1.0"); 
    1397    RegisterOption("BspTree.Factor.blockedRays", optFloat, "bsp_factor_blocked=", "1.0"); 
    1398    RegisterOption("BspTree.Factor.leastSplits", optFloat, "bsp_factor_least_splits=", "1.0"); 
    1399    RegisterOption("BspTree.Factor.balancedPolys", optFloat, "bsp_factor_balanced_polys=", "1.0"); 
    1400    RegisterOption("BspTree.Factor.balancedViewCells", optFloat, "bsp_factor_balanced_view_cells=", "1.0"); 
    1401    RegisterOption("BspTree.Factor.leastRaySplits", optFloat, "bsp_factor_least_ray_splits=", "1.0"); 
    1402    RegisterOption("BspTree.Factor.balancedRays", optFloat, "bsp_factor_balanced_rays=", "1.0"); 
    1403    RegisterOption("BspTree.Factor.pvs", optFloat, "bsp_factor_pvs=", "1.0"); 
    1404  
    1405    /************************************************************************************/ 
    1406    /*                         Preprocessor related options                             */ 
    1407    /************************************************************************************/ 
    1408  
    1409    RegisterOption("Preprocessor.type", 
    1410                                  optString, 
    1411                                  "preprocessor=", 
    1412                                  "sampling"); 
    1413  
    1414    RegisterOption("Preprocessor.samplesFilename", 
    1415                                   optString, 
    1416                                   "-preprocessor_samples_filename=", 
    1417                                   "rays.out"); 
    1418  
    1419   RegisterOption("Preprocessor.useGlRenderer", 
    1420                                  optBool, 
    1421                                  "useGlRenderer", 
    1422                                  "false"); 
    1423    
    1424   /**************************************************************************************/ 
    1425   /*                  View space partition KD tree related options                      */ 
    1426   /**************************************************************************************/ 
    1427  
    1428    RegisterOption("VspKdTree.Construction.samples", 
    1429                                   optInt, 
    1430                                   "vsp_kd_construction_samples=", 
    1431                                   "100000"); 
    1432  
    1433    RegisterOption("VspKdTree.Termination.maxDepth",  
    1434            optInt,  
    1435            "vsp_term_maxdepth=", "30"); 
    1436  
    1437    RegisterOption("VspKdTree.Termination.minPvs",  
    1438            optInt,  
    1439            "vsp_minpvs=",  
    1440            "1"); 
    1441  
    1442    RegisterOption("VspKdTree.Termination.minRays",  
    1443            optInt,  
    1444            "vsp_term_minrays=",  
    1445            "10"); 
    1446  
    1447    RegisterOption("VspKdTree.Termination.minSize",  
    1448            optFloat,  
    1449            "vsp_term_minsize=",  
    1450            "0.001"); 
    1451  
    1452    RegisterOption("VspKdTree.Termination.maxCostRatio",  
    1453            optFloat,  
    1454            "vsp_term_maxcost=", 
    1455            "0.95"); 
    1456  
    1457    RegisterOption("VspKdTree.Termination.maxRayContribution",  
    1458            optFloat,  
    1459            "vsp_term_max_ray_contrib=",  
    1460            "0.5"); 
    1461  
    1462    RegisterOption("VspKdTree.epsilon",  
    1463            optFloat,  
    1464            "kd_eps=",  
    1465            "1e-6"); 
    1466  
    1467    RegisterOption("VspKdTree.ct_div_ci",  
    1468            optFloat,  
    1469            "vsp_ctdivci=", "1.0"); 
    1470     
    1471    RegisterOption("VspKdTree.splitType",  
    1472            optString,  
    1473            "split=",  
    1474            "queries"); 
    1475  
    1476   RegisterOption("VspKdTree.splitAxis",  
    1477            optString,  
    1478            "split=",  
    1479            "drivingAxis"); 
    1480  
    1481   RegisterOption("VspKdTree.splitUseOnlyDrivingAxis",  
    1482           optBool,  
    1483           "vsp_kd_splitdriving=",  
    1484           "false"); 
     1251        RegisterOption("ViewCells.Visualization.exportRays", 
     1252                optBool, 
     1253                "-bsp_visualization.export_rays", 
     1254                "false"); 
     1255 
     1256        RegisterOption("ViewCells.Visualization.exportGeometry", 
     1257                optBool, 
     1258                "-bsp_visualization.export_geometry", 
     1259                "false"); 
     1260 
     1261 
     1262        /************************************************************************************/ 
     1263        /*                         Render simulation related options                        */ 
     1264        /************************************************************************************/ 
     1265 
     1266 
     1267        RegisterOption("Simulation.objRenderCost", 
     1268                        optFloat, 
     1269                        "simulation_obj_render_cost", 
     1270                        "1.0"); 
     1271 
     1272        RegisterOption("Simulation.vcOverhead", 
     1273                        optFloat, 
     1274                        "simulation_vc_overhead", 
     1275                        "0.05"); 
     1276 
     1277        RegisterOption("Simulation.moveSpeed", 
     1278                        optFloat, 
     1279                        "simulation_moveSpeed", 
     1280                        "1.0"); 
     1281 
     1282 
     1283 
     1284 
     1285        /************************************************************************************/ 
     1286        /*                         Bsp tree related options                                 */ 
     1287        /************************************************************************************/ 
     1288 
     1289 
     1290        RegisterOption("BspTree.Construction.input", 
     1291                optString, 
     1292                "bsp_construction_input=", 
     1293                "fromViewCells"); 
     1294 
     1295        RegisterOption("BspTree.Construction.samples", 
     1296                optInt, 
     1297                "bsp_construction_samples=", 
     1298                "100000"); 
     1299 
     1300        RegisterOption("BspTree.Construction.epsilon", 
     1301                optFloat, 
     1302                "bsp_construction_side_tolerance=", 
     1303                "0.002"); 
     1304 
     1305        RegisterOption("BspTree.Termination.minPolygons", 
     1306                        optInt, 
     1307                        "bsp_term_min_polygons=", 
     1308                        "5"); 
     1309 
     1310        RegisterOption("BspTree.Termination.minPvs", 
     1311                        optInt, 
     1312                        "bsp_term_min_pvs=", 
     1313                        "20"); 
     1314 
     1315        RegisterOption("BspTree.Termination.minArea", 
     1316                        optFloat, 
     1317                        "bsp_term_min_area=", 
     1318                        "0.001"); 
     1319 
     1320        RegisterOption("BspTree.Termination.maxRayContribution", 
     1321                        optFloat, 
     1322                        "bsp_term_ray_contribution=", 
     1323                        "0.005"); 
     1324 
     1325        RegisterOption("BspTree.Termination.minAccRayLenght", 
     1326                        optFloat, 
     1327                        "bsp_term_min_acc_ray_length=", 
     1328                        "50"); 
     1329 
     1330        RegisterOption("BspTree.Termination.minRays", 
     1331                        optInt, 
     1332                        "bsp_term_min_rays=", 
     1333                        "-1"); 
     1334 
     1335        RegisterOption("BspTree.Termination.ct_div_ci", 
     1336                        optFloat, 
     1337                        "bsp_term_ct_div_ci=", 
     1338                        "0.0"); 
     1339 
     1340        RegisterOption("BspTree.Termination.maxDepth", 
     1341                        optInt, 
     1342                        "bsp_term_max_depth=", 
     1343                        "100"); 
     1344 
     1345        RegisterOption("BspTree.Termination.maxCostRatio", 
     1346                        optFloat, 
     1347                        "bsp_term_axis_aligned_max_cost_ratio=", 
     1348                        "1.5"); 
     1349 
     1350        RegisterOption("BspTree.Termination.AxisAligned.ct_div_ci", 
     1351                        optFloat, 
     1352                        "bsp_term_axis_aligned_ct_div_ci=", 
     1353                        "0.5"); 
     1354 
     1355        RegisterOption("BspTree.AxisAligned.splitBorder", 
     1356                        optFloat, 
     1357                        "bsp__axis_aligned_split_border=", 
     1358                        "0.1"); 
     1359 
     1360        RegisterOption("BspTree.Termination.AxisAligned.minPolys", 
     1361                        optInt, 
     1362                        "bsp_term_axis_aligned_max_polygons=", 
     1363                        "50"); 
     1364 
     1365        RegisterOption("BspTree.Termination.AxisAligned.minObjects", 
     1366                        optInt, 
     1367                        "bsp_term_min_objects=", 
     1368                        "3"); 
     1369 
     1370        RegisterOption("BspTree.Termination.AxisAligned.minRays", 
     1371                        optInt, 
     1372                        "bsp_term_axis_aligned_min_rays=", 
     1373                        "-1"); 
     1374 
     1375        RegisterOption("BspTree.splitPlaneStrategy", 
     1376                        optString, 
     1377                        "bsp_split_method=", 
     1378                        "leastSplits"); 
     1379 
     1380        RegisterOption("BspTree.maxPolyCandidates", 
     1381                optInt, 
     1382                "bsp_max_poly_candidates=", 
     1383                "20"); 
     1384 
     1385        RegisterOption("BspTree.maxRayCandidates", 
     1386                optInt, 
     1387                "bsp_max_plane_candidates=", 
     1388                "20"); 
     1389 
     1390        RegisterOption("BspTree.maxTests", 
     1391                optInt, 
     1392                "bsp_max_tests=", 
     1393                "5000"); 
     1394 
     1395        RegisterOption("BspTree.Visualization.exportSplits", 
     1396                optBool, 
     1397                "bsp_visualization.export_splits", 
     1398                "false"); 
     1399 
     1400        RegisterOption("BspTree.Factor.verticalSplits", optFloat, "bsp_factor_vertical=", "1.0"); 
     1401        RegisterOption("BspTree.Factor.largestPolyArea", optFloat, "bsp_factor_largest_poly=", "1.0"); 
     1402        RegisterOption("BspTree.Factor.blockedRays", optFloat, "bsp_factor_blocked=", "1.0"); 
     1403        RegisterOption("BspTree.Factor.leastSplits", optFloat, "bsp_factor_least_splits=", "1.0"); 
     1404        RegisterOption("BspTree.Factor.balancedPolys", optFloat, "bsp_factor_balanced_polys=", "1.0"); 
     1405        RegisterOption("BspTree.Factor.balancedViewCells", optFloat, "bsp_factor_balanced_view_cells=", "1.0"); 
     1406        RegisterOption("BspTree.Factor.leastRaySplits", optFloat, "bsp_factor_least_ray_splits=", "1.0"); 
     1407        RegisterOption("BspTree.Factor.balancedRays", optFloat, "bsp_factor_balanced_rays=", "1.0"); 
     1408        RegisterOption("BspTree.Factor.pvs", optFloat, "bsp_factor_pvs=", "1.0"); 
     1409 
     1410        /************************************************************************************/ 
     1411        /*                         Preprocessor related options                             */ 
     1412        /************************************************************************************/ 
     1413 
     1414        RegisterOption("Preprocessor.type", 
     1415                                        optString, 
     1416                                        "preprocessor=", 
     1417                                        "sampling"); 
     1418 
     1419        RegisterOption("Preprocessor.samplesFilename", 
     1420                                        optString, 
     1421                                        "-preprocessor_samples_filename=", 
     1422                                        "rays.out"); 
     1423 
     1424        RegisterOption("Preprocessor.useGlRenderer", 
     1425                                        optBool, 
     1426                                        "useGlRenderer", 
     1427                                        "false"); 
     1428 
     1429        /**************************************************************************************/ 
     1430        /*                  View space partition KD tree related options                      */ 
     1431        /**************************************************************************************/ 
     1432 
     1433        RegisterOption("VspKdTree.Construction.samples", 
     1434                                        optInt, 
     1435                                        "vsp_kd_construction_samples=", 
     1436                                        "100000"); 
     1437 
     1438        RegisterOption("VspKdTree.Termination.maxDepth",  
     1439                optInt,  
     1440                "vsp_term_maxdepth=", "30"); 
     1441 
     1442        RegisterOption("VspKdTree.Termination.minPvs",  
     1443                optInt,  
     1444                "vsp_minpvs=",  
     1445                "1"); 
     1446 
     1447        RegisterOption("VspKdTree.Termination.minRays",  
     1448                optInt,  
     1449                "vsp_term_minrays=",  
     1450                "10"); 
     1451 
     1452        RegisterOption("VspKdTree.Termination.minSize",  
     1453                optFloat,  
     1454                "vsp_term_minsize=",  
     1455                "0.001"); 
     1456 
     1457        RegisterOption("VspKdTree.Termination.maxCostRatio",  
     1458                optFloat,  
     1459                "vsp_term_maxcost=", 
     1460                "0.95"); 
     1461 
     1462        RegisterOption("VspKdTree.Termination.maxRayContribution",  
     1463                optFloat,  
     1464                "vsp_term_max_ray_contrib=",  
     1465                "0.5"); 
     1466 
     1467        RegisterOption("VspKdTree.epsilon",  
     1468                optFloat,  
     1469                "kd_eps=",  
     1470                "1e-6"); 
     1471 
     1472        RegisterOption("VspKdTree.ct_div_ci",  
     1473                optFloat,  
     1474                "vsp_ctdivci=", "1.0"); 
     1475 
     1476        RegisterOption("VspKdTree.splitType",  
     1477                optString,  
     1478                "split=",  
     1479                "queries"); 
     1480 
     1481        RegisterOption("VspKdTree.splitAxis",  
     1482                optString,  
     1483                "split=",  
     1484                "drivingAxis"); 
     1485 
     1486        RegisterOption("VspKdTree.splitUseOnlyDrivingAxis",  
     1487                optBool,  
     1488                "vsp_kd_splitdriving=",  
     1489                "false"); 
    14851490 
    14861491        RegisterOption("VspKdTree.numberOfEndPointDomains",  
     
    15351540 
    15361541        RegisterOption("VspKdTree.Termination.missTolerance", 
    1537                  optInt, 
    1538                  "-vsp_kd_term_miss_tolerance=", 
    1539                  "4"); 
     1542                        optInt, 
     1543                        "-vsp_kd_term_miss_tolerance=", 
     1544                        "4"); 
    15401545 
    15411546        /************************************************************************************/ 
     
    15821587 
    15831588        RegisterOption("RssPreprocessor.vssSamples", 
    1584                                    optInt, 
    1585                                    "rss_vss_samples=", 
    1586                                    "1000000"); 
    1587          
     1589                                        optInt, 
     1590                                        "rss_vss_samples=", 
     1591                                        "1000000"); 
     1592 
    15881593        RegisterOption("RssPreprocessor.vssSamplesPerPass", 
    1589                                    optInt, 
    1590                                    "rss_vss_samples_per_pass=", 
    1591                                    "1000"); 
    1592          
     1594                                        optInt, 
     1595                                        "rss_vss_samples_per_pass=", 
     1596                                        "1000"); 
     1597 
    15931598        RegisterOption("RssPreprocessor.samplesPerPass", 
    1594                                    optInt, 
    1595                                    "rss_samples_per_pass=", 
    1596                                    "100000"); 
    1597          
     1599                                        optInt, 
     1600                                        "rss_samples_per_pass=", 
     1601                                        "100000"); 
     1602 
    15981603        RegisterOption("RssPreprocessor.useImportanceSampling", 
    1599                                    optBool, 
    1600                                    "rss_use_importance", 
    1601                                    "true"); 
    1602          
     1604                                        optBool, 
     1605                                        "rss_use_importance", 
     1606                                        "true"); 
     1607 
    16031608        RegisterOption("RssPreprocessor.objectBasedSampling", 
    1604                                    optBool, 
    1605                                    "rss_object_based_sampling", 
    1606                                    "true"); 
    1607          
     1609                                        optBool, 
     1610                                        "rss_object_based_sampling", 
     1611                                        "true"); 
     1612 
    16081613        RegisterOption("RssPreprocessor.directionalSampling", 
    1609                                    optBool, 
    1610                                    "rss_directional_sampling", 
    1611                                    "false"); 
    1612          
     1614                                        optBool, 
     1615                                        "rss_directional_sampling", 
     1616                                        "false"); 
     1617 
    16131618        RegisterOption("RssTree.maxDepth", optInt, "kd_depth=", "12"); 
    16141619        RegisterOption("RssTree.minPvs", optInt, "kd_minpvs=", "1"); 
     
    16161621        RegisterOption("RssTree.maxCostRatio", optFloat, "maxcost=", "0.95"); 
    16171622        RegisterOption("RssTree.maxRayContribution", optFloat, "maxraycontrib=", "0.5"); 
    1618          
     1623 
    16191624        RegisterOption("RssTree.epsilon", optFloat, "kd_eps=", "1e-6"); 
    16201625        RegisterOption("RssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0"); 
     
    16221627        RegisterOption("RssTree.splitType", optString, "split=", "queries"); 
    16231628        RegisterOption("RssTree.splitUseOnlyDrivingAxis", optBool, "splitdriving=", "false"); 
    1624          
     1629 
    16251630        RegisterOption("RssTree.numberOfEndPointDomains", optInt, "endpoints=", "10000"); 
    1626          
     1631 
    16271632        RegisterOption("RssTree.minSize", optFloat, "minsize=", "0.001"); 
    1628          
     1633 
    16291634        RegisterOption("RssTree.maxTotalMemory", optFloat, "mem=", "60.0"); 
    16301635        RegisterOption("RssTree.maxStaticMemory", optFloat, "statmem=", "8.0"); 
    1631          
     1636 
    16321637        RegisterOption("RssTree.queryType", optString, "qtype=", "static"); 
    1633          
     1638 
    16341639        RegisterOption("RssTree.queryPosWeight", optFloat, "qposweight=", "0.0"); 
    16351640        RegisterOption("RssTree.useRefDirSplits", optBool, "refdir", "false"); 
     
    16381643        RegisterOption("RssTree.accessTimeThreshold", optInt, "accesstime=", "1000"); 
    16391644        RegisterOption("RssTree.minCollapseDepth", optInt, "colldepth=", "4"); 
    1640          
     1645 
    16411646        RegisterOption("RssTree.interleaveDirSplits", optBool, "interleavedirsplits", "true"); 
    16421647        RegisterOption("RssTree.dirSplitDepth", optInt, "dirsplidepth=", "10"); 
    16431648        RegisterOption("RssTree.importanceBasedCost", optBool, "importance_based_cost", "true"); 
    16441649        RegisterOption("RssTree.maxRays", optInt, "rss_max_rays=", "2000000"); 
    1645          
     1650 
    16461651        RegisterOption("RssPreprocessor.Export.pvs", optBool, "rss_export_pvs", "false"); 
    16471652        RegisterOption("RssPreprocessor.Export.rssTree", optBool, "rss_export_rss_tree", "false"); 
     
    16501655        RegisterOption("RssPreprocessor.useViewcells", optBool, "rss_use_viewcells", "false"); 
    16511656        RegisterOption("RssPreprocessor.updateSubdivision", optBool, "rss_update_subdivision", "false"); 
    1652          
    1653          
    1654   /************************************************************************************/ 
    1655   /*               View space partition BSP tree related options                      */ 
    1656   /************************************************************************************/ 
     1657 
     1658 
     1659/************************************************************************************/ 
     1660/*               View space partition BSP tree related options                      */ 
     1661/************************************************************************************/ 
    16571662 
    16581663 
    16591664        RegisterOption("RssPreprocessor.loadInitialSamples", 
    1660                                    optBool, 
    1661                                    "vss_load_loadInitialSamples=", 
    1662                                    "false"); 
     1665                                        optBool, 
     1666                                        "vss_load_loadInitialSamples=", 
     1667                                        "false"); 
    16631668 
    16641669        RegisterOption("RssPreprocessor.storeInitialSamples", 
    1665                                    optBool, 
    1666                                    "vss_store_storeInitialSamples=", 
    1667                                    "false"); 
    1668  
    1669         /************************************************************************************/ 
    1670         /*               View space partition BSP tree related options                      */ 
    1671         /************************************************************************************/ 
     1670                                        optBool, 
     1671                                        "vss_store_storeInitialSamples=", 
     1672                                        "false"); 
     1673 
     1674 
     1675/************************************************************************************/ 
     1676/*               View space partition BSP tree related options                      */ 
     1677/************************************************************************************/ 
     1678 
     1679 
    16721680        RegisterOption("VspBspTree.Termination.minPolygons", 
    1673                                    optInt, 
    1674                                    "vsp_bsp_term_min_polygons=", 
    1675                                    "5"); 
     1681                                        optInt, 
     1682                                        "vsp_bsp_term_min_polygons=", 
     1683                                        "5"); 
    16761684 
    16771685        RegisterOption("VspBspTree.Termination.minPvs", 
    1678                                    optInt, 
    1679                                    "vsp_bsp_term_min_pvs=", 
    1680                                    "20"); 
     1686                                        optInt, 
     1687                                        "vsp_bsp_term_min_pvs=", 
     1688                                        "20"); 
    16811689        RegisterOption("VspBspTree.Termination.minArea", 
    1682                                    optFloat, 
    1683                                    "vsp_bsp_term_min_area=", 
    1684                                    "0.001"); 
     1690                                        optFloat, 
     1691                                        "vsp_bsp_term_min_area=", 
     1692                                        "0.001"); 
    16851693 
    16861694        RegisterOption("VspBspTree.Termination.maxRayContribution", 
    1687                                    optFloat, 
    1688                                    "vsp_bsp_term_ray_contribution=", 
    1689                                    "0.005"); 
     1695                                        optFloat, 
     1696                                        "vsp_bsp_term_ray_contribution=", 
     1697                                        "0.005"); 
    16901698 
    16911699        RegisterOption("VspBspTree.Termination.minAccRayLenght", 
    1692                                    optFloat, 
    1693                                    "vsp_bsp_term_min_acc_ray_length=", 
    1694                                    "50"); 
     1700                                        optFloat, 
     1701                                        "vsp_bsp_term_min_acc_ray_length=", 
     1702                                        "50"); 
    16951703 
    16961704        RegisterOption("VspBspTree.Termination.minRays", 
    1697                                    optInt, 
    1698                                    "vsp_bsp_term_min_rays=", 
    1699                                    "-1"); 
     1705                                        optInt, 
     1706                                        "vsp_bsp_term_min_rays=", 
     1707                                        "-1"); 
    17001708 
    17011709        RegisterOption("VspBspTree.Termination.ct_div_ci", 
    1702                                    optFloat, 
    1703                                    "vsp_bsp_term_ct_div_ci=", 
    1704                                    "0.0"); 
     1710                                        optFloat, 
     1711                                        "vsp_bsp_term_ct_div_ci=", 
     1712                                        "0.0"); 
    17051713 
    17061714        RegisterOption("VspBspTree.Termination.maxDepth", 
    1707                                    optInt, 
    1708                                    "vsp_bsp_term_max_depth=", 
    1709                                    "100"); 
     1715                                        optInt, 
     1716                                        "vsp_bsp_term_max_depth=", 
     1717                                        "100"); 
    17101718 
    17111719        RegisterOption("VspBspTree.Termination.AxisAligned.maxCostRatio", 
     
    17251733 
    17261734        RegisterOption("VspBspTree.Termination.missTolerance", 
    1727                                    optInt, 
    1728                                    "vsp_bsp_term_miss_tolerance=", 
    1729                                    "4"); 
     1735                                        optInt, 
     1736                                        "vsp_bsp_term_miss_tolerance=", 
     1737                                        "4"); 
    17301738        RegisterOption("VspBspTree.splitPlaneStrategy", 
    1731                                    optString, 
    1732                                    "vsp_bsp_split_method=", 
    1733                                    "leastSplits"); 
     1739                                        optString, 
     1740                                        "vsp_bsp_split_method=", 
     1741                                        "leastSplits"); 
    17341742 
    17351743        RegisterOption("VspBspTree.maxPolyCandidates", 
    1736                                    optInt, 
    1737                                    "vsp_bsp_max_poly_candidates=", 
    1738                                    "20"); 
     1744                                        optInt, 
     1745                                        "vsp_bsp_max_poly_candidates=", 
     1746                                        "20"); 
    17391747        RegisterOption("VspBspTree.maxRayCandidates", 
    1740                                    optInt, 
    1741                                    "vsp_bsp_max_plane_candidates=", 
    1742                                    "20"); 
     1748                                        optInt, 
     1749                                        "vsp_bsp_max_plane_candidates=", 
     1750                                        "20"); 
    17431751 
    17441752        RegisterOption("VspBspTree.maxTests", 
    1745                                    optInt, 
    1746                                    "vsp_bsp_max_tests=", 
    1747                                    "5000"); 
     1753                                        optInt, 
     1754                                        "vsp_bsp_max_tests=", 
     1755                                        "5000"); 
    17481756 
    17491757        RegisterOption("VspBspTree.Construction.samples", 
    1750                                    optInt, 
    1751                                    "bsp_construction_samples=", 
    1752                                    "100000"); 
     1758                                        optInt, 
     1759                                        "bsp_construction_samples=", 
     1760                                        "100000"); 
    17531761 
    17541762        RegisterOption("VspBspTree.Construction.epsilon", 
    1755                                    optFloat, 
    1756                                    "vsp_bsp_construction_side_tolerance=", 
    1757                                    "0.002"); 
     1763                                        optFloat, 
     1764                                        "vsp_bsp_construction_side_tolerance=", 
     1765                                        "0.002"); 
    17581766 
    17591767        RegisterOption("VspBspTree.Visualization.exportSplits", 
    1760                                    optBool, 
    1761                                    "vsp_bsp_visualization.export_splits", 
    1762                                    "false"); 
     1768                                        optBool, 
     1769                                        "vsp_bsp_visualization.export_splits", 
     1770                                        "false"); 
     1771 
     1772        RegisterOption("VspBspTree.splitUseOnlyDrivingAxis",  
     1773                                        optBool,  
     1774                                        "vsp_bsp_splitdriving=",  
     1775                                        "false"); 
     1776 
     1777        RegisterOption("VspBspTree.Termination.AxisAligned.minRays", 
     1778                        optInt, 
     1779                        "bsp_term_axis_aligned_min_rays=", 
     1780                        "100"); 
    17631781         
    1764         RegisterOption("VspBspTree.splitUseOnlyDrivingAxis",  
    1765                                    optBool,  
    1766                                    "vsp_bsp_splitdriving=",  
    1767                                    "false"); 
    1768          
     1782        RegisterOption("VspBspTree.Termination.AxisAligned.maxRayContribution", 
     1783                        optFloat, 
     1784                        "bsp_term_axis_aligned_min_rays=", 
     1785                        "0.1"); 
     1786 
    17691787        RegisterOption("VspBspTree.Factor.leastRaySplits", optFloat, "-vsp_bsp_factor_least_ray_splits=", "1.0"); 
    17701788        RegisterOption("VspBspTree.Factor.balancedRays", optFloat, "-vsp_bsp_factor_balanced_rays=", "1.0"); 
     
    17851803                "vsp_bsp_term_post_process_max_pvs_size=",  
    17861804                "100"); 
    1787          
     1805 
    17881806        RegisterOption("VspBspTree.PostProcess.useRaysForMerge",  
    17891807                optBool,  
     
    17951813                "vsp_bsp_construction_randomize=",  
    17961814                "false"); 
     1815 
     1816         
     1817        RegisterOption("VspBspTree.maxTotalMemory",  
     1818                optFloat,  
     1819                "vsp_bsp_max_total_mem=",  
     1820                "60.0"); 
     1821 
     1822        RegisterOption("VspBspTree.maxStaticMemory",  
     1823                optFloat,  
     1824                "vsp_bsp_max_static_mem=",  
     1825                "8.0"); 
    17971826        ////////////////////////////////////////////////////////////////////////////////// 
    17981827} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Parser.h

    r339 r508  
    1414  Parser() {} 
    1515 
    16         virtual bool ParseFile(const string filename, SceneGraphNode **root) = 0; 
     16  virtual bool ParseFile(const string filename, SceneGraphNode **root) {return false;}; 
    1717         
    1818}; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp

    r503 r508  
    477477        int i = 1; 
    478478        int j = 0; 
    479         int k = mVertices.size() - 1; 
     479        int k = (int)mVertices.size() - 1; 
    480480        int count = 0; 
    481481 
     
    490490        } 
    491491} 
     492 
     493 
     494void Polygon3::Triangulate(VertexIndexContainer &indices) 
     495{ 
     496        int i = 1; 
     497        int j = 0; 
     498        int k = (int)mVertices.size() - 1; 
     499 
     500        int count = 0; 
     501 
     502        while (i < k) 
     503        { 
     504                indices.push_back(k); 
     505                indices.push_back(j); 
     506                indices.push_back(i); 
     507 
     508                if ((count ++) % 2) 
     509                        j = i ++; 
     510                else 
     511                        j = k --; 
     512        } 
     513} 
     514 
     515 
     516void Polygon3::AddToMesh(Mesh &mesh) 
     517{ 
     518        const int n = (int)mesh.mVertices.size(); 
     519 
     520    //-- add the vertices 
     521    VertexContainer::const_iterator vit, vit_end = mVertices.end(); 
     522        for (vit = mVertices.begin(); vit != vit_end; ++ vit) 
     523        { 
     524                mesh.mVertices.push_back(*vit); 
     525        } 
     526 
     527        // one quad => no triangulation necessary 
     528        if ((int)mVertices.size() == 4) 
     529        { 
     530                mesh.AddFace(new Face(n, n + 1, n + 2, n + 3)); 
     531        } 
     532        else 
     533        { 
     534                VertexIndexContainer indices; 
     535                Triangulate(indices); 
     536 
     537                // add indices of triangle strip 
     538                for (int i = 0; i < (int)indices.size(); i += 3) 
     539                { 
     540                        Face *face = new Face(n + indices[i],  
     541                                                                  n + indices[i + 1],  
     542                                                                  n + indices[i + 2]); 
     543                        mesh.AddFace(face); 
     544                } 
     545        } 
     546} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h

    r503 r508  
    9898        int CastRay(const Ray &ray, float &t, const float nearestT); 
    9999 
    100         /** The polygon is triangulated. 
     100        /** The polygon is converted to triangles. 
    101101        */ 
    102102        void Triangulate(vector<Triangle3> &triangles); 
    103  
     103        /** 
     104                Adds polygon to mesh 
     105        */ 
     106        void AddToMesh(Mesh &mesh); 
     107        /**  
     108                Triangle strip indices are created from this polgon. 
     109        */ 
     110        void Triangulate(VertexIndexContainer &indices); 
     111         
    104112        /** The piercing rays of the polygon are inherited by the child fragments 
    105113                @parm front_piece the front fragment inheriting the front rays 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp

    r496 r508  
    5959Preprocessor::LoadScene(const string filename) 
    6060{ 
    61   // use leaf nodes of the original spatial hiearrchy as occludees 
    62  
    63   mSceneGraph = new SceneGraph; 
     61        // use leaf nodes of the original spatial hiearrchy as occludees 
     62        mSceneGraph = new SceneGraph; 
    6463   
    65   Parser *parser; 
     64        Parser *parser; 
    6665        vector<string> filenames; 
    6766        int files = SplitFilenames(filename, filenames); 
     
    176175} 
    177176 
     177 
    178178bool Preprocessor::PrepareViewCells() 
    179179{ 
     
    257257                environment->GetStringValue("ViewCells.filename", buff); 
    258258                string vcFilename(buff); 
    259                 mViewCellsManager->LoadViewCells(vcFilename); 
     259                mViewCellsManager->LoadViewCells(vcFilename, &mObjects); 
    260260        } 
    261261 
     
    364364} 
    365365 
    366 bool Preprocessor::WriteSamples(const VssRayContainer &samples) const 
     366 
     367bool Preprocessor::ExportSamples(const VssRayContainer &samples) const 
    367368{ 
    368369        char fileName[100]; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h

    r496 r508  
    9696          @returns true if samples were written successfully 
    9797  */ 
    98   bool WriteSamples(const VssRayContainer &samples) const; 
     98  bool ExportSamples(const VssRayContainer &samples) const; 
     99 
    99100  /// scene graph loaded from file 
    100101  SceneGraph *mSceneGraph; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RayInfo.cpp

    r485 r508  
    139139        // non-intersecting, otherwise polygon-plane intersections of bsp tree 
    140140        // approaches are not eliminating any rays intersecting the polygon! 
    141  
    142         //if (t > GetMaxT()) 
     141#if 1 
    143142        if (t >= GetMaxT() - 1e-20) 
    144143                return splitPlane.Side(ExtrapOrigin()); 
    145         //if (t < GetMinT()) 
    146144        if (t <= GetMinT() + 1e-20) 
    147145                return splitPlane.Side(ExtrapTermination()); 
    148  
     146#else 
     147        if (t > GetMaxT()) 
     148                return splitPlane.Side(ExtrapOrigin()); 
     149        else if (t < GetMinT()) 
     150                return splitPlane.Side(ExtrapTermination()); 
     151#endif 
    149152        return 0; 
    150153} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp

    r504 r508  
    580580        cout << "#totalRayStackSize=" << (int)mVssRays.size() << endl <<flush; 
    581581         
    582         rssSamples += mVssRays.size(); 
     582        rssSamples += (int)mVssRays.size(); 
    583583         
    584584         
     
    592592          { 
    593593                cout << "Writing samples to file ... "; 
    594                 WriteSamples(mVssRays); 
     594                ExportSamples(mVssRays); 
    595595                cout << "finished\n" << endl; 
    596596          } 
     
    731731          VssRayContainer contributingRays; 
    732732          vssRays.GetContributingRays(contributingRays, mPass); 
    733           mStats<<"#NUM_CONTRIBUTING_RAYS\n"<<contributingRays.size()<<endl; 
     733          mStats<<"#NUM_CONTRIBUTING_RAYS\n"<<(int)contributingRays.size()<<endl; 
    734734          sprintf(filename, "rss-crays-%04d.x3d", rssPass); 
    735735          ExportRays(filename, contributingRays, mExportNumRays); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r503 r508  
    25272527 
    25282528 
     2529BspNodeGeometry::BspNodeGeometry(const BspNodeGeometry &rhs) 
     2530{ 
     2531        PolygonContainer::const_iterator it, it_end = rhs.mPolys.end(); 
     2532        for (it = rhs.mPolys.begin(); it != it_end; ++ it) 
     2533        { 
     2534                Polygon3 *poly = *it; 
     2535                mPolys.push_back(new Polygon3(*poly)); 
     2536        } 
     2537} 
     2538 
    25292539BspNodeGeometry::~BspNodeGeometry() 
    25302540{ 
     
    25422552{ 
    25432553        PolygonContainer::const_iterator it, it_end = mPolys.end(); 
    2544         int vcount = 0; 
    2545  
     2554         
    25462555        for (it = mPolys.begin(); it != mPolys.end(); ++ it) 
    25472556        { 
    2548                 Polygon3 *poly = *it; 
    2549                  
    2550                 vector<Triangle3> triangles; 
    2551                 poly->Triangulate(triangles); 
    2552                 vector<Triangle3>::const_iterator tit, tit_end = triangles.end(); 
    2553          
    2554                 for (tit = triangles.begin(); tit != tit_end; ++ tit) 
    2555                 { 
    2556                         mesh.mVertices.push_back((*tit).mVertices[0]); 
    2557                         mesh.mVertices.push_back((*tit).mVertices[1]); 
    2558                         mesh.mVertices.push_back((*tit).mVertices[2]); 
    2559  
    2560                         Face *face = new Face(vcount ++, vcount ++, vcount ++); 
    2561                         mesh.AddFace(face); 
    2562                 } 
     2557                (*it)->AddToMesh(mesh); 
    25632558        } 
    25642559} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r503 r508  
    2525        BspNodeGeometry() 
    2626        {};   
     27 
     28        // copy constructor copying the polygon array 
     29        BspNodeGeometry(const BspNodeGeometry &rhs); 
    2730 
    2831        ~BspNodeGeometry(); 
     
    330333        /// leaf pvs 
    331334        ObjectPvs *mPvs; 
     335 
    332336        /// leaf area 
    333337        float mArea; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp

    r503 r508  
    1111#include "Exporter.h" 
    1212#include "VspBspTree.h" 
    13  
     13#include "ViewCellsParser.h" 
    1414 
    1515ViewCellsManager::ViewCellsManager(): 
     
    6666 
    6767 
    68 bool ViewCellsManager::LoadViewCells(const string filename) 
     68bool ViewCellsManager::LoadViewCells(const string filename, ObjectContainer *objects) 
    6969{ 
    7070        X3dParser parser; 
     
    317317{ 
    318318        mViewCells.clear(); 
    319  
     319         
    320320        CollectViewCells(); 
     321         
    321322        mViewCellsStats.Reset(); 
    322323        EvaluateViewCellsStats(); 
     
    328329void ViewCellsManager::ComputeSampleContributions(VssRay &ray) 
    329330{ 
    330  
    331  
    332  
    333331  ViewCellContainer viewcells; 
    334332 
     
    445443 
    446444 
    447 void ViewCellsManager::ExportViewCells(Exporter *exporter) const 
     445void ViewCellsManager::CreateUniqueViewCellIds() 
     446{ 
     447        for (int i = 0; i < (int)mViewCells.size(); ++ i) 
     448                mViewCells[i]->SetId(i); 
     449} 
     450 
     451 
     452void ViewCellsManager::ExportViewCellsForViz(Exporter *exporter) const 
    448453{ 
    449454        ViewCellContainer::const_iterator it, it_end = mViewCells.end(); 
     
    457462 
    458463 
    459  
    460464void ViewCellsManager::CreateViewCellsMeshes() 
    461465{ 
     
    468472        } 
    469473} 
     474 
     475 
     476bool ViewCellsManager::ExportViewCells(const string filename)  
     477{  
     478        return false; 
     479} 
     480 
     481 
     482void ViewCellsManager::ExportViewCell(ViewCell *viewCell, ofstream &stream) 
     483{ 
     484        stream << "<ViewCell id=\"" << viewCell->GetId() << "\" "; 
     485        stream << "pvs=\""; 
     486 
     487        ObjectPvsMap::iterator it, it_end = viewCell->GetPvs().mEntries.end(); 
     488        if(0) // test with empty pvs 
     489        for (it = viewCell->GetPvs().mEntries.begin(); it != it_end; ++ it) 
     490        { 
     491                stream << (*it).first->GetId() << " "; 
     492        } 
     493 
     494        stream << "\" />" << endl; 
     495} 
     496 
    470497 
    471498/**********************************************************************/ 
     
    617644                        //exporter->SetWireframe(); 
    618645                        exporter->SetFilled(); 
    619                         ExportViewCells(exporter); 
     646                        ExportViewCellsForViz(exporter); 
    620647 
    621648                        if (mExportGeometry) 
     
    723750                if (exporter) 
    724751                { 
    725                         ExportViewCells(exporter); 
     752                        ExportViewCellsForViz(exporter); 
    726753                        delete exporter; 
    727754                } 
     
    16051632        //else exporter->SetFilled(); 
    16061633 
    1607         ExportViewCells(exporter); 
     1634        ExportViewCellsForViz(exporter); 
    16081635 
    16091636        if (mExportGeometry) 
     
    17891816        GetRaySets(rays, mConstructionSamples, constructionRays, &savedRays); 
    17901817 
    1791         Debug << "construction rays: " << (int)savedRays.size() << endl; 
    1792         Debug << "saved rays: " << (int)constructionRays.size() << endl; 
     1818        Debug << "construction rays: " << (int)constructionRays.size() << endl; 
     1819        Debug << "saved rays: " << (int)savedRays.size() << endl; 
    17931820 
    17941821        mVspBspTree->Construct(constructionRays, &mSceneBox); 
     
    18181845                        //exporter->SetWireframe(); 
    18191846                        exporter->SetFilled(); 
    1820                         ExportViewCells(exporter); 
     1847                        ExportViewCellsForViz(exporter); 
    18211848 
    18221849                        if (0 && mExportRays) 
     
    19091936                        //exporter->SetWireframe(); 
    19101937                        exporter->SetFilled(); 
    1911                         ExportViewCells(exporter); 
     1938                        ExportViewCellsForViz(exporter); 
    19121939 
    19131940                        if (mExportGeometry) 
     
    19601987        } 
    19611988 
     1989        // real meshes are only contructed only at this stage 
    19621990        CreateViewCellsMeshes(); 
     1991        // write view cells to disc 
     1992        if (mExportViewCells) 
     1993        { 
     1994                ExportViewCells("viewcells.xml"); 
     1995        } 
    19631996 
    19641997        return 0; 
     
    20252058                        } 
    20262059 
    2027                         ExportViewCells(exporter); 
     2060                        ExportViewCellsForViz(exporter); 
    20282061                        delete exporter; 
    20292062                } 
     
    23102343ViewCell *VspBspViewCellsManager::GetViewCell(const Vector3 &point) 
    23112344{ 
    2312   if (!mVspBspTree) 
    2313         return NULL; 
    2314   return mVspBspTree->GetViewCell(point); 
     2345        if (!mVspBspTree) 
     2346                return NULL; 
     2347        return mVspBspTree->GetViewCell(point); 
    23152348} 
    23162349 
     
    23272360        mMeshContainer.push_back(mesh); 
    23282361} 
     2362 
     2363 
     2364bool VspBspViewCellsManager::LoadViewCells(const string filename, ObjectContainer *objects) 
     2365{ 
     2366        ViewCellsParser parser; 
     2367         
     2368        DEL_PTR(mVspBspTree); 
     2369        mVspBspTree = new VspBspTree(); 
     2370         
     2371        bool success = parser.ParseFile(filename, mVspBspTree, this, objects); 
     2372        ResetViewCells(); 
     2373         
     2374        Debug << (int)mViewCells.size() << " view cells loaded" << endl; 
     2375 
     2376        return success; 
     2377} 
     2378 
     2379 
     2380inline bool ilt(Intersectable *obj1, Intersectable *obj2) 
     2381{ 
     2382        return obj1->mId < obj2->mId; 
     2383} 
     2384 
     2385 
     2386bool VspBspViewCellsManager::ExportViewCells(const string filename) 
     2387{ 
     2388        cout << "exporting view cells to xml ... ";  
     2389        std::ofstream stream; 
     2390 
     2391        // for output we need unique ids 
     2392        CreateUniqueViewCellIds(); 
     2393 
     2394        stream.open(filename.c_str()); 
     2395        stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"<<endl; 
     2396        stream << "<Visibility_Solution>" << endl; 
     2397         
     2398        //-- load the view cells itself, i.e., the ids and the pvs 
     2399        stream << "<ViewCells>" << endl; 
     2400        ViewCellContainer::const_iterator it, it_end = mViewCells.end(); 
     2401        for (it = mViewCells.begin(); it != it_end; ++ it) 
     2402                ExportViewCell(*it, stream); 
     2403     
     2404        stream << "</ViewCells>" << endl; 
     2405         
     2406        //-- load the hierarchy 
     2407        stream << "<BspTree>" << endl; 
     2408        mVspBspTree->Export(stream); 
     2409        stream << endl << "</BspTree>" << endl; 
     2410         
     2411        stream << "</Visibility_Solution>" << endl; 
     2412        stream.close(); 
     2413 
     2414        cout << "finished" << endl; 
     2415 
     2416        return true; 
     2417} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h

    r503 r508  
    104104                @return true on success 
    105105    */ 
    106     bool LoadViewCells(const string filename); 
     106    virtual bool LoadViewCells(const string filename, ObjectContainer *objects); 
    107107 
    108108        /** Constructs view cell from base triangle. The ViewCell is extruded along the normal vector. 
     
    237237        virtual void CreateMesh(ViewCell *vc) = NULL; 
    238238 
     239        /** Writes view cells to disc. 
     240        */ 
     241        virtual bool ExportViewCells(const string filename); 
     242 
    239243protected: 
    240244 
    241245        void ParseEnvironment(); 
    242246 
     247        /** Creates unique view cell ids. 
     248        */ 
     249        void CreateUniqueViewCellIds(); 
    243250        /** Recollects view cells and resets statistics. 
    244251        */ 
     
    254261        void EvaluateViewCellsStats(); 
    255262 
    256  
    257263        //-- helper functions for view cell visualization 
    258264 
    259265        /** Exports the view cell partition. 
    260266        */ 
    261         void ExportViewCells(Exporter *exporter) const; 
     267        void ExportViewCellsForViz(Exporter *exporter) const; 
    262268 
    263269        /** Sets exporter color. 
     
    272278        */ 
    273279        void CreateViewCellsMeshes(); 
     280 
     281        /** 
     282                Exports single view cell. 
     283                NOTE: should be in exporter!! 
     284        */ 
     285        void ExportViewCell(ViewCell *viewCell, ofstream &stream); 
    274286 
    275287        /// the view cell corresponding to space ouside the valid view space 
     
    298310        /// the scene bounding box 
    299311        AxisAlignedBox3 mSceneBox; 
    300  
     312        /// holds the view cell meshes 
    301313        MeshContainer mMeshContainer; 
    302  
     314        /// if view cells should be exported 
     315        bool mExportViewCells; 
    303316        //-- visualization options 
    304317         
     
    551564        void CreateMesh(ViewCell *vc); 
    552565 
     566        bool LoadViewCells(const string filename, ObjectContainer *objects); 
     567        bool ExportViewCells(const string filename); 
     568 
    553569protected: 
    554570 
    555571        /** Merges the view cells. 
    556572        */ 
    557         void MergeViewCells(const VssRayContainer &rays, const ObjectContainer &objects); 
     573        void MergeViewCells(const VssRayContainer &rays,  
     574                                                const ObjectContainer &objects); 
    558575         
    559576        void RefineViewCells(const VssRayContainer &rays); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp

    r503 r508  
    1919 
    2020//-- static members 
     21 
    2122/** Evaluates split plane classification with respect to the plane's 
    2223        contribution for a minimum number of ray splits. 
     
    3536float BspMergeCandidate::sOverallCost = 0; 
    3637 
    37 /****************************************************************/ 
    38 /*                  class VspBspTree implementation             */ 
    39 /****************************************************************/ 
     38/********************************************************************/ 
     39/*                  class VspBspTree implementation                 */ 
     40/********************************************************************/ 
    4041 
    4142VspBspTree::VspBspTree(): 
     
    4445mCostNormalizer(Limits::Small), 
    4546mViewCellsManager(NULL), 
    46 mStoreRays(false), 
    4747mOutOfBoundsCell(NULL), 
    48 mShowInvalidSpace(false) 
     48mShowInvalidSpace(false), 
     49mStoreRays(false) 
    4950{ 
    5051        bool randomize = false; 
     
    8889        environment->GetIntValue("ViewCells.maxPvs", mMaxPvs); 
    8990 
     91        //-- termination criteria for axis aligned split 
     92        environment->GetFloatValue("VspBspTree.Termination.AxisAligned.maxRayContribution",  
     93                mTermMaxRayContriForAxisAligned); 
     94        environment->GetIntValue("VspBspTree.Termination.AxisAligned.minRays", 
     95                mTermMinRaysForAxisAligned); 
     96 
     97        //environment->GetFloatValue("VspBspTree.maxTotalMemory", mMaxTotalMemory); 
     98        environment->GetFloatValue("VspBspTree.maxStaticMemory", mMaxMemory); 
    9099 
    91100        //-- debug output 
     
    135144} 
    136145 
     146BspViewCell *VspBspTree::GetOutOfBoundsCell() 
     147{ 
     148        return mOutOfBoundsCell; 
     149} 
     150 
    137151 
    138152BspViewCell *VspBspTree::GetOrCreateOutOfBoundsCell() 
    139153{ 
    140154        if (!mOutOfBoundsCell) 
     155        { 
    141156                mOutOfBoundsCell = new BspViewCell(); 
    142  
     157                mOutOfBoundsCell->SetId(-1); 
     158        } 
    143159        return mOutOfBoundsCell; 
    144160} 
     
    326342} 
    327343 
     344 
     345// return memory usage in MB 
     346float VspBspTree::GetMemUsage() const 
     347{ 
     348        return 
     349                (sizeof(VspBspTree) + 
     350                 mStat.Leaves() * sizeof(BspLeaf) + 
     351                 mStat.Interior() * sizeof(BspInterior) + 
     352                 mStat.accumRays * sizeof(RayInfo)) / (1024.0f * 1024.0f); 
     353} 
     354 
     355 
     356 
    328357void VspBspTree::Construct(const PolygonContainer &polys, RayInfoContainer *rays) 
    329358{ 
     
    350379 
    351380        long startTime = GetTime(); 
     381         
     382        bool mOutOfMemory = false; 
    352383 
    353384        while (!tStack.empty()) 
    354385        { 
    355386                tData = tStack.top(); 
    356  
    357             tStack.pop(); 
     387            tStack.pop();                
     388 
     389                if (0 && !mOutOfMemory) 
     390                { 
     391                        float mem = GetMemUsage(); 
     392 
     393                        if (mem > mMaxMemory) 
     394                        { 
     395                                mOutOfMemory = true; 
     396                                Debug << "memory limit reached: " << mem << endl; 
     397                        } 
     398                } 
    358399 
    359400                // subdivide leaf node 
     
    365406        } 
    366407 
     408        Debug << "Used Memory: " << GetMemUsage() << " MB" << endl; 
    367409        cout << "finished\n"; 
    368410 
    369411        mStat.Stop(); 
    370412} 
     413 
    371414 
    372415bool VspBspTree::TerminationCriteriaMet(const VspBspTraversalData &data) const 
     
    377420                 (data.mArea <= mTermMinArea) || 
    378421                 (mStat.Leaves() >= mMaxViewCells) || 
    379                 // (data.GetAvgRayContribution() >= mTermMaxRayContribution) || 
     422                (data.GetAvgRayContribution() >= mTermMaxRayContribution) || 
    380423                 (data.mDepth >= mTermMaxDepth)); 
    381424} 
     425 
    382426 
    383427BspNode *VspBspTree::Subdivide(VspBspTraversalStack &tStack, 
     
    386430        BspNode *newNode = tData.mNode; 
    387431 
    388         if (!TerminationCriteriaMet(tData)) 
     432        if (!mOutOfMemory || !TerminationCriteriaMet(tData)) 
    389433        { 
    390434                PolygonContainer coincident; 
     
    423467                } 
    424468                else 
    425                 { 
    426                         // create new view cell for this leaf 
     469                {       // create new view cell for this leaf                    
    427470                        viewCell = new BspViewCell(); 
    428471                } 
     
    465508{ 
    466509        BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode); 
    467  
    468         int maxCostMisses = tData.mMaxCostMisses; 
    469  
     510         
    470511        // select subdivision plane 
    471512        Plane3 splitPlane; 
    472         if (!SelectPlane(splitPlane, leaf, tData)) 
     513        int maxCostMisses = tData.mMaxCostMisses; 
     514        bool success = SelectPlane(splitPlane,  
     515                                                           leaf,  
     516                                                           tData, 
     517                                                           frontData, 
     518                                                           backData); 
     519        if (!success) 
    473520        { 
    474521                ++ maxCostMisses; 
     
    492539 
    493540        //-- the front and back traversal data is filled with the new values 
     541        frontData.mDepth = tData.mDepth + 1; 
    494542        frontData.mPolygons = new PolygonContainer(); 
    495         frontData.mDepth = tData.mDepth + 1; 
    496543        frontData.mRays = new RayInfoContainer(); 
    497         frontData.mGeometry = new BspNodeGeometry(); 
    498  
     544         
     545        backData.mDepth = tData.mDepth + 1; 
    499546        backData.mPolygons = new PolygonContainer(); 
    500         backData.mDepth = tData.mDepth + 1; 
    501547        backData.mRays = new RayInfoContainer(); 
    502         backData.mGeometry = new BspNodeGeometry(); 
    503  
     548         
    504549        // subdivide rays 
    505550        SplitRays(interior->GetPlane(), 
     
    524569        backData.mPvs = ComputePvsSize(*backData.mRays); 
    525570 
    526         // split geometry and compute area 
    527         if (1) 
    528         { 
    529                 tData.mGeometry->SplitGeometry(*frontData.mGeometry, 
    530                                                                            *backData.mGeometry, 
    531                                                                            interior->GetPlane(), 
    532                                                                            mBox, 
    533                                                                            mEpsilon); 
    534  
    535                 frontData.mArea = frontData.mGeometry->GetArea(); 
    536                 backData.mArea = backData.mGeometry->GetArea(); 
    537         } 
    538  
    539         // compute accumulated ray length 
    540         //frontData.mAccRayLength = AccumulatedRayLength(*frontData.mRays); 
    541         //backData.mAccRayLength = AccumulatedRayLength(*backData.mRays); 
     571        // split front and back node geometry and compute area 
     572        if (mPvsUseArea) 
     573        { 
     574                // if not already computed 
     575                if (!frontData.mGeometry && !backData.mGeometry) 
     576                { 
     577                        frontData.mGeometry = new BspNodeGeometry(); 
     578                        backData.mGeometry = new BspNodeGeometry(); 
     579 
     580                        tData.mGeometry->SplitGeometry(*frontData.mGeometry, 
     581                                                                                   *backData.mGeometry, 
     582                                                                                   interior->GetPlane(), 
     583                                                                                   mBox, 
     584                                                                                   mEpsilon); 
     585                 
     586                        frontData.mArea = frontData.mGeometry->GetArea(); 
     587                        backData.mArea = backData.mGeometry->GetArea(); 
     588                } 
     589        } 
     590        else 
     591        { 
     592                frontData.mArea = (float)frontData.mRays->size(); 
     593                backData.mArea = (float)backData.mRays->size(); 
     594        } 
    542595 
    543596        //-- create front and back leaf 
     
    565618        return interior; 
    566619} 
     620 
    567621 
    568622void VspBspTree::AddToPvs(BspLeaf *leaf, 
     
    757811                                                                                 const VspBspTraversalData &tData, 
    758812                                                                                 int &axis, 
    759                                                                                  float &position, 
    760                                                                                  int &raysBack, 
    761                                                                                  int &raysFront, 
    762                                                                                  int &pvsBack, 
    763                                                                                  int &pvsFront) 
    764 { 
    765         AxisAlignedBox3 box; 
    766         box.Initialize(); 
    767  
    768         // create bounding box of region 
    769         RayInfoContainer::const_iterator ri, ri_end = tData.mRays->end(); 
    770  
    771         for(ri = tData.mRays->begin(); ri < ri_end; ++ ri) 
    772                 box.Include((*ri).ExtrapTermination()); 
    773  
     813                                                                                 BspNodeGeometry **frontGeom, 
     814                                                                                 BspNodeGeometry **backGeom, 
     815                                                                                 float &frontArea, 
     816                                                                                 float &backArea) 
     817{ 
    774818        const bool useCostHeuristics = false; 
    775819 
     
    777821        float nPosition[3]; 
    778822        float nCostRatio[3]; 
     823        float nFrontArea[3]; 
     824        float nBackArea[3]; 
     825 
     826        BspNodeGeometry *nFrontGeom[3]; 
     827        BspNodeGeometry *nBackGeom[3]; 
     828 
    779829        int bestAxis = -1; 
    780830 
    781         const int sAxis = box.Size().DrivingAxis(); 
     831        // create bounding box of node extent 
     832        AxisAlignedBox3 box; 
     833        box.Initialize(); 
     834         
     835#if 0 
     836        RayInfoContainer::const_iterator ri, ri_end = tData.mRays->end(); 
     837 
     838        for(ri = tData.mRays->begin(); ri < ri_end; ++ ri) 
     839                box.Include((*ri).ExtrapTermination()); 
     840#else 
     841        PolygonContainer::const_iterator it, it_end = tData.mGeometry->mPolys.end(); 
     842 
     843        for(it = tData.mGeometry->mPolys.begin(); it < it_end; ++ it) 
     844                box.Include(*(*it)); 
     845 
     846#endif 
     847        int sAxis = box.Size().DrivingAxis(); 
    782848 
    783849        for (axis = 0; axis < 3; ++ axis) 
    784850        { 
     851                nFrontGeom[axis] = new BspNodeGeometry(); 
     852                nBackGeom[axis] = new BspNodeGeometry(); 
     853 
    785854                if (!mOnlyDrivingAxis || axis == sAxis) 
    786855                { 
     
    789858                                nPosition[axis] = (box.Min()[axis] + box.Max()[axis]) * 0.5f; 
    790859                                Vector3 normal(0,0,0); normal[axis] = 1; 
    791  
    792                                 nCostRatio[axis] = SplitPlaneCost(Plane3(normal, nPosition[axis]), tData); 
     860                                 
     861                                nCostRatio[axis] = SplitPlaneCost(Plane3(normal, nPosition[axis]),  
     862                                                                                                  tData, *nFrontGeom[axis], *nBackGeom[axis], 
     863                                                                                                  nFrontArea[axis], nBackArea[axis]); 
    793864                        } 
    794865                        else 
     
    809880                        else if (nCostRatio[axis] < nCostRatio[bestAxis]) 
    810881                        { 
    811                                 /*Debug << "pvs front " << nPvsBack[axis] 
    812                                           << " pvs back " << nPvsFront[axis] 
    813                                           << " overall pvs " << leaf->GetPvsSize() << endl;*/ 
    814882                                bestAxis = axis; 
    815883                        } 
     
    820888        //-- assign values 
    821889        axis = bestAxis; 
    822         position = nPosition[bestAxis]; 
    823  
    824         raysBack = 0;//nRaysBack[bestAxis]; 
    825         raysFront = 0;//nRaysFront[bestAxis]; 
    826  
    827         pvsBack = 0;//nPvsBack[bestAxis]; 
    828         pvsFront = 0;//nPvsFront[bestAxis]; 
    829  
    830         Vector3 normal(0,0,0); normal[bestAxis] = 1; 
     890        frontArea = nFrontArea[bestAxis]; 
     891        backArea = nBackArea[bestAxis]; 
     892 
     893        // assign best split nodes geometry  
     894        *frontGeom = nFrontGeom[bestAxis]; 
     895        *backGeom = nBackGeom[bestAxis]; 
     896        // and delete other geometry 
     897        delete nFrontGeom[(bestAxis + 1) % 3]; 
     898        delete nBackGeom[(bestAxis + 2) % 3]; 
     899 
     900        //-- split plane 
     901    Vector3 normal(0,0,0); normal[bestAxis] = 1; 
    831902        plane = Plane3(normal, nPosition[bestAxis]); 
    832          
     903 
    833904        return nCostRatio[bestAxis]; 
    834905} 
    835906 
    836907 
    837 /* 
    838 float VspBspTree::EvalCostRatio(const VspBspTraversalData &tData, 
    839                                                                 const AxisAlignedBox3 &box, 
    840                                                                 const int axis, 
    841                                                                 const float position, 
    842                                                                 int &raysBack, 
    843                                                                 int &raysFront, 
    844                                                                 int &pvsBack, 
    845                                                                 int &pvsFront) 
    846 { 
    847         raysBack = 0; 
    848         raysFront = 0; 
    849         pvsFront = 0; 
    850         pvsBack = 0; 
    851  
    852         Intersectable::NewMail(3); 
    853  
    854         // eval pvs size 
    855         const int pvsSize = tData.mPvs; 
    856  
    857         // create unique ids for pvs heuristics 
    858         GenerateUniqueIdsForPvs(); 
    859  
    860         // this is the main ray classification loop! 
    861         for(RayInfoContainer::iterator ri = tData.mRays->begin(); 
    862                         ri != tData.mRays->end(); ++ ri) 
    863         { 
    864                 if (!(*ri).mRay->IsActive()) 
    865                         continue; 
    866  
    867                 // determine the side of this ray with respect to the plane 
    868                 float t; 
    869                 int side = (*ri).ComputeRayIntersection(axis, position, t); 
    870                          
    871                 if (side <= 0) 
    872                         ++ raysBack; 
    873  
    874                 if (side >= 0) 
    875                         ++ raysFront; 
    876  
    877                 AddObjToPvs((*ri).mRay->mTerminationObject, side, pvsBack, pvsFront); 
    878         } 
    879  
    880         //-- only one of these options should be one 
    881  
    882         if (0) //-- only pvs 
    883         { 
    884                 const float sum = float(pvsBack + pvsFront); 
    885                 const float oldCost = (float)pvsSize; 
    886  
    887                 return sum / oldCost; 
    888         } 
    889  
    890         //-- pvs + probability heuristics 
    891         float pBack, pFront, pOverall; 
    892  
    893         if (0) 
    894         { 
    895                 // box length substitute for probability 
    896                 const float minBox = box.Min(axis); 
    897                 const float maxBox = box.Max(axis); 
    898  
    899                 pBack = position - minBox; 
    900                 pFront = maxBox - position; 
    901                 pOverall = maxBox - minBox; 
    902         } 
    903  
    904         if (1) //-- area substitute for probability 
    905         { 
    906                  
    907                 const bool useMidSplit = true; 
    908                 //const bool useMidSplit = false; 
    909                          
    910                 pOverall = box.SurfaceArea(); 
    911                          
    912                 if (!useMidSplit) 
    913                 { 
    914                         Vector3 pos = box.Max(); pos[axis] = position; 
    915                         pBack = AxisAlignedBox3(box.Min(), pos).SurfaceArea(); 
    916  
    917                         pos = box.Min(); pos[axis] = position; 
    918                         pFront = AxisAlignedBox3(pos, box.Max()).SurfaceArea(); 
    919                 } 
    920                 else 
    921                 { 
    922                         //-- simplified computation for mid split 
    923                         const int axis2 = (axis + 1) % 3; 
    924                         const int axis3 = (axis + 2) % 3; 
    925  
    926                         const float faceArea =  
    927                                 (box.Max(axis2) - box.Min(axis2)) * 
    928                                 (box.Max(axis3) - box.Min(axis3)); 
    929  
    930                         pBack = pFront = pOverall * 0.5f + faceArea; 
    931                 } 
    932         } 
    933  
    934         //-- ray density substitute for probability 
    935         if (0) 
    936         { 
    937                 pBack = (float)raysBack; 
    938                 pFront = (float)raysFront; 
    939                 pOverall = (float)tData.mRays->size(); 
    940         } 
    941  
    942         //Debug << axis << " " << pvsSize << " " << pvsBack << " " << pvsFront << endl; 
    943         //Debug << pFront << " " << pBack << " " << pOverall << endl; 
    944  
    945         // float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 
    946         const float newCost = pvsBack * pBack + pvsFront * pFront; 
    947         //  float oldCost = leaf->mRays.size(); 
    948         const float oldCost = (float)pvsSize * pOverall; 
    949  
    950         return  (mCtDivCi + newCost) / oldCost; 
    951 } 
    952 */ 
    953  
    954  
    955 bool VspBspTree::SelectPlane(Plane3 &plane, 
     908bool VspBspTree::SelectPlane(Plane3 &bestPlane, 
    956909                                                         BspLeaf *leaf, 
    957                                                          VspBspTraversalData &data) 
     910                                                         VspBspTraversalData &data, 
     911                                                         VspBspTraversalData &frontData, 
     912                                                         VspBspTraversalData &backData) 
    958913{ 
    959914        // simplest strategy: just take next polygon 
     
    962917        if (!data.mPolygons->empty()) 
    963918                { 
    964                         const int randIdx = (int)RandomValue(0, (Real)((int)data.mPolygons->size() - 1)); 
     919                        const int randIdx =  
     920                                (int)RandomValue(0, (Real)((int)data.mPolygons->size() - 1)); 
    965921                        Polygon3 *nextPoly = (*data.mPolygons)[randIdx]; 
    966922 
    967                         plane = nextPoly->GetSupportingPlane(); 
     923                        bestPlane = nextPoly->GetSupportingPlane(); 
    968924                        return true; 
    969925                } 
    970926        } 
    971927 
    972         // use heuristics to find appropriate plane 
    973         return SelectPlaneHeuristics(plane, leaf, data); 
     928        //-- use heuristics to find appropriate plane 
     929 
     930        // intermediate plane 
     931        Plane3 plane; 
     932        float lowestCost = MAX_FLOAT; 
     933                 
     934        const bool onlyAxisAligned  =  
     935                (mSplitPlaneStrategy & AXIS_ALIGNED) && 
     936                ((int)data.mRays->size() > mTermMinRaysForAxisAligned) && 
     937                ((int)data.GetAvgRayContribution() < mTermMaxRayContriForAxisAligned); 
     938         
     939        // split polygons if no axis aligned splits 
     940        const int limit = onlyAxisAligned ? 0 :  
     941                Min((int)data.mPolygons->size(), mMaxPolyCandidates); 
     942 
     943        float candidateCost; 
     944 
     945        int maxIdx = (int)data.mPolygons->size(); 
     946 
     947        for (int i = 0; i < limit; ++ i) 
     948        { 
     949                //-- assure that no index is taken twice 
     950                const int candidateIdx = (int)RandomValue(0, (Real)(-- maxIdx)); 
     951                Polygon3 *poly = (*data.mPolygons)[candidateIdx]; 
     952 
     953                // swap candidate to the end to avoid testing same plane 
     954                std::swap((*data.mPolygons)[maxIdx], (*data.mPolygons)[candidateIdx]); 
     955                //Polygon3 *poly = (*data.mPolygons)[(int)RandomValue(0, (int)polys.size() - 1)]; 
     956 
     957                // evaluate current candidate 
     958                BspNodeGeometry fGeom, bGeom; 
     959                float fArea, bArea; 
     960                plane = poly->GetSupportingPlane(); 
     961                candidateCost = SplitPlaneCost(plane, data, fGeom, bGeom, fArea, bArea); 
     962                 
     963                if (candidateCost < lowestCost) 
     964                { 
     965                        bestPlane = plane; 
     966                        lowestCost = candidateCost; 
     967                } 
     968        } 
     969 
     970        //-- evaluate axis aligned splits 
     971        int axis; 
     972        BspNodeGeometry *fGeom, *bGeom; 
     973        float fArea, bArea; 
     974 
     975        candidateCost = SelectAxisAlignedPlane(plane, data, axis, 
     976                                                                                   &fGeom, &bGeom,  
     977                                                                                   fArea, bArea);                                                 
     978 
     979        if (candidateCost < lowestCost) 
     980        {        
     981                bestPlane = plane; 
     982                lowestCost = candidateCost; 
     983 
     984                //-- assign already computed values 
     985                frontData.mGeometry = fGeom; 
     986                backData.mGeometry = bGeom; 
     987                frontData.mArea = fArea; 
     988                backData.mArea = bArea; 
     989 
     990                //! error also computed if cost ratio is missed 
     991                ++ mStat.splits[axis]; 
     992        } 
     993        else 
     994        { 
     995                DEL_PTR(fGeom); 
     996                DEL_PTR(bGeom); 
     997        } 
     998 
     999#ifdef _DEBUG 
     1000        Debug << "plane lowest cost: " << lowestCost << endl; 
     1001#endif 
     1002 
     1003        // cost ratio miss 
     1004        if (lowestCost > mTermMaxCostRatio) 
     1005                return false; 
     1006 
     1007        return true; 
    9741008} 
    9751009 
     
    10481082 
    10491083 
    1050 bool VspBspTree::SelectPlaneHeuristics(Plane3 &bestPlane, 
    1051                                                                            BspLeaf *leaf, 
    1052                                                                            VspBspTraversalData &data) 
    1053 { 
    1054         float lowestCost = MAX_FLOAT; 
    1055         // intermediate plane 
    1056         Plane3 plane; 
    1057         bool useAxisAlignedPlane = false; 
    1058  
    1059         const int limit = Min((int)data.mPolygons->size(), mMaxPolyCandidates); 
    1060         int maxIdx = (int)data.mPolygons->size(); 
    1061  
    1062         float candidateCost; 
    1063  
    1064         for (int i = 0; i < limit; ++ i) 
    1065         { 
    1066                 //-- assure that no index is taken twice 
    1067                 const int candidateIdx = (int)RandomValue(0, (Real)(-- maxIdx)); 
    1068                 Polygon3 *poly = (*data.mPolygons)[candidateIdx]; 
    1069  
    1070                 // swap candidate to the end to avoid testing same plane 
    1071                 std::swap((*data.mPolygons)[maxIdx], (*data.mPolygons)[candidateIdx]); 
    1072  
    1073                 //Polygon3 *poly = (*data.mPolygons)[(int)RandomValue(0, (int)polys.size() - 1)]; 
    1074  
    1075                 // evaluate current candidate 
    1076                 candidateCost = SplitPlaneCost(poly->GetSupportingPlane(), data); 
    1077  
    1078                 if (candidateCost < lowestCost) 
    1079                 { 
    1080                         bestPlane = poly->GetSupportingPlane(); 
    1081                         lowestCost = candidateCost; 
    1082                 } 
    1083         } 
    1084  
    1085         //-- axis aligned splits 
    1086         int axis; 
    1087         float position; 
    1088         int raysBack; 
    1089         int raysFront; 
    1090         int pvsFront; 
    1091         int pvsBack; 
    1092  
    1093         candidateCost = SelectAxisAlignedPlane(plane,  
    1094                                                                                    data,  
    1095                                                                                    axis, 
    1096                                                                                    position, 
    1097                                                                                    raysBack, 
    1098                                                                                    raysFront, 
    1099                                                                                    pvsFront, 
    1100                                                                                    pvsBack); 
    1101  
    1102         if (candidateCost < lowestCost) 
    1103         {        
    1104                 if (!useAxisAlignedPlane) 
    1105                 { 
    1106                         useAxisAlignedPlane = true; 
    1107                         //if (data.mPolygons->size() > 0) 
    1108                         //      Debug << "haha" << endl; 
    1109                         //! error also computed if cost ratio is missed 
    1110                         ++ mStat.splits[axis]; 
    1111                 } 
    1112  
    1113                 bestPlane = plane; 
    1114                 lowestCost = candidateCost; 
    1115         } 
    1116  
    1117 #ifdef _DEBUG 
    1118         Debug << "plane lowest cost: " << lowestCost << endl; 
    1119 #endif 
    1120  
    1121         // cost ratio miss 
    1122         if (lowestCost > mTermMaxCostRatio) 
    1123                 return false; 
    1124  
    1125         return true; 
    1126 } 
    1127  
    1128  
    11291084inline void VspBspTree::GenerateUniqueIdsForPvs() 
    11301085{ 
     
    11361091 
    11371092float VspBspTree::SplitPlaneCost(const Plane3 &candidatePlane, 
    1138                                                                  const VspBspTraversalData &data) const 
     1093                                                                 const VspBspTraversalData &data, 
     1094                                                                 BspNodeGeometry &geomFront, 
     1095                                                                 BspNodeGeometry &geomBack, 
     1096                                                                 float &areaFront, 
     1097                                                                 float &areaBack) const 
    11391098{ 
    11401099        float cost = 0; 
     
    11431102        float sumRaySplits = 0; 
    11441103 
    1145         int frontPvs = 0; 
    1146         int backPvs = 0; 
    1147  
    1148         // probability that view point lies in child 
     1104        int pvsFront = 0; 
     1105        int pvsBack = 0; 
     1106 
     1107        // probability that view point lies in back / front node 
    11491108        float pOverall = 0; 
    11501109        float pFront = 0; 
    11511110        float pBack = 0; 
    11521111 
     1112        int raysFront = 0; 
     1113        int raysBack = 0; 
     1114        int totalPvs = 0; 
     1115 
    11531116        if (mSplitPlaneStrategy & PVS) 
    11541117        { 
     
    11591122                { 
    11601123                        // construct child geometry with regard to the candidate split plane 
    1161                         BspNodeGeometry frontCell; 
    1162                         BspNodeGeometry backCell; 
    1163  
    1164                         data.mGeometry->SplitGeometry(frontCell, 
    1165                                                                                   backCell, 
     1124                        data.mGeometry->SplitGeometry(geomFront, 
     1125                                                                                  geomBack, 
    11661126                                                                                  candidatePlane, 
    11671127                                                                                  mBox, 
    11681128                                                                                  mEpsilon); 
    11691129 
    1170                         pFront = frontCell.GetArea(); 
    1171                         pBack = backCell.GetArea(); 
    1172  
     1130                        areaFront = geomFront.GetArea(); 
     1131                        areaBack = geomBack.GetArea(); 
     1132 
     1133                        pBack = areaBack; 
     1134                        pFront = areaFront; 
    11731135                        pOverall = data.mArea; 
     1136                } 
     1137                else // use number of rays to approximate volume 
     1138                { 
     1139                        pOverall = (float)data.mRays->size(); 
     1140                        pFront = (float)raysFront; 
     1141                        pBack = (float)raysBack; 
    11741142                } 
    11751143        } 
     
    11891157                limit = (int)data.mRays->size(); 
    11901158        } 
    1191  
     1159         
    11921160        for (int i = 0; i < limit; ++ i) 
    11931161        { 
    1194                 const int testIdx = useRand ? (int)RandomValue(0, (Real)(limit - 1)) : i; 
     1162                const int testIdx = useRand ?  
     1163                        (int)RandomValue(0, (Real)((int)data.mRays->size() - 1)) : i; 
    11951164                RayInfo rayInf = (*data.mRays)[testIdx]; 
    11961165 
     1166                float t; 
    11971167                VssRay *ray = rayInf.mRay; 
    1198                 float t; 
    11991168                const int cf = rayInf.ComputeRayIntersection(candidatePlane, t); 
     1169 
     1170        if (cf >= 0) 
     1171                        ++ raysFront; 
     1172                if (cf <= 0) 
     1173                        ++ raysBack; 
    12001174 
    12011175                if (mSplitPlaneStrategy & LEAST_RAY_SPLITS) 
     
    12121186                if (mSplitPlaneStrategy & PVS) 
    12131187                { 
    1214                         // in case the ray intersects an object 
    1215                         // assure that we only count the object 
    1216                         // once for the front and once for the back side of the plane 
    1217                         AddObjToPvs(ray->mTerminationObject, cf, frontPvs, backPvs); 
    1218                         AddObjToPvs(ray->mOriginObject, cf, frontPvs, backPvs); 
    1219  
    1220                         // use number of rays to approximate volume 
    1221                         if (!mPvsUseArea) 
    1222                         { 
    1223                                 pOverall = (float)data.mRays->size(); 
    1224  
    1225                                 if (cf >= 0) 
    1226                                         ++ pFront; 
    1227                                 if (cf <= 0) 
    1228                                         ++ pBack; 
    1229                         } 
     1188                        // find front and back pvs for origing and termination object 
     1189                        AddObjToPvs(ray->mTerminationObject, cf, pvsFront, pvsBack, totalPvs); 
     1190                        AddObjToPvs(ray->mOriginObject, cf, pvsFront, pvsBack, totalPvs); 
    12301191                } 
    12311192        } 
     
    12421203        if (mSplitPlaneStrategy & PVS) 
    12431204        { 
    1244                 const float oldCost = pOverall * (float)data.mPvs + Limits::Small; 
    1245                 cost += mPvsFactor * (frontPvs * pFront + backPvs * pBack) / oldCost; 
    1246  
    1247                 //cost += mPvsFactor * 0.5 * (frontPvs * pFront + backPvs * pBack) / oldCost; 
    1248                 //Debug << "new cost: " << cost << " over" << frontPvs * pFront + backPvs * pBack << " old cost " << oldCost << endl; 
    1249  
    1250                 if (0) // give penalty to unbalanced split 
    1251                         if (((pFront * 0.2 + Limits::Small) > pBack) || 
    1252                                 (pFront < (pBack * 0.2 + Limits::Small))) 
    1253                                         cost += 0.5; 
     1205                const float oldCost = pOverall * (float)totalPvs + Limits::Small; 
     1206                cost += mPvsFactor * (pvsFront * pFront + pvsBack * pBack) / oldCost; 
    12541207        } 
    12551208 
    12561209#ifdef _DEBUG 
    12571210        Debug << "totalpvs: " << data.mPvs << " ptotal: " << pOverall 
    1258                   << " frontpvs: " << frontPvs << " pFront: " << pFront 
    1259                   << " backpvs: " << backPvs << " pBack: " << pBack << endl << endl; 
     1211                  << " frontpvs: " << pvsFront << " pFront: " << pFront 
     1212                  << " backpvs: " << pvsBack << " pBack: " << pBack << endl << endl; 
    12601213#endif 
    12611214 
     
    12631216        return cost / (float)mCostNormalizer; 
    12641217} 
     1218 
    12651219 
    12661220void VspBspTree::AddObjToPvs(Intersectable *obj, 
    12671221                                                         const int cf, 
    12681222                                                         int &frontPvs, 
    1269                                                          int &backPvs) const 
     1223                                                         int &backPvs, 
     1224                                                         int &totalPvs) const 
    12701225{ 
    12711226        if (!obj) 
    12721227                return; 
     1228         
     1229        if ((obj->mMailbox != sFrontId) && 
     1230                (obj->mMailbox != sBackId) && 
     1231                (obj->mMailbox != sFrontAndBackId)) 
     1232        { 
     1233                ++ totalPvs; 
     1234        } 
     1235 
    12731236        // TODO: does this really belong to no pvs? 
    12741237        //if (cf == Ray::COINCIDENT) return; 
     
    12811244                { 
    12821245                        ++ frontPvs; 
    1283  
     1246                 
    12841247                        if (obj->mMailbox == sBackId) 
    12851248                                obj->mMailbox = sFrontAndBackId; 
     
    12951258                { 
    12961259                        ++ backPvs; 
    1297  
     1260                 
    12981261                        if (obj->mMailbox == sFrontId) 
    12991262                                obj->mMailbox = sFrontAndBackId; 
     
    13221285                        BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
    13231286                        if (leaf->TreeValid() &&  
    1324                                 (!onlyUnmailed || leaf->Mailed()) && 
     1287                                (!onlyUnmailed || !leaf->Mailed()) && 
    13251288                                ((maxPvsSize < 0) || (leaf->GetViewCell()->GetPvs().GetSize() <= maxPvsSize))) 
    13261289                        { 
     
    13511314 
    13521315 
    1353 BspViewCell *VspBspTree::GetOutOfBoundsCell() const 
    1354 { 
    1355         return mOutOfBoundsCell; 
    1356 } 
    1357  
    1358  
    13591316void VspBspTree::EvaluateLeafStats(const VspBspTraversalData &data) 
    13601317{ 
     
    13681325        if (data.mPvs > mStat.maxPvs) 
    13691326                mStat.maxPvs = data.mPvs; 
     1327         
    13701328        if (data.mDepth < mStat.minDepth) 
    13711329                mStat.minDepth = data.mDepth; 
     1330 
    13721331        if (data.mDepth >= mTermMaxDepth) 
    13731332                ++ mStat.maxDepthNodes; 
     1333        // accumulate rays to compute rays /  leaf 
     1334        mStat.accumRays += (int)data.mRays->size(); 
    13741335 
    13751336        if (data.mPvs < mTermMinPvs) 
     
    13831344 
    13841345        if (data.mArea <= mTermMinArea) 
    1385         { 
    1386                 //Debug << "area: " << data.mArea / mBox.SurfaceArea() << " min area: " << mTermMinArea / mBox.SurfaceArea() << endl; 
    13871346                ++ mStat.minAreaNodes; 
    1388         } 
     1347         
    13891348        // accumulate depth to compute average depth 
    13901349        mStat.accumDepth += data.mDepth; 
     
    14981457} 
    14991458 
    1500 bool VspBspTree::Export(const string filename) 
    1501 { 
    1502         Exporter *exporter = Exporter::GetExporter(filename); 
    1503  
    1504         if (exporter) 
    1505         { 
    1506                 //exporter->ExportVspBspTree(*this); 
    1507                 return true; 
    1508         } 
    1509  
    1510         return false; 
    1511 } 
    1512  
    15131459void VspBspTree::CollectViewCells(ViewCellContainer &viewCells) const 
    15141460{ 
     
    15161462 
    15171463        if (!mRoot) 
    1518         return; 
     1464                return; 
    15191465 
    15201466        nodeStack.push(mRoot); 
     
    15431489                { 
    15441490                        BspInterior *interior = dynamic_cast<BspInterior *>(node); 
    1545                          
     1491                 
    15461492                        nodeStack.push(interior->GetFront()); 
    15471493                        nodeStack.push(interior->GetBack()); 
     
    22452191{ 
    22462192        BspLeaf::NewMail(); 
    2247  
     2193         
    22482194        vector<BspLeaf *>::const_iterator it, it_end = leaves.end(); 
    22492195 
     2196        Debug << "mergequeue size: " << mMergeQueue.size() << endl; 
    22502197        // find merge candidates and push them into queue 
    22512198        for (it = leaves.begin(); it != it_end; ++ it) 
     
    22682215                // TODO: test if at least one ray goes from one leaf to the other 
    22692216                for (nit = neighbors.begin(); nit != nit_end; ++ nit) 
    2270                 {                        
    2271                         mMergeQueue.push(BspMergeCandidate(leaf, *nit)); 
    2272                 } 
    2273         } 
     2217                { 
     2218                        if ((*nit)->GetViewCell() != leaf->GetViewCell()) 
     2219                                mMergeQueue.push(BspMergeCandidate(leaf, *nit)); 
     2220                } 
     2221        } 
     2222 
     2223        Debug << "new mergequeue size: " << mMergeQueue.size() << endl; 
    22742224 
    22752225        return (int)leaves.size(); 
     
    22832233        long startTime = GetTime(); 
    22842234        ConstructBspRays(bspRays, rays); 
    2285         Debug << (int)bspRays.size() << " bsp rays constructed in " << TimeDiff(startTime, GetTime()) * 1e-3f << " secs" << endl; 
     2235        Debug << (int)bspRays.size() << " bsp rays constructed in "  
     2236                  << TimeDiff(startTime, GetTime()) * 1e-3f << " secs" << endl; 
    22862237 
    22872238        map<BspLeaf *, vector<BspLeaf*> > neighborMap; 
     
    23242275            leaf = (*iit).mLeaf; 
    23252276 
    2326                         // view space not valid 
    2327                         if (!leaf->TreeValid() || !prevLeaf->TreeValid()) 
     2277                        // view space not valid or same view cell 
     2278                        if (!leaf->TreeValid() || !prevLeaf->TreeValid() || 
     2279                                (leaf->GetViewCell() == prevLeaf->GetViewCell())) 
    23282280                                continue; 
    23292281 
     
    23792331        vector<BspLeaf *> leaves; 
    23802332        CollectLeaves(leaves, true, mMaxPvs); 
    2381         Debug << "found " << (int)leaves.size() << " new leaves" << endl; 
    2382         //CollectMergeCandidates(leaves); 
     2333        Debug << "found " << (int)leaves.size() << " new leaves" << endl << endl; 
     2334        // TODO 
     2335        CollectMergeCandidates(leaves); 
    23832336 
    23842337        return numLeaves; 
     
    25082461 
    25092462 
    2510 ViewCell * 
    2511 VspBspTree::GetViewCell(const Vector3 &point) 
     2463ViewCell *VspBspTree::GetViewCell(const Vector3 &point) 
    25122464{ 
    25132465  if (mRoot == NULL) 
     
    27372689} 
    27382690 
    2739 #define USE_ASCII 0 
    2740 bool VspBspTree::WriteVspBspTree() 
    2741 { 
    2742         char fileName[100]; 
    2743         environment->GetStringValue("VspBspTree.viewCellsFilename", fileName); 
     2691 
     2692bool VspBspTree::Export(ofstream &stream) 
     2693{ 
     2694        ExportNode(mRoot, stream); 
     2695 
     2696        return true; 
     2697} 
     2698 
     2699 
     2700void VspBspTree::ExportNode(BspNode *node, ofstream &stream) 
     2701{ 
     2702        if (node->IsLeaf()) 
     2703        { 
     2704                BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
     2705                         
     2706                int id = -1; 
     2707                if (leaf->GetViewCell() != mOutOfBoundsCell) 
     2708                        id = leaf->GetViewCell()->GetId(); 
     2709 
     2710                stream << "<Leaf viewCellId=\"" << id << "\" />" << endl; 
     2711        } 
     2712        else 
     2713        { 
     2714                BspInterior *interior = dynamic_cast<BspInterior *>(node); 
    27442715         
    2745         /*VssRayContainer::const_iterator it, it_end = samples.end(); 
    2746          
    2747 #if USE_ASCII 
    2748         ofstream samplesOut(fileName); 
    2749         if (!samplesOut.is_open()) 
    2750                 return false; 
    2751  
    2752         for (it = samples.begin(); it != it_end; ++ it) 
    2753         { 
    2754                 VssRay *ray = *it; 
    2755                 int sourceid = ray->mOriginObject ? ray->mOriginObject->mId : -1;                
    2756                 int termid = ray->mTerminationObject ? ray->mTerminationObject->mId : -1;        
    2757  
    2758                 samplesOut << ray->GetOrigin().x << " " << ray->GetOrigin().y << " " << ray->GetOrigin().z << " "  
    2759                                    << ray->GetTermination().x << " " << ray->GetTermination().y << " " << ray->GetTermination().z << " "  
    2760                                    << sourceid << " " << termid << "\n"; 
    2761         } 
    2762 #else 
    2763         ofstream samplesOut(fileName, ios::binary); 
    2764         if (!samplesOut.is_open()) 
    2765                 return false; 
    2766  
    2767         for (it = samples.begin(); it != it_end; ++ it) 
    2768         {        
    2769                 VssRay *ray = *it; 
    2770                 Vector3 origin(ray->GetOrigin()); 
    2771                 Vector3 termination(ray->GetTermination()); 
    2772                  
    2773                 int sourceid = ray->mOriginObject ? ray->mOriginObject->mId : -1;                
    2774                 int termid = ray->mTerminationObject ? ray->mTerminationObject->mId : -1;                
    2775  
    2776                 samplesOut.write(reinterpret_cast<char *>(&origin), sizeof(Vector3)); 
    2777                 samplesOut.write(reinterpret_cast<char *>(&termination), sizeof(Vector3)); 
    2778                 samplesOut.write(reinterpret_cast<char *>(&sourceid), sizeof(int)); 
    2779                 samplesOut.write(reinterpret_cast<char *>(&termid), sizeof(int)); 
    2780     } 
    2781 #endif 
    2782  
    2783         samplesOut.close(); 
    2784         */ 
    2785         return true; 
    2786 } 
    2787  
    2788 bool VspBspTree::LoadVspBspTree() 
    2789 { 
    2790         /*std::stable_sort(objects.begin(), objects.end(), ilt); 
    2791         char fileName[100]; 
    2792         environment->GetStringValue("Preprocessor.samplesFilename", fileName); 
    2793          
    2794     Vector3 origin, termination; 
    2795         // HACK: needed only for lower_bound algorithm to find the  
    2796         // intersected objects 
    2797         MeshInstance sObj(NULL); 
    2798         MeshInstance tObj(NULL); 
    2799  
    2800 #if USE_ASCII 
    2801         ifstream samplesIn(fileName, ios::binary); 
    2802         if (!samplesIn.is_open()) 
    2803                 return false; 
    2804  
    2805         string buf; 
    2806         while (!(getline(samplesIn, buf)).eof()) 
    2807         { 
    2808                 sscanf(buf.c_str(), "%f %f %f %f %f %f %d %d",  
    2809                            &origin.x, &origin.y, &origin.z, 
    2810                            &termination.x, &termination.y, &termination.z,  
    2811                            &(sObj.mId), &(tObj.mId)); 
    2812                  
    2813                 Intersectable *sourceObj = NULL; 
    2814                 Intersectable *termObj = NULL; 
    2815                  
    2816                 if (sObj.mId >= 0) 
    2817                 { 
    2818                         ObjectContainer::iterator oit = 
    2819                                 lower_bound(objects.begin(), objects.end(), &sObj, ilt); 
    2820                         sourceObj = *oit; 
    2821                 } 
    2822                  
    2823                 if (tObj.mId >= 0) 
    2824                 { 
    2825                         ObjectContainer::iterator oit = 
    2826                                 lower_bound(objects.begin(), objects.end(), &tObj, ilt); 
    2827                         termObj = *oit; 
    2828                 } 
    2829  
    2830                 samples.push_back(new VssRay(origin, termination, sourceObj, termObj)); 
    2831         } 
    2832 #else 
    2833         ifstream samplesIn(fileName, ios::binary); 
    2834         if (!samplesIn.is_open()) 
    2835                 return false; 
    2836  
    2837         while (1) 
    2838         { 
    2839                  samplesIn.read(reinterpret_cast<char *>(&origin), sizeof(Vector3)); 
    2840                  samplesIn.read(reinterpret_cast<char *>(&termination), sizeof(Vector3)); 
    2841                  samplesIn.read(reinterpret_cast<char *>(&(sObj.mId)), sizeof(int)); 
    2842                  samplesIn.read(reinterpret_cast<char *>(&(tObj.mId)), sizeof(int)); 
    2843                  
    2844                  if (samplesIn.eof()) 
    2845                         break; 
    2846  
    2847                 Intersectable *sourceObj = NULL; 
    2848                 Intersectable *termObj = NULL; 
    2849                  
    2850                 if (sObj.mId >= 0) 
    2851                 { 
    2852                         ObjectContainer::iterator oit = 
    2853                                 lower_bound(objects.begin(), objects.end(), &sObj, ilt); 
    2854                         sourceObj = *oit; 
    2855                 } 
    2856                  
    2857                 if (tObj.mId >= 0) 
    2858                 { 
    2859                         ObjectContainer::iterator oit = 
    2860                                 lower_bound(objects.begin(), objects.end(), &tObj, ilt); 
    2861                         termObj = *oit; 
    2862                 } 
    2863  
    2864                 samples.push_back(new VssRay(origin, termination, sourceObj, termObj)); 
    2865         } 
    2866  
    2867 #endif 
    2868         samplesIn.close(); 
    2869 */ 
    2870         return true; 
    2871 } 
    2872  
     2716                Plane3 plane = interior->GetPlane(); 
     2717                stream << "<Interior plane=\"" << plane.mNormal.x << " "  
     2718                           << plane.mNormal.y << " " << plane.mNormal.z << " "  
     2719                           << plane.mD << "\">" << endl; 
     2720 
     2721                ExportNode(interior->GetBack(), stream); 
     2722                ExportNode(interior->GetFront(), stream); 
     2723 
     2724                stream << "</Interior>" << endl; 
     2725        } 
     2726} 
    28732727 
    28742728/************************************************************************/ 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h

    r503 r508  
    3434class VspBspTree  
    3535{ 
     36        friend class ViewCellsParseHandlers; 
     37 
    3638public: 
    3739         
     
    180182        BspNode *GetRoot() const; 
    181183 
    182         /** Exports VspBsp tree to file. 
    183         */ 
    184         bool Export(const string filename); 
    185  
    186184        /** Collects the leaf view cells of the tree 
    187185                @param viewCells returns the view cells  
     
    279277        bool ViewPointValid(const Vector3 &viewPoint) const; 
    280278 
    281         /** Returns the view cell corresponding to  
    282                 the space outside the valid view space. 
    283         */ 
    284         BspViewCell *GetOutOfBoundsCell() const; 
    285  
    286         /** Writes tree to disc. 
    287         */ 
    288         bool WriteVspBspTree(); 
    289  
    290         /** Loads tree from disc. 
    291         */ 
    292         bool LoadVspBspTree(); 
     279        /** Returns view cell corresponding to  
     280                the invalid view space. 
     281        */ 
     282        BspViewCell *GetOutOfBoundsCell(); 
     283 
     284        /** Writes tree to output stream 
     285        */ 
     286        bool Export(ofstream &stream); 
    293287 
    294288protected: 
     
    321315        }; 
    322316 
     317        /** Returns view cell corresponding to  
     318                the invalid view space. If it does not exist, it is created. 
     319        */ 
     320        BspViewCell *GetOrCreateOutOfBoundsCell(); 
     321 
    323322        /** Collapses the tree with respect to the view cell partition, 
    324323                i.e. leaves having the same view cell are collapsed. 
     
    329328        */ 
    330329        BspNode *CollapseTree(BspNode *node, int &collapsed); 
     330 
    331331        /** Shuffles the leaves, i.e., tests if exchanging 
    332332                the leaves helps in improving the view cells. 
     
    367367        bool SelectPlane(Plane3 &plane,  
    368368                                         BspLeaf *leaf,  
    369                                          VspBspTraversalData &data); 
     369                                         VspBspTraversalData &data, 
     370                                         VspBspTraversalData &frontData, 
     371                                         VspBspTraversalData &backData); 
    370372         
    371373        /** Strategies where the effect of the split plane is tested 
     
    375377        */ 
    376378        float SplitPlaneCost(const Plane3 &candidatePlane,  
    377                                                  const VspBspTraversalData &data) const; 
    378  
     379                                                 const VspBspTraversalData &data, 
     380                                                 BspNodeGeometry &geomFront, 
     381                                                 BspNodeGeometry &geomBack, 
     382                                                 float &areaFront, 
     383                                                 float &areaBack) const; 
    379384 
    380385        /** Subdivide leaf. 
     
    397402                                                   PolygonContainer &coincident); 
    398403 
    399         /** Selects the split plane in order to construct a tree with 
    400                 certain characteristics (e.g., balanced tree, least splits,  
    401                 2.5d aligned) 
    402                 @param bestPlane returns the split plane 
    403                 @param polygons container of polygons 
    404                 @param rays bundle of rays on which the split can be based 
    405  
    406                 @returns true if the overall cost is under maxCostRatio 
    407         */ 
    408         bool SelectPlaneHeuristics(Plane3 &bestPlane,  
    409                                                            BspLeaf *leaf,  
    410                                                            VspBspTraversalData &data); 
    411  
    412404        /** Extracts the meshes of the objects and adds them to polygons.  
    413405                Adds object aabb to the aabb of the tree. 
     
    441433                                                                 const VspBspTraversalData &tData, 
    442434                                                                 int &axis, 
    443                                                                  float &position, 
    444                                                                  int &raysBack, 
    445                                                                  int &raysFront, 
    446                                                                  int &pvsBack, 
    447                                                                  int &pvsFront); 
     435                                                                 BspNodeGeometry **frontGeom, 
     436                                                                 BspNodeGeometry **backGeom, 
     437                                                                 float &frontArea, 
     438                                                                 float &backArea); 
    448439 
    449440        /** Sorts split candidates for surface area heuristics for axis aligned splits. 
     
    506497         
    507498        */ 
    508         void AddObjToPvs(Intersectable *obj, const int cf, int &frontPvs, int &backPvs) const; 
     499        void AddObjToPvs(Intersectable *obj,  
     500                                         const int cf,  
     501                                         int &frontPvs,  
     502                                         int &backPvs,  
     503                                         int &totalPvs) const; 
    509504         
    510505        /** Computes PVS size induced by the rays. 
     
    591586        void PropagateUpValidity(BspNode *node); 
    592587 
    593         /** Creates or returns view cell corresponding to  
    594                 the space outside the valid view space. 
    595         */ 
    596         BspViewCell *GetOrCreateOutOfBoundsCell(); 
     588        /** Writes the node to disk 
     589                @note: should be implemented as visitor 
     590        */ 
     591        void ExportNode(BspNode *node, ofstream &stream); 
     592 
     593        /** Returns memory usage of tree. 
     594        */ 
     595        float GetMemUsage() const; 
    597596 
    598597        /// Pointer to the root of the tree 
     
    621620        /// mininum PVS 
    622621        int mTermMinPvs; 
    623  
    624         /// minimal number of rays for axis aligned split 
    625         int mTermMinRaysForAxisAligned; 
    626         /// minimal number of objects for axis aligned split 
    627         int mTermMinObjectsForAxisAligned; 
    628622        /// maximal contribution per ray 
    629623        float mTermMaxRayContribution; 
    630624        /// minimal accumulated ray length 
    631625        float mTermMinAccRayLength; 
     626 
     627        //-- termination criteria for axis aligned split 
     628 
     629        /// minimal number of rays for axis aligned split 
     630        int mTermMinRaysForAxisAligned; 
     631        // max ray contribution 
     632        float mTermMaxRayContriForAxisAligned; 
    632633 
    633634        /// strategy to get the best split plane 
     
    684685 
    685686        MergeQueue mMergeQueue; 
     687 
    686688        /// if rays should be used to collect merge candidates 
    687689        bool mUseRaysForMerge; 
     690         
    688691        /// maximal allowed pvs so that view cell is valid 
    689692        int mMaxPvs; 
     
    695698        bool mShowInvalidSpace; 
    696699 
     700        int mCurrentViewCellsId; 
     701 
     702        /// maximal tree memory 
     703        float mMaxMemory; 
     704 
     705        bool mOutOfMemory; 
    697706private: 
    698707         
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp

    r501 r508  
    2929  environment->GetBoolValue("VssPreprocessor.storeInitialSamples", mStoreInitialSamples); 
    3030  environment->GetBoolValue("VssPreprocessor.useViewSpaceBox", mUseViewSpaceBox); 
     31  useViewspacePlane = mUseViewSpaceBox; //hack 
    3132 
    3233  mStats.open("stats.log"); 
     
    473474  { 
    474475          cout << "Writing " << (int)mVssRays.size() << " samples to file ... "; 
    475           WriteSamples(mVssRays); 
     476          ExportSamples(mVssRays); 
    476477          cout << "finished\n" << endl; 
    477478 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.cpp

    r490 r508  
    134134        } 
    135135        ptr = endptr; 
    136       } 
     136          } 
    137137    } 
    138138  } 
     
    380380 
    381381 
    382 /*********************************************************** 
    383  *         class X3dViewCellsParseHandlers implemenation   * 
    384  ***********************************************************/ 
     382/************************************************************************/ 
     383/*             class X3dViewCellsParseHandlers implementation           */ 
     384/************************************************************************/ 
    385385 
    386386 
     
    534534  } 
    535535         
    536   // do nothing 
    537   //if (element == "Shape") {} 
    538    
    539536  if (element == "Coordinate") { 
    540537          // add coordinates to the triangles 
    541538      StartCoordinate(attributes); 
    542539  } 
     540  // do nothing 
     541  //if (element == "Shape") {} 
    543542  // ignore material 
    544543  //if (element == "Material") {} 
    545544 
    546   mElementCount++; 
     545  ++ mElementCount; 
    547546  mAttrCount += attributes.getLength(); 
    548547} 
Note: See TracChangeset for help on using the changeset viewer.