mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 12:13:40 +02:00
latest jurisdiction work
This commit is contained in:
parent
f57d86ddb2
commit
558fca7936
6 changed files with 92 additions and 14 deletions
libraries
voxel-server/src
|
@ -257,3 +257,42 @@ unsigned char* rebaseOctalCode(unsigned char* originalOctalCode, unsigned char*
|
|||
return newCode;
|
||||
}
|
||||
|
||||
bool isAncestorOf(unsigned char* possibleAncestor, unsigned char* possibleDescendent, int descendentsChild) {
|
||||
if (!possibleAncestor || !possibleDescendent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int ancestorCodeLength = numberOfThreeBitSectionsInCode(possibleAncestor);
|
||||
if (ancestorCodeLength == 0) {
|
||||
return true; // this is the root, it's the anscestor of all
|
||||
}
|
||||
|
||||
int descendentCodeLength = numberOfThreeBitSectionsInCode(possibleDescendent);
|
||||
|
||||
// if the caller also include a child, then our descendent length is actually one extra!
|
||||
if (descendentsChild != CHECK_NODE_ONLY) {
|
||||
descendentCodeLength++;
|
||||
}
|
||||
|
||||
if (ancestorCodeLength > descendentCodeLength) {
|
||||
return false; // if the descendent is shorter, it can't be a descendent
|
||||
}
|
||||
|
||||
// compare the sections for the ancestor to the descendent
|
||||
for (int section = 0; section < ancestorCodeLength; section++) {
|
||||
char sectionValueAncestor = getOctalCodeSectionValue(possibleAncestor, section);
|
||||
char sectionValueDescendent;
|
||||
if (ancestorCodeLength <= descendentCodeLength) {
|
||||
sectionValueDescendent = getOctalCodeSectionValue(possibleDescendent, section);
|
||||
} else {
|
||||
assert(descendentsChild != CHECK_NODE_ONLY);
|
||||
sectionValueDescendent = descendentsChild;
|
||||
}
|
||||
if (sectionValueAncestor != sectionValueDescendent) {
|
||||
return false; // first non-match, means they don't match
|
||||
}
|
||||
}
|
||||
|
||||
// they all match, so we are an ancestor
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ const int BLUE_INDEX = 2;
|
|||
|
||||
void printOctalCode(unsigned char * octalCode);
|
||||
int bytesRequiredForCodeLength(unsigned char threeBitCodes);
|
||||
bool isDirectParentOfChild(unsigned char *parentOctalCode, unsigned char * childOctalCode);
|
||||
int branchIndexWithDescendant(unsigned char * ancestorOctalCode, unsigned char * descendantOctalCode);
|
||||
unsigned char * childOctalCode(unsigned char * parentOctalCode, char childNumber);
|
||||
int numberOfThreeBitSectionsInCode(unsigned char * octalCode);
|
||||
|
@ -29,6 +28,9 @@ unsigned char* chopOctalCode(unsigned char* originalOctalCode, int chopLevels);
|
|||
unsigned char* rebaseOctalCode(unsigned char* originalOctalCode, unsigned char* newParentOctalCode,
|
||||
bool includeColorSpace = false);
|
||||
|
||||
const int CHECK_NODE_ONLY = -1;
|
||||
bool isAncestorOf(unsigned char* possibleAncestor, unsigned char* possibleDescendent, int descendentsChild = CHECK_NODE_ONLY);
|
||||
|
||||
// Note: copyFirstVertexForCode() is preferred because it doesn't allocate memory for the return
|
||||
// but other than that these do the same thing.
|
||||
float * firstVertexForCode(unsigned char * octalCode);
|
||||
|
|
|
@ -56,8 +56,34 @@ void JurisdictionMap::init(unsigned char* rootOctalCode, const std::vector<unsig
|
|||
_endNodes = endNodes;
|
||||
}
|
||||
|
||||
bool JurisdictionMap::isMyJurisdiction(VoxelNode* node, int childIndex) const {
|
||||
return true;
|
||||
JurisdictionMap::Area JurisdictionMap::isMyJurisdiction(unsigned char* nodeOctalCode, int childIndex) const {
|
||||
// to be in our jurisdiction, we must be under the root...
|
||||
|
||||
// if the node is an ancestor of my root, then we return ABOVE
|
||||
if (isAncestorOf(nodeOctalCode, _rootOctalCode)) {
|
||||
return ABOVE;
|
||||
}
|
||||
|
||||
// otherwise...
|
||||
bool isInJurisdiction = isAncestorOf(_rootOctalCode, nodeOctalCode, childIndex);
|
||||
|
||||
//printf("isInJurisdiction=%s rootOctalCode=",debug::valueOf(isInJurisdiction));
|
||||
//printOctalCode(_rootOctalCode);
|
||||
//printf("nodeOctalCode=");
|
||||
//printOctalCode(nodeOctalCode);
|
||||
|
||||
// if we're under the root, then we can't be under any of the endpoints
|
||||
if (isInJurisdiction) {
|
||||
for (int i = 0; i < _endNodes.size(); i++) {
|
||||
bool isUnderEndNode = isAncestorOf(_endNodes[i], nodeOctalCode);
|
||||
if (isUnderEndNode) {
|
||||
isInJurisdiction = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return isInJurisdiction ? WITHIN : BELOW;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -12,16 +12,20 @@
|
|||
#include <vector>
|
||||
#include <QString>
|
||||
|
||||
class VoxelNode; // forward declaration
|
||||
|
||||
class JurisdictionMap {
|
||||
public:
|
||||
enum Area {
|
||||
ABOVE,
|
||||
WITHIN,
|
||||
BELOW
|
||||
};
|
||||
|
||||
JurisdictionMap();
|
||||
JurisdictionMap(const char* filename);
|
||||
JurisdictionMap(unsigned char* rootOctalCode, const std::vector<unsigned char*>& endNodes);
|
||||
~JurisdictionMap();
|
||||
|
||||
bool isMyJurisdiction(VoxelNode* node, int childIndex) const;
|
||||
Area isMyJurisdiction(unsigned char* nodeOctalCode, int childIndex) const;
|
||||
|
||||
bool writeToFile(const char* filename);
|
||||
bool readFromFile(const char* filename);
|
||||
|
@ -33,7 +37,6 @@ private:
|
|||
unsigned char* hexStringToOctalCode(const QString& input) const;
|
||||
QString octalCodeToHexString(unsigned char* octalCode) const;
|
||||
|
||||
|
||||
unsigned char* _rootOctalCode;
|
||||
std::vector<unsigned char*> _endNodes;
|
||||
};
|
||||
|
|
|
@ -1078,6 +1078,15 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp
|
|||
if (currentEncodeLevel >= params.maxEncodeLevel) {
|
||||
return bytesAtThisLevel;
|
||||
}
|
||||
|
||||
// If we've been provided a jurisdiction map, then we need to honor it.
|
||||
if (params.jurisdictionMap) {
|
||||
// here's how it works... if we're currently above our root jurisdiction, then we proceed normally.
|
||||
// but once we're in our own jurisdiction, then we need to make sure we're not below it.
|
||||
if (JurisdictionMap::BELOW == params.jurisdictionMap->isMyJurisdiction(node->getOctalCode(), CHECK_NODE_ONLY)) {
|
||||
return bytesAtThisLevel;
|
||||
}
|
||||
}
|
||||
|
||||
// caller can pass NULL as viewFrustum if they want everything
|
||||
if (params.viewFrustum) {
|
||||
|
@ -1200,13 +1209,13 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp
|
|||
// if the caller wants to include childExistsBits, then include them even if not in view, if however,
|
||||
// we're in a portion of the tree that's not our responsibility, then we assume the child nodes exist
|
||||
// even if they don't in our local tree
|
||||
bool notMyJurisdictionBro = false;
|
||||
bool notMyJurisdiction = false;
|
||||
if (params.jurisdictionMap) {
|
||||
notMyJurisdictionBro = !params.jurisdictionMap->isMyJurisdiction(node, i);
|
||||
notMyJurisdiction = (JurisdictionMap::BELOW == params.jurisdictionMap->isMyJurisdiction(node->getOctalCode(), i));
|
||||
}
|
||||
if (params.includeExistsBits) {
|
||||
// If the child is known to exist, OR, it's not my jurisdiction, then we mark the bit as existing
|
||||
if (childNode || notMyJurisdictionBro) {
|
||||
if (childNode || notMyJurisdiction) {
|
||||
childrenExistInTreeBits += (1 << (7 - i));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,6 +67,8 @@ bool debugVoxelReceiving = false;
|
|||
|
||||
EnvironmentData environmentData[3];
|
||||
|
||||
int receivedPacketCount = 0;
|
||||
JurisdictionMap* jurisdiction = NULL;
|
||||
|
||||
void randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) {
|
||||
// randomly generate children for this node
|
||||
|
@ -294,7 +296,7 @@ void deepestLevelVoxelDistributor(NodeList* nodeList,
|
|||
WANT_EXISTS_BITS, DONT_CHOP, wantDelta, lastViewFrustum,
|
||||
wantOcclusionCulling, coverageMap, boundaryLevelAdjust,
|
||||
nodeData->getLastTimeBagEmpty(),
|
||||
isFullScene, &nodeData->stats);
|
||||
isFullScene, &nodeData->stats, ::jurisdiction);
|
||||
|
||||
nodeData->stats.encodeStarted();
|
||||
bytesWritten = serverTree.encodeTreeBitstream(subTree, &tempOutputBuffer[0], MAX_VOXEL_PACKET_SIZE - 1,
|
||||
|
@ -429,9 +431,6 @@ void attachVoxelNodeDataToNode(Node* newNode) {
|
|||
}
|
||||
}
|
||||
|
||||
int receivedPacketCount = 0;
|
||||
JurisdictionMap* jurisdiction = NULL;
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
pthread_mutex_init(&::treeLock, NULL);
|
||||
|
||||
|
|
Loading…
Reference in a new issue