mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 08:04:01 +02:00
add VoxelNode and VoxelTree classes for shared tree representation
This commit is contained in:
parent
e7db715ee7
commit
763c09f562
4 changed files with 141 additions and 0 deletions
20
shared/src/VoxelNode.cpp
Normal file
20
shared/src/VoxelNode.cpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
//
|
||||
// VoxelNode.cpp
|
||||
// hifi
|
||||
//
|
||||
// Created by Stephen Birarda on 3/13/13.
|
||||
//
|
||||
//
|
||||
|
||||
#include "VoxelNode.h"
|
||||
|
||||
VoxelNode::VoxelNode() {
|
||||
|
||||
// default pointers to child nodes to NULL
|
||||
for (int i = 0; i < 8; i++) {
|
||||
children[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
23
shared/src/VoxelNode.h
Normal file
23
shared/src/VoxelNode.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
//
|
||||
// VoxelNode.h
|
||||
// hifi
|
||||
//
|
||||
// Created by Stephen Birarda on 3/13/13.
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef __hifi__VoxelNode__
|
||||
#define __hifi__VoxelNode__
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class VoxelNode {
|
||||
public:
|
||||
VoxelNode();
|
||||
|
||||
unsigned char color[4];
|
||||
VoxelNode *children[8];
|
||||
unsigned char childMask;
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__VoxelNode__) */
|
70
shared/src/VoxelTree.cpp
Normal file
70
shared/src/VoxelTree.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
//
|
||||
// VoxelTree.cpp
|
||||
// hifi
|
||||
//
|
||||
// Created by Stephen Birarda on 3/13/13.
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#include "VoxelTree.h"
|
||||
|
||||
const int MAX_VOXEL_PACKET_SIZE = 1492;
|
||||
const int MAX_TREE_SIZE_BYTES = 26;
|
||||
|
||||
VoxelTree::VoxelTree() {
|
||||
rootNode = new VoxelNode();
|
||||
}
|
||||
|
||||
unsigned char * VoxelTree::loadBitstream(unsigned char * bitstreamBuffer, VoxelNode *bitstreamRootNode, unsigned char ** startSplitPtr) {
|
||||
static unsigned char **packetSplitPtr = startSplitPtr;
|
||||
|
||||
if (bitstreamRootNode->childMask != 0) {
|
||||
|
||||
if ((bitstreamBuffer + MAX_TREE_SIZE_BYTES - *packetSplitPtr) > MAX_VOXEL_PACKET_SIZE) {
|
||||
// we need to add a packet split here
|
||||
|
||||
// add the octal code for the current root
|
||||
|
||||
// increment packetSplitPtr and set the pointer it points to
|
||||
// to the beginning of the next tree section
|
||||
*(++packetSplitPtr) = bitstreamBuffer;
|
||||
}
|
||||
|
||||
// default color mask is 0, increment pointer for colors
|
||||
*(bitstreamBuffer++) = 0;
|
||||
|
||||
// keep a colorPointer so we can check how many colors were added
|
||||
unsigned char *colorPointer = bitstreamBuffer;
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
// grab this child
|
||||
VoxelNode *child = bitstreamRootNode->children[i];
|
||||
|
||||
// check if the child exists and is not transparent
|
||||
if (child != NULL && child->color[3] != 0) {
|
||||
|
||||
// copy in the childs color to bitstreamBuffer
|
||||
memcpy(colorPointer, child->color, 3);
|
||||
colorPointer += 3;
|
||||
|
||||
// set the colorMask by bitshifting the value of childExists
|
||||
*(bitstreamBuffer - 1) += (1 << (7 - i));
|
||||
}
|
||||
}
|
||||
|
||||
// push the bitstreamBuffer forwards for the number of added colors
|
||||
bitstreamBuffer += (colorPointer - bitstreamBuffer);
|
||||
// copy the childMask to the current position of the bitstreamBuffer, and increment it
|
||||
*(bitstreamBuffer++) = bitstreamRootNode->childMask;
|
||||
|
||||
for (int j = 0; j < 8; j++) {
|
||||
// make sure we have a child to visit
|
||||
if (bitstreamRootNode->children[j] != NULL) {
|
||||
bitstreamBuffer = loadBitstream(bitstreamBuffer,
|
||||
bitstreamRootNode->children[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bitstreamBuffer;
|
||||
}
|
28
shared/src/VoxelTree.h
Normal file
28
shared/src/VoxelTree.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
//
|
||||
// VoxelTree.h
|
||||
// hifi
|
||||
//
|
||||
// Created by Stephen Birarda on 3/13/13.
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __hifi__VoxelTree__
|
||||
#define __hifi__VoxelTree__
|
||||
|
||||
#include <iostream>
|
||||
#include "VoxelNode.h"
|
||||
|
||||
class VoxelTree {
|
||||
public:
|
||||
VoxelTree();
|
||||
|
||||
VoxelNode *rootNode;
|
||||
|
||||
|
||||
void addBitstreamPacketMarker();
|
||||
|
||||
void outputDebugInformation(VoxelNode *currentRootNode = NULL);
|
||||
unsigned char * loadBitstream(unsigned char * bitstreamBuffer, VoxelNode *bitstreamRootNode, unsigned char ** curPacketSplitPtr = NULL);
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__VoxelTree__) */
|
Loading…
Reference in a new issue