From f720513affc145ebce1835f98085e6d15a3389b9 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 10 Jul 2013 17:30:40 -0700 Subject: [PATCH] removed scanTreeWithOcclusion() experimental code --- voxel-server/src/main.cpp | 275 +------------------------------------- 1 file changed, 1 insertion(+), 274 deletions(-) diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 05d834c7df..87ee020bde 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -65,9 +65,6 @@ bool wantSearchForColoredNodes = false; EnvironmentData environmentData[3]; -void scanTreeWithOcclusion(VoxelTree* tree, ViewFrustum* viewFrustum, CoverageMap* coverageMap, bool wantsOcclusionCulling); - - void randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) { // randomly generate children for this node // the first level of the tree (where levelsToGo = MAX_VOXEL_TREE_DEPTH_LEVELS) has all 8 @@ -466,16 +463,7 @@ void *distributeVoxelsToListeners(void *args) { } if (nodeData->getWantResIn()) { - //resInVoxelDistributor(nodeList, node, nodeData); - - // hack, just test scanning the tree here! - scanTreeWithOcclusion(&serverTree, &nodeData->getCurrentViewFrustum(), &nodeData->map, - nodeData->getWantOcclusionCulling()); - printf("AFTER scanTreeWithOcclusion() map->printStats()\n"); - CoverageMap::wantDebugging = true; - nodeData->map.printStats(); - - + resInVoxelDistributor(nodeList, node, nodeData); } else { deepestLevelVoxelDistributor(nodeList, node, nodeData, viewFrustumChanged); } @@ -767,264 +755,3 @@ int main(int argc, const char * argv[]) { } -const long MAX_SCAN = 100 * 1000; - -struct ScanTreeArgs { - ViewFrustum* viewFrustum; - glm::vec3 cameraPosition; - CoverageMap* map; -// CoverageMapV2* mapV2; - VoxelTree* tree; - long totalVoxels; - long coloredVoxels; - long occludedVoxels; - long notOccludedVoxels; - - long outOfView; // not in the view frustum - long leavesOutOfView; // not in the view frustum - - long tooFar; // out of LOD - long leavesTooFar; // out of LOD - - long notAllInView; // in the view frustum, but the projection can't be calculated, assume it needs to be sent - long subtreeVoxelsSkipped; - - long nonLeaves; - long nonLeavesNotAllInView; - long nonLeavesOutOfView; // not in the view frustum - long nonLeavesOccluded; - long nonLeavesTooFar; - - long stagedForDeletion; - long doesntFit; - - bool wantsOcclusionCulling; - - ViewFrustum::location subTreeLocation; - long subTreeInside; - - int level; -}; - -struct CountSubTreeOperationArgs { - long voxelsTouched; -}; - - -bool scanTreeWithOcclusionOperation(VoxelNode* node, void* extraData) { - - ScanTreeArgs* args = (ScanTreeArgs*) extraData; - - // fastest, scan entire tree... - //args->totalVoxels++; - //return true; - - - args->totalVoxels++; - - // SOME FACTS WE KNOW... - // If a node is INSIDE the view frustum, then ALL it's child nodes are also INSIDE, and so we - // shouldn't have to check that any more... use InFrustum() and store something in args to know - // that that part of the stack is in frustum. (do we also need to store a pointer to the parent node - // that is INSIDE so that when we unwind back to that point we start checking again?... probably) - if (args->subTreeLocation == ViewFrustum::INSIDE) { - args->subTreeInside++; - // continue without checking further - } else { - // if this node is not in the view frustum, then just return, since we know none of it's children will be - // in the view. - ViewFrustum::location location = node->inFrustum(*args->viewFrustum); - if (location == ViewFrustum::OUTSIDE) { - args->outOfView++; - if (node->isLeaf()) { - args->leavesOutOfView++; - } else { - args->nonLeavesOutOfView++; - } - return false; - } - // remember this for next recursion pass - // NOTE: This doesn't actually work because we need a stack of these, and our code doesn't execute - // to pop the stack. Similar problem with level. So we need a solution to allow operation functions to - // store information on a stack. - //args->subTreeLocation = location; - } - - // If this node is too far for LOD... - float distanceSquared = node->distanceSquareToPoint(args->cameraPosition); - float boundaryDistanceSquared = boundaryDistanceSquaredForRenderLevel(node->getLevel()); //level+1); - if (distanceSquared >= boundaryDistanceSquared) { - args->tooFar++; - if (node->isLeaf()) { - args->leavesTooFar++; - } else { - args->nonLeavesTooFar++; - } - return false; - } - - // Handle occlusion culling tests. - if (args->wantsOcclusionCulling) { - if (!node->isLeaf()) { - args->nonLeaves++; - - AABox voxelBox = node->getAABox(); - voxelBox.scale(TREE_SCALE); - VoxelProjectedPolygon* voxelPolygon = new VoxelProjectedPolygon(args->viewFrustum->getProjectedPolygon(voxelBox)); - - // If we're not all in view, then ignore it, and just return. But keep searching... - if (!voxelPolygon->getAllInView()) { - args->nonLeavesNotAllInView++; - delete voxelPolygon; - - // we can't determine occlusion, so assume it's not - return true; - } - - CoverageMapStorageResult result = args->map->checkMap(voxelPolygon, false); - if (result == OCCLUDED) { - args->nonLeavesOccluded++; - delete voxelPolygon; - return false; - } - - delete voxelPolygon; - return true; // keep looking... - } - - // we don't want to check shouldRender in the server... that's not used - if (node->isLeaf() && node->isColored() /*&& node->getShouldRender()*/) { - args->coloredVoxels++; - - AABox voxelBox = node->getAABox(); - voxelBox.scale(TREE_SCALE); - VoxelProjectedPolygon* voxelPolygon = new VoxelProjectedPolygon(args->viewFrustum->getProjectedPolygon(voxelBox)); - - // If we're not all in view, then ignore it, and just return. But keep searching... - if (!voxelPolygon->getAllInView()) { - args->notAllInView++; - delete voxelPolygon; - - // But, this is one we do want to send... - - return true; - } - - CoverageMapStorageResult result = args->map->checkMap(voxelPolygon, true); - if (result == OCCLUDED) { - args->occludedVoxels++; - // This is one we don't want to send... - - } else if (result == STORED) { - args->notOccludedVoxels++; - // This is one we do want to send... - } else if (result == DOESNT_FIT) { - args->doesntFit++; - // Not sure what to do with this one... probably send it? - } - } - } - return true; // keep going! -} - -PointerStack stackOfNodes; -long long scanStart = 0; -ScanTreeArgs args; - -void scanTreeWithOcclusion(VoxelTree* tree, ViewFrustum* viewFrustum, CoverageMap* coverageMap, bool wantsOcclusionCulling) { - PerformanceWarning warn(true, "scanTreeWithOcclusion()",true); - //CoverageMap::wantDebugging = false; - //coverageMap->erase(); - - // if we're starting from scratch, remember our time - if (stackOfNodes.isEmpty()) { - printf("scanTreeWithOcclusion() -----> STARTING \n"); - ::scanStart = usecTimestampNow(); - - args.viewFrustum = viewFrustum; - args.cameraPosition = viewFrustum->getPosition()/(float)TREE_SCALE; - args.map = coverageMap; - args.totalVoxels = 0; - args.coloredVoxels = 0; - args.occludedVoxels = 0; - args.notOccludedVoxels = 0; - args.notAllInView = 0; - args.outOfView = 0; - args.leavesOutOfView = 0; - args.nonLeavesOutOfView = 0; - args.subtreeVoxelsSkipped = 0; - args.nonLeaves = 0; - args.stagedForDeletion = 0; - args.nonLeavesNotAllInView = 0; - args.nonLeavesOccluded = 0; - args.doesntFit = 0; - args.tooFar = 0; - args.leavesTooFar = 0; - args.nonLeavesTooFar = 0; - args.tree = tree; - args.subTreeLocation = ViewFrustum::OUTSIDE; // assume the worst - args.subTreeInside = 0; - args.level = 0; - args.wantsOcclusionCulling = wantsOcclusionCulling; - - VoxelProjectedPolygon::pointInside_calls = 0; - VoxelProjectedPolygon::occludes_calls = 0; - VoxelProjectedPolygon::intersects_calls = 0; - } else { - printf("scanTreeWithOcclusion() -----> still working\n"); - } - - glm::vec3 position = args.viewFrustum->getPosition() * (1.0f/TREE_SCALE); - - long allowedTime = 80 * 1000; - tree->recurseTreeWithOperationDistanceSortedTimed(&stackOfNodes, allowedTime, - scanTreeWithOcclusionOperation, position, (void*)&args); - - - if (stackOfNodes.isEmpty()) { - printf("scanTreeWithOcclusion() -----> finished??? \n"); - long long endScan = usecTimestampNow(); - int totalScanmsecs = (endScan - scanStart)/1000; - float elapsedSceneSend = totalScanmsecs/1000.0f; - printf("scanTreeWithOcclusion() -----> totalScanmsecs=%d \n", totalScanmsecs); - printf("scanTreeWithOcclusion() --> elapsed time to send scene = %f seconds, args.totalVoxels=%ld ", elapsedSceneSend,args.totalVoxels); - printf(" [occlusionCulling: %s]\n", debug::valueOf(args.wantsOcclusionCulling)); - - coverageMap->erase(); - - - } else { - printf("scanTreeWithOcclusion() -----> still working\n"); - } - - //tree->recurseTreeWithOperationDistanceSorted(scanTreeWithOcclusionOperation, position, (void*)&args); - - printf("scanTreeWithOcclusion()\n"); - printf(" position=(%f,%f)\n", position.x, position.y); - printf(" total=%ld\n", args.totalVoxels); - printf(" colored=%ld\n", args.coloredVoxels); - printf("\n"); - printf(" occluded=%ld\n", args.occludedVoxels); - printf(" notOccluded=%ld\n", args.notOccludedVoxels); - printf(" nonLeavesOccluded=%ld\n", args.nonLeavesOccluded); - printf("\n"); - printf(" outOfView=%ld\n", args.outOfView); - printf(" leavesOutOfView=%ld\n", args.leavesOutOfView); - printf(" nonLeavesOutOfView=%ld\n", args.nonLeavesOutOfView); - printf("\n"); - printf(" tooFar=%ld\n", args.tooFar); - printf(" leavesTooFar=%ld\n", args.leavesTooFar); - printf(" nonLeavesTooFar=%ld\n", args.nonLeavesTooFar); - printf("\n"); - printf(" nonLeaves=%ld\n", args.nonLeaves); - printf(" notAllInView=%ld\n", args.notAllInView); - printf(" nonLeavesNotAllInView=%ld\n", args.nonLeavesNotAllInView); - printf(" subtreeVoxelsSkipped=%ld\n", args.subtreeVoxelsSkipped); - printf(" stagedForDeletion=%ld\n", args.stagedForDeletion); - printf(" pointInside_calls=%ld\n", VoxelProjectedPolygon::pointInside_calls); - printf(" occludes_calls=%ld\n", VoxelProjectedPolygon::occludes_calls); - printf(" intersects_calls=%ld\n", VoxelProjectedPolygon::intersects_calls); - - printf("\n"); - printf(" subTreeInside=%ld\n", args.subTreeInside); -}