Showing the changes to interface/src/VoxelSystem.cpp (1 of 5 files). Show all
Unified · Split
| @@ -8,6 +8,8 @@ · 7 unmodified lines | ||
| 8 | 8 | |
| 9 | 9 | #include <cstring> |
| 10 | 10 | #include <cmath> |
| 11 | +#include <iostream> // to load voxels from file | |
| 12 | +#include <fstream> // to load voxels from file | |
| 11 | 13 | #include <SharedUtil.h> |
| 12 | 14 | #include <OctalCode.h> |
| 13 | 15 | #include <AgentList.h> |
| @@ -46,6 +48,56 @@ VoxelSystem::~VoxelSystem() { · 32 unmodified lines | ||
| 46 | 48 | delete tree; |
| 47 | 49 | } |
| 48 | 50 | |
| 51 | +////////////////////////////////////////////////////////////////////////////////////////// | |
| 52 | +// Method: VoxelSystem::loadVoxelsFile() | |
| 53 | +// Description: Loads HiFidelity encoded Voxels from a binary file. The current file | |
| 54 | +// format is a stream of single voxels with NO color data. Currently | |
| 55 | +// colors are set randomly | |
| 56 | +// Complaints: Brad :) | |
| 57 | +// To Do: Need to add color data to the file. | |
| 58 | +void VoxelSystem::loadVoxelsFile(char* fileName) { | |
| 59 | + | |
| 60 | + std::ifstream file(fileName, std::ios::in|std::ios::binary); | |
| 61 | + | |
| 62 | + char octets; | |
| 63 | + unsigned int lengthInBytes; | |
| 64 | + | |
| 65 | + int totalBytesRead = 0; | |
| 66 | + if(file.is_open()) | |
| 67 | + { | |
| 68 | + while (!file.eof()) { | |
| 69 | + file.get(octets); | |
| 70 | + totalBytesRead++; | |
| 71 | + lengthInBytes = (octets*3/8)+1; | |
| 72 | + unsigned char * voxelData = new unsigned char[lengthInBytes+1+3]; | |
| 73 | + voxelData[0]=octets; | |
| 74 | + char byte; | |
| 75 | + | |
| 76 | + for (size_t i = 0; i < lengthInBytes; i++) { | |
| 77 | + file.get(byte); | |
| 78 | + totalBytesRead++; | |
| 79 | + voxelData[i+1] = byte; | |
| 80 | + } | |
| 81 | + // random color data | |
| 82 | + voxelData[lengthInBytes+1] = randomColorValue(65); | |
| 83 | + voxelData[lengthInBytes+2] = randomColorValue(65); | |
| 84 | + voxelData[lengthInBytes+3] = randomColorValue(65); | |
| 85 | + | |
| 86 | + tree->readCodeColorBufferToTree(voxelData); | |
| 87 | + delete voxelData; | |
| 88 | + } | |
| 89 | + file.close(); | |
| 90 | + } | |
| 91 | + | |
| 92 | + // reset the verticesEndPointer so we're writing to the beginning of the array | |
| 93 | + verticesEndPointer = verticesArray; | |
| 94 | + // call recursive function to populate in memory arrays | |
| 95 | + // it will return the number of voxels added | |
| 96 | + voxelsRendered = treeToArrays(tree->rootNode); | |
| 97 | + // set the boolean if there are any voxels to be rendered so we re-fill the VBOs | |
| 98 | + voxelsToRender = (voxelsRendered > 0); | |
| 99 | +} | |
| 100 | + | |
| 49 | 101 | void VoxelSystem::parseData(void *data, int size) { |
| 50 | 102 | // output the bits received from the voxel server |
| 51 | 103 | unsigned char *voxelData = (unsigned char *) data + 1; |
| @@ -68,7 +120,7 @@ void VoxelSystem::parseData(void *data, int size) { · 16 unmodified lines | ||
| 68 | 120 | |
| 69 | 121 | int VoxelSystem::treeToArrays(VoxelNode *currentNode) { |
| 70 | 122 | int voxelsAdded = 0; |
| 71 | − | |
| 123 | + | |
| 72 | 124 | for (int i = 0; i < 8; i++) { |
| 73 | 125 | // check if there is a child here |
| 74 | 126 | if (currentNode->children[i] != NULL) { |
| @@ -95,7 +147,7 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode) { · 20 unmodified lines | ||
| 95 | 147 | |
| 96 | 148 | delete [] startVertex; |
| 97 | 149 | } |
| 98 | − | |
| 150 | + | |
| 99 | 151 | return voxelsAdded; |
| 100 | 152 | } |
| 101 | 153 | |