Showing the changes to interface/src/VoxelSystem.cpp (1 of 5 files). Show all
Unified · Split
| @@ -1158,70 +1158,138 @@ void VoxelSystem::copyFromTreeIntoSubTree(VoxelTree* sourceTree, VoxelNode* dest · 1157 unmodified lines | ||
| 1158 | 1158 | } |
| 1159 | 1159 | |
| 1160 | 1160 | struct FalseColorizeOccludedArgs { |
| 1161 | − VoxelProjectedShadow occluder; | |
| 1162 | 1161 | ViewFrustum* viewFrustum; |
| 1163 | 1162 | CoverageMap* map; |
| 1163 | + VoxelTree* tree; | |
| 1164 | + long totalVoxels; | |
| 1165 | + long coloredVoxels; | |
| 1166 | + long occludedVoxels; | |
| 1167 | + long notOccludedVoxels; | |
| 1168 | + long outOfView; | |
| 1169 | + long subtreeVoxelsSkipped; | |
| 1170 | + long nonLeaves; | |
| 1171 | + long nonLeavesOutOfView; | |
| 1172 | + long nonLeavesOccluded; | |
| 1173 | + long stagedForDeletion; | |
| 1164 | 1174 | }; |
| 1165 | 1175 | |
| 1166 | −bool VoxelSystem::falseColorizeTestOccludedOperation(VoxelNode* node, void* extraData) { | |
| 1176 | +struct FalseColorizeSubTreeOperationArgs { | |
| 1177 | + unsigned char color[NUMBER_OF_COLORS]; | |
| 1178 | + long voxelsTouched; | |
| 1179 | +}; | |
| 1180 | + | |
| 1181 | +bool VoxelSystem::falseColorizeSubTreeOperation(VoxelNode* node, void* extraData) { | |
| 1182 | + FalseColorizeSubTreeOperationArgs* args = (FalseColorizeSubTreeOperationArgs*) extraData; | |
| 1183 | + node->setFalseColor(args->color[0], args->color[1], args->color[2]); | |
| 1184 | + args->voxelsTouched++; | |
| 1185 | + return true; | |
| 1186 | +} | |
| 1187 | + | |
| 1188 | +bool VoxelSystem::falseColorizeOccludedOperation(VoxelNode* node, void* extraData) { | |
| 1189 | + | |
| 1167 | 1190 | FalseColorizeOccludedArgs* args = (FalseColorizeOccludedArgs*) extraData; |
| 1168 | − if (node->isColored()) { | |
| 1191 | + args->totalVoxels++; | |
| 1192 | + | |
| 1193 | + // if this node is staged for deletion, then just return | |
| 1194 | + if (node->isStagedForDeletion()) { | |
| 1195 | + args->stagedForDeletion++; | |
| 1196 | + return true; | |
| 1197 | + } | |
| 1198 | + | |
| 1199 | + // If we are a parent, let's see if we're completely occluded. | |
| 1200 | + if (!node->isLeaf()) { | |
| 1201 | + args->nonLeaves++; | |
| 1202 | + | |
| 1169 | 1203 | AABox voxelBox = node->getAABox(); |
| 1170 | 1204 | voxelBox.scale(TREE_SCALE); |
| 1171 | − VoxelProjectedShadow voxelShadow = args->viewFrustum->getProjectedShadow(voxelBox); | |
| 1172 | − if (args->occluder.occludes(voxelShadow)) { | |
| 1173 | − node->setFalseColor(255, 0, 0); | |
| 1205 | + VoxelProjectedShadow* voxelShadow = new VoxelProjectedShadow(args->viewFrustum->getProjectedShadow(voxelBox)); | |
| 1206 | + | |
| 1207 | + // If we're not all in view, then ignore it, and just return. But keep searching... | |
| 1208 | + if (!voxelShadow->getAllInView()) { | |
| 1209 | + args->nonLeavesOutOfView++; | |
| 1210 | + delete voxelShadow; | |
| 1211 | + return true; | |
| 1174 | 1212 | } |
| 1175 | − } | |
| 1176 | − return true; // keep going! | |
| 1177 | −} | |
| 1178 | 1213 | |
| 1179 | −void VoxelSystem::falseColorizeTestOccluded() { | |
| 1180 | − FalseColorizeOccludedArgs args; | |
| 1181 | − args.viewFrustum = Application::getInstance()->getViewFrustum(); | |
| 1182 | − | |
| 1183 | − AABox box(glm::vec3(0.0125,0,0.025), 0.0125); | |
| 1184 | − box.scale(TREE_SCALE); | |
| 1185 | − args.occluder = args.viewFrustum->getProjectedShadow(box); | |
| 1214 | + CoverageMap::StorageResult result = args->map->checkMap(voxelShadow, false); | |
| 1215 | + if (result == CoverageMap::OCCLUDED) { | |
| 1216 | + args->nonLeavesOccluded++; | |
| 1217 | + delete voxelShadow; | |
| 1218 | + | |
| 1219 | + FalseColorizeSubTreeOperationArgs subArgs; | |
| 1220 | + subArgs.color[0] = 0; | |
| 1221 | + subArgs.color[1] = 255; | |
| 1222 | + subArgs.color[2] = 0; | |
| 1223 | + subArgs.voxelsTouched = 0; | |
| 1224 | + | |
| 1225 | + args->tree->recurseNodeWithOperation(node, falseColorizeSubTreeOperation, &subArgs ); | |
| 1226 | + | |
| 1227 | + args->subtreeVoxelsSkipped += (subArgs.voxelsTouched - 1); | |
| 1228 | + args->totalVoxels += (subArgs.voxelsTouched - 1); | |
| 1229 | + | |
| 1230 | + return false; | |
| 1231 | + } | |
| 1186 | 1232 | |
| 1187 | − _tree->recurseTreeWithOperation(falseColorizeTestOccludedOperation,(void*)&args); | |
| 1188 | − setupNewVoxelsForDrawing(); | |
| 1189 | −} | |
| 1233 | + delete voxelShadow; | |
| 1234 | + return true; // keep looking... | |
| 1235 | + } | |
| 1236 | + | |
| 1237 | + if (node->isLeaf() && node->isColored() && node->getShouldRender()) { | |
| 1238 | + args->coloredVoxels++; | |
| 1190 | 1239 | |
| 1191 | −bool VoxelSystem::falseColorizeOccludedOperation(VoxelNode* node, void* extraData) { | |
| 1192 | −//node->printDebugDetails(">>>>>>>>>>>>>>> falseColorizeOccludedOperation() BEGIN >>>>>>>>>>>>>>"); | |
| 1193 | − FalseColorizeOccludedArgs* args = (FalseColorizeOccludedArgs*) extraData; | |
| 1194 | − if (node->isColored() && node->isLeaf() && !node->isStagedForDeletion() && node->getShouldRender()) { | |
| 1195 | −//printLog("***** falseColorizeOccludedOperation() NODE is colored, etc, so consider it *****\n"); | |
| 1196 | 1240 | AABox voxelBox = node->getAABox(); |
| 1197 | 1241 | voxelBox.scale(TREE_SCALE); |
| 1198 | 1242 | VoxelProjectedShadow* voxelShadow = new VoxelProjectedShadow(args->viewFrustum->getProjectedShadow(voxelBox)); |
| 1199 | − CoverageMap::StorageResult result = args->map->storeInMap(voxelShadow); | |
| 1243 | + | |
| 1244 | + // If we're not all in view, then ignore it, and just return. But keep searching... | |
| 1245 | + if (!voxelShadow->getAllInView()) { | |
| 1246 | + args->outOfView++; | |
| 1247 | + delete voxelShadow; | |
| 1248 | + return true; | |
| 1249 | + } | |
| 1250 | + | |
| 1251 | + CoverageMap::StorageResult result = args->map->checkMap(voxelShadow, true); | |
| 1200 | 1252 | if (result == CoverageMap::OCCLUDED) { |
| 1201 | −//printLog("***** falseColorizeOccludedOperation() NODE is OCCLUDED *****\n"); | |
| 1202 | 1253 | node->setFalseColor(255, 0, 0); |
| 1254 | + args->occludedVoxels++; | |
| 1203 | 1255 | } else if (result == CoverageMap::STORED) { |
| 1204 | −//printLog("***** falseColorizeOccludedOperation() NODE is STORED *****\n"); | |
| 1256 | + args->notOccludedVoxels++; | |
| 1257 | + //printLog("***** falseColorizeOccludedOperation() NODE is STORED *****\n"); | |
| 1205 | 1258 | } else if (result == CoverageMap::DOESNT_FIT) { |
| 1206 | −//printLog("***** falseColorizeOccludedOperation() NODE DOESNT_FIT???? *****\n"); | |
| 1259 | + //printLog("***** falseColorizeOccludedOperation() NODE DOESNT_FIT???? *****\n"); | |
| 1207 | 1260 | } |
| 1208 | 1261 | } |
| 1209 | −//printLog("<<<<<<<<<<<<<<<<< falseColorizeOccludedOperation() END <<<<<<<<<<<<<<<<<\n"); | |
| 1210 | 1262 | return true; // keep going! |
| 1211 | 1263 | } |
| 1212 | − | |
| 1213 | 1264 | void VoxelSystem::falseColorizeOccluded() { |
| 1265 | + PerformanceWarning warn(true, "falseColorizeOccluded()",true); | |
| 1214 | 1266 | CoverageMap map(BoundingBox(glm::vec2(-2.f,-2.f), glm::vec2(4.f,4.f)), true); |
| 1215 | 1267 | FalseColorizeOccludedArgs args; |
| 1216 | 1268 | args.viewFrustum = Application::getInstance()->getViewFrustum(); |
| 1217 | 1269 | args.map = ↦ |
| 1270 | + args.totalVoxels = 0; | |
| 1271 | + args.coloredVoxels = 0; | |
| 1272 | + args.occludedVoxels = 0; | |
| 1273 | + args.notOccludedVoxels = 0; | |
| 1274 | + args.outOfView = 0; | |
| 1275 | + args.subtreeVoxelsSkipped = 0; | |
| 1276 | + args.nonLeaves = 0; | |
| 1277 | + args.stagedForDeletion = 0; | |
| 1278 | + args.nonLeavesOutOfView = 0; | |
| 1279 | + args.nonLeavesOccluded = 0; | |
| 1280 | + args.tree = _tree; | |
| 1218 | 1281 | |
| 1219 | − AABox box(glm::vec3(0.0125,0,0.025), 0.0125); | |
| 1220 | − box.scale(TREE_SCALE); | |
| 1221 | − args.occluder = args.viewFrustum->getProjectedShadow(box); | |
| 1222 | 1282 | glm::vec3 position = args.viewFrustum->getPosition() * (1.0f/TREE_SCALE); |
| 1223 | 1283 | |
| 1224 | 1284 | _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedOperation, position, (void*)&args); |
| 1285 | + | |
| 1286 | + printLog("falseColorizeOccluded()\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", | |
| 1287 | + args.totalVoxels, args.coloredVoxels, args.occludedVoxels, | |
| 1288 | + args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped, | |
| 1289 | + args.stagedForDeletion, | |
| 1290 | + args.nonLeaves, args.nonLeavesOutOfView, args.nonLeavesOccluded); | |
| 1291 | + | |
| 1292 | + | |
| 1225 | 1293 | setupNewVoxelsForDrawing(); |
| 1226 | 1294 | } |
| 1227 | 1295 | |