Showing the changes to interface/src/VoxelSystem.cpp (1 of 10 files). Show all
Unified · Split
| @@ -23,6 +23,7 @@ · 22 unmodified lines | |||
| 23 | #include "Log.h" | 23 | #include "Log.h" |
| 24 | #include "VoxelConstants.h" | 24 | #include "VoxelConstants.h" |
| 25 | #include "CoverageMap.h" | 25 | #include "CoverageMap.h" |
| 26 | #include "CoverageMapV2.h" | ||
| 26 | #include "InterfaceConfig.h" | 27 | #include "InterfaceConfig.h" |
| 27 | #include "renderer/ProgramObject.h" | 28 | #include "renderer/ProgramObject.h" |
| 28 | 29 | ||
| @@ -1160,6 +1161,7 @@ void VoxelSystem::copyFromTreeIntoSubTree(VoxelTree* sourceTree, VoxelNode* dest · 1131 unmodified lines | |||
| 1160 | struct FalseColorizeOccludedArgs { | 1161 | struct FalseColorizeOccludedArgs { |
| 1161 | ViewFrustum* viewFrustum; | 1162 | ViewFrustum* viewFrustum; |
| 1162 | CoverageMap* map; | 1163 | CoverageMap* map; |
| 1164 | CoverageMapV2* mapV2; | ||
| 1163 | VoxelTree* tree; | 1165 | VoxelTree* tree; |
| 1164 | long totalVoxels; | 1166 | long totalVoxels; |
| 1165 | long coloredVoxels; | 1167 | long coloredVoxels; |
| @@ -1179,9 +1181,11 @@ struct FalseColorizeSubTreeOperationArgs { · 13 unmodified lines | |||
| 1179 | }; | 1181 | }; |
| 1180 | 1182 | ||
| 1181 | bool VoxelSystem::falseColorizeSubTreeOperation(VoxelNode* node, void* extraData) { | 1183 | bool VoxelSystem::falseColorizeSubTreeOperation(VoxelNode* node, void* extraData) { |
| 1182 | FalseColorizeSubTreeOperationArgs* args = (FalseColorizeSubTreeOperationArgs*) extraData; | 1184 | if (node->getShouldRender()) { |
| 1183 | node->setFalseColor(args->color[0], args->color[1], args->color[2]); | 1185 | FalseColorizeSubTreeOperationArgs* args = (FalseColorizeSubTreeOperationArgs*) extraData; |
| 1184 | args->voxelsTouched++; | 1186 | node->setFalseColor(args->color[0], args->color[1], args->color[2]); |
| 1187 | args->voxelsTouched++; | ||
| 1188 | } | ||
| 1185 | return true; | 1189 | return true; |
| 1186 | } | 1190 | } |
| 1187 | 1191 | ||
| @@ -1261,12 +1265,14 @@ bool VoxelSystem::falseColorizeOccludedOperation(VoxelNode* node, void* extraDat · 73 unmodified lines | |||
| 1261 | } | 1265 | } |
| 1262 | return true; // keep going! | 1266 | return true; // keep going! |
| 1263 | } | 1267 | } |
| 1268 | |||
| 1264 | void VoxelSystem::falseColorizeOccluded() { | 1269 | void VoxelSystem::falseColorizeOccluded() { |
| 1265 | PerformanceWarning warn(true, "falseColorizeOccluded()",true); | 1270 | PerformanceWarning warn(true, "falseColorizeOccluded()",true); |
| 1266 | CoverageMap map; | 1271 | myCoverageMap.erase(); |
| 1272 | |||
| 1267 | FalseColorizeOccludedArgs args; | 1273 | FalseColorizeOccludedArgs args; |
| 1268 | args.viewFrustum = Application::getInstance()->getViewFrustum(); | 1274 | args.viewFrustum = Application::getInstance()->getViewFrustum(); |
| 1269 | args.map = ↦ | 1275 | args.map = &myCoverageMap; |
| 1270 | args.totalVoxels = 0; | 1276 | args.totalVoxels = 0; |
| 1271 | args.coloredVoxels = 0; | 1277 | args.coloredVoxels = 0; |
| 1272 | args.occludedVoxels = 0; | 1278 | args.occludedVoxels = 0; |
| @@ -1278,19 +1284,151 @@ void VoxelSystem::falseColorizeOccluded() { · 5 unmodified lines | |||
| 1278 | args.nonLeavesOutOfView = 0; | 1284 | args.nonLeavesOutOfView = 0; |
| 1279 | args.nonLeavesOccluded = 0; | 1285 | args.nonLeavesOccluded = 0; |
| 1280 | args.tree = _tree; | 1286 | args.tree = _tree; |
| 1287 | |||
| 1288 | VoxelProjectedPolygon::pointInside_calls = 0; | ||
| 1289 | VoxelProjectedPolygon::occludes_calls = 0; | ||
| 1281 | 1290 | ||
| 1282 | glm::vec3 position = args.viewFrustum->getPosition() * (1.0f/TREE_SCALE); | 1291 | glm::vec3 position = args.viewFrustum->getPosition() * (1.0f/TREE_SCALE); |
| 1283 | 1292 | ||
| 1284 | _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedOperation, position, (void*)&args); | 1293 | _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedOperation, position, (void*)&args); |
| 1285 | 1294 | ||
| 1286 | printLog("falseColorizeOccluded()\n position=(%f,%f)\n total=%ld\n colored=%ld\n occluded=%ld\n notOccluded=%ld\n outOfView=%ld\n subtreeVoxelsSkipped=%ld\n stagedForDeletion=%ld\n nonLeaves=%ld\n nonLeavesOutOfView=%ld\n nonLeavesOccluded=%ld\n", | 1295 | printLog("falseColorizeOccluded()\n position=(%f,%f)\n total=%ld\n colored=%ld\n occluded=%ld\n notOccluded=%ld\n outOfView=%ld\n subtreeVoxelsSkipped=%ld\n stagedForDeletion=%ld\n nonLeaves=%ld\n nonLeavesOutOfView=%ld\n nonLeavesOccluded=%ld\n pointInside_calls=%ld\n occludes_calls=%ld\n", |
| 1296 | position.x, position.y, | ||
| 1297 | args.totalVoxels, args.coloredVoxels, args.occludedVoxels, | ||
| 1298 | args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped, | ||
| 1299 | args.stagedForDeletion, | ||
| 1300 | args.nonLeaves, args.nonLeavesOutOfView, args.nonLeavesOccluded, | ||
| 1301 | VoxelProjectedPolygon::pointInside_calls, | ||
| 1302 | VoxelProjectedPolygon::occludes_calls | ||
| 1303 | ); | ||
| 1304 | |||
| 1305 | |||
| 1306 | myCoverageMap.erase(); | ||
| 1307 | |||
| 1308 | setupNewVoxelsForDrawing(); | ||
| 1309 | } | ||
| 1310 | |||
| 1311 | bool VoxelSystem::falseColorizeOccludedV2Operation(VoxelNode* node, void* extraData) { | ||
| 1312 | |||
| 1313 | FalseColorizeOccludedArgs* args = (FalseColorizeOccludedArgs*) extraData; | ||
| 1314 | args->totalVoxels++; | ||
| 1315 | |||
| 1316 | // if this node is staged for deletion, then just return | ||
| 1317 | if (node->isStagedForDeletion()) { | ||
| 1318 | args->stagedForDeletion++; | ||
| 1319 | return true; | ||
| 1320 | } | ||
| 1321 | |||
| 1322 | // If we are a parent, let's see if we're completely occluded. | ||
| 1323 | if (!node->isLeaf()) { | ||
| 1324 | args->nonLeaves++; | ||
| 1325 | |||
| 1326 | AABox voxelBox = node->getAABox(); | ||
| 1327 | voxelBox.scale(TREE_SCALE); | ||
| 1328 | VoxelProjectedPolygon* voxelPolygon = new VoxelProjectedPolygon(args->viewFrustum->getProjectedPolygon(voxelBox)); | ||
| 1329 | |||
| 1330 | // If we're not all in view, then ignore it, and just return. But keep searching... | ||
| 1331 | if (!voxelPolygon->getAllInView()) { | ||
| 1332 | args->nonLeavesOutOfView++; | ||
| 1333 | delete voxelPolygon; | ||
| 1334 | return true; | ||
| 1335 | } | ||
| 1336 | |||
| 1337 | CoverageMapV2StorageResult result = args->mapV2->checkMap(voxelPolygon, false); | ||
| 1338 | if (result == V2_OCCLUDED) { | ||
| 1339 | args->nonLeavesOccluded++; | ||
| 1340 | delete voxelPolygon; | ||
| 1341 | |||
| 1342 | FalseColorizeSubTreeOperationArgs subArgs; | ||
| 1343 | subArgs.color[0] = 0; | ||
| 1344 | subArgs.color[1] = 255; | ||
| 1345 | subArgs.color[2] = 0; | ||
| 1346 | subArgs.voxelsTouched = 0; | ||
| 1347 | |||
| 1348 | args->tree->recurseNodeWithOperation(node, falseColorizeSubTreeOperation, &subArgs ); | ||
| 1349 | |||
| 1350 | args->subtreeVoxelsSkipped += (subArgs.voxelsTouched - 1); | ||
| 1351 | args->totalVoxels += (subArgs.voxelsTouched - 1); | ||
| 1352 | |||
| 1353 | return false; | ||
| 1354 | } | ||
| 1355 | |||
| 1356 | delete voxelPolygon; | ||
| 1357 | return true; // keep looking... | ||
| 1358 | } | ||
| 1359 | |||
| 1360 | if (node->isLeaf() && node->isColored() && node->getShouldRender()) { | ||
| 1361 | args->coloredVoxels++; | ||
| 1362 | |||
| 1363 | AABox voxelBox = node->getAABox(); | ||
| 1364 | voxelBox.scale(TREE_SCALE); | ||
| 1365 | VoxelProjectedPolygon* voxelPolygon = new VoxelProjectedPolygon(args->viewFrustum->getProjectedPolygon(voxelBox)); | ||
| 1366 | |||
| 1367 | // If we're not all in view, then ignore it, and just return. But keep searching... | ||
| 1368 | if (!voxelPolygon->getAllInView()) { | ||
| 1369 | args->outOfView++; | ||
| 1370 | delete voxelPolygon; | ||
| 1371 | return true; | ||
| 1372 | } | ||
| 1373 | |||
| 1374 | CoverageMapV2StorageResult result = args->mapV2->checkMap(voxelPolygon, true); | ||
| 1375 | if (result == V2_OCCLUDED) { | ||
| 1376 | node->setFalseColor(255, 0, 0); | ||
| 1377 | args->occludedVoxels++; | ||
| 1378 | } else if (result == V2_STORED) { | ||
| 1379 | args->notOccludedVoxels++; | ||
| 1380 | //printLog("***** falseColorizeOccludedOperation() NODE is STORED *****\n"); | ||
| 1381 | } else if (result == V2_DOESNT_FIT) { | ||
| 1382 | //printLog("***** falseColorizeOccludedOperation() NODE DOESNT_FIT???? *****\n"); | ||
| 1383 | } | ||
| 1384 | delete voxelPolygon; // V2 maps don't store polygons, so we're always in charge of freeing | ||
| 1385 | } | ||
| 1386 | return true; // keep going! | ||
| 1387 | } | ||
| 1388 | |||
| 1389 | |||
| 1390 | void VoxelSystem::falseColorizeOccludedV2() { | ||
| 1391 | PerformanceWarning warn(true, "falseColorizeOccludedV2()",true); | ||
| 1392 | myCoverageMapV2.erase(); | ||
| 1393 | |||
| 1394 | CoverageMapV2::wantDebugging = true; | ||
| 1395 | |||
| 1396 | VoxelProjectedPolygon::pointInside_calls = 0; | ||
| 1397 | VoxelProjectedPolygon::occludes_calls = 0; | ||
| 1398 | |||
| 1399 | |||
| 1400 | FalseColorizeOccludedArgs args; | ||
| 1401 | args.viewFrustum = Application::getInstance()->getViewFrustum(); | ||
| 1402 | args.mapV2 = &myCoverageMapV2; | ||
| 1403 | args.totalVoxels = 0; | ||
| 1404 | args.coloredVoxels = 0; | ||
| 1405 | args.occludedVoxels = 0; | ||
| 1406 | args.notOccludedVoxels = 0; | ||
| 1407 | args.outOfView = 0; | ||
| 1408 | args.subtreeVoxelsSkipped = 0; | ||
| 1409 | args.nonLeaves = 0; | ||
| 1410 | args.stagedForDeletion = 0; | ||
| 1411 | args.nonLeavesOutOfView = 0; | ||
| 1412 | args.nonLeavesOccluded = 0; | ||
| 1413 | args.tree = _tree; | ||
| 1414 | |||
| 1415 | glm::vec3 position = args.viewFrustum->getPosition() * (1.0f/TREE_SCALE); | ||
| 1416 | |||
| 1417 | _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedV2Operation, position, (void*)&args); | ||
| 1418 | |||
| 1419 | printLog("falseColorizeOccludedV2()\n position=(%f,%f)\n total=%ld\n colored=%ld\n occluded=%ld\n notOccluded=%ld\n outOfView=%ld\n subtreeVoxelsSkipped=%ld\n stagedForDeletion=%ld\n nonLeaves=%ld\n nonLeavesOutOfView=%ld\n nonLeavesOccluded=%ld\n pointInside_calls=%ld\n occludes_calls=%ld\n", | ||
| 1287 | position.x, position.y, | 1420 | position.x, position.y, |
| 1288 | args.totalVoxels, args.coloredVoxels, args.occludedVoxels, | 1421 | args.totalVoxels, args.coloredVoxels, args.occludedVoxels, |
| 1289 | args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped, | 1422 | args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped, |
| 1290 | args.stagedForDeletion, | 1423 | args.stagedForDeletion, |
| 1291 | args.nonLeaves, args.nonLeavesOutOfView, args.nonLeavesOccluded); | 1424 | args.nonLeaves, args.nonLeavesOutOfView, args.nonLeavesOccluded, |
| 1425 | VoxelProjectedPolygon::pointInside_calls, | ||
| 1426 | VoxelProjectedPolygon::occludes_calls | ||
| 1427 | ); | ||
| 1428 | myCoverageMapV2.erase(); | ||
| 1292 | 1429 | ||
| 1293 | 1430 | ||
| 1294 | setupNewVoxelsForDrawing(); | 1431 | setupNewVoxelsForDrawing(); |
| 1295 | } | 1432 | } |
| 1296 | 1433 | ||
| 1434 | |||