From 1bb7d75794ea8166321c060687390ab84cd1d7af Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 8 Aug 2013 14:36:42 -0700 Subject: [PATCH] added tool for splitting SVOs on jurisdiction boundaries --- libraries/voxels/src/JurisdictionMap.h | 4 +- voxel-edit/src/main.cpp | 94 ++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 1 deletion(-) diff --git a/libraries/voxels/src/JurisdictionMap.h b/libraries/voxels/src/JurisdictionMap.h index 59e08e85e9..cf6dba677b 100644 --- a/libraries/voxels/src/JurisdictionMap.h +++ b/libraries/voxels/src/JurisdictionMap.h @@ -31,7 +31,9 @@ public: bool writeToFile(const char* filename); bool readFromFile(const char* filename); - unsigned char* getRootOctalCode() const { return _rootOctalCode; } + unsigned char* getRootOctalCode() const { return _rootOctalCode; } + unsigned char* getEndNodeOctalCode(int index) const { return _endNodes[index]; } + int getEndNodeCount() const { return _endNodes.size(); } private: void clear(); diff --git a/voxel-edit/src/main.cpp b/voxel-edit/src/main.cpp index 9571e4adf5..da92505aed 100644 --- a/voxel-edit/src/main.cpp +++ b/voxel-edit/src/main.cpp @@ -9,6 +9,7 @@ #include #include #include +#include VoxelTree myTree; @@ -56,10 +57,103 @@ void voxelTutorial(VoxelTree * tree) { int main(int argc, const char * argv[]) { + qInstallMessageHandler(sharedMessageHandler); + const char* SAY_HELLO = "--sayHello"; if (cmdOptionExists(argc, argv, SAY_HELLO)) { printf("I'm just saying hello...\n"); } + + + // Handles taking and SVO and splitting it into multiple SVOs based on + // jurisdiction details + const char* SPLIT_SVO = "--splitSVO"; + const char* splitSVOFile = getCmdOption(argc, argv, SPLIT_SVO); + const char* SPLIT_JURISDICTION_ROOT = "--splitJurisdictionRoot"; + const char* SPLIT_JURISDICTION_ENDNODES = "--splitJurisdictionEndNodes"; + const char* splitJurisdictionRoot = getCmdOption(argc, argv, SPLIT_JURISDICTION_ROOT); + const char* splitJurisdictionEndNodes = getCmdOption(argc, argv, SPLIT_JURISDICTION_ENDNODES); + if (splitSVOFile && splitJurisdictionRoot && splitJurisdictionEndNodes) { + char outputFileName[512]; + + printf("splitSVOFile: %s Jurisdictions Root: %s EndNodes: %s\n", + splitSVOFile, splitJurisdictionRoot, splitJurisdictionEndNodes); + + VoxelTree rootSVO; + + rootSVO.readFromSVOFile(splitSVOFile); + JurisdictionMap jurisdiction(splitJurisdictionRoot, splitJurisdictionEndNodes); + + printf("Jurisdiction Root Octcode: "); + printOctalCode(jurisdiction.getRootOctalCode()); + + printf("Jurisdiction End Nodes: %d \n", jurisdiction.getEndNodeCount()); + for (int i = 0; i < jurisdiction.getEndNodeCount(); i++) { + unsigned char* endNodeCode = jurisdiction.getEndNodeOctalCode(i); + printf("End Node: %d ", i); + printOctalCode(endNodeCode); + + // get the endNode details + VoxelPositionSize endNodeDetails; + voxelDetailsForCode(endNodeCode, endNodeDetails); + + // Now, create a split SVO for the EndNode. + // copy the EndNode into a temporary tree + VoxelTree endNodeTree; + + // create a small voxels at corners of the endNode Tree, this will is a hack + // to work around a bug in voxel server that will send Voxel not exists + // for regions that don't contain anything even if they're not in the + // jurisdiction of the server + // This hack assumes the end nodes for demo dinner since it only guarantees + // nodes in the 8 child voxels of the main root voxel + endNodeTree.createVoxel(0.0, 0.0, 0.0, 0.015625, 1, 1, 1, true); + endNodeTree.createVoxel(1.0, 0.0, 0.0, 0.015625, 1, 1, 1, true); + endNodeTree.createVoxel(0.0, 1.0, 0.0, 0.015625, 1, 1, 1, true); + endNodeTree.createVoxel(0.0, 0.0, 1.0, 0.015625, 1, 1, 1, true); + endNodeTree.createVoxel(1.0, 1.0, 1.0, 0.015625, 1, 1, 1, true); + endNodeTree.createVoxel(1.0, 1.0, 0.0, 0.015625, 1, 1, 1, true); + endNodeTree.createVoxel(0.0, 1.0, 1.0, 0.015625, 1, 1, 1, true); + endNodeTree.createVoxel(1.0, 0.0, 1.0, 0.015625, 1, 1, 1, true); + + // Delete the voxel for the EndNode from the temporary tree, so we can + // import our endNode content into it... + endNodeTree.deleteVoxelCodeFromTree(endNodeCode, COLLAPSE_EMPTY_TREE); + + VoxelNode* endNode = rootSVO.getVoxelAt(endNodeDetails.x, + endNodeDetails.y, + endNodeDetails.z, + endNodeDetails.s); + + rootSVO.copySubTreeIntoNewTree(endNode, &endNodeTree, false); + + sprintf(outputFileName, "splitENDNODE%d%s", i, splitSVOFile); + printf("outputFile: %s\n", outputFileName); + endNodeTree.writeToSVOFile(outputFileName); + + // Delete the voxel for the EndNode from the root tree... + rootSVO.deleteVoxelCodeFromTree(endNodeCode, COLLAPSE_EMPTY_TREE); + + // create a small voxel in center of each EndNode, this will is a hack + // to work around a bug in voxel server that will send Voxel not exists + // for regions that don't contain anything even if they're not in the + // jurisdiction of the server + float x = endNodeDetails.x + endNodeDetails.s * 0.5; + float y = endNodeDetails.y + endNodeDetails.s * 0.5; + float z = endNodeDetails.z + endNodeDetails.s * 0.5; + float s = endNodeDetails.s * 0.015625; + + rootSVO.createVoxel(x, y, z, s, 1, 1, 1, true); + + } + + sprintf(outputFileName, "splitROOT%s", splitSVOFile); + printf("outputFile: %s\n", outputFileName); + rootSVO.writeToSVOFile(outputFileName); + + printf("exiting now\n"); + return 0; + } const char* DONT_CREATE_FILE = "--dontCreateSceneFile"; bool dontCreateFile = cmdOptionExists(argc, argv, DONT_CREATE_FILE);