Showing the changes to interface/src/VoxelSystem.cpp (1 of 9 files). Show all
Unified · Split
| @@ -14,7 +14,7 @@ · 13 unmodified lines | ||
| 14 | 14 | #include <OctalCode.h> |
| 15 | 15 | #include "VoxelSystem.h" |
| 16 | 16 | |
| 17 | −const int MAX_VOXELS_PER_SYSTEM = 250000; | |
| 17 | +const int MAX_VOXELS_PER_SYSTEM = 1500000; //250000; | |
| 18 | 18 | |
| 19 | 19 | const int VERTICES_PER_VOXEL = 8; |
| 20 | 20 | const int VERTEX_POINTS_PER_VOXEL = 3 * VERTICES_PER_VOXEL; |
| @@ -54,57 +54,9 @@ VoxelSystem::~VoxelSystem() { · 33 unmodified lines | ||
| 54 | 54 | // colors are set randomly |
| 55 | 55 | // Complaints: Brad :) |
| 56 | 56 | // To Do: Need to add color data to the file. |
| 57 | −void VoxelSystem::loadVoxelsFile(char* fileName) { | |
| 58 | − int vCount = 0; | |
| 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 | − bool bail = false; | |
| 69 | − while (!file.eof() && !bail) { | |
| 70 | − file.get(octets); | |
| 71 | − totalBytesRead++; | |
| 72 | − lengthInBytes = bytesRequiredForCodeLength(octets)-1; //(octets*3/8)+1; | |
| 73 | − unsigned char * voxelData = new unsigned char[lengthInBytes+1+3]; | |
| 74 | − voxelData[0]=octets; | |
| 75 | − char byte; | |
| 76 | − | |
| 77 | − for (size_t i = 0; i < lengthInBytes; i++) { | |
| 78 | − file.get(byte); | |
| 79 | − totalBytesRead++; | |
| 80 | − voxelData[i+1] = byte; | |
| 81 | − } | |
| 82 | − // read color data | |
| 83 | − char red,green,blue; | |
| 84 | − file.get(red); | |
| 85 | − file.get(green); | |
| 86 | − file.get(blue); | |
| 87 | − | |
| 88 | − //printf("red:%d\n",red); | |
| 89 | − //printf("green:%d\n",green); | |
| 90 | − //printf("blue:%d\n",blue); | |
| 91 | − vCount++; | |
| 92 | − //printf("vCount:%d\n",vCount); | |
| 93 | − | |
| 94 | − //randomColorValue(65); | |
| 95 | − float rf = randFloatInRange(.5,1); // add a little bit of variance to colors so we can see the voxels | |
| 96 | − voxelData[lengthInBytes+1] = red * rf; | |
| 97 | − voxelData[lengthInBytes+2] = green * rf; | |
| 98 | − voxelData[lengthInBytes+3] = blue * rf; | |
| 99 | − | |
| 100 | − //printVoxelCode(voxelData); | |
| 101 | − tree->readCodeColorBufferToTree(voxelData); | |
| 102 | − delete voxelData; | |
| 103 | − } | |
| 104 | − file.close(); | |
| 105 | − } | |
| 57 | +void VoxelSystem::loadVoxelsFile(const char* fileName, bool wantColorRandomizer) { | |
| 106 | 58 | |
| 107 | − tree->pruneTree(tree->rootNode); | |
| 59 | + tree->loadVoxelsFile(fileName,wantColorRandomizer); | |
| 108 | 60 | |
| 109 | 61 | // reset the verticesEndPointer so we're writing to the beginning of the array |
| 110 | 62 | verticesEndPointer = verticesArray; |
| @@ -122,99 +74,9 @@ void VoxelSystem::loadVoxelsFile(char* fileName) { · 11 unmodified lines | ||
| 122 | 74 | // mechanism to tell the system to redraw it's arrays after voxels are done |
| 123 | 75 | // being added. This is a concept mostly only understood by VoxelSystem. |
| 124 | 76 | // Complaints: Brad :) |
| 125 | −void VoxelSystem::createSphere(float r,float xc, float yc, float zc, float s, bool solid) | |
| 126 | −{ | |
| 127 | − // About the color of the sphere... we're going to make this sphere be a gradient | |
| 128 | − // between two RGB colors. We will do the gradient along the phi spectrum | |
| 129 | − unsigned char r1 = randomColorValue(165); | |
| 130 | − unsigned char g1 = randomColorValue(165); | |
| 131 | − unsigned char b1 = randomColorValue(165); | |
| 132 | − unsigned char r2 = randomColorValue(65); | |
| 133 | − unsigned char g2 = randomColorValue(65); | |
| 134 | − unsigned char b2 = randomColorValue(65); | |
| 135 | − | |
| 136 | − // we don't want them to match!! | |
| 137 | − if (r1==r2 && g1==g2 && b1==b2) | |
| 138 | − { | |
| 139 | − r2=r1/2; | |
| 140 | − g2=g1/2; | |
| 141 | − b2=b1/2; | |
| 142 | − } | |
| 143 | − | |
| 144 | − /** | |
| 145 | − std::cout << "creatSphere COLORS "; | |
| 146 | − std::cout << " r1=" << (int)r1; | |
| 147 | − std::cout << " g1=" << (int)g1; | |
| 148 | − std::cout << " b1=" << (int)b1; | |
| 149 | − std::cout << " r2=" << (int)r2; | |
| 150 | − std::cout << " g2=" << (int)g2; | |
| 151 | − std::cout << " b2=" << (int)b2; | |
| 152 | − std::cout << std::endl; | |
| 153 | − **/ | |
| 154 | − | |
| 155 | − // Psuedocode for creating a sphere: | |
| 156 | − // | |
| 157 | − // for (theta from 0 to 2pi): | |
| 158 | − // for (phi from 0 to pi): | |
| 159 | − // x = xc+r*cos(theta)*sin(phi) | |
| 160 | − // y = yc+r*sin(theta)*sin(phi) | |
| 161 | − // z = zc+r*cos(phi) | |
| 162 | − | |
| 163 | − int t=0; // total points | |
| 164 | − | |
| 165 | − // We want to make sure that as we "sweep" through our angles | |
| 166 | − // we use a delta angle that's small enough to not skip any voxels | |
| 167 | − // we can calculate theta from our desired arc length | |
| 168 | − // | |
| 169 | − // lenArc = ndeg/360deg * 2pi*R | |
| 170 | − // lenArc = theta/2pi * 2pi*R | |
| 171 | − // lenArc = theta*R | |
| 172 | − // theta = lenArc/R | |
| 173 | − // theta = g/r | |
| 174 | − float angleDelta = (s/r); | |
| 77 | +void VoxelSystem::createSphere(float r,float xc, float yc, float zc, float s, bool solid) { | |
| 175 | 78 | |
| 176 | − // assume solid for now | |
| 177 | − float ri = 0.0; | |
| 178 | − if (!solid) | |
| 179 | − { | |
| 180 | − ri=r; // just the outer surface | |
| 181 | − } | |
| 182 | − // If you also iterate form the interior of the sphere to the radius, makeing | |
| 183 | − // larger and larger sphere's you'd end up with a solid sphere. And lots of voxels! | |
| 184 | − for (; ri <= r; ri+=s) | |
| 185 | − { | |
| 186 | − for (float theta=0.0; theta <= 2*M_PI; theta += angleDelta) | |
| 187 | − { | |
| 188 | − for (float phi=0.0; phi <= M_PI; phi += angleDelta) | |
| 189 | − { | |
| 190 | − t++; // total voxels | |
| 191 | − float x = xc+r*cos(theta)*sin(phi); | |
| 192 | − float y = yc+r*sin(theta)*sin(phi); | |
| 193 | − float z = zc+r*cos(phi); | |
| 194 | − /* | |
| 195 | − std::cout << " r=" << r; | |
| 196 | − std::cout << " theta=" << theta; | |
| 197 | − std::cout << " phi=" << phi; | |
| 198 | − std::cout << " x=" << x; | |
| 199 | − std::cout << " y=" << y; | |
| 200 | − std::cout << " z=" << z; | |
| 201 | − std::cout << " t=" << t; | |
| 202 | − std::cout << std::endl; | |
| 203 | − */ | |
| 204 | − | |
| 205 | − // gradient color data | |
| 206 | − float gradient = (phi/M_PI); | |
| 207 | − unsigned char red = r1+((r2-r1)*gradient); | |
| 208 | − unsigned char green = g1+((g2-g1)*gradient); | |
| 209 | − unsigned char blue = b1+((b2-b1)*gradient); | |
| 210 | − | |
| 211 | − unsigned char* voxelData = pointToVoxel(x,y,z,s,red,green,blue); | |
| 212 | − tree->readCodeColorBufferToTree(voxelData); | |
| 213 | − delete voxelData; | |
| 214 | − | |
| 215 | − } | |
| 216 | − } | |
| 217 | − } | |
| 79 | + tree->createSphere(r,xc,yc,zc,s,solid); | |
| 218 | 80 | |
| 219 | 81 | // reset the verticesEndPointer so we're writing to the beginning of the array |
| 220 | 82 | verticesEndPointer = verticesArray; |