Showing the changes to interface/src/VoxelSystem.cpp (1 of 6 files). Show all
Unified · Split
| @@ -56,6 +56,7 @@ VoxelSystem::~VoxelSystem() { · 55 unmodified lines | ||
| 56 | 56 | // Complaints: Brad :) |
| 57 | 57 | // To Do: Need to add color data to the file. |
| 58 | 58 | void VoxelSystem::loadVoxelsFile(char* fileName) { |
| 59 | + int vCount = 0; | |
| 59 | 60 | |
| 60 | 61 | std::ifstream file(fileName, std::ios::in|std::ios::binary); |
| 61 | 62 | |
| @@ -65,10 +66,11 @@ void VoxelSystem::loadVoxelsFile(char* fileName) { · 3 unmodified lines | ||
| 65 | 66 | int totalBytesRead = 0; |
| 66 | 67 | if(file.is_open()) |
| 67 | 68 | { |
| 68 | − while (!file.eof()) { | |
| 69 | + bool bail = false; | |
| 70 | + while (!file.eof() && !bail) { | |
| 69 | 71 | file.get(octets); |
| 70 | 72 | totalBytesRead++; |
| 71 | − lengthInBytes = (octets*3/8)+1; | |
| 73 | + lengthInBytes = bytesRequiredForCodeLength(octets)-1; //(octets*3/8)+1; | |
| 72 | 74 | unsigned char * voxelData = new unsigned char[lengthInBytes+1+3]; |
| 73 | 75 | voxelData[0]=octets; |
| 74 | 76 | char byte; |
| @@ -78,16 +80,32 @@ void VoxelSystem::loadVoxelsFile(char* fileName) { · 3 unmodified lines | ||
| 78 | 80 | totalBytesRead++; |
| 79 | 81 | voxelData[i+1] = byte; |
| 80 | 82 | } |
| 81 | − // random color data | |
| 82 | − voxelData[lengthInBytes+1] = randomColorValue(65); | |
| 83 | − voxelData[lengthInBytes+2] = randomColorValue(65); | |
| 84 | − voxelData[lengthInBytes+3] = randomColorValue(65); | |
| 85 | − | |
| 83 | + // read color data | |
| 84 | + char red,green,blue; | |
| 85 | + file.get(red); | |
| 86 | + file.get(green); | |
| 87 | + file.get(blue); | |
| 88 | + | |
| 89 | + //printf("red:%d\n",red); | |
| 90 | + //printf("green:%d\n",green); | |
| 91 | + //printf("blue:%d\n",blue); | |
| 92 | + vCount++; | |
| 93 | + //printf("vCount:%d\n",vCount); | |
| 94 | + | |
| 95 | + //randomColorValue(65); | |
| 96 | + float rf = randFloatInRange(.5,1); // add a little bit of variance to colors so we can see the voxels | |
| 97 | + voxelData[lengthInBytes+1] = red * rf; | |
| 98 | + voxelData[lengthInBytes+2] = green * rf; | |
| 99 | + voxelData[lengthInBytes+3] = blue * rf; | |
| 100 | + | |
| 101 | + //printVoxelCode(voxelData); | |
| 86 | 102 | tree->readCodeColorBufferToTree(voxelData); |
| 87 | 103 | delete voxelData; |
| 88 | 104 | } |
| 89 | 105 | file.close(); |
| 90 | 106 | } |
| 107 | + | |
| 108 | + tree->pruneTree(tree->rootNode); | |
| 91 | 109 | |
| 92 | 110 | // reset the verticesEndPointer so we're writing to the beginning of the array |
| 93 | 111 | verticesEndPointer = verticesArray; |