latest copy and paste

This commit is contained in:
ZappoMan 2013-05-29 12:06:58 -07:00
parent eb675c8dd7
commit 377fb1e936
7 changed files with 127 additions and 9 deletions

View file

@ -1153,6 +1153,22 @@ void Application::importVoxels() {
// not yet supported!!!
_voxels.readFromFileV2(fileName,selectedNode);
}
void Application::copyVoxels() {
VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
printf("copyVoxels() _mouseVoxel: %f,%f,%f-%f \n", _mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
if (selectedNode) {
selectedNode->printDebugDetails("selected voxel");
}
}
void Application::pasteVoxels() {
VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
printf("pasteVoxels() _mouseVoxel: %f,%f,%f-%f \n", _mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
if (selectedNode) {
selectedNode->printDebugDetails("selected voxel");
}
}
void Application::initMenu() {
QMenuBar* menuBar = new QMenuBar();
@ -1211,29 +1227,32 @@ void Application::initMenu() {
_voxelModeActions = new QActionGroup(this);
_voxelModeActions->setExclusive(false); // exclusivity implies one is always checked
(_addVoxelMode = voxelMenu->addAction(
"Add Voxel Mode", this, SLOT(updateVoxelModeActions()), Qt::Key_1))->setCheckable(true);
"Add Voxel Mode", this, SLOT(updateVoxelModeActions()), Qt::CTRL | Qt::SHIFT | Qt::Key_A))->setCheckable(true);
_voxelModeActions->addAction(_addVoxelMode);
(_deleteVoxelMode = voxelMenu->addAction(
"Delete Voxel Mode", this, SLOT(updateVoxelModeActions()), Qt::Key_2))->setCheckable(true);
"Delete Voxel Mode", this, SLOT(updateVoxelModeActions()), Qt::CTRL | Qt::SHIFT | Qt::Key_D))->setCheckable(true);
_voxelModeActions->addAction(_deleteVoxelMode);
(_colorVoxelMode = voxelMenu->addAction(
"Color Voxel Mode", this, SLOT(updateVoxelModeActions()), Qt::Key_3))->setCheckable(true);
"Color Voxel Mode", this, SLOT(updateVoxelModeActions()), Qt::CTRL | Qt::SHIFT | Qt::Key_C))->setCheckable(true);
_voxelModeActions->addAction(_colorVoxelMode);
(_selectVoxelMode = voxelMenu->addAction(
"Select Voxel Mode", this, SLOT(updateVoxelModeActions()), Qt::Key_8))->setCheckable(true);
"Select Voxel Mode", this, SLOT(updateVoxelModeActions()), Qt::CTRL | Qt::SHIFT | Qt::Key_S))->setCheckable(true);
_voxelModeActions->addAction(_selectVoxelMode);
voxelMenu->addAction("Place Voxel", this, SLOT(addVoxelInFrontOfAvatar()), Qt::Key_4);
voxelMenu->addAction("Decrease Voxel Size", this, SLOT(decreaseVoxelSize()), Qt::Key_5);
voxelMenu->addAction("Increase Voxel Size", this, SLOT(increaseVoxelSize()), Qt::Key_6);
voxelMenu->addAction("Place Voxel", this, SLOT(addVoxelInFrontOfAvatar()), Qt::CTRL | Qt::SHIFT | Qt::Key_P);
voxelMenu->addAction("Decrease Voxel Size", this, SLOT(decreaseVoxelSize()), Qt::CTRL | Qt::SHIFT | Qt::Key_Minus);
voxelMenu->addAction("Increase Voxel Size", this, SLOT(increaseVoxelSize()), Qt::CTRL | Qt::SHIFT | Qt::Key_Plus);
_voxelPaintColor = voxelMenu->addAction("Voxel Paint Color", this, SLOT(chooseVoxelPaintColor()), Qt::Key_7);
_voxelPaintColor = voxelMenu->addAction("Voxel Paint Color", this, SLOT(chooseVoxelPaintColor()),
Qt::CTRL | Qt::SHIFT | Qt::Key_C);
QColor paintColor(128, 128, 128);
_voxelPaintColor->setData(paintColor);
_voxelPaintColor->setIcon(createSwatchIcon(paintColor));
(_destructiveAddVoxel = voxelMenu->addAction("Create Voxel is Destructive"))->setCheckable(true);
voxelMenu->addAction("Export Voxels", this, SLOT(exportVoxels()), Qt::CTRL | Qt::Key_E);
voxelMenu->addAction("Import Voxels", this, SLOT(importVoxels()), Qt::CTRL | Qt::Key_I);
voxelMenu->addAction("Copy Voxels", this, SLOT(copyVoxels()), Qt::CTRL | Qt::Key_C);
voxelMenu->addAction("Paste Voxels", this, SLOT(pasteVoxels()), Qt::CTRL | Qt::Key_V);
QMenu* frustumMenu = menuBar->addMenu("Frustum");
(_frustumOn = frustumMenu->addAction("Display Frustum"))->setCheckable(true);

View file

@ -101,6 +101,8 @@ private slots:
void chooseVoxelPaintColor();
void exportVoxels();
void importVoxels();
void copyVoxels();
void pasteVoxels();
private:

View file

