Showing the changes to interface/src/VoxelSystem.cpp (1 of 54 files). Show all
Unified · Split
| @@ -5,28 +5,31 @@ · 4 unmodified lines | |||
| 5 | // Created by Philip on 12/31/12. | 5 | // Created by Philip on 12/31/12. |
| 6 | // Copyright (c) 2012 High Fidelity, Inc. All rights reserved. | 6 | // Copyright (c) 2012 High Fidelity, Inc. All rights reserved. |
| 7 | // | 7 | // |
| 8 | |||
| 8 | #ifdef _WIN32 | 9 | #ifdef _WIN32 |
| 9 | #define _timeval_ | 10 | #define _timeval_ |
| 10 | #define _USE_MATH_DEFINES | 11 | #define _USE_MATH_DEFINES |
| 11 | #endif | 12 | #endif |
| 13 | |||
| 12 | #include <cstring> | 14 | #include <cstring> |
| 13 | #include <cmath> | 15 | #include <cmath> |
| 14 | #include <iostream> // to load voxels from file | 16 | #include <iostream> // to load voxels from file |
| 15 | #include <fstream> // to load voxels from file | 17 | #include <fstream> // to load voxels from file |
| 18 | #include <pthread.h> | ||
| 19 | |||
| 16 | #include <glm/gtc/random.hpp> | 20 | #include <glm/gtc/random.hpp> |
| 17 | #include <SharedUtil.h> | 21 | |
| 22 | #include <OctalCode.h> | ||
| 18 | #include <PacketHeaders.h> | 23 | #include <PacketHeaders.h> |
| 19 | #include <PerfStat.h> | 24 | #include <PerfStat.h> |
| 20 | #include <OctalCode.h> | 25 | #include <SharedUtil.h> |
| 21 | #include <pthread.h> | 26 | |
| 22 | #include "Application.h" | 27 | #include "Application.h" |
| 23 | #include "Log.h" | ||
| 24 | #include "VoxelConstants.h" | ||
| 25 | #include "CoverageMap.h" | 28 | #include "CoverageMap.h" |
| 26 | #include "CoverageMapV2.h" | 29 | #include "CoverageMapV2.h" |
| 27 | #include "InterfaceConfig.h" | 30 | #include "InterfaceConfig.h" |
| 28 | #include "renderer/ProgramObject.h" | 31 | #include "renderer/ProgramObject.h" |
| 29 | 32 | #include "VoxelConstants.h" | |
| 30 | #include "VoxelSystem.h" | 33 | #include "VoxelSystem.h" |
| 31 | 34 | ||
| 32 | float identityVertices[] = { 0,0,0, 1,0,0, 1,1,0, 0,1,0, 0,0,1, 1,0,1, 1,1,1, 0,1,1, | 35 | float identityVertices[] = { 0,0,0, 1,0,0, 1,1,0, 0,1,0, 0,0,1, 1,0,1, 1,1,1, 0,1,1, |
| @@ -141,16 +144,16 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 108 unmodified lines | |||
| 141 | int commandLength = strlen(command); // commands are null terminated strings | 144 | int commandLength = strlen(command); // commands are null terminated strings |
| 142 | int totalLength = 1+commandLength+1; | 145 | int totalLength = 1+commandLength+1; |
| 143 | 146 | ||
| 144 | printLog("got Z message len(%d)= %s\n", numBytes, command); | 147 | qDebug("got Z message len(%d)= %s\n", numBytes, command); |
| 145 | 148 | ||
| 146 | while (totalLength <= numBytes) { | 149 | while (totalLength <= numBytes) { |
| 147 | if (0==strcmp(command,(char*)"erase all")) { | 150 | if (0==strcmp(command,(char*)"erase all")) { |
| 148 | printLog("got Z message == erase all\n"); | 151 | qDebug("got Z message == erase all\n"); |
| 149 | _tree->eraseAllVoxels(); | 152 | _tree->eraseAllVoxels(); |
| 150 | _voxelsInReadArrays = _voxelsInWriteArrays = 0; // better way to do this?? | 153 | _voxelsInReadArrays = _voxelsInWriteArrays = 0; // better way to do this?? |
| 151 | } | 154 | } |
| 152 | if (0==strcmp(command,(char*)"add scene")) { | 155 | if (0==strcmp(command,(char*)"add scene")) { |
| 153 | printLog("got Z message == add scene - NOT SUPPORTED ON INTERFACE\n"); | 156 | qDebug("got Z message == add scene - NOT SUPPORTED ON INTERFACE\n"); |
| 154 | } | 157 | } |
| 155 | totalLength += commandLength+1; | 158 | totalLength += commandLength+1; |
| 156 | } | 159 | } |
| @@ -705,7 +708,7 @@ bool VoxelSystem::randomColorOperation(VoxelNode* node, void* extraData) { · 548 unmodified lines | |||
| 705 | void VoxelSystem::randomizeVoxelColors() { | 708 | void VoxelSystem::randomizeVoxelColors() { |
| 706 | _nodeCount = 0; | 709 | _nodeCount = 0; |
| 707 | _tree->recurseTreeWithOperation(randomColorOperation); | 710 | _tree->recurseTreeWithOperation(randomColorOperation); |
| 708 | printLog("setting randomized true color for %d nodes\n", _nodeCount); | 711 | qDebug("setting randomized true color for %d nodes\n", _nodeCount); |
| 709 | setupNewVoxelsForDrawing(); | 712 | setupNewVoxelsForDrawing(); |
| 710 | } | 713 | } |
| 711 | 714 | ||
| @@ -719,7 +722,7 @@ bool VoxelSystem::falseColorizeRandomOperation(VoxelNode* node, void* extraData) · 7 unmodified lines | |||
| 719 | void VoxelSystem::falseColorizeRandom() { | 722 | void VoxelSystem::falseColorizeRandom() { |
| 720 | _nodeCount = 0; | 723 | _nodeCount = 0; |
| 721 | _tree->recurseTreeWithOperation(falseColorizeRandomOperation); | 724 | _tree->recurseTreeWithOperation(falseColorizeRandomOperation); |
| 722 | printLog("setting randomized false color for %d nodes\n", _nodeCount); | 725 | qDebug("setting randomized false color for %d nodes\n", _nodeCount); |
| 723 | setupNewVoxelsForDrawing(); | 726 | setupNewVoxelsForDrawing(); |
| 724 | } | 727 | } |
| 725 | 728 | ||
| @@ -733,7 +736,7 @@ void VoxelSystem::trueColorize() { · 7 unmodified lines | |||
| 733 | PerformanceWarning warn(true, "trueColorize()",true); | 736 | PerformanceWarning warn(true, "trueColorize()",true); |
| 734 | _nodeCount = 0; | 737 | _nodeCount = 0; |
| 735 | _tree->recurseTreeWithOperation(trueColorizeOperation); | 738 | _tree->recurseTreeWithOperation(trueColorizeOperation); |
| 736 | printLog("setting true color for %d nodes\n", _nodeCount); | 739 | qDebug("setting true color for %d nodes\n", _nodeCount); |
| 737 | setupNewVoxelsForDrawing(); | 740 | setupNewVoxelsForDrawing(); |
| 738 | } | 741 | } |
| 739 | 742 | ||
| @@ -753,7 +756,7 @@ bool VoxelSystem::falseColorizeInViewOperation(VoxelNode* node, void* extraData) · 13 unmodified lines | |||
| 753 | void VoxelSystem::falseColorizeInView(ViewFrustum* viewFrustum) { | 756 | void VoxelSystem::falseColorizeInView(ViewFrustum* viewFrustum) { |
| 754 | _nodeCount = 0; | 757 | _nodeCount = 0; |
| 755 | _tree->recurseTreeWithOperation(falseColorizeInViewOperation,(void*)viewFrustum); | 758 | _tree->recurseTreeWithOperation(falseColorizeInViewOperation,(void*)viewFrustum); |
| 756 | printLog("setting in view false color for %d nodes\n", _nodeCount); | 759 | qDebug("setting in view false color for %d nodes\n", _nodeCount); |
| 757 | setupNewVoxelsForDrawing(); | 760 | setupNewVoxelsForDrawing(); |
| 758 | } | 761 | } |
| 759 | 762 | ||
| @@ -803,10 +806,10 @@ void VoxelSystem::falseColorizeDistanceFromView(ViewFrustum* viewFrustum) { · 43 unmodified lines | |||
| 803 | _maxDistance = 0.0; | 806 | _maxDistance = 0.0; |
| 804 | _minDistance = FLT_MAX; | 807 | _minDistance = FLT_MAX; |
| 805 | _tree->recurseTreeWithOperation(getDistanceFromViewRangeOperation,(void*)viewFrustum); | 808 | _tree->recurseTreeWithOperation(getDistanceFromViewRangeOperation,(void*)viewFrustum); |
| 806 | printLog("determining distance range for %d nodes\n", _nodeCount); | 809 | qDebug("determining distance range for %d nodes\n", _nodeCount); |
| 807 | _nodeCount = 0; | 810 | _nodeCount = 0; |
| 808 | _tree->recurseTreeWithOperation(falseColorizeDistanceFromViewOperation,(void*)viewFrustum); | 811 | _tree->recurseTreeWithOperation(falseColorizeDistanceFromViewOperation,(void*)viewFrustum); |
| 809 | printLog("setting in distance false color for %d nodes\n", _nodeCount); | 812 | qDebug("setting in distance false color for %d nodes\n", _nodeCount); |
| 810 | setupNewVoxelsForDrawing(); | 813 | setupNewVoxelsForDrawing(); |
| 811 | } | 814 | } |
| 812 | 815 | ||
| @@ -918,7 +921,7 @@ void VoxelSystem::removeOutOfView() { · 105 unmodified lines | |||
| 918 | } | 921 | } |
| 919 | bool showRemoveDebugDetails = false; | 922 | bool showRemoveDebugDetails = false; |
| 920 | if (showRemoveDebugDetails) { | 923 | if (showRemoveDebugDetails) { |
| 921 | printLog("removeOutOfView() scanned=%ld removed=%ld inside=%ld intersect=%ld outside=%ld _removedVoxels.count()=%d \n", | 924 | qDebug("removeOutOfView() scanned=%ld removed=%ld inside=%ld intersect=%ld outside=%ld _removedVoxels.count()=%d \n", |
| 922 | args.nodesScanned, args.nodesRemoved, args.nodesInside, | 925 | args.nodesScanned, args.nodesRemoved, args.nodesInside, |
| 923 | args.nodesIntersect, args.nodesOutside, _removedVoxels.count() | 926 | args.nodesIntersect, args.nodesOutside, _removedVoxels.count() |
| 924 | ); | 927 | ); |
| @@ -984,7 +987,7 @@ bool VoxelSystem::falseColorizeRandomEveryOtherOperation(VoxelNode* node, void* · 59 unmodified lines | |||
| 984 | void VoxelSystem::falseColorizeRandomEveryOther() { | 987 | void VoxelSystem::falseColorizeRandomEveryOther() { |
| 985 | falseColorizeRandomEveryOtherArgs args; | 988 | falseColorizeRandomEveryOtherArgs args; |
| 986 | _tree->recurseTreeWithOperation(falseColorizeRandomEveryOtherOperation,&args); | 989 | _tree->recurseTreeWithOperation(falseColorizeRandomEveryOtherOperation,&args); |
| 987 | printLog("randomized false color for every other node: total %ld, colorable %ld, colored %ld\n", | 990 | qDebug("randomized false color for every other node: total %ld, colorable %ld, colored %ld\n", |
| 988 | args.totalNodes, args.colorableNodes, args.coloredNodes); | 991 | args.totalNodes, args.colorableNodes, args.coloredNodes); |
| 989 | setupNewVoxelsForDrawing(); | 992 | setupNewVoxelsForDrawing(); |
| 990 | } | 993 | } |
| @@ -1045,7 +1048,7 @@ bool VoxelSystem::collectStatsForTreesAndVBOsOperation(VoxelNode* node, void* ex · 54 unmodified lines | |||
| 1045 | unsigned long nodeIndex = node->getBufferIndex(); | 1048 | unsigned long nodeIndex = node->getBufferIndex(); |
| 1046 | if (args->hasIndexFound[nodeIndex]) { | 1049 | if (args->hasIndexFound[nodeIndex]) { |
| 1047 | args->duplicateVBOIndex++; | 1050 | args->duplicateVBOIndex++; |
| 1048 | printLog("duplicateVBO found... index=%ld, isDirty=%s, shouldRender=%s \n", nodeIndex, | 1051 | qDebug("duplicateVBO found... index=%ld, isDirty=%s, shouldRender=%s \n", nodeIndex, |
| 1049 | debug::valueOf(node->isDirty()), debug::valueOf(node->getShouldRender())); | 1052 | debug::valueOf(node->isDirty()), debug::valueOf(node->getShouldRender())); |
| 1050 | } else { | 1053 | } else { |
| 1051 | args->hasIndexFound[nodeIndex] = true; | 1054 | args->hasIndexFound[nodeIndex] = true; |
| @@ -1080,13 +1083,13 @@ void VoxelSystem::collectStatsForTreesAndVBOs() { · 28 unmodified lines | |||
| 1080 | args.expectedMax = _voxelsInWriteArrays; | 1083 | args.expectedMax = _voxelsInWriteArrays; |
| 1081 | _tree->recurseTreeWithOperation(collectStatsForTreesAndVBOsOperation,&args); | 1084 | _tree->recurseTreeWithOperation(collectStatsForTreesAndVBOsOperation,&args); |
| 1082 | 1085 | ||
| 1083 | printLog("Local Voxel Tree Statistics:\n total nodes %ld \n leaves %ld \n dirty %ld \n colored %ld \n shouldRender %ld \n", | 1086 | qDebug("Local Voxel Tree Statistics:\n total nodes %ld \n leaves %ld \n dirty %ld \n colored %ld \n shouldRender %ld \n", |
| 1084 | args.totalNodes, args.leafNodes, args.dirtyNodes, args.coloredNodes, args.shouldRenderNodes); | 1087 | args.totalNodes, args.leafNodes, args.dirtyNodes, args.coloredNodes, args.shouldRenderNodes); |
| 1085 | 1088 | ||
| 1086 | printLog(" _voxelsDirty=%s \n _voxelsInWriteArrays=%ld \n minDirty=%ld \n maxDirty=%ld \n", debug::valueOf(_voxelsDirty), | 1089 | qDebug(" _voxelsDirty=%s \n _voxelsInWriteArrays=%ld \n minDirty=%ld \n maxDirty=%ld \n", debug::valueOf(_voxelsDirty), |
| 1087 | _voxelsInWriteArrays, minDirty, maxDirty); | 1090 | _voxelsInWriteArrays, minDirty, maxDirty); |
| 1088 | 1091 | ||
| 1089 | printLog(" inVBO %ld \n nodesInVBOOverExpectedMax %ld \n duplicateVBOIndex %ld \n nodesInVBONotShouldRender %ld \n", | 1092 | qDebug(" inVBO %ld \n nodesInVBOOverExpectedMax %ld \n duplicateVBOIndex %ld \n nodesInVBONotShouldRender %ld \n", |
| 1090 | args.nodesInVBO, args.nodesInVBOOverExpectedMax, args.duplicateVBOIndex, args.nodesInVBONotShouldRender); | 1093 | args.nodesInVBO, args.nodesInVBOOverExpectedMax, args.duplicateVBOIndex, args.nodesInVBONotShouldRender); |
| 1091 | 1094 | ||
| 1092 | glBufferIndex minInVBO = GLBUFFER_INDEX_UNKNOWN; | 1095 | glBufferIndex minInVBO = GLBUFFER_INDEX_UNKNOWN; |
| @@ -1099,7 +1102,7 @@ void VoxelSystem::collectStatsForTreesAndVBOs() { · 6 unmodified lines | |||
| 1099 | } | 1102 | } |
| 1100 | } | 1103 | } |
| 1101 | 1104 | ||
| 1102 | printLog(" minInVBO=%ld \n maxInVBO=%ld \n _voxelsInWriteArrays=%ld \n _voxelsInReadArrays=%ld \n", | 1105 | qDebug(" minInVBO=%ld \n maxInVBO=%ld \n _voxelsInWriteArrays=%ld \n _voxelsInReadArrays=%ld \n", |
| 1103 | minInVBO, maxInVBO, _voxelsInWriteArrays, _voxelsInReadArrays); | 1106 | minInVBO, maxInVBO, _voxelsInWriteArrays, _voxelsInReadArrays); |
| 1104 | 1107 | ||
| 1105 | } | 1108 | } |
| @@ -1124,7 +1127,7 @@ void VoxelSystem::createVoxel(float x, float y, float z, float s, · 18 unmodified lines | |||
| 1124 | unsigned char red, unsigned char green, unsigned char blue, bool destructive) { | 1127 | unsigned char red, unsigned char green, unsigned char blue, bool destructive) { |
| 1125 | pthread_mutex_lock(&_treeLock); | 1128 | pthread_mutex_lock(&_treeLock); |
| 1126 | 1129 | ||
| 1127 | //printLog("VoxelSystem::createVoxel(%f,%f,%f,%f)\n",x,y,z,s); | 1130 | //qDebug("VoxelSystem::createVoxel(%f,%f,%f,%f)\n",x,y,z,s); |
| 1128 | _tree->createVoxel(x, y, z, s, red, green, blue, destructive); | 1131 | _tree->createVoxel(x, y, z, s, red, green, blue, destructive); |
| 1129 | setupNewVoxelsForDrawing(); | 1132 | setupNewVoxelsForDrawing(); |
| 1130 | 1133 | ||
| @@ -1250,9 +1253,9 @@ bool VoxelSystem::falseColorizeOccludedOperation(VoxelNode* node, void* extraDat · 119 unmodified lines | |||
| 1250 | args->occludedVoxels++; | 1253 | args->occludedVoxels++; |
| 1251 | } else if (result == STORED) { | 1254 | } else if (result == STORED) { |
| 1252 | args->notOccludedVoxels++; | 1255 | args->notOccludedVoxels++; |
| 1253 | //printLog("***** falseColorizeOccludedOperation() NODE is STORED *****\n"); | 1256 | //qDebug("***** falseColorizeOccludedOperation() NODE is STORED *****\n"); |
| 1254 | } else if (result == DOESNT_FIT) { | 1257 | } else if (result == DOESNT_FIT) { |
| 1255 | //printLog("***** falseColorizeOccludedOperation() NODE DOESNT_FIT???? *****\n"); | 1258 | //qDebug("***** falseColorizeOccludedOperation() NODE DOESNT_FIT???? *****\n"); |
| 1256 | } | 1259 | } |
| 1257 | } | 1260 | } |
| 1258 | return true; // keep going! | 1261 | return true; // keep going! |
| @@ -1285,7 +1288,7 @@ void VoxelSystem::falseColorizeOccluded() { · 26 unmodified lines | |||
| 1285 | 1288 | ||
| 1286 | _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedOperation, position, (void*)&args); | 1289 | _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedOperation, position, (void*)&args); |
| 1287 | 1290 | ||
| 1288 | 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 intersects_calls=%ld\n", | 1291 | qDebug("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 intersects_calls=%ld\n", |
| 1289 | position.x, position.y, | 1292 | position.x, position.y, |
| 1290 | args.totalVoxels, args.coloredVoxels, args.occludedVoxels, | 1293 | args.totalVoxels, args.coloredVoxels, args.occludedVoxels, |
| 1291 | args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped, | 1294 | args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped, |
| @@ -1371,9 +1374,9 @@ bool VoxelSystem::falseColorizeOccludedV2Operation(VoxelNode* node, void* extraD · 79 unmodified lines | |||
| 1371 | args->occludedVoxels++; | 1374 | args->occludedVoxels++; |
| 1372 | } else if (result == V2_STORED) { | 1375 | } else if (result == V2_STORED) { |
| 1373 | args->notOccludedVoxels++; | 1376 | args->notOccludedVoxels++; |
| 1374 | //printLog("***** falseColorizeOccludedOperation() NODE is STORED *****\n"); | 1377 | //qDebug("***** falseColorizeOccludedOperation() NODE is STORED *****\n"); |
| 1375 | } else if (result == V2_DOESNT_FIT) { | 1378 | } else if (result == V2_DOESNT_FIT) { |
| 1376 | //printLog("***** falseColorizeOccludedOperation() NODE DOESNT_FIT???? *****\n"); | 1379 | //qDebug("***** falseColorizeOccludedOperation() NODE DOESNT_FIT???? *****\n"); |
| 1377 | } | 1380 | } |
| 1378 | delete voxelPolygon; // V2 maps don't store polygons, so we're always in charge of freeing | 1381 | delete voxelPolygon; // V2 maps don't store polygons, so we're always in charge of freeing |
| 1379 | } | 1382 | } |
| @@ -1410,7 +1413,7 @@ void VoxelSystem::falseColorizeOccludedV2() { · 30 unmodified lines | |||
| 1410 | 1413 | ||
| 1411 | _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedV2Operation, position, (void*)&args); | 1414 | _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedV2Operation, position, (void*)&args); |
| 1412 | 1415 | ||
| 1413 | 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 intersects_calls=%ld\n", | 1416 | qDebug("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 intersects_calls=%ld\n", |
| 1414 | position.x, position.y, | 1417 | position.x, position.y, |
| 1415 | args.totalVoxels, args.coloredVoxels, args.occludedVoxels, | 1418 | args.totalVoxels, args.coloredVoxels, args.occludedVoxels, |
| 1416 | args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped, | 1419 | args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped, |