@ -18,7 +18,21 @@
#include "Application.h"
#include "Log.h"
#include <OctalCode.h>
int main(int argc, const char * argv[]) {
unsigned char test1[2] = {2, 0xE0 };
unsigned char test2[2] = {2, 0xFC };
unsigned char* result1 = chopOctalCode((unsigned char*)&test1, 1);
printOctalCode((unsigned char*)&test1);
printOctalCode(result1);
unsigned char* result2 = chopOctalCode((unsigned char*)&test2, 1);
printOctalCode((unsigned char*)&test2);
printOctalCode(result2);
timeval startup_time;
gettimeofday(&startup_time, NULL);

View file

@ -168,3 +168,54 @@ OctalCodeComparison compareOctalCodes(unsigned char* codeA, unsigned char* codeB
return result;
}
char getOctalCodeSectionValue(unsigned char* octalCode, int section) {
return sectionValue(octalCode + 1 + (3 * section / 8), (3 * section) % 8);
}
void setOctalCodeSectionValue(unsigned char* octalCode, int section, char sectionValue) {
unsigned char* byteAt = octalCode + 1 + (3 * section / 8);
char bitInByte = (3 * section) % 8;
char shiftBy = 8 - bitInByte - 3;
const unsigned char UNSHIFTED_MASK = 0x03;
unsigned char shiftedMask;
unsigned char shiftedValue;
if (shiftBy >=0) {
shiftedMask = UNSHIFTED_MASK << shiftBy;
shiftedValue = sectionValue << shiftBy;
} else {
shiftedMask = UNSHIFTED_MASK >> -shiftBy;
shiftedValue = sectionValue >> -shiftBy;
}
byteAt[0] = byteAt[0] & (shiftedMask | shiftedValue);
if (bitInByte >= 6) {
shiftBy = bitInByte + 1;
shiftedMask = UNSHIFTED_MASK << shiftBy;
shiftedValue = sectionValue << shiftBy;
byteAt[1] = byteAt[1] & (shiftedMask | shiftedValue);
}
}
unsigned char* chopOctalCode(unsigned char* originalOctalCode, int chopLevels) {
int codeLength = numberOfThreeBitSectionsInCode(originalOctalCode);
unsigned char* newCode = NULL;
if (codeLength > chopLevels) {
int newLength = codeLength - chopLevels;
newCode = new unsigned char[newLength+1];
*newCode = newLength; // set the length byte
for (int section = chopLevels; section < codeLength; section++) {
char sectionValue = getOctalCodeSectionValue(originalOctalCode, section);
setOctalCodeSectionValue(newCode, section - chopLevels, sectionValue);
}
}
return newCode;
}
unsigned char* rebaseOctalCode(unsigned char* originalOctalCode, unsigned char* newParentOctalCode) {
}

View file

@ -17,6 +17,9 @@ bool isDirectParentOfChild(unsigned char *parentOctalCode, unsigned char * child
int branchIndexWithDescendant(unsigned char * ancestorOctalCode, unsigned char * descendantOctalCode);
unsigned char * childOctalCode(unsigned char * parentOctalCode, char childNumber);
unsigned char* chopOctalCode(unsigned char* originalOctalCode, int chopLevels);
unsigned char* rebaseOctalCode(unsigned char* originalOctalCode, unsigned char* newParentOctalCode);
// Note: copyFirstVertexForCode() is preferred because it doesn't allocate memory for the return
// but other than that these do the same thing.

View file

@ -53,7 +53,7 @@ VoxelTree::~VoxelTree() {
// Recurses voxel tree calling the RecurseVoxelTreeOperation function for each node.
// stops recursion if operation function returns false.
void VoxelTree::recurseTreeWithOperation(RecurseVoxelTreeOperation operation, void* extraData) {
recurseNodeWithOperation(rootNode, operation,extraData);
recurseNodeWithOperation(rootNode, operation, extraData);
}
// Recurses voxel node with an operation function
@ -1165,3 +1165,28 @@ bool VoxelTree::countVoxelsOperation(VoxelNode* node, void* extraData) {
(*(unsigned long*)extraData)++;
return true; // keep going
}
void VoxelTree::copySubTreeIntoNewTree(VoxelNode* startNode, VoxelTree* destinationTree, bool rebaseToRoot) {
printLog("copySubTreeIntoNewTree()...\n");
VoxelNodeBag nodeBag;
// If we were given a specific node, start from there, otherwise start from root
nodeBag.insert(startNode);
static unsigned char outputBuffer[MAX_VOXEL_PACKET_SIZE - 1]; // save on allocs by making this static
int bytesWritten = 0;
while (!nodeBag.isEmpty()) {
VoxelNode* subTree = nodeBag.extract();
// ask our tree to write a bitsteam
bytesWritten = encodeTreeBitstream(INT_MAX, subTree, &outputBuffer[0],
MAX_VOXEL_PACKET_SIZE - 1, nodeBag, IGNORE_VIEW_FRUSTUM, WANT_COLOR, NO_EXISTS_BITS);
// ask destination tree to read the bitstream
destinationTree->readBitstreamToTree(&outputBuffer[0], bytesWritten, WANT_COLOR, NO_EXISTS_BITS);
}
}

View file

@ -95,6 +95,9 @@ public:
bool readFromFileV2(const char* filename, VoxelNode* node = NULL);
unsigned long getVoxelCount();
void copySubTreeIntoNewTree(VoxelNode* startNode, VoxelTree* destinationTree, bool rebaseToRoot);
void copyNodeIntoTree(VoxelNode* node);
private:
int encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEncodeLevel,
@ -107,6 +110,7 @@ private:
bool deltaViewFrustum, const ViewFrustum* lastViewFrustum);
static bool countVoxelsOperation(VoxelNode* node, void* extraData);
static bool copySubTreeIntoNewTreeOperation(VoxelNode* node, void* extraData);
void recurseNodeWithOperation(VoxelNode* node, RecurseVoxelTreeOperation operation, void* extraData);
VoxelNode* nodeForOctalCode(VoxelNode* ancestorNode, unsigned char* needleCode, VoxelNode** parentOfFoundNode) const